Replace createNewGlobal with $262.createRealm().global

This commit is contained in:
André Bargull 2025-04-30 14:15:55 +02:00 committed by Philip Chimento
parent eae3f3a386
commit d77f35a4ec
30 changed files with 196 additions and 194 deletions

View File

@ -9,7 +9,7 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var g = createNewGlobal(); var g = $262.createRealm().global;
var arr = [1, 2, 3]; var arr = [1, 2, 3];
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.at.length, 1); 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 assert.sameValue(new constructor([0, 1]).at(NaN), 0); // ToInteger(NaN) = 0
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var at = otherGlobal[constructor.name].prototype.at;
var at = createNewGlobal()[constructor.name].prototype.at; assert.sameValue(at.call(new constructor([1, 2, 3]), 2), 3);
assert.sameValue(at.call(new constructor([1, 2, 3]), 2), 3);
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -10,7 +10,7 @@ description: |
esid: pending esid: pending
---*/ ---*/
let g = createNewGlobal(); let g = $262.createRealm().global;
// Both TypedArray and ArrayBuffer from different global. // Both TypedArray and ArrayBuffer from different global.
for (let ctor of typedArrayConstructors) { for (let ctor of typedArrayConstructors) {

View File

@ -13,7 +13,7 @@ esid: pending
// Ensure the various error conditions are tested in the correct order. // Ensure the various error conditions are tested in the correct order.
const otherGlobal = createNewGlobal(); const otherGlobal = $262.createRealm().global;
function* createBuffers(lengths = [0, 8]) { function* createBuffers(lengths = [0, 8]) {
for (let length of lengths) { for (let length of lengths) {

View File

@ -15,7 +15,7 @@ esid: pending
// ensure they are both created in the correct global. // ensure they are both created in the correct global.
const thisGlobal = this; const thisGlobal = this;
const otherGlobal = createNewGlobal(); const otherGlobal = $262.createRealm().global;
const typedArrays = [otherGlobal.eval("new Int32Array(0)")]; const typedArrays = [otherGlobal.eval("new Int32Array(0)")];

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.entries.length, 0); assert.sameValue(constructor.prototype.entries.length, 0);
assert.sameValue(constructor.prototype.entries.name, "entries"); assert.sameValue(constructor.prototype.entries.name, "entries");
@ -26,14 +29,11 @@ for (var constructor of anyTypedArrayConstructors) {
assert.deepEqual(iterator.next(), {value: undefined, done: true}); assert.deepEqual(iterator.next(), {value: undefined, done: true});
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var entries = otherGlobal[constructor.name].prototype.entries;
var otherGlobal = createNewGlobal(); assert.deepEqual([...entries.call(new constructor(2))],
var entries = otherGlobal[constructor.name].prototype.entries; [new otherGlobal.Array(0, 0), new otherGlobal.Array(1, 0)]);
assert.deepEqual([...entries.call(new constructor(2))], arr = new (otherGlobal[constructor.name])(2);
[new otherGlobal.Array(0, 0), new otherGlobal.Array(1, 0)]); assert.sameValue([...constructor.prototype.entries.call(arr)].toString(), "0,0,1,0");
arr = new (createNewGlobal()[constructor.name])(2);
assert.sameValue([...constructor.prototype.entries.call(arr)].toString(), "0,0,1,0");
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
// Tests for TypedArray#every. // Tests for TypedArray#every.
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.every.length, 1); assert.sameValue(constructor.prototype.every.length, 1);
@ -102,12 +105,10 @@ for (var constructor of anyTypedArrayConstructors) {
}); });
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var every = otherGlobal[constructor.name].prototype.every;
var every = createNewGlobal()[constructor.name].prototype.every; var sum = 0;
var sum = 0; assert.sameValue(every.call(new constructor([1, 2, 3]), v => sum += v), true);
assert.sameValue(every.call(new constructor([1, 2, 3]), v => sum += v), true); assert.sameValue(sum, 6);
assert.sameValue(sum, 6);
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
@ -225,15 +226,13 @@ for (var constructor of anyTypedArrayConstructors) {
}); });
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var some = otherGlobal[constructor.name].prototype.some;
var some = createNewGlobal()[constructor.name].prototype.some; var sum = 0;
var sum = 0; assert.sameValue(some.call(new constructor([1, 2, 3]), v => {
assert.sameValue(some.call(new constructor([1, 2, 3]), v => { sum += v;
sum += v; return false;
return false; }), false);
}), false); assert.sameValue(sum, 6);
assert.sameValue(sum, 6);
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.deepEqual(constructor.prototype.fill.length, 1); 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])); assert.deepEqual(new constructor([1,1,1]).fill(2, 0, {valueOf: ()=>1}), new constructor([2,1,1]));
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var fill = otherGlobal[constructor.name].prototype.fill;
var fill = createNewGlobal()[constructor.name].prototype.fill; assert.deepEqual(fill.call(new constructor([3, 2, 1]), 2), new constructor([2, 2, 2]));
assert.deepEqual(fill.call(new constructor([3, 2, 1]), 2), new constructor([2, 2, 2]));
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
// Tests for TypedArray#forEach // Tests for TypedArray#forEach
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.forEach.length, 1); assert.sameValue(constructor.prototype.forEach.length, 1);
@ -81,14 +84,12 @@ for (var constructor of anyTypedArrayConstructors) {
}); });
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var forEach = otherGlobal[constructor.name].prototype.forEach;
var forEach = createNewGlobal()[constructor.name].prototype.forEach; var sum = 0;
var sum = 0; forEach.call(new constructor([1, 2, 3]), v => {
forEach.call(new constructor([1, 2, 3]), v => { sum += v;
sum += v; });
}); assert.sameValue(sum, 6);
assert.sameValue(sum, 6);
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -9,13 +9,13 @@ description: |
pending pending
esid: 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 // G[constructor.name].from, where G is any global, produces an array whose prototype
// is G[constructor.name].prototype. // is G[constructor.name].prototype.
var g = createNewGlobal();
var ga = g[constructor.name].from([1, 2, 3]); var ga = g[constructor.name].from([1, 2, 3]);
assert.sameValue(ga instanceof g[constructor.name], true); 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 // 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. // 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.mainGlobal = this;
h.eval("function f() { mainGlobal.result = this; }"); h.eval("function f() { mainGlobal.result = this; }");
g[constructor.name].from.call(constructor, [5, 6, 7], h.f); g[constructor.name].from.call(constructor, [5, 6, 7], h.f);

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.includes.length, 1); 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); assert.sameValue(new constructor([1, 2, 3]).includes(2, 100), false);
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var includes = otherGlobal[constructor.name].prototype.includes;
var includes = createNewGlobal()[constructor.name].prototype.includes; assert.sameValue(includes.call(new constructor([1, 2, 3]), 2), true);
assert.sameValue(includes.call(new constructor([1, 2, 3]), 2), true);
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -15,13 +15,13 @@ function checkResult(actual, expected)
assert.sameValue(actual.done, expected.done); 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 iteratorFunction = Uint8Array.prototype[Symbol.iterator];
var thisGlobal = this; var thisGlobal = this;
var otherGlobal = createNewGlobal(); var otherGlobal = $262.createRealm().global;
var thisNext = new Uint8Array()[Symbol.iterator]().next var thisNext = new Uint8Array()[Symbol.iterator]().next

