ladybird/Libraries/LibJS/Tests/Symbol.keyFor.js
mattco98 4ced126704 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.
2020-05-17 18:05:15 +02:00

31 lines
836 B
JavaScript

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);
}