Align detached buffer semantics with web reality, R3

This commit is contained in:
Rick Waldron 2020-10-20 17:38:52 -04:00
parent 0e7319c015
commit a60a67ea88
9 changed files with 87 additions and 111 deletions

View File

@ -15,7 +15,7 @@ info: |
22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] )
... ...
6. Repeat, while k < len 5. Repeat, while k < len
... ...
c. If kPresent is true, then c. If kPresent is true, then
i. Let kValue be ? Get(O, Pk). i. Let kValue be ? Get(O, Pk).
@ -29,16 +29,13 @@ testWithTypedArrayConstructors(function(TA) {
var loops = 0; var loops = 0;
var sample = new TA(2); var sample = new TA(2);
assert.throws(TypeError, function() {
sample.every(function() { sample.every(function() {
if (loops === 1) { if (loops === 0) {
throw new Test262Error("callbackfn called twice");
}
$DETACHBUFFER(sample.buffer); $DETACHBUFFER(sample.buffer);
}
loops++; loops++;
return true; return true;
}); });
});
assert.sameValue(loops, 1); assert.sameValue(loops, 2);
}); });

View File

@ -21,15 +21,13 @@ testWithTypedArrayConstructors(function(TA) {
var loops = 0; var loops = 0;
var sample = new TA(2); var sample = new TA(2);
assert.throws(TypeError, function() {
sample.filter(function() { sample.filter(function() {
if (loops === 1) { if (loops === 0) {
throw new Test262Error("callbackfn called twice");
}
$DETACHBUFFER(sample.buffer); $DETACHBUFFER(sample.buffer);
}
loops++; loops++;
}); return true;
}); });
assert.sameValue(loops, 1); assert.sameValue(loops, 2);
}); });

View File

@ -5,7 +5,7 @@ esid: sec-%typedarray%.prototype.find
description: > description: >
Predicate may detach the buffer Predicate may detach the buffer
info: | 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 %TypedArray%.prototype.find is a distinct function that implements the same
algorithm as Array.prototype.find as defined in 22.1.3.8 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 possibility that calls to predicate may cause the this value to become
detached. 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. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
5. Let k be 0. If IsDetachedBuffer(buffer) is true, return undefined.
6. Repeat, while k < len
...
b. Let kValue be ? Get(O, Pk).
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
...
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: [testTypedArray.js, detachArrayBuffer.js] includes: [testTypedArray.js, detachArrayBuffer.js]
features: [TypedArray] features: [TypedArray]
---*/ ---*/
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var sample = new TA(2);
var loops = 0; var loops = 0;
var completion = false; var sample = new TA(2);
assert.throws(TypeError, function() {
sample.find(function() { sample.find(function() {
loops++; if (loops === 0) {
$DETACHBUFFER(sample.buffer); $DETACHBUFFER(sample.buffer);
completion = true; }
loops++;
}); });
}, "throws a TypeError getting a value from the detached buffer");
assert.sameValue(loops, 1, "predicate is called once"); assert.sameValue(loops, 2);
assert(completion, "abrupt completion does not come from DETACHBUFFER");
}); });

View File

@ -16,19 +16,17 @@ info: |
22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
... Repeat, while k < len,
6. Repeat, while k < len Let Pk be ! ToString(𝔽(k)).
... Let kValue be ? Get(O, Pk).
b. Let kValue be ? Get(O, Pk). Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
... ...
9.4.5.8 IntegerIndexedElementGet ( O, index ) IntegerIndexedElementGet ( O, index )
Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
If IsDetachedBuffer(buffer) is true, return undefined.
...
3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
...
includes: [testTypedArray.js, detachArrayBuffer.js] includes: [testTypedArray.js, detachArrayBuffer.js]
features: [TypedArray] features: [TypedArray]
---*/ ---*/
@ -36,16 +34,12 @@ features: [TypedArray]
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var sample = new TA(2); var sample = new TA(2);
var loops = 0; var loops = 0;
var completion = false;
assert.throws(TypeError, function() {
sample.findIndex(function() { sample.findIndex(function() {
loops++; if (loops === 0) {
$DETACHBUFFER(sample.buffer); $DETACHBUFFER(sample.buffer);
completion = true; }
loops++;
}); });
}, "throws a TypeError getting a value from the detached buffer"); assert.sameValue(loops, 2, "predicate is called once");
assert.sameValue(loops, 1, "predicated is called once");
assert(completion, "abrupt completion does not come from DETACHBUFFER");
}); });

View File

@ -29,15 +29,12 @@ testWithTypedArrayConstructors(function(TA) {
var loops = 0; var loops = 0;
var sample = new TA(2); var sample = new TA(2);
assert.throws(TypeError, function() {
sample.forEach(function() { sample.forEach(function() {
if (loops === 1) { if (loops === 0) {
throw new Test262Error("callbackfn called twice");
}
$DETACHBUFFER(sample.buffer); $DETACHBUFFER(sample.buffer);
}
loops++; loops++;
}); });
});
assert.sameValue(loops, 1); assert.sameValue(loops, 1);
}); });

View File

@ -21,16 +21,13 @@ testWithTypedArrayConstructors(function(TA) {
var loops = 0; var loops = 0;
var sample = new TA(2); var sample = new TA(2);
assert.throws(TypeError, function() {
sample.map(function() { sample.map(function() {
if (loops === 1) { if (loops === 0) {
throw new Test262Error("callbackfn called twice");
}
$DETACHBUFFER(sample.buffer); $DETACHBUFFER(sample.buffer);
}
loops++; loops++;
return 0; return true;
});
}); });
assert.sameValue(loops, 1, "callbackfn called only once"); assert.sameValue(loops, 2);
}); });

View File

@ -30,15 +30,13 @@ testWithTypedArrayConstructors(function(TA) {
var loops = 0; var loops = 0;
var sample = new TA(2); var sample = new TA(2);
assert.throws(TypeError, function() {
sample.reduce(function() { sample.reduce(function() {
if (loops === 1) { if (loops === 0) {
throw new Test262Error("callbackfn called twice");
}
$DETACHBUFFER(sample.buffer); $DETACHBUFFER(sample.buffer);
}
loops++; loops++;
return true;
}, 0); }, 0);
});
assert.sameValue(loops, 1, "callbackfn called only once"); assert.sameValue(loops, 2);
}); });

View File

@ -30,15 +30,13 @@ testWithTypedArrayConstructors(function(TA) {
var loops = 0; var loops = 0;
var sample = new TA(2); var sample = new TA(2);
assert.throws(TypeError, function() {
sample.reduceRight(function() { sample.reduceRight(function() {
if (loops === 1) { if (loops === 0) {
throw new Test262Error("callbackfn called twice");
}
$DETACHBUFFER(sample.buffer); $DETACHBUFFER(sample.buffer);
}
loops++; loops++;
return true;
}, 0); }, 0);
});
assert.sameValue(loops, 1, "callbackfn called only once"); assert.sameValue(loops, 2);
}); });

View File

@ -29,15 +29,13 @@ testWithTypedArrayConstructors(function(TA) {
var loops = 0; var loops = 0;
var sample = new TA(2); var sample = new TA(2);
assert.throws(TypeError, function() {
sample.some(function() { sample.some(function() {
if (loops === 1) { if (loops === 0) {
throw new Test262Error("callbackfn called twice");
}
$DETACHBUFFER(sample.buffer); $DETACHBUFFER(sample.buffer);
}
loops++; loops++;
}); return false;
}); });
assert.sameValue(loops, 1); assert.sameValue(loops, 2);
}); });