From 7f96cb10c174ab3d82210154d8e28b7392a4f26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Fri, 8 Dec 2017 13:22:34 -0800 Subject: [PATCH] Add tests for accessing Infinity on detached typed arrays --- .../internals/Get/infinity-detached-buffer.js | 39 ++++++++++++++++++ .../enumerate-detached-buffer.js | 41 +++++++++++++++++++ .../infinity-with-detached-buffer.js | 35 ++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 test/built-ins/TypedArrays/internals/Get/infinity-detached-buffer.js create mode 100644 test/built-ins/TypedArrays/internals/GetOwnProperty/enumerate-detached-buffer.js create mode 100644 test/built-ins/TypedArrays/internals/HasProperty/infinity-with-detached-buffer.js diff --git a/test/built-ins/TypedArrays/internals/Get/infinity-detached-buffer.js b/test/built-ins/TypedArrays/internals/Get/infinity-detached-buffer.js new file mode 100644 index 0000000000..3451ea2494 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/infinity-detached-buffer.js @@ -0,0 +1,39 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +id: sec-integerindexedelementget +info: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +description: | + 9.4.5.4 [[Get]] ( P, Receiver ) + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + ... + 3. Let buffer be O.[[ViewedArrayBuffer]]. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample.Infinity; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/enumerate-detached-buffer.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/enumerate-detached-buffer.js new file mode 100644 index 0000000000..b5ff13a34d --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/enumerate-detached-buffer.js @@ -0,0 +1,41 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +id: sec-integer-indexed-exotic-objects-getownproperty-p +info: Test for-in enumeration with detached buffer. +description: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + ... + 3. Let buffer be O.[[ViewedArrayBuffer]]. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + + 13.7.5.15 EnumerateObjectProperties (O) + ... + EnumerateObjectProperties must obtain the own property keys of the + target object by calling its [[OwnPropertyKeys]] internal method. + Property attributes of the target object must be obtained by + calling its [[GetOwnProperty]] internal method. + +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + for (var key in sample) { + throw new Test262Error(); + } + }); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/infinity-with-detached-buffer.js b/test/built-ins/TypedArrays/internals/HasProperty/infinity-with-detached-buffer.js new file mode 100644 index 0000000000..4d2001f03f --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/infinity-with-detached-buffer.js @@ -0,0 +1,35 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +id: sec-integer-indexed-exotic-objects-hasproperty-p +info: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +description: | + 9.4.5.2 [[HasProperty]]( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + +flags: [noStrict] +includes: [testTypedArray.js, detachArrayBuffer.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + with (sample) Infinity; + }); +});