diff options
Diffstat (limited to 'test/built-ins/TypedArrays/internals')
85 files changed, 3463 insertions, 0 deletions
diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/conversion-operation.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/conversion-operation.js new file mode 100644 index 000000000..9fe931cfa --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/conversion-operation.js @@ -0,0 +1,54 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Verify conversion after defining value +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + + ... + 3. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + Object.defineProperty(sample, "0", {value: value}); + + assert.sameValue(sample[0], expected, value + " converts to " + expected); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/desc-value-throws.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/desc-value-throws.js new file mode 100644 index 000000000..d4dbc7267 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/desc-value-throws.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Return abrupt from the evaluation of ToNumber(desc.value) +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.throws(Test262Error, function() { + Object.defineProperty(sample, "0", {value: obj}); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..3fa462103 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer-realm.js @@ -0,0 +1,47 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws a TypeError if object has valid numeric index and a detached buffer + (honoring the Realm of the current execution context) +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var desc = { + value: 0, + configurable: false, + enumerable: true, + writable: true +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Reflect.defineProperty(sample, '0', desc); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer.js new file mode 100644 index 000000000..f20176156 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer.js @@ -0,0 +1,134 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws a TypeError if object has valid numeric index and a detached buffer +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var desc = { + value: 0, + configurable: false, + enumerable: true, + writable: true +}; + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Reflect.defineProperty(sample, "0", desc); + }, "Throws TypeError on valid numeric index if instance has a detached buffer"); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", desc), + false, + "Return false before Detached Buffer check when value is a negative number" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1.1", desc), + false, + "Return false before Detached Buffer check when value is not an integer" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-0", desc), + false, + "Return false before Detached Buffer check when value is -0" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "2", { + configurable: true, + enumerable: true, + writable: true, + value: obj + }), + false, + "Return false before Detached Buffer check when desc configurable is true" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "3", { + configurable: false, + enumerable: false, + writable: true, + value: obj + }), + false, + "Return false before Detached Buffer check when desc enumerable is false" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "4", { + writable: false, + configurable: false, + enumerable: true, + value: obj + }), + false, + "Return false before Detached Buffer check when desc writable is false" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "42", desc), + false, + "Return false before Detached Buffer check when key == [[ArrayLength]]" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "43", desc), + false, + "Return false before Detached Buffer check when key > [[ArrayLength]]" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "5", { + get: function() {} + }), + false, + "Return false before Detached Buffer check with accessor descriptor" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "6", { + configurable: false, + enumerable: true, + writable: true + }), + true, + "Return true before Detached Buffer check when desc value is not present" + ); + + assert.throws(Test262Error, function() { + Reflect.defineProperty(sample, "7", {value: obj}); + }, "Return Abrupt before Detached Buffer check from ToNumber(desc.value)"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js new file mode 100644 index 000000000..c558041e1 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js @@ -0,0 +1,47 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is >= [[ArrayLength]] +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ii. Let intIndex be numericIndex. + ... + v. Let length be the value of O's [[ArrayLength]] internal slot. + vi. If intIndex ≥ length, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Reflect.defineProperty(sample, "2", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex == length" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "3", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex > length" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js new file mode 100644 index 000000000..c9ff53898 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is < 0 +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ii. Let intIndex be numericIndex. + iv. If intIndex < 0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-1" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 000000000..73dcde780 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-minus-zero.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is "-0" +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If IsInteger(numericIndex) is false, return false. + ii. Let intIndex be numericIndex. + iii. If intIndex = -0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "-0", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "defineProperty returns false" + ); + assert.sameValue(sample[0], 0n, "does not change the value for [0]"); + assert.sameValue(sample["-0"], undefined, "does define a value for ['-0']"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..616875f7e --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,98 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Sets an ordinary property value if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +var fnset = function() {}; +var fnget = function() {}; + +var acDesc = { + get: fnget, + set: fnset, + enumerable: true, + configurable: false +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var dataDesc = { + value: 42n, + writable: true, + configurable: true + }; + + var sample1 = new TA(); + + assert.sameValue( + Reflect.defineProperty(sample1, key, dataDesc), + true, + "return true after defining data property [" + key + "]" + ); + + assert.sameValue(sample1[key], 42n, "value is set to [" + key + "]"); + verifyNotEnumerable(sample1, key); + verifyWritable(sample1, key); + verifyConfigurable(sample1, key); + + assert.sameValue(sample1[0], undefined, "no value is set on sample1[0]"); + assert.sameValue(sample1.length, 0, "length is still 0"); + + var sample2 = new TA(); + + assert.sameValue( + Reflect.defineProperty(sample2, key, acDesc), + true, + "return true after defining accessors property [" + key + "]" + ); + + var desc = Object.getOwnPropertyDescriptor(sample2, key); + verifyEnumerable(sample2, key); + assert.sameValue(desc.get, fnget, "accessor's get [" + key + "]"); + assert.sameValue(desc.set, fnset, "accessor's set [" + key + "]"); + verifyNotConfigurable(sample2, key); + + assert.sameValue(sample2[0], undefined,"no value is set on sample2[0]"); + assert.sameValue(sample2.length, 0, "length is still 0"); + + var sample3 = new TA(); + Object.preventExtensions(sample3); + + assert.sameValue( + Reflect.defineProperty(sample3, key, dataDesc), + false, + "return false defining property on a non-extensible sample" + ); + assert.sameValue(Object.getOwnPropertyDescriptor(sample3, key), undefined); + + var sample4 = new TA(); + Object.preventExtensions(sample4); + + assert.sameValue( + Reflect.defineProperty(sample4, key, acDesc), + false, + "return false defining property on a non-extensible sample" + ); + assert.sameValue(Object.getOwnPropertyDescriptor(sample4, key), undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..15bc69fb4 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-integer.js @@ -0,0 +1,124 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is not an integer +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If IsInteger(numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0.1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.1" + ); + assert.sameValue(sample[0], 0n, "'0.1' - does not change the value for [0]"); + assert.sameValue( + sample["0.1"], + undefined, + "'0.1' - does not define a value for ['0.1']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "0.000001", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.000001" + ); + assert.sameValue( + sample[0], 0n, + "'0.000001' - does not change the value for [0]" + ); + assert.sameValue( + sample["0.000001"], + undefined, + "'0.000001' - does not define a value for ['0.000001']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1.1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "1.1" + ); + assert.sameValue(sample[1], 0n, "'1.1' - does not change the value for [1]"); + assert.sameValue( + sample["1.1"], + undefined, + "'1.1' - does not define a value for ['1.1']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "Infinity", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "Infinity" + ); + assert.sameValue( + sample[0], 0n, + "'Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 0n, + "'Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["Infinity"], + undefined, + "'Infinity' - does not define a value for ['Infinity']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-Infinity", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-Infinity" + ); + assert.sameValue( + sample[0], 0n, + "'-Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 0n, + "'-Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["-Infinity"], + undefined, + "'-Infinity' - does not define a value for ['-Infinity']" + ); + +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..b68c6553c --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,52 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns an ordinary property value if key is not a CanonicalNumericIndex +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + true, + "return true after defining property" + ); + + assert.sameValue(sample.foo, 42); + verifyNotWritable(sample, "foo"); + verifyNotConfigurable(sample, "foo"); + verifyNotEnumerable(sample, "foo"); + + var fnset = function() {}; + var fnget = function() {}; + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: fnget, + set: fnset, + enumerable: false, + configurable: true + }), + true, + "return true after defining property" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, "bar"); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + verifyNotEnumerable(sample, "bar"); + verifyConfigurable(sample, "bar"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js new file mode 100644 index 000000000..4b4b60ffd --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js @@ -0,0 +1,58 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Descriptor is an + AccessorDescriptor +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + vii. If IsAccessorDescriptor(Desc) is true, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + get: function() { + return 42; + }, + enumerable: true + }), + false, + "get accessor" + ); + assert.sameValue(sample[0], 0n, "get accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + enumerable: true + }), + false, + "set accessor" + ); + assert.sameValue(sample[0], 0n, "set accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + get: function() { + return 42; + }, + enumerable: true + }), + false, + "get and set accessors" + ); + assert.sameValue(sample[0], 0n, "get and set accessors - side effect check"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js new file mode 100644 index 000000000..51fd77203 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Configurable]] is true +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + viii. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is + true, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: true, + enumerable: true, + writable: true + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], 0n, "side effect check"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js new file mode 100644 index 000000000..37315f7c9 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Enumerable]] is false +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ix. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is + false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: false, + enumerable: false, + writable: true + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], 0n, "side effect check"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js new file mode 100644 index 000000000..26f4363fe --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Writable]] is false +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, + return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: false, + enumerable: true, + writable: false + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], 0n, "side effect check"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex.js new file mode 100644 index 000000000..3e8241ca0 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns true after setting a valid numeric index key +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, + return false. + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 42n]); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 8n, + configurable: false, + enumerable: true, + writable: true + }), + true + ); + + assert.sameValue(sample[0], 8n, "property value was set"); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + + assert.sameValue(desc.value, 8n, "desc.value"); + assert.sameValue(desc.writable, true, "property is writable"); + + verifyEnumerable(sample, "0"); + verifyNotConfigurable(sample, "0"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-symbol.js new file mode 100644 index 000000000..08c9d1064 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-symbol.js @@ -0,0 +1,54 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Define an ordinary property value if key is a Symbol +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + var s1 = Symbol("foo"); + assert.sameValue( + Reflect.defineProperty(sample, s1, { + value: 42, + configurable: true + }), + true, + "return true after defining property" + ); + + assert.sameValue(sample[s1], 42); + verifyNotWritable(sample, s1); + verifyNotEnumerable(sample, s1); + verifyConfigurable(sample, s1); + + var s2 = Symbol("bar"); + var fnset = function() {}; + var fnget = function() {}; + assert.sameValue( + Reflect.defineProperty(sample, s2, { + get: fnget, + set: fnset, + enumerable: true + }), + true, + "return true after defining property" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, s2); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + assert.sameValue(desc.enumerable, true); + verifyNotConfigurable(sample, s2); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js new file mode 100644 index 000000000..d3b2694fb --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js @@ -0,0 +1,44 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Can't define a new non-numerical key on a non-extensible instance +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + Object.preventExtensions(sample); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + false, + "return false on a non-extensible object - data descriptor" + ); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "foo"), undefined); + + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: function() {}, + set: function() {}, + enumerable: false, + configurable: true + }), + false, + "return false on a non-extensible object - accessor descriptor" + ); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "bar"), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js new file mode 100644 index 000000000..81c7894db --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Redefine a non-numerical key on a non-extensible instance +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + sample.foo = true; + sample.bar = true; + + Object.preventExtensions(sample); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + true, + "data descriptor" + ); + + assert.sameValue(sample.foo, 42); + verifyEnumerable(sample, "foo"); + verifyWritable(sample, "foo"); + verifyConfigurable(sample, "foo"); + + var fnget = function() {}; + var fnset = function() {}; + + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: fnget, + set: fnset, + enumerable: false, + configurable: false + }), + true, + "accessor descriptor" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, "bar"); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + verifyNotEnumerable(sample, "bar"); + verifyNotConfigurable(sample, "bar"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/set-value.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/set-value.js new file mode 100644 index 000000000..1bcba5b21 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/set-value.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Set the value and return true +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + 16. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n, 0n]); + + assert.sameValue( + Reflect.defineProperty(sample, "0", {value: 1n}), + true, + "set value for sample[0] returns true" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1", {value: 2n}), + true, + "set value for sample[1] returns true" + ); + + assert.sameValue(sample[0], 1n, "sample[0]"); + assert.sameValue(sample[1], 2n, "sample[1]"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js new file mode 100644 index 000000000..df15ab556 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/this-is-not-extensible.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false for non-numeric index property value if `this` is not extensible +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + Object.preventExtensions(sample); + + assert.sameValue(Reflect.defineProperty(sample, "foo", {value:42}), false); + assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, "foo"), undefined); + + var s = Symbol("1"); + assert.sameValue(Reflect.defineProperty(sample, s, {value:42}), false); + assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, s), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js new file mode 100644 index 000000000..26eb3526b --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js @@ -0,0 +1,55 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Defining a typed array element to a value that, when converted to the typed + array element type, detaches the typed array's underlying buffer, should + throw a TypeError and not modify the typed array. +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, numericIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + 16. Return true. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = new TA([17]); + + var desc = + { + value: { + valueOf: function() { + $262.detachArrayBuffer(ta.buffer); + return 42; + } + } + }; + + assert.throws(TypeError, function() { + Reflect.defineProperty(ta, 0, desc); + }, + "detaching a ArrayBuffer during defining an element of a typed array " + + "viewing it should throw"); + + assert.throws(TypeError, function() { + ta[0]; + }); +}); + diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/conversion-operation-consistent-nan.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/conversion-operation-consistent-nan.js index 19323c66d..c990ecd97 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/conversion-operation-consistent-nan.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/conversion-operation-consistent-nan.js @@ -45,6 +45,7 @@ info: | each implementation distinguishable NaN value. ... includes: [nans.js, testTypedArray.js, compareArray.js] +features: [TypedArray] ---*/ function body(FloatArray) { diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/conversion-operation.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/conversion-operation.js index f78228c5b..a496517ea 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/conversion-operation.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/conversion-operation.js @@ -42,6 +42,7 @@ info: | e. Else, ... includes: [byteConversionValues.js, testTypedArray.js] +features: [TypedArray] ---*/ testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 000000000..21b3b11b1 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + sample.foo = "test262"; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.undef, undefined); + assert.sameValue(sample.foo, "test262"); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 000000000..fe0e8c412 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-symbol.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("1"); + + assert.sameValue(sample[s], undefined); + + sample[s] = "test262"; + assert.sameValue(sample[s], "test262"); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..af52e3392 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-realm.js @@ -0,0 +1,32 @@ +// 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-integer-indexed-exotic-objects-get-p-receiver +description: > + Throws a TypeError if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample[0]; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer.js new file mode 100644 index 000000000..0ac96a863 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer.js @@ -0,0 +1,47 @@ +// 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-integer-indexed-exotic-objects-get-p-receiver +description: > + Throws a TypeError if key has a numeric index and object has a detached buffer +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample[0]; + }, "valid numeric index"); + + assert.throws(TypeError, function() { + sample["1.1"]; + }, "detach buffer runs before checking for 1.1"); + + assert.throws(TypeError, function() { + sample["-0"]; + }, "detach buffer runs before checking for -0"); + + assert.throws(TypeError, function() { + sample["-1"]; + }, "detach buffer runs before checking for -1"); + + assert.throws(TypeError, function() { + sample["1"]; + }, "detach buffer runs before checking for key == length"); + + assert.throws(TypeError, function() { + sample["2"]; + }, "detach buffer runs before checking for key > length"); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value-sab.js b/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value-sab.js new file mode 100644 index 000000000..e8e27c666 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value-sab.js @@ -0,0 +1,28 @@ +// 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-integer-indexed-exotic-objects-get-p-receiver +description: > + Return value from valid numeric index, with SharedArrayBuffer +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray, SharedArrayBuffer] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + var sample = new TA(sab); + sample.set([42n, 1n]); + + assert.sameValue(sample["0"], 42n); + assert.sameValue(sample["1"], 1n); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value.js b/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value.js new file mode 100644 index 000000000..6cc015407 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Return value from valid numeric index +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 1n]); + + assert.sameValue(sample["0"], 42n); + assert.sameValue(sample["1"], 1n); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/infinity-detached-buffer.js b/test/built-ins/TypedArrays/internals/Get/BigInt/infinity-detached-buffer.js new file mode 100644 index 000000000..1e04f9544 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/infinity-detached-buffer.js @@ -0,0 +1,40 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integerindexedelementget +description: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +info: | + 9.4.5.4 [[Get]] ( P, Receiver ) + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + ... + 3. Let buffer be O.[[ViewedArrayBuffer]]. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample.Infinity; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..5a599409a --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,61 @@ +// 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-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrginaryGet if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(); + + assert.sameValue( + sample[key], undefined, + "return undefined for inexistent properties [" + key + "]" + ); + + TypedArray.prototype[key] = "test262"; + + assert.sameValue( + sample[key], + "test262", + "return value from inherited key [" + key + "]" + ); + + sample[key] = "bar"; + assert.sameValue( + sample[key], "bar", + "return value from own key [" + key + "]" + ); + + Object.defineProperty(sample, key, { + get: function() { return "baz"; } + }); + + assert.sameValue( + sample[key], "baz", + "return value from get accessor [" + key + "]" + ); + + delete TypedArray.prototype[key]; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..862178d03 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-integer.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index is not an integer. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +Object.defineProperty(proto, "1.1", { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(sample["1.1"], undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-minus-zero.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-minus-zero.js new file mode 100644 index 000000000..792e32064 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-minus-zero.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index is -0. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 6. If index = -0, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +Object.defineProperty(proto, "-0", { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(sample["-0"], undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js new file mode 100644 index 000000000..a532b6cea --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index-get-throws.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Returns abrupt from OrginaryGet when key is not a numeric index +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). + + 9.1.8.1 OrdinaryGet (O, P, Receiver) + + ... + 8. Return ? Call(getter, Receiver). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..3167ddf0c --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrginaryGet if key is not a CanonicalNumericIndex +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +TypedArray.prototype.baz = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + sample.foo, undefined, + "return undefined for inexistent properties" + ); + + sample.foo = "bar"; + assert.sameValue(sample.foo, "bar", "return value"); + + Object.defineProperty(sample, "bar", { + get: function() { return "baz"; } + }); + assert.sameValue(sample.bar, "baz", "return value from get accessor"); + + assert.sameValue(sample.baz, "test262", "return value from inherited key"); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-out-of-bounds.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-out-of-bounds.js new file mode 100644 index 000000000..583b7c549 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-out-of-bounds.js @@ -0,0 +1,43 @@ +// 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-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index < 0 or index ≥ [[ArrayLength]]. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 7. Let length be the value of O's [[ArrayLength]] internal slot. + 8. If index < 0 or index ≥ length, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "-1", throwDesc); +Object.defineProperty(proto, "2", throwDesc); +Object.defineProperty(proto, "3", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(sample["-1"], undefined); + assert.sameValue(sample["2"], undefined); + assert.sameValue(sample["3"], undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-symbol.js new file mode 100644 index 000000000..11e80f8d8 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-symbol.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrginaryGet if key is a Symbol +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var parentKey = Symbol("2"); +TypedArray.prototype[parentKey] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + var s1 = Symbol("1"); + + assert.sameValue( + sample[s1], undefined, + "return undefined if not property is present" + ); + + sample[s1] = "foo"; + assert.sameValue(sample[s1], "foo", "return value"); + + Object.defineProperty(sample, s1, { + get: function() { return "bar"; } + }); + assert.sameValue(sample[s1], "bar", "return value from get accessor"); + + assert.sameValue(sample[parentKey], "test262", "value from parent key"); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js new file mode 100644 index 000000000..6f7ad44ab --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.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-integer-indexed-exotic-objects-getownproperty-p +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "undef"), + undefined, + "undefined property" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, "foo", { value: "bar" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "foo").value, + "bar", + "return value from a String key" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 000000000..e316218f5 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.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-integer-indexed-exotic-objects-getownproperty-p +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("foo"); + Object.defineProperty(sample, s, { value: "baz" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, s).value, + "baz", + "return value from a Symbol key" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..91c06732b --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-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-integer-indexed-exotic-objects-getownproperty-p +description: > + Throws a TypeError if this has a detached buffer (honoring the Realm of the + current execution context) +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(sample, 0); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer.js new file mode 100644 index 000000000..5f14f0317 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer.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-integer-indexed-exotic-objects-getownproperty-p +description: Throws a TypeError if this has a detached buffer +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(sample, 0); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js new file mode 100644 index 000000000..9523e3a5f --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js @@ -0,0 +1,42 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Test for-in enumeration with detached buffer. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + ... + 3. Let buffer be O.[[ViewedArrayBuffer]]. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + + 13.7.5.15 EnumerateObjectProperties (O) + ... + EnumerateObjectProperties must obtain the own property keys of the + target object by calling its [[OwnPropertyKeys]] internal method. + Property attributes of the target object must be obtained by + calling its [[GetOwnProperty]] internal method. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + for (var key in sample) { + throw new Test262Error(); + } + }); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/index-prop-desc.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/index-prop-desc.js new file mode 100644 index 000000000..ad44eb8d3 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/index-prop-desc.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-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns a descriptor object from an index property +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. Return a PropertyDescriptor{[[Value]]: value, [[Writable]]: true, + [[Enumerable]]: true, [[Configurable]]: false}. + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + var desc0 = Object.getOwnPropertyDescriptor(sample, 0); + assert.sameValue(desc0.value, 42n, "value", "desc0.value === 42"); + assert.sameValue(desc0.writable, true, "index descriptor is writable [0]"); + verifyEnumerable(sample, "0", "index descriptor is enumerable [0]"); + verifyNotConfigurable(sample, "0", "index descriptor is not configurable [0]"); + + var desc1 = Object.getOwnPropertyDescriptor(sample, 1); + assert.sameValue(desc1.value, 43n, "value", "desc1.value === 43"); + assert.sameValue(desc1.writable, true, "index descriptor is writable [1]"); + verifyEnumerable(sample, "1", "index descriptor is enumerable [1]"); + verifyNotConfigurable(sample, "1", "index descriptor is not configurable [1]"); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 000000000..598deda2c --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-minus-zero.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-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is -0. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + + ... + 2. If argument is "-0", return -0. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 6. If index = -0, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + // -0 as a number value is converted to "0" before calling [[GetOwnProperty]] + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-0"), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..02f46bd6d --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,48 @@ +// 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-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if numeric key is not a + CanonicalNumericIndex +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, key), + undefined, + "undefined property [" + key + "]" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, key, {value: "bar"}); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, key).value, + "bar", + "return value from a ordinary property key [" + key + "]" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..e52e033aa --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-integer.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-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is not an integer. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1.1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "0.1"), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..e65c23ad9 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.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-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if key is not a CanonicalNumericIndex +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "undef"), + undefined, + "undefined property" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, "foo", { value: "bar" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "foo").value, + "bar", + "return value from a String key" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js new file mode 100644 index 000000000..71e5d5ef7 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.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-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is not a valid index number. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 7. Let length be the value of O's [[ArrayLength]] internal slot. + 8. If index < 0 or index ≥ length, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-42"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "42"), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-symbol.js new file mode 100644 index 000000000..c5509a0d9 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-symbol.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-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if key is a Symbol +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + var s = Symbol("foo"); + Object.defineProperty(sample, s, { value: "baz" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, s).value, + "baz", + "return value from a Symbol key" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js new file mode 100644 index 000000000..5c788c69a --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js @@ -0,0 +1,63 @@ +// 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-integer-indexed-exotic-objects-hasproperty-p +description: Return abrupt from OrdinaryHasProperty parent's [[HasProperty]] +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + + 9.1.7.1 OrdinaryHasProperty (O, P) + + ... + 2. Let hasOwn be ? O.[[GetOwnProperty]](P). + 3. If hasOwn is not undefined, return true. + 4. Let parent be ? O.[[GetPrototypeOf]](). + 5. If parent is not null, then + a. Return ? parent.[[HasProperty]](P). + 6. Return false. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, Proxy, TypedArray] +---*/ + +var handler = { + has: function() { + throw new Test262Error(); + } +}; + +var proxy = new Proxy(TypedArray.prototype, handler); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.setPrototypeOf(sample, proxy); + + assert.sameValue( + Reflect.has(sample, 0), true, + "OrdinaryHasProperty does not affect numericIndex properties [0]" + ); + assert.sameValue( + Reflect.has(sample, 1), false, + "OrdinaryHasProperty does not affect numericIndex properties [1]" + ); + + assert.throws(Test262Error, function() { + Reflect.has(sample, "foo"); + }, "Return abrupt from parent's [[HasProperty]] 'foo'"); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue( + Reflect.has(sample, "foo"), + true, + "trap is not triggered if [[GetOwnProperty]] returns a defined value" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js new file mode 100644 index 000000000..aeda046b0 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.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-integer-indexed-exotic-objects-getproperty-p +description: > + Does not throw on an instance with a detached buffer if key is not a + CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + Object.defineProperty(sample, "bar", { value: 42 }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, "foo"), false); + assert.sameValue(Reflect.has(sample, "bar"), true); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 000000000..44475d9aa --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("foo"); +var s2 = Symbol("bar"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + Object.defineProperty(sample, s1, { value: "baz" }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, s1), true); + assert.sameValue(Reflect.has(sample, s2), false); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..3870e5282 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-realm.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Throws a TypeError if this has a detached buffer (honoring the Realm of the + current execution context) +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Reflect.has(sample, '0'); + }, '0'); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer.js new file mode 100644 index 000000000..d78265e35 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer.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-integer-indexed-exotic-objects-hasproperty-p +description: Throws a TypeError if this has a detached buffer +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Reflect.has(sample, "0"); + }, "0"); + + assert.throws(TypeError, function() { + Reflect.has(sample, "-0"); + }, "-0"); + + assert.throws(TypeError, function() { + Reflect.has(sample, "1.1"); + }, "1.1"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/indexed-value.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/indexed-value.js new file mode 100644 index 000000000..9133ae261 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/indexed-value.js @@ -0,0 +1,32 @@ +// 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-integer-indexed-exotic-objects-hasproperty-p +description: > + Return true for indexed properties +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + iii. If IsInteger(numericIndex) is false, return false. + iv. If numericIndex = -0, return false. + v. If numericIndex < 0, return false. + vi. If numericIndex ≥ the value of O's [[ArrayLength]] internal slot, + return false. + vii. Return true. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(Reflect.has(sample, 0), true); + assert.sameValue(Reflect.has(sample, 1), true); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/infinity-with-detached-buffer.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/infinity-with-detached-buffer.js new file mode 100644 index 000000000..2e4cdb7ae --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/infinity-with-detached-buffer.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +info: | + 9.4.5.2 [[HasProperty]]( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + +flags: [noStrict] +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + with (sample) Infinity; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/inherited-property.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/inherited-property.js new file mode 100644 index 000000000..6407c2644 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/inherited-property.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Find inherited properties if property is not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +TypedArray.prototype.foo = 42; +TypedArray.prototype[42] = true; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + TA.prototype.bar = 42; + + assert.sameValue(Reflect.has(sample, "subarray"), true, "subarray"); + assert.sameValue(Reflect.has(sample, "foo"), true, "foo"); + assert.sameValue(Reflect.has(sample, "bar"), true, "bar"); + assert.sameValue(Reflect.has(sample, "baz"), false, "baz"); + + assert.sameValue(Reflect.has(sample, "42"), false, "42"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-greater-than-last-index.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-greater-than-last-index.js new file mode 100644 index 000000000..c1d721348 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-greater-than-last-index.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-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is >= this's [[ArrayLength]] +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + vi. If numericIndex ≥ the value of O's [[ArrayLength]] internal slot, + return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[1] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "1"), false, "1"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-lower-than-zero.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-lower-than-zero.js new file mode 100644 index 000000000..0048a4f97 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-lower-than-zero.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-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is < 0 +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + v. If numericIndex < 0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[-1] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-1"), false, "-1"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 000000000..0d6a1515f --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-minus-zero.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-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is "-0" +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iv. If numericIndex = -0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["-0"] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-0"), false, "-0"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..a92f3346e --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,53 @@ +// 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-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from numeric keys that are not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(1); + + assert.sameValue( + Reflect.has(sample, key), false, + "returns false without key [" + key + "]" + ); + + TypedArray.prototype[key] = 42; + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with inherited key [" + key + "]" + ); + + delete TypedArray.prototype[key]; + + Object.defineProperty(sample, key, {value: 42n}); + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with own key [" + key + "]" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..303b60278 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-integer.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-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is not an integer +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If IsInteger(numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["1.1"] = "test262"; +TypedArray.prototype["0.000001"] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "1.1"), false, "1.1"); + assert.sameValue(Reflect.has(sample, "0.000001"), false, "0.000001"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..d960abfdd --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-numeric-index.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from properties that are not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "foo"), false); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue(Reflect.has(sample, "foo"), true); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-symbol.js new file mode 100644 index 000000000..0f6d74487 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-symbol.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from Symbol properties +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("foo"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, s), false); + + Object.defineProperty(sample, s, { value: 42 }); + + assert.sameValue(Reflect.has(sample, s), true); +}); diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js new file mode 100644 index 000000000..6f64fa646 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js @@ -0,0 +1,48 @@ +// 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-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return integer index + non numeric string keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA([42n, 42n, 42n]); + sample1[s1] = 42; + sample1[s2] = 42; + sample1.test262 = 42; + sample1.ecma262 = 42; + var result1 = Reflect.ownKeys(sample1); + assert( + compareArray(result1, ["0", "1", "2", "test262", "ecma262", s1, s2]), + "result1" + ); + + var sample2 = new TA(4).subarray(2); + sample2[s1] = 42; + sample2[s2] = 42; + sample2.test262 = 42; + sample2.ecma262 = 42; + var result2 = Reflect.ownKeys(sample2); + assert( + compareArray(result2, ["0", "1", "test262", "ecma262", s1, s2]), + "result2" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js new file mode 100644 index 000000000..8de17148b --- /dev/null +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js @@ -0,0 +1,41 @@ +// 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-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return integer index + non numeric string keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA([42n, 42n, 42n]); + sample1.test262 = 42; + sample1.ecma262 = 42; + var result1 = Reflect.ownKeys(sample1); + assert( + compareArray(result1, ["0", "1", "2", "test262", "ecma262"]), + "result1" + ); + + var sample2 = new TA(4).subarray(2); + sample2.test262 = 42; + sample2.ecma262 = 42; + var result2 = Reflect.ownKeys(sample2); + assert( + compareArray(result2, ["0", "1", "test262", "ecma262"]), + "result2" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes.js new file mode 100644 index 000000000..88f6f3b8f --- /dev/null +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes.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-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA([42n, 42n, 42n]); + var result1 = Reflect.ownKeys(sample1); + assert(compareArray(result1, ["0", "1", "2"]), "result1"); + + var sample2 = new TA(4); + var result2 = Reflect.ownKeys(sample2); + assert(compareArray(result2, ["0", "1", "2", "3"]), "result2"); + + var sample3 = new TA(4).subarray(2); + var result3 = Reflect.ownKeys(sample3); + assert(compareArray(result3, ["0", "1"]), "result3"); + + var sample4 = new TA(); + var result4 = Reflect.ownKeys(sample4); + assert(compareArray(result4, []), "result4"); +}); diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js new file mode 100644 index 000000000..d50d2d20f --- /dev/null +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.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-integer-indexed-exotic-objects-ownpropertykeys +description: > + List not-enumerable own keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + Object.defineProperty(sample, s, { + value: 42, + enumerable: false + }); + Object.defineProperty(sample, "test262", { + value: 42, + enumerable: false + }); + var result = Reflect.ownKeys(sample); + assert(compareArray(result, ["test262", s])); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/conversion-operation.js b/test/built-ins/TypedArrays/internals/Set/BigInt/conversion-operation.js new file mode 100644 index 000000000..8f30a59a4 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/conversion-operation.js @@ -0,0 +1,51 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Verify conversion after setting value +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + sample[0] = value; + + assert.sameValue(sample[0], expected, value + " converts to " + expected); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 000000000..87f24f8f6 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,26 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.set(sample, "foo", "test262"), true); + assert.sameValue(sample.foo, "test262"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 000000000..f22e808ba --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-symbol.js @@ -0,0 +1,26 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol, Reflect, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.set(sample, s, "test262"), true); + assert.sameValue(sample[s], "test262"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..f7e71ff0e --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-realm.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Throws a TypeError if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample[0] = 0; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer.js new file mode 100644 index 000000000..614f7779c --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer.js @@ -0,0 +1,65 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Throws a TypeError if key has a numeric index and object has a detached buffer +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample[0] = 1n; + }, "valid numeric index"); + + assert.throws(TypeError, function() { + sample["1.1"] = 1n; + }, "detach buffer runs before checking for 1.1"); + + assert.throws(TypeError, function() { + sample["-0"] = 1n; + }, "detach buffer runs before checking for -0"); + + assert.throws(TypeError, function() { + sample["-1"] = 1n; + }, "detach buffer runs before checking for -1"); + + assert.throws(TypeError, function() { + sample["1"] = 1n; + }, "detach buffer runs before checking for key == length"); + + assert.throws(TypeError, function() { + sample["2"] = 1n; + }, "detach buffer runs before checking for key > length"); + + var obj = { + valueOf: function() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample["0"] = obj; + }, "ToNumber(value) is called before detached buffer check"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/indexed-value.js b/test/built-ins/TypedArrays/internals/Set/BigInt/indexed-value.js new file mode 100644 index 000000000..71c914f87 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/indexed-value.js @@ -0,0 +1,43 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true after setting value +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + 16. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + set: function() { + throw new Test262Error("OrdinarySet was called! Ref: 9.1.9.1 3.b.i"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(Reflect.set(sample, "0", 1n), true, "sample[0]"); + assert.sameValue(sample[0], 1n, "sample[0] value is set"); + + assert.sameValue(Reflect.set(sample, "1", 42n), true, "sample[1]"); + assert.sameValue(sample[1], 42n, "sample[1] value is set"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-minus-zero.js new file mode 100644 index 000000000..e937c4d28 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-minus-zero.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false if index is -0 +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 7. If index = -0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue(Reflect.set(sample, "-0", 1), false, "-0"); + assert.sameValue(sample.hasOwnProperty("-0"), false, "has no property [-0]"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..9a1296fa5 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,58 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrginarySet if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, key, "ecma262"), + true, + "Return true setting a new property [" + key + "]" + ); + assert.sameValue(sample[key], "ecma262"); + + assert.sameValue( + Reflect.set(sample, key, "es3000"), + true, + "Return true setting a value to a writable property [" + key + "]" + ); + assert.sameValue(sample[key], "es3000"); + + Object.defineProperty(sample, key, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, key, 42), + false, + "Return false setting a value to a non-writable property [" + key + "]" + ); + assert.sameValue( + sample[key], undefined, "non-writable [" + key + "] is preserved" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..1d8e72b14 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-integer.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false if index is not integer +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 6. If IsInteger(index) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue(Reflect.set(sample, "1.1", 1), false, "1.1"); + assert.sameValue(Reflect.set(sample, "0.0001", 1), false, "0.0001"); + + assert.sameValue(sample.hasOwnProperty("1.1"), false, "has no property [1.1]"); + assert.sameValue( + sample.hasOwnProperty("0.0001"), + false, + "has no property [0.0001]" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js new file mode 100644 index 000000000..1e55325f6 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index-set-throws.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from OrginarySet when key is not a numeric index +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). + + 9.1.9.1 OrdinarySet (O, P, V, Receiver) + + ... + 8. Perform ? Call(setter, Receiver, « V »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + set: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262 = 1; + }); + + assert.sameValue(sample.test262, undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..602820de9 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,47 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrginarySet if key is not a CanonicalNumericIndex +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, "test262", "ecma262"), + true, + "Return true setting a new property" + ); + assert.sameValue(sample.test262, "ecma262"); + + assert.sameValue( + Reflect.set(sample, "test262", "es3000"), + true, + "Return true setting a value to a writable property" + ); + assert.sameValue(sample.test262, "es3000"); + + Object.defineProperty(sample, "foo", { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, "foo", 42), + false, + "Return false setting a value to a non-writable property" + ); + assert.sameValue(sample.foo, undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-out-of-bounds.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-out-of-bounds.js new file mode 100644 index 000000000..a9a4d8b0a --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-out-of-bounds.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false if index is out of bounds +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 8. Let length be the value of O's [[ArrayLength]] internal slot. + 9. If index < 0 or index ≥ length, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue(Reflect.set(sample, "-1", 1), false, "-1"); + assert.sameValue(Reflect.set(sample, "1", 1), false, "1"); + assert.sameValue(Reflect.set(sample, "2", 1), false, "2"); + + assert.sameValue(sample.hasOwnProperty("-1"), false, "has no property [-1]"); + assert.sameValue(sample.hasOwnProperty("1"), false, "has no property [1]"); + assert.sameValue(sample.hasOwnProperty("2"), false, "has no property [2]"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-symbol.js new file mode 100644 index 000000000..e63baedb0 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-symbol.js @@ -0,0 +1,48 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrginarySet if key is a Symbol +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, s1, "ecma262"), + true, + "Return true setting a new property" + ); + assert.sameValue(sample[s1], "ecma262"); + + assert.sameValue( + Reflect.set(sample, s1, "es3000"), + true, + "Return true setting a value to a writable property" + ); + assert.sameValue(sample[s1], "es3000"); + + Object.defineProperty(sample, s2, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, s2, 42), + false, + "Return false setting a value to a non-writable property" + ); + assert.sameValue(sample[s2], undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-detached-buffer.js b/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-detached-buffer.js new file mode 100644 index 000000000..2111ef645 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-detached-buffer.js @@ -0,0 +1,46 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Setting a typed array element to a value that, when converted to the typed + array element type, detaches the typed array's underlying buffer, should + throw a TypeError and not modify the typed array. +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + 16. Return true. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = new TA([17]); + + assert.throws(TypeError, function() { + Reflect.set(ta, 0, { + valueOf: function() { + $262.detachArrayBuffer(ta.buffer); + return 42; + } + }); + }, + "detaching a ArrayBuffer during setting an element of a typed array " + + "viewing it should throw"); + + assert.throws(TypeError, function() { + ta[0]; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-throws.js b/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-throws.js new file mode 100644 index 000000000..a91f3fbe6 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-throws.js @@ -0,0 +1,58 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from ToNumber(value) +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + var obj = { + valueOf: function() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample["0"] = obj; + }, "ToNumber check with a valid index"); + + assert.throws(Test262Error, function() { + sample["1.1"] = obj; + }, "ToNumber runs before ToInteger(index)"); + + assert.throws(Test262Error, function() { + sample["-0"] = obj; + }, "ToNumber runs before -0 check"); + + assert.throws(Test262Error, function() { + sample["-1"] = obj; + }, "ToNumber runs before < 0 check"); + + assert.throws(Test262Error, function() { + sample["1"] = obj; + }, "ToNumber runs before index == length check"); + + assert.throws(Test262Error, function() { + sample["2"] = obj; + }, "ToNumber runs before index > length check"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/conversion-operation-consistent-nan.js b/test/built-ins/TypedArrays/internals/Set/conversion-operation-consistent-nan.js index 71703cd5f..39a672a64 100644 --- a/test/built-ins/TypedArrays/internals/Set/conversion-operation-consistent-nan.js +++ b/test/built-ins/TypedArrays/internals/Set/conversion-operation-consistent-nan.js @@ -42,6 +42,7 @@ info: | each implementation distinguishable NaN value. ... includes: [nans.js, testTypedArray.js, compareArray.js] +features: [TypedArray] ---*/ function body(FloatArray) { diff --git a/test/built-ins/TypedArrays/internals/Set/conversion-operation.js b/test/built-ins/TypedArrays/internals/Set/conversion-operation.js index 7ef883bcd..e7eedd407 100644 --- a/test/built-ins/TypedArrays/internals/Set/conversion-operation.js +++ b/test/built-ins/TypedArrays/internals/Set/conversion-operation.js @@ -39,6 +39,7 @@ info: | e. Else, ... includes: [byteConversionValues.js, testTypedArray.js] +features: [TypedArray] ---*/ testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { |