diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/detached-buffer.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/detached-buffer.js new file mode 100644 index 0000000000..f80f9189b1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/detached-buffer.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: The getter method does not throw with a detached buffer +info: > + 22.2.3.32 get %TypedArray%.prototype [ @@toStringTag ] + + ... + 4. Let name be the value of O's [[TypedArrayName]] internal slot. + 5. Assert: name is a String value. + 6. Return name. +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample[Symbol.toStringTag], TA.name); +}); diff --git a/test/built-ins/TypedArray/prototype/buffer/detached-buffer.js b/test/built-ins/TypedArray/prototype/buffer/detached-buffer.js new file mode 100644 index 0000000000..4ae269ba0a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/buffer/detached-buffer.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: The getter method does not throw with a detached buffer +info: > + 22.2.3.1 get %TypedArray%.prototype.buffer + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. Return buffer. +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(8); + var sample = new TA(buffer, 0, 1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.buffer, buffer); +}); diff --git a/test/built-ins/TypedArray/prototype/byteLength/detached-buffer.js b/test/built-ins/TypedArray/prototype/byteLength/detached-buffer.js new file mode 100644 index 0000000000..74e124761e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteLength/detached-buffer.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: Returns 0 if the instance has a detached buffer +info: > + 22.2.3.2 get %TypedArray%.prototype.byteLength + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.byteLength, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/byteOffset/detached-buffer.js b/test/built-ins/TypedArray/prototype/byteOffset/detached-buffer.js new file mode 100644 index 0000000000..d8100bc6eb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteOffset/detached-buffer.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: Returns 0 if the instance has a detached buffer +info: > + 22.2.3.3 get %TypedArray%.prototype.byteOffset + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(128); + var sample = new TA(buffer, 8, 1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.byteOffset, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/detached-buffer.js b/test/built-ins/TypedArray/prototype/copyWithin/detached-buffer.js new file mode 100644 index 0000000000..335ea7f836 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/detached-buffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.copywithin +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.copyWithin(obj, obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/entries/detached-buffer.js b/test/built-ins/TypedArray/prototype/entries/detached-buffer.js new file mode 100644 index 0000000000..7839eb5d26 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/entries/detached-buffer.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.entries +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.6 %TypedArray%.prototype.entries ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.entries(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/every/detached-buffer.js b/test/built-ins/TypedArray/prototype/every/detached-buffer.js new file mode 100644 index 0000000000..171695542a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.every(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/detached-buffer.js b/test/built-ins/TypedArray/prototype/fill/detached-buffer.js new file mode 100644 index 0000000000..dff2522d9b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/detached-buffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.fill(obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/detached-buffer.js b/test/built-ins/TypedArray/prototype/filter/detached-buffer.js new file mode 100644 index 0000000000..2effd4cb9c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/find/detached-buffer.js b/test/built-ins/TypedArray/prototype/find/detached-buffer.js new file mode 100644 index 0000000000..f53e423dc1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.find +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.find(predicate); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/detached-buffer.js b/test/built-ins/TypedArray/prototype/findIndex/detached-buffer.js new file mode 100644 index 0000000000..f8ccd34c9b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.findindex +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.findIndex(predicate); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/detached-buffer.js b/test/built-ins/TypedArray/prototype/forEach/detached-buffer.js new file mode 100644 index 0000000000..5b9f1af0c0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.foreach +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.forEach(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/detached-buffer.js b/test/built-ins/TypedArray/prototype/includes/detached-buffer.js new file mode 100644 index 0000000000..59ee5b00f0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/detached-buffer.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.includes(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/detached-buffer.js b/test/built-ins/TypedArray/prototype/indexOf/detached-buffer.js new file mode 100644 index 0000000000..45345f663b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/detached-buffer.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. 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: > + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.indexOf(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/join/detached-buffer.js b/test/built-ins/TypedArray/prototype/join/detached-buffer.js new file mode 100644 index 0000000000..b1e9b8a4ff --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/detached-buffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.join +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.15 %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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.join(obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/keys/detached-buffer.js b/test/built-ins/TypedArray/prototype/keys/detached-buffer.js new file mode 100644 index 0000000000..9000308f9d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/detached-buffer.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.keys +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.16 %TypedArray%.prototype.keys ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.keys(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer.js b/test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer.js new file mode 100644 index 0000000000..a4f42db4ef --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/detached-buffer.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.lastindexof +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.lastIndexOf(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/length/detached-buffer.js b/test/built-ins/TypedArray/prototype/length/detached-buffer.js new file mode 100644 index 0000000000..e7a912885e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/detached-buffer.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype.length +description: Returns 0 if the instance has a detached buffer +info: > + 22.2.3.18 get %TypedArray%.prototype.length + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.length, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/map/detached-buffer.js b/test/built-ins/TypedArray/prototype/map/detached-buffer.js new file mode 100644 index 0000000000..7cc09b5eb9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.map(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/detached-buffer.js b/test/built-ins/TypedArray/prototype/reduce/detached-buffer.js new file mode 100644 index 0000000000..795e7f4af1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduce +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reduce(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/detached-buffer.js b/test/built-ins/TypedArray/prototype/reduceRight/detached-buffer.js new file mode 100644 index 0000000000..22505f257f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduceright +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reduceRight(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reverse/detached-buffer.js b/test/built-ins/TypedArray/prototype/reverse/detached-buffer.js new file mode 100644 index 0000000000..0eddeb3010 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/detached-buffer.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reverse +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.22 %TypedArray%.prototype.reverse ( ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reverse(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/set/detached-buffer.js b/test/built-ins/TypedArray/prototype/set/detached-buffer.js new file mode 100644 index 0000000000..d26fc68f05 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/detached-buffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.23 %TypedArray%.prototype.set ( overloaded [ , offset ]) + + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + ... + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... + + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + ... + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.set([]); + }, "argument is an array"); + + assert.throws(TypeError, function() { + sample.set(sample); + }, "argument is a TypedArray object"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/detached-buffer.js b/test/built-ins/TypedArray/prototype/slice/detached-buffer.js new file mode 100644 index 0000000000..e3e32168ea --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/detached-buffer.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.slice(obj, obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/some/detached-buffer.js b/test/built-ins/TypedArray/prototype/some/detached-buffer.js new file mode 100644 index 0000000000..1555cf64dd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.some +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.some(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/detached-buffer.js b/test/built-ins/TypedArray/prototype/sort/detached-buffer.js new file mode 100644 index 0000000000..17f13c4465 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/detached-buffer.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.sort +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value. + 2. Let buffer be ? ValidateTypedArray(obj). + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +var comparefn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.sort(comparefn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/detached-buffer.js b/test/built-ins/TypedArray/prototype/toLocaleString/detached-buffer.js new file mode 100644 index 0000000000..b72be0968a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/detached-buffer.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.tolocalestring +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + 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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toLocaleString(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/toString/detached-buffer.js b/test/built-ins/TypedArray/prototype/toString/detached-buffer.js new file mode 100644 index 0000000000..d9be9c4608 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toString/detached-buffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.tostring +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.29 %TypedArray%.prototype.toString () + + ... + + 22.2.3.15 %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. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toString(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/values/detached-buffer.js b/test/built-ins/TypedArray/prototype/values/detached-buffer.js new file mode 100644 index 0000000000..e2f2548ce0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/detached-buffer.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.values +description: Throws a TypeError if this has a detached buffer +info: > + 22.2.3.30 %TypedArray%.prototype.values ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.values(); + }); +});