mirror of
https://github.com/tc39/test262.git
synced 2025-09-24 10:38:30 +02:00
Replace createNewGlobal with $262.createRealm().global in sm/Symbol
This commit is contained in:
parent
d24dd57c58
commit
49fe44d1b3
@ -13,32 +13,26 @@ esid: pending
|
|||||||
---*/
|
---*/
|
||||||
// Symbols can be shared across realms.
|
// Symbols can be shared across realms.
|
||||||
|
|
||||||
if (typeof Reflect !== "undefined" && typeof Reflect.Realm === "function") {
|
var g = $262.createRealm().global;
|
||||||
throw new Error("Congratulations on implementing Reflect.Realm! " +
|
var gj = g.eval("jones = Symbol('jones')");
|
||||||
"Please update this test to use it.");
|
assert.sameValue(typeof gj, "symbol");
|
||||||
}
|
assert.sameValue(g.jones, g.jones);
|
||||||
if (typeof createNewGlobal === "function") {
|
assert.sameValue(gj, g.jones);
|
||||||
var g = createNewGlobal();
|
assert.sameValue(gj !== Symbol("jones"), true);
|
||||||
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;
|
// A symbol can be round-tripped to another realm and back;
|
||||||
// the result is the original symbol.
|
// the result is the original symbol.
|
||||||
var smith = Symbol("smith");
|
var smith = Symbol("smith");
|
||||||
g.smith = smith; // put smith into the realm
|
g.smith = smith; // put smith into the realm
|
||||||
assert.sameValue(g.smith, smith); // pull it back out
|
assert.sameValue(g.smith, smith); // pull it back out
|
||||||
|
|
||||||
// Spot-check that non-generic methods can be applied to symbols and Symbol
|
// Spot-check that non-generic methods can be applied to symbols and Symbol
|
||||||
// objects from other realms.
|
// objects from other realms.
|
||||||
assert.sameValue(Symbol.prototype.toString.call(gj), "Symbol(jones)");
|
assert.sameValue(Symbol.prototype.toString.call(gj), "Symbol(jones)");
|
||||||
assert.sameValue(Symbol.prototype.toString.call(g.eval("Object(Symbol('brown'))")),
|
assert.sameValue(Symbol.prototype.toString.call(g.eval("Object(Symbol('brown'))")),
|
||||||
"Symbol(brown)");
|
"Symbol(brown)");
|
||||||
|
|
||||||
// Symbol.for functions share a symbol registry across all realms.
|
// Symbol.for functions share a symbol registry across all realms.
|
||||||
assert.sameValue(g.Symbol.for("ponies"), Symbol.for("ponies"));
|
assert.sameValue(g.Symbol.for("ponies"), Symbol.for("ponies"));
|
||||||
assert.sameValue(g.eval("Symbol.for('rainbows')"), Symbol.for("rainbows"));
|
assert.sameValue(g.eval("Symbol.for('rainbows')"), Symbol.for("rainbows"));
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ assert.sameValue(obj[Symbol.toPrimitive](Math.atan2), sym);
|
|||||||
assert.sameValue(sym[Symbol.toPrimitive](), sym);
|
assert.sameValue(sym[Symbol.toPrimitive](), sym);
|
||||||
|
|
||||||
// Or a wrapper to a Symbol object in another compartment.
|
// 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);
|
assert.sameValue(obj2[Symbol.toPrimitive]("default"), sym);
|
||||||
|
|
||||||
// Otherwise a TypeError is thrown.
|
// Otherwise a TypeError is thrown.
|
||||||
|
@ -25,6 +25,8 @@ var names = [
|
|||||||
"asyncIterator"
|
"asyncIterator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var g = $262.createRealm().global;
|
||||||
|
|
||||||
for (var name of names) {
|
for (var name of names) {
|
||||||
// Well-known symbols exist.
|
// Well-known symbols exist.
|
||||||
assert.sameValue(typeof Symbol[name], "symbol");
|
assert.sameValue(typeof Symbol[name], "symbol");
|
||||||
@ -33,12 +35,7 @@ for (var name of names) {
|
|||||||
assert.sameValue(Symbol[name] !== Symbol.for("Symbol." + name), true);
|
assert.sameValue(Symbol[name] !== Symbol.for("Symbol." + name), true);
|
||||||
|
|
||||||
// They are shared across realms.
|
// They are shared across realms.
|
||||||
if (typeof Realm === 'function')
|
assert.sameValue(Symbol[name], g.Symbol[name]);
|
||||||
throw new Error("please update this test to use Realms");
|
|
||||||
if (typeof createNewGlobal === 'function') {
|
|
||||||
var g = createNewGlobal();
|
|
||||||
assert.sameValue(Symbol[name], g.Symbol[name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Descriptor is all false.
|
// Descriptor is all false.
|
||||||
var desc = Object.getOwnPropertyDescriptor(Symbol, name);
|
var desc = Object.getOwnPropertyDescriptor(Symbol, name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user