diff options
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp index bd97834680..e8dc16e15e 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp @@ -7,6 +7,7 @@ #include <AK/Function.h> #include <AK/TypeCasts.h> +#include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/Object.h> @@ -41,24 +42,21 @@ SymbolPrototype::~SymbolPrototype() } // thisSymbolValue ( value ), https://tc39.es/ecma262/#thissymbolvalue -static Value this_symbol_value(GlobalObject& global_object, Value value) +static ThrowCompletionOr<Symbol*> this_symbol_value(GlobalObject& global_object, Value value) { if (value.is_symbol()) - return value; + return &value.as_symbol(); if (value.is_object() && is<SymbolObject>(value.as_object())) - return static_cast<SymbolObject&>(value.as_object()).value_of(); + return &static_cast<SymbolObject&>(value.as_object()).primitive_symbol(); auto& vm = global_object.vm(); - vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Symbol"); - return {}; + return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Symbol"); } // 20.4.3.2 get Symbol.prototype.description, https://tc39.es/ecma262/#sec-symbol.prototype.description JS_DEFINE_NATIVE_GETTER(SymbolPrototype::description_getter) { - auto symbol_value = this_symbol_value(global_object, vm.this_value(global_object)); - if (vm.exception()) - return {}; - auto& description = symbol_value.as_symbol().raw_description(); + auto* symbol = TRY_OR_DISCARD(this_symbol_value(global_object, vm.this_value(global_object))); + auto& description = symbol->raw_description(); if (!description.has_value()) return js_undefined(); return js_string(vm, *description); @@ -67,23 +65,21 @@ JS_DEFINE_NATIVE_GETTER(SymbolPrototype::description_getter) // 20.4.3.3 Symbol.prototype.toString ( ), https://tc39.es/ecma262/#sec-symbol.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string) { - auto symbol_value = this_symbol_value(global_object, vm.this_value(global_object)); - if (vm.exception()) - return {}; - return js_string(vm, symbol_value.as_symbol().to_string()); + auto* symbol = TRY_OR_DISCARD(this_symbol_value(global_object, vm.this_value(global_object))); + return js_string(vm, symbol->to_string()); } // 20.4.3.4 Symbol.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-symbol.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::value_of) { - return this_symbol_value(global_object, vm.this_value(global_object)); + return TRY_OR_DISCARD(this_symbol_value(global_object, vm.this_value(global_object))); } // 20.4.3.5 Symbol.prototype [ @@toPrimitive ] ( hint ), https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::symbol_to_primitive) { // The hint argument is ignored. - return this_symbol_value(global_object, vm.this_value(global_object)); + return TRY_OR_DISCARD(this_symbol_value(global_object, vm.this_value(global_object))); } } |