mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Align detached buffer semantics with web reality, R3
This commit is contained in:
parent
0e7319c015
commit
a60a67ea88
test/built-ins/TypedArray/prototype
@ -15,7 +15,7 @@ info: |
|
||||
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
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
@ -29,16 +29,13 @@ testWithTypedArrayConstructors(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);
|
||||
});
|
||||
|
@ -21,15 +21,13 @@ testWithTypedArrayConstructors(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);
|
||||
});
|
||||
|
@ -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: [testTypedArray.js, detachArrayBuffer.js]
|
||||
features: [TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(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);
|
||||
});
|
||||
|
@ -7,28 +7,26 @@ description: >
|
||||
info: |
|
||||
22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.findIndex is a distinct function that implements the
|
||||
same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that
|
||||
the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
%TypedArray%.prototype.findIndex is a distinct function that implements the
|
||||
same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that
|
||||
the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
...
|
||||
...
|
||||
|
||||
22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
|
||||
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
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 »)).
|
||||
...
|
||||
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 )
|
||||
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]
|
||||
features: [TypedArray]
|
||||
---*/
|
||||
@ -36,16 +34,12 @@ features: [TypedArray]
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(2);
|
||||
var loops = 0;
|
||||
var completion = false;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.findIndex(function() {
|
||||
loops++;
|
||||
sample.findIndex(function() {
|
||||
if (loops === 0) {
|
||||
$DETACHBUFFER(sample.buffer);
|
||||
completion = true;
|
||||
});
|
||||
}, "throws a TypeError getting a value from the detached buffer");
|
||||
|
||||
assert.sameValue(loops, 1, "predicated is called once");
|
||||
assert(completion, "abrupt completion does not come from DETACHBUFFER");
|
||||
}
|
||||
loops++;
|
||||
});
|
||||
assert.sameValue(loops, 2, "predicate is called once");
|
||||
});
|
||||
|
@ -29,14 +29,11 @@ testWithTypedArrayConstructors(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);
|
||||
|
@ -21,16 +21,13 @@ testWithTypedArrayConstructors(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 0;
|
||||
});
|
||||
}
|
||||
loops++;
|
||||
return true;
|
||||
});
|
||||
|
||||
assert.sameValue(loops, 1, "callbackfn called only once");
|
||||
assert.sameValue(loops, 2);
|
||||
});
|
||||
|
@ -30,15 +30,13 @@ testWithTypedArrayConstructors(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);
|
||||
});
|
||||
|
@ -30,15 +30,13 @@ testWithTypedArrayConstructors(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);
|
||||
});
|
||||
|
@ -29,15 +29,13 @@ testWithTypedArrayConstructors(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);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user