diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/non262/arrow-functions | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/arrow-functions')
5 files changed, 280 insertions, 0 deletions
diff --git a/js/src/tests/non262/arrow-functions/arrow-not-as-end-of-statement.js b/js/src/tests/non262/arrow-functions/arrow-not-as-end-of-statement.js new file mode 100644 index 0000000000..53926d65da --- /dev/null +++ b/js/src/tests/non262/arrow-functions/arrow-not-as-end-of-statement.js @@ -0,0 +1,188 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Grab-bag of ArrowFunctions with block bodies appearing in contexts where the +// subsequent token-examination must use the Operand modifier to avoid an +// assertion. + +assertEq(`x ${a => {}} z`, "x a => {} z"); + +for (a => {}; ; ) + break; + +for (; a => {}; ) + break; + +for (; ; a => {}) + break; + +Function.prototype[Symbol.iterator] = function() { return { next() { return { done: true }; } }; }; +for (let m of 0 ? 1 : a => {}) + assertEq(true, false); +for (let [m] of 0 ? 1 : a => {}) + assertEq(true, false); +delete Function.prototype[Symbol.iterator]; + +for (let w in 0 ? 1 : a => {}) + break; +for (let [w] in 0 ? 1 : a => {}) + break; + +function* stargen() +{ + yield a => {} + /Q/g; + + var first = true; + Function.prototype[Symbol.iterator] = function() { + return { + next() { + var res = { done: true, value: 8675309 }; + if (first) + { + res = { value: "fnord", done: false }; + first = false; + } + + return res; + } + }; + }; + + + yield* a => {} + /Q/g; + + delete Function.prototype[Symbol.iterator]; + + yield 99; +} +var gen = stargen(); +assertEq(typeof gen.next().value, "function"); +var result = gen.next(); +assertEq(result.value, "fnord"); +assertEq(result.done, false); +assertEq(gen.next().value, 99); +assertEq(gen.next().done, true); + +switch (1) +{ + case a => {}: + break; +} + +assertEq(0[a => {}], undefined); + +class Y {}; +class X extends Y { constructor() { super[a => {}](); } }; + +if (a => {}) + assertEq(true, true); +else + assertEq(true, false); + +switch (a => {}) +{ +} + +with (a => {}); + +assertEq(typeof (a => {}), "function"); +assertEq(typeof (a => b => {}), "function"); + +for (var x in y => {}) + continue; + +assertEq(eval("a => {}, 17, 42;"), 42); +assertEq(eval("42, a => {}, 17;"), 17); +assertEq(typeof eval("17, 42, a => {};"), "function"); + +assertEq(eval("1 ? 0 : a => {}, 17, 42;"), 42); +assertEq(eval("42, 1 ? 0 : a => {}, 17;"), 17); +assertEq(eval("17, 42, 1 ? 0 : a => {};"), 0); + +var z = { x: 0 ? 1 : async a => {} }; +assertEq(typeof z.x, "function"); + +var q = 0 ? 1 : async () => {}; +assertEq(typeof q, "function"); + +var m = 0 ? 42 : m = foo => {} // ASI +/Q/g; +assertEq(typeof m, "function"); + +var { q: w = 0 ? 1 : a => {} } = {}; +assertEq(typeof w, "function"); + +Function.prototype.c = 42; +var { c } = 0 ? 1 : a => {} // ASI +/Q/g; +assertEq(c, 42); + +var c = 0 ? 1 : a => {} +/Q/g; +assertEq(typeof c, "function"); +delete Function.prototype.c; + +assertEq(typeof eval(0 ? 1 : a => {}), "function"); + +var zoom = 1 ? a => {} : 357; +assertEq(typeof zoom, "function"); + +var { b = 0 ? 1 : a => {} } = {}; +assertEq(typeof b, "function"); + +var [k = 0 ? 1 : a => {}] = []; +assertEq(typeof k, "function"); + +assertEq(typeof [0 ? 1 : a => {}][0], "function"); + +Function.prototype[Symbol.iterator] = function() { return { next() { return { done: true }; } }; }; +assertEq([...0 ? 1 : a => {}].length, 0); +delete Function.prototype[Symbol.iterator]; + +var props = Object.getOwnPropertyNames({ ...0 ? 1 : a => {} }).sort(); +assertEq(props.length, 0); + +function f1(x = 0 ? 1 : a => {}) { return x; } +assertEq(typeof f1(), "function"); +assertEq(f1(5), 5); + +var g1 = (x = 0 ? 1 : a => {}) => { return x; }; +assertEq(typeof g1(), "function"); +assertEq(g1(5), 5); + +var h1 = async (x = 0 ? 1 : a => {}) => { return x; }; +assertEq(typeof h1, "function"); + +function f2(m, x = 0 ? 1 : a => {}) { return x; } +assertEq(typeof f2(1), "function"); +assertEq(f2(1, 5), 5); + +var g2 = (m, x = 0 ? 1 : a => {}) => { return x; }; +assertEq(typeof g2(1), "function"); +assertEq(g2(1, 5), 5); + +var h2 = async (m, x = 0 ? 1 : a => {}) => { return x; }; +assertEq(typeof h2, "function"); + +function f3(x = 0 ? 1 : a => {}, q) { return x; } +assertEq(typeof f3(), "function"); +assertEq(f3(5), 5); + +var g3 = (x = 0 ? 1 : a => {}, q) => { return x; }; +assertEq(typeof g3(), "function"); +assertEq(g3(5), 5); + +var h3 = async (x = 0 ? 1 : a => {}, q) => { return x; }; +assertEq(typeof h3, "function"); + +var asyncf = async () => {}; +assertEq(typeof asyncf, "function"); + +var { [0 ? 1 : a => {}]: h } = { "a => {}": "boo-urns!" }; +assertEq(h, "boo-urns!"); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/arrow-functions/arrow-returning-arrow-with-block-body-followed-by-regexp.js b/js/src/tests/non262/arrow-functions/arrow-returning-arrow-with-block-body-followed-by-regexp.js new file mode 100644 index 0000000000..8a53074e3d --- /dev/null +++ b/js/src/tests/non262/arrow-functions/arrow-returning-arrow-with-block-body-followed-by-regexp.js @@ -0,0 +1,15 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +function t() +{ + var x = y => z => {} // ASI occurs here + /Q/; + return 42; +} + +assertEq(t(), 42); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/arrow-functions/browser.js b/js/src/tests/non262/arrow-functions/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/arrow-functions/browser.js diff --git a/js/src/tests/non262/arrow-functions/shell.js b/js/src/tests/non262/arrow-functions/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/arrow-functions/shell.js diff --git a/js/src/tests/non262/arrow-functions/yield-in-arrow.js b/js/src/tests/non262/arrow-functions/yield-in-arrow.js new file mode 100644 index 0000000000..8b849a1c88 --- /dev/null +++ b/js/src/tests/non262/arrow-functions/yield-in-arrow.js @@ -0,0 +1,77 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const yieldInParameters = [ + `(a = yield) => {}`, + `(a = yield /a/g) => {}`, // Should parse as division, not yield expression with regexp. + `yield => {};`, + `(yield) => {};`, + `(yield = 0) => {};`, + `([yield]) => {};`, + `([yield = 0]) => {};`, + `([...yield]) => {};`, + `({a: yield}) => {};`, + `({yield}) => {};`, + `({yield = 0}) => {};`, +]; + +const yieldInBody = [ + `() => yield;`, + `() => yield /a/g;`, + `() => { var x = yield; }`, + `() => { var x = yield /a/g; }`, + + `() => { var yield; };`, + `() => { var yield = 0; };`, + `() => { var [yield] = []; };`, + `() => { var [yield = 0] = []; };`, + `() => { var [...yield] = []; };`, + `() => { var {a: yield} = {}; };`, + `() => { var {yield} = {}; };`, + `() => { var {yield = 0} = {}; };`, + + `() => { let yield; };`, + `() => { let yield = 0; };`, + `() => { let [yield] = []; };`, + `() => { let [yield = 0] = []; };`, + `() => { let [...yield] = []; };`, + `() => { let {a: yield} = {}; };`, + `() => { let {yield} = {}; };`, + `() => { let {yield = 0} = {}; };`, + + `() => { const yield = 0; };`, + `() => { const [yield] = []; };`, + `() => { const [yield = 0] = []; };`, + `() => { const [...yield] = []; };`, + `() => { const {a: yield} = {}; };`, + `() => { const {yield} = {}; };`, + `() => { const {yield = 0} = {}; };`, +]; + + +// Script context. +for (let test of [...yieldInParameters, ...yieldInBody]) { + eval(test); + assertThrowsInstanceOf(() => eval(`"use strict"; ${test}`), SyntaxError); +} + +// Function context. +for (let test of [...yieldInParameters, ...yieldInBody]) { + eval(`function f() { ${test} }`); + assertThrowsInstanceOf(() => eval(`"use strict"; function f() { ${test} }`), SyntaxError); +} + +// Generator context. +for (let test of yieldInParameters) { + assertThrowsInstanceOf(() => eval(`function* g() { ${test} }`), SyntaxError); +} +for (let test of yieldInBody) { + eval(`function* g() { ${test} }`); +} +for (let test of [...yieldInParameters, ...yieldInBody]) { + assertThrowsInstanceOf(() => eval(`"use strict"; function* g() { ${test} }`), SyntaxError); +} + +if (typeof reportCompare === "function") + reportCompare(0, 0, "ok"); |