diff options
Diffstat (limited to '')
54 files changed, 2084 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 0000000000..17a67c109c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength modulo elementSize ≠ 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000..4fd2fe7557 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.js @@ -0,0 +1,34 @@ +// 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: > + Throws a RangeError if bufferByteLength modulo elementSize ≠ 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws-sab.js new file mode 100644 index 0000000000..8de2a88295 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws-sab.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) is < 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + 8. If offset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, -1); + }); + assert.throws(RangeError, function() { + new TA(buffer, -Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws.js new file mode 100644 index 0000000000..17c490f7d5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws.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-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) is < 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + 8. If offset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, -1); + }); + assert.throws(RangeError, function() { + new TA(buffer, -Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero-sab.js new file mode 100644 index 0000000000..067562add9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero-sab.js @@ -0,0 +1,26 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: pending +description: > + TypedArray's [[ByteOffset]] internal slot is always a positive number, test with negative zero. +info: | + %TypedArray% ( buffer [ , byteOffset [ , length ] ] ) + + ... + 6. Let offset be ? ToInteger(byteOffset). + 7. If offset < 0, throw a RangeError exception. + 8. If offset is -0, let offset be +0. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TAConstructor) { + var typedArray = new TAConstructor(new SharedArrayBuffer(8), -0); + assert.sameValue(typedArray.byteOffset, +0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js new file mode 100644 index 0000000000..e67b124ab2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: pending +description: > + TypedArray's [[ByteOffset]] internal slot is always a positive number, test with negative zero. +info: | + %TypedArray% ( buffer [ , byteOffset [ , length ] ] ) + + ... + 6. Let offset be ? ToInteger(byteOffset). + 7. If offset < 0, throw a RangeError exception. + 8. If offset is -0, let offset be +0. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TAConstructor) { + var typedArray = new TAConstructor(new ArrayBuffer(8), -0); + assert.sameValue(typedArray.byteOffset, +0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws-sab.js new file mode 100644 index 0000000000..ad2a67f321 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws-sab.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset as a symbol +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, SharedArrayBuffer, TypedArray] +---*/ + +var byteOffset = Symbol("1"); +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws.js new file mode 100644 index 0000000000..020fe02256 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws.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-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset as a symbol +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var byteOffset = Symbol("1"); +var buffer = new ArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 0000000000..af8fee1332 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,31 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) modulo elementSize is not 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 10. If offset modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000..7a06d2d90e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size.js @@ -0,0 +1,29 @@ +// 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: > + Throws a RangeError if ToInteger(byteOffset) modulo elementSize is not 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 10. If offset modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-detachbuffer.js new file mode 100644 index 0000000000..f7ed2b83f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-detachbuffer.js @@ -0,0 +1,23 @@ +// 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: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + var byteOffset = { valueOf() { $DETACHBUFFER(buffer); return offset; } }; + assert.throws(TypeError, () => new TA(buffer, byteOffset)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws-sab.js new file mode 100644 index 0000000000..cb1f36aa18 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); +var byteOffset = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws.js new file mode 100644 index 0000000000..4506ef7091 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws.js @@ -0,0 +1,34 @@ +// 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: > + Return abrupt from parsing integer value from byteOffset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); +var byteOffset = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws-sab.js new file mode 100644 index 0000000000..6e5409b30a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws-sab.js @@ -0,0 +1,51 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt completion getting newTarget's prototype +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [buffer], newTarget); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..108824e778 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws.js @@ -0,0 +1,49 @@ +// 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: > + Return abrupt completion getting newTarget's prototype +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [buffer], newTarget); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset-sab.js new file mode 100644 index 0000000000..48548d742f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from defined length and offset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(3 * offset); + + var ta1 = new TA(buffer, offset, 2); + assert.sameValue(ta1.length, 2, "ta1.length"); + assert.sameValue(ta1.buffer, buffer, "ta1.buffer"); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, offset, 0); + assert.sameValue(ta2.length, 0, "ta2.length"); + assert.sameValue(ta2.buffer, buffer, "ta2.buffer"); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset.js new file mode 100644 index 0000000000..2805a58bae --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset.js @@ -0,0 +1,34 @@ +// 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: > + Return new typedArray from defined length and offset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + + var ta1 = new TA(buffer, offset, 2); + assert.sameValue(ta1.length, 2, "ta1.length"); + assert.sameValue(ta1.buffer, buffer, "ta1.buffer"); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, offset, 0); + assert.sameValue(ta2.length, 0, "ta2.length"); + assert.sameValue(ta2.buffer, buffer, "ta2.buffer"); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-sab.js new file mode 100644 index 0000000000..b96e70672d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-sab.js @@ -0,0 +1,38 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from defined length +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var length = 4; + var buffer = new SharedArrayBuffer(bpe * length * 4); + + var ta1 = new TA(buffer, 0, length); + assert.sameValue(ta1.length, length); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0, 0); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length.js new file mode 100644 index 0000000000..67ea4cacef --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length.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: > + Return new typedArray from defined length +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var length = 4; + var buffer = new ArrayBuffer(bpe * length * 4); + + var ta1 = new TA(buffer, 0, length); + assert.sameValue(ta1.length, length); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0, 0); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length-sab.js new file mode 100644 index 0000000000..8af91702b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length-sab.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws RangeError for negative ToInteger(length) +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 0, -1); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, -Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length.js new file mode 100644 index 0000000000..9132a9611f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length.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-buffer-byteoffset-length +description: > + Throws RangeError for negative ToInteger(length) +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 0, -1); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, -Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset-sab.js new file mode 100644 index 0000000000..08b4ee8c7b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from defined offset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe * 4); + + var ta1 = new TA(buffer, bpe * 2); + assert.sameValue(ta1.length, 2); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0); + assert.sameValue(ta2.length, 4); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset.js new file mode 100644 index 0000000000..883f17b91f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset.js @@ -0,0 +1,34 @@ +// 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: > + Return new typedArray from defined offset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe * 4); + + var ta1 = new TA(buffer, bpe * 2); + assert.sameValue(ta1.length, 2); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0); + assert.sameValue(ta2.length, 4); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/detachedbuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/detachedbuffer.js new file mode 100644 index 0000000000..c9137f8f25 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/detachedbuffer.js @@ -0,0 +1,23 @@ +// 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: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + $DETACHBUFFER(buffer); + assert.throws(TypeError, () => new TA(buffer)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws-sab.js new file mode 100644 index 0000000000..d79be12adf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws-sab.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + If offset + newByteLength > bufferByteLength, throw a RangeError exception. +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + b. Let newByteLength be newLength × elementSize. + c. If offset+newByteLength > bufferByteLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, 0, bpe * 2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws.js new file mode 100644 index 0000000000..c617926519 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws.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-buffer-byteoffset-length +description: > + If offset + newByteLength > bufferByteLength, throw a RangeError exception. +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + b. Let newByteLength be newLength × elementSize. + c. If offset+newByteLength > bufferByteLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, 0, bpe * 2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws-sab.js new file mode 100644 index 0000000000..7eeb93fcea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws-sab.js @@ -0,0 +1,39 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength - ToInteger(byteOffset) < 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. + b. Let newByteLength be bufferByteLength - offset. + c. If newByteLength < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2); + }); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2, undefined); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws.js new file mode 100644 index 0000000000..134c621afc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws.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-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength - ToInteger(byteOffset) < 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. + b. Let newByteLength be bufferByteLength - offset. + c. If newByteLength < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2); + }); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2, undefined); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget-sab.js new file mode 100644 index 0000000000..c531b120af --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget-sab.js @@ -0,0 +1,30 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget.js new file mode 100644 index 0000000000..3f4ead077e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget.js @@ -0,0 +1,28 @@ +// 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: > + Throws a TypeError if NewTarget is undefined. +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(TA.BYTES_PER_ELEMENT); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced-sab.js new file mode 100644 index 0000000000..9d4c5fc17f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Reuse buffer argument instead of making a new clone +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 15. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer = new SharedArrayBuffer(bpe); + + var ta1 = new TA(buffer); + var ta2 = new TA(buffer); + + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta1.buffer, ta2.buffer); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced.js new file mode 100644 index 0000000000..45428dfbe4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced.js @@ -0,0 +1,34 @@ +// 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: > + Reuse buffer argument instead of making a new clone +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 15. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer = new ArrayBuffer(bpe); + + var ta1 = new TA(buffer); + var ta2 = new TA(buffer); + + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta1.buffer, ta2.buffer); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws-sab.js new file mode 100644 index 0000000000..c427ae805b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws-sab.js @@ -0,0 +1,37 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Returns abrupt from ToLength(length) +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); +var len = { + valueOf() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, 0, len); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws.js new file mode 100644 index 0000000000..ce616b31b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws.js @@ -0,0 +1,35 @@ +// 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: > + Returns abrupt from ToLength(length) +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); +var len = { + valueOf() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, 0, len); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws-sab.js new file mode 100644 index 0000000000..c28a05dada --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws-sab.js @@ -0,0 +1,33 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a TypeError if length is a Symbol +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws.js new file mode 100644 index 0000000000..adcbfc36e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws.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-buffer-byteoffset-length +description: > + Throws a TypeError if length is a Symbol +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-to-number-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-to-number-detachbuffer.js new file mode 100644 index 0000000000..83ca72fc7c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-to-number-detachbuffer.js @@ -0,0 +1,23 @@ +// 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: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(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)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility-sab.js new file mode 100644 index 0000000000..8c464be41b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility-sab.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. 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: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..c85d2e32f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility.js @@ -0,0 +1,39 @@ +// 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js new file mode 100644 index 0000000000..e91da4c63c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + [...] + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, SharedArrayBuffer, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [new SharedArrayBuffer(8)], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..3aefc42967 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm.js @@ -0,0 +1,39 @@ +// 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: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + [...] + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [new ArrayBuffer(8)], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance-sab.js new file mode 100644 index 0000000000..bbf1124b01 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance-sab.js @@ -0,0 +1,37 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from undefined offset and length +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer1 = new SharedArrayBuffer(bpe * 4); + var ta1 = new TA(buffer1); + assert.sameValue(ta1.length, 4); + assert.sameValue(ta1.buffer, buffer1); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var buffer2 = new SharedArrayBuffer(0); + var ta2 = new TA(buffer2); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer2); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance.js new file mode 100644 index 0000000000..f307a9dd17 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance.js @@ -0,0 +1,35 @@ +// 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: > + Return new typedArray from undefined offset and length +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer1 = new ArrayBuffer(bpe * 4); + var ta1 = new TA(buffer1); + assert.sameValue(ta1.length, 4); + assert.sameValue(ta1.buffer, buffer1); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var buffer2 = new ArrayBuffer(0); + var ta2 = new TA(buffer2); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer2); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/shell.js new file mode 100644 index 0000000000..1c02f57631 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/shell.js @@ -0,0 +1,60 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength-sab.js new file mode 100644 index 0000000000..ee266307a8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength-sab.js @@ -0,0 +1,76 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + ToIndex(length) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 11. If length is either not present or undefined, then + ... + 12. Else, + a. Let newLength be ? ToIndex(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 1; + } +}; + +var obj2 = { + toString: function() { + return 1; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 1, "object's valueOf"], + [obj2, 1, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["1", 1, "string '1'"], + [false, 0, "false"], + [true, 1, "true"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [1.1, 1, "1.1"], + [1.9, 1, "1.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var len = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, 0, len); + assert.sameValue(typedArray.length, expected, name + " length"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength.js new file mode 100644 index 0000000000..3822a656f8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength.js @@ -0,0 +1,74 @@ +// 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: > + ToIndex(length) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 11. If length is either not present or undefined, then + ... + 12. Else, + a. Let newLength be ? ToIndex(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 1; + } +}; + +var obj2 = { + toString: function() { + return 1; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 1, "object's valueOf"], + [obj2, 1, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["1", 1, "string '1'"], + [false, 0, "false"], + [true, 1, "true"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [1.1, 1, "1.1"], + [1.9, 1, "1.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var len = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, 0, len); + assert.sameValue(typedArray.length, expected, name + " length"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset-sab.js new file mode 100644 index 0000000000..b0ef7909c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset-sab.js @@ -0,0 +1,90 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + ToIndex(byteOffset) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToIndex(byteOffset). + 8. If offset modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 8; + } +}; + +var obj2 = { + toString: function() { + return 8; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 8, "object's valueOf"], + [obj2, 8, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["8", 8, "string '8'"], + [false, 0, "false"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [undefined, 0, "undefined"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [8.1, 8, "8.1"], + [8.9, 8, "8.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var offset = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, offset); + assert.sameValue(typedArray.byteOffset, expected, name + " byteOffset"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); + + // Testing `true`. See step 8 + if (TA.BYTES_PER_ELEMENT === 1) { + var typedArray = new TA(buffer, true); + assert.sameValue(typedArray.byteOffset, 1, "true => 1 byteOffset"); + assert.sameValue(typedArray.constructor, TA, "true => 1 constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + "true => 1 prototype" + ); + } else { + assert.throws(RangeError, function() { + new TA(buffer, true); + }, "1 modulo elementSize ≠ 0, throws a RangeError"); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset.js new file mode 100644 index 0000000000..5d11140a7c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset.js @@ -0,0 +1,88 @@ +// 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: > + ToIndex(byteOffset) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToIndex(byteOffset). + 8. If offset modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 8; + } +}; + +var obj2 = { + toString: function() { + return 8; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 8, "object's valueOf"], + [obj2, 8, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["8", 8, "string '8'"], + [false, 0, "false"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [undefined, 0, "undefined"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [8.1, 8, "8.1"], + [8.9, 8, "8.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var offset = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, offset); + assert.sameValue(typedArray.byteOffset, expected, name + " byteOffset"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); + + // Testing `true`. See step 8 + if (TA.BYTES_PER_ELEMENT === 1) { + var typedArray = new TA(buffer, true); + assert.sameValue(typedArray.byteOffset, 1, "true => 1 byteOffset"); + assert.sameValue(typedArray.constructor, TA, "true => 1 constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + "true => 1 prototype" + ); + } else { + assert.throws(RangeError, function() { + new TA(buffer, true); + }, "1 modulo elementSize ≠ 0, throws a RangeError"); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/typedarray-backed-by-sharedarraybuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/typedarray-backed-by-sharedarraybuffer.js new file mode 100644 index 0000000000..d72633b53c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/typedarray-backed-by-sharedarraybuffer.js @@ -0,0 +1,28 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-typedarray +description: > + Passing a SharedArrayBuffer-backed TypedArray to a TypedArray constructor + produces an ArrayBuffer-backed TypedArray. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(8); + +testWithBigIntTypedArrayConstructors(function(View1) { + var ta1 = new View1(sab); + testWithBigIntTypedArrayConstructors(function(View2) { + var ta2 = new View2(ta1); + assert.sameValue( + ta2.buffer.constructor, + ArrayBuffer, + "TypedArray of SharedArrayBuffer-backed TypedArray is ArrayBuffer-backed" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object-sab.js new file mode 100644 index 0000000000..d03bc4726b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object-sab.js @@ -0,0 +1,52 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Use prototype from new target if it's an Object +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, Reflect, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object.js new file mode 100644 index 0000000000..6baa8c836c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object.js @@ -0,0 +1,50 @@ +// 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: > + Use prototype from new target if it's an Object +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js new file mode 100644 index 0000000000..0a442701f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js @@ -0,0 +1,51 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..520a8d1f61 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js @@ -0,0 +1,49 @@ +// 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: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); + +reportCompare(0, 0); |