diff --git a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp index c60e25f773..d890f6fb8b 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp @@ -26,28 +26,26 @@ void ErrorPrototype::initialize(GlobalObject& global_object) u8 attr = Attribute::Writable | Attribute::Configurable; define_direct_property(vm.names.name, js_string(vm, "Error"), attr); define_direct_property(vm.names.message, js_string(vm, ""), attr); - define_old_native_function(vm.names.toString, to_string, 0, attr); + define_native_function(vm.names.toString, to_string, 0, attr); } // 20.5.3.4 Error.prototype.toString ( ), https://tc39.es/ecma262/#sec-error.prototype.tostring -JS_DEFINE_OLD_NATIVE_FUNCTION(ErrorPrototype::to_string) +JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string) { auto this_value = vm.this_value(global_object); - if (!this_value.is_object()) { - vm.throw_exception(global_object, ErrorType::NotAnObject, this_value.to_string_without_side_effects()); - return {}; - } + if (!this_value.is_object()) + return vm.throw_completion(global_object, ErrorType::NotAnObject, this_value.to_string_without_side_effects()); auto& this_object = this_value.as_object(); String name = "Error"; - auto name_property = TRY_OR_DISCARD(this_object.get(vm.names.name)); + auto name_property = TRY(this_object.get(vm.names.name)); if (!name_property.is_undefined()) - name = TRY_OR_DISCARD(name_property.to_string(global_object)); + name = TRY(name_property.to_string(global_object)); String message = ""; - auto message_property = TRY_OR_DISCARD(this_object.get(vm.names.message)); + auto message_property = TRY(this_object.get(vm.names.message)); if (!message_property.is_undefined()) - message = TRY_OR_DISCARD(message_property.to_string(global_object)); + message = TRY(message_property.to_string(global_object)); if (name.is_empty()) return js_string(vm, message); diff --git a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.h b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.h index 64f9a7cee3..081a19666c 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.h @@ -19,7 +19,7 @@ public: virtual ~ErrorPrototype() override = default; private: - JS_DECLARE_OLD_NATIVE_FUNCTION(to_string); + JS_DECLARE_NATIVE_FUNCTION(to_string); }; #define DECLARE_NATIVE_ERROR_PROTOTYPE(ClassName, snake_name, PrototypeName, ConstructorName) \