mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 14:37:45 +00:00
LibJS: Replace standalone js_symbol() with Symbol::create()
This commit is contained in:
parent
525f22d018
commit
1dd8655514
4 changed files with 12 additions and 15 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -16,14 +17,9 @@ Symbol::Symbol(Optional<DeprecatedString> description, bool is_global)
|
|||
{
|
||||
}
|
||||
|
||||
Symbol* js_symbol(Heap& heap, Optional<DeprecatedString> description, bool is_global)
|
||||
NonnullGCPtr<Symbol> Symbol::create(VM& vm, Optional<DeprecatedString> description, bool is_global)
|
||||
{
|
||||
return heap.allocate_without_realm<Symbol>(move(description), is_global);
|
||||
}
|
||||
|
||||
Symbol* js_symbol(VM& vm, Optional<DeprecatedString> description, bool is_global)
|
||||
{
|
||||
return js_symbol(vm.heap(), move(description), is_global);
|
||||
return *vm.heap().allocate_without_realm<Symbol>(move(description), is_global);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -16,6 +17,8 @@ class Symbol final : public Cell {
|
|||
JS_CELL(Symbol, Cell);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static NonnullGCPtr<Symbol> create(VM&, Optional<DeprecatedString> description, bool is_global);
|
||||
|
||||
virtual ~Symbol() = default;
|
||||
|
||||
DeprecatedString description() const { return m_description.value_or(""); }
|
||||
|
@ -30,7 +33,4 @@ private:
|
|||
bool m_is_global;
|
||||
};
|
||||
|
||||
Symbol* js_symbol(Heap&, Optional<DeprecatedString> description, bool is_global);
|
||||
Symbol* js_symbol(VM&, Optional<DeprecatedString> description, bool is_global);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -40,8 +41,8 @@ ThrowCompletionOr<Value> SymbolConstructor::call()
|
|||
{
|
||||
auto& vm = this->vm();
|
||||
if (vm.argument(0).is_undefined())
|
||||
return js_symbol(vm, {}, false);
|
||||
return js_symbol(vm, TRY(vm.argument(0).to_string(vm)), false);
|
||||
return Symbol::create(vm, {}, false);
|
||||
return Symbol::create(vm, TRY(vm.argument(0).to_string(vm)), false);
|
||||
}
|
||||
|
||||
// 20.4.1.1 Symbol ( [ description ] ), https://tc39.es/ecma262/#sec-symbol-description
|
||||
|
@ -67,10 +68,10 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::for_)
|
|||
VERIFY(!result.has_value());
|
||||
|
||||
// 4. Let newSymbol be a new unique Symbol value whose [[Description]] value is stringKey.
|
||||
auto* new_symbol = js_symbol(vm, string_key, true);
|
||||
auto new_symbol = Symbol::create(vm, string_key, true);
|
||||
|
||||
// 5. Append the Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to the GlobalSymbolRegistry List.
|
||||
vm.global_symbol_registry().set(string_key, *new_symbol);
|
||||
vm.global_symbol_registry().set(string_key, new_symbol);
|
||||
|
||||
// 6. Return newSymbol.
|
||||
return new_symbol;
|
||||
|
|
|
@ -140,7 +140,7 @@ VM::VM(OwnPtr<CustomData> custom_data)
|
|||
};
|
||||
|
||||
#define __JS_ENUMERATE(SymbolName, snake_name) \
|
||||
m_well_known_symbol_##snake_name = js_symbol(*this, "Symbol." #SymbolName, false);
|
||||
m_well_known_symbol_##snake_name = Symbol::create(*this, "Symbol." #SymbolName, false);
|
||||
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
|
||||
#undef __JS_ENUMERATE
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue