From 755b0d61171a7b16fd81979bc8d6f24bb832ecc6 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Wed, 23 Mar 2016 15:23:48 -0400 Subject: [PATCH] Add tests for typedArrays extensibility Ref: https://github.com/tc39/test262/pull/536#issuecomment-200455389 --- .../buffer-arg-new-instance-extensibility.js | 36 +++++++++++++++ .../length-arg-new-instance-extensibility.js | 37 +++++++++++++++ .../no-args-new-instance-extensibility.js | 37 +++++++++++++++ .../object-arg-new-instance-extensibility.js | 42 +++++++++++++++++ ...pedarray-arg-new-instance-extensibility.js | 45 +++++++++++++++++++ 5 files changed, 197 insertions(+) create mode 100644 test/built-ins/TypedArrays/buffer-arg-new-instance-extensibility.js create mode 100644 test/built-ins/TypedArrays/length-arg-new-instance-extensibility.js create mode 100644 test/built-ins/TypedArrays/no-args-new-instance-extensibility.js create mode 100644 test/built-ins/TypedArrays/object-arg-new-instance-extensibility.js create mode 100644 test/built-ins/TypedArrays/typedarray-arg-new-instance-extensibility.js diff --git a/test/built-ins/TypedArrays/buffer-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/buffer-arg-new-instance-extensibility.js new file mode 100644 index 0000000000..843369f9da --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-new-instance-extensibility.js @@ -0,0 +1,36 @@ +// 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-buffer-byteoffset-length +description: > + The new typedArray instance from a buffer argument is extensible +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/length-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/length-arg-new-instance-extensibility.js new file mode 100644 index 0000000000..7f71859bca --- /dev/null +++ b/test/built-ins/TypedArrays/length-arg-new-instance-extensibility.js @@ -0,0 +1,37 @@ +// 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-length +description: > + The new typedArray instance from a length argument is extensible +info: > + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/no-args-new-instance-extensibility.js b/test/built-ins/TypedArrays/no-args-new-instance-extensibility.js new file mode 100644 index 0000000000..ef2893313d --- /dev/null +++ b/test/built-ins/TypedArrays/no-args-new-instance-extensibility.js @@ -0,0 +1,37 @@ +// 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 +description: > + The new typedArray instance is extensible +info: > + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/object-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/object-arg-new-instance-extensibility.js new file mode 100644 index 0000000000..b24132104d --- /dev/null +++ b/test/built-ins/TypedArrays/object-arg-new-instance-extensibility.js @@ -0,0 +1,42 @@ +// 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-object +description: > + The new typedArray instance from an object argument is extensible +info: > + 22.2.4.4 TypedArray ( object ) + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testTypedArray.js] +---*/ + +var obj = { + "0": 0, + "1": 1, + "2": 2, + length: 3 +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(obj); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/typedarray-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/typedarray-arg-new-instance-extensibility.js new file mode 100644 index 0000000000..604233609e --- /dev/null +++ b/test/built-ins/TypedArrays/typedarray-arg-new-instance-extensibility.js @@ -0,0 +1,45 @@ +// 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-typedarray +description: > + The new typedArray instance from a typedArray argument is extensible +info: > + 22.2.4.3 TypedArray ( typedArray ) + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testTypedArray.js] +---*/ + +var typedArraySample1 = new Int8Array(); +var typedArraySample2 = new Int8Array(); +Object.preventExtensions(typedArraySample2); + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(typedArraySample1); + + assert(Object.isExtensible(sample1), "new instance is extensible"); + + var sample2 = new TA(typedArraySample2); + assert( + Object.isExtensible(sample2), + "new instance does not inherit extensibility from typedarray argument" + ); +});