summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-16 21:56:14 +0300
committerLinus Groh <mail@linusgroh.de>2021-10-17 12:12:35 +0100
commitdf181809fda75c88310cca76baaa1cfd1975b66e (patch)
tree70958344aeafcee1ca8fd081d64af280fdbf478f /Userland
parente87cea8248115dd035ee91f56c1853d2391b84c0 (diff)
downloadserenity-df181809fda75c88310cca76baaa1cfd1975b66e.zip
LibJS: Convert to_bigint_int64() to ThrowCompletionOr
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayBuffer.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.h2
3 files changed, 5 insertions, 4 deletions
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<typename T>
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<IsSame<ClampedU8, T>, 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<UnderlyingBufferDataType>)
- 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<BigInt*> 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<i64> 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<i64>(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<Value> to_numeric(GlobalObject&) const;
Value to_number(GlobalObject&) const;
ThrowCompletionOr<BigInt*> to_bigint(GlobalObject&) const;
- i64 to_bigint_int64(GlobalObject&) const;
+ ThrowCompletionOr<i64> to_bigint_int64(GlobalObject&) const;
u64 to_bigint_uint64(GlobalObject&) const;
double to_double(GlobalObject&) const;
StringOrSymbol to_property_key(GlobalObject&) const;