diff options
author | Linus Groh <mail@linusgroh.de> | 2021-10-18 19:51:43 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-18 21:24:30 +0100 |
commit | 08db3b9f66fbedf0a89591597edbf1de9fdbb71a (patch) | |
tree | 1288b6cede90430ed9806c7226af7de047df7fb0 /Userland/Libraries/LibJS | |
parent | 60366ae03239b9987539e9359ed06276488f50ec (diff) | |
download | serenity-08db3b9f66fbedf0a89591597edbf1de9fdbb71a.zip |
LibJS: Convert this_symbol_value() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibJS')
-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))); } } |