summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js')
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js
new file mode 100644
index 0000000000..c649f8db07
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js
@@ -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: 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: [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");
+
+reportCompare(0, 0);