1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:17:35 +00:00

LibJS: Add spec comments to SymbolConstructor

This commit is contained in:
Linus Groh 2023-04-12 23:12:54 +02:00
parent 066133d97b
commit 0ae511edae
3 changed files with 35 additions and 10 deletions

View file

@ -34,4 +34,20 @@ ErrorOr<String> Symbol::descriptive_string() const
return String::formatted("Symbol({})", description);
}
// 20.4.5.1 KeyForSymbol ( sym ), https://tc39.es/ecma262/#sec-keyforsymbol
Optional<String> Symbol::key() const
{
// 1. For each element e of the GlobalSymbolRegistry List, do
// a. If SameValue(e.[[Symbol]], sym) is true, return e.[[Key]].
if (m_is_global) {
// NOTE: Global symbols should always have a description string
VERIFY(m_description.has_value());
return m_description;
}
// 2. Assert: GlobalSymbolRegistry does not currently contain an entry for sym.
// 3. Return undefined.
return {};
}
}