mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
LibJS: Convert to_u16() to ThrowCompletionOr
This commit is contained in:
parent
627b1205ce
commit
7bbb92dfe9
Notes:
sideshowbarker
2024-07-18 02:12:31 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/7bbb92dfe9a Pull-request: https://github.com/SerenityOS/serenity/pull/10522 Reviewed-by: https://github.com/linusg ✅
5 changed files with 7 additions and 13 deletions
|
@ -1121,9 +1121,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
)~~~");
|
||||
} else if (parameter.type->name == "unsigned short") {
|
||||
scoped_generator.append(R"~~~(
|
||||
auto @cpp_name@ = @js_name@@js_suffix@.to_u16(global_object);
|
||||
if (vm.exception())
|
||||
@return_statement@
|
||||
auto @cpp_name@ = TRY_OR_DISCARD(@js_name@@js_suffix@.to_u16(global_object));
|
||||
)~~~");
|
||||
} else if (parameter.type->name == "long") {
|
||||
scoped_generator.append(R"~~~(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue