From f6cf44c3db77bbfc51b950b9abb01d5251fff990 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 18 Oct 2021 19:44:46 +0100 Subject: LibJS: Convert this_bigint_value() to ThrowCompletionOr --- Userland/Libraries/LibJS/Runtime/BigIntObject.h | 4 +++- Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp | 16 +++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibJS/Runtime/BigIntObject.h b/Userland/Libraries/LibJS/Runtime/BigIntObject.h index 11175a4d30..461f109d79 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntObject.h +++ b/Userland/Libraries/LibJS/Runtime/BigIntObject.h @@ -20,7 +20,9 @@ public: BigIntObject(BigInt&, Object& prototype); virtual ~BigIntObject(); - const BigInt& bigint() const { return m_bigint; } + BigInt const& bigint() const { return m_bigint; } + BigInt& bigint() { return m_bigint; } + virtual Value value_of() const override { return Value(&m_bigint); diff --git a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp index 2617759d80..cacaf41d20 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -36,23 +37,20 @@ BigIntPrototype::~BigIntPrototype() } // thisBigIntValue ( value ), https://tc39.es/ecma262/#thisbigintvalue -static Value this_bigint_value(GlobalObject& global_object, Value value) +static ThrowCompletionOr this_bigint_value(GlobalObject& global_object, Value value) { if (value.is_bigint()) - return value; + return &value.as_bigint(); if (value.is_object() && is(value.as_object())) return &static_cast(value.as_object()).bigint(); auto& vm = global_object.vm(); - vm.throw_exception(global_object, ErrorType::NotAnObjectOfType, "BigInt"); - return {}; + return vm.throw_completion(global_object, ErrorType::NotAnObjectOfType, "BigInt"); } // 21.2.3.3 BigInt.prototype.toString ( [ radix ] ), https://tc39.es/ecma262/#sec-bigint.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string) { - auto bigint_value = this_bigint_value(global_object, vm.this_value(global_object)); - if (vm.exception()) - return {}; + auto* bigint = TRY_OR_DISCARD(this_bigint_value(global_object, vm.this_value(global_object))); double radix = 10; if (!vm.argument(0).is_undefined()) { radix = TRY_OR_DISCARD(vm.argument(0).to_integer_or_infinity(global_object)); @@ -61,7 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string) return {}; } } - return js_string(vm, bigint_value.as_bigint().big_integer().to_base(radix)); + return js_string(vm, bigint->big_integer().to_base(radix)); } // 21.2.3.2 BigInt.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-bigint.prototype.tolocalestring @@ -73,7 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string) // 21.2.3.4 BigInt.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-bigint.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::value_of) { - return this_bigint_value(global_object, vm.this_value(global_object)); + return TRY_OR_DISCARD(this_bigint_value(global_object, vm.this_value(global_object))); } } -- cgit v1.2.3