diff options
Diffstat (limited to '')
44 files changed, 2813 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js new file mode 100644 index 0000000000..fac2234818 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js @@ -0,0 +1,102 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for input array of BigInts +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + 16. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, "Unordered"). + 17. Return true. + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigInt64 + Conversion Operation: ToBigInt64 + + ToBigInt64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. If int64bit ≥ 2^63, return int64bit - 2^64; otherwise return int64bit. + +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +// 2n ** 64n + 2n +// 2n ** 63n + 2n +// -(2n ** 63n) - 2n +// -(2n ** 64n) - 2n +// 2n - 2n ** 63n +// 2n ** 63n - 2 +var vals = [ + 18446744073709551618n, + 9223372036854775810n, + 2n, + 0n, + -2n, + -9223372036854775810n, + -18446744073709551618n +]; + +var typedArray = new BigInt64Array(1); +typedArray[0] = vals[0]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[1]; +assert.sameValue(typedArray[0], -9223372036854775806n, 'The value of typedArray[0] is -9223372036854775806n'); +typedArray[0] = vals[2]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[3]; +assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); +typedArray[0] = vals[4]; +assert.sameValue(typedArray[0], -2n, 'The value of typedArray[0] is -2n'); +typedArray[0] = vals[5]; +assert.sameValue(typedArray[0], 9223372036854775806n, 'The value of typedArray[0] is 9223372036854775806n'); +typedArray[0] = vals[6]; +assert.sameValue(typedArray[0], -2n, 'The value of typedArray[0] is -2n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js new file mode 100644 index 0000000000..d1b8b9067e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js @@ -0,0 +1,104 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for input array of BigInts +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + 16. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, "Unordered"). + 17. Return true. + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigUint64 + Conversion Operation: ToBigUint64 + + ToBigUint64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. Return int64bit. + +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +// 2n ** 64n + 2n +// 2n ** 63n + 2n +// -(2n ** 63n) - 2n +// -(2n ** 64n) - 2n +// 2n ** 63n + 2n +// 2n ** 64n - 2n +// 2n ** 63n - 2n +// 2n ** 64n - 2n +var vals = [ + 18446744073709551618n, + 9223372036854775810n, + 2n, + 0n, + -2n, + -9223372036854775810n, + -18446744073709551618n +]; + +var typedArray = new BigUint64Array(1); +typedArray[0] = vals[0]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[1]; +assert.sameValue(typedArray[0], 9223372036854775810n, 'The value of typedArray[0] is 9223372036854775810n'); +typedArray[0] = vals[2]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[3]; +assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); +typedArray[0] = vals[4]; +assert.sameValue(typedArray[0], 18446744073709551614n, 'The value of typedArray[0] is 18446744073709551614n'); +typedArray[0] = vals[5]; +assert.sameValue(typedArray[0], 9223372036854775806n, 'The value of typedArray[0] is 9223372036854775806n'); +typedArray[0] = vals[6]; +assert.sameValue(typedArray[0], 18446744073709551614n, 'The value of typedArray[0] is 18446744073709551614n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js new file mode 100644 index 0000000000..e41c023d36 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for assigning Booleans to BigInt TypedArray +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Boolean + Result: Return 1n if prim is true and 0n if prim is false. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(2); + typedArray[0] = false; + typedArray[1] = true; + assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); + assert.sameValue(typedArray[1], 1n, 'The value of typedArray[1] is 1n'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..27d868a915 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.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-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: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, 'foo', 'test262'), + true, + 'Reflect.set(sample, "foo", "test262") must return true' + ); + + assert.sameValue(sample.foo, 'test262', 'The value of sample.foo is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..5a34f8f6d9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-symbol.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-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: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol, Reflect, TypedArray] +---*/ +var s = Symbol('1'); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, s, 'test262'), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "test262") must return true' + ); + + assert.sameValue(sample[s], 'test262', 'The value of sample[s] is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..ed67be5eaa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.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-set-p-v-receiver +description: > + Returns false 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; +testWithBigIntTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + $DETACHBUFFER(sample.buffer); + sample[0] = 1n; + assert.sameValue(sample[0], undefined, '`sample[0]` is undefined'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js new file mode 100644 index 0000000000..d4b7ea8ba3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js @@ -0,0 +1,56 @@ +// 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 when setting the value of any CanonicalNumericIndexString if buffer is detached. +info: | + [[Set]] ( P, V, Receiver) + + ... + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA([42n]); + $DETACHBUFFER(sample.buffer); + sample[0] = 1n; + assert.sameValue(sample[0], undefined, '`sample[0] = 1n` is undefined'); + sample['1.1'] = 1n; + assert.sameValue(sample['1.1'], undefined, '`sample["1.1"] = 1n` is undefined'); + sample['-0'] = 1n; + assert.sameValue(sample['-0'], undefined, '`sample["-0"] = 1n` is undefined'); + sample['-1'] = 1n; + assert.sameValue(sample['-1'], undefined, '`sample["-1"] = 1n` is undefined'); + sample['1'] = 1n; + assert.sameValue(sample['1'], undefined, '`sample["1"] = 1n` is undefined'); + sample['2'] = 1n; + assert.sameValue(sample['2'], undefined, '`sample["2"] = 1n` is undefined'); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample['0'] = obj; + }, '`sample["0"] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.js new file mode 100644 index 0000000000..60d0b4b736 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.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 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + +let proto = TypedArray.prototype; +let throwDesc = { + set: function() { + throw new Test262Error('OrdinarySet was called!'); + } +}; + +Object.defineProperty(proto, '0', throwDesc); +Object.defineProperty(proto, '1', throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(2); + assert.sameValue(Reflect.set(sample, '0', 1n), true, 'Reflect.set(sample, "0", 1n) must return true'); + assert.sameValue(sample[0], 1n, 'The value of sample[0] is 1n'); + assert.sameValue(Reflect.set(sample, '1', 42n), true, 'Reflect.set(sample, "1", 42n) must return true'); + assert.sameValue(sample[1], 42n, 'The value of sample[1] is 42n'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.js new file mode 100644 index 0000000000..a8027b8002 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.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: > + Returns true, even if index is -0 +info: | + [[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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + assert.sameValue(Reflect.set(sample, '-0', 1n), true, 'Reflect.set("new TA([42n])", "-0", 1n) must return true'); + assert.sameValue(sample.hasOwnProperty('-0'), false, 'sample.hasOwnProperty("-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..380c18c935 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.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: > + Use OrdinarySet 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: [align-detached-buffer-semantics-with-web-reality, 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, + 'Reflect.set("new TA([42n])", key, "ecma262") must return true' + ); + + assert.sameValue(sample[key], 'ecma262', 'The value of sample[key] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, key, 'es3000'), + true, + 'Reflect.set("new TA([42n])", key, "es3000") must return true' + ); + + assert.sameValue(sample[key], 'es3000', 'The value of sample[key] is "es3000"'); + + Object.defineProperty(sample, key, { + writable: false, + value: undefined + }); + + assert.sameValue(Reflect.set(sample, key, 42), false, 'Reflect.set("new TA([42n])", key, 42) must return false'); + assert.sameValue(sample[key], undefined, 'The value of sample[key] is expected to equal `undefined`'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..cb8fa7a526 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.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-set-p-v-receiver +description: > + Returns true, even if index is not CanonicalNumericIndexString +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + assert.sameValue(Reflect.set(sample, '1.1', 1n), true, 'Reflect.set("new TA([42n])", "1.1", 1n) must return true'); + + assert.sameValue( + Reflect.set(sample, '0.0001', 1n), + true, + 'Reflect.set("new TA([42n])", "0.0001", 1n) must return true' + ); + + assert.sameValue(sample.hasOwnProperty('1.1'), false, 'sample.hasOwnProperty("1.1") must return false'); + assert.sameValue(sample.hasOwnProperty('0.0001'), false, 'sample.hasOwnProperty("0.0001") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js new file mode 100644 index 0000000000..5b8dd12f01 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-throws.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-set-p-v-receiver +description: > + Returns abrupt from OrdinarySet 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: [align-detached-buffer-semantics-with-web-reality, 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; + }, '`sample.test262 = 1` throws Test262Error'); + + assert.sameValue(sample.test262, undefined, 'The value of sample.test262 is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..04f4deab89 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/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 OrdinarySet 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: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, 'test262', 'ecma262'), + true, + 'Reflect.set("new TA([42n])", "test262", "ecma262") must return true' + ); + + assert.sameValue(sample.test262, 'ecma262', 'The value of sample.test262 is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, 'test262', 'es3000'), + true, + 'Reflect.set("new TA([42n])", "test262", "es3000") must return true' + ); + + assert.sameValue(sample.test262, 'es3000', 'The value of sample.test262 is "es3000"'); + + Object.defineProperty(sample, 'foo', { + writable: false, + value: undefined + }); + + assert.sameValue(Reflect.set(sample, 'foo', 42), false, 'Reflect.set("new TA([42n])", "foo", 42) must return false'); + assert.sameValue(sample.foo, undefined, 'The value of sample.foo is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-out-of-bounds.js new file mode 100644 index 0000000000..5fe02832bd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/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 true, even 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + 9.4.5.11 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: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + assert.sameValue(Reflect.set(sample, '-1', 1n), true, 'Reflect.set("new TA([42n])", "-1", 1n) must return false'); + assert.sameValue(Reflect.set(sample, '1', 1n), true, 'Reflect.set("new TA([42n])", "1", 1n) must return false'); + assert.sameValue(Reflect.set(sample, '2', 1n), true, 'Reflect.set("new TA([42n])", "2", 1n) must return false'); + assert.sameValue(sample.hasOwnProperty('-1'), false, 'sample.hasOwnProperty("-1") must return false'); + assert.sameValue(sample.hasOwnProperty('1'), false, 'sample.hasOwnProperty("1") must return false'); + assert.sameValue(sample.hasOwnProperty('2'), false, 'sample.hasOwnProperty("2") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..0fc2d9ec46 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.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-set-p-v-receiver +description: > + Use OrdinarySet 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: [align-detached-buffer-semantics-with-web-reality, 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, + 'Reflect.set("new TA([42n])", "Symbol(\\"1\\")", "ecma262") must return true' + ); + + assert.sameValue(sample[s1], 'ecma262', 'The value of sample[s1] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, s1, 'es3000'), + true, + 'Reflect.set("new TA([42n])", "Symbol(\\"1\\")", "es3000") must return true' + ); + + assert.sameValue(sample[s1], 'es3000', 'The value of sample[s1] is "es3000"'); + + Object.defineProperty(sample, s2, { + writable: false, + value: undefined + }); + + assert.sameValue( + Reflect.set(sample, s2, 42), + false, + 'Reflect.set("new TA([42n])", "Symbol(\\"2\\")", 42) must return false' + ); + + assert.sameValue(sample[s2], undefined, 'The value of sample[s2] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js new file mode 100644 index 0000000000..104c5a8509 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js @@ -0,0 +1,63 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on null +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Null + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = null; + }, '`typedArray[0] = null` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js new file mode 100644 index 0000000000..b7724a0aed --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js @@ -0,0 +1,87 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on Number +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Number + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = 1; + }, '`typedArray[0] = 1` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = Math.pow(2, 63); + }, '`typedArray[0] = Math.pow(2, 63)` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = +0; + }, '`typedArray[0] = +0` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = -0; + }, '`typedArray[0] = -0` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = Infinity; + }, '`typedArray[0] = Infinity` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = -Infinity; + }, '`typedArray[0] = -Infinity` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = NaN; + }, '`typedArray[0] = NaN` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js new file mode 100644 index 0000000000..f0646cc025 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js @@ -0,0 +1,67 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt String, when StringToBigInt returns NaN +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + ... + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(SyntaxError, function() { + typedArray[0] = "definately not a number"; + }, '`typedArray[0] = "definately not a number"` throws SyntaxError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js new file mode 100644 index 0000000000..ff5aa4145a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js @@ -0,0 +1,87 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for input array of Strings, successful conversion +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + + StringToBigInt (argument) + Apply the algorithm in 3.1.3.1 with the following changes: + * Replace the StrUnsignedDecimalLiteral production with DecimalDigits to + not allow Infinity, decimal points, or exponents. + * If the MV is NaN, return NaN, otherwise return the BigInt which exactly + corresponds to the MV, rather than rounding to a Number. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + typedArray[0] = ''; + assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); + typedArray[0] = '1'; + assert.sameValue(typedArray[0], 1n, 'The value of typedArray[0] is 1n'); + + assert.throws(SyntaxError, function() { + typedArray[0] = '1n'; + }, '`typedArray[0] = "1n"` throws SyntaxError'); + + assert.throws(SyntaxError, function() { + typedArray[0] = 'Infinity'; + }, '`typedArray[0] = "Infinity"` throws SyntaxError'); + + assert.throws(SyntaxError, function() { + typedArray[0] = '1.1'; + }, '`typedArray[0] = "1.1"` throws SyntaxError'); + + assert.throws(SyntaxError, function() { + typedArray[0] = '1e7'; + }, '`typedArray[0] = "1e7"` throws SyntaxError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js new file mode 100644 index 0000000000..6b5618b568 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js @@ -0,0 +1,65 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on Symbol +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Symbol + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray, Symbol] +---*/ + +var s = Symbol() + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1) + + assert.throws(TypeError, function() { + typedArray[0] = s; + }, '`typedArray[0] = s` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..974de14c4a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js @@ -0,0 +1,40 @@ +// 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, + will always return true. +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let ta = new TA(1); + let isDetached = false; + let result = Reflect.set(ta, 0, { + valueOf() { + $DETACHBUFFER(ta.buffer); + isDetached = true; + return 42n; + } + }); + + assert.sameValue(result, true); + assert.sameValue(ta[0], undefined); + assert.sameValue(isDetached, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-throws.js new file mode 100644 index 0000000000..665d19b195 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-throws.js @@ -0,0 +1,62 @@ +// 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA([42n]); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample['0'] = obj; + }, '`sample["0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['1.1'] = obj; + }, '`sample["1.1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['-0'] = obj; + }, '`sample["-0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['-1'] = obj; + }, '`sample["-1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['1'] = obj; + }, '`sample["1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['2'] = obj; + }, '`sample["2"] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js new file mode 100644 index 0000000000..a2152d98f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js @@ -0,0 +1,64 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on undefined +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + ... + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Undefined + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = undefined; + }, '`typedArray[0] = undefined` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js new file mode 100644 index 0000000000..d2355a13c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on BigInt +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + 6. Otherwise, let numValue be ? ToNumber(value). + ... + + ToNumber ( argument ) + The abstract operation ToNumber converts argument to a value of type Number + according to: + + Number Conversion + Argument Type: BigInt + Result: Throw a TypeError Exception + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = 1n; + }, '`typedArray[0] = 1n` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js new file mode 100644 index 0000000000..d51afcab7a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js @@ -0,0 +1,107 @@ +// 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: Consistent canonicalization of NaN values +info: | + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + #sec-setvalueinbuffer + SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + + #sec-numbertorawbytes + + NumberToRawBytes( type, value, isLittleEndian ) + + 1. If type is "Float32", then + a. Set rawBytes to a List containing the 4 bytes that are the result + of converting value to IEEE 754-2008 binary32 format using “Round to + nearest, ties to even” rounding mode. If isLittleEndian is false, the + bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number + encoding. An implementation must always choose either the same encoding + for each implementation distinguishable *NaN* value, or an + implementation-defined canonical value. + 2. Else, if type is "Float64", then + a. Set _rawBytes_ to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of _value_. If _isLittleEndian_ is + *false*, the bytes are arranged in big endian order. Otherwise, + the bytes are arranged in little endian order. If _value_ is *NaN*, + _rawValue_ may be set to any implementation chosen IEEE 754-2008 + binary64 format Not-a-Number encoding. An implementation must + always choose either the same encoding for each implementation + distinguishable *NaN* value, or an implementation-defined + canonical value. + ... + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js, testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(FA) { + var precision = FA === Float32Array ? "single" : "double"; + var samples = new FA(1); + var controls, idx, aNaN; + + for (idx = 0; idx < NaNs.length; ++idx) { + aNaN = NaNs[idx]; + controls = new FA([aNaN, aNaN, aNaN]); + + samples[0] = aNaN; + + for (var i = 0; i < samples.length; i++) { + var sample = samples[i]; + var control = controls[i]; + + assert( + samples[i] !== samples[i], + 'The result of `(samples[i] !== samples[i])` is true' + ); + + assert( + controls[i] !== controls[i], + 'The result of `(controls[i] !== controls[i])` is true' + ); + } + } +}, [Float32Array, Float64Array]); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.js new file mode 100644 index 0000000000..786b0c4bec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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, testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + sample[0] = value; + + assert.sameValue(sample[0], expected, 'The value of sample[0] is expected to equal the value of expected'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..81a22ef437 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, "foo", "test262"), + true, + 'Reflect.set(sample, "foo", "test262") must return true' + ); + assert.sameValue(sample.foo, "test262", 'The value of sample.foo is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..183070c85b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-symbol.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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, Reflect, TypedArray] +---*/ + +let s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, s, "test262"), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "test262") must return true' + ); + assert.sameValue(sample[s], "test262", 'The value of sample[s] is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js new file mode 100644 index 0000000000..5e6269b2e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; +testWithTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + $DETACHBUFFER(sample.buffer); + sample[0] = 1; + assert.sameValue(sample[0], undefined, '`sample[0]` is undefined'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js new file mode 100644 index 0000000000..705b22dca5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.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-set-p-v-receiver +description: > + Returns false if key has a numeric index and object has a detached buffer +info: | + [[Set]] ( P, V, Receiver) + + ... + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ +testWithTypedArrayConstructors(function(TA) { + let sample = new TA([42]); + $DETACHBUFFER(sample.buffer); + sample[0] = 1; + + assert.sameValue(sample[0], undefined, '`sample[0] = 1` is undefined'); + sample['1.1'] = 1; + assert.sameValue(sample['1.1'], undefined, '`sample[\'1.1\'] = 1` is undefined'); + sample['-0'] = 1; + assert.sameValue(sample['-0'], undefined, '`sample[\'-0\'] = 1` is undefined'); + sample['-1'] = 1; + assert.sameValue(sample['-1'], undefined, '`sample[\'-1\'] = 1` is undefined'); + sample['1'] = 1; + assert.sameValue(sample['1'], undefined, '`sample[\'1\'] = 1` is undefined'); + sample['2'] = 1; + assert.sameValue(sample['2'], undefined, '`sample[\'2\'] = 1` is undefined'); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample['0'] = obj; + }, '`sample[\'0\'] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.js new file mode 100644 index 0000000000..66cf4571ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +let proto = TypedArray.prototype; +let throwDesc = { + set: function() { + throw new Test262Error('OrdinarySet was called!'); + } +}; + +Object.defineProperty(proto, '0', throwDesc); +Object.defineProperty(proto, '1', throwDesc); + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(2); + assert.sameValue(Reflect.set(sample, '0', 1), true, 'Reflect.set(sample, "0", 1) must return true'); + assert.sameValue(sample[0], 1, 'The value of sample[0] is 1'); + assert.sameValue(Reflect.set(sample, '1', 42), true, 'Reflect.set(sample, "1", 42) must return true'); + assert.sameValue(sample[1], 42, 'The value of sample[1] is 42'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.js new file mode 100644 index 0000000000..c171aa1a3c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.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-set-p-v-receiver +description: > + Returns true, even 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Reflect.set(sample, "-0", 1), true, 'Reflect.set(sample, "-0", 1) must return true'); + assert.sameValue(sample.hasOwnProperty("-0"), false, 'sample.hasOwnProperty("-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.js new file mode 100644 index 0000000000..72d1f7769a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.js @@ -0,0 +1,60 @@ +// 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 OrdinarySet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([42]); + + assert.sameValue( + Reflect.set(sample, key, "ecma262"), + true, + 'Reflect.set(sample, key, "ecma262") must return true' + ); + assert.sameValue(sample[key], "ecma262", 'The value of sample[key] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, key, "es3000"), + true, + 'Reflect.set(sample, key, "es3000") must return true' + ); + assert.sameValue(sample[key], "es3000", 'The value of sample[key] is "es3000"'); + + Object.defineProperty(sample, key, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, key, 42), + false, + 'Reflect.set(sample, key, 42) must return false' + ); + assert.sameValue( + sample[key], undefined, 'The value of sample[key] is expected to equal `undefined`' + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.js new file mode 100644 index 0000000000..a13b9cfe79 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.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-set-p-v-receiver +description: > + Returns true, even if index is not CanonicalNumericIndexString +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Reflect.set(sample, "1.1", 1), true, 'Reflect.set(sample, "1.1", 1) must return true'); + assert.sameValue(Reflect.set(sample, "0.0001", 1), true, 'Reflect.set(sample, "0.0001", 1) must return true'); + + assert.sameValue(sample.hasOwnProperty("1.1"), false, 'sample.hasOwnProperty("1.1") must return false'); + assert.sameValue( + sample.hasOwnProperty("0.0001"), + false, + 'sample.hasOwnProperty("0.0001") must return false' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-throws.js new file mode 100644 index 0000000000..13360bfa55 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-throws.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-set-p-v-receiver +description: > + Returns abrupt from OrdinarySet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + set: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262 = 1; + }, '`sample.test262 = 1` throws Test262Error'); + + assert.sameValue(sample.test262, undefined, 'The value of sample.test262 is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.js new file mode 100644 index 0000000000..9db75bd292 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue( + Reflect.set(sample, "test262", "ecma262"), + true, + 'Reflect.set(sample, "test262", "ecma262") must return true' + ); + assert.sameValue(sample.test262, "ecma262", 'The value of sample.test262 is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, "test262", "es3000"), + true, + 'Reflect.set(sample, "test262", "es3000") must return true' + ); + assert.sameValue(sample.test262, "es3000", 'The value of sample.test262 is "es3000"'); + + Object.defineProperty(sample, "foo", { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, "foo", 42), + false, + 'Reflect.set(sample, "foo", 42) must return false' + ); + assert.sameValue(sample.foo, undefined, 'The value of sample.foo is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds.js new file mode 100644 index 0000000000..5470398b71 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/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-set-p-v-receiver +description: > + Returns true even 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Reflect.set(sample, "-1", 1), true, 'Reflect.set(sample, "-1", 1) must return true'); + assert.sameValue(Reflect.set(sample, "1", 1), true, 'Reflect.set(sample, "1", 1) must return true'); + assert.sameValue(Reflect.set(sample, "2", 1), true, 'Reflect.set(sample, "2", 1) must return true'); + + assert.sameValue(sample.hasOwnProperty("-1"), false, 'sample.hasOwnProperty("-1") must return false'); + assert.sameValue(sample.hasOwnProperty("1"), false, 'sample.hasOwnProperty("1") must return false'); + assert.sameValue(sample.hasOwnProperty("2"), false, 'sample.hasOwnProperty("2") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.js new file mode 100644 index 0000000000..fe624e4725 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue( + Reflect.set(sample, s1, "ecma262"), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "ecma262") must return true' + ); + assert.sameValue(sample[s1], "ecma262", 'The value of sample[s1] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, s1, "es3000"), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "es3000") must return true' + ); + assert.sameValue(sample[s1], "es3000", 'The value of sample[s1] is "es3000"'); + + Object.defineProperty(sample, s2, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, s2, 42), + false, + 'Reflect.set(sample, "Symbol(\\"2\\")", 42) must return false' + ); + assert.sameValue(sample[s2], undefined, 'The value of sample[s2] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js new file mode 100644 index 0000000000..abdb960ca1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js @@ -0,0 +1,614 @@ +// GENERATED, DO NOT EDIT +// file: byteConversionValues.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Provide a list for original and expected values for different byte + conversions. + This helper is mostly used on tests for TypedArray and DataView, and each + array from the expected values must match the original values array on every + index containing its original value. +defines: [byteConversionValues] +---*/ +var byteConversionValues = { + values: [ + 127, // 2 ** 7 - 1 + 128, // 2 ** 7 + 32767, // 2 ** 15 - 1 + 32768, // 2 ** 15 + 2147483647, // 2 ** 31 - 1 + 2147483648, // 2 ** 31 + 255, // 2 ** 8 - 1 + 256, // 2 ** 8 + 65535, // 2 ** 16 - 1 + 65536, // 2 ** 16 + 4294967295, // 2 ** 32 - 1 + 4294967296, // 2 ** 32 + 9007199254740991, // 2 ** 53 - 1 + 9007199254740992, // 2 ** 53 + 1.1, + 0.1, + 0.5, + 0.50000001, + 0.6, + 0.7, + undefined, + -1, + -0, + -0.1, + -1.1, + NaN, + -127, // - ( 2 ** 7 - 1 ) + -128, // - ( 2 ** 7 ) + -32767, // - ( 2 ** 15 - 1 ) + -32768, // - ( 2 ** 15 ) + -2147483647, // - ( 2 ** 31 - 1 ) + -2147483648, // - ( 2 ** 31 ) + -255, // - ( 2 ** 8 - 1 ) + -256, // - ( 2 ** 8 ) + -65535, // - ( 2 ** 16 - 1 ) + -65536, // - ( 2 ** 16 ) + -4294967295, // - ( 2 ** 32 - 1 ) + -4294967296, // - ( 2 ** 32 ) + Infinity, + -Infinity, + 0 + ], + + expected: { + Int8: [ + 127, // 127 + -128, // 128 + -1, // 32767 + 0, // 32768 + -1, // 2147483647 + 0, // 2147483648 + -1, // 255 + 0, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 0, // 32768 + 255, // 2147483647 + 0, // 2147483648 + 255, // 255 + 0, // 256 + 255, // 65535 + 0, // 65536 + 255, // 4294967295 + 0, // 4294967296 + 255, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 255, // -1 + 0, // -0 + 0, // -0.1 + 255, // -1.1 + 0, // NaN + 129, // -127 + 128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8Clamped: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 255, // 32768 + 255, // 2147483647 + 255, // 2147483648 + 255, // 255 + 255, // 256 + 255, // 65535 + 255, // 65536 + 255, // 4294967295 + 255, // 4294967296 + 255, // 9007199254740991 + 255, // 9007199254740992 + 1, // 1.1, + 0, // 0.1 + 0, // 0.5 + 1, // 0.50000001, + 1, // 0.6 + 1, // 0.7 + 0, // undefined + 0, // -1 + 0, // -0 + 0, // -0.1 + 0, // -1.1 + 0, // NaN + 0, // -127 + 0, // -128 + 0, // -32767 + 0, // -32768 + 0, // -2147483647 + 0, // -2147483648 + 0, // -255 + 0, // -256 + 0, // -65535 + 0, // -65536 + 0, // -4294967295 + 0, // -4294967296 + 255, // Infinity + 0, // -Infinity + 0 + ], + Int16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + -32768, // 32768 + -1, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + -255, // -255 + -256, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 65535, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 0, // 65536 + 65535, // 4294967295 + 0, // 4294967296 + 65535, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 65535, // -1 + 0, // -0 + 0, // -0.1 + 65535, // -1.1 + 0, // NaN + 65409, // -127 + 65408, // -128 + 32769, // -32767 + 32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 65281, // -255 + 65280, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Int32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + -2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 0, // 4294967296 + 4294967295, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 4294967295, // -1 + 0, // -0 + 0, // -0.1 + 4294967295, // -1.1 + 0, // NaN + 4294967169, // -127 + 4294967168, // -128 + 4294934529, // -32767 + 4294934528, // -32768 + 2147483649, // -2147483647 + 2147483648, // -2147483648 + 4294967041, // -255 + 4294967040, // -256 + 4294901761, // -65535 + 4294901760, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Float32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483648, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967296, // 4294967295 + 4294967296, // 4294967296 + 9007199254740992, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.100000023841858, // 1.1 + 0.10000000149011612, // 0.1 + 0.5, // 0.5 + 0.5, // 0.50000001, + 0.6000000238418579, // 0.6 + 0.699999988079071, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.10000000149011612, // -0.1 + -1.100000023841858, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483648, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967296, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ], + Float64: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 4294967296, // 4294967296 + 9007199254740991, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.1, // 1.1 + 0.1, // 0.1 + 0.5, // 0.5 + 0.50000001, // 0.50000001, + 0.6, // 0.6 + 0.7, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.1, // -0.1 + -1.1, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967295, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ] + } +}; + +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: nans.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A collection of NaN values produced from expressions that have been observed + to create distinct bit representations on various platforms. These provide a + weak basis for assertions regarding the consistent canonicalization of NaN + values in Array buffers. +defines: [NaNs] +---*/ + +var NaNs = [ + NaN, + Number.NaN, + NaN * 0, + 0/0, + Infinity/Infinity, + -(0/0), + Math.pow(-1, 0.5), + -Math.pow(-1, 0.5), + Number("Not-a-Number"), +]; + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..bdb3a74ae9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js @@ -0,0 +1,52 @@ +// 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, will return true. +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + 9.4.5.11 IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let ta = new TA(1); + let result = Reflect.set(ta, 0, { + valueOf() { + $DETACHBUFFER(ta.buffer); + return 42; + } + }); + + assert.sameValue(result, true); + assert.sameValue(ta[0], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-throws.js new file mode 100644 index 0000000000..08f17de272 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-throws.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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA([42]); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample["0"] = obj; + }, '`sample["0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["1.1"] = obj; + }, '`sample["1.1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["-0"] = obj; + }, '`sample["-0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["-1"] = obj; + }, '`sample["-1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["1"] = obj; + }, '`sample["1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["2"] = obj; + }, '`sample["2"] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); |