From 98552bf4c9373f3119733c219cfa39e13a871f3a Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 28 Feb 2024 09:39:28 -0500 Subject: [PATCH] Revert "LibJS: Add fast path for checking if attached TAs are OOB" This reverts commit 5fd53652b714287d05fc06b9d24c128993b3c03a. This optimization is superseded by optimizing IsValidIntegerIndex for TypedArrays with non-resizable ArrayBuffers. Reverting this commit has no impact on test-js, test262, or live website performance. --- Userland/Libraries/LibJS/Runtime/TypedArray.cpp | 8 ++++++-- Userland/Libraries/LibJS/Runtime/TypedArray.h | 12 ------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 980a729b64..e910a89baa 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -668,7 +668,7 @@ u32 typed_array_length_with_known_valid_bounds(TypedArrayWithBufferWitness const } // 10.4.5.13 IsTypedArrayOutOfBounds ( taRecord ), https://tc39.es/ecma262/#sec-istypedarrayoutofbounds -bool is_typed_array_out_of_bounds_for_known_attached_array(TypedArrayWithBufferWitness const& typed_array_record) +bool is_typed_array_out_of_bounds(TypedArrayWithBufferWitness const& typed_array_record) { // 1. Let O be taRecord.[[Object]]. auto object = typed_array_record.object; @@ -677,7 +677,11 @@ bool is_typed_array_out_of_bounds_for_known_attached_array(TypedArrayWithBufferW auto const& buffer_byte_length = typed_array_record.cached_buffer_byte_length; // 3. Assert: IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true if and only if bufferByteLength is detached. + VERIFY(object->viewed_array_buffer()->is_detached() == buffer_byte_length.is_detached()); + // 4. If bufferByteLength is detached, return true. + if (buffer_byte_length.is_detached()) + return true; // 5. Let byteOffsetStart be O.[[ByteOffset]]. auto byte_offset_start = object->byte_offset(); @@ -715,7 +719,7 @@ bool is_valid_integer_index_slow_case(TypedArrayBase const& typed_array, Canonic // 5. NOTE: Bounds checking is not a synchronizing operation when O's backing buffer is a growable SharedArrayBuffer. // 6. If IsTypedArrayOutOfBounds(taRecord) is true, return false. - if (is_typed_array_out_of_bounds_for_known_attached_array(typed_array_record)) + if (is_typed_array_out_of_bounds(typed_array_record)) return false; // 7. Let length be TypedArrayLength(taRecord). diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h index 7eb31aa4ad..08ac6fb241 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.h +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h @@ -111,18 +111,6 @@ inline u32 typed_array_length(TypedArrayWithBufferWitness const& typed_array_rec return typed_array_length_with_known_valid_bounds(typed_array_record); } -// Fast-path version of IsTypedArrayOutOfBounds when you already know the TA is not detached. -bool is_typed_array_out_of_bounds_for_known_attached_array(TypedArrayWithBufferWitness const&); - -// 10.4.5.13 IsTypedArrayOutOfBounds ( taRecord ), https://tc39.es/ecma262/#sec-istypedarrayoutofbounds -inline bool is_typed_array_out_of_bounds(TypedArrayWithBufferWitness const& typed_array_record) -{ - if (typed_array_record.cached_buffer_byte_length.is_detached()) - return true; - - return is_typed_array_out_of_bounds_for_known_attached_array(typed_array_record); -} - bool is_valid_integer_index_slow_case(TypedArrayBase const&, CanonicalIndex property_index); // 10.4.5.14 IsValidIntegerIndex ( O, index ), https://tc39.es/ecma262/#sec-isvalidintegerindex