Align detached buffer semantics with web reality, R6. Fixes gh-2915

This commit is contained in:
Rick Waldron 2020-12-09 13:43:58 -05:00
parent f9a834c05e
commit 167e596a64
14 changed files with 482 additions and 59 deletions

View File

@ -0,0 +1,46 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.includes
description: Returns -1 if buffer is detached after ValidateTypedArray
info: |
%TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of %TypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13.
When the includes method is called with one or two arguments, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If len is 0, return false.
Let n be ? ToIntegerOrInfinity(fromIndex).
Assert: If fromIndex is undefined, then n is 0.
If n is +, return false.
Else if n is -, set n to 0.
If n 0, then
Let k be n.
Else,
Let k be len + n.
If k < 0, set k to 0.
Repeat, while k < len,
Let elementK be the result of ! Get(O, ! ToString(F(k))).
If SameValueZero(searchElement, elementK) is true, return true.
Set k to k + 1.
Return false.
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
const sample = new TA(1);
const fromIndex = {
valueOf() {
$DETACHBUFFER(sample.buffer);
return 0;
}
};
assert.sameValue(sample.includes(0n, fromIndex), false);
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.includes
description: >
Returns false if buffer is detached after ValidateTypedArray and searchElement is a value
info: |
%TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of %TypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13.
When the includes method is called with one or two arguments, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If len is 0, return false.
Let n be ? ToIntegerOrInfinity(fromIndex).
Assert: If fromIndex is undefined, then n is 0.
If n is +, return false.
Else if n is -, set n to 0.
If n 0, then
Let k be n.
Else,
Let k be len + n.
If k < 0, set k to 0.
Repeat, while k < len,
Let elementK be the result of ! Get(O, ! ToString(F(k))).
If SameValueZero(searchElement, elementK) is true, return true.
Set k to k + 1.
Return false.
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
const sample = new TA(1);
const fromIndex = {
valueOf() {
$DETACHBUFFER(sample.buffer);
return 0;
}
};
assert.sameValue(sample.includes(undefined, fromIndex), true);
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.includes
description: >
Returns false if buffer is detached after ValidateTypedArray and searchElement is a value
info: |
%TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of %TypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13.
When the includes method is called with one or two arguments, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If len is 0, return false.
Let n be ? ToIntegerOrInfinity(fromIndex).
Assert: If fromIndex is undefined, then n is 0.
If n is +, return false.
Else if n is -, set n to 0.
If n 0, then
Let k be n.
Else,
Let k be len + n.
If k < 0, set k to 0.
Repeat, while k < len,
Let elementK be the result of ! Get(O, ! ToString(F(k))).
If SameValueZero(searchElement, elementK) is true, return true.
Set k to k + 1.
Return false.
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
const sample = new TA(1);
const fromIndex = {
valueOf() {
$DETACHBUFFER(sample.buffer);
return 0;
}
};
assert.sameValue(sample.includes(0, fromIndex), false);
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.includes
description: >
Returns true if buffer is detached after ValidateTypedArray and searchElement is undefined
info: |
%TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of %TypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13.
When the includes method is called with one or two arguments, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If len is 0, return false.
Let n be ? ToIntegerOrInfinity(fromIndex).
Assert: If fromIndex is undefined, then n is 0.
If n is +, return false.
Else if n is -, set n to 0.
If n 0, then
Let k be n.
Else,
Let k be len + n.
If k < 0, set k to 0.
Repeat, while k < len,
Let elementK be the result of ! Get(O, ! ToString(F(k))).
If SameValueZero(searchElement, elementK) is true, return true.
Set k to k + 1.
Return false.
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
const sample = new TA(1);
const fromIndex = {
valueOf() {
$DETACHBUFFER(sample.buffer);
return 0;
}
};
assert.sameValue(sample.includes(undefined, fromIndex), true);
});

View File

@ -1,37 +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.includes
description: >
Does not throw a TypeError if this has a detached buffer after index coercion,
because ValidateTypedArray has already successfully completed.
info: |
22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of %TypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13.
When the includes method is called with one or two arguments, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If len is 0, return false.
Let n be ? ToIntegerOrInfinity(fromIndex).
...
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
const sample = new TA(10);
let isDetached = false;
function valueOf(){
$DETACHBUFFER(sample.buffer);
isDetached = true;
return 0;
}
assert.sameValue(sample.includes(0, {valueOf}), false);
assert.sameValue(isDetached, true);
});

