From 08fb31087bfe8cc7a9b4d7ea94fcf030123ba527 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Fri, 29 Oct 2021 00:41:04 +0300 Subject: [PATCH] LibJS: Convert BooleanPrototype functions to ThrowCompletionOr --- .../LibJS/Runtime/BooleanPrototype.cpp | 20 ++++++++----------- .../LibJS/Runtime/BooleanPrototype.h | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp index 21af8ada91..fd5abfed30 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp @@ -22,8 +22,8 @@ void BooleanPrototype::initialize(GlobalObject& global_object) auto& vm = this->vm(); BooleanObject::initialize(global_object); u8 attr = Attribute::Writable | Attribute::Configurable; - define_old_native_function(vm.names.toString, to_string, 0, attr); - define_old_native_function(vm.names.valueOf, value_of, 0, attr); + define_native_function(vm.names.toString, to_string, 0, attr); + define_native_function(vm.names.valueOf, value_of, 0, attr); } BooleanPrototype::~BooleanPrototype() @@ -31,30 +31,26 @@ BooleanPrototype::~BooleanPrototype() } // 20.3.3.2 Boolean.prototype.toString ( ), https://tc39.es/ecma262/#sec-boolean.prototype.tostring -JS_DEFINE_OLD_NATIVE_FUNCTION(BooleanPrototype::to_string) +JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::to_string) { auto this_value = vm.this_value(global_object); if (this_value.is_boolean()) return js_string(vm, this_value.as_bool() ? "true" : "false"); - if (!this_value.is_object() || !is(this_value.as_object())) { - vm.throw_exception(global_object, ErrorType::NotAnObjectOfType, "Boolean"); - return {}; - } + if (!this_value.is_object() || !is(this_value.as_object())) + return vm.throw_completion(global_object, ErrorType::NotAnObjectOfType, "Boolean"); bool bool_value = static_cast(this_value.as_object()).value_of().as_bool(); return js_string(vm, bool_value ? "true" : "false"); } // 20.3.3.3 Boolean.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-boolean.prototype.valueof -JS_DEFINE_OLD_NATIVE_FUNCTION(BooleanPrototype::value_of) +JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::value_of) { auto this_value = vm.this_value(global_object); if (this_value.is_boolean()) return this_value; - if (!this_value.is_object() || !is(this_value.as_object())) { - vm.throw_exception(global_object, ErrorType::NotAnObjectOfType, "Boolean"); - return {}; - } + if (!this_value.is_object() || !is(this_value.as_object())) + return vm.throw_completion(global_object, ErrorType::NotAnObjectOfType, "Boolean"); return static_cast(this_value.as_object()).value_of(); } diff --git a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.h b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.h index 0e6d65e199..9b5683c874 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.h @@ -19,8 +19,8 @@ public: virtual ~BooleanPrototype() override; private: - JS_DECLARE_OLD_NATIVE_FUNCTION(to_string); - JS_DECLARE_OLD_NATIVE_FUNCTION(value_of); + JS_DECLARE_NATIVE_FUNCTION(to_string); + JS_DECLARE_NATIVE_FUNCTION(value_of); }; }