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

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

View File

@ -13,32 +13,26 @@ esid: pending
---*/
// Symbols can be shared across realms.
if (typeof Reflect !== "undefined" && typeof Reflect.Realm === "function") {
throw new Error("Congratulations on implementing Reflect.Realm! " +
"Please update this test to use it.");
}
if (typeof createNewGlobal === "function") {
var g = createNewGlobal();
var gj = g.eval("jones = Symbol('jones')");
assert.sameValue(typeof gj, "symbol");
assert.sameValue(g.jones, g.jones);
assert.sameValue(gj, g.jones);
assert.sameValue(gj !== Symbol("jones"), true);
var g = $262.createRealm().global;
var gj = g.eval("jones = Symbol('jones')");
assert.sameValue(typeof gj, "symbol");
assert.sameValue(g.jones, g.jones);
assert.sameValue(gj, g.jones);
assert.sameValue(gj !== Symbol("jones"), true);
// A symbol can be round-tripped to another realm and back;
// the result is the original symbol.
var smith = Symbol("smith");
g.smith = smith; // put smith into the realm
assert.sameValue(g.smith, smith); // pull it back out
// A symbol can be round-tripped to another realm and back;
// the result is the original symbol.
var smith = Symbol("smith");
g.smith = smith; // put smith into the realm
assert.sameValue(g.smith, smith); // pull it back out
// Spot-check that non-generic methods can be applied to symbols and Symbol
// objects from other realms.
assert.sameValue(Symbol.prototype.toString.call(gj), "Symbol(jones)");
assert.sameValue(Symbol.prototype.toString.call(g.eval("Object(Symbol('brown'))")),
"Symbol(brown)");
// Spot-check that non-generic methods can be applied to symbols and Symbol
// objects from other realms.
assert.sameValue(Symbol.prototype.toString.call(gj), "Symbol(jones)");
assert.sameValue(Symbol.prototype.toString.call(g.eval("Object(Symbol('brown'))")),
"Symbol(brown)");
// Symbol.for functions share a symbol registry across all realms.
assert.sameValue(g.Symbol.for("ponies"), Symbol.for("ponies"));
assert.sameValue(g.eval("Symbol.for('rainbows')"), Symbol.for("rainbows"));
}
// Symbol.for functions share a symbol registry across all realms.
assert.sameValue(g.Symbol.for("ponies"), Symbol.for("ponies"));
assert.sameValue(g.eval("Symbol.for('rainbows')"), Symbol.for("rainbows"));

View File

@ -26,7 +26,7 @@ assert.sameValue(obj[Symbol.toPrimitive](Math.atan2), sym);
assert.sameValue(sym[Symbol.toPrimitive](), sym);
// Or a wrapper to a Symbol object in another compartment.
var obj2 = createNewGlobal().Object(sym);
var obj2 = $262.createRealm().global.Object(sym);
assert.sameValue(obj2[Symbol.toPrimitive]("default"), sym);
// Otherwise a TypeError is thrown.

View File

@ -25,6 +25,8 @@ var names = [
"asyncIterator"
];
var g = $262.createRealm().global;
for (var name of names) {
// Well-known symbols exist.
assert.sameValue(typeof Symbol[name], "symbol");
@ -33,12 +35,7 @@ for (var name of names) {
assert.sameValue(Symbol[name] !== Symbol.for("Symbol." + name), true);
// They are shared across realms.
if (typeof Realm === 'function')
throw new Error("please update this test to use Realms");
if (typeof createNewGlobal === 'function') {
var g = createNewGlobal();
assert.sameValue(Symbol[name], g.Symbol[name]);
}
assert.sameValue(Symbol[name], g.Symbol[name]);
// Descriptor is all false.
var desc = Object.getOwnPropertyDescriptor(Symbol, name);