diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg')
14 files changed, 529 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..51cf40ab6f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/custom-proto-access-throws.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-length +description: > + Return abrupt completion getting newTarget's prototype +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 ]) + + 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 newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [1], newTarget); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/init-zeros.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/init-zeros.js new file mode 100644 index 0000000000..b857489ae1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/init-zeros.js @@ -0,0 +1,57 @@ +// 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: All bytes are initialized to zero +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 ]) + + 5. If length was not passed, then + ... + 6. Else, + a. Perform ? AllocateTypedArrayBuffer(obj, length). + + 22.2.4.2.2 Runtime Semantics: AllocateTypedArrayBuffer + + 7. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength). + + 24.1.1.1 AllocateArrayBuffer + + 3. Let block be ? CreateByteDataBlock(byteLength). + + 6.2.6.1 CreateByteDataBlock + + 1. Assert: size≥0. + 2. Let db be a new Data Block value consisting of size bytes. If it is + impossible to create such a Data Block, throw a RangeError exception. + 3. Set all of the bytes of db to 0. + 4. Return db. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var subject = new TA(9); + + assert.sameValue(subject[0], 0n, 'index 0'); + assert.sameValue(subject[1], 0n, 'index 1'); + assert.sameValue(subject[2], 0n, 'index 2'); + assert.sameValue(subject[3], 0n, 'index 3'); + assert.sameValue(subject[4], 0n, 'index 4'); + assert.sameValue(subject[5], 0n, 'index 5'); + assert.sameValue(subject[6], 0n, 'index 6'); + assert.sameValue(subject[7], 0n, 'index 7'); + assert.sameValue(subject[8], 0n, 'index 8'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-infinity-throws-rangeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-infinity-throws-rangeerror.js new file mode 100644 index 0000000000..e1a9d812ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-infinity-throws-rangeerror.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-length +description: > + Throws a RangeError if length is a Infinity value +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. + + ... + 4. Let numberLength be ? ToNumber(length). + 5. Let elementLength be ToLength(numberLength). + 6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-negative-integer-throws-rangeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-negative-integer-throws-rangeerror.js new file mode 100644 index 0000000000..57f8f11914 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-negative-integer-throws-rangeerror.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-length +description: > + Throws a RangeError if ToInteger(length) is a negative value +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. + + ... + 3. Let elementLength be ? ToIndex(length). + ... + + 7.1.17 ToIndex ( value ) + + 1. If value is undefined, then + ... + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(-1); + }); + + assert.throws(RangeError, function() { + new TA(-Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-symbol-throws.js new file mode 100644 index 0000000000..130470811b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-symbol-throws.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-length +description: > + If length is a Symbol, throw a TypeError exception. +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. + + ... + 4. Let numberLength be ? ToNumber(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol('1'); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..6378d55d33 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/new-instance-extensibility.js @@ -0,0 +1,40 @@ +// 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..6351fd73f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/proto-from-ctor-realm.js @@ -0,0 +1,38 @@ +// 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: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%", elementLength). + + 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, [0], 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/length-arg/returns-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/returns-object.js new file mode 100644 index 0000000000..b8b24235fd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/returns-object.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-length +description: > + Return a TypedArray object +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 ]) + + ... + 7. Return obj +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(4); + var length = typedArray.length; + + assert.sameValue(length, 4, "length"); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// 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/length-arg/toindex-length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/toindex-length.js new file mode 100644 index 0000000000..64ef8ac3c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/toindex-length.js @@ -0,0 +1,55 @@ +// 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: > + ToIndex(length) operations +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. + + ... + 3. Let elementLength be ? ToIndex(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var items = [ + [-0, 0, "-0"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["1", 1, "string '1'"], + [true, 1, "true"], + [false, 0, "false"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [undefined, 0, "undefined"], + [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(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/length-arg/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/undefined-newtarget-throws.js new file mode 100644 index 0000000000..65bc5efd6f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/undefined-newtarget-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-length +description: > + Throws a TypeError if NewTarget is undefined. +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. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA(0); + }); + + assert.throws(TypeError, function() { + TA(Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-custom-proto-if-object.js new file mode 100644 index 0000000000..87cef3c04c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-custom-proto-if-object.js @@ -0,0 +1,46 @@ +// 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: > + Use prototype from new target if it's an Object +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 ]) + + 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] +---*/ + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [1], 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/length-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..b1fd97885e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-default-proto-if-custom-proto-is-not-object.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-length +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +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 ]) + + 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] +---*/ + +function newTarget() {} +newTarget.prototype = null; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [1], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); + +reportCompare(0, 0); |