View File

@ -0,0 +1,49 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.indexof
description: Throws a TypeError if this has a detached buffer
info: |
%TypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of %TypedArray%.prototype.indexOf are the same as for Array.prototype.indexOf as defined in 22.1.3.14.
When the indexOf method is called with one or two arguments, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If len is 0, return -1F.
Let n be ? ToIntegerOrInfinity(fromIndex).
Assert: If fromIndex is undefined, then n is 0.
If n is +, return -1F.
Else if n is -, set n to 0.
If n 0, then
Let k be n.
Else,
Let k be len + n.
If k < 0, set k to 0.
Repeat, while k < len,
Let kPresent be ! HasProperty(O, ! ToString(F(k))).
If kPresent is true, then
Let elementK be ! Get(O, ! ToString(F(k))).
Let same be the result of performing Strict Equality Comparison searchElement === elementK.
If same is true, return F(k).
Set k to k + 1.
Return -1F.
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
const sample = new TA(1);
const fromIndex = {
valueOf() {
$DETACHBUFFER(sample.buffer);
return 0;
}
};
assert.sameValue(sample.indexOf(0n, fromIndex), -1);
});

View File

@ -0,0 +1,49 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.indexof
description: Returns -1 if buffer is detached after ValidateTypedArray
info: |
%TypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of %TypedArray%.prototype.indexOf are the same as for Array.prototype.indexOf as defined in 22.1.3.14.
When the indexOf method is called with one or two arguments, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If len is 0, return -1F.
Let n be ? ToIntegerOrInfinity(fromIndex).
Assert: If fromIndex is undefined, then n is 0.
If n is +, return -1F.
Else if n is -, set n to 0.
If n 0, then
Let k be n.
Else,
Let k be len + n.
If k < 0, set k to 0.
Repeat, while k < len,
Let kPresent be ! HasProperty(O, ! ToString(F(k))).
If kPresent is true, then
Let elementK be ! Get(O, ! ToString(F(k))).
Let same be the result of performing Strict Equality Comparison searchElement === elementK.
If same is true, return F(k).
Set k to k + 1.
Return -1F.
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
const sample = new TA(1);
const fromIndex = {
valueOf() {
$DETACHBUFFER(sample.buffer);
return 0;
}
};
assert.sameValue(sample.indexOf(0, fromIndex), -1);
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.join
description: Returns single separator if buffer is detached after ValidateTypedArray
info: |
%TypedArray%.prototype.join ( separator )
The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15.
When the join method is called with one argument separator, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If separator is undefined, let sep be the single-element String ",".
Else, let sep be ? ToString(separator).
Let R be the empty String.
Let k be 0.
Repeat, while k < len,
If k > 0, set R to the string-concatenation of R and sep.
Let element be ! Get(O, ! ToString(𝔽(k))).
If element is undefined or null, let next be the empty String; otherwise, let next be ! ToString(element).
Set R to the string-concatenation of R and next.
Set k to k + 1.
Return R.
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
const sample = new TA([1n,2n,3n]);
const separator = {
toString() {
$DETACHBUFFER(sample.buffer);
return ',';
}
};
assert.sameValue(sample.join(separator), ',,');
});

View File

@ -4,31 +4,30 @@
esid: sec-%typedarray%.prototype.join
description: Throws a TypeError if this has a detached buffer
info: |
22.2.3.15 %TypedArray%.prototype.join ( separator )
%TypedArray%.prototype.join ( separator )
This function is not generic. ValidateTypedArray is applied to the this value
prior to evaluating the algorithm. If its result is an abrupt completion that
exception is thrown instead of evaluating the algorithm.
The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15.
22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
When the join method is called with one argument separator, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
...
5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
...
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [BigInt, TypedArray]
---*/
var obj = {
toString: function() {
let obj = {
toString() {
throw new Test262Error();
}
};
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(1);
let sample = new TA(1);
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
assert.throws(TypeError, () => {
sample.join(obj);
});
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.join
description: Returns single separator if buffer is detached after ValidateTypedArray
info: |
%TypedArray%.prototype.join ( separator )
The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15.
When the join method is called with one argument separator, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If separator is undefined, let sep be the single-element String ",".
Else, let sep be ? ToString(separator).
Let R be the empty String.
Let k be 0.
Repeat, while k < len,
If k > 0, set R to the string-concatenation of R and sep.
Let element be ! Get(O, ! ToString(𝔽(k))).
If element is undefined or null, let next be the empty String; otherwise, let next be ! ToString(element).
Set R to the string-concatenation of R and next.
Set k to k + 1.
Return R.
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
const sample = new TA([1,2,3]);
const separator = {
toString() {
$DETACHBUFFER(sample.buffer);
return ',';
}
};
assert.sameValue(sample.join(separator), ',,');
});

View File

@ -4,31 +4,30 @@
esid: sec-%typedarray%.prototype.join
description: Throws a TypeError if this has a detached buffer
info: |
22.2.3.15 %TypedArray%.prototype.join ( separator )
%TypedArray%.prototype.join ( separator )
This function is not generic. ValidateTypedArray is applied to the this value
prior to evaluating the algorithm. If its result is an abrupt completion that
exception is thrown instead of evaluating the algorithm.
The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15.
22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
When the join method is called with one argument separator, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
...
5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
...
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [TypedArray]
---*/
var obj = {
toString: function() {
let obj = {
toString() {
throw new Test262Error();
}
};
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
let sample = new TA(1);
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
assert.throws(TypeError, () => {
sample.join(obj);
});
});

View File

@ -0,0 +1,46 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.lastindexof
description: Returns -1 if buffer is detached after ValidateTypedArray
info: |
%TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of %TypedArray%.prototype.lastIndexOf are the same as for Array.prototype.lastIndexOf as defined in 22.1.3.17.
When the lastIndexOf method is called with one or two arguments, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If len is 0, return -1F.
If fromIndex is present, let n be ? ToIntegerOrInfinity(fromIndex); else let n be len - 1.
If n is -, return -1F.
If n 0, then
Let k be min(n, len - 1).
Else,
Let k be len + n.
Repeat, while k 0,
Let kPresent be ! HasProperty(O, ! ToString(F(k))).
If kPresent is true, then
Let elementK be ! Get(O, ! ToString(F(k))).
Let same be the result of performing Strict Equality Comparison searchElement === elementK.
If same is true, return F(k).
Set k to k - 1.
Return -1F.
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
const sample = new TA(1);
const fromIndex = {
valueOf() {
$DETACHBUFFER(sample.buffer);
return 0;
}
};
assert.sameValue(sample.lastIndexOf(0n, fromIndex), -1);
});

View File

@ -0,0 +1,46 @@
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.lastindexof
description: Returns -1 if buffer is detached after ValidateTypedArray
info: |
%TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of %TypedArray%.prototype.lastIndexOf are the same as for Array.prototype.lastIndexOf as defined in 22.1.3.17.
When the lastIndexOf method is called with one or two arguments, the following steps are taken:
Let O be the this value.
Perform ? ValidateTypedArray(O).
Let len be O.[[ArrayLength]].
If len is 0, return -1F.
If fromIndex is present, let n be ? ToIntegerOrInfinity(fromIndex); else let n be len - 1.
If n is -, return -1F.
If n 0, then
Let k be min(n, len - 1).
Else,
Let k be len + n.
Repeat, while k 0,
Let kPresent be ! HasProperty(O, ! ToString(F(k))).
If kPresent is true, then
Let elementK be ! Get(O, ! ToString(F(k))).
Let same be the result of performing Strict Equality Comparison searchElement === elementK.
If same is true, return F(k).
Set k to k - 1.
Return -1F.
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [align-detached-buffer-semantics-with-web-reality, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
const sample = new TA(1);
const fromIndex = {
valueOf() {
$DETACHBUFFER(sample.buffer);
return 0;
}
};
assert.sameValue(sample.lastIndexOf(0, fromIndex), -1);
});

View File

@ -30,6 +30,7 @@ testWithTypedArrayConstructors(function(TA) {
let sample = new TA([42]);
$DETACHBUFFER(sample.buffer);
sample[0] = 1;
assert.sameValue(sample[0], undefined, '`sample[0] = 1` is undefined');
sample['1.1'] = 1;
assert.sameValue(sample['1.1'], undefined, '`sample[\'1.1\'] = 1` is undefined');