mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:27:35 +00:00
LibJS: Convert to_length() to ThrowCompletionOr
This commit is contained in:
parent
750da61c0f
commit
aad12b050b
8 changed files with 20 additions and 34 deletions
|
@ -692,13 +692,13 @@ ThrowCompletionOr<u8> Value::to_u8_clamp(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 7.1.20 ToLength ( argument ), https://tc39.es/ecma262/#sec-tolength
|
||||
size_t Value::to_length(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<size_t> Value::to_length(GlobalObject& global_object) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
auto len = to_integer_or_infinity(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
// FIXME: The spec says that this function's output range is 0 - 2^53-1. But we don't want to overflow the size_t.
|
||||
|
@ -720,8 +720,7 @@ size_t Value::to_index(GlobalObject& global_object) const
|
|||
vm.throw_exception<RangeError>(global_object, ErrorType::InvalidIndex);
|
||||
return {};
|
||||
}
|
||||
auto index = Value(integer_index).to_length(global_object);
|
||||
VERIFY(!vm.exception());
|
||||
auto index = MUST(Value(integer_index).to_length(global_object));
|
||||
if (integer_index != index) {
|
||||
vm.throw_exception<RangeError>(global_object, ErrorType::InvalidIndex);
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue