From d77f35a4ecce96347203a2cfeffc1935556d8eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 30 Apr 2025 14:15:55 +0200 Subject: [PATCH] Replace createNewGlobal with $262.createRealm().global --- .../Tconstructor-fromTypedArray-byteLength.js | 2 +- test/staging/sm/TypedArray/at.js | 9 +- .../constructor-ArrayBuffer-species-wrap.js | 2 +- .../TypedArray/constructor-buffer-sequence.js | 2 +- ...tructor-typedarray-species-other-global.js | 2 +- test/staging/sm/TypedArray/entries.js | 16 +- test/staging/sm/TypedArray/every-and-some.js | 29 ++-- test/staging/sm/TypedArray/fill.js | 9 +- test/staging/sm/TypedArray/forEach.js | 17 ++- test/staging/sm/TypedArray/from_realms.js | 10 +- test/staging/sm/TypedArray/includes.js | 9 +- .../TypedArray/iterator-next-with-detached.js | 4 +- test/staging/sm/TypedArray/iterator.js | 2 +- test/staging/sm/TypedArray/join.js | 9 +- test/staging/sm/TypedArray/keys.js | 13 +- test/staging/sm/TypedArray/map-and-filter.js | 25 ++-- test/staging/sm/TypedArray/of.js | 13 +- .../sm/TypedArray/reduce-and-reduceRight.js | 15 +- test/staging/sm/TypedArray/reverse.js | 9 +- test/staging/sm/TypedArray/set-wrapped.js | 141 +++++++++--------- .../sm/TypedArray/slice-bitwise-same.js | 2 +- test/staging/sm/TypedArray/slice-memcpy.js | 2 +- test/staging/sm/TypedArray/slice.js | 11 +- .../sm/TypedArray/sort-negative-nan.js | 4 +- test/staging/sm/TypedArray/sort_byteoffset.js | 6 +- test/staging/sm/TypedArray/sort_errors.js | 8 +- test/staging/sm/TypedArray/sort_globals.js | 2 +- test/staging/sm/TypedArray/toLocaleString.js | 2 +- .../toStringTag-cross-compartment.js | 2 +- test/staging/sm/TypedArray/values.js | 13 +- 30 files changed, 196 insertions(+), 194 deletions(-) diff --git a/test/staging/sm/TypedArray/Tconstructor-fromTypedArray-byteLength.js b/test/staging/sm/TypedArray/Tconstructor-fromTypedArray-byteLength.js index 2ca848910f..640277ded3 100644 --- a/test/staging/sm/TypedArray/Tconstructor-fromTypedArray-byteLength.js +++ b/test/staging/sm/TypedArray/Tconstructor-fromTypedArray-byteLength.js @@ -9,7 +9,7 @@ description: | pending esid: pending ---*/ -var g = createNewGlobal(); +var g = $262.createRealm().global; var arr = [1, 2, 3]; for (var constructor of anyTypedArrayConstructors) { diff --git a/test/staging/sm/TypedArray/at.js b/test/staging/sm/TypedArray/at.js index 52d22d9479..ffdc5a4c10 100644 --- a/test/staging/sm/TypedArray/at.js +++ b/test/staging/sm/TypedArray/at.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.at.length, 1); @@ -32,10 +35,8 @@ for (var constructor of anyTypedArrayConstructors) { assert.sameValue(new constructor([0, 1]).at(NaN), 0); // ToInteger(NaN) = 0 // Called from other globals. - if (typeof createNewGlobal === "function") { - var at = createNewGlobal()[constructor.name].prototype.at; - assert.sameValue(at.call(new constructor([1, 2, 3]), 2), 3); - } + var at = otherGlobal[constructor.name].prototype.at; + assert.sameValue(at.call(new constructor([1, 2, 3]), 2), 3); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/constructor-ArrayBuffer-species-wrap.js b/test/staging/sm/TypedArray/constructor-ArrayBuffer-species-wrap.js index b75c1582bb..4d40f3c76a 100644 --- a/test/staging/sm/TypedArray/constructor-ArrayBuffer-species-wrap.js +++ b/test/staging/sm/TypedArray/constructor-ArrayBuffer-species-wrap.js @@ -10,7 +10,7 @@ description: | esid: pending ---*/ -let g = createNewGlobal(); +let g = $262.createRealm().global; // Both TypedArray and ArrayBuffer from different global. for (let ctor of typedArrayConstructors) { diff --git a/test/staging/sm/TypedArray/constructor-buffer-sequence.js b/test/staging/sm/TypedArray/constructor-buffer-sequence.js index cc273a7be6..9c61254da1 100644 --- a/test/staging/sm/TypedArray/constructor-buffer-sequence.js +++ b/test/staging/sm/TypedArray/constructor-buffer-sequence.js @@ -13,7 +13,7 @@ esid: pending // Ensure the various error conditions are tested in the correct order. -const otherGlobal = createNewGlobal(); +const otherGlobal = $262.createRealm().global; function* createBuffers(lengths = [0, 8]) { for (let length of lengths) { diff --git a/test/staging/sm/TypedArray/constructor-typedarray-species-other-global.js b/test/staging/sm/TypedArray/constructor-typedarray-species-other-global.js index 9ce71c1d3c..775d9c072e 100644 --- a/test/staging/sm/TypedArray/constructor-typedarray-species-other-global.js +++ b/test/staging/sm/TypedArray/constructor-typedarray-species-other-global.js @@ -15,7 +15,7 @@ esid: pending // ensure they are both created in the correct global. const thisGlobal = this; -const otherGlobal = createNewGlobal(); +const otherGlobal = $262.createRealm().global; const typedArrays = [otherGlobal.eval("new Int32Array(0)")]; diff --git a/test/staging/sm/TypedArray/entries.js b/test/staging/sm/TypedArray/entries.js index 48e4d3dec9..2390bb02cb 100644 --- a/test/staging/sm/TypedArray/entries.js +++ b/test/staging/sm/TypedArray/entries.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.entries.length, 0); assert.sameValue(constructor.prototype.entries.name, "entries"); @@ -26,14 +29,11 @@ for (var constructor of anyTypedArrayConstructors) { assert.deepEqual(iterator.next(), {value: undefined, done: true}); // Called from other globals. - if (typeof createNewGlobal === "function") { - var otherGlobal = createNewGlobal(); - var entries = otherGlobal[constructor.name].prototype.entries; - assert.deepEqual([...entries.call(new constructor(2))], - [new otherGlobal.Array(0, 0), new otherGlobal.Array(1, 0)]); - arr = new (createNewGlobal()[constructor.name])(2); - assert.sameValue([...constructor.prototype.entries.call(arr)].toString(), "0,0,1,0"); - } + var entries = otherGlobal[constructor.name].prototype.entries; + assert.deepEqual([...entries.call(new constructor(2))], + [new otherGlobal.Array(0, 0), new otherGlobal.Array(1, 0)]); + arr = new (otherGlobal[constructor.name])(2); + assert.sameValue([...constructor.prototype.entries.call(arr)].toString(), "0,0,1,0"); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/every-and-some.js b/test/staging/sm/TypedArray/every-and-some.js index acd333f8ee..823a1a1a8c 100644 --- a/test/staging/sm/TypedArray/every-and-some.js +++ b/test/staging/sm/TypedArray/every-and-some.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + // Tests for TypedArray#every. for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.every.length, 1); @@ -102,12 +105,10 @@ for (var constructor of anyTypedArrayConstructors) { }); // Called from other globals. - if (typeof createNewGlobal === "function") { - var every = createNewGlobal()[constructor.name].prototype.every; - var sum = 0; - assert.sameValue(every.call(new constructor([1, 2, 3]), v => sum += v), true); - assert.sameValue(sum, 6); - } + var every = otherGlobal[constructor.name].prototype.every; + var sum = 0; + assert.sameValue(every.call(new constructor([1, 2, 3]), v => sum += v), true); + assert.sameValue(sum, 6); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, @@ -225,15 +226,13 @@ for (var constructor of anyTypedArrayConstructors) { }); // Called from other globals. - if (typeof createNewGlobal === "function") { - var some = createNewGlobal()[constructor.name].prototype.some; - var sum = 0; - assert.sameValue(some.call(new constructor([1, 2, 3]), v => { - sum += v; - return false; - }), false); - assert.sameValue(sum, 6); - } + var some = otherGlobal[constructor.name].prototype.some; + var sum = 0; + assert.sameValue(some.call(new constructor([1, 2, 3]), v => { + sum += v; + return false; + }), false); + assert.sameValue(sum, 6); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/fill.js b/test/staging/sm/TypedArray/fill.js index 8ee8b8712b..be7abefba7 100644 --- a/test/staging/sm/TypedArray/fill.js +++ b/test/staging/sm/TypedArray/fill.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.deepEqual(constructor.prototype.fill.length, 1); @@ -46,10 +49,8 @@ for (var constructor of anyTypedArrayConstructors) { assert.deepEqual(new constructor([1,1,1]).fill(2, 0, {valueOf: ()=>1}), new constructor([2,1,1])); // Called from other globals. - if (typeof createNewGlobal === "function") { - var fill = createNewGlobal()[constructor.name].prototype.fill; - assert.deepEqual(fill.call(new constructor([3, 2, 1]), 2), new constructor([2, 2, 2])); - } + var fill = otherGlobal[constructor.name].prototype.fill; + assert.deepEqual(fill.call(new constructor([3, 2, 1]), 2), new constructor([2, 2, 2])); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/forEach.js b/test/staging/sm/TypedArray/forEach.js index 93a202e2a3..a48d9a7ea9 100644 --- a/test/staging/sm/TypedArray/forEach.js +++ b/test/staging/sm/TypedArray/forEach.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + // Tests for TypedArray#forEach for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.forEach.length, 1); @@ -81,14 +84,12 @@ for (var constructor of anyTypedArrayConstructors) { }); // Called from other globals. - if (typeof createNewGlobal === "function") { - var forEach = createNewGlobal()[constructor.name].prototype.forEach; - var sum = 0; - forEach.call(new constructor([1, 2, 3]), v => { - sum += v; - }); - assert.sameValue(sum, 6); - } + var forEach = otherGlobal[constructor.name].prototype.forEach; + var sum = 0; + forEach.call(new constructor([1, 2, 3]), v => { + sum += v; + }); + assert.sameValue(sum, 6); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/from_realms.js b/test/staging/sm/TypedArray/from_realms.js index 9d7c39ff66..feb4c3b73d 100644 --- a/test/staging/sm/TypedArray/from_realms.js +++ b/test/staging/sm/TypedArray/from_realms.js @@ -9,13 +9,13 @@ description: | pending esid: pending ---*/ -for (var constructor of anyTypedArrayConstructors) { - if (typeof createNewGlobal !== 'function') - break; +var g = $262.createRealm().global; +var h = $262.createRealm().global; + +for (var constructor of anyTypedArrayConstructors) { // G[constructor.name].from, where G is any global, produces an array whose prototype // is G[constructor.name].prototype. - var g = createNewGlobal(); var ga = g[constructor.name].from([1, 2, 3]); assert.sameValue(ga instanceof g[constructor.name], true); @@ -27,7 +27,7 @@ for (var constructor of anyTypedArrayConstructors) { // 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 = createNewGlobal(), result = undefined; + var result = undefined; h.mainGlobal = this; h.eval("function f() { mainGlobal.result = this; }"); g[constructor.name].from.call(constructor, [5, 6, 7], h.f); diff --git a/test/staging/sm/TypedArray/includes.js b/test/staging/sm/TypedArray/includes.js index 833ef00c93..0a81b844d9 100644 --- a/test/staging/sm/TypedArray/includes.js +++ b/test/staging/sm/TypedArray/includes.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.includes.length, 1); @@ -25,10 +28,8 @@ for (var constructor of anyTypedArrayConstructors) { assert.sameValue(new constructor([1, 2, 3]).includes(2, 100), false); // Called from other globals. - if (typeof createNewGlobal === "function") { - var includes = createNewGlobal()[constructor.name].prototype.includes; - assert.sameValue(includes.call(new constructor([1, 2, 3]), 2), true); - } + var includes = otherGlobal[constructor.name].prototype.includes; + assert.sameValue(includes.call(new constructor([1, 2, 3]), 2), true); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/iterator-next-with-detached.js b/test/staging/sm/TypedArray/iterator-next-with-detached.js index 8c4ed8c496..594be96f2b 100644 --- a/test/staging/sm/TypedArray/iterator-next-with-detached.js +++ b/test/staging/sm/TypedArray/iterator-next-with-detached.js @@ -15,13 +15,13 @@ function checkResult(actual, expected) assert.sameValue(actual.done, expected.done); } -if (typeof $262.detachArrayBuffer === "function" && typeof createNewGlobal === "function") +if (typeof $262.detachArrayBuffer === "function") { var iteratorFunction = Uint8Array.prototype[Symbol.iterator]; var thisGlobal = this; - var otherGlobal = createNewGlobal(); + var otherGlobal = $262.createRealm().global; var thisNext = new Uint8Array()[Symbol.iterator]().next diff --git a/test/staging/sm/TypedArray/iterator.js b/test/staging/sm/TypedArray/iterator.js index 2d65df5e41..ddeec1c83b 100644 --- a/test/staging/sm/TypedArray/iterator.js +++ b/test/staging/sm/TypedArray/iterator.js @@ -41,7 +41,7 @@ Object.defineProperty(i8Array, "length", {value: 15}); (new Uint8Array(4)).set(i8Array, 3); // Ensure that it works across globals -let g2 = createNewGlobal(); +let g2 = $262.createRealm().global; i8Array = new Int8Array(8); Object.defineProperty(i8Array, "length", {value: 0}); diff --git a/test/staging/sm/TypedArray/join.js b/test/staging/sm/TypedArray/join.js index 3eddb899c5..cb84db4dbc 100644 --- a/test/staging/sm/TypedArray/join.js +++ b/test/staging/sm/TypedArray/join.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.join.length, 1); @@ -29,10 +32,8 @@ for (var constructor of anyTypedArrayConstructors) { assert.throws(TypeError, () => new constructor().join(Symbol())); // Called from other globals. - if (typeof createNewGlobal === "function") { - var join = createNewGlobal()[constructor.name].prototype.join; - assert.sameValue(join.call(new constructor([1, 2, 3]), "\t"), "1\t2\t3"); - } + var join = otherGlobal[constructor.name].prototype.join; + assert.sameValue(join.call(new constructor([1, 2, 3]), "\t"), "1\t2\t3"); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/keys.js b/test/staging/sm/TypedArray/keys.js index 0763a2ca70..16bd6fa216 100644 --- a/test/staging/sm/TypedArray/keys.js +++ b/test/staging/sm/TypedArray/keys.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.keys.length, 0); assert.sameValue(constructor.prototype.keys.name, "keys"); @@ -26,12 +29,10 @@ for (var constructor of anyTypedArrayConstructors) { assert.deepEqual(iterator.next(), {value: undefined, done: true}); // Called from other globals. - if (typeof createNewGlobal === "function") { - var keys = createNewGlobal()[constructor.name].prototype.keys; - assert.deepEqual([...keys.call(new constructor(2))], [0, 1]); - arr = new (createNewGlobal()[constructor.name])(2); - assert.sameValue([...constructor.prototype.keys.call(arr)].toString(), "0,1"); - } + var keys = otherGlobal[constructor.name].prototype.keys; + assert.deepEqual([...keys.call(new constructor(2))], [0, 1]); + arr = new (otherGlobal[constructor.name])(2); + assert.sameValue([...constructor.prototype.keys.call(arr)].toString(), "0,1"); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/map-and-filter.js b/test/staging/sm/TypedArray/map-and-filter.js index ce8ea0e761..5c93af049d 100644 --- a/test/staging/sm/TypedArray/map-and-filter.js +++ b/test/staging/sm/TypedArray/map-and-filter.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + // Tests for TypedArray#map. for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.map.length, 1); @@ -110,12 +113,10 @@ for (var constructor of anyTypedArrayConstructors) { }); // Called from other globals. - if (typeof createNewGlobal === "function") { - var map = createNewGlobal()[constructor.name].prototype.map; - var sum = 0; - assert.compareArray(map.call(new constructor([1, 2, 3]), v => sum += v), new constructor([1,3,6])); - assert.sameValue(sum, 6); - } + var map = otherGlobal[constructor.name].prototype.map; + var sum = 0; + assert.compareArray(map.call(new constructor([1, 2, 3]), v => sum += v), new constructor([1,3,6])); + assert.sameValue(sum, 6); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, @@ -234,13 +235,11 @@ for (var constructor of anyTypedArrayConstructors) { }); // Called from other globals. - if (typeof createNewGlobal === "function") { - var filter = createNewGlobal()[constructor.name].prototype.filter; - var sum = 0; - assert.compareArray(filter.call(new constructor([1, 2, 3]), v => {sum += v; return true}), - new constructor([1,2,3])); - assert.sameValue(sum, 6); - } + var filter = otherGlobal[constructor.name].prototype.filter; + var sum = 0; + assert.compareArray(filter.call(new constructor([1, 2, 3]), v => {sum += v; return true}), + new constructor([1,2,3])); + assert.sameValue(sum, 6); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/of.js b/test/staging/sm/TypedArray/of.js index 77f2877e77..df4bface5f 100644 --- a/test/staging/sm/TypedArray/of.js +++ b/test/staging/sm/TypedArray/of.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.of.length, 0); @@ -40,12 +43,10 @@ for (var constructor of anyTypedArrayConstructors) { assert.sameValue(hits, 1); // Behavior across compartments. - if (typeof createNewGlobal === "function") { - var newC = createNewGlobal()[constructor.name]; - assert.sameValue(newC.of() instanceof newC, true); - assert.sameValue(newC.of() instanceof constructor, false); - assert.sameValue(newC.of.call(constructor) instanceof constructor, true); - } + var newC = otherGlobal[constructor.name]; + assert.sameValue(newC.of() instanceof newC, true); + assert.sameValue(newC.of() instanceof constructor, false); + assert.sameValue(newC.of.call(constructor) instanceof constructor, true); // Throws if `this` isn't a constructor. var invalidConstructors = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/reduce-and-reduceRight.js b/test/staging/sm/TypedArray/reduce-and-reduceRight.js index e5bb47aa35..f35c82e883 100644 --- a/test/staging/sm/TypedArray/reduce-and-reduceRight.js +++ b/test/staging/sm/TypedArray/reduce-and-reduceRight.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + // Tests for TypedArray#reduce. for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.reduce.length, 1); @@ -80,10 +83,8 @@ for (var constructor of anyTypedArrayConstructors) { }); // Called from other globals. - if (typeof createNewGlobal === "function") { - var reduce = createNewGlobal()[constructor.name].prototype.reduce; - assert.sameValue(reduce.call(arr, (previous, current) => Math.min(previous, current)), 1); - } + var reduce = otherGlobal[constructor.name].prototype.reduce; + assert.sameValue(reduce.call(arr, (previous, current) => Math.min(previous, current)), 1); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, @@ -173,10 +174,8 @@ for (var constructor of anyTypedArrayConstructors) { }); // Called from other globals. - if (typeof createNewGlobal === "function") { - var reduceRight = createNewGlobal()[constructor.name].prototype.reduceRight; - assert.sameValue(reduceRight.call(arr, (previous, current) => Math.min(previous, current)), 1); - } + var reduceRight = otherGlobal[constructor.name].prototype.reduceRight; + assert.sameValue(reduceRight.call(arr, (previous, current) => Math.min(previous, current)), 1); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/reverse.js b/test/staging/sm/TypedArray/reverse.js index 3b2fb0165e..cca9bf0ceb 100644 --- a/test/staging/sm/TypedArray/reverse.js +++ b/test/staging/sm/TypedArray/reverse.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.deepEqual(constructor.prototype.reverse.length, 0); @@ -23,10 +26,8 @@ for (var constructor of anyTypedArrayConstructors) { assert.deepEqual(new constructor([.1, .2, .3]).reverse(), new constructor([.3, .2, .1])); // Called from other globals. - if (typeof createNewGlobal === "function") { - var reverse = createNewGlobal()[constructor.name].prototype.reverse; - assert.deepEqual(reverse.call(new constructor([3, 2, 1])), new constructor([1, 2, 3])); - } + var reverse = otherGlobal[constructor.name].prototype.reverse; + assert.deepEqual(reverse.call(new constructor([3, 2, 1])), new constructor([1, 2, 3])); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/set-wrapped.js b/test/staging/sm/TypedArray/set-wrapped.js index 975fce9752..d0d2c4bc42 100644 --- a/test/staging/sm/TypedArray/set-wrapped.js +++ b/test/staging/sm/TypedArray/set-wrapped.js @@ -12,79 +12,76 @@ esid: pending // Test %TypedArray%.prototype.set(typedArray, offset) when called with wrapped // typed array. -if (typeof createNewGlobal === "function") { - var otherGlobal = createNewGlobal(); +var otherGlobal = $262.createRealm().global; - function taintLengthProperty(obj) { - Object.defineProperty(obj, "length", { - get() { - assert.sameValue(true, false); - } - }); - } - - for (var TA of anyTypedArrayConstructors) { - var target = new TA(4); - var source = new otherGlobal[TA.name]([10, 20]); - - // Ensure "length" getter accessor isn't called. - taintLengthProperty(source); - - assert.compareArray(target, [0, 0, 0, 0]); - target.set(source, 1); - assert.compareArray(target, [0, 10, 20, 0]); - } - - // Detachment checks are also applied correctly for wrapped typed arrays. - if (typeof $262.detachArrayBuffer === "function") { - // Create typed array from different global (explicit constructor call). - for (var TA of typedArrayConstructors) { - var target = new TA(4); - var source = new otherGlobal[TA.name](1); - taintLengthProperty(source); - - // Called with wrapped typed array, array buffer already detached. - otherGlobal.$262.detachArrayBuffer(source.buffer); - assert.throws(TypeError, () => target.set(source)); - - var source = new otherGlobal[TA.name](1); - taintLengthProperty(source); - - // Called with wrapped typed array, array buffer detached when - // processing offset parameter. - var offset = { - valueOf() { - otherGlobal.$262.detachArrayBuffer(source.buffer); - return 0; - } - }; - assert.throws(TypeError, () => target.set(source, offset)); +function taintLengthProperty(obj) { + Object.defineProperty(obj, "length", { + get() { + assert.sameValue(true, false); } - - // Create typed array from different global (implictly created when - // ArrayBuffer is a CCW). - for (var TA of typedArrayConstructors) { - var target = new TA(4); - var source = new TA(new otherGlobal.ArrayBuffer(1 * TA.BYTES_PER_ELEMENT)); - taintLengthProperty(source); - - // Called with wrapped typed array, array buffer already detached. - otherGlobal.$262.detachArrayBuffer(source.buffer); - assert.throws(TypeError, () => target.set(source)); - - var source = new TA(new otherGlobal.ArrayBuffer(1 * TA.BYTES_PER_ELEMENT)); - taintLengthProperty(source); - - // Called with wrapped typed array, array buffer detached when - // processing offset parameter. - var offset = { - valueOf() { - otherGlobal.$262.detachArrayBuffer(source.buffer); - return 0; - } - }; - assert.throws(TypeError, () => target.set(source, offset)); - } - } + }); } +for (var TA of anyTypedArrayConstructors) { + var target = new TA(4); + var source = new otherGlobal[TA.name]([10, 20]); + + // Ensure "length" getter accessor isn't called. + taintLengthProperty(source); + + assert.compareArray(target, [0, 0, 0, 0]); + target.set(source, 1); + assert.compareArray(target, [0, 10, 20, 0]); +} + +// Detachment checks are also applied correctly for wrapped typed arrays. +if (typeof $262.detachArrayBuffer === "function") { + // Create typed array from different global (explicit constructor call). + for (var TA of typedArrayConstructors) { + var target = new TA(4); + var source = new otherGlobal[TA.name](1); + taintLengthProperty(source); + + // Called with wrapped typed array, array buffer already detached. + otherGlobal.$262.detachArrayBuffer(source.buffer); + assert.throws(TypeError, () => target.set(source)); + + var source = new otherGlobal[TA.name](1); + taintLengthProperty(source); + + // Called with wrapped typed array, array buffer detached when + // processing offset parameter. + var offset = { + valueOf() { + otherGlobal.$262.detachArrayBuffer(source.buffer); + return 0; + } + }; + assert.throws(TypeError, () => target.set(source, offset)); + } + + // Create typed array from different global (implictly created when + // ArrayBuffer is a CCW). + for (var TA of typedArrayConstructors) { + var target = new TA(4); + var source = new TA(new otherGlobal.ArrayBuffer(1 * TA.BYTES_PER_ELEMENT)); + taintLengthProperty(source); + + // Called with wrapped typed array, array buffer already detached. + otherGlobal.$262.detachArrayBuffer(source.buffer); + assert.throws(TypeError, () => target.set(source)); + + var source = new TA(new otherGlobal.ArrayBuffer(1 * TA.BYTES_PER_ELEMENT)); + taintLengthProperty(source); + + // Called with wrapped typed array, array buffer detached when + // processing offset parameter. + var offset = { + valueOf() { + otherGlobal.$262.detachArrayBuffer(source.buffer); + return 0; + } + }; + assert.throws(TypeError, () => target.set(source, offset)); + } +} diff --git a/test/staging/sm/TypedArray/slice-bitwise-same.js b/test/staging/sm/TypedArray/slice-bitwise-same.js index c73dd1114c..83f9363ae3 100644 --- a/test/staging/sm/TypedArray/slice-bitwise-same.js +++ b/test/staging/sm/TypedArray/slice-bitwise-same.js @@ -17,7 +17,7 @@ const float64Constructors = anyTypedArrayConstructors.filter(isFloatConstructor) .filter(c => c.BYTES_PER_ELEMENT === 8); // Also test with cross-compartment typed arrays. -const otherGlobal = createNewGlobal(); +const otherGlobal = $262.createRealm().global; float32Constructors.push(otherGlobal.Float32Array); float64Constructors.push(otherGlobal.Float64Array); diff --git a/test/staging/sm/TypedArray/slice-memcpy.js b/test/staging/sm/TypedArray/slice-memcpy.js index 5a5f61a2a3..aa48f1e0c1 100644 --- a/test/staging/sm/TypedArray/slice-memcpy.js +++ b/test/staging/sm/TypedArray/slice-memcpy.js @@ -9,7 +9,7 @@ description: | pending esid: pending ---*/ -const otherGlobal = createNewGlobal(); +const otherGlobal = $262.createRealm().global; // Create with new ArrayBuffer and offset. for (var constructor of typedArrayConstructors) { diff --git a/test/staging/sm/TypedArray/slice.js b/test/staging/sm/TypedArray/slice.js index 1a8ca3c879..c491fbaf4e 100644 --- a/test/staging/sm/TypedArray/slice.js +++ b/test/staging/sm/TypedArray/slice.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.slice.length, 2); @@ -28,11 +31,9 @@ for (var constructor of anyTypedArrayConstructors) { assert.compareArray(new constructor([1, 2]).slice(1, 5), new constructor([2])); // Called from other globals. - if (typeof createNewGlobal === "function") { - var slice = createNewGlobal()[constructor.name].prototype.slice; - assert.compareArray(slice.call(new constructor([3, 2, 1]), 1), - new constructor([2, 1])); - } + var slice = otherGlobal[constructor.name].prototype.slice; + assert.compareArray(slice.call(new constructor([3, 2, 1]), 1), + new constructor([2, 1])); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, diff --git a/test/staging/sm/TypedArray/sort-negative-nan.js b/test/staging/sm/TypedArray/sort-negative-nan.js index be3fe5630a..abb6f2e5ec 100644 --- a/test/staging/sm/TypedArray/sort-negative-nan.js +++ b/test/staging/sm/TypedArray/sort-negative-nan.js @@ -13,8 +13,8 @@ esid: pending const floatConstructors = anyTypedArrayConstructors.filter(isFloatConstructor); // Also test with cross-compartment wrapped typed arrays. -if (typeof createNewGlobal === "function") { - const otherGlobal = createNewGlobal(); +{ + const otherGlobal = $262.createRealm().global; floatConstructors.push(otherGlobal.Float16Array); floatConstructors.push(otherGlobal.Float32Array); floatConstructors.push(otherGlobal.Float64Array); diff --git a/test/staging/sm/TypedArray/sort_byteoffset.js b/test/staging/sm/TypedArray/sort_byteoffset.js index 63aff3633f..5672e437b4 100644 --- a/test/staging/sm/TypedArray/sort_byteoffset.js +++ b/test/staging/sm/TypedArray/sort_byteoffset.js @@ -15,10 +15,8 @@ esid: pending var sortFunctions = [Int32Array.prototype.sort]; // Also test with cross-compartment wrapped typed arrays. -if (typeof createNewGlobal === "function") { - var otherGlobal = createNewGlobal(); - sortFunctions.push(createNewGlobal().Int32Array.prototype.sort); -} +var otherGlobal = $262.createRealm().global; +sortFunctions.push(otherGlobal.Int32Array.prototype.sort); // The bug manifests itself only with Float arrays, // but checking everything here just for sanity. diff --git a/test/staging/sm/TypedArray/sort_errors.js b/test/staging/sm/TypedArray/sort_errors.js index a8f2b9a259..2e7b44480e 100644 --- a/test/staging/sm/TypedArray/sort_errors.js +++ b/test/staging/sm/TypedArray/sort_errors.js @@ -33,20 +33,20 @@ if (typeof $262.detachArrayBuffer === "function") { assert.sameValue(detached, true); } +let otherGlobal = $262.createRealm().global; + // Ensure detachment check doesn't choke on wrapped typed array. -if (typeof createNewGlobal === "function") { +{ let ta = new Int32Array(3); - let otherGlobal = createNewGlobal(); otherGlobal.Int32Array.prototype.sort.call(ta, function(a, b) { return a - b; }); } // Ensure detaching buffer in comparator doesn't throw an error when the typed array is wrapped. -if (typeof createNewGlobal === "function" && typeof $262.detachArrayBuffer === "function") { +if (typeof $262.detachArrayBuffer === "function") { let detached = false; let ta = new Int32Array(3); - let otherGlobal = createNewGlobal(); otherGlobal.Int32Array.prototype.sort.call(ta, function(a,b) { if (!detached) { detached = true; diff --git a/test/staging/sm/TypedArray/sort_globals.js b/test/staging/sm/TypedArray/sort_globals.js index 6923122ae0..4a96f42c21 100644 --- a/test/staging/sm/TypedArray/sort_globals.js +++ b/test/staging/sm/TypedArray/sort_globals.js @@ -10,7 +10,7 @@ description: | esid: pending ---*/ // TypedArray.prototype.sort should work across globals -let g2 = createNewGlobal(); +let g2 = $262.createRealm().global; assert.compareArray( Int32Array.prototype.sort.call(new g2.Int32Array([3, 2, 1])), new Int32Array([1, 2, 3]) diff --git a/test/staging/sm/TypedArray/toLocaleString.js b/test/staging/sm/TypedArray/toLocaleString.js index 16239161cb..6146adbe94 100644 --- a/test/staging/sm/TypedArray/toLocaleString.js +++ b/test/staging/sm/TypedArray/toLocaleString.js @@ -73,7 +73,7 @@ for (let constructor of anyTypedArrayConstructors) { Number.prototype.toLocaleString = originalNumberToLocaleString; // Calls Number.prototype.toLocaleString from the current Realm. -const otherGlobal = createNewGlobal(); +const otherGlobal = $262.createRealm().global; for (let constructor of anyTypedArrayConstructors) { Number.prototype.toLocaleString = function() { "use strict"; diff --git a/test/staging/sm/TypedArray/toStringTag-cross-compartment.js b/test/staging/sm/TypedArray/toStringTag-cross-compartment.js index d4b0b935f2..8972bae3da 100644 --- a/test/staging/sm/TypedArray/toStringTag-cross-compartment.js +++ b/test/staging/sm/TypedArray/toStringTag-cross-compartment.js @@ -12,7 +12,7 @@ esid: pending const TypedArrayPrototype = Object.getPrototypeOf(Int8Array.prototype); const {get: toStringTag} = Object.getOwnPropertyDescriptor(TypedArrayPrototype, Symbol.toStringTag); -const otherGlobal = createNewGlobal(); +const otherGlobal = $262.createRealm().global; for (let constructor of anyTypedArrayConstructors) { let ta = new otherGlobal[constructor.name](0); diff --git a/test/staging/sm/TypedArray/values.js b/test/staging/sm/TypedArray/values.js index 631acd170d..ec7c1098d0 100644 --- a/test/staging/sm/TypedArray/values.js +++ b/test/staging/sm/TypedArray/values.js @@ -9,6 +9,9 @@ description: | pending esid: pending ---*/ + +var otherGlobal = $262.createRealm().global; + for (var constructor of anyTypedArrayConstructors) { assert.sameValue(constructor.prototype.values.length, 0); assert.sameValue(constructor.prototype.values.name, "values"); @@ -27,12 +30,10 @@ for (var constructor of anyTypedArrayConstructors) { assert.deepEqual(iterator.next(), {value: undefined, done: true}); // Called from other globals. - if (typeof createNewGlobal === "function") { - var values = createNewGlobal()[constructor.name].prototype.values; - assert.deepEqual([...values.call(new constructor([42, 36]))], [42, 36]); - arr = new (createNewGlobal()[constructor.name])([42, 36]); - assert.sameValue([...constructor.prototype.values.call(arr)].toString(), "42,36"); - } + var values = otherGlobal[constructor.name].prototype.values; + assert.deepEqual([...values.call(new constructor([42, 36]))], [42, 36]); + arr = new (otherGlobal[constructor.name])([42, 36]); + assert.sameValue([...constructor.prototype.values.call(arr)].toString(), "42,36"); // Throws if `this` isn't a TypedArray. var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,