From df181809fda75c88310cca76baaa1cfd1975b66e Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sat, 16 Oct 2021 21:56:14 +0300 Subject: [PATCH] LibJS: Convert to_bigint_int64() to ThrowCompletionOr --- Tests/LibWasm/test-wasm.cpp | 2 +- Userland/Libraries/LibJS/Runtime/ArrayBuffer.h | 3 ++- Userland/Libraries/LibJS/Runtime/Value.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/Value.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 0f6a8ad4ba..9bbb59e778 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -229,7 +229,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke) break; case Wasm::ValueType::Kind::I64: if (argument.is_bigint()) { - auto value = argument.to_bigint_int64(global_object); + auto value = TRY_OR_DISCARD(argument.to_bigint_int64(global_object)); arguments.append(Wasm::Value(param, bit_cast(value))); } else { arguments.append(Wasm::Value(param, static_cast(double_value))); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h index 504e0b59f4..a00162a284 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h +++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h @@ -130,6 +130,7 @@ Value ArrayBuffer::get_value(size_t byte_index, [[maybe_unused]] bool is_typed_a template static ByteBuffer numeric_to_raw_bytes(GlobalObject& global_object, Value value, bool is_little_endian) { + VERIFY(value.is_number() || value.is_bigint()); using UnderlyingBufferDataType = Conditional, u8, T>; ByteBuffer raw_bytes = ByteBuffer::create_uninitialized(sizeof(UnderlyingBufferDataType)).release_value(); // FIXME: Handle possible OOM situation. auto flip_if_needed = [&]() { @@ -157,7 +158,7 @@ static ByteBuffer numeric_to_raw_bytes(GlobalObject& global_object, Value value, UnderlyingBufferDataType int_value; if constexpr (IsSigned) - int_value = value.to_bigint_int64(global_object); + int_value = MUST(value.to_bigint_int64(global_object)); else int_value = value.to_bigint_uint64(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 397866cfd2..cef553e6e7 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -546,9 +546,9 @@ ThrowCompletionOr Value::to_bigint(GlobalObject& global_object) const } // 7.1.15 ToBigInt64 ( argument ), https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tobigint64 -i64 Value::to_bigint_int64(GlobalObject& global_object) const +ThrowCompletionOr Value::to_bigint_int64(GlobalObject& global_object) const { - auto* bigint = TRY_OR_DISCARD(to_bigint(global_object)); + auto* bigint = TRY(to_bigint(global_object)); return static_cast(bigint->big_integer().to_u64()); } diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index 0deb26b2a0..8febee8c68 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -311,7 +311,7 @@ public: ThrowCompletionOr to_numeric(GlobalObject&) const; Value to_number(GlobalObject&) const; ThrowCompletionOr to_bigint(GlobalObject&) const; - i64 to_bigint_int64(GlobalObject&) const; + ThrowCompletionOr to_bigint_int64(GlobalObject&) const; u64 to_bigint_uint64(GlobalObject&) const; double to_double(GlobalObject&) const; StringOrSymbol to_property_key(GlobalObject&) const;