-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-58286] JSConstantNumericUnitNode should never be executed.
PullRequest: js/3265
- Loading branch information
Showing
7 changed files
with
72 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
graal-js/src/com.oracle.truffle.js.test/js/const_reassign_ident_global.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. | ||
*/ | ||
|
||
/** | ||
* Tests correct immutable binding reassignment handling for `const` variables in the global scope | ||
* via increment (++), decrement (--), and compound assignment operators. | ||
*/ | ||
|
||
const i = 4; try { i++; fail(); } catch (e) { if (!(e instanceof TypeError)) throw e; } | ||
const j = 4; try { ++j; fail(); } catch (e) { if (!(e instanceof TypeError)) throw e; } | ||
const k = 4; try { k--; fail(); } catch (e) { if (!(e instanceof TypeError)) throw e; } | ||
const l = 4; try { --l; fail(); } catch (e) { if (!(e instanceof TypeError)) throw e; } | ||
|
||
// If binding is immutable, compound assignment should fail only after the binary operator (including both its operands) has been executed. | ||
let side_effects = 0; | ||
const m = {toString() { side_effects += 1; return "a"; }}; | ||
try { | ||
m += {toString() { side_effects += 2; return "b"; }}; | ||
fail(); | ||
} catch (e) { | ||
if (!(e instanceof TypeError)) throw e; | ||
} | ||
if (side_effects !== 3) throw new Error(`${side_effects}`); | ||
|
||
// TypeError due to mixing BigInt and Number is thrown first. | ||
const n = 1n; | ||
try { | ||
n += 1; | ||
fail(); | ||
} catch (e) { | ||
if (!(e instanceof TypeError && e.message.includes("BigInt"))) throw e; | ||
} | ||
|
||
function fail() { | ||
throw new Error("Expected a TypeError, but no error was thrown."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters