Skip to content

Commit

Permalink
LibJS: Port this_symbol_value() to NonnullGCPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
linusg committed Apr 15, 2023
1 parent dd91f1a commit b110258
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ ThrowCompletionOr<void> SymbolPrototype::initialize(Realm& realm)
}

// thisSymbolValue ( value ), https://tc39.es/ecma262/#thissymbolvalue
static ThrowCompletionOr<Symbol*> this_symbol_value(VM& vm, Value value)
static ThrowCompletionOr<NonnullGCPtr<Symbol>> this_symbol_value(VM& vm, Value value)
{
// 1. If value is a Symbol, return value.
if (value.is_symbol())
return &value.as_symbol();
return value.as_symbol();

// 2. If value is an Object and value has a [[SymbolData]] internal slot, then
if (value.is_object() && is<SymbolObject>(value.as_object())) {
// a. Let s be value.[[SymbolData]].
// b. Assert: s is a Symbol.
// c. Return s.
return &static_cast<SymbolObject&>(value.as_object()).primitive_symbol();
return static_cast<SymbolObject&>(value.as_object()).primitive_symbol();
}

// 3. Throw a TypeError exception.
Expand All @@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::description_getter)
{
// 1. Let s be the this value.
// 2. Let sym be ? thisSymbolValue(s).
auto* symbol = TRY(this_symbol_value(vm, vm.this_value()));
auto symbol = TRY(this_symbol_value(vm, vm.this_value()));

// 3. Return sym.[[Description]].
auto& description = symbol->description();
Expand All @@ -76,7 +76,7 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::description_getter)
JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string)
{
// 1. Let sym be ? thisSymbolValue(this value).
auto* symbol = TRY(this_symbol_value(vm, vm.this_value()));
auto symbol = TRY(this_symbol_value(vm, vm.this_value()));

// 2. Return SymbolDescriptiveString(sym).
return PrimitiveString::create(vm, TRY_OR_THROW_OOM(vm, symbol->descriptive_string()));
Expand Down

0 comments on commit b110258

Please sign in to comment.