From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../non262/AsyncGenerators/cross-compartment.js | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 js/src/tests/non262/AsyncGenerators/cross-compartment.js (limited to 'js/src/tests/non262/AsyncGenerators/cross-compartment.js') 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); -- cgit v1.2.3