View File

@ -41,7 +41,7 @@ Object.defineProperty(i8Array, "length", {value: 15});
(new Uint8Array(4)).set(i8Array, 3); (new Uint8Array(4)).set(i8Array, 3);
// Ensure that it works across globals // Ensure that it works across globals
let g2 = createNewGlobal(); let g2 = $262.createRealm().global;
i8Array = new Int8Array(8); i8Array = new Int8Array(8);
Object.defineProperty(i8Array, "length", {value: 0}); Object.defineProperty(i8Array, "length", {value: 0});

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.join.length, 1); assert.sameValue(constructor.prototype.join.length, 1);
@ -29,10 +32,8 @@ for (var constructor of anyTypedArrayConstructors) {
assert.throws(TypeError, () => new constructor().join(Symbol())); assert.throws(TypeError, () => new constructor().join(Symbol()));
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var join = otherGlobal[constructor.name].prototype.join;
var join = createNewGlobal()[constructor.name].prototype.join; assert.sameValue(join.call(new constructor([1, 2, 3]), "\t"), "1\t2\t3");
assert.sameValue(join.call(new constructor([1, 2, 3]), "\t"), "1\t2\t3");
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.keys.length, 0); assert.sameValue(constructor.prototype.keys.length, 0);
assert.sameValue(constructor.prototype.keys.name, "keys"); assert.sameValue(constructor.prototype.keys.name, "keys");
@ -26,12 +29,10 @@ for (var constructor of anyTypedArrayConstructors) {
assert.deepEqual(iterator.next(), {value: undefined, done: true}); assert.deepEqual(iterator.next(), {value: undefined, done: true});
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var keys = otherGlobal[constructor.name].prototype.keys;
var keys = createNewGlobal()[constructor.name].prototype.keys; assert.deepEqual([...keys.call(new constructor(2))], [0, 1]);
assert.deepEqual([...keys.call(new constructor(2))], [0, 1]); arr = new (otherGlobal[constructor.name])(2);
arr = new (createNewGlobal()[constructor.name])(2); assert.sameValue([...constructor.prototype.keys.call(arr)].toString(), "0,1");
assert.sameValue([...constructor.prototype.keys.call(arr)].toString(), "0,1");
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
// Tests for TypedArray#map. // Tests for TypedArray#map.
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.map.length, 1); assert.sameValue(constructor.prototype.map.length, 1);
@ -110,12 +113,10 @@ for (var constructor of anyTypedArrayConstructors) {
}); });
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var map = otherGlobal[constructor.name].prototype.map;
var map = createNewGlobal()[constructor.name].prototype.map; var sum = 0;
var sum = 0; assert.compareArray(map.call(new constructor([1, 2, 3]), v => sum += v), new constructor([1,3,6]));
assert.compareArray(map.call(new constructor([1, 2, 3]), v => sum += v), new constructor([1,3,6])); assert.sameValue(sum, 6);
assert.sameValue(sum, 6);
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
@ -234,13 +235,11 @@ for (var constructor of anyTypedArrayConstructors) {
}); });
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var filter = otherGlobal[constructor.name].prototype.filter;
var filter = createNewGlobal()[constructor.name].prototype.filter; var sum = 0;
var sum = 0; assert.compareArray(filter.call(new constructor([1, 2, 3]), v => {sum += v; return true}),
assert.compareArray(filter.call(new constructor([1, 2, 3]), v => {sum += v; return true}), new constructor([1,2,3]));
new constructor([1,2,3])); assert.sameValue(sum, 6);
assert.sameValue(sum, 6);
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.of.length, 0); assert.sameValue(constructor.of.length, 0);
@ -40,12 +43,10 @@ for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(hits, 1); assert.sameValue(hits, 1);
// Behavior across compartments. // Behavior across compartments.
if (typeof createNewGlobal === "function") { var newC = otherGlobal[constructor.name];
var newC = createNewGlobal()[constructor.name]; assert.sameValue(newC.of() instanceof newC, true);
assert.sameValue(newC.of() instanceof newC, true); assert.sameValue(newC.of() instanceof constructor, false);
assert.sameValue(newC.of() instanceof constructor, false); assert.sameValue(newC.of.call(constructor) instanceof constructor, true);
assert.sameValue(newC.of.call(constructor) instanceof constructor, true);
}
// Throws if `this` isn't a constructor. // Throws if `this` isn't a constructor.
var invalidConstructors = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidConstructors = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
// Tests for TypedArray#reduce. // Tests for TypedArray#reduce.
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.reduce.length, 1); assert.sameValue(constructor.prototype.reduce.length, 1);
@ -80,10 +83,8 @@ for (var constructor of anyTypedArrayConstructors) {
}); });
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var reduce = otherGlobal[constructor.name].prototype.reduce;
var reduce = createNewGlobal()[constructor.name].prototype.reduce; assert.sameValue(reduce.call(arr, (previous, current) => Math.min(previous, current)), 1);
assert.sameValue(reduce.call(arr, (previous, current) => Math.min(previous, current)), 1);
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
@ -173,10 +174,8 @@ for (var constructor of anyTypedArrayConstructors) {
}); });
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var reduceRight = otherGlobal[constructor.name].prototype.reduceRight;
var reduceRight = createNewGlobal()[constructor.name].prototype.reduceRight; assert.sameValue(reduceRight.call(arr, (previous, current) => Math.min(previous, current)), 1);
assert.sameValue(reduceRight.call(arr, (previous, current) => Math.min(previous, current)), 1);
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.deepEqual(constructor.prototype.reverse.length, 0); 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])); assert.deepEqual(new constructor([.1, .2, .3]).reverse(), new constructor([.3, .2, .1]));
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var reverse = otherGlobal[constructor.name].prototype.reverse;
var reverse = createNewGlobal()[constructor.name].prototype.reverse; assert.deepEqual(reverse.call(new constructor([3, 2, 1])), new constructor([1, 2, 3]));
assert.deepEqual(reverse.call(new constructor([3, 2, 1])), new constructor([1, 2, 3]));
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -12,79 +12,76 @@ esid: pending
// Test %TypedArray%.prototype.set(typedArray, offset) when called with wrapped // Test %TypedArray%.prototype.set(typedArray, offset) when called with wrapped
// typed array. // typed array.
if (typeof createNewGlobal === "function") { var otherGlobal = $262.createRealm().global;
var otherGlobal = createNewGlobal();
function taintLengthProperty(obj) { function taintLengthProperty(obj) {
Object.defineProperty(obj, "length", { Object.defineProperty(obj, "length", {
get() { get() {
assert.sameValue(true, false); 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));
} }
});
// 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));
}
}

View File

@ -17,7 +17,7 @@ const float64Constructors = anyTypedArrayConstructors.filter(isFloatConstructor)
.filter(c => c.BYTES_PER_ELEMENT === 8); .filter(c => c.BYTES_PER_ELEMENT === 8);
// Also test with cross-compartment typed arrays. // Also test with cross-compartment typed arrays.
const otherGlobal = createNewGlobal(); const otherGlobal = $262.createRealm().global;
float32Constructors.push(otherGlobal.Float32Array); float32Constructors.push(otherGlobal.Float32Array);
float64Constructors.push(otherGlobal.Float64Array); float64Constructors.push(otherGlobal.Float64Array);

View File

@ -9,7 +9,7 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
const otherGlobal = createNewGlobal(); const otherGlobal = $262.createRealm().global;
// Create with new ArrayBuffer and offset. // Create with new ArrayBuffer and offset.
for (var constructor of typedArrayConstructors) { for (var constructor of typedArrayConstructors) {

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.slice.length, 2); 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])); assert.compareArray(new constructor([1, 2]).slice(1, 5), new constructor([2]));
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var slice = otherGlobal[constructor.name].prototype.slice;
var slice = createNewGlobal()[constructor.name].prototype.slice; assert.compareArray(slice.call(new constructor([3, 2, 1]), 1),
assert.compareArray(slice.call(new constructor([3, 2, 1]), 1), new constructor([2, 1]));
new constructor([2, 1]));
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,

View File

@ -13,8 +13,8 @@ esid: pending
const floatConstructors = anyTypedArrayConstructors.filter(isFloatConstructor); const floatConstructors = anyTypedArrayConstructors.filter(isFloatConstructor);
// Also test with cross-compartment wrapped typed arrays. // 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.Float16Array);
floatConstructors.push(otherGlobal.Float32Array); floatConstructors.push(otherGlobal.Float32Array);
floatConstructors.push(otherGlobal.Float64Array); floatConstructors.push(otherGlobal.Float64Array);

View File

@ -15,10 +15,8 @@ esid: pending
var sortFunctions = [Int32Array.prototype.sort]; var sortFunctions = [Int32Array.prototype.sort];
// Also test with cross-compartment wrapped typed arrays. // Also test with cross-compartment wrapped typed arrays.
if (typeof createNewGlobal === "function") { var otherGlobal = $262.createRealm().global;
var otherGlobal = createNewGlobal(); sortFunctions.push(otherGlobal.Int32Array.prototype.sort);
sortFunctions.push(createNewGlobal().Int32Array.prototype.sort);
}
// The bug manifests itself only with Float arrays, // The bug manifests itself only with Float arrays,
// but checking everything here just for sanity. // but checking everything here just for sanity.

View File

@ -33,20 +33,20 @@ if (typeof $262.detachArrayBuffer === "function") {
assert.sameValue(detached, true); assert.sameValue(detached, true);
} }
let otherGlobal = $262.createRealm().global;
// Ensure detachment check doesn't choke on wrapped typed array. // Ensure detachment check doesn't choke on wrapped typed array.
if (typeof createNewGlobal === "function") { {
let ta = new Int32Array(3); let ta = new Int32Array(3);
let otherGlobal = createNewGlobal();
otherGlobal.Int32Array.prototype.sort.call(ta, function(a, b) { otherGlobal.Int32Array.prototype.sort.call(ta, function(a, b) {
return a - b; return a - b;
}); });
} }
// Ensure detaching buffer in comparator doesn't throw an error when the typed array is wrapped. // 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 detached = false;
let ta = new Int32Array(3); let ta = new Int32Array(3);
let otherGlobal = createNewGlobal();
otherGlobal.Int32Array.prototype.sort.call(ta, function(a,b) { otherGlobal.Int32Array.prototype.sort.call(ta, function(a,b) {
if (!detached) { if (!detached) {
detached = true; detached = true;

View File

@ -10,7 +10,7 @@ description: |
esid: pending esid: pending
---*/ ---*/
// TypedArray.prototype.sort should work across globals // TypedArray.prototype.sort should work across globals
let g2 = createNewGlobal(); let g2 = $262.createRealm().global;
assert.compareArray( assert.compareArray(
Int32Array.prototype.sort.call(new g2.Int32Array([3, 2, 1])), Int32Array.prototype.sort.call(new g2.Int32Array([3, 2, 1])),
new Int32Array([1, 2, 3]) new Int32Array([1, 2, 3])

View File

@ -73,7 +73,7 @@ for (let constructor of anyTypedArrayConstructors) {
Number.prototype.toLocaleString = originalNumberToLocaleString; Number.prototype.toLocaleString = originalNumberToLocaleString;
// Calls Number.prototype.toLocaleString from the current Realm. // Calls Number.prototype.toLocaleString from the current Realm.
const otherGlobal = createNewGlobal(); const otherGlobal = $262.createRealm().global;
for (let constructor of anyTypedArrayConstructors) { for (let constructor of anyTypedArrayConstructors) {
Number.prototype.toLocaleString = function() { Number.prototype.toLocaleString = function() {
"use strict"; "use strict";

View File

@ -12,7 +12,7 @@ esid: pending
const TypedArrayPrototype = Object.getPrototypeOf(Int8Array.prototype); const TypedArrayPrototype = Object.getPrototypeOf(Int8Array.prototype);
const {get: toStringTag} = Object.getOwnPropertyDescriptor(TypedArrayPrototype, Symbol.toStringTag); const {get: toStringTag} = Object.getOwnPropertyDescriptor(TypedArrayPrototype, Symbol.toStringTag);
const otherGlobal = createNewGlobal(); const otherGlobal = $262.createRealm().global;
for (let constructor of anyTypedArrayConstructors) { for (let constructor of anyTypedArrayConstructors) {
let ta = new otherGlobal[constructor.name](0); let ta = new otherGlobal[constructor.name](0);

View File

@ -9,6 +9,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var otherGlobal = $262.createRealm().global;
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(constructor.prototype.values.length, 0); assert.sameValue(constructor.prototype.values.length, 0);
assert.sameValue(constructor.prototype.values.name, "values"); assert.sameValue(constructor.prototype.values.name, "values");
@ -27,12 +30,10 @@ for (var constructor of anyTypedArrayConstructors) {
assert.deepEqual(iterator.next(), {value: undefined, done: true}); assert.deepEqual(iterator.next(), {value: undefined, done: true});
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { var values = otherGlobal[constructor.name].prototype.values;
var values = createNewGlobal()[constructor.name].prototype.values; assert.deepEqual([...values.call(new constructor([42, 36]))], [42, 36]);
assert.deepEqual([...values.call(new constructor([42, 36]))], [42, 36]); arr = new (otherGlobal[constructor.name])([42, 36]);
arr = new (createNewGlobal()[constructor.name])([42, 36]); assert.sameValue([...constructor.prototype.values.call(arr)].toString(), "42,36");
assert.sameValue([...constructor.prototype.values.call(arr)].toString(), "42,36");
}
// Throws if `this` isn't a TypedArray. // Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,