mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
LibJS: Add symbol objects
This commit adds the following classes: SymbolObject, SymbolConstructor, SymbolPrototype, and Symbol. This commit does not introduce any new functionality to the Object class, so they cannot be used as property keys in objects.
This commit is contained in:
parent
b5b08fba92
commit
4ced126704
21 changed files with 819 additions and 3 deletions
26
Libraries/LibJS/Tests/Symbol.js
Normal file
26
Libraries/LibJS/Tests/Symbol.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
load("test-common.js")
|
||||
|
||||
try {
|
||||
const s1 = Symbol("foo");
|
||||
const s2 = Symbol("foo");
|
||||
|
||||
assert(s1 !== s2);
|
||||
assert(s1.description === "foo");
|
||||
assert(s2.description === "foo");
|
||||
|
||||
s1.description = "bar";
|
||||
assert(s1.description === "foo");
|
||||
|
||||
assert(typeof s1 === "symbol");
|
||||
|
||||
assertThrowsError(() => {
|
||||
Symbol(Symbol('foo'));
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "Can't convert symbol to string"
|
||||
})
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue