summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-17 23:50:06 +0300
committerIdan Horowitz <idan.horowitz@gmail.com>2021-10-18 08:01:38 +0300
commit750da61c0fee4990a44b6113169d0740990596b3 (patch)
tree3aff4a4ac4f9549e848459e2775d26d4147c0bd9
parent99287afc99053e59983d116defa00166a65b0891 (diff)
downloadserenity-750da61c0fee4990a44b6113169d0740990596b3.zip
LibJS: Convert to_u8_clamp() to ThrowCompletionOr
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayBuffer.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.h2
3 files changed, 4 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
index af6044f7b4..ec438d319e 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
+++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
@@ -182,7 +182,7 @@ static ByteBuffer numeric_to_raw_bytes(GlobalObject& global_object, Value value,
else if constexpr (!IsSame<T, ClampedU8>)
int_value = MUST(value.to_u8(global_object));
else
- int_value = value.to_u8_clamp(global_object);
+ int_value = MUST(value.to_u8_clamp(global_object));
}
ReadonlyBytes { &int_value, sizeof(UnderlyingBufferDataType) }.copy_to(raw_bytes);
if constexpr (sizeof(UnderlyingBufferDataType) % 2 == 0)
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index 3738464b4e..d16ac860e6 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -671,9 +671,9 @@ ThrowCompletionOr<u8> Value::to_u8(GlobalObject& global_object) const
}
// 7.1.12 ToUint8Clamp ( argument ), https://tc39.es/ecma262/#sec-touint8clamp
-u8 Value::to_u8_clamp(GlobalObject& global_object) const
+ThrowCompletionOr<u8> Value::to_u8_clamp(GlobalObject& global_object) const
{
- auto number = TRY_OR_DISCARD(to_number(global_object));
+ auto number = TRY(to_number(global_object));
if (number.is_nan())
return 0;
double value = number.as_double();
diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h
index 8bd7bfad55..7696fcbc60 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.h
+++ b/Userland/Libraries/LibJS/Runtime/Value.h
@@ -321,7 +321,7 @@ public:
ThrowCompletionOr<u16> to_u16(GlobalObject&) const;
ThrowCompletionOr<i8> to_i8(GlobalObject&) const;
ThrowCompletionOr<u8> to_u8(GlobalObject&) const;
- u8 to_u8_clamp(GlobalObject&) const;
+ ThrowCompletionOr<u8> to_u8_clamp(GlobalObject&) const;
size_t to_length(GlobalObject&) const;
size_t to_index(GlobalObject&) const;
double to_integer_or_infinity(GlobalObject&) const;