sec-%typedarray%.prototype.slice

This commit is contained in:
Rick Waldron 2020-09-28 14:30:21 -04:00
parent 36c2cd165f
commit 9c069a6810
12 changed files with 174 additions and 174 deletions

View File

@ -3,7 +3,7 @@
/*---
esid: sec-%typedarray%.prototype.slice
description: >
Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached.
Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached during Get custom constructor (other targetType)
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )

View File

@ -2,33 +2,35 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.slice
description: Throws a TypeError buffer is detached on Get custom constructor.
description: Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached on Get custom constructor.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
14. If SameValue(srcType, targetType) is false, then
...
15. Else if count > 0, then
a. Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot.
b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [BigInt, Symbol.species, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(1);
let counter = 0;
let sample = new TA(1);
sample.constructor = {};
sample.constructor[Symbol.species] = function(count) {
counter++;
assert.sameValue(count, 1, 'The value of `count` is 1');
$DETACHBUFFER(sample.buffer);
return new TA(count);
};
assert.throws(TypeError, function() {
counter++;
sample.slice();
}, "step 15.b, IsDetachedBuffer(srcBuffer) is true");
}, '`sample.slice()` throws TypeError');
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -2,32 +2,33 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.slice
description: Throws a TypeError buffer is detached on Get constructor.
description: Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
14. If SameValue(srcType, targetType) is false, then
...
15. Else if count > 0, then
a. Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot.
b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [BigInt, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(1);
let counter = 0;
let sample = new TA(1);
Object.defineProperty(sample, "constructor", {
get: function() {
get() {
counter++;
$DETACHBUFFER(sample.buffer);
}
});
assert.throws(TypeError, function() {
counter++;
sample.slice();
});
}, '`sample.slice()` throws TypeError');
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -2,42 +2,37 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.slice
description: >
Custom @@species constructor throws if it returns an instance with a detached
buffer
description: Throws a TypeError if buffer of object created by custom constructor is detached.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
Return A.
22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList )
...
3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor).
4. Return ? TypedArrayCreate(constructor, argumentList).
22.2.4.6 TypedArrayCreate ( constructor, argumentList )
1. Let newTypedArray be ? Construct(constructor, argumentList).
2. Perform ? ValidateTypedArray(newTypedArray).
...
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [BigInt, Symbol.species, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
let counter = 0;
let sample = new TA(1);
sample.constructor = {};
sample.constructor[Symbol.species] = function(count) {
var other = new TA(count);
let other = new TA(count);
counter++;
assert.sameValue(count, 1, 'The value of `count` is 1');
$DETACHBUFFER(other.buffer);
return other;
};
assert.throws(TypeError, function() {
counter++;
sample.slice();
});
}, '`sample.slice()` throws TypeError');
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -4,45 +4,44 @@
esid: sec-%typedarray%.prototype.slice
description: >
Does not throw a TypeError if buffer is detached on custom constructor and
`k >= final`. Using other targetType.
count <= 0. Using other targetType.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
14. If SameValue(srcType, targetType) is false, then
a. Let n be 0.
b. Repeat, while k < final
...
ii. Let kValue be ? Get(O, Pk).
...
...
16. Return A.
Return A
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [BigInt, Symbol.species, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
var sample, result, other;
var ctor = {};
let counter = 0;
let sample, result, Other, other;
let ctor = {};
ctor[Symbol.species] = function(count) {
other = TA === BigInt64Array ? BigUint64Array : BigInt64Array;
counter++;
assert.sameValue(count, 0);
Other = TA === BigInt64Array ? BigUint64Array : BigInt64Array;
$DETACHBUFFER(sample.buffer);
return new other(count);
other = new Other(count);
return other;
};
sample = new TA(0);
sample.constructor = ctor;
result = sample.slice();
assert.sameValue(result.length, 0, "#1: result.length");
assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer");
assert.sameValue(result.constructor, other, "#1: ctor");
assert.sameValue(result.length, 0, 'The value of result.length is 0');
assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`');
assert.sameValue(result.constructor, Other, 'The value of result.constructor is expected to equal the value of Other');
assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other');
assert.sameValue(counter, 1, 'The value of `counter` is 1');
sample = new TA(4);
sample.constructor = ctor;
result = sample.slice(1, 1);
assert.sameValue(result.length, 0, "#2: result.length");
assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer");
assert.sameValue(result.constructor, other, "#2: ctor");
sample.slice(1, 1); // count = 0;
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -4,42 +4,48 @@
esid: sec-%typedarray%.prototype.slice
description: >
Does not throw a TypeError if buffer is detached on custom constructor and
`k >= final`. Using same targetType.
count <= 0. Using same targetType.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
14. If SameValue(srcType, targetType) is false, then
...
15. Else if count > 0, then
a. Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot.
b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
...
Return A
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [BigInt, Symbol.species, TypedArray]
---*/
testWithBigIntTypedArrayConstructors(function(TA) {
var sample, result;
var ctor = {};
let counter = 0;
let sample, result, other;
let ctor = {};
ctor[Symbol.species] = function(count) {
counter++;
assert.sameValue(count, 0, 'The value of `count` is 0');
$DETACHBUFFER(sample.buffer);
return new TA(count);
other = new TA(count);
return other;
};
sample = new TA(0);
sample.constructor = ctor;
result = sample.slice();
assert.sameValue(result.length, 0, "#1: result.length");
assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer");
assert.sameValue(result.constructor, TA, "#1: ctor");
assert.sameValue(result.length, 0, 'The value of result.length is 0');
assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`');
assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other');
assert.sameValue(counter, 1, 'The value of `counter` is 1');
sample = new TA(4);
sample.constructor = ctor;
result = sample.slice(1, 1);
assert.sameValue(result.length, 0, "#2: result.length");
assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer");
assert.sameValue(result.constructor, TA, "#2: ctor");
result = sample.slice(1, 1); // count = 0;
assert.sameValue(result.length, 0, 'The value of result.length is 0');
assert.notSameValue(
result.buffer,
sample.buffer,
'The value of result.buffer is expected to not equal the value of `sample.buffer`'
);
assert.sameValue(result.constructor, TA, 'The value of result.constructor is expected to equal the value of TA');
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -3,36 +3,37 @@
/*---
esid: sec-%typedarray%.prototype.slice
description: >
Throws a TypeError buffer is detached on Get custom constructor. Using other
Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached. Using other
targetType
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
14. If SameValue(srcType, targetType) is false, then
a. Let n be 0.
b. Repeat, while k < final
...
ii. Let kValue be ? Get(O, Pk).
...
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Symbol.species, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
let counter = 0;
var sample = new TA(1);
sample.constructor = {};
sample.constructor[Symbol.species] = function(count) {
var other = TA === Int8Array ? Int16Array : Int8Array;
counter++;
assert.sameValue(count, 1, 'The value of `count` is 1');
$DETACHBUFFER(sample.buffer);
return new other(count);
};
assert.throws(TypeError, function() {
counter++;
sample.slice();
}, "step 14.b.ii - ? Get(O, Pk), O has a detached buffer");
}, '`sample.slice()` throws TypeError');
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -2,33 +2,35 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.slice
description: Throws a TypeError buffer is detached on Get custom constructor.
description: Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached on Get custom constructor.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
14. If SameValue(srcType, targetType) is false, then
...
15. Else if count > 0, then
a. Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot.
b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Symbol.species, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
let counter = 0;
let sample = new TA(1);
sample.constructor = {};
sample.constructor[Symbol.species] = function(count) {
counter++;
assert.sameValue(count, 1, 'The value of `count` is 1');
$DETACHBUFFER(sample.buffer);
return new TA(count);
};
assert.throws(TypeError, function() {
counter++;
sample.slice();
}, "step 15.b, IsDetachedBuffer(srcBuffer) is true");
}, '`sample.slice()` throws TypeError');
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -2,32 +2,33 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.slice
description: Throws a TypeError buffer is detached on Get constructor.
description: Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
14. If SameValue(srcType, targetType) is false, then
...
15. Else if count > 0, then
a. Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot.
b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [TypedArray]
features: [Symbol.species, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
let counter = 0;
let sample = new TA(1);
Object.defineProperty(sample, "constructor", {
get: function() {
get() {
counter++;
$DETACHBUFFER(sample.buffer);
}
});
assert.throws(TypeError, function() {
counter++;
sample.slice();
});
}, '`sample.slice()` throws TypeError');
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -2,42 +2,37 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.slice
description: >
Custom @@species constructor throws if it returns an instance with a detached
buffer
description: Throws a TypeError if buffer of object created by custom constructor is detached.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
Return A.
22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList )
...
3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor).
4. Return ? TypedArrayCreate(constructor, argumentList).
22.2.4.6 TypedArrayCreate ( constructor, argumentList )
1. Let newTypedArray be ? Construct(constructor, argumentList).
2. Perform ? ValidateTypedArray(newTypedArray).
...
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Symbol.species, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
let counter = 0;
let sample = new TA(1);
sample.constructor = {};
sample.constructor[Symbol.species] = function(count) {
var other = new TA(count);
let other = new TA(count);
counter++;
assert.sameValue(count, 1, 'The value of `count` is 1');
$DETACHBUFFER(other.buffer);
return other;
};
assert.throws(TypeError, function() {
counter++;
sample.slice();
});
}, '`sample.slice()` throws TypeError');
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -4,45 +4,44 @@
esid: sec-%typedarray%.prototype.slice
description: >
Does not throw a TypeError if buffer is detached on custom constructor and
`k >= final`. Using other targetType.
count <= 0. Using other targetType.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
14. If SameValue(srcType, targetType) is false, then
a. Let n be 0.
b. Repeat, while k < final
...
ii. Let kValue be ? Get(O, Pk).
...
...
16. Return A.
Return A
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Symbol.species, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample, result, other;
var ctor = {};
let counter = 0;
let sample, result, Other, other;
let ctor = {};
ctor[Symbol.species] = function(count) {
other = TA === Int8Array ? Int16Array : Int8Array;
counter++;
assert.sameValue(count, 0);
Other = TA === Int16Array ? Int8Array : Int16Array;
$DETACHBUFFER(sample.buffer);
return new other(count);
other = new Other(count);
return other;
};
sample = new TA(0);
sample.constructor = ctor;
result = sample.slice();
assert.sameValue(result.length, 0, "#1: result.length");
assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer");
assert.sameValue(result.constructor, other, "#1: ctor");
assert.sameValue(result.length, 0, 'The value of result.length is 0');
assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`');
assert.sameValue(result.constructor, Other, 'The value of result.constructor is expected to equal the value of Other');
assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other');
assert.sameValue(counter, 1, 'The value of `counter` is 1');
sample = new TA(4);
sample.constructor = ctor;
result = sample.slice(1, 1);
assert.sameValue(result.length, 0, "#2: result.length");
assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer");
assert.sameValue(result.constructor, other, "#2: ctor");
sample.slice(1, 1); // count = 0;
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});

View File

@ -4,42 +4,41 @@
esid: sec-%typedarray%.prototype.slice
description: >
Does not throw a TypeError if buffer is detached on custom constructor and
`k >= final`. Using same targetType.
count <= 0. Using other targetType.
info: |
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
Let A be ? TypedArraySpeciesCreate(O, « count »).
If count > 0, then
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
...
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
...
14. If SameValue(srcType, targetType) is false, then
...
15. Else if count > 0, then
a. Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot.
b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
...
Return A
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Symbol.species, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample, result;
var ctor = {};
let counter = 0;
let sample, result, other;
let ctor = {};
ctor[Symbol.species] = function(count) {
counter++;
assert.sameValue(count, 0);
$DETACHBUFFER(sample.buffer);
return new TA(count);
other = new TA(count);
return other;
};
sample = new TA(0);
sample.constructor = ctor;
result = sample.slice();
assert.sameValue(result.length, 0, "#1: result.length");
assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer");
assert.sameValue(result.constructor, TA, "#1: ctor");
assert.sameValue(result.length, 0, 'The value of result.length is 0');
assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`');
assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other');
assert.sameValue(counter, 1, 'The value of `counter` is 1');
sample = new TA(4);
sample.constructor = ctor;
result = sample.slice(1, 1);
assert.sameValue(result.length, 0, "#2: result.length");
assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer");
assert.sameValue(result.constructor, TA, "#2: ctor");
sample.slice(1, 1); // count = 0;
assert.sameValue(counter, 2, 'The value of `counter` is 2');
});