diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/jit-test/tests/basic/eval-scopes.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/tests/basic/eval-scopes.js')
-rw-r--r-- | js/src/jit-test/tests/basic/eval-scopes.js | 133 |
1 files changed, 133 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 000000000..1342ef564 --- /dev/null +++ b/js/src/jit-test/tests/basic/eval-scopes.js @@ -0,0 +1,133 @@ +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"; + +setLazyParsingDisabled(true); +{ + let x = "inner"; + eval("function g() { assertEq(x, 'inner');} g()"); + eval("function g2() { (function nest() { assertEq(x, 'inner'); })(); } g2()"); +} +eval(` + function g3() { + assertEq(x, 'outer'); + } + g3(); + hasGname(g3, 'x'); + `); +eval(` + function g4() { + function nest() { assertEq(x, 'outer'); } + nest(); + return nest; + } + hasGname(g4(), 'x'); + `); +setLazyParsingDisabled(false); + +{ + 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); + `); + +setLazyParsingDisabled(true); +with ({}) { + let x = "inner"; + eval("function i() { assertEq(x, 'inner');} i()"); + eval("function i2() { (function nest() { assertEq(x, 'inner'); })(); } i2()"); +} +setLazyParsingDisabled(false); + +with ({}) { + let x = "inner"; + eval("function j() { assertEq(x, 'inner');} j()"); + eval("function j2() { (function nest() { assertEq(x, 'inner'); })(); } j2()"); +} + +setLazyParsingDisabled(true); +(function () { + var x = "inner"; + eval("function k() { assertEq(x, 'inner');} k()"); + eval("function k2() { (function nest() { assertEq(x, 'inner'); })(); } k2()"); +})(); +setLazyParsingDisabled(false); + +(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); })() + `); + +setLazyParsingDisabled(true); + +var y3 = 5; +eval(` + 'use strict'; + var y3 = 6; + assertEq(y3, 6); + (function() { assertEq(y3, 6); })() + `); +assertEq(y3, 5); + +eval(` + 'use strict'; + var y4 = 6; + assertEq(y4, 6); + (function() { assertEq(y4, 6); })() + `); + +setLazyParsingDisabled(false); |