From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../async-generator-declaration-in-modules.js | 11 +++ js/src/tests/non262/AsyncGenerators/browser.js | 0 .../create-function-parse-before-getprototype.js | 19 +++++ .../non262/AsyncGenerators/cross-compartment.js | 90 ++++++++++++++++++++++ .../non262/AsyncGenerators/for-await-bad-syntax.js | 24 ++++++ .../non262/AsyncGenerators/for-await-of-error.js | 26 +++++++ js/src/tests/non262/AsyncGenerators/shell.js | 0 7 files changed, 170 insertions(+) create mode 100644 js/src/tests/non262/AsyncGenerators/async-generator-declaration-in-modules.js create mode 100644 js/src/tests/non262/AsyncGenerators/browser.js create mode 100644 js/src/tests/non262/AsyncGenerators/create-function-parse-before-getprototype.js create mode 100644 js/src/tests/non262/AsyncGenerators/cross-compartment.js create mode 100644 js/src/tests/non262/AsyncGenerators/for-await-bad-syntax.js create mode 100644 js/src/tests/non262/AsyncGenerators/for-await-of-error.js create mode 100644 js/src/tests/non262/AsyncGenerators/shell.js (limited to 'js/src/tests/non262/AsyncGenerators') diff --git a/js/src/tests/non262/AsyncGenerators/async-generator-declaration-in-modules.js b/js/src/tests/non262/AsyncGenerators/async-generator-declaration-in-modules.js new file mode 100644 index 0000000000..40509d990d --- /dev/null +++ b/js/src/tests/non262/AsyncGenerators/async-generator-declaration-in-modules.js @@ -0,0 +1,11 @@ +async function* f() { + return "success"; +} + +var AsyncGenerator = (async function*(){}).constructor; + +assertEq(f instanceof AsyncGenerator, true); + +f().next().then(v => { + reportCompare("success", v.value); +}); diff --git a/js/src/tests/non262/AsyncGenerators/browser.js b/js/src/tests/non262/AsyncGenerators/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/non262/AsyncGenerators/create-function-parse-before-getprototype.js b/js/src/tests/non262/AsyncGenerators/create-function-parse-before-getprototype.js new file mode 100644 index 0000000000..1c7f8df689 --- /dev/null +++ b/js/src/tests/non262/AsyncGenerators/create-function-parse-before-getprototype.js @@ -0,0 +1,19 @@ +var getProtoCalled = false; + +var newTarget = Object.defineProperty(function(){}.bind(), "prototype", { + get() { + getProtoCalled = true; + return null; + } +}); + +var AsyncGenerator = async function*(){}.constructor; + +assertThrowsInstanceOf(() => { + Reflect.construct(AsyncGenerator, ["@error"], newTarget); +}, SyntaxError); + +assertEq(getProtoCalled, false); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/AsyncGenerators/cross-compartment.js b/js/src/tests/non262/AsyncGenerators/cross-compartment.js new file mode 100644 index 0000000000..2cf577b126 --- /dev/null +++ b/js/src/tests/non262/AsyncGenerators/cross-compartment.js @@ -0,0 +1,90 @@ +var g = newGlobal(); +g.mainGlobal = this; + +if (typeof isSameCompartment !== "function") { + var isSameCompartment = SpecialPowers.Cu.getJSTestingFunctions().isSameCompartment; +} + +var next = async function*(){}.prototype.next; + +var f = g.eval(`(async function*() { + var x = yield {message: "yield"}; + + // Input completion values are correctly wrapped into |f|'s compartment. + assertEq(isSameCompartment(x, mainGlobal), true); + assertEq(x.message, "continue"); + + return {message: "return"}; +})`); + +var it = f(); + +// The async iterator is same-compartment with |f|. +assertEq(isSameCompartment(it, f), true); + +var p1 = next.call(it, {message: "initial yield"}); + +// The promise object is same-compartment with |f|. +assertEq(isSameCompartment(p1, f), true); + +// Note: This doesn't follow the spec, which requires that only |p1 instanceof Promise| is true. +assertEq(p1 instanceof Promise || p1 instanceof g.Promise, true); + +p1.then(v => { + // The iterator result object is same-compartment with |f|. + assertEq(isSameCompartment(v, f), true); + assertEq(v.done, false); + + assertEq(isSameCompartment(v.value, f), true); + assertEq(v.value.message, "yield"); +}); + +var p2 = next.call(it, {message: "continue"}); + +// The promise object is same-compartment with |f|. +assertEq(isSameCompartment(p2, f), true); + +// Note: This doesn't follow the spec, which requires that only |p2 instanceof Promise| is true. +assertEq(p2 instanceof Promise || p2 instanceof g.Promise, true); + +p2.then(v => { + // The iterator result object is same-compartment with |f|. + assertEq(isSameCompartment(v, f), true); + assertEq(v.done, true); + + assertEq(isSameCompartment(v.value, f), true); + assertEq(v.value.message, "return"); +}); + +var p3 = next.call(it, {message: "already finished"}); + +// The promise object is same-compartment with |f|. +assertEq(isSameCompartment(p3, f), true); + +// Note: This doesn't follow the spec, which requires that only |p3 instanceof Promise| is true. +assertEq(p3 instanceof Promise || p3 instanceof g.Promise, true); + +p3.then(v => { + // The iterator result object is same-compartment with |f|. + assertEq(isSameCompartment(v, f), true); + assertEq(v.done, true); + assertEq(v.value, undefined); +}); + +var p4 = next.call({}, {message: "bad |this| argument"}); + +// The promise object is same-compartment with |next|. +assertEq(isSameCompartment(p4, next), true); + +// Only in this case we're following the spec and are creating the promise object +// in the correct realm. +assertEq(p4 instanceof Promise, true); + +p4.then(() => { + throw new Error("expected a TypeError"); +}, e => { + assertEq(e instanceof TypeError, true); +}); + +if (typeof reportCompare === "function") + reportCompare(0, 0); diff --git a/js/src/tests/non262/AsyncGenerators/for-await-bad-syntax.js b/js/src/tests/non262/AsyncGenerators/for-await-bad-syntax.js new file mode 100644 index 0000000000..e1d90aeb76 --- /dev/null +++ b/js/src/tests/non262/AsyncGenerators/for-await-bad-syntax.js @@ -0,0 +1,24 @@ +var AsyncGenerator = async function*(){}.constructor; + +function assertSyntaxError(code) { + var functionCode = `async function* f() { ${code} }`; + assertThrowsInstanceOf(() => AsyncGenerator(code), SyntaxError, "AsyncGenerator:" + code); + assertThrowsInstanceOf(() => eval(functionCode), SyntaxError, "eval:" + functionCode); + var ieval = eval; + assertThrowsInstanceOf(() => ieval(functionCode), SyntaxError, "indirect eval:" + functionCode); +} + +assertSyntaxError(`for await (;;) ;`); + +for (var decl of ["", "var", "let", "const"]) { + for (var head of ["a", "a = 0", "a, b", "[a]", "[a] = 0", "{a}", "{a} = 0"]) { + // Ends with C-style for loop syntax. + assertSyntaxError(`for await (${decl} ${head} ;;) ;`); + + // Ends with for-in loop syntax. + assertSyntaxError(`for await (${decl} ${head} in null) ;`); + } +} + +if (typeof reportCompare === "function") + reportCompare(0, 0); diff --git a/js/src/tests/non262/AsyncGenerators/for-await-of-error.js b/js/src/tests/non262/AsyncGenerators/for-await-of-error.js new file mode 100644 index 0000000000..36e10313a4 --- /dev/null +++ b/js/src/tests/non262/AsyncGenerators/for-await-of-error.js @@ -0,0 +1,26 @@ +var BUGNUMBER = 1391519; +var summary = "for-await-of outside of async function should provide better error"; + +print(BUGNUMBER + ": " + summary); + +let caught = false; +try { + eval("for await (let x of []) {}"); +} catch(e) { + assertEq(e.message.includes("for await (... of ...) is only valid in"), true); + caught = true; +} +assertEq(caught, true); + +// Extra `await` shouldn't throw that error. +caught = false; +try { + eval("async function f() { for await await (let x of []) {} }"); +} catch(e) { + assertEq(e.message, "missing ( after for"); + caught = true; +} +assertEq(caught, true); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/AsyncGenerators/shell.js b/js/src/tests/non262/AsyncGenerators/shell.js new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3