Selaa lähdekoodia

LibJS: Do not throw a TypeError when sorting a detached TypedArray

This is a normative change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/e0c74e1
Timothy Flynn 3 vuotta sitten
vanhempi
commit
84a81dd466

+ 0 - 3
Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp

@@ -952,9 +952,6 @@ static ThrowCompletionOr<void> typed_array_merge_sort(GlobalObject& global_objec
 
 
             auto value = TRY(result.to_number(global_object));
             auto value = TRY(result.to_number(global_object));
 
 
-            if (buffer.is_detached())
-                return vm.throw_completion<TypeError>(global_object, ErrorType::DetachedArrayBuffer);
-
             if (value.is_nan())
             if (value.is_nan())
                 comparison_result = 0;
                 comparison_result = 0;
             else
             else

+ 18 - 0
Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.sort.js

@@ -51,3 +51,21 @@ test("basic functionality", () => {
         expect(typedArray[2]).toBe(1n);
         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();
+    });
+});