mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 07:07:34 +00:00
LibJS: Do not throw a TypeError when sorting a detached TypedArray
This is a normative change in the ECMA-262 spec. See:
e0c74e1
This commit is contained in:
parent
d04a683f85
commit
84a81dd466
2 changed files with 18 additions and 3 deletions
|
@ -952,9 +952,6 @@ static ThrowCompletionOr<void> typed_array_merge_sort(GlobalObject& global_objec
|
|||
|
||||
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())
|
||||
comparison_result = 0;
|
||||
else
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue