diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/basic/eval-scopes.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/basic/eval-scopes.js')
-rw-r--r-- | js/src/jit-test/tests/basic/eval-scopes.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/eval-scopes.js b/js/src/jit-test/tests/basic/eval-scopes.js new file mode 100644 index 0000000000..695adb8a79 --- /dev/null +++ b/js/src/jit-test/tests/basic/eval-scopes.js @@ -0,0 +1,74 @@ +function bytecode(f) { + if (typeof disassemble !== "function") + return "unavailable"; + var d = disassemble(f); + return d.slice(d.indexOf("main:"), d.indexOf("\n\n")); +} + +function hasGname(f, v, hasIt = true) { + // Do a try-catch that prints the full stack, so we can tell + // _which_ part of this test failed. + try { + var b = bytecode(f); + if (b != "unavailable") { + assertEq(b.includes(`GetGName "${v}"`), hasIt); + assertEq(b.includes(`GetName "${v}"`), !hasIt); + } + } catch (e) { + print(e.stack); + throw e; + } +} + +var x = "outer"; + +{ + let x = "inner"; + eval("function h() { assertEq(x, 'inner');} h()"); + eval("function h2() { (function nest() { assertEq(x, 'inner'); })(); } h2()"); +} + +// GNAME optimizations should work through lazy parsing. +eval(` + function h3() { + assertEq(x, 'outer'); + } + h3(); + hasGname(h3, 'x', true); + `); +eval(` + function h4() { + function nest() { assertEq(x, 'outer'); } + nest(); + return nest; + } + hasGname(h4(), 'x', true); + `); + +with ({}) { + let x = "inner"; + eval("function j() { assertEq(x, 'inner');} j()"); + eval("function j2() { (function nest() { assertEq(x, 'inner'); })(); } j2()"); +} + +(function () { + let x = "inner"; + eval("function l() { assertEq(x, 'inner');} l()"); + eval("function l2() { (function nest() { assertEq(x, 'inner'); })(); } l2()"); +})(); + +var y1 = 5; +eval(` + 'use strict'; + var y1 = 6; + assertEq(y1, 6); + (function() { assertEq(y1, 6); })() + `); +assertEq(y1, 5); + +eval(` + 'use strict'; + var y2 = 6; + assertEq(y2, 6); + (function() { assertEq(y2, 6); })() + `); |