LibJS: Convert to_bigint_int64() to ThrowCompletionOr

This commit is contained in:
Idan Horowitz 2021-10-16 21:56:14 +03:00 committed by Linus Groh
parent e87cea8248
commit df181809fd
4 changed files with 6 additions and 5 deletions

View file

@ -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<u64>(value)));
} else {
arguments.append(Wasm::Value(param, static_cast<u64>(double_value)));

View file

@ -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);

View file

@ -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());
}

View file

@ -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;