mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
BigInt: Add tests for BigInt conversions in TypedArray prototype/set and TypedArray internal [[set]] (#1478)
* BigInt: Add tests for BigInt conversions in prototype/set * BigInt: add conversion tests for internal [[set]]
This commit is contained in:
parent
3c69133cc4
commit
985c439c94
89
test/built-ins/TypedArray/prototype/set/BigInt/bigint-tobigint64.js
vendored
Normal file
89
test/built-ins/TypedArray/prototype/set/BigInt/bigint-tobigint64.js
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-array-offset
|
||||
description: >
|
||||
Behavior for input array of BigInts
|
||||
info: |
|
||||
%TypedArray%.prototype.set ( array [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the object
|
||||
array. The optional offset value indicates the first element index in this
|
||||
TypedArray where values are written. If omitted, it is assumed to be 0.
|
||||
...
|
||||
21. Repeat, while targetByteIndex < limit
|
||||
a. Let Pk be ! ToString(k).
|
||||
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||
c. Let value be ? Get(src, Pk).
|
||||
d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array",
|
||||
let value be ? ToBigInt(value).
|
||||
e. Otherwise, let value be ? ToNumber(value).
|
||||
f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||
g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||
kNumbervalue, true, "Unordered").
|
||||
h. Set k to k + 1.
|
||||
i. Set targetByteIndex to targetByteIndex + targetElementSize.
|
||||
...
|
||||
|
||||
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.
|
||||
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
var vals = [
|
||||
18446744073709551618n, // 2n ** 64n + 2n
|
||||
9223372036854775810n, // 2n ** 63n + 2n
|
||||
2n,
|
||||
0n,
|
||||
-2n,
|
||||
-9223372036854775810n, // -(2n ** 63n) - 2n
|
||||
-18446744073709551618n, // -(2n ** 64n) - 2n
|
||||
];
|
||||
|
||||
var typedArray = new BigInt64Array(vals.length);
|
||||
typedArray.set(vals);
|
||||
|
||||
assert.sameValue(typedArray[0], 2n,
|
||||
"ToBigInt64(2n ** 64n + 2n) => 2n");
|
||||
|
||||
assert.sameValue(typedArray[1], -9223372036854775806n, // 2n - 2n ** 63n
|
||||
"ToBigInt64(2n ** 63n + 2n) => -9223372036854775806n");
|
||||
|
||||
assert.sameValue(typedArray[2], 2n,
|
||||
"ToBigInt64(2n) => 2n");
|
||||
|
||||
assert.sameValue(typedArray[3], 0n,
|
||||
"ToBigInt64(0n) => 0n");
|
||||
|
||||
assert.sameValue(typedArray[4], -2n,
|
||||
"ToBigInt64( -2n) => -2n");
|
||||
|
||||
assert.sameValue(typedArray[5], 9223372036854775806n, // 2n ** 63n - 2
|
||||
"ToBigInt64( -(2n ** 64n) - 2n) => 9223372036854775806n");
|
||||
|
||||
assert.sameValue(typedArray[6], -2n,
|
||||
"ToBigInt64( -(2n ** 64n) - 2n) => -2n");
|
||||
|
88
test/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js
vendored
Normal file
88
test/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-array-offset
|
||||
description: >
|
||||
Behavior for input array of BigInts
|
||||
info: |
|
||||
%TypedArray%.prototype.set ( array [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the object
|
||||
array. The optional offset value indicates the first element index in this
|
||||
TypedArray where values are written. If omitted, it is assumed to be 0.
|
||||
...
|
||||
21. Repeat, while targetByteIndex < limit
|
||||
a. Let Pk be ! ToString(k).
|
||||
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||
c. Let value be ? Get(src, Pk).
|
||||
d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array",
|
||||
let value be ? ToBigInt(value).
|
||||
e. Otherwise, let value be ? ToNumber(value).
|
||||
f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||
g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||
kNumbervalue, true, "Unordered").
|
||||
h. Set k to k + 1.
|
||||
i. Set targetByteIndex to targetByteIndex + targetElementSize.
|
||||
...
|
||||
|
||||
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.
|
||||
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
var vals = [
|
||||
18446744073709551618n, // 2n ** 64n + 2n
|
||||
9223372036854775810n, // 2n ** 63n + 2n
|
||||
2n,
|
||||
0n,
|
||||
-2n,
|
||||
-9223372036854775810n, // -(2n ** 63n) - 2n
|
||||
-18446744073709551618n, // -(2n ** 64n) - 2n
|
||||
];
|
||||
|
||||
var typedArray = new BigUint64Array(vals.length);
|
||||
typedArray.set(vals);
|
||||
|
||||
assert.sameValue(typedArray[0], 2n,
|
||||
"ToBigUint64(2n ** 64n + 2n) => 2n");
|
||||
|
||||
assert.sameValue(typedArray[1], 9223372036854775810n, // 2n ** 63n + 2n
|
||||
"ToBigUint64(2n ** 63n + 2n) => 9223372036854775810");
|
||||
|
||||
assert.sameValue(typedArray[2], 2n,
|
||||
"ToBigUint64(2n) => 2n");
|
||||
|
||||
assert.sameValue(typedArray[3], 0n,
|
||||
"ToBigUint64(0n) => 0n");
|
||||
|
||||
assert.sameValue(typedArray[4], 18446744073709551614n, // 2n ** 64n - 2n
|
||||
"ToBigUint64( -2n) => 18446744073709551614n");
|
||||
|
||||
assert.sameValue(typedArray[5], 9223372036854775806n, // 2n ** 63n - 2n
|
||||
"ToBigUint64( -(2n ** 63n) - 2n) => 9223372036854775806n");
|
||||
|
||||
assert.sameValue(typedArray[6], 18446744073709551614n, // 2n ** 64n - 2n
|
||||
"ToBigUint64( -(2n ** 64n) - 2n) => 18446744073709551614n");
|
46
test/built-ins/TypedArray/prototype/set/BigInt/boolean-tobigint.js
vendored
Normal file
46
test/built-ins/TypedArray/prototype/set/BigInt/boolean-tobigint.js
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-array-offset
|
||||
description: >
|
||||
Behavior for input array of Booleans
|
||||
info: |
|
||||
%TypedArray%.prototype.set ( array [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the object
|
||||
array. The optional offset value indicates the first element index in this
|
||||
TypedArray where values are written. If omitted, it is assumed to be 0.
|
||||
...
|
||||
21. Repeat, while targetByteIndex < limit
|
||||
a. Let Pk be ! ToString(k).
|
||||
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||
c. Let value be ? Get(src, Pk).
|
||||
d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array",
|
||||
let value be ? ToBigInt(value).
|
||||
e. Otherwise, let value be ? ToNumber(value).
|
||||
f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||
g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||
kNumbervalue, true, "Unordered").
|
||||
h. Set k to k + 1.
|
||||
i. Set targetByteIndex to targetByteIndex + targetElementSize.
|
||||
...
|
||||
|
||||
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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(2);
|
||||
typedArray.set([false, true])
|
||||
|
||||
assert.sameValue(typedArray[0], 0n, "False converts to BigInt");
|
||||
assert.sameValue(typedArray[1], 1n, "True converts to BigInt");
|
||||
});
|
47
test/built-ins/TypedArray/prototype/set/BigInt/null-tobigint.js
vendored
Normal file
47
test/built-ins/TypedArray/prototype/set/BigInt/null-tobigint.js
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-array-offset
|
||||
description: >
|
||||
Return abrupt on null
|
||||
info: |
|
||||
%TypedArray%.prototype.set ( array [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the object
|
||||
array. The optional offset value indicates the first element index in this
|
||||
TypedArray where values are written. If omitted, it is assumed to be 0.
|
||||
...
|
||||
21. Repeat, while targetByteIndex < limit
|
||||
a. Let Pk be ! ToString(k).
|
||||
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||
c. Let value be ? Get(src, Pk).
|
||||
d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array",
|
||||
let value be ? ToBigInt(value).
|
||||
e. Otherwise, let value be ? ToNumber(value).
|
||||
f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||
g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||
kNumbervalue, true, "Unordered").
|
||||
h. Set k to k + 1.
|
||||
i. Set targetByteIndex to targetByteIndex + targetElementSize.
|
||||
...
|
||||
|
||||
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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([null]);
|
||||
}, "abrupt completion from Null");
|
||||
|
||||
});
|
72
test/built-ins/TypedArray/prototype/set/BigInt/number-tobigint.js
vendored
Normal file
72
test/built-ins/TypedArray/prototype/set/BigInt/number-tobigint.js
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-array-offset
|
||||
description: >
|
||||
Return abrupt on Number
|
||||
info: |
|
||||
%TypedArray%.prototype.set ( array [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the object
|
||||
array. The optional offset value indicates the first element index in this
|
||||
TypedArray where values are written. If omitted, it is assumed to be 0.
|
||||
...
|
||||
21. Repeat, while targetByteIndex < limit
|
||||
a. Let Pk be ! ToString(k).
|
||||
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||
c. Let value be ? Get(src, Pk).
|
||||
d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array",
|
||||
let value be ? ToBigInt(value).
|
||||
e. Otherwise, let value be ? ToNumber(value).
|
||||
f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||
g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||
kNumbervalue, true, "Unordered").
|
||||
h. Set k to k + 1.
|
||||
i. Set targetByteIndex to targetByteIndex + targetElementSize.
|
||||
...
|
||||
|
||||
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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([1]);
|
||||
}, "abrupt completion from Number: 1");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([Math.pow(2, 63)]);
|
||||
}, "abrupt completion from Number: 2**63");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([+0]);
|
||||
}, "abrupt completion from Number: +0");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([-0]);
|
||||
}, "abrupt completion from Number: -0");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([Infinity]);
|
||||
}, "abrupt completion from Number: Infinity");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([-Infinity]);
|
||||
}, "abrupt completion from Number: -Infinity");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([NaN]);
|
||||
}, "abrupt completion from Number: NaN");
|
||||
|
||||
});
|
38
test/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-big.js
vendored
Normal file
38
test/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-big.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-typedarray-offset
|
||||
description: >
|
||||
If typedArray constructor argument is a Big(U)Int, succeed in set
|
||||
info: |
|
||||
%TypedArray%.prototype.set( typedArray [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the
|
||||
typedArray argument object. The optional offset value indicates the first
|
||||
element index in this TypedArray where values are written. If omitted, it
|
||||
is assumed to be 0.
|
||||
...
|
||||
23. If one of srcType and targetType contains the substring "Big" and the
|
||||
other does not, throw a TypeError exception.
|
||||
...
|
||||
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
var srcTypedArray;
|
||||
var targetTypedArray;
|
||||
var testValue = 42n;
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(BTA1) {
|
||||
|
||||
srcTypedArray = new BTA1([testValue]);
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(BTA2) {
|
||||
|
||||
targetTypedArray = new BTA2(1);
|
||||
targetTypedArray.set(srcTypedArray);
|
||||
assert.sameValue(targetTypedArray[0], testValue,
|
||||
"Setting BigInt TypedArray with BigInt TypedArray should succeed.")
|
||||
});
|
||||
});
|
||||
|
37
test/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-not-big-throws.js
vendored
Normal file
37
test/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-not-big-throws.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-typedarray-offset
|
||||
description: >
|
||||
If typedArray set argument is not a Big(U)Int, and target is "Big", throw
|
||||
info: |
|
||||
%TypedArray%.prototype.set( typedArray [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the
|
||||
typedArray argument object. The optional offset value indicates the first
|
||||
element index in this TypedArray where values are written. If omitted, it
|
||||
is assumed to be 0.
|
||||
...
|
||||
23. If one of srcType and targetType contains the substring "Big" and the
|
||||
other does not, throw a TypeError exception.
|
||||
...
|
||||
|
||||
includes: [testBigIntTypedArray.js, testTypedArray.js]
|
||||
features: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
var bigTypedArray;
|
||||
var littleTypedArray;
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
|
||||
littleTypedArray = new TA([1]);
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(BTA) {
|
||||
|
||||
bigTypedArray = new BTA(1);
|
||||
assert.throws(TypeError, function() {
|
||||
bigTypedArray.set(littleTypedArray);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
50
test/built-ins/TypedArray/prototype/set/BigInt/string-nan-tobigint.js
vendored
Normal file
50
test/built-ins/TypedArray/prototype/set/BigInt/string-nan-tobigint.js
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-array-offset
|
||||
description: >
|
||||
Return abrupt String, when StringToBigInt returns NaN
|
||||
info: |
|
||||
%TypedArray%.prototype.set ( array [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the object
|
||||
array. The optional offset value indicates the first element index in this
|
||||
TypedArray where values are written. If omitted, it is assumed to be 0.
|
||||
...
|
||||
21. Repeat, while targetByteIndex < limit
|
||||
a. Let Pk be ! ToString(k).
|
||||
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||
c. Let value be ? Get(src, Pk).
|
||||
d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array",
|
||||
let value be ? ToBigInt(value).
|
||||
e. Otherwise, let value be ? ToNumber(value).
|
||||
f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||
g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||
kNumbervalue, true, "Unordered").
|
||||
h. Set k to k + 1.
|
||||
i. Set targetByteIndex to targetByteIndex + targetElementSize.
|
||||
...
|
||||
|
||||
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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1);
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
typedArray.set(["definately not a number"]);
|
||||
}, "StringToBigInt(prim) == NaN");
|
||||
|
||||
});
|
66
test/built-ins/TypedArray/prototype/set/BigInt/string-tobigint.js
vendored
Normal file
66
test/built-ins/TypedArray/prototype/set/BigInt/string-tobigint.js
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-array-offset
|
||||
description: >
|
||||
Behavior for input array of Strings, successful conversion
|
||||
info: |
|
||||
%TypedArray%.prototype.set ( array [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the object
|
||||
array. The optional offset value indicates the first element index in this
|
||||
TypedArray where values are written. If omitted, it is assumed to be 0.
|
||||
...
|
||||
21. Repeat, while targetByteIndex < limit
|
||||
a. Let Pk be ! ToString(k).
|
||||
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||
c. Let value be ? Get(src, Pk).
|
||||
d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array",
|
||||
let value be ? ToBigInt(value).
|
||||
e. Otherwise, let value be ? ToNumber(value).
|
||||
f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||
g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||
kNumbervalue, true, "Unordered").
|
||||
h. Set k to k + 1.
|
||||
i. Set targetByteIndex to targetByteIndex + targetElementSize.
|
||||
...
|
||||
|
||||
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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(2);
|
||||
typedArray.set(['', '1'])
|
||||
|
||||
assert.sameValue(typedArray[0], 0n);
|
||||
assert.sameValue(typedArray[1], 1n);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set(['1n']);
|
||||
}, "A StringNumericLiteral may not include a BigIntLiteralSuffix.");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set(["Infinity"]);
|
||||
}, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity..");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set(["1.1"]);
|
||||
}, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... decimal points...");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set(["1e7"]);
|
||||
}, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... exponents...");
|
||||
|
||||
});
|
50
test/built-ins/TypedArray/prototype/set/BigInt/symbol-tobigint.js
vendored
Normal file
50
test/built-ins/TypedArray/prototype/set/BigInt/symbol-tobigint.js
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-array-offset
|
||||
description: >
|
||||
Return abrupt on Symbol
|
||||
info: |
|
||||
%TypedArray%.prototype.set ( array [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the object
|
||||
array. The optional offset value indicates the first element index in this
|
||||
TypedArray where values are written. If omitted, it is assumed to be 0.
|
||||
...
|
||||
21. Repeat, while targetByteIndex < limit
|
||||
a. Let Pk be ! ToString(k).
|
||||
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||
c. Let value be ? Get(src, Pk).
|
||||
d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array",
|
||||
let value be ? ToBigInt(value).
|
||||
e. Otherwise, let value be ? ToNumber(value).
|
||||
f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||
g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||
kNumbervalue, true, "Unordered").
|
||||
h. Set k to k + 1.
|
||||
i. Set targetByteIndex to targetByteIndex + targetElementSize.
|
||||
...
|
||||
|
||||
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: [BigInt, TypedArray, Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol()
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1)
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([s]);
|
||||
}, "abrupt completion from Symbol");
|
||||
|
||||
});
|
47
test/built-ins/TypedArray/prototype/set/BigInt/undefined-tobigint.js
vendored
Normal file
47
test/built-ins/TypedArray/prototype/set/BigInt/undefined-tobigint.js
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-typedarray-offset
|
||||
description: >
|
||||
Return abrupt on undefined
|
||||
info: |
|
||||
%TypedArray%.prototype.set ( array [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the object
|
||||
array. The optional offset value indicates the first element index in this
|
||||
TypedArray where values are written. If omitted, it is assumed to be 0.
|
||||
...
|
||||
21. Repeat, while targetByteIndex < limit
|
||||
a. Let Pk be ! ToString(k).
|
||||
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||
c. Let value be ? Get(src, Pk).
|
||||
d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array",
|
||||
let value be ? ToBigInt(value).
|
||||
e. Otherwise, let value be ? ToNumber(value).
|
||||
f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||
g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||
kNumbervalue, true, "Unordered").
|
||||
h. Set k to k + 1.
|
||||
i. Set targetByteIndex to targetByteIndex + targetElementSize.
|
||||
...
|
||||
|
||||
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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray.set([undefined]);
|
||||
}, "abrupt completion from undefined");
|
||||
|
||||
});
|
37
test/built-ins/TypedArray/prototype/set/src-typedarray-big-throws.js
vendored
Normal file
37
test/built-ins/TypedArray/prototype/set/src-typedarray-big-throws.js
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.set-typedarray-offset
|
||||
description: >
|
||||
If typedArray set argument is a Big(U)Int, and target not "Big", throw
|
||||
info: |
|
||||
%TypedArray%.prototype.set( typedArray [ , offset ] )
|
||||
Sets multiple values in this TypedArray, reading the values from the
|
||||
typedArray argument object. The optional offset value indicates the first
|
||||
element index in this TypedArray where values are written. If omitted, it
|
||||
is assumed to be 0.
|
||||
...
|
||||
23. If one of srcType and targetType contains the substring "Big" and the
|
||||
other does not, throw a TypeError exception.
|
||||
...
|
||||
|
||||
includes: [testBigIntTypedArray.js, testTypedArray.js]
|
||||
features: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
var bigTypedArray;
|
||||
var littleTypedArray;
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(BTA) {
|
||||
|
||||
bigTypedArray = new BTA([1n]);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
|
||||
littleTypedArray = new TA(1);
|
||||
assert.throws(TypeError, function() {
|
||||
littleTypedArray.set(bigTypedArray);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -0,0 +1,111 @@
|
||||
// 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.
|
||||
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
var vals = [
|
||||
18446744073709551618n, // 2n ** 64n + 2n
|
||||
9223372036854775810n, // 2n ** 63n + 2n
|
||||
2n,
|
||||
0n,
|
||||
-2n,
|
||||
-9223372036854775810n, // -(2n ** 63n) - 2n
|
||||
-18446744073709551618n, // -(2n ** 64n) - 2n
|
||||
];
|
||||
|
||||
var typedArray = new BigInt64Array(1);
|
||||
|
||||
typedArray[0] = vals[0];
|
||||
assert.sameValue(typedArray[0], 2n,
|
||||
"ToBigInt64(2n ** 64n + 2n) => 2n");
|
||||
|
||||
typedArray[0] = vals[1];
|
||||
assert.sameValue(typedArray[0], -9223372036854775806n, // 2n - 2n ** 63n
|
||||
"ToBigInt64(2n ** 63n + 2n) => -9223372036854775806n");
|
||||
|
||||
typedArray[0] = vals[2];
|
||||
assert.sameValue(typedArray[0], 2n,
|
||||
"ToBigInt64(2n) => 2n");
|
||||
|
||||
typedArray[0] = vals[3];
|
||||
assert.sameValue(typedArray[0], 0n,
|
||||
"ToBigInt64(0n) => 0n");
|
||||
|
||||
typedArray[0] = vals[4];
|
||||
assert.sameValue(typedArray[0], -2n,
|
||||
"ToBigInt64( -2n) => -2n");
|
||||
|
||||
typedArray[0] = vals[5];
|
||||
assert.sameValue(typedArray[0], 9223372036854775806n, // 2n ** 63n - 2
|
||||
"ToBigInt64( -(2n ** 64n) - 2n) => 9223372036854775806n");
|
||||
|
||||
typedArray[0] = vals[6];
|
||||
assert.sameValue(typedArray[0], -2n,
|
||||
"ToBigInt64( -(2n ** 64n) - 2n) => -2n");
|
||||
|
@ -0,0 +1,110 @@
|
||||
// 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.
|
||||
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
var vals = [
|
||||
18446744073709551618n, // 2n ** 64n + 2n
|
||||
9223372036854775810n, // 2n ** 63n + 2n
|
||||
2n,
|
||||
0n,
|
||||
-2n,
|
||||
-9223372036854775810n, // -(2n ** 63n) - 2n
|
||||
-18446744073709551618n, // -(2n ** 64n) - 2n
|
||||
];
|
||||
|
||||
var typedArray = new BigUint64Array(1);
|
||||
|
||||
typedArray[0] = vals[0];
|
||||
assert.sameValue(typedArray[0], 2n,
|
||||
"ToBigUint64(2n ** 64n + 2n) => 2n");
|
||||
|
||||
typedArray[0] = vals[1];
|
||||
assert.sameValue(typedArray[0], 9223372036854775810n, // 2n ** 63n + 2n
|
||||
"ToBigUint64(2n ** 63n + 2n) => 9223372036854775810");
|
||||
|
||||
typedArray[0] = vals[2];
|
||||
assert.sameValue(typedArray[0], 2n,
|
||||
"ToBigUint64(2n) => 2n");
|
||||
|
||||
typedArray[0] = vals[3];
|
||||
assert.sameValue(typedArray[0], 0n,
|
||||
"ToBigUint64(0n) => 0n");
|
||||
|
||||
typedArray[0] = vals[4];
|
||||
assert.sameValue(typedArray[0], 18446744073709551614n, // 2n ** 64n - 2n
|
||||
"ToBigUint64( -2n) => 18446744073709551614n");
|
||||
|
||||
typedArray[0] = vals[5];
|
||||
assert.sameValue(typedArray[0], 9223372036854775806n, // 2n ** 63n - 2n
|
||||
"ToBigUint64( -(2n ** 63n) - 2n) => 9223372036854775806n");
|
||||
|
||||
typedArray[0] = vals[6];
|
||||
assert.sameValue(typedArray[0], 18446744073709551614n, // 2n ** 64n - 2n
|
||||
"ToBigUint64( -(2n ** 64n) - 2n) => 18446744073709551614n");
|
@ -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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(2);
|
||||
typedArray[0] = false;
|
||||
typedArray[1] = true;
|
||||
|
||||
assert.sameValue(typedArray[0], 0n, "False converts to BigInt");
|
||||
assert.sameValue(typedArray[1], 1n, "True converts to BigInt");
|
||||
});
|
@ -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 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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = null;
|
||||
}, "abrupt completion from Null");
|
||||
|
||||
});
|
@ -0,0 +1,85 @@
|
||||
// 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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = 1;
|
||||
}, "abrupt completion from Number: 1");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = Math.pow(2, 63);
|
||||
}, "abrupt completion from Number: 2**63");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = +0;
|
||||
}, "abrupt completion from Number: +0");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = -0;
|
||||
}, "abrupt completion from Number: -0");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = Infinity;
|
||||
}, "abrupt completion from Number: Infinity");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = -Infinity;
|
||||
}, "abrupt completion from Number: -Infinity");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = NaN;
|
||||
}, "abrupt completion from Number: NaN");
|
||||
|
||||
});
|
@ -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 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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1);
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
typedArray[0] = "definately not a number";
|
||||
}, "StringToBigInt(prim) == NaN");
|
||||
|
||||
});
|
@ -0,0 +1,89 @@
|
||||
// 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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1);
|
||||
|
||||
typedArray[0] = '';
|
||||
assert.sameValue(typedArray[0], 0n);
|
||||
|
||||
typedArray[0] = '1';
|
||||
assert.sameValue(typedArray[0], 1n);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = '1n';
|
||||
}, "A StringNumericLiteral may not include a BigIntLiteralSuffix.");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = "Infinity";
|
||||
}, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity..");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = "1.1";
|
||||
}, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... decimal points...");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = "1e7";
|
||||
}, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... exponents...");
|
||||
|
||||
});
|
@ -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 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: [BigInt, TypedArray, Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol()
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1)
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = s;
|
||||
}, "abrupt completion from Symbol");
|
||||
|
||||
});
|
@ -0,0 +1,62 @@
|
||||
// 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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = undefined;
|
||||
}, "abrupt completion from undefined");
|
||||
|
||||
});
|
63
test/built-ins/TypedArrays/internals/Set/bigint-tonumber.js
Normal file
63
test/built-ins/TypedArrays/internals/Set/bigint-tonumber.js
Normal file
@ -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 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: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
var typedArray;
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
|
||||
typedArray = new TA(1);
|
||||
assert.throws(TypeError, function() {
|
||||
typedArray[0] = 1n;
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user