From 233bb899292172e6aa994ac92d4cec83b4298416 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 18 Oct 2021 19:46:30 +0100 Subject: [PATCH] LibJS: Convert this_number_value() to ThrowCompletionOr --- .../LibJS/Runtime/NumberPrototype.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp index 7947a7e9bb..8fc0a9f980 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -45,24 +46,20 @@ NumberPrototype::~NumberPrototype() } // thisNumberValue ( value ), https://tc39.es/ecma262/#thisnumbervalue -static Value this_number_value(GlobalObject& global_object, Value value) +static ThrowCompletionOr this_number_value(GlobalObject& global_object, Value value) { if (value.is_number()) return value; if (value.is_object() && is(value.as_object())) return static_cast(value.as_object()).value_of(); auto& vm = global_object.vm(); - vm.throw_exception(global_object, ErrorType::NotAnObjectOfType, "Number"); - return {}; + return vm.throw_completion(global_object, ErrorType::NotAnObjectOfType, "Number"); } // 21.1.3.3 Number.prototype.toFixed ( fractionDigits ), https://tc39.es/ecma262/#sec-number.prototype.tofixed JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed) { - auto number_value = this_number_value(global_object, vm.this_value(global_object)); - if (vm.exception()) - return {}; - + auto number_value = TRY_OR_DISCARD(this_number_value(global_object, vm.this_value(global_object))); auto fraction_digits = TRY_OR_DISCARD(vm.argument(0).to_integer_or_infinity(global_object)); if (!vm.argument(0).is_finite_number()) { vm.throw_exception(global_object, ErrorType::InvalidFractionDigits); @@ -87,10 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed) // 21.1.3.6 Number.prototype.toString ( [ radix ] ), https://tc39.es/ecma262/#sec-number.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string) { - auto number_value = this_number_value(global_object, vm.this_value(global_object)); - if (vm.exception()) - return {}; - + auto number_value = TRY_OR_DISCARD(this_number_value(global_object, vm.this_value(global_object))); double radix_argument = 10; auto argument = vm.argument(0); if (!vm.argument(0).is_undefined()) @@ -162,7 +156,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string) // 21.1.3.7 Number.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-number.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::value_of) { - return this_number_value(global_object, vm.this_value(global_object)); + return TRY_OR_DISCARD(this_number_value(global_object, vm.this_value(global_object))); } }