Replace createNewGlobal with $262.createRealm().global in sm/Array

This commit is contained in:
André Bargull 2025-04-30 14:15:56 +02:00 committed by Philip Chimento
parent 4ea90c4681
commit d24dd57c58
5 changed files with 32 additions and 36 deletions

View File

@ -29,6 +29,4 @@ function test(otherGlobal) {
}
}
test(createNewGlobal());
test(createNewGlobal({newCompartment: true}));
test($262.createRealm().global);

View File

@ -83,6 +83,4 @@ function test(otherGlobal) {
}
}
test(createNewGlobal());
test(createNewGlobal({newCompartment: true}));
test($262.createRealm().global);

View File

@ -11,35 +11,34 @@ description: |
pending
esid: pending
---*/
if (typeof createNewGlobal === 'function') {
// G.Array.from, where G is any global, produces an array whose prototype
// is G.Array.prototype.
var g = createNewGlobal();
var ga = g.Array.from([1, 2, 3]);
assert.sameValue(ga instanceof g.Array, true);
// Even if G.Array is not passed in as the 'this' value to the call.
var from = g.Array.from
var ga2 = from([1, 2, 3]);
assert.sameValue(ga2 instanceof g.Array, true);
// G.Array.from, where G is any global, produces an array whose prototype
// is G.Array.prototype.
var g = $262.createRealm().global;
var ga = g.Array.from([1, 2, 3]);
assert.sameValue(ga instanceof g.Array, true);
// Array.from can be applied to a constructor from another realm.
var p = Array.from.call(g.Array, [1, 2, 3]);
assert.sameValue(p instanceof g.Array, true);
var q = g.Array.from.call(Array, [3, 4, 5]);
assert.sameValue(q instanceof Array, true);
// Even if G.Array is not passed in as the 'this' value to the call.
var from = g.Array.from
var ga2 = from([1, 2, 3]);
assert.sameValue(ga2 instanceof g.Array, true);
// The default 'this' value received by a non-strict mapping function is
// that function's global, not Array.from's global or the caller's global.
var h = createNewGlobal(), result = undefined;
h.mainGlobal = this;
h.eval("function f() { mainGlobal.result = this; }");
g.Array.from.call(Array, [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";
assert.sameValue(result.globalName, "h");
}
// Array.from can be applied to a constructor from another realm.
var p = Array.from.call(g.Array, [1, 2, 3]);
assert.sameValue(p instanceof g.Array, true);
var q = g.Array.from.call(Array, [3, 4, 5]);
assert.sameValue(q instanceof Array, true);
// The default 'this' value received by a non-strict mapping function is
// that function's global, not Array.from's global or the caller's global.
var h = $262.createRealm().global;
var result = undefined;
h.mainGlobal = this;
h.eval("function f() { mainGlobal.result = this; }");
g.Array.from.call(Array, [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";
assert.sameValue(result.globalName, "h");

View File

@ -12,7 +12,7 @@ description: |
esid: pending
---*/
var global = this;
var otherGlobal = createNewGlobal();
var otherGlobal = $262.createRealm().global;
var thisGlobal = () => global;
var alternateGlobals = (function(i) {

View File

@ -14,6 +14,8 @@ var summary = 'Use ArraySpeciesCreate in Array.prototype.{concat,filter,map,slic
print(BUGNUMBER + ": " + summary);
var g = $262.createRealm().global;
function test(funcName, args, expectedLength, expectedLogs) {
// modified @@species
function FakeArray(n) {
@ -128,7 +130,6 @@ function test(funcName, args, expectedLength, expectedLogs) {
assert.sameValue(b.constructor, Array);
// @@species from different global
var g = createNewGlobal();
g.eval("function FakeArray(n) { this.length = n; }");
a = [1, 2, 3, 4, 5];
a.constructor = {