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 --- js/src/tests/non262/TypedArray/from_realms.js | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 js/src/tests/non262/TypedArray/from_realms.js (limited to 'js/src/tests/non262/TypedArray/from_realms.js') diff --git a/js/src/tests/non262/TypedArray/from_realms.js b/js/src/tests/non262/TypedArray/from_realms.js new file mode 100644 index 0000000000..590589392f --- /dev/null +++ b/js/src/tests/non262/TypedArray/from_realms.js @@ -0,0 +1,32 @@ +for (var constructor of anyTypedArrayConstructors) { + if (typeof newGlobal !== 'function') + break; + + // G[constructor.name].from, where G is any global, produces an array whose prototype + // is G[constructor.name].prototype. + var g = newGlobal(); + var ga = g[constructor.name].from([1, 2, 3]); + assertEq(ga instanceof g[constructor.name], true); + + // %TypedArray%.from can be applied to a constructor from another realm. + var p = constructor.from.call(g[constructor.name], [1, 2, 3]); + assertEq(p instanceof g[constructor.name], true); + var q = g[constructor.name].from.call(constructor, [3, 4, 5]); + assertEq(q instanceof constructor, true); + + // The default 'this' value received by a non-strict mapping function is + // that function's global, not %TypedArray%.from's global or the caller's global. + var h = newGlobal(), result = undefined; + h.mainGlobal = this; + h.eval("function f() { mainGlobal.result = this; }"); + g[constructor.name].from.call(constructor, [5, 6, 7], h.f); + // (Give each global in the test a name, for better error messages. But use + // globalName, because window.name is complicated.) + this.globalName = "main"; + g.globalName = "g"; + h.globalName = "h"; + assertEq(result.globalName, "h"); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); -- cgit v1.2.3