From 067dff87573507c7addfe7fb50b8f5aa0fc848fc Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Mon, 4 Apr 2022 16:36:56 -0700 Subject: [PATCH] Remove check for per-comparator call detach check in TypedArray.prototype.sort This updates tests in line with the normative change in https://github.com/tc39/ecma262/pull/2723 --- .../sort/BigInt/detached-buffer-comparefn.js | 38 ---------------- .../sort/detached-buffer-comparefn-coerce.js | 44 ------------------- .../sort/detached-buffer-comparefn.js | 38 ---------------- .../prototype/sort/sort-tonumber.js | 16 +++---- 4 files changed, 6 insertions(+), 130 deletions(-) delete mode 100644 test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js delete mode 100644 test/built-ins/TypedArray/prototype/sort/detached-buffer-comparefn-coerce.js delete mode 100644 test/built-ins/TypedArray/prototype/sort/detached-buffer-comparefn.js diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js b/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js deleted file mode 100644 index caa7f80a28a..00000000000 --- a/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2016 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-%typedarray%.prototype.sort -description: Throws a TypeError if comparefn detaches the object buffer -info: | - 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) - - When the TypedArray SortCompare abstract operation is called with two - arguments x and y, the following steps are taken: - - ... - 2. If the argument comparefn is not undefined, then - a. Let v be ? Call(comparefn, undefined, « x, y »). - b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - ... - ... -includes: [testBigIntTypedArray.js, detachArrayBuffer.js] -features: [BigInt, TypedArray] ----*/ - -testWithBigIntTypedArrayConstructors(function(TA) { - var sample = new TA(4); - var calls = 0; - var comparefn = function() { - if (calls > 0) { - throw new Test262Error(); - } - calls++; - $DETACHBUFFER(sample.buffer); - }; - - assert.throws(TypeError, function() { - sample.sort(comparefn); - }); - - assert.sameValue(calls, 1); -}); diff --git a/test/built-ins/TypedArray/prototype/sort/detached-buffer-comparefn-coerce.js b/test/built-ins/TypedArray/prototype/sort/detached-buffer-comparefn-coerce.js deleted file mode 100644 index 6e2be4cafda..00000000000 --- a/test/built-ins/TypedArray/prototype/sort/detached-buffer-comparefn-coerce.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2020 Google. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-%typedarray%.prototype.sort -description: > - SECURITY Throws a TypeError if coercion of the comparefn return value - detaches the object buffer -info: | - 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) - - When the TypedArray SortCompare abstract operation is called with two - arguments x and y, the following steps are taken: - - ... - 2. If the argument comparefn is not undefined, then - a. Let v be ? ToNumber(? Call(comparefn, undefined, « x, y »)). - b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - ... - ... -includes: [testTypedArray.js, detachArrayBuffer.js] -features: [TypedArray] ----*/ - -testWithTypedArrayConstructors(function(TA) { - var sample = new TA(4); - var calls = 0; - var convertfn = function(){ - $DETACHBUFFER(sample.buffer); - return 1; - } - var comparefn = function() { - if (calls > 0) { - throw new Test262Error(); - } - calls++; - return {valueOf : convertfn} - }; - - assert.throws(TypeError, function() { - sample.sort(comparefn); - }, "Coercion that detaches buffer should throw TypeError"); - - assert.sameValue(calls, 1); -}); diff --git a/test/built-ins/TypedArray/prototype/sort/detached-buffer-comparefn.js b/test/built-ins/TypedArray/prototype/sort/detached-buffer-comparefn.js deleted file mode 100644 index 6ff08beb603..00000000000 --- a/test/built-ins/TypedArray/prototype/sort/detached-buffer-comparefn.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2016 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-%typedarray%.prototype.sort -description: Throws a TypeError if comparefn detaches the object buffer -info: | - 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) - - When the TypedArray SortCompare abstract operation is called with two - arguments x and y, the following steps are taken: - - ... - 2. If the argument comparefn is not undefined, then - a. Let v be ? Call(comparefn, undefined, « x, y »). - b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - ... - ... -includes: [testTypedArray.js, detachArrayBuffer.js] -features: [TypedArray] ----*/ - -testWithTypedArrayConstructors(function(TA) { - var sample = new TA(4); - var calls = 0; - var comparefn = function() { - if (calls > 0) { - throw new Test262Error(); - } - calls++; - $DETACHBUFFER(sample.buffer); - }; - - assert.throws(TypeError, function() { - sample.sort(comparefn); - }); - - assert.sameValue(calls, 1); -}); diff --git a/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js b/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js index 627ed55ecdf..36d8457e980 100644 --- a/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js +++ b/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js @@ -21,16 +21,12 @@ testWithTypedArrayConstructors(function(TA) { var ab = ta.buffer; var called = false; - assert.throws(TypeError, function() { - ta.sort(function(a, b) { - // IsDetachedBuffer is checked right after calling comparefn. - // So, detach the ArrayBuffer to cause sort to throw, to make sure we're actually calling ToNumber immediately (as spec'd) - // (a possible bug is to wait until the result is inspected to call ToNumber, rather than immediately) - $DETACHBUFFER(ab); - return { - [Symbol.toPrimitive]() { called = true; } - }; - }); + ta.sort(function(a, b) { + // Detaching the buffer does not cause sort to throw. + $DETACHBUFFER(ab); + return { + [Symbol.toPrimitive]() { called = true; } + }; }); assert.sameValue(true, called);