From cf9da66b3e692cf41855e87f8cfbb107b55a2f37 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 2 Dec 2020 13:24:34 +0000 Subject: [PATCH] LibJS: Use Value::to_index() in typed array constructors --- Libraries/LibJS/Runtime/TypedArray.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Libraries/LibJS/Runtime/TypedArray.cpp b/Libraries/LibJS/Runtime/TypedArray.cpp index a27023f9cd..d184925e52 100644 --- a/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Libraries/LibJS/Runtime/TypedArray.cpp @@ -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(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(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; \ }