mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
LibJS: Use Value::to_index() in typed array constructors
This commit is contained in:
parent
eaa85969c4
commit
cf9da66b3e
Notes:
sideshowbarker
2024-07-19 01:05:08 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/cf9da66b3e6 Pull-request: https://github.com/SerenityOS/serenity/pull/4307
1 changed files with 6 additions and 5 deletions
|
@ -77,13 +77,14 @@ namespace JS {
|
|||
/* FIXME: Initialize from TypedArray, ArrayBuffer, Iterable or Array-like object */ \
|
||||
TODO(); \
|
||||
} \
|
||||
/* FIXME: Use ToIndex() abstract operation */ \
|
||||
auto array_length_value = vm.argument(0); \
|
||||
if (!array_length_value.is_integer() || array_length_value.as_i32() < 0) { \
|
||||
vm.throw_exception<TypeError>(global_object(), ErrorType::ArrayInvalidLength); \
|
||||
auto array_length = vm.argument(0).to_index(global_object()); \
|
||||
if (vm.exception()) { \
|
||||
/* Re-throw more specific RangeError */ \
|
||||
vm.clear_exception(); \
|
||||
vm.throw_exception<RangeError>(global_object(), ErrorType::InvalidLength, "typed array"); \
|
||||
return {}; \
|
||||
} \
|
||||
auto* array = ClassName::create(global_object(), array_length_value.as_i32()); \
|
||||
auto* array = ClassName::create(global_object(), array_length); \
|
||||
return array; \
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue