mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:37:36 +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
31
Libraries/LibJS/Tests/Symbol.keyFor.js
Normal file
31
Libraries/LibJS/Tests/Symbol.keyFor.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
load("test-common.js")
|
||||
|
||||
try {
|
||||
const localSym = Symbol("foo");
|
||||
const globalSym = Symbol.for("foo");
|
||||
|
||||
assert(Symbol.keyFor(localSym) === undefined);
|
||||
assert(Symbol.keyFor(globalSym) === "foo");
|
||||
|
||||
const testThrows = (value, str) => {
|
||||
assertThrowsError(() => {
|
||||
Symbol.keyFor(value);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: str + " is not a symbol",
|
||||
});
|
||||
};
|
||||
|
||||
testThrows(1, "1");
|
||||
testThrows(null, "null");
|
||||
testThrows(undefined, "undefined");
|
||||
testThrows([], "[object Array]");
|
||||
testThrows({}, "[object Object]");
|
||||
testThrows(true, "true");
|
||||
testThrows("foobar", "foobar");
|
||||
testThrows(function(){}, "[object ScriptFunction]"); // FIXME: Better function stringification
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue