mirror of https://github.com/tc39/test262.git
sec-%typedarray%.prototype.slice
This commit is contained in:
parent
36c2cd165f
commit
9c069a6810
|
@ -3,7 +3,7 @@
|
||||||
/*---
|
/*---
|
||||||
esid: sec-%typedarray%.prototype.slice
|
esid: sec-%typedarray%.prototype.slice
|
||||||
description: >
|
description: >
|
||||||
Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached.
|
Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached during Get custom constructor (other targetType)
|
||||||
info: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
||||||
|
|
||||||
|
|
|
@ -2,33 +2,35 @@
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
esid: sec-%typedarray%.prototype.slice
|
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: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
||||||
|
|
||||||
...
|
...
|
||||||
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
|
Let A be ? TypedArraySpeciesCreate(O, « count »).
|
||||||
...
|
If count > 0, then
|
||||||
14. If SameValue(srcType, targetType) is false, then
|
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
|
||||||
...
|
|
||||||
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.
|
|
||||||
...
|
...
|
||||||
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [BigInt, Symbol.species, TypedArray]
|
features: [BigInt, Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
var sample = new TA(1);
|
let counter = 0;
|
||||||
|
let sample = new TA(1);
|
||||||
|
|
||||||
sample.constructor = {};
|
sample.constructor = {};
|
||||||
sample.constructor[Symbol.species] = function(count) {
|
sample.constructor[Symbol.species] = function(count) {
|
||||||
|
counter++;
|
||||||
|
assert.sameValue(count, 1, 'The value of `count` is 1');
|
||||||
$DETACHBUFFER(sample.buffer);
|
$DETACHBUFFER(sample.buffer);
|
||||||
return new TA(count);
|
return new TA(count);
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
|
counter++;
|
||||||
sample.slice();
|
sample.slice();
|
||||||
}, "step 15.b, IsDetachedBuffer(srcBuffer) is true");
|
}, '`sample.slice()` throws TypeError');
|
||||||
|
|
||||||
|
assert.sameValue(counter, 2, 'The value of `counter` is 2');
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,32 +2,33 @@
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
esid: sec-%typedarray%.prototype.slice
|
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: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
||||||
|
|
||||||
...
|
...
|
||||||
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
|
Let A be ? TypedArraySpeciesCreate(O, « count »).
|
||||||
...
|
If count > 0, then
|
||||||
14. If SameValue(srcType, targetType) is false, then
|
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
|
||||||
...
|
|
||||||
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.
|
|
||||||
...
|
...
|
||||||
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [BigInt, TypedArray]
|
features: [BigInt, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
var sample = new TA(1);
|
let counter = 0;
|
||||||
|
let sample = new TA(1);
|
||||||
|
|
||||||
Object.defineProperty(sample, "constructor", {
|
Object.defineProperty(sample, "constructor", {
|
||||||
get: function() {
|
get() {
|
||||||
|
counter++;
|
||||||
$DETACHBUFFER(sample.buffer);
|
$DETACHBUFFER(sample.buffer);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
|
counter++;
|
||||||
sample.slice();
|
sample.slice();
|
||||||
});
|
}, '`sample.slice()` throws TypeError');
|
||||||
|
|
||||||
|
assert.sameValue(counter, 2, 'The value of `counter` is 2');
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,42 +2,37 @@
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
esid: sec-%typedarray%.prototype.slice
|
esid: sec-%typedarray%.prototype.slice
|
||||||
description: >
|
description: Throws a TypeError if buffer of object created by custom constructor is detached.
|
||||||
Custom @@species constructor throws if it returns an instance with a detached
|
|
||||||
buffer
|
|
||||||
info: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
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]
|
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [BigInt, Symbol.species, TypedArray]
|
features: [BigInt, Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
var sample = new TA();
|
let counter = 0;
|
||||||
|
let sample = new TA(1);
|
||||||
|
|
||||||
sample.constructor = {};
|
sample.constructor = {};
|
||||||
sample.constructor[Symbol.species] = function(count) {
|
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);
|
$DETACHBUFFER(other.buffer);
|
||||||
return other;
|
return other;
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
|
counter++;
|
||||||
sample.slice();
|
sample.slice();
|
||||||
});
|
}, '`sample.slice()` throws TypeError');
|
||||||
|
|
||||||
|
assert.sameValue(counter, 2, 'The value of `counter` is 2');
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,45 +4,44 @@
|
||||||
esid: sec-%typedarray%.prototype.slice
|
esid: sec-%typedarray%.prototype.slice
|
||||||
description: >
|
description: >
|
||||||
Does not throw a TypeError if buffer is detached on custom constructor and
|
Does not throw a TypeError if buffer is detached on custom constructor and
|
||||||
`k >= final`. Using other targetType.
|
count <= 0. Using other targetType.
|
||||||
info: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
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
|
||||||
...
|
|
||||||
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.
|
|
||||||
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [BigInt, Symbol.species, TypedArray]
|
features: [BigInt, Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
var sample, result, other;
|
let counter = 0;
|
||||||
var ctor = {};
|
let sample, result, Other, other;
|
||||||
|
let ctor = {};
|
||||||
ctor[Symbol.species] = function(count) {
|
ctor[Symbol.species] = function(count) {
|
||||||
other = TA === BigInt64Array ? BigUint64Array : BigInt64Array;
|
counter++;
|
||||||
|
assert.sameValue(count, 0);
|
||||||
|
Other = TA === BigInt64Array ? BigUint64Array : BigInt64Array;
|
||||||
$DETACHBUFFER(sample.buffer);
|
$DETACHBUFFER(sample.buffer);
|
||||||
return new other(count);
|
other = new Other(count);
|
||||||
|
return other;
|
||||||
};
|
};
|
||||||
|
|
||||||
sample = new TA(0);
|
sample = new TA(0);
|
||||||
sample.constructor = ctor;
|
sample.constructor = ctor;
|
||||||
result = sample.slice();
|
result = sample.slice();
|
||||||
assert.sameValue(result.length, 0, "#1: result.length");
|
assert.sameValue(result.length, 0, 'The value of result.length is 0');
|
||||||
assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer");
|
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, "#1: ctor");
|
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 = new TA(4);
|
||||||
sample.constructor = ctor;
|
sample.constructor = ctor;
|
||||||
result = sample.slice(1, 1);
|
sample.slice(1, 1); // count = 0;
|
||||||
assert.sameValue(result.length, 0, "#2: result.length");
|
assert.sameValue(counter, 2, 'The value of `counter` is 2');
|
||||||
assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer");
|
|
||||||
assert.sameValue(result.constructor, other, "#2: ctor");
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,42 +4,48 @@
|
||||||
esid: sec-%typedarray%.prototype.slice
|
esid: sec-%typedarray%.prototype.slice
|
||||||
description: >
|
description: >
|
||||||
Does not throw a TypeError if buffer is detached on custom constructor and
|
Does not throw a TypeError if buffer is detached on custom constructor and
|
||||||
`k >= final`. Using same targetType.
|
count <= 0. Using same targetType.
|
||||||
info: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
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
|
||||||
...
|
|
||||||
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.
|
|
||||||
...
|
|
||||||
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [BigInt, Symbol.species, TypedArray]
|
features: [BigInt, Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
var sample, result;
|
let counter = 0;
|
||||||
var ctor = {};
|
let sample, result, other;
|
||||||
|
let ctor = {};
|
||||||
ctor[Symbol.species] = function(count) {
|
ctor[Symbol.species] = function(count) {
|
||||||
|
counter++;
|
||||||
|
assert.sameValue(count, 0, 'The value of `count` is 0');
|
||||||
$DETACHBUFFER(sample.buffer);
|
$DETACHBUFFER(sample.buffer);
|
||||||
return new TA(count);
|
other = new TA(count);
|
||||||
|
return other;
|
||||||
};
|
};
|
||||||
|
|
||||||
sample = new TA(0);
|
sample = new TA(0);
|
||||||
sample.constructor = ctor;
|
sample.constructor = ctor;
|
||||||
result = sample.slice();
|
result = sample.slice();
|
||||||
assert.sameValue(result.length, 0, "#1: result.length");
|
assert.sameValue(result.length, 0, 'The value of result.length is 0');
|
||||||
assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer");
|
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, "#1: ctor");
|
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 = new TA(4);
|
||||||
sample.constructor = ctor;
|
sample.constructor = ctor;
|
||||||
result = sample.slice(1, 1);
|
result = sample.slice(1, 1); // count = 0;
|
||||||
assert.sameValue(result.length, 0, "#2: result.length");
|
assert.sameValue(result.length, 0, 'The value of result.length is 0');
|
||||||
assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer");
|
assert.notSameValue(
|
||||||
assert.sameValue(result.constructor, TA, "#2: ctor");
|
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');
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,36 +3,37 @@
|
||||||
/*---
|
/*---
|
||||||
esid: sec-%typedarray%.prototype.slice
|
esid: sec-%typedarray%.prototype.slice
|
||||||
description: >
|
description: >
|
||||||
Throws a TypeError buffer is detached on Get custom constructor. Using other
|
Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached. Using other
|
||||||
targetType
|
targetType
|
||||||
info: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
||||||
|
|
||||||
...
|
...
|
||||||
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
|
Let A be ? TypedArraySpeciesCreate(O, « count »).
|
||||||
...
|
If count > 0, then
|
||||||
14. If SameValue(srcType, targetType) is false, then
|
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
|
||||||
a. Let n be 0.
|
|
||||||
b. Repeat, while k < final
|
|
||||||
...
|
|
||||||
ii. Let kValue be ? Get(O, Pk).
|
|
||||||
...
|
|
||||||
...
|
...
|
||||||
includes: [testTypedArray.js, detachArrayBuffer.js]
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [Symbol.species, TypedArray]
|
features: [Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithTypedArrayConstructors(function(TA) {
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
let counter = 0;
|
||||||
var sample = new TA(1);
|
var sample = new TA(1);
|
||||||
|
|
||||||
sample.constructor = {};
|
sample.constructor = {};
|
||||||
sample.constructor[Symbol.species] = function(count) {
|
sample.constructor[Symbol.species] = function(count) {
|
||||||
var other = TA === Int8Array ? Int16Array : Int8Array;
|
var other = TA === Int8Array ? Int16Array : Int8Array;
|
||||||
|
counter++;
|
||||||
|
assert.sameValue(count, 1, 'The value of `count` is 1');
|
||||||
$DETACHBUFFER(sample.buffer);
|
$DETACHBUFFER(sample.buffer);
|
||||||
return new other(count);
|
return new other(count);
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
|
counter++;
|
||||||
sample.slice();
|
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');
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,33 +2,35 @@
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
esid: sec-%typedarray%.prototype.slice
|
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: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
||||||
|
|
||||||
...
|
...
|
||||||
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
|
Let A be ? TypedArraySpeciesCreate(O, « count »).
|
||||||
...
|
If count > 0, then
|
||||||
14. If SameValue(srcType, targetType) is false, then
|
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
|
||||||
...
|
|
||||||
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.
|
|
||||||
...
|
...
|
||||||
includes: [testTypedArray.js, detachArrayBuffer.js]
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [Symbol.species, TypedArray]
|
features: [Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithTypedArrayConstructors(function(TA) {
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
var sample = new TA(1);
|
let counter = 0;
|
||||||
|
let sample = new TA(1);
|
||||||
|
|
||||||
sample.constructor = {};
|
sample.constructor = {};
|
||||||
sample.constructor[Symbol.species] = function(count) {
|
sample.constructor[Symbol.species] = function(count) {
|
||||||
|
counter++;
|
||||||
|
assert.sameValue(count, 1, 'The value of `count` is 1');
|
||||||
$DETACHBUFFER(sample.buffer);
|
$DETACHBUFFER(sample.buffer);
|
||||||
return new TA(count);
|
return new TA(count);
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
|
counter++;
|
||||||
sample.slice();
|
sample.slice();
|
||||||
}, "step 15.b, IsDetachedBuffer(srcBuffer) is true");
|
}, '`sample.slice()` throws TypeError');
|
||||||
|
|
||||||
|
assert.sameValue(counter, 2, 'The value of `counter` is 2');
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,32 +2,33 @@
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
esid: sec-%typedarray%.prototype.slice
|
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: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
||||||
|
|
||||||
...
|
...
|
||||||
9. Let A be ? TypedArraySpeciesCreate(O, « count »).
|
Let A be ? TypedArraySpeciesCreate(O, « count »).
|
||||||
...
|
If count > 0, then
|
||||||
14. If SameValue(srcType, targetType) is false, then
|
If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
|
||||||
...
|
|
||||||
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.
|
|
||||||
...
|
...
|
||||||
includes: [testTypedArray.js, detachArrayBuffer.js]
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [TypedArray]
|
features: [Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithTypedArrayConstructors(function(TA) {
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
var sample = new TA(1);
|
let counter = 0;
|
||||||
|
let sample = new TA(1);
|
||||||
|
|
||||||
Object.defineProperty(sample, "constructor", {
|
Object.defineProperty(sample, "constructor", {
|
||||||
get: function() {
|
get() {
|
||||||
|
counter++;
|
||||||
$DETACHBUFFER(sample.buffer);
|
$DETACHBUFFER(sample.buffer);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
|
counter++;
|
||||||
sample.slice();
|
sample.slice();
|
||||||
});
|
}, '`sample.slice()` throws TypeError');
|
||||||
|
|
||||||
|
assert.sameValue(counter, 2, 'The value of `counter` is 2');
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,42 +2,37 @@
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
esid: sec-%typedarray%.prototype.slice
|
esid: sec-%typedarray%.prototype.slice
|
||||||
description: >
|
description: Throws a TypeError if buffer of object created by custom constructor is detached.
|
||||||
Custom @@species constructor throws if it returns an instance with a detached
|
|
||||||
buffer
|
|
||||||
info: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
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]
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [Symbol.species, TypedArray]
|
features: [Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithTypedArrayConstructors(function(TA) {
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
var sample = new TA();
|
let counter = 0;
|
||||||
|
let sample = new TA(1);
|
||||||
|
|
||||||
sample.constructor = {};
|
sample.constructor = {};
|
||||||
sample.constructor[Symbol.species] = function(count) {
|
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);
|
$DETACHBUFFER(other.buffer);
|
||||||
return other;
|
return other;
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
|
counter++;
|
||||||
sample.slice();
|
sample.slice();
|
||||||
});
|
}, '`sample.slice()` throws TypeError');
|
||||||
|
|
||||||
|
assert.sameValue(counter, 2, 'The value of `counter` is 2');
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,45 +4,44 @@
|
||||||
esid: sec-%typedarray%.prototype.slice
|
esid: sec-%typedarray%.prototype.slice
|
||||||
description: >
|
description: >
|
||||||
Does not throw a TypeError if buffer is detached on custom constructor and
|
Does not throw a TypeError if buffer is detached on custom constructor and
|
||||||
`k >= final`. Using other targetType.
|
count <= 0. Using other targetType.
|
||||||
info: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
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
|
||||||
...
|
|
||||||
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.
|
|
||||||
includes: [testTypedArray.js, detachArrayBuffer.js]
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [Symbol.species, TypedArray]
|
features: [Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithTypedArrayConstructors(function(TA) {
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
var sample, result, other;
|
let counter = 0;
|
||||||
var ctor = {};
|
let sample, result, Other, other;
|
||||||
|
let ctor = {};
|
||||||
ctor[Symbol.species] = function(count) {
|
ctor[Symbol.species] = function(count) {
|
||||||
other = TA === Int8Array ? Int16Array : Int8Array;
|
counter++;
|
||||||
|
assert.sameValue(count, 0);
|
||||||
|
Other = TA === Int16Array ? Int8Array : Int16Array;
|
||||||
$DETACHBUFFER(sample.buffer);
|
$DETACHBUFFER(sample.buffer);
|
||||||
return new other(count);
|
other = new Other(count);
|
||||||
|
return other;
|
||||||
};
|
};
|
||||||
|
|
||||||
sample = new TA(0);
|
sample = new TA(0);
|
||||||
sample.constructor = ctor;
|
sample.constructor = ctor;
|
||||||
result = sample.slice();
|
result = sample.slice();
|
||||||
assert.sameValue(result.length, 0, "#1: result.length");
|
assert.sameValue(result.length, 0, 'The value of result.length is 0');
|
||||||
assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer");
|
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, "#1: ctor");
|
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 = new TA(4);
|
||||||
sample.constructor = ctor;
|
sample.constructor = ctor;
|
||||||
result = sample.slice(1, 1);
|
sample.slice(1, 1); // count = 0;
|
||||||
assert.sameValue(result.length, 0, "#2: result.length");
|
assert.sameValue(counter, 2, 'The value of `counter` is 2');
|
||||||
assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer");
|
|
||||||
assert.sameValue(result.constructor, other, "#2: ctor");
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,42 +4,41 @@
|
||||||
esid: sec-%typedarray%.prototype.slice
|
esid: sec-%typedarray%.prototype.slice
|
||||||
description: >
|
description: >
|
||||||
Does not throw a TypeError if buffer is detached on custom constructor and
|
Does not throw a TypeError if buffer is detached on custom constructor and
|
||||||
`k >= final`. Using same targetType.
|
count <= 0. Using other targetType.
|
||||||
info: |
|
info: |
|
||||||
22.2.3.24 %TypedArray%.prototype.slice ( start, end )
|
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
|
||||||
...
|
|
||||||
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.
|
|
||||||
...
|
|
||||||
includes: [testTypedArray.js, detachArrayBuffer.js]
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
features: [Symbol.species, TypedArray]
|
features: [Symbol.species, TypedArray]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
testWithTypedArrayConstructors(function(TA) {
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
var sample, result;
|
let counter = 0;
|
||||||
var ctor = {};
|
let sample, result, other;
|
||||||
|
let ctor = {};
|
||||||
ctor[Symbol.species] = function(count) {
|
ctor[Symbol.species] = function(count) {
|
||||||
|
counter++;
|
||||||
|
assert.sameValue(count, 0);
|
||||||
$DETACHBUFFER(sample.buffer);
|
$DETACHBUFFER(sample.buffer);
|
||||||
return new TA(count);
|
other = new TA(count);
|
||||||
|
return other;
|
||||||
};
|
};
|
||||||
|
|
||||||
sample = new TA(0);
|
sample = new TA(0);
|
||||||
sample.constructor = ctor;
|
sample.constructor = ctor;
|
||||||
result = sample.slice();
|
result = sample.slice();
|
||||||
assert.sameValue(result.length, 0, "#1: result.length");
|
assert.sameValue(result.length, 0, 'The value of result.length is 0');
|
||||||
assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer");
|
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, "#1: ctor");
|
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 = new TA(4);
|
||||||
sample.constructor = ctor;
|
sample.constructor = ctor;
|
||||||
result = sample.slice(1, 1);
|
sample.slice(1, 1); // count = 0;
|
||||||
assert.sameValue(result.length, 0, "#2: result.length");
|
assert.sameValue(counter, 2, 'The value of `counter` is 2');
|
||||||
assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer");
|
|
||||||
assert.sameValue(result.constructor, TA, "#2: ctor");
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue