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

LibJS: Port Symbol to String

This includes the VM's global_symbol_registry HashMap, which can now
store String keys.
This commit is contained in:
Linus Groh 2023-02-11 16:14:41 +00:00
parent 5e72fde954
commit a8bf2f8e4c
11 changed files with 27 additions and 27 deletions

View file

@ -11,27 +11,27 @@
namespace JS {
Symbol::Symbol(Optional<DeprecatedString> description, bool is_global)
Symbol::Symbol(Optional<String> description, bool is_global)
: m_description(move(description))
, m_is_global(is_global)
{
}
NonnullGCPtr<Symbol> Symbol::create(VM& vm, Optional<DeprecatedString> description, bool is_global)
NonnullGCPtr<Symbol> Symbol::create(VM& vm, Optional<String> description, bool is_global)
{
return vm.heap().allocate_without_realm<Symbol>(move(description), is_global);
}
// 20.4.3.3.1 SymbolDescriptiveString ( sym ), https://tc39.es/ecma262/#sec-symboldescriptivestring
DeprecatedString Symbol::descriptive_string() const
ErrorOr<String> Symbol::descriptive_string() const
{
// 1. Let desc be sym's [[Description]] value.
// 2. If desc is undefined, set desc to the empty String.
// 3. Assert: desc is a String.
auto description = m_description.value_or("");
auto description = m_description.value_or(String {});
// 4. Return the string-concatenation of "Symbol(", desc, and ")".
return DeprecatedString::formatted("Symbol({})", description);
return String::formatted("Symbol({})", description);
}
}