Replace createNewGlobal with $262.createRealm().global

This commit is contained in:
André Bargull 2025-04-30 14:15:57 +02:00 committed by Philip Chimento
parent 49fe44d1b3
commit 28238d3b88
29 changed files with 43 additions and 77 deletions

View File

@ -123,7 +123,7 @@ for (let [ctor, answer] of tests) {
}
// @@species from different global
let g = createNewGlobal();
let g = $262.createRealm().global;
g.eval("var MyArrayBuffer = class MyArrayBuffer extends ArrayBuffer {};");
a = arr.buffer;
a.constructor = {

View File

@ -10,7 +10,7 @@ description: |
esid: pending
---*/
const otherGlobal = createNewGlobal();
const otherGlobal = $262.createRealm().global;
const intArrayConstructors = [
otherGlobal.Int32Array,

View File

@ -30,7 +30,7 @@ Date.prototype.valueOf = () => 42;
d = new Date(new Date(8675309));
assert.sameValue(d.getTime(), 8675309);
var D = createNewGlobal().Date;
var D = $262.createRealm().global.Date;
D.prototype.toString = D.prototype.valueOf = null;
var d = new Date(new D(3141592654));

View File

@ -21,7 +21,7 @@ print(BUGNUMBER + ": " + summary);
* BEGIN TEST *
**************/
function allTests()
function allTests(Date)
{
var DS = new Date(2010, 1, 1).toString();
@ -182,13 +182,8 @@ function allTests()
testInOperatorName();
}
allTests();
if (typeof createNewGlobal === "function")
{
Date = createNewGlobal().Date;
allTests();
}
allTests(Date);
allTests($262.createRealm().global.Date);
/******************************************************************************/

View File

@ -74,7 +74,7 @@ assert.throws(TypeError, () => AggregateError());
assert.sameValue(writable, true);
assert.sameValue(value.length, 0);
const g = createNewGlobal();
const g = $262.createRealm().global;
let obj = {};
let errors = new g.AggregateError([obj]).errors;

View File

@ -86,7 +86,7 @@ for (let f of mapped) {
f(10, 20, 30);
}
var g1 = createNewGlobal();
var g1 = $262.createRealm().global;
assert.sameValue(g1.eval(`
function f(a, b, c) {
return arguments[Symbol.iterator].name;
@ -166,7 +166,7 @@ for (let f of unmapped) {
f([10], 20, 30);
}
var g2 = createNewGlobal();
var g2 = $262.createRealm().global;
assert.sameValue(g2.eval(`
function f([a], b, c) {
return arguments[Symbol.iterator].name;

View File

@ -121,7 +121,7 @@ esid: pending
})();
(function checkErrorsComeFromCorrectRealm() {
const otherGlobal = createNewGlobal({newCompartment: true});
const otherGlobal = $262.createRealm().global;
assert.sameValue(TypeError !== otherGlobal.TypeError, true);
assertErrorComesFromCorrectRealm = (fun, thisRealmType) => {

View File

@ -9,7 +9,7 @@ description: |
pending
esid: pending
---*/
var global = createNewGlobal();
var global = $262.createRealm().global;
Promise.prototype.then = global.Promise.prototype.then;
p1 = new Promise(function f(r) {
r(1);

View File

@ -49,7 +49,7 @@ new Proxy(p, {});
new Proxy({}, p);
var g = createNewGlobal();
var g = $262.createRealm().global;
p = g.eval(`var r = Proxy.revocable({}, {}); r.proxy;`);
new Proxy(p, {});

View File

@ -70,7 +70,7 @@ assert.sameValue(Reflect.apply(new Proxy(f, {}),
13);
// Cross-compartment wrappers:
var gw = createNewGlobal();
var gw = $262.createRealm().global;
assert.sameValue(Reflect.apply(gw.parseInt,
undefined,
["45"]),

View File

@ -56,7 +56,7 @@ g = Derived.bind(null, "q");
assert.deepEqual(Reflect.construct(g, [8, 9]), new g(8, 9));
// Cross-compartment wrappers:
var g = createNewGlobal();
var g = $262.createRealm().global;
var local = {here: this};
g.eval("function F(arg) { this.arg = arg }");
assert.deepEqual(Reflect.construct(g.F, [local]), new g.F(local));

View File

@ -40,7 +40,7 @@ var cases = [
keys: ["0", "8", "773", // indexes in numeric order
"str", "-1", "second str", // strings in insertion order
sym, sym2]}, // symbols in insertion order
{object: createNewGlobal().Math, // cross-compartment wrapper
{object: $262.createRealm().global.Math, // cross-compartment wrapper
keys: Reflect.ownKeys(Math)}
];
for (var {object, keys} of cases)

View File

@ -124,7 +124,7 @@ assert.sameValue(log, "sp");
// When calling a cross-compartment wrapper, receiver is rewrapped for the
// target compartment.
var g = createNewGlobal();
var g = $262.createRealm().global;
if (!("assert" in g) && "assert" in globalThis)
g.assert = assert; // necessary when exporting to test262
if (!("assert.sameValue" in g))

View File

@ -14,7 +14,7 @@ var summary = "RegExp constructor should check pattern.constructor.";
print(BUGNUMBER + ": " + summary);
var g = createNewGlobal();
var g = $262.createRealm().global;
var re = /foo/;
assert.sameValue(RegExp(re), re);

View File

@ -39,7 +39,7 @@ assert.sameValue(sourceCalled, false);
assert.sameValue(flagsCalled, false);
// cross-compartment
var g = createNewGlobal();
var g = $262.createRealm().global;
var b = g.eval(`
var b = /foo2/;
var flagsCalled = false;

View File

@ -9,7 +9,7 @@ description: |
pending
esid: pending
---*/
const otherGlobal = createNewGlobal({newCompartment: true});
const otherGlobal = $262.createRealm().global;
let regExp = otherGlobal.eval("/a(b|c)/iy");

View File

@ -32,6 +32,5 @@ function test(otherGlobal) {
assert.sameValue(RegExp.prototype.toString.call(otherRegExp.prototype), "/(?:)/");
}
test(createNewGlobal());
test(createNewGlobal({newCompartment: true}));
test($262.createRealm().global);

View File

@ -25,10 +25,7 @@ TestStringIteratorPrototypeConfusion();
// cross-compartment iterator.
function TestStringIteratorWrappers() {
var iter = ""[Symbol.iterator]();
assert.deepEqual(iter.next.call(createNewGlobal().eval('"x"[Symbol.iterator]()')),
assert.deepEqual(iter.next.call($262.createRealm().global.eval('"x"[Symbol.iterator]()')),
{ value: "x", done: false })
}
if (typeof createNewGlobal === "function") {
TestStringIteratorWrappers();
}
TestStringIteratorWrappers();

View File

@ -81,7 +81,7 @@ assertEqMatchResults("ababcca".matchAll("a"), matchResults("ababcca", /a/g));
// Cross-compartment tests.
{
let otherGlobal = createNewGlobal();
let otherGlobal = $262.createRealm().global;
let iterator = otherGlobal.eval(`"ababcca".matchAll(/a/g)`);
let expected = matchResults("ababcca", /a/g);

View File

@ -13,7 +13,7 @@ function neverCalled() {
assert.sameValue(true, false, "unexpected call");
}
const g = createNewGlobal();
const g = $262.createRealm().global;
assert.sameValue(typeof String.prototype.replaceAll, "function");
assert.sameValue(String.prototype.replaceAll.length, 2);

View File

@ -104,7 +104,7 @@ testBuiltin(WeakSet);
testBuiltin(ArrayBuffer);
testBuiltinTypedArrays();
testBuiltin(DataView, new ArrayBuffer());
testBuiltin(DataView, new (createNewGlobal().ArrayBuffer)());
testBuiltin(DataView, new ($262.createRealm().global.ArrayBuffer)());
testBuiltin(String);
testBuiltin(Array);
testBuiltin(Array, 15);

View File

@ -10,7 +10,7 @@ description: |
esid: pending
---*/
// Make sure we wrap the new target on CCW construct calls.
var g = createNewGlobal();
var g = $262.createRealm().global;
let f = g.eval('(function (expected) { this.accept = new.target === expected; })');

View File

@ -80,7 +80,7 @@ child.testStaticLookups();
assert.sameValue(new Proxy(({ method() { return super.hasOwnProperty("method"); } }), {}).method(), true);
// What about a CCW?
var g = createNewGlobal();
var g = $262.createRealm().global;
var wrappedSuper = g.eval("({ method() { return super.hasOwnProperty('method'); } })");
assert.sameValue(wrappedSuper.method(), true);

View File

@ -33,33 +33,19 @@ function f()
return [this, eval("this")];
}
var otherGlobalSameCompartment = createNewGlobal("same-compartment");
var otherGlobal = $262.createRealm().global;
eval = otherGlobalSameCompartment.eval;
eval = otherGlobal.eval;
res = new f();
assert.sameValue(res[0] !== res[1], true);
assert.sameValue(res[0] !== this, true);
assert.sameValue(res[0] instanceof f, true);
assert.sameValue(res[1], otherGlobalSameCompartment);
assert.sameValue(res[1], otherGlobal);
res = f();
assert.sameValue(res[0] !== res[1], true);
assert.sameValue(res[0], this);
assert.sameValue(res[1], otherGlobalSameCompartment);
var otherGlobalDifferentCompartment = createNewGlobal();
eval = otherGlobalDifferentCompartment.eval;
res = new f();
assert.sameValue(res[0] !== res[1], true);
assert.sameValue(res[0] !== this, true);
assert.sameValue(res[0] instanceof f, true);
assert.sameValue(res[1], otherGlobalDifferentCompartment);
res = f();
assert.sameValue(res[0] !== res[1], true);
assert.sameValue(res[0], this);
assert.sameValue(res[1], otherGlobalDifferentCompartment);
assert.sameValue(res[1], otherGlobal);
/******************************************************************************/

View File

@ -1564,7 +1564,7 @@ function test(sharedMem) {
checkThrow(() => DataView.prototype.buffer, TypeError);
// Protos and proxies, oh my!
var alien = createNewGlobal();
var alien = $262.createRealm().global;
var alien_data = alien.eval('data = ' + JSON.stringify(data1));
var alien_buffer = alien.eval(`buffer = new ${sharedMem ? 'Shared' : ''}ArrayBuffer(data.length)`);
alien.eval('new Uint8Array(buffer).set(data)');

View File

@ -22,7 +22,7 @@ print(BUGNUMBER + ": " + summary);
* BEGIN TEST *
**************/
var g = createNewGlobal();
var g = $262.createRealm().global;
var otherStr = new g.String("foo");
assert.sameValue(otherStr instanceof g.String, true);

View File

@ -12,7 +12,7 @@ esid: pending
// The cycle check in 9.1.2 [[SetPrototypeOf]] prevents cross-realm cycles
// involving only ordinary objects.
var gw = createNewGlobal();
var gw = $262.createRealm().global;
var obj = {};
var w = gw.Object.create(obj);

View File

@ -11,25 +11,14 @@ description: |
pending
esid: pending
---*/
if (typeof createNewGlobal == 'function') {
var gsame = createNewGlobal('same-compartment');
gsame.eval("function f() { return this; }");
f = gsame.f;
assert.sameValue(f(), gsame);
var gnew = $262.createRealm().global;
gsame.eval("function g() { 'use strict'; return this; }");
g = gsame.g;
assert.sameValue(g(), undefined);
gnew.eval("function f() { return this; }");
f = gnew.f;
assert.sameValue(f(), gnew);
var gnew = createNewGlobal();
gnew.eval("function f() { return this; }");
f = gnew.f;
assert.sameValue(f(), gnew);
gnew.eval("function g() { 'use strict'; return this; }");
g = gnew.g;
assert.sameValue(g(), undefined);
}
gnew.eval("function g() { 'use strict'; return this; }");
g = gnew.g;
assert.sameValue(g(), undefined);

View File

@ -21,13 +21,13 @@ print(BUGNUMBER + ": " + summary);
* BEGIN TEST *
**************/
var g = $262.createRealm().global;
function t(code)
{
var strictSemi = " 'use strict'; " + code;
var strictASI = " 'use strict' \n " + code;
var g = createNewGlobal();
g.Function(code);
assert.throws(g.SyntaxError, () => g.Function(strictSemi));