From d713a84851ffab2a7fdee6ce17ad53dd3a6b0109 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Mon, 5 Jul 2021 02:42:16 +0300 Subject: [PATCH] LibJS: Stop masking non-RangeError exceptions in TypedArray creation Non-RangeError exceptions can be thrown by user implementations of valueOf (which are called by to_index), and the specification disallows changing the type of the thrown error. --- Userland/Libraries/LibJS/Runtime/TypedArray.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 90d543acc6..24b2491113 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -313,9 +313,11 @@ void TypedArrayBase::visit_edges(Visitor& visitor) \ auto array_length = first_argument.to_index(global_object()); \ if (vm.exception()) { \ - /* Re-throw more specific RangeError */ \ - vm.clear_exception(); \ - vm.throw_exception(global_object(), ErrorType::InvalidLength, "typed array"); \ + if (vm.exception()->value().is_object() && is(vm.exception()->value().as_object())) { \ + /* Re-throw more specific RangeError */ \ + vm.clear_exception(); \ + vm.throw_exception(global_object(), ErrorType::InvalidLength, "typed array"); \ + } \ return {}; \ } \ if (array_length > NumericLimits::max() / sizeof(Type)) { \