Align detached buffer semantics with web reality, R4. Fixes gh-2879

This commit is contained in:
Rick Waldron 2020-10-28 11:47:50 -04:00
parent 959840a62a
commit 3c58228465
10 changed files with 70 additions and 88 deletions

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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]

View File

@ -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)