blob: 11b586ffcba08d3974e5419ebe416cf559c2f98c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
load("test-common.js")
try {
const localSym = Symbol("foo");
const globalSym = Symbol.for("foo");
assert(localSym !== globalSym);
assert(localSym !== Symbol("foo"));
assert(globalSym !== Symbol("foo"));
assert(globalSym === Symbol.for("foo"));
assert(localSym.toString() === "Symbol(foo)");
assert(globalSym.toString() === "Symbol(foo)");
assert(Symbol.for(1).description === "1");
assert(Symbol.for(true).description === "true");
assert(Symbol.for({}).description === "[object Object]");
assert(Symbol.for().description === "undefined");
assert(Symbol.for(null).description === "null");
assertThrowsError(() => {
Symbol.for(Symbol());
}, {
error: TypeError,
message: "Cannot convert symbol to string",
});
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
|