diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index edf9773165..3b749e0b1a 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -952,9 +952,6 @@ static ThrowCompletionOr typed_array_merge_sort(GlobalObject& global_objec auto value = TRY(result.to_number(global_object)); - if (buffer.is_detached()) - return vm.throw_completion(global_object, ErrorType::DetachedArrayBuffer); - if (value.is_nan()) comparison_result = 0; else diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.sort.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.sort.js index 02f2642047..09dc6c9fc8 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.sort.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.sort.js @@ -51,3 +51,21 @@ test("basic functionality", () => { expect(typedArray[2]).toBe(1n); }); }); + +test("detached buffer", () => { + TYPED_ARRAYS.forEach(T => { + const typedArray = new T(3); + typedArray[0] = 3; + typedArray[1] = 1; + typedArray[2] = 2; + + typedArray.sort((a, b) => { + detachArrayBuffer(typedArray.buffer); + return a - b; + }); + + expect(typedArray[0]).toBeUndefined(); + expect(typedArray[1]).toBeUndefined(); + expect(typedArray[2]).toBeUndefined(); + }); +});