From dbb80c81a694959e578790cc2ea0a70e7bd0c7b4 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg <littledan@chromium.org> Date: Tue, 21 Mar 2017 11:41:26 +0100 Subject: [PATCH] Test that TypedArray constructor throws when detaching buffer in length calculation This test is only valid with the PR in https://github.com/tc39/ecma262/pull/852 --- .../TypedArrays/buffer-arg-detached.js | 2 +- .../byteoffset-arg-detachbuffer.js | 2 +- .../TypedArrays/length-arg-detachbuffer.js | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/built-ins/TypedArrays/length-arg-detachbuffer.js diff --git a/test/built-ins/TypedArrays/buffer-arg-detached.js b/test/built-ins/TypedArrays/buffer-arg-detached.js index 9e112d0bca..7a69e249ea 100644 --- a/test/built-ins/TypedArrays/buffer-arg-detached.js +++ b/test/built-ins/TypedArrays/buffer-arg-detached.js @@ -7,7 +7,7 @@ info: > 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) ... - 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. ... includes: [testTypedArray.js, detachArrayBuffer.js] ---*/ diff --git a/test/built-ins/TypedArrays/byteoffset-arg-detachbuffer.js b/test/built-ins/TypedArrays/byteoffset-arg-detachbuffer.js index 5f3406ce1c..c290dcdc11 100644 --- a/test/built-ins/TypedArrays/byteoffset-arg-detachbuffer.js +++ b/test/built-ins/TypedArrays/byteoffset-arg-detachbuffer.js @@ -7,7 +7,7 @@ info: > 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) ... - 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. ... includes: [testTypedArray.js, detachArrayBuffer.js] ---*/ diff --git a/test/built-ins/TypedArrays/length-arg-detachbuffer.js b/test/built-ins/TypedArrays/length-arg-detachbuffer.js new file mode 100644 index 0000000000..a4d57d6e57 --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-detachbuffer.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: If TypedArray() is passed a detached buffer, throw +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + var length = { valueOf() { $DETACHBUFFER(buffer); return 1; } }; + assert.throws(TypeError, () => new TA(buffer, 0, length)); +}); -- GitLab