From 3c582284654668ceaca708c3436e429cc01b2a48 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 28 Oct 2020 11:47:50 -0400 Subject: [PATCH] Align detached buffer semantics with web reality, R4. Fixes gh-2879 --- .../every/BigInt/callbackfn-detachbuffer.js | 15 +++--- .../filter/BigInt/callbackfn-detachbuffer.js | 14 +++-- .../BigInt/predicate-may-detach-buffer.js | 51 +++++++++---------- .../forEach/BigInt/callbackfn-detachbuffer.js | 13 ++--- .../map/BigInt/callbackfn-detachbuffer.js | 15 +++--- .../reduce/BigInt/callbackfn-detachbuffer.js | 16 +++--- .../BigInt/callbackfn-detachbuffer.js | 16 +++--- .../some/BigInt/callbackfn-detachbuffer.js | 14 +++-- .../GetOwnProperty/index-prop-desc.js | 2 +- .../internals/Set/BigInt/detached-buffer.js | 2 +- 10 files changed, 70 insertions(+), 88 deletions(-) diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js index 144798687f..a2618c4dcf 100644 --- a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js @@ -29,16 +29,13 @@ testWithBigIntTypedArrayConstructors(function(TA) { var loops = 0; var sample = new TA(2); - assert.throws(TypeError, function() { - sample.every(function() { - if (loops === 1) { - throw new Test262Error("callbackfn called twice"); - } + sample.every(function() { + if (loops === 0) { $DETACHBUFFER(sample.buffer); - loops++; - return true; - }); + } + loops++; + return true; }); - assert.sameValue(loops, 1); + assert.sameValue(loops, 2); }); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js index c5bba7c921..cfb3f92f31 100644 --- a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js @@ -21,15 +21,13 @@ testWithBigIntTypedArrayConstructors(function(TA) { var loops = 0; var sample = new TA(2); - assert.throws(TypeError, function() { - sample.filter(function() { - if (loops === 1) { - throw new Test262Error("callbackfn called twice"); - } + sample.filter(function() { + if (loops === 0) { $DETACHBUFFER(sample.buffer); - loops++; - }); + } + loops++; + return true; }); - assert.sameValue(loops, 1); + assert.sameValue(loops, 2); }); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js index 49e58ac618..49f713555a 100644 --- a/test/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js +++ b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js @@ -5,7 +5,7 @@ esid: sec-%typedarray%.prototype.find description: > Predicate may detach the buffer info: | - 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + %TypedArray%.prototype.find (predicate [ , thisArg ] ) %TypedArray%.prototype.find is a distinct function that implements the same algorithm as Array.prototype.find as defined in 22.1.3.8 @@ -17,42 +17,41 @@ info: | possibility that calls to predicate may cause the this value to become detached. - ... - 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + Array.prototype.find ( predicate[ , thisArg ] ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + If IsCallable(predicate) is false, throw a TypeError exception. + Let k be 0. + Repeat, while k < len, + Let Pk be ! ToString(𝔽(k)). + Let kValue be ? Get(O, Pk). + Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + If testResult is true, return kValue. + Set k to k + 1. + Return undefined. + + IntegerIndexedElementGet ( O, index ) - ... - 4. If thisArg was supplied, let T be thisArg; else let T be undefined. - 5. Let k be 0. - 6. Repeat, while k < len ... - b. Let kValue be ? Get(O, Pk). - c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). - ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. - 9.4.5.8 IntegerIndexedElementGet ( O, index ) - - ... - 3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. - 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - ... includes: [testBigIntTypedArray.js, detachArrayBuffer.js] features: [BigInt, TypedArray] ---*/ testWithBigIntTypedArrayConstructors(function(TA) { - var sample = new TA(2); var loops = 0; - var completion = false; + var sample = new TA(2); - assert.throws(TypeError, function() { - sample.find(function() { - loops++; + sample.find(function() { + if (loops === 0) { $DETACHBUFFER(sample.buffer); - completion = true; - }); - }, "throws a TypeError getting a value from the detached buffer"); + } + loops++; + }); - assert.sameValue(loops, 1, "predicate is called once"); - assert(completion, "abrupt completion does not come from DETACHBUFFER"); + assert.sameValue(loops, 2); }); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js index bf04fe9796..bc8e60c279 100644 --- a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js @@ -29,15 +29,12 @@ testWithBigIntTypedArrayConstructors(function(TA) { var loops = 0; var sample = new TA(2); - assert.throws(TypeError, function() { - sample.forEach(function() { - if (loops === 1) { - throw new Test262Error("callbackfn called twice"); - } + sample.forEach(function() { + if (loops === 0) { $DETACHBUFFER(sample.buffer); - loops++; - }); + } + loops++; }); - assert.sameValue(loops, 1); + assert.sameValue(loops, 2); }); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js index d8abe4bd46..c9ff3cdc4e 100644 --- a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js @@ -21,16 +21,13 @@ testWithBigIntTypedArrayConstructors(function(TA) { var loops = 0; var sample = new TA(2); - assert.throws(TypeError, function() { - sample.map(function() { - if (loops === 1) { - throw new Test262Error("callbackfn called twice"); - } + sample.map(function() { + if (loops === 0) { $DETACHBUFFER(sample.buffer); - loops++; - return 0n; - }); + } + loops++; + return true; }); - assert.sameValue(loops, 1, "callbackfn called only once"); + assert.sameValue(loops, 2); }); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.js index f904d53a12..7527cf918c 100644 --- a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.js +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.js @@ -30,15 +30,13 @@ testWithBigIntTypedArrayConstructors(function(TA) { var loops = 0; var sample = new TA(2); - assert.throws(TypeError, function() { - sample.reduce(function() { - if (loops === 1) { - throw new Test262Error("callbackfn called twice"); - } + sample.reduce(function() { + if (loops === 0) { $DETACHBUFFER(sample.buffer); - loops++; - }, 0); - }); + } + loops++; + return true; + }, 0); - assert.sameValue(loops, 1, "callbackfn called only once"); + assert.sameValue(loops, 2); }); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js index fe816660c0..64edd5a57d 100644 --- a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js @@ -30,15 +30,13 @@ testWithBigIntTypedArrayConstructors(function(TA) { var loops = 0; var sample = new TA(2); - assert.throws(TypeError, function() { - sample.reduceRight(function() { - if (loops === 1) { - throw new Test262Error("callbackfn called twice"); - } + sample.reduceRight(function() { + if (loops === 0) { $DETACHBUFFER(sample.buffer); - loops++; - }, 0); - }); + } + loops++; + return true; + }, 0); - assert.sameValue(loops, 1, "callbackfn called only once"); + assert.sameValue(loops, 2); }); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js index 9d504d2e3a..3aaa70fad4 100644 --- a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js @@ -29,15 +29,13 @@ testWithBigIntTypedArrayConstructors(function(TA) { var loops = 0; var sample = new TA(2); - assert.throws(TypeError, function() { - sample.some(function() { - if (loops === 1) { - throw new Test262Error("callbackfn called twice"); - } + sample.some(function() { + if (loops === 0) { $DETACHBUFFER(sample.buffer); - loops++; - }); + } + loops++; + return false; }); - assert.sameValue(loops, 1); + assert.sameValue(loops, 2); }); diff --git a/test/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js b/test/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js index b94220c522..83b637d9c0 100644 --- a/test/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js +++ b/test/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js @@ -13,7 +13,7 @@ info: | b. If numericIndex is not undefined, then ... iii. Return a PropertyDescriptor{[[Value]]: value, [[Writable]]: true, - [[Enumerable]]: true, [[Configurable]]: false}. + [[Enumerable]]: true, [[Configurable]]: true}. ... includes: [testTypedArray.js, propertyHelper.js] features: [align-detached-buffer-semantics-with-web-reality, TypedArray] diff --git a/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js b/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js index b927a6fb16..5e6465bce8 100644 --- a/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js +++ b/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js @@ -3,7 +3,7 @@ /*--- esid: sec-integer-indexed-exotic-objects-set-p-v-receiver description: > - Returns true when setting the value of any CanonicalNumericIndexString if buffer is detached. + Returns false when setting the value of any CanonicalNumericIndexString if buffer is detached. info: | [[Set]] ( P, V, Receiver)