summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-17 23:48:24 +0300
committerIdan Horowitz <idan.horowitz@gmail.com>2021-10-18 08:01:38 +0300
commit7bbb92dfe9af40a340092df3263efa8fd3cf611c (patch)
tree1a129be4f85cdf2e1e3ccfa055bbe57d9baf1c6d /Userland/Libraries
parent627b1205ced61ace766bff9b486f2718cd02c26a (diff)
downloadserenity-7bbb92dfe9af40a340092df3263efa8fd3cf611c.zip
LibJS: Convert to_u16() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayBuffer.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringConstructor.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.h2
4 files changed, 6 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
index dd860f7b2a..891a5acce5 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
+++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h
@@ -178,7 +178,7 @@ static ByteBuffer numeric_to_raw_bytes(GlobalObject& global_object, Value value,
if constexpr (sizeof(UnderlyingBufferDataType) == 4)
int_value = MUST(value.to_u32(global_object));
else if constexpr (sizeof(UnderlyingBufferDataType) == 2)
- int_value = value.to_u16(global_object);
+ int_value = MUST(value.to_u16(global_object));
else if constexpr (!IsSame<T, ClampedU8>)
int_value = value.to_u8(global_object);
else
diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
index da32893924..ed77b2adec 100644
--- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
@@ -105,12 +105,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code)
Vector<u16, 1> string;
string.ensure_capacity(vm.argument_count());
- for (size_t i = 0; i < vm.argument_count(); ++i) {
- auto code_unit = vm.argument(i).to_u16(global_object);
- if (vm.exception())
- return {};
- string.append(code_unit);
- }
+ for (size_t i = 0; i < vm.argument_count(); ++i)
+ string.append(TRY_OR_DISCARD(vm.argument(i).to_u16(global_object)));
return js_string(vm, Utf16String(move(string)));
}
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index b33d0ad1f0..f17a695612 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -624,9 +624,9 @@ ThrowCompletionOr<i16> Value::to_i16(GlobalObject& global_object) const
}
// 7.1.9 ToUint16 ( argument ), https://tc39.es/ecma262/#sec-touint16
-u16 Value::to_u16(GlobalObject& global_object) const
+ThrowCompletionOr<u16> Value::to_u16(GlobalObject& global_object) const
{
- double value = TRY_OR_DISCARD(to_number(global_object)).as_double();
+ double value = TRY(to_number(global_object)).as_double();
if (!isfinite(value) || value == 0)
return 0;
auto int_val = floor(fabs(value));
diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h
index 39ea340698..095af07800 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.h
+++ b/Userland/Libraries/LibJS/Runtime/Value.h
@@ -318,7 +318,7 @@ public:
ThrowCompletionOr<i32> to_i32(GlobalObject& global_object) const;
ThrowCompletionOr<u32> to_u32(GlobalObject&) const;
ThrowCompletionOr<i16> to_i16(GlobalObject&) const;
- u16 to_u16(GlobalObject&) const;
+ ThrowCompletionOr<u16> to_u16(GlobalObject&) const;
i8 to_i8(GlobalObject&) const;
u8 to_u8(GlobalObject&) const;
u8 to_u8_clamp(GlobalObject&) const;