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/parser | |
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/parser')
94 files changed, 1456 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/parser/arrow-rest.js b/js/src/jit-test/tests/parser/arrow-rest.js new file mode 100644 index 000000000..53750f25b --- /dev/null +++ b/js/src/jit-test/tests/parser/arrow-rest.js @@ -0,0 +1,222 @@ +// The parser should throw SyntaxError immediately if it finds "..." in a +// context where it's not allowed. + +function testThrow(code, column) { + var caught = false; + try { + eval(code); + } catch (e) { + caught = true; + assertEq(e.columnNumber, column); + } + assertEq(caught, true, + "failed to throw evaluating <" + code + ">"); +} + +// expression statement + +testThrow(` +...a)=> +`, 0); + +// default parameter + +testThrow(` +function f(x=...a) => +`, 13); + +// rest parameter + +testThrow(` +function f(... ...a) => +`, 15); + +// destructuring parameter + +testThrow(` +([... ...a)=> +`, 6); + +testThrow(` +({...a)=> +`, 2); + +testThrow(` +function f([... ...a)=> +`, 16); + +testThrow(` +function f({...a)=> +`, 12); + +// arrow + +testThrow(` +x => ...a)=> +`, 5); + +// template literal + +testThrow("`${ ...a)=>}`", 4); + +// destructing assignment + +testThrow(` +var [... ...a)=> +`, 9); + +testThrow(` +var {...a)=> +`, 5); + +// initializer + +testThrow(` +var [a] = ...a)=> +`, 10); + +testThrow(` +var {a:a} = ...a)=> +`, 12); + +testThrow(` +var a = ...a)=> +`, 8); + +// if statement + +testThrow(` +if (...a) => +`, 4); + +// for statement + +testThrow(` +for (...a)=> +`, 5); + +testThrow(` +for (let a in ...a)=> +`, 14); + +testThrow(` +for (let a of ...a)=> +`, 14); + +testThrow(` +for (; ...a)=> +`, 7); + +testThrow(` +for (;; ...a)=> +`, 8); + +// case + +testThrow(` +switch (x) { case ...a)=> +`, 18); + +// return statement + +testThrow(` +function f(x) { return ...a)=> +`, 23); + +// yield expression + +testThrow(` +function* f(x) { yield ...a)=> +`, 23); + +// throw statement + +testThrow(` +throw ...a) => +`, 6); + +testThrow(` +try {} catch (x if ...a) => +`, 19); + +// class + +testThrow(` +class A extends ...a) => +`, 16); + +// conditional expression + +testThrow(` +1 ? ...a) => +`, 4); + +testThrow(` +1 ? 2 : ...a) => +`, 8); + +// unary operators + +testThrow(` +void ...a) => +`, 5); + +testThrow(` +typeof ...a) => +`, 7); + +testThrow(` +++ ...a) => +`, 3); + +testThrow(` +delete ...a) => +`, 7); + +// array comprehension + +testThrow(` +[for (...a) => +`, 6); + +testThrow(` +[for (x of y) if (...a) => +`, 18); + +testThrow(` +[for (x of y) if (x) ...a) => +`, 21); + +// new + +testThrow(` +new ...a) => +`, 4); + +// member expression + +testThrow(` +x[...a) => +`, 2); + +// array literal + +testThrow(` +[... ...a) => +`, 5); + +// object literal + +testThrow(` +({[...a) => +`, 3); + +testThrow(` +({x: ...a) => +`, 5); + +// assignment + +testThrow(` +x = ...a) => +`, 4); diff --git a/js/src/jit-test/tests/parser/arrow-with-block.js b/js/src/jit-test/tests/parser/arrow-with-block.js new file mode 100644 index 000000000..de6f34c31 --- /dev/null +++ b/js/src/jit-test/tests/parser/arrow-with-block.js @@ -0,0 +1,92 @@ +load(libdir + "asserts.js"); + +let x = 10; +let g = 4; + +assertEq(eval(` +a => {} +/x/g; +`).toString(), "/x/g"); +assertEq(eval(` +a => {} +/x/; +`).toString(), "/x/"); +assertThrowsInstanceOf(() => eval(` +a => {} /x/g; +`), SyntaxError); + +assertEq(eval(` +a => {}, +/x/; +`).toString(), "/x/"); +assertEq(eval(` +a => {} +, +/x/; +`).toString(), "/x/"); + +assertEq(eval(` +false ? +a => {} : +/x/; +`).toString(), "/x/"); +assertEq(eval(` +false ? +a => {} +: +/x/; +`).toString(), "/x/"); + +assertEq(eval(` +a => {}; +/x/; +`).toString(), "/x/"); +assertEq(eval(` +a => {} +; +/x/; +`).toString(), "/x/"); + +assertEq(eval(` +a => 200 +/x/g; +`) instanceof Function, true); +assertEq(eval(` +a => 200 +/x/g; +`)(), 5); +assertEq(eval(` +a => 200 /x/g; +`)(), 5); + +assertEq(eval(` +a => 1, +/x/; +`).toString(), "/x/"); +assertEq(eval(` +a => 1 +, +/x/; +`).toString(), "/x/"); + +assertEq(eval(` +false ? +a => 1 : +/x/; +`).toString(), "/x/"); +assertEq(eval(` +false ? +a => 1 +: +/x/; +`).toString(), "/x/"); + +assertEq(eval(` +a => 1; +/x/; +`).toString(), "/x/"); +assertEq(eval(` +a => 1 +; +/x/; +`).toString(), "/x/"); diff --git a/js/src/jit-test/tests/parser/break-continue-errors.js b/js/src/jit-test/tests/parser/break-continue-errors.js new file mode 100644 index 000000000..9d484506e --- /dev/null +++ b/js/src/jit-test/tests/parser/break-continue-errors.js @@ -0,0 +1,22 @@ +load(libdir + "asserts.js"); + +function test(s, expected) { + assertErrorMessage(() => Function(s), SyntaxError, expected); +} + +test("A: continue;", "continue must be inside loop"); +test("A: continue B;", "continue must be inside loop"); +test("A: if (false) { continue; }", "continue must be inside loop"); +test("A: if (false) { continue B; }", "continue must be inside loop"); +test("while (false) { (() => { continue B; })(); }", "continue must be inside loop"); +test("B: while (false) { (() => { continue B; })(); }", "continue must be inside loop"); + +test("do { continue B; } while (false);", "label not found"); +test("A: for (;;) { continue B; }", "label not found"); +test("A: while (false) { if (x) { continue B; } }", "label not found"); +test("A: while (false) { B: if (x) { continue B; } }", "label not found"); + +test("A: if (false) { break B; }", "label not found"); +test("A: while (false) { break B; }", "label not found"); +test("A: while (true) { if (x) { break B; } }", "label not found"); +test("B: while (false) { (() => { break B; })(); }", "label not found"); diff --git a/js/src/jit-test/tests/parser/bug-1090096.js b/js/src/jit-test/tests/parser/bug-1090096.js new file mode 100644 index 000000000..3894630af --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1090096.js @@ -0,0 +1,12 @@ +load(libdir + "asserts.js"); + +assertThrowsInstanceOf( + () => Function(` +for (let { + [ + function(x) {; + } + ]: {} +} in 0 +`), + SyntaxError) diff --git a/js/src/jit-test/tests/parser/bug-1250192.js b/js/src/jit-test/tests/parser/bug-1250192.js new file mode 100644 index 000000000..39b0ff0f5 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1250192.js @@ -0,0 +1,5 @@ +(function * YearFromTime(x, ... get) { +try {} catch (x) { + for (var x;;); +} +})(); diff --git a/js/src/jit-test/tests/parser/bug-1254164.js b/js/src/jit-test/tests/parser/bug-1254164.js new file mode 100644 index 000000000..3b08180a7 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1254164.js @@ -0,0 +1,6 @@ +// |jit-test| slow; + +var s = ''; +for (var i = 0; i < 70000; i++) + s += 'function x' + i + '() { x' + i + '(); }\n'; +eval("(function() { " + s + " })();"); diff --git a/js/src/jit-test/tests/parser/bug-1263355-1.js b/js/src/jit-test/tests/parser/bug-1263355-1.js new file mode 100644 index 000000000..e5dbb5645 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-1.js @@ -0,0 +1,5 @@ +// |jit-test| error: ReferenceError + +for (let b in [0]) { + let b = b ? 0 : 1 +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-10.js b/js/src/jit-test/tests/parser/bug-1263355-10.js new file mode 100644 index 000000000..1b7888d86 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-10.js @@ -0,0 +1,4 @@ +// |jit-test| error: TypeError + +function f(m, k = class C extends Array { }, p = m()) { } +f() diff --git a/js/src/jit-test/tests/parser/bug-1263355-11.js b/js/src/jit-test/tests/parser/bug-1263355-11.js new file mode 100644 index 000000000..1e363dc79 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-11.js @@ -0,0 +1,6 @@ +function assertNotSame(expected, actual, message = "") { } +function g3(h = () => arguments) { + function arguments() { } + assertNotSame(arguments, h()); +} +g3(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-12.js b/js/src/jit-test/tests/parser/bug-1263355-12.js new file mode 100644 index 000000000..d2049bfa2 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-12.js @@ -0,0 +1,6 @@ + + +syntaxParse(` +if (scriptArgs.length === 0) { } +var file = scriptArgs[0]; +`); diff --git a/js/src/jit-test/tests/parser/bug-1263355-13.js b/js/src/jit-test/tests/parser/bug-1263355-13.js new file mode 100644 index 000000000..09294b08a --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-13.js @@ -0,0 +1,26 @@ +// |jit-test| error: ReferenceError + +// jsfunfuzz-generated +gczeal(9); +for (var i in function(){}); +s = newGlobal(); +aa = f(); +function f(x) { + evalcx(x, s) +} +function h(x) { + f(x) +} +// Adapted from randomly chosen test: js/src/jit-test/tests/debug/resumption-05.js +h("\ + var g = newGlobal();\ + g.debuggeeGlobal = this;\ + g.eval(\"(\" + function() {\ + var dbg = Debugger(debuggeeGlobal);\ + dbg.onDebuggerStatement = function(frame) {\ + frame.eval(\"f\")\ + }\ + } + \")()\");\ + debugger;\ +"); +z; diff --git a/js/src/jit-test/tests/parser/bug-1263355-14.js b/js/src/jit-test/tests/parser/bug-1263355-14.js new file mode 100644 index 000000000..38b3777c3 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-14.js @@ -0,0 +1,26 @@ +function g() { + for (var j = 0; j < 999; ++j) { + try { + k + } catch (e) { + try { + r + } catch (e) {} + } + } +} +function h(code) { + try { + f = Function(code) + } catch (r) {}; + try { + f() + } catch (r) {} + eval("") +} +h("m=function(){};g(m,[,])") +h("=") +h("=") +h("=") +h("startgc(1,'shrinking')") +h("gcparam(\"maxBytes\",gcparam(\"gcBytes\")+4);for(r;;i++){}") diff --git a/js/src/jit-test/tests/parser/bug-1263355-15.js b/js/src/jit-test/tests/parser/bug-1263355-15.js new file mode 100644 index 000000000..409ead51d --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-15.js @@ -0,0 +1,4 @@ +// Adapted from randomly chosen test: js/src/jit-test/tests/parser/yield-in-formal-destructuring.js +function f({ + [e]: {} +}) {} diff --git a/js/src/jit-test/tests/parser/bug-1263355-16.js b/js/src/jit-test/tests/parser/bug-1263355-16.js new file mode 100644 index 000000000..2bb173c8a --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-16.js @@ -0,0 +1,10 @@ +// |jit-test| error: ReferenceError + +let m = parseModule(` +var i = 0; +addThis(); +function addThis() + statusmessages[i] = Number; +`); +m.declarationInstantiation(); +m.evaluation(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-17.js b/js/src/jit-test/tests/parser/bug-1263355-17.js new file mode 100644 index 000000000..f472efcd3 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-17.js @@ -0,0 +1,4 @@ +let m = parseModule(` + var expect = ''; + var [ ... of ] = ( ... of ) => expect; +`); diff --git a/js/src/jit-test/tests/parser/bug-1263355-18.js b/js/src/jit-test/tests/parser/bug-1263355-18.js new file mode 100644 index 000000000..683c24851 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-18.js @@ -0,0 +1,4 @@ +function f14(g = 0) { + { function g() { return "g" } } +} +f14(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-19.js b/js/src/jit-test/tests/parser/bug-1263355-19.js new file mode 100644 index 000000000..c3d118635 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-19.js @@ -0,0 +1,4 @@ +(function(p = null){ + var q; + (function() { q })(); +})(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-2.js b/js/src/jit-test/tests/parser/bug-1263355-2.js new file mode 100644 index 000000000..bb37715b6 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-2.js @@ -0,0 +1,2 @@ +eval(); +try {} catch (abc) {}; diff --git a/js/src/jit-test/tests/parser/bug-1263355-20.js b/js/src/jit-test/tests/parser/bug-1263355-20.js new file mode 100644 index 000000000..f98cf7b44 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-20.js @@ -0,0 +1,2 @@ +{ function c() {} } +class c { } diff --git a/js/src/jit-test/tests/parser/bug-1263355-21.js b/js/src/jit-test/tests/parser/bug-1263355-21.js new file mode 100644 index 000000000..9dfa94e69 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-21.js @@ -0,0 +1,7 @@ +// |jit-test| error: TypeError + +(function() { + "use asm"; + var [] = 0; +})() + diff --git a/js/src/jit-test/tests/parser/bug-1263355-22.js b/js/src/jit-test/tests/parser/bug-1263355-22.js new file mode 100644 index 000000000..c64ef0a78 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-22.js @@ -0,0 +1,16 @@ +// |jit-test| error: ReferenceError + +// Adapted from randomly chosen test: js/src/jit-test/tests/debug/Frame-onPop-error-scope-unwind-02.js +var g = newGlobal(); +var dbg = new Debugger(g); +dbg.onEnterFrame = function(f) { + (f.environment.getVariable("e") == 0); +}; +g.eval("" + function f() { + try { + throw 42; + } catch (e) { + noSuchFn(e); + } +}); +g.eval("f();"); diff --git a/js/src/jit-test/tests/parser/bug-1263355-23.js b/js/src/jit-test/tests/parser/bug-1263355-23.js new file mode 100644 index 000000000..690a6c728 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-23.js @@ -0,0 +1,7 @@ +let m = parseModule(` + const root = newGlobal(); + minorgc(); + root.eval(); +`); +m.declarationInstantiation(); +m.evaluation(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-24.js b/js/src/jit-test/tests/parser/bug-1263355-24.js new file mode 100644 index 000000000..0c33ec353 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-24.js @@ -0,0 +1,3 @@ +function TestFunction_4(get, b, [] = status, d, e) { + var arguments = "FAIL"; +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-25.js b/js/src/jit-test/tests/parser/bug-1263355-25.js new file mode 100644 index 000000000..0775dc88e --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-25.js @@ -0,0 +1,22 @@ +// |jit-test| error: TypeError + +var lfLogBuffer = ` +function testcase( [] = (function() { return x++; }), get, target, ... f1) { + return function () { + } ( ... 2 || (this) ? (yield) : (yield)) ; + } +`; +lfLogBuffer = lfLogBuffer.split('\n'); +var lfCodeBuffer = ""; +while (true) { + var line = lfLogBuffer.shift(); + if (line == null) { + break; + } else { + lfCodeBuffer += line + "\n"; + } +} +if (lfCodeBuffer) loadFile(lfCodeBuffer); +function loadFile(lfVarx) { + eval(lfVarx); +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-26.js b/js/src/jit-test/tests/parser/bug-1263355-26.js new file mode 100644 index 000000000..a3c09459a --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-26.js @@ -0,0 +1,7 @@ +// |jit-test| error: TypeError + +function test(a, b, c, d, e, {} = "zmi") { + var r = 0 + r += Math.min(a, b, c, r.script.getLineOffsets(g.line0 + 3), e); +} +test(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-27.js b/js/src/jit-test/tests/parser/bug-1263355-27.js new file mode 100644 index 000000000..ba334a3eb --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-27.js @@ -0,0 +1,5 @@ +// |jit-test| error: ReferenceError + +load(libdir + "evalInFrame.js"); +evalInFrame(1, "a = 43"); +let a = 42; diff --git a/js/src/jit-test/tests/parser/bug-1263355-28.js b/js/src/jit-test/tests/parser/bug-1263355-28.js new file mode 100644 index 000000000..88c7b0653 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-28.js @@ -0,0 +1,3 @@ +for (var i = 0; i < 1; i++) { + L: break; +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-29.js b/js/src/jit-test/tests/parser/bug-1263355-29.js new file mode 100644 index 000000000..ace3e5faa --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-29.js @@ -0,0 +1,6 @@ +// |jit-test| error: ReferenceError + +{ + for (var x = 0; i < 100; i++) a >>= i + let i = 1; +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-3.js b/js/src/jit-test/tests/parser/bug-1263355-3.js new file mode 100644 index 000000000..00a1cef38 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-3.js @@ -0,0 +1,4 @@ +// |jit-test| error: ReferenceError + +f = ([a = class b extends b {}, b] = [void 0]) => {}; +f() diff --git a/js/src/jit-test/tests/parser/bug-1263355-30.js b/js/src/jit-test/tests/parser/bug-1263355-30.js new file mode 100644 index 000000000..437c75cdb --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-30.js @@ -0,0 +1,19 @@ +// |jit-test| error: ReferenceError + +var g = newGlobal("same-compartment"); +var dbg = new Debugger; +g.toggle = function toggle(d) { + if (d) { + dbg.addDebuggee(g); + frame1.onPop = function() { + onPopExecuted = setJitCompilerOption('offthread-compilation.enable', 0) >> toggle('#2: x = null; x ^= true; x === 1. Actual: ' + (getObjectMetadata)) + (this); + }; + } +}; +g.eval("" + function f(d) { + toggle(d); +}); +g.eval("(" + function test() { + for (var i = 0; i < 5; i++) f(false); + f(true); +} + ")();"); diff --git a/js/src/jit-test/tests/parser/bug-1263355-31.js b/js/src/jit-test/tests/parser/bug-1263355-31.js new file mode 100644 index 000000000..2ffe295d0 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-31.js @@ -0,0 +1,6 @@ +try { + eval('"use strict"; var x = "a\\4";'); +} catch (e) { + var e = ''; + let arguments; +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-32.js b/js/src/jit-test/tests/parser/bug-1263355-32.js new file mode 100644 index 000000000..db31a6b12 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-32.js @@ -0,0 +1,4 @@ +// |jit-test| error: ReferenceError + +f = ([a = class target extends b {}, b] = [void 0]) => {}; +f() diff --git a/js/src/jit-test/tests/parser/bug-1263355-33.js b/js/src/jit-test/tests/parser/bug-1263355-33.js new file mode 100644 index 000000000..e1732de59 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-33.js @@ -0,0 +1,22 @@ +// |jit-test| error: InternalError + +var lfLogBuffer = ` +if (lfCodeBuffer) loadFile(lfCodeBuffer); +function loadFile(await ) { + eval(lfVarx); +} +`; +lfLogBuffer = lfLogBuffer.split('\n'); +var lfCodeBuffer = ""; +while (true) { + var line = lfLogBuffer.shift(); + if (line == null) { + break; + } else { + lfCodeBuffer += line + "\n"; + } +} +if (lfCodeBuffer) loadFile(lfCodeBuffer); +function loadFile(lfVarx) { + eval(lfVarx); +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-34.js b/js/src/jit-test/tests/parser/bug-1263355-34.js new file mode 100644 index 000000000..975c6d33d --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-34.js @@ -0,0 +1,4 @@ +eval(` +var of; +let expect =false , assertEq; +`); diff --git a/js/src/jit-test/tests/parser/bug-1263355-35.js b/js/src/jit-test/tests/parser/bug-1263355-35.js new file mode 100644 index 000000000..1bb5f44dd --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-35.js @@ -0,0 +1,7 @@ +function f({get +} = (0), y) { + var stack = getBacktrace({ + args: true, + }); +} +f(1, 2); diff --git a/js/src/jit-test/tests/parser/bug-1263355-36.js b/js/src/jit-test/tests/parser/bug-1263355-36.js new file mode 100644 index 000000000..b6d07c3ce --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-36.js @@ -0,0 +1,9 @@ +// |jit-test| error: ReferenceError + +(function f() { + let x = (new function() { + x(() => { + f.ArrayType(1, 2); + }, "first argument of ctypes.cast must be a CData"); + }) +})(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-37.js b/js/src/jit-test/tests/parser/bug-1263355-37.js new file mode 100644 index 000000000..c9829c01e --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-37.js @@ -0,0 +1,7 @@ +// |jit-test| error: ReferenceError + +{ + while (x && 0) + if (!((x = 1) === x)) {} + let x = () => sym() +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-38.js b/js/src/jit-test/tests/parser/bug-1263355-38.js new file mode 100644 index 000000000..4a4264276 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-38.js @@ -0,0 +1,9 @@ +// |jit-test| error: SyntaxError + +function crashMe2(n) { + var nasty = [], + fn + while (n--) nasty[n] = "a" + 1234567890 + fn = Function(nasty.join(), "void 0") +} +crashMe2(0x10000); diff --git a/js/src/jit-test/tests/parser/bug-1263355-39.js b/js/src/jit-test/tests/parser/bug-1263355-39.js new file mode 100644 index 000000000..85d0f8aae --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-39.js @@ -0,0 +1,8 @@ +function f() { + var init, first; + for (let i = (init = () => i = 1, 0); (first = () => i, i) < 0; ++i); + assertEq(init(), 1); + assertEq(first(), 0); +} + +f(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-4.js b/js/src/jit-test/tests/parser/bug-1263355-4.js new file mode 100644 index 000000000..f2b855f7d --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-4.js @@ -0,0 +1,2 @@ +function f(a = (eval("var b"))) {} +f() diff --git a/js/src/jit-test/tests/parser/bug-1263355-40.js b/js/src/jit-test/tests/parser/bug-1263355-40.js new file mode 100644 index 000000000..0142054d4 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-40.js @@ -0,0 +1,5 @@ + + +function test(get, [] = Bool16x8(...w), ...of) { + var f; +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-41.js b/js/src/jit-test/tests/parser/bug-1263355-41.js new file mode 100644 index 000000000..6c7905417 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-41.js @@ -0,0 +1,5 @@ +for (var i = 0; i < 200; i++) { + (function* get(undefined, ...get) { + g.apply(this, arguments); + })(); +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-42.js b/js/src/jit-test/tests/parser/bug-1263355-42.js new file mode 100644 index 000000000..b874006a4 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-42.js @@ -0,0 +1,11 @@ +// |jit-test| error: ReferenceError + +function f() { + switch (2) { + case 1: + x = 1; + case (x, 2): + let x; + } +} +f(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-43.js b/js/src/jit-test/tests/parser/bug-1263355-43.js new file mode 100644 index 000000000..8605108ac --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-43.js @@ -0,0 +1,4 @@ +// |jit-test| error: ReferenceError + +function f(a = x, x = x) {} +f(/y/) diff --git a/js/src/jit-test/tests/parser/bug-1263355-44.js b/js/src/jit-test/tests/parser/bug-1263355-44.js new file mode 100644 index 000000000..122123be8 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-44.js @@ -0,0 +1,9 @@ +if (!('oomTest' in this)) + quit(); + +// Adapted from randomly chosen test: js/src/jit-test/tests/profiler/bug1231925.js +"use strict"; +enableSPSProfiling(); +oomTest(function() { + eval("(function() {})()"); +}); diff --git a/js/src/jit-test/tests/parser/bug-1263355-45.js b/js/src/jit-test/tests/parser/bug-1263355-45.js new file mode 100644 index 000000000..968c59566 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-45.js @@ -0,0 +1,8 @@ +// |jit-test| error: ReferenceError + +gczeal(4, 10); +f = ([a = class target extends b {}, b] = [void 0]) => { + class dbg {} + class get {} +}; +f() diff --git a/js/src/jit-test/tests/parser/bug-1263355-46.js b/js/src/jit-test/tests/parser/bug-1263355-46.js new file mode 100644 index 000000000..e5c3ec1db --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-46.js @@ -0,0 +1,23 @@ +setJitCompilerOption("ion.warmup.trigger", 4); +var lfLogBuffer = ` +function logProxy(object = {}, handler = {}) { + var log = []; + var proxy = new WeakMap(object, new Proxy(handler, { + get(proto) { + log.push(propertyKey); + } + })); +} +var {proxy, log} = logProxy(); +`; +loadFile(lfLogBuffer); +loadFile(lfLogBuffer); +loadFile(lfLogBuffer); +function loadFile(lfVarx) { + try { + function newFunc(x) { + new Function(x)(); + }; + newFunc(lfVarx); + } catch (lfVare) {} +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-47.js b/js/src/jit-test/tests/parser/bug-1263355-47.js new file mode 100644 index 000000000..da6575e3f --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-47.js @@ -0,0 +1,6 @@ + +for (let x = 0; x < 4; ++x) { + (function() { + for (var set = 0, get, get; eval("\tvar\tx\t=\t1\t");) {} + })() +}; diff --git a/js/src/jit-test/tests/parser/bug-1263355-48.js b/js/src/jit-test/tests/parser/bug-1263355-48.js new file mode 100644 index 000000000..2345b422e --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-48.js @@ -0,0 +1,18 @@ +if (helperThreadCount() == 0) + quit(); + +function eval(source) { + offThreadCompileModule(source); + let m = finishOffThreadModule(); + m.declarationInstantiation(); + return m.evaluation(); +} +function runTestCase(testcase) { + if (testcase() !== true) {} +} +eval(` + function testcase() { + function set () {} + } + runTestCase(testcase); +`); diff --git a/js/src/jit-test/tests/parser/bug-1263355-49.js b/js/src/jit-test/tests/parser/bug-1263355-49.js new file mode 100644 index 000000000..e5fad3532 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-49.js @@ -0,0 +1,4 @@ +load(libdir + "iteration.js"); +function* f4(get = [1], f2, ...each) {} +it = f4(); +assertIteratorResult(it.return(2), 2, true); diff --git a/js/src/jit-test/tests/parser/bug-1263355-5.js b/js/src/jit-test/tests/parser/bug-1263355-5.js new file mode 100644 index 000000000..89fff8ea0 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-5.js @@ -0,0 +1,3 @@ +// |jit-test| error: ReferenceError + +new class extends Object { constructor(a = (()=>{delete super[super()]})()) { } } diff --git a/js/src/jit-test/tests/parser/bug-1263355-50.js b/js/src/jit-test/tests/parser/bug-1263355-50.js new file mode 100644 index 000000000..0416249ec --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-50.js @@ -0,0 +1,4 @@ +// |jit-test| error: TypeError + +function* of([d] = eval("var MYVAR=new String('0Xf');++MYVAR"), ...get) { var x = 42;} +of(); diff --git a/js/src/jit-test/tests/parser/bug-1263355-51.js b/js/src/jit-test/tests/parser/bug-1263355-51.js new file mode 100644 index 000000000..b2bdb680d --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-51.js @@ -0,0 +1,9 @@ +// TDZ checks work in destructuring default expressions, +// even after the variables are initialized the first time. + +load(libdir + "asserts.js"); + +assertThrowsInstanceOf(() => { + // should throw the second time through: b is uninitialized + for (const {a=b, b} of [{a:1, b:2}, {b:3}]) {} +}, ReferenceError); diff --git a/js/src/jit-test/tests/parser/bug-1263355-52.js b/js/src/jit-test/tests/parser/bug-1263355-52.js new file mode 100644 index 000000000..0b0cb4fa2 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-52.js @@ -0,0 +1,11 @@ +// |jit-test| error: ReferenceError + +(function() { + if ({}) {} + else if (x) {} + else {} + + return "" + x; + + let x; +})() diff --git a/js/src/jit-test/tests/parser/bug-1263355-6.js b/js/src/jit-test/tests/parser/bug-1263355-6.js new file mode 100644 index 000000000..4297e33fb --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-6.js @@ -0,0 +1,3 @@ +// |jit-test| error: TypeError + +(new class extends Array {constructor(a=()=>eval("super()")){ var f = ()=>super(); f() }})(0) diff --git a/js/src/jit-test/tests/parser/bug-1263355-7.js b/js/src/jit-test/tests/parser/bug-1263355-7.js new file mode 100644 index 000000000..b45f1a97a --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-7.js @@ -0,0 +1,5 @@ +// |jit-test| error: ReferenceError + +let a; +for(let {a = new class extends Array { constructor(){super(a)} }} of [[]]) { +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-8.js b/js/src/jit-test/tests/parser/bug-1263355-8.js new file mode 100644 index 000000000..c6d01da9e --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-8.js @@ -0,0 +1,5 @@ +// |jit-test| error: ReferenceError + +let a; +for(let {a = new class extends Array { constructor(){super[a]} }} of [[]]) { +} diff --git a/js/src/jit-test/tests/parser/bug-1263355-9.js b/js/src/jit-test/tests/parser/bug-1263355-9.js new file mode 100644 index 000000000..80e991eb0 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263355-9.js @@ -0,0 +1,5 @@ +// |jit-test| error: ReferenceError + +let a; +for(let {a = new class extends Array { constructor(b = (a = eval("()=>super()"))){} }} of [[]]) { +} diff --git a/js/src/jit-test/tests/parser/bug-1263881-1.js b/js/src/jit-test/tests/parser/bug-1263881-1.js new file mode 100644 index 000000000..5b9cf622c --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263881-1.js @@ -0,0 +1,10 @@ +let moduleRepo = {}; +setModuleResolveHook(function(module, specifier) { + return moduleRepo[specifier]; +}); +moduleRepo['a'] = parseModule("export let a = 1;"); +let s = ""; +let max = 65536; +for (let i = 0; i < max; i++) + s += "import * as ns" + i + " from 'a';\n"; +parseModule(s); diff --git a/js/src/jit-test/tests/parser/bug-1263881-2.js b/js/src/jit-test/tests/parser/bug-1263881-2.js new file mode 100644 index 000000000..06c304908 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263881-2.js @@ -0,0 +1,5 @@ +let s = ""; +let max = 65536; +for (let i = 0; i < max; i++) + s += "let ns" + i + " = "+ i +";\n"; +eval(s); diff --git a/js/src/jit-test/tests/parser/bug-1263881-3.js b/js/src/jit-test/tests/parser/bug-1263881-3.js new file mode 100644 index 000000000..4d3573b6c --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1263881-3.js @@ -0,0 +1,6 @@ +let s = "function foo() {\n"; +let max = 65536; +for (let i = 0; i < max; i++) + s += "let ns" + i + " = "+ i +";\n"; +s += "};"; +eval(s); diff --git a/js/src/jit-test/tests/parser/bug-1264568.js b/js/src/jit-test/tests/parser/bug-1264568.js new file mode 100644 index 000000000..086a04aa9 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1264568.js @@ -0,0 +1,6 @@ +// |jit-test| error: SyntaxError +f = (function(stdlib, foreign, heap) { + "use asm"; + ({ "0" + () + { eval } diff --git a/js/src/jit-test/tests/parser/bug-1298809.js b/js/src/jit-test/tests/parser/bug-1298809.js new file mode 100644 index 000000000..b93c7b083 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1298809.js @@ -0,0 +1,6 @@ +function f() { + if (0) + function g() x; + else; +} +f(); diff --git a/js/src/jit-test/tests/parser/bug-1316832.js b/js/src/jit-test/tests/parser/bug-1316832.js new file mode 100644 index 000000000..8b299dd00 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1316832.js @@ -0,0 +1,10 @@ + +(function(x, x) { + eval(` + var y = 1; + function f() { + return delete y; + } + f(); + `); +})() diff --git a/js/src/jit-test/tests/parser/bug-1324773-2.js b/js/src/jit-test/tests/parser/bug-1324773-2.js new file mode 100644 index 000000000..151023223 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1324773-2.js @@ -0,0 +1,15 @@ +if (!('gczeal' in this)) + quit(); +var lfGlobal = newGlobal(); +lfGlobal.evaluate(` + for (var i = 0; i < 600; i++) + eval('function f' + i + '() {}'); +`); +var lfGlobal = newGlobal(); +lfGlobal.evaluate(` + if (!('gczeal' in this)) + quit(); + var dbg = new Debugger(); + gczeal(9, 10); + dbg.findScripts({}); +`); diff --git a/js/src/jit-test/tests/parser/bug-1324773.js b/js/src/jit-test/tests/parser/bug-1324773.js new file mode 100644 index 000000000..95248c023 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-1324773.js @@ -0,0 +1,15 @@ +if (!('gczeal' in this)) + quit(); +var lfGlobal = newGlobal(); +lfGlobal.evaluate(` + for (var i = 0; i < 600; i++) + eval('function f' + i + '() {}'); +`); +var lfGlobal = newGlobal(); +lfGlobal.evaluate(` + if (!('gczeal' in this)) + quit(); + var dbg = new Debugger(); + gczeal(9, 1); + dbg.findScripts({}); +`); diff --git a/js/src/jit-test/tests/parser/bug-844805-1.js b/js/src/jit-test/tests/parser/bug-844805-1.js new file mode 100644 index 000000000..b6bad2105 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-844805-1.js @@ -0,0 +1 @@ +if (Math["key"]) {} diff --git a/js/src/jit-test/tests/parser/bug-844805-2.js b/js/src/jit-test/tests/parser/bug-844805-2.js new file mode 100644 index 000000000..5a278ef9b --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-844805-2.js @@ -0,0 +1,10 @@ +// Constant folding does not affect strict delete. + +function f(x) { + "use strict"; + + // This senseless delete-expression is legal even in strict mode. Per ES5.1 + // 11.4.1 step 2, it does nothing and returns true. + return delete (1 ? x : x); +} +assertEq(f(), true); diff --git a/js/src/jit-test/tests/parser/bug-888002-1.js b/js/src/jit-test/tests/parser/bug-888002-1.js new file mode 100644 index 000000000..44333e0bc --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-888002-1.js @@ -0,0 +1 @@ +Function("var e = delete(false ? e : e)")(); diff --git a/js/src/jit-test/tests/parser/bug-888002-2.js b/js/src/jit-test/tests/parser/bug-888002-2.js new file mode 100644 index 000000000..f0ccfca99 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-888002-2.js @@ -0,0 +1,12 @@ +// Constant folding doesn't affect non-strict delete. + +(function (x) { + // These senseless delete-expressions are legal. Per ES5.1 11.4.1 step 2, + // each one does nothing and returns true. + assertEq(delete (1 ? x : x), true); + assertEq(delete (0 || x), true); + assertEq(delete (1 && x), true); + + // This one is legal too, but returns false. + assertEq(delete x, false); +}()); diff --git a/js/src/jit-test/tests/parser/bug-888002-3.js b/js/src/jit-test/tests/parser/bug-888002-3.js new file mode 100644 index 000000000..964ae2e1b --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-888002-3.js @@ -0,0 +1,18 @@ +// Constant folding doesn't affect strict delete either. +// In particular, it doesn't affect whether |delete x| is a strict error. + +load(libdir + "asserts.js"); + +(function (x) { + "use strict"; + + // These senseless delete-expressions are legal even in strict mode. + // Per ES5.1 11.4.1 step 2, each one does nothing and returns true. + assertEq(delete (1 ? x : x), true); + assertEq(delete (0 || x), true); + assertEq(delete (1 && x), true); + + // Plain `delete x` is a SyntaxError though. + assertThrowsInstanceOf(() => eval('delete x'), SyntaxError); + assertThrowsInstanceOf(() => Function('"use strict"; delete x'), SyntaxError); +}()); diff --git a/js/src/jit-test/tests/parser/bug-888002.js b/js/src/jit-test/tests/parser/bug-888002.js new file mode 100644 index 000000000..44333e0bc --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-888002.js @@ -0,0 +1 @@ +Function("var e = delete(false ? e : e)")(); diff --git a/js/src/jit-test/tests/parser/bug-889628.js b/js/src/jit-test/tests/parser/bug-889628.js new file mode 100644 index 000000000..bb337c35d --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-889628.js @@ -0,0 +1,33 @@ +// Destructuring assignment to eval or arguments in destructuring is a SyntaxError +// in strict mode + +load(libdir + "asserts.js"); + +var patterns = [ + "[_]", + "[a, b, _]", + "[[_]]", + "[[], [{}, [_]]]", + "{x:_}", + "{x:y, z:_}", + "{0:_}", + "{_}", + "[..._]" +]; + +for (var pattern of patterns) { + var stmt = pattern + " = obj"; + if (stmt[0] == "{") + stmt = "(" + stmt + ")"; + stmt += ";" + + // stmt is a legal statement... + Function(stmt); + + // ...but not if you replace _ with one of these two names. + for (var name of ["eval", "arguments"]) { + var s = stmt.replace("_", name); + Function(s); + assertThrowsInstanceOf(() => Function("'use strict'; " + s), SyntaxError); + } +} diff --git a/js/src/jit-test/tests/parser/bug-896126.js b/js/src/jit-test/tests/parser/bug-896126.js new file mode 100644 index 000000000..334ea33b9 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-896126.js @@ -0,0 +1,11 @@ +// |jit-test| error: SyntaxError +({ + r: function() { + function f() { + w[0xe56241c6 >> 3] + } + }, + s: function() { + "use asm" + return (1 for + diff --git a/js/src/jit-test/tests/parser/bug-975484.js b/js/src/jit-test/tests/parser/bug-975484.js new file mode 100644 index 000000000..b16449224 --- /dev/null +++ b/js/src/jit-test/tests/parser/bug-975484.js @@ -0,0 +1,7 @@ +var loc = Reflect.parse("f()").body[0].expression.loc; +assertEq(loc.start.column, 0); +assertEq(loc.end.column, 3); + +loc = Reflect.parse("f(x)").body[0].expression.loc; +assertEq(loc.start.column, 0); +assertEq(loc.end.column, 4); diff --git a/js/src/jit-test/tests/parser/columnNumber.js b/js/src/jit-test/tests/parser/columnNumber.js new file mode 100644 index 000000000..ce29db33c --- /dev/null +++ b/js/src/jit-test/tests/parser/columnNumber.js @@ -0,0 +1,45 @@ +// Simple tests for evaluate's "columnNumber" option. + +load(libdir + 'asserts.js'); + +assertEq(evaluate("saveStack().column"), 1); +assertEq(evaluate("saveStack().column", { columnNumber: 1729 }), 1730); +assertEq(evaluate("\nsaveStack().column", { columnNumber: 1729 }), 1); +assertEq(evaluate("saveStack().column", { columnNumber: "42" }), 43); +assertThrowsInstanceOf(() => evaluate("saveStack().column", { columnNumber: -10 }), + RangeError); +assertThrowsInstanceOf(() => evaluate("saveStack().column", { columnNumber: Math.pow(2,30) }), + RangeError); + +if (helperThreadCount() > 0) { + print("offThreadCompileScript 1"); + offThreadCompileScript("saveStack().column", { columnNumber: -10 }); + assertThrowsInstanceOf(runOffThreadScript, RangeError); + + print("offThreadCompileScript 2"); + offThreadCompileScript("saveStack().column", { columnNumber: Math.pow(2,30) }); + assertThrowsInstanceOf(runOffThreadScript, RangeError); + + print("offThreadCompileScript 3"); + offThreadCompileScript("saveStack().column", { columnNumber: 10000 }); + assertEq(runOffThreadScript(), 10001); +} + +// Check handling of columns near the limit of our ability to represent them. +// (This is hardly thorough, but since web content can't set column numbers, +// it's probably not worth it to be thorough.) +const maxColumn = Math.pow(2, 30) - 1; +assertEq(evaluate("saveStack().column", { columnNumber: maxColumn }), + maxColumn + 1); + +// Check the 'silently zero' behavior when we reach the limit of the srcnotes +// column encoding. +assertEq(evaluate(" saveStack().column", { columnNumber: maxColumn }), + 1); + +// Gathering source text for inclusion in error messages should not try to reach +// outside the buffer to find the start of the source line. The below should +// report the error without crashing. +assertThrowsInstanceOf(() => evaluate("function x(y,y) { 'use strict'; } x()", + { columnNumber: 10 }), + SyntaxError); diff --git a/js/src/jit-test/tests/parser/expr-closure-warn.js b/js/src/jit-test/tests/parser/expr-closure-warn.js new file mode 100644 index 000000000..faadd8eb6 --- /dev/null +++ b/js/src/jit-test/tests/parser/expr-closure-warn.js @@ -0,0 +1,63 @@ +// Expression closure should be warned once and only once. + +var release_or_beta = getBuildConfiguration().release_or_beta; + +function testWarn(code) { + if (release_or_beta) { + // Warning for expression closure is non-release-only (not Release/Beta). + testPass(code); + return; + } + + enableLastWarning(); + var g = newGlobal(); + g.code = code; + g.eval('eval(code)'); + var warning = getLastWarning(); + assertEq(warning !== null, true, "warning should be caught for " + code); + assertEq(warning.name, "Warning"); + + clearLastWarning(); + g.eval('eval(code)'); + warning = getLastWarning(); + assertEq(warning, null, "warning should not be caught for 2nd ocurrence"); + + clearLastWarning(); + g = newGlobal(); + g.code = code; + g.eval('Reflect.parse(code);'); + warning = getLastWarning(); + assertEq(warning !== null, true, "warning should be caught for " + code); + assertEq(warning.name, "Warning"); + + clearLastWarning(); + g.eval('Reflect.parse(code);'); + warning = getLastWarning(); + assertEq(warning, null, "warning should not be caught for 2nd ocurrence"); + disableLastWarning(); +} + +function testPass(code) { + enableLastWarning(); + var g = newGlobal(); + g.code = code; + g.eval('eval(code)'); + var warning = getLastWarning(); + assertEq(warning, null, "warning should not be caught for " + code); + + clearLastWarning(); + g = newGlobal(); + g.code = code; + g.eval('Reflect.parse(code);'); + warning = getLastWarning(); + assertEq(warning, null, "warning should not be caught for " + code); + disableLastWarning(); +} + +testWarn("function f() 1"); +testWarn("(function() 1)"); +testWarn("({ get x() 1 })"); +testWarn("({ set x(v) 1 })"); + +testPass("function f() { 1 }"); +testPass("() => 1"); diff --git a/js/src/jit-test/tests/parser/for-each-warn.js b/js/src/jit-test/tests/parser/for-each-warn.js new file mode 100644 index 000000000..2b20c6174 --- /dev/null +++ b/js/src/jit-test/tests/parser/for-each-warn.js @@ -0,0 +1,36 @@ +// for-each should be warned once and only once. + +function testWarn(code) { + enableLastWarning(); + var g = newGlobal(); + g.code = code; + g.eval('eval(code)'); + var warning = getLastWarning(); + assertEq(warning !== null, true, "warning should be caught for " + code); + assertEq(warning.name, "Warning"); + + clearLastWarning(); + g.eval('eval(code)'); + warning = getLastWarning(); + assertEq(warning, null, "warning should not be caught for 2nd ocurrence"); + + clearLastWarning(); + g = newGlobal(); + g.code = code; + g.eval('Reflect.parse(code);'); + warning = getLastWarning(); + assertEq(warning !== null, true, "warning should be caught for " + code); + assertEq(warning.name, "Warning"); + + clearLastWarning(); + g.eval('Reflect.parse(code);'); + warning = getLastWarning(); + assertEq(warning, null, "warning should not be caught for 2nd ocurrence"); + disableLastWarning(); +} + +testWarn("for each (var x in {}) {}"); +testWarn("for each (x in {}) {}"); +testWarn("for each (let y in {}) {}"); +testWarn("for each (const y in {}) {}"); +testWarn("for each ([x, y] in {}) {}"); diff --git a/js/src/jit-test/tests/parser/home-object-getter.js b/js/src/jit-test/tests/parser/home-object-getter.js new file mode 100644 index 000000000..d4ee62acc --- /dev/null +++ b/js/src/jit-test/tests/parser/home-object-getter.js @@ -0,0 +1,4 @@ +var o = {get a() { + return eval("5"); +}} +assertEq(o.a, 5); diff --git a/js/src/jit-test/tests/parser/lazy-parse-bad-offset.js b/js/src/jit-test/tests/parser/lazy-parse-bad-offset.js new file mode 100644 index 000000000..4b4ef1ba9 --- /dev/null +++ b/js/src/jit-test/tests/parser/lazy-parse-bad-offset.js @@ -0,0 +1,5 @@ +// Bug 1098132: Shouldn't assert. + +options('strict'); +function eval() {}; +eval(); diff --git a/js/src/jit-test/tests/parser/let-after-directive.js b/js/src/jit-test/tests/parser/let-after-directive.js new file mode 100644 index 000000000..58864ab34 --- /dev/null +++ b/js/src/jit-test/tests/parser/let-after-directive.js @@ -0,0 +1,6 @@ +// 'let' after "use strict" directive without semicolon is lexed as TOK_NAME +// before parsing the directive. 'let' with TOK_NAME should be handled +// correctly in strict mode. + +"use strict" +let a = 1; diff --git a/js/src/jit-test/tests/parser/letContextualKeyword.js b/js/src/jit-test/tests/parser/letContextualKeyword.js new file mode 100644 index 000000000..8bccfacf0 --- /dev/null +++ b/js/src/jit-test/tests/parser/letContextualKeyword.js @@ -0,0 +1,110 @@ +function expectError(str) { + var log = ""; + try { + eval(str); + } catch (e) { + log += "e"; + assertEq(e instanceof SyntaxError, true); + } + assertEq(log, "e"); +} + +eval(`let x = 42; assertEq(x, 42);`); +eval(`var let = 42; assertEq(let, 42);`); +eval(`let;`); +eval(`[...let] = [];`); +eval(`function let() { return 42; } assertEq(let(), 42);`) +eval(`let {x:x} = {x:42}; assertEq(x, 42);`); +eval(`let [x] = [42]; assertEq(x, 42);`); + +eval(`for (let x in [1]) { assertEq(x, "0"); }`); +eval(`for (const x in [1]) { assertEq(x, "0"); }`); + +eval(`for (let x of [1]) { assertEq(x, 1); }`); +eval(`for (const x of [1]) { assertEq(x, 1); }`); + +eval(`for (let i = 0; i < 1; i++) { assertEq(i, 0); }`); +eval(`var done = false; for (const i = 0; !done; done = true) { assertEq(i, 0); }`); + +eval(`for (let of of [1]) { assertEq(of, 1); }`); +eval(`for (const of of [1]) { assertEq(of, 1); }`); + +eval(`try { throw 17; } catch (let) { assertEq(let, 17); }`); +eval(`try { throw [17]; } catch ([let]) { assertEq(let, 17); }`); +eval(`try { throw { x: 17 }; } catch ({ x: let }) { assertEq(let, 17); }`); +eval(`try { throw {}; } catch ({ x: let = 17 }) { assertEq(let, 17); }`); + +expectError(`try { throw [17, 42]; } catch ([let, let]) {}`); + +eval(`for (let in [1]) { assertEq(let, "0"); }`); +eval(`for (let / 1; ; ) { break; }`); +expectError(`let = {}; for (let.x of;;);`); +expectError(`for (let of [1]) { }`); + +expectError(`for (let let in [1]) { }`); +expectError(`for (const let in [1]) { }`); + +expectError(`for (let let of [1]) { }`); +expectError(`for (const let of [1]) { }`); + +expectError(`for (let let = 17; false; ) { }`); +expectError(`for (const let = 17; false; ) { }`); + +expectError(`for (let [let] = 17; false; ) { }`); +expectError(`for (const [let] = 17; false; ) { }`); + +expectError(`for (let [let = 42] = 17; false; ) { }`); +expectError(`for (const [let = 42] = 17; false; ) { }`); + +expectError(`for (let { x: let } = 17; false; ) { }`); +expectError(`for (const { x: let } = 17; false; ) { }`); + +expectError(`for (let { x: let = 42 } = 17; false; ) { }`); +expectError(`for (const { x: let = 42 } = 17; false; ) { }`); + +expectError("let\nlet;"); +expectError("const\nlet;"); + +expectError(`let let = 17;`); +expectError(`const let = 17;`); + +expectError(`let [let] = 17;`); +expectError(`const [let] = 17;`); + +expectError(`let [let = 42] = 17;`); +expectError(`const [let = 42] = 17;`); + +expectError(`let {let} = 17;`); +expectError(`const {let} = 17;`); + +expectError(`let { let = 42 } = 17;`); +expectError(`const { let = 42 } = 17;`); + +expectError(`let { x: let } = 17;`); +expectError(`const { x: let } = 17;`); + +expectError(`let { x: let = 42 } = 17;`); +expectError(`const { x: let = 42 } = 17;`); + +expectError(`let { ['y']: let } = 17;`); +expectError(`const { ['y']: let } = 17;`); + +expectError(`let { ['y']: let = 42 } = 17;`); +expectError(`const { ['y']: let = 42 } = 17;`); + +expectError(`let { x: [let] } = { x: 17 };`); +expectError(`const { x: [let] } = { x: 17 };`); + +expectError(`let { x: [let = 42] } = { x: 17 };`); +expectError(`const { x: [let = 42] } = { x: 17 };`); + +expectError(`let [foo, let] = 42;`); +expectError(`const [foo, let] = 42;`); + +expectError(`let [foo, { let }] = [17, {}];`); +expectError(`const [foo, { let }] = [17, {}];`); + +expectError(`"use strict"; var let = 42;`); +expectError(`"use strict"; function let() {}`); +expectError(`"use strict"; for (let of [1]) {}`); +expectError(`"use strict"; try {} catch (let) {}`); diff --git a/js/src/jit-test/tests/parser/modifier-arrow-rest.js b/js/src/jit-test/tests/parser/modifier-arrow-rest.js new file mode 100644 index 000000000..e66aa5c37 --- /dev/null +++ b/js/src/jit-test/tests/parser/modifier-arrow-rest.js @@ -0,0 +1,11 @@ +load(libdir + "syntax.js"); + +var postfixes = [ + "...foo) => 1 @", +]; + +function check_syntax_error(e, code) { + assertEq(e instanceof SyntaxError, true); +} + +test_syntax(postfixes, check_syntax_error, true); diff --git a/js/src/jit-test/tests/parser/modifier-do-while.js b/js/src/jit-test/tests/parser/modifier-do-while.js new file mode 100644 index 000000000..9fa9b06df --- /dev/null +++ b/js/src/jit-test/tests/parser/modifier-do-while.js @@ -0,0 +1,12 @@ +do 1 +while(false); + +do if (1) { +} while(false); + +do if (1) 1 +while(false); + +do try { +} catch(ex) { +} while(false); diff --git a/js/src/jit-test/tests/parser/modifier-regexp-vs-div.js b/js/src/jit-test/tests/parser/modifier-regexp-vs-div.js new file mode 100644 index 000000000..7754bcb19 --- /dev/null +++ b/js/src/jit-test/tests/parser/modifier-regexp-vs-div.js @@ -0,0 +1,12 @@ +load(libdir + "syntax.js"); + +var postfixes = [ + "/bar/g; @", + "\n/bar/g; @", +]; + +function check_syntax_error(e, code) { + assertEq(e instanceof SyntaxError, true); +} + +test_syntax(postfixes, check_syntax_error, true); diff --git a/js/src/jit-test/tests/parser/modifier-semicolon-insertion.js b/js/src/jit-test/tests/parser/modifier-semicolon-insertion.js new file mode 100644 index 000000000..d56b15c47 --- /dev/null +++ b/js/src/jit-test/tests/parser/modifier-semicolon-insertion.js @@ -0,0 +1,52 @@ +Reflect.parse(` +function a()f1() +f2() +`); +Reflect.parse(` +let a +f2() +`); +Reflect.parse(` +let a=1 +f2() +`); +Reflect.parse(` +import 'a' +f2() +`, {target: "module"}); +Reflect.parse(` +export { a } from 'a' +f2() +`, {target: "module"}); +Reflect.parse(` +var a +f2() +`); +Reflect.parse(` +var a=1 +f2() +`); +Reflect.parse(` +f1() +f2() +`); +Reflect.parse(` +while(false) { continue +f2() } +`); +Reflect.parse(` +while(false) { break +f2() } +`); +Reflect.parse(` +function a() { return +f2() } +`); +Reflect.parse(` +throw 1 +f2() +`); +Reflect.parse(` +debugger +f2() +`); diff --git a/js/src/jit-test/tests/parser/modifier-yield-without-operand-1.js b/js/src/jit-test/tests/parser/modifier-yield-without-operand-1.js new file mode 100644 index 000000000..635acbe32 --- /dev/null +++ b/js/src/jit-test/tests/parser/modifier-yield-without-operand-1.js @@ -0,0 +1,12 @@ +load(libdir + "syntax.js"); + +var postfixes = [ + "yield, @", + "yield; @", +]; + +function check_syntax_error(e, code) { + // No need to check exception type +} + +test_syntax(postfixes, check_syntax_error, true); diff --git a/js/src/jit-test/tests/parser/modifier-yield-without-operand-2.js b/js/src/jit-test/tests/parser/modifier-yield-without-operand-2.js new file mode 100644 index 000000000..2b7a8dded --- /dev/null +++ b/js/src/jit-test/tests/parser/modifier-yield-without-operand-2.js @@ -0,0 +1,13 @@ +load(libdir + "syntax.js"); + +var postfixes = [ + "yield) @", + "yield} @", + "yield] @", +]; + +function check_syntax_error(e, code) { + // No need to check exception type +} + +test_syntax(postfixes, check_syntax_error, true); diff --git a/js/src/jit-test/tests/parser/regexp-after-do-while.js b/js/src/jit-test/tests/parser/regexp-after-do-while.js new file mode 100644 index 000000000..e94f8ac24 --- /dev/null +++ b/js/src/jit-test/tests/parser/regexp-after-do-while.js @@ -0,0 +1,8 @@ +// RegExp after do-while get parsed. + +load(libdir + "asserts.js"); + +assertNoWarning(() => Function("do {} while (true) \n /bar/g"), SyntaxError, + "RegExp in next line should be parsed"); +assertNoWarning(() => Function("do {} while (true) /bar/g"), SyntaxError, + "RegExp in same line should be parsed"); diff --git a/js/src/jit-test/tests/parser/regexp-after-variable.js b/js/src/jit-test/tests/parser/regexp-after-variable.js new file mode 100644 index 000000000..3ba2206c1 --- /dev/null +++ b/js/src/jit-test/tests/parser/regexp-after-variable.js @@ -0,0 +1,8 @@ +// RegExp after variable name get parsed or throws error correctly. + +load(libdir + "asserts.js"); + +assertNoWarning(() => Function("var foo \n /bar/g"), SyntaxError, + "RegExp in next line should be parsed"); +assertThrowsInstanceOf(() => Function("var foo /bar/g"), SyntaxError, + "RegExp in same line should be error"); diff --git a/js/src/jit-test/tests/parser/syntax-error-illegal-character.js b/js/src/jit-test/tests/parser/syntax-error-illegal-character.js new file mode 100644 index 000000000..b633b6406 --- /dev/null +++ b/js/src/jit-test/tests/parser/syntax-error-illegal-character.js @@ -0,0 +1,14 @@ +load(libdir + "syntax.js"); + +var JSMSG_ILLEGAL_CHARACTER = "illegal character"; + +var postfixes = [ + "@", +]; + +function check_syntax_error(e, code, name) { + assertEq(e instanceof SyntaxError, true, name + ": " + code); + assertEq(e.message, JSMSG_ILLEGAL_CHARACTER, name + ": " + code); +} + +test_syntax(postfixes, check_syntax_error, false); diff --git a/js/src/jit-test/tests/parser/truncation.js b/js/src/jit-test/tests/parser/truncation.js new file mode 100644 index 000000000..3cfc6e37f --- /dev/null +++ b/js/src/jit-test/tests/parser/truncation.js @@ -0,0 +1,73 @@ +load(libdir + "asserts.js"); + +var cases = [ + "{", + "{ ;", + "var", + "var x,", + "var x =", + "let x,", + "let x =", + "const", + "const x =", + "const x = 1,", + "if", + "if (", + "if (0) ; else", + "do", + "do ;", + "do ; while", + "do ; while (", + "do ; while (1", + "while", + "while (", + "while (1", + "while (1)", + "for", + "for (", + "for (;", + "for (;;", + "for (;;)", + "for (var", + "for (x", + "for (x in", + "for (x in y", + "for (x in y)", + "for (x of", + "for (x of y", + "for (x of y)", + "switch", + "switch (", + "switch (x", + "switch (x)", + "with", + "with (", + "with (x", + "with (x)", + "a:", + "throw", + "try", + "try {", + "try {} catch", + "try {} catch (", + "try {} catch (exc", + "try {} catch (exc if", + "try {} catch (exc if 1", + "try {} finally", + "try {} finally {", + + "function", + "function f", + "function f(", + "function f()", + "function f() {", + "(function", + "(function f", + "(function f(", + "(function f()", + +]; + +for (var s of cases) + assertThrowsInstanceOf(() => Function(s), SyntaxError); + diff --git a/js/src/jit-test/tests/parser/yield-in-formal-destructuring.js b/js/src/jit-test/tests/parser/yield-in-formal-destructuring.js new file mode 100644 index 000000000..7c2d2e0f7 --- /dev/null +++ b/js/src/jit-test/tests/parser/yield-in-formal-destructuring.js @@ -0,0 +1,2 @@ +// |jit-test| error: SyntaxError +function d([{ [yield]: {} } ]) f diff --git a/js/src/jit-test/tests/parser/yield-without-operand.js b/js/src/jit-test/tests/parser/yield-without-operand.js new file mode 100644 index 000000000..56f041a73 --- /dev/null +++ b/js/src/jit-test/tests/parser/yield-without-operand.js @@ -0,0 +1,26 @@ +// yield without an operand is fine and dandy. + +load(libdir + "asserts.js"); + +assertNoWarning(() => Function("yield"), SyntaxError, + "yield followed by EOF is fine"); +assertNoWarning(() => Function("yield;"), SyntaxError, + "yield followed by semicolon is fine"); +assertNoWarning(() => Function("yield\n"), SyntaxError, + "yield followed by newline is fine"); +assertNoWarning(() => Function("yield\n print('ok');"), SyntaxError, + "yield followed by newline and statement is fine"); +assertNoWarning(() => Function("yield\n /x/;"), SyntaxError, + "yield followed by newline and regexp is fine"); +assertThrowsInstanceOf(() => Function("yield\n /"), SyntaxError, + "yield followed by newline and slash is fine"); + +assertNoWarning(() => eval("(function () { yield; })"), SyntaxError, + "yield followed by semicolon in eval code is fine"); +assertNoWarning(() => eval("(function () { yield })"), SyntaxError, + "yield followed by } in eval code is fine"); + +assertNoWarning(() => Function("yield 0;"), + "yield with an operand should be fine"); +assertNoWarning(() => Function("yield 0"), + "yield with an operand should be fine, even without a semicolon"); |