diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js index 888adae73c..056a22f6a9 100644 --- a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js @@ -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 ) diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js index a5e64a7d18..b3153a71f9 100644 --- a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js index 5ce258d5c3..43ee9c7ed9 100644 --- a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js index 29258266b6..2092fdd055 100644 --- a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js index 851468f93f..13773be7a9 100644 --- a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js index 67372bd737..f6775fd9fd 100644 --- a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.js b/test/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.js index 7f8eb4bb70..c5207efae4 100644 --- a/test/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.js +++ b/test/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.js b/test/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.js index 8d041cd986..9547ff6cf0 100644 --- a/test/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.js +++ b/test/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/detached-buffer-get-ctor.js b/test/built-ins/TypedArray/prototype/slice/detached-buffer-get-ctor.js index fc6fe21015..d0f659bfcb 100644 --- a/test/built-ins/TypedArray/prototype/slice/detached-buffer-get-ctor.js +++ b/test/built-ins/TypedArray/prototype/slice/detached-buffer-get-ctor.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js b/test/built-ins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js index 6bab6b6c36..7e4412e945 100644 --- a/test/built-ins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js +++ b/test/built-ins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js b/test/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js index d081be3a1b..d8548c3bb4 100644 --- a/test/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js +++ b/test/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js @@ -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'); }); diff --git a/test/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js b/test/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js index 549d56c876..b2df9f99d1 100644 --- a/test/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js +++ b/test/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js @@ -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'); });