diff --git a/test/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-bigint-value.js b/test/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-bigint-value.js new file mode 100644 index 0000000000..7a96e21ca8 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-bigint-value.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Detached buffer is checked after ToBigInt(value) +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { valueOf() { throw new Test262Error(); } }; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setBigInt64(0, v); +}); diff --git a/test/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-toindex-byteoffset.js b/test/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..23e57b631a --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-toindex-byteoffset.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setBigInt64(Infinity, 0); +}, "DataView access at index Infinity should throw"); + +assert.throws(RangeError, function() { + sample.setBigInt64(-1, 0); +}, "DataView access at index -1 should throw"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/detached-buffer-before-outofrange-byteoffset.js b/test/built-ins/DataView/prototype/setBigInt64/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..a2a8044f48 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/detached-buffer-before-outofrange-byteoffset.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Detached buffer is checked before out of range byteOffset's value +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setBigInt64(13, 0); +}, "detached DataView access should throw"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/detached-buffer.js b/test/built-ins/DataView/prototype/setBigInt64/detached-buffer.js new file mode 100644 index 0000000000..3b25b94979 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/detached-buffer.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Throws a TypeError if buffer is detached +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setBigInt64(0, 0n); +}); diff --git a/test/built-ins/DataView/prototype/setBigInt64/index-check-before-value-conversion.js b/test/built-ins/DataView/prototype/setBigInt64/index-check-before-value-conversion.js new file mode 100644 index 0000000000..a092a47c3c --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/index-check-before-value-conversion.js @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + RangeError exception for negative or non-integral index is thrown before + the value conversion. +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf() { throw new Test262Error("valueOf called"); } +}; + +assert.throws(RangeError, function() { + dataView.setBigInt64(-1.5, poisoned); +}, "setBigInt64(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setBigInt64(-1, poisoned); +}, "setBigInt64(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setBigInt64(-Infinity, poisoned); +}, "setBigInt64(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setBigInt64(Infinity, poisoned); +}, "setBigInt64(Infinity, poisoned)"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/index-is-out-of-range.js b/test/built-ins/DataView/prototype/setBigInt64/index-is-out-of-range.js new file mode 100644 index 0000000000..17664246e7 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/index-is-out-of-range.js @@ -0,0 +1,88 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setBigInt64(Infinity, 39n); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setBigInt64(13, 39n); +}, "13 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(12, 39n); +}, "12 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(11, 39n); +}, "11 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(10, 39n); +}, "10 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(9, 39n); +}, "9 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(8, 39n); +}, "8 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(7, 39n); +}, "7 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(6, 39n); +}, "6 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(5, 39n); +}, "5 + 8 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.setBigInt64(1, 39n); +}, "1 + 8 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.setBigInt64(0, 39n); +}, "0 + 8 > 3 (offset)"); + +sample = new DataView(buffer, 0, 8); +assert.throws(RangeError, function() { + sample.setBigInt64(1, 39n); +}, "1 + 8 > 8 (length)"); + +sample = new DataView(buffer, 0, 7); +assert.throws(RangeError, function() { + sample.setBigInt64(0, 39n); +}, "0 + 8 > 7 (length)"); + +sample = new DataView(buffer, 4, 8); +assert.throws(RangeError, function() { + sample.setBigInt64(1, 39n); +}, "1 + 8 > 8 (offset+length)"); + +sample = new DataView(buffer, 4, 7); +assert.throws(RangeError, function() { + sample.setBigInt64(0, 39n); +}, "0 + 8 > 7 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getBigInt64(0), 0n, "[0] no value was set"); +assert.sameValue(sample.getBigInt64(4), 0n, "[1] no value was set"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/length.js b/test/built-ins/DataView/prototype/setBigInt64/length.js new file mode 100644 index 0000000000..ca9ecb24f6 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/length.js @@ -0,0 +1,16 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: DataView.prototype.setBigInt64.length property descriptor +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.setBigInt64, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/DataView/prototype/setBigInt64/name.js b/test/built-ins/DataView/prototype/setBigInt64/name.js new file mode 100644 index 0000000000..ec8b60504c --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/name.js @@ -0,0 +1,16 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: DataView.prototype.setBigInt64.name property descriptor +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.setBigInt64, "name", { + value: "setBigInt64", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/DataView/prototype/setBigInt64/negative-byteoffset-throws.js b/test/built-ins/DataView/prototype/setBigInt64/negative-byteoffset-throws.js new file mode 100644 index 0000000000..fcb35cf21f --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/negative-byteoffset-throws.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Throws a RangeError if getIndex < 0 +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setBigInt64(-1, 39n); +}, "DataView access at index -1 should throw"); +assert.sameValue(sample.getBigInt64(0), 0n, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setBigInt64(-Infinity, 39n); +}, "DataView access at index -Infinity should throw"); +assert.sameValue(sample.getBigInt64(0), 0n, "-Infinity - no value was set"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/no-value-arg.js b/test/built-ins/DataView/prototype/setBigInt64/no-value-arg.js new file mode 100644 index 0000000000..fc771348ac --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/no-value-arg.js @@ -0,0 +1,14 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Set value as undefined (cast to 0) when value argument is not present +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert.throws(TypeError, () => sample.setBigInt64(0)); diff --git a/test/built-ins/DataView/prototype/setBigInt64/range-check-after-value-conversion.js b/test/built-ins/DataView/prototype/setBigInt64/range-check-after-value-conversion.js new file mode 100644 index 0000000000..85e88974cc --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/range-check-after-value-conversion.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Index bounds checks are performed after value conversion. +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { valueOf() { throw new Test262Error(); } }; + +assert.throws(Test262Error, function() { + dataView.setBigInt64(100, poisoned); +}, "setBigInt64(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setBigInt64('100', poisoned); +}, "setBigInt64('100', poisoned)"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value-symbol.js b/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value-symbol.js new file mode 100644 index 0000000000..97ed821d5c --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value-symbol.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Return abrupt from ToBigInt(symbol value) +features: [DataView, ArrayBuffer, Symbol, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setBigInt64(0, s); +}); diff --git a/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value.js b/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value.js new file mode 100644 index 0000000000..0411fe56b0 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Return abrupt from ToBigInt(value) +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var bo1 = { valueOf() { throw new Test262Error(); } }; +var bo2 = { toString() { throw new Test262Error(); } }; + +assert.throws(Test262Error, function() { + sample.setBigInt64(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setBigInt64(0, bo2); +}, "toString"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js b/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..caddbafdb8 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Return abrupt from ToNumber(symbol byteOffset) +features: [DataView, ArrayBuffer, Symbol, BigInt] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setBigInt64(s, 1n); +}); diff --git a/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset.js b/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..c54224decf --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Return abrupt from ToNumber(byteOffset) +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { valueOf() { throw new Test262Error(); } }; +var bo2 = { toString() { throw new Test262Error(); } }; + +assert.throws(Test262Error, function() { + sample.setBigInt64(bo1, 1n); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setBigInt64(bo2, 1n); +}, "toString"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/set-values-little-endian-order.js b/test/built-ins/DataView/prototype/setBigInt64/set-values-little-endian-order.js new file mode 100644 index 0000000000..9edb9da5b3 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/set-values-little-endian-order.js @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Set values on the little endian order +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result; + +result = sample.setBigInt64(0, -0x6f80ff08n, true); +assert.sameValue(result, undefined, "returns undefined #1"); +assert.sameValue(sample.getBigInt64(0), -0x7ff806f00000001n); + +result = sample.setBigInt64(0, -0x7ff8070n, true); +assert.sameValue(result, undefined, "returns undefined #2"); +assert.sameValue(sample.getBigInt64(0), -0x6f80ff0700000001n); + +result = sample.setBigInt64(0, 0x6f80ff08n, true); +assert.sameValue(result, undefined, "returns undefined #3"); +assert.sameValue(sample.getBigInt64(0), 0x8ff806f00000000n); + +result = sample.setBigInt64(0, 0x8ff806fn, true); +assert.sameValue(result, undefined, "returns undefined #4"); +assert.sameValue(sample.getBigInt64(0), 0x6f80ff0800000000n); + +result = sample.setBigInt64(0, 0xf8007f90n, true); +assert.sameValue(result, undefined, "returns undefined #5"); +assert.sameValue(sample.getBigInt64(0), -0x6f80ff0800000000n); + +result = sample.setBigInt64(0, 0x907f00f8n, true); +assert.sameValue(result, undefined, "returns undefined #6"); +assert.sameValue(sample.getBigInt64(0), -0x7ff807000000000n); diff --git a/test/built-ins/DataView/prototype/setBigInt64/set-values-return-undefined.js b/test/built-ins/DataView/prototype/setBigInt64/set-values-return-undefined.js new file mode 100644 index 0000000000..a92ede6c69 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/set-values-return-undefined.js @@ -0,0 +1,43 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Set values and return undefined +includes: [byteConversionValues.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var values = byteConversionValues.values; + +values.forEach(function(value, i) { + if (value === undefined) { + assert.throws(TypeError, + () => sample.setBigInt64(0, BigInt(value), false), + "value: " + value); + return; + } else if (!Number.isInteger(value) || value > 9007199254740991) { + assert.throws(RangeError, + () => sample.setBigInt64(0, BigInt(value), false), + "value " + value); + return; + } + + var result = sample.setBigInt64(0, BigInt(value), false); + + assert.sameValue( + sample.getBigInt64(0), + BigInt(value), + "value: " + value + ); + + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); diff --git a/test/built-ins/DataView/prototype/setBigInt64/this-has-no-dataview-internal.js b/test/built-ins/DataView/prototype/setBigInt64/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..fe9a4b4859 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/this-has-no-dataview-internal.js @@ -0,0 +1,29 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var setBigInt64 = DataView.prototype.setBigInt64; + +assert.throws(TypeError, function() { + setBigInt64.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setBigInt64.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setBigInt64.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setBigInt64.call(ta); +}, "TypedArray"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/this-is-not-object.js b/test/built-ins/DataView/prototype/setBigInt64/this-is-not-object.js new file mode 100644 index 0000000000..0e4e401bc5 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/this-is-not-object.js @@ -0,0 +1,39 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: Throws a TypeError if this is not Object +features: [DataView, ArrayBuffer, Symbol, BigInt] +---*/ + +var setBigInt64 = DataView.prototype.setBigInt64; + +assert.throws(TypeError, function() { + setBigInt64.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setBigInt64.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setBigInt64.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setBigInt64.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setBigInt64.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setBigInt64.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setBigInt64.call(s); +}, "symbol"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/to-boolean-littleendian.js b/test/built-ins/DataView/prototype/setBigInt64/to-boolean-littleendian.js new file mode 100644 index 0000000000..760dd8f625 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/to-boolean-littleendian.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Boolean littleEndian argument coerced in ToBoolean +features: [DataView, ArrayBuffer, Symbol, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +// False +sample.setBigInt64(0, 1n); +assert.sameValue(sample.getBigInt64(0), 1n, "no arg"); +sample.setBigInt64(0, 2n, undefined); +assert.sameValue(sample.getBigInt64(0), 2n, "undefined"); +sample.setBigInt64(0, 3n, null); +assert.sameValue(sample.getBigInt64(0), 3n, "null"); +sample.setBigInt64(0, 4n, 0); +assert.sameValue(sample.getBigInt64(0), 4n, "0"); +sample.setBigInt64(0, 5n, ""); +assert.sameValue(sample.getBigInt64(0), 5n, "the empty string"); + +// True +sample.setBigInt64(0, 6n, {}); +assert.sameValue(sample.getBigInt64(0), 0x600000000000000n, "{}"); +sample.setBigInt64(0, 7n, Symbol("1")); +assert.sameValue(sample.getBigInt64(0), 0x700000000000000n, "symbol"); +sample.setBigInt64(0, 8n, 1); +assert.sameValue(sample.getBigInt64(0), 0x800000000000000n, "1"); +sample.setBigInt64(0, 9n, "string"); +assert.sameValue(sample.getBigInt64(0), 0x900000000000000n, "string"); diff --git a/test/built-ins/DataView/prototype/setBigInt64/toindex-byteoffset.js b/test/built-ins/DataView/prototype/setBigInt64/toindex-byteoffset.js new file mode 100644 index 0000000000..a55f905ae3 --- /dev/null +++ b/test/built-ins/DataView/prototype/setBigInt64/toindex-byteoffset.js @@ -0,0 +1,83 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + ToIndex conversions on byteOffset +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +var obj1 = { valueOf() { return 3; } }; +var obj2 = { toString() { return 4; } }; + +sample.setBigInt64(0, 0n); +sample.setBigInt64(-0, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "-0"); + +sample.setBigInt64(3, 0n); +sample.setBigInt64(obj1, 42n); +assert.sameValue(sample.getBigInt64(3), 42n, "object's valueOf"); + +sample.setBigInt64(4, 0n); +sample.setBigInt64(obj2, 42n); +assert.sameValue(sample.getBigInt64(4), 42n, "object's toString"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64("", 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "the Empty string"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64("0", 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "string '0'"); + +sample.setBigInt64(2, 0n); +sample.setBigInt64("2", 42n); +assert.sameValue(sample.getBigInt64(2), 42n, "string '2'"); + +sample.setBigInt64(1, 0n); +sample.setBigInt64(true, 42n); +assert.sameValue(sample.getBigInt64(1), 42n, "true"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(false, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "false"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(NaN, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "NaN"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(null, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "null"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(0.1, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "0.1"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(0.9, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "0.9"); + +sample.setBigInt64(1, 0n); +sample.setBigInt64(1.1, 42n); +assert.sameValue(sample.getBigInt64(1), 42n, "1.1"); + +sample.setBigInt64(1, 0n); +sample.setBigInt64(1.9, 42n); +assert.sameValue(sample.getBigInt64(1), 42n, "1.9"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(-0.1, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "-0.1"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(-0.99999, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "-0.99999"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(undefined, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "undefined");