diff options
Diffstat (limited to '')
23 files changed, 1274 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/browser.js diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..d5d1a51f92 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-after-toindex-byteoffset.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.getbigint64 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, () => sample.getBigInt64(Infinity), + "DataView access at index Infinity should throw"); + +assert.throws(RangeError, () => sample.getBigInt64(-1), + "DataView access at index -1 should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..b74a9e54ea --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-before-outofrange-byteoffset.js @@ -0,0 +1,37 @@ +// 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.getbigint64 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.8 DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, () => sample.getBigInt64(13), + "detached DataView access should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer.js new file mode 100644 index 0000000000..697b6b181e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer.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.getbigint64 +description: > + Throws a TypeError if buffer is detached +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, () => sample.getBigInt64(0), + "detached DataView access should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/index-is-out-of-range.js new file mode 100644 index 0000000000..bd03fe7962 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/index-is-out-of-range.js @@ -0,0 +1,77 @@ +// 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.getbigint64 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, () => sample.getBigInt64(Infinity), + "DataView access at index Infinity should throw"); + +assert.throws(RangeError, () => sample.getBigInt64(13), "13 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(12), "12 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(11), "11 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(10), "10 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(9), "9 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(8), "8 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(7), "7 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(6), "6 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(5), "5 + 8 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, () => sample.getBigInt64(1), + "1 + 8 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, () => sample.getBigInt64(0), + "0 + 8 > 3 (offset)"); + +sample = new DataView(buffer, 0, 8); +assert.throws(RangeError, () => sample.getBigInt64(1), + "1 + 8 > 8 (length)"); + +sample = new DataView(buffer, 0, 7); +assert.throws(RangeError, () => sample.getBigInt64(0), + "0 + 8 > 7 (length)"); + +sample = new DataView(buffer, 4, 8); +assert.throws(RangeError, () => sample.getBigInt64(1), + "1 + 8 > 8 (offset+length)"); + +sample = new DataView(buffer, 4, 7); +assert.throws(RangeError, () => sample.getBigInt64(0), + "0 + 8 > 7 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/length.js new file mode 100644 index 0000000000..f45bdc5f25 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/length.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.getbigint64 +description: DataView.prototype.getBigInt64.length property descriptor +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in + function object has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.getBigInt64, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/name.js new file mode 100644 index 0000000000..9d6b4253aa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/name.js @@ -0,0 +1,33 @@ +// 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.getbigint64 +description: DataView.prototype.getBigInt64.name property descriptor +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. Unless otherwise specified, this value is the name that + is given to the function in this specification. For functions that + are specified as properties of objects, the name value is the + property name string used to access the function. [...] + + Unless otherwise specified, the name property of a built-in function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.getBigInt64, "name", { + value: "getBigInt64", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/negative-byteoffset-throws.js new file mode 100644 index 0000000000..7f15464f69 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/negative-byteoffset-throws.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.getbigint64 +description: > + Throws a RangeError if getIndex < 0 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, () => sample.getBigInt64(-1), + "DataView access at index -1 should throw"); + +assert.throws(RangeError, () => sample.getBigInt64(-Infinity), + "DataView access at index -Infinity should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/not-a-constructor.js new file mode 100644 index 0000000000..20cb228a77 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getBigInt64 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, BigInt, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getBigInt64), + false, + 'isConstructor(DataView.prototype.getBigInt64) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getBigInt64(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getBigInt64(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/resizable-buffer.js new file mode 100644 index 0000000000..ac4b57792d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-dataview.prototype.getbigint64 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getBigInt64(0), 0n, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getBigInt64(0), 0n, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getBigInt64(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..c14c271245 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js @@ -0,0 +1,30 @@ +// 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.getbigint64 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToNumber(requestIndex). + ... +features: [DataView, ArrayBuffer, Symbol, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, () => sample.getBigInt64(s)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..4ce2b32f1e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,41 @@ +// 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.getbigint64 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToNumber(requestIndex). + ... +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +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, () => sample.getBigInt64(bo1), "valueOf"); + +assert.throws(Test262Error, () => sample.getBigInt64(bo2), "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..2fabb4edce --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-value-clean-arraybuffer.js @@ -0,0 +1,50 @@ +// 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.getbigint64 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 12. Let bufferIndex be getIndex + viewOffset. + 13. Return GetValueFromBuffer(buffer, bufferIndex, type, false, + "Unordered", isLittleEndian). + + 24.1.1.6 GetValueFromBuffer ( arrayBuffer, byteIndex, type, + isTypedArray, order [ , isLittleEndian ] ) + + ... + 9. Return RawBytesToNumber(type, rawValue, isLittleEndian). + + 24.1.1.5 RawBytesToNumber( type, rawBytes, isLittleEndian ) + + ... + 2. If isLittleEndian is false, reverse the order of the elements of rawBytes. + ... +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getBigInt64(0, true), 0n, "sample.getBigInt64(0, true)"); +assert.sameValue(sample.getBigInt64(1, true), 0n, "sample.getBigInt64(1, true)"); +assert.sameValue(sample.getBigInt64(2, true), 0n, "sample.getBigInt64(2, true)"); +assert.sameValue(sample.getBigInt64(3, true), 0n, "sample.getBigInt64(3, true)"); +assert.sameValue(sample.getBigInt64(4, true), 0n, "sample.getBigInt64(4, true)"); +assert.sameValue(sample.getBigInt64(0, false), 0n, "sample.getBigInt64(0, false)"); +assert.sameValue(sample.getBigInt64(1, false), 0n, "sample.getBigInt64(1, false)"); +assert.sameValue(sample.getBigInt64(2, false), 0n, "sample.getBigInt64(2, false)"); +assert.sameValue(sample.getBigInt64(3, false), 0n, "sample.getBigInt64(3, false)"); +assert.sameValue(sample.getBigInt64(4, false), 0n, "sample.getBigInt64(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values-custom-offset.js new file mode 100644 index 0000000000..aaefaca0ff --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values-custom-offset.js @@ -0,0 +1,70 @@ +// 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.getbigint64 +description: > + Return values from Buffer using a custom offset +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 12. Let bufferIndex be getIndex + viewOffset. + 13. Return GetValueFromBuffer(buffer, bufferIndex, type, false, + "Unordered", isLittleEndian). + + 24.1.1.6 GetValueFromBuffer ( arrayBuffer, byteIndex, type, + isTypedArray, order [ , isLittleEndian ] ) + + ... + 9. Return RawBytesToNumber(type, rawValue, isLittleEndian). + + 24.1.1.5 RawBytesToNumber( type, rawBytes, isLittleEndian ) + + ... + 2. If isLittleEndian is false, reverse the order of the elements of rawBytes. + ... +features: [DataView, ArrayBuffer, DataView.prototype.setUint8, BigInt] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); +sample.setUint8(12, 0x80); +sample.setUint8(13, 0x7f); +sample.setUint8(14, 0xff); +sample.setUint8(15, 0x80); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getBigInt64(0, false), -0x7fff7ffe80fffefen, "0, false"); +assert.sameValue(sample.getBigInt64(1, false), 0x80017f00010280n, "1, false"); +assert.sameValue(sample.getBigInt64(2, false), -0x7ffe80fffefd7f81n, "2, false"); +assert.sameValue(sample.getBigInt64(3, false), 0x17f000102807fffn, "3, false"); +assert.sameValue(sample.getBigInt64(4, false), 0x7f000102807fff80n, "4, false"); + +assert.sameValue(sample.getBigInt64(0, true), 0x201007f01800080n, "0, true"); +assert.sameValue(sample.getBigInt64(1, true), -0x7ffdfeff80fe8000n, "1, true"); +assert.sameValue(sample.getBigInt64(2, true), 0x7f800201007f0180n, "2, true"); +assert.sameValue(sample.getBigInt64(3, true), -0x807ffdfeff80ffn, "3, true"); +assert.sameValue(sample.getBigInt64(4, true), -0x7f00807ffdfeff81n, "4, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values.js new file mode 100644 index 0000000000..3a86cee604 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values.js @@ -0,0 +1,71 @@ +// 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.getbigint64 +description: > + Return values from Buffer +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.6 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView, ArrayBuffer, DataView.prototype.setUint8, BigInt] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); +sample.setUint8(12, 0x80); +sample.setUint8(13, 0x7f); +sample.setUint8(14, 0xff); +sample.setUint8(15, 0x80); + +assert.sameValue(sample.getBigInt64(0, false), 0x2702060280008001n, "0, false"); +assert.sameValue(sample.getBigInt64(1, false), 0x20602800080017fn, "1, false"); +assert.sameValue(sample.getBigInt64(2, false), 0x602800080017f00n, "2, false"); +assert.sameValue(sample.getBigInt64(3, false), 0x2800080017f0001n, "3, false"); +assert.sameValue(sample.getBigInt64(4, false), -0x7fff7ffe80fffefen, "4, false"); +assert.sameValue(sample.getBigInt64(5, false), 0x80017f00010280n, "5, false"); +assert.sameValue(sample.getBigInt64(6, false), -0x7ffe80fffefd7f81n, "6, false"); +assert.sameValue(sample.getBigInt64(7, false), 0x17f000102807fffn, "7, false"); +assert.sameValue(sample.getBigInt64(8, false), 0x7f000102807fff80n, "8, false"); + +assert.sameValue(sample.getBigInt64(0, true), 0x180008002060227n, "0, true"); +assert.sameValue(sample.getBigInt64(1, true), 0x7f01800080020602n, "1, true"); +assert.sameValue(sample.getBigInt64(2, true), 0x7f018000800206n, "2, true"); +assert.sameValue(sample.getBigInt64(3, true), 0x1007f0180008002n, "3, true"); +assert.sameValue(sample.getBigInt64(4, true), 0x201007f01800080n, "4, true"); +assert.sameValue(sample.getBigInt64(5, true), -0x7ffdfeff80fe8000n, "5, true"); +assert.sameValue(sample.getBigInt64(6, true), 0x7f800201007f0180n, "6, true"); +assert.sameValue(sample.getBigInt64(7, true), -0x807ffdfeff80ffn, "7, true"); +assert.sameValue(sample.getBigInt64(8, true), -0x7f00807ffdfeff81n, "8, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/shell.js diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..cc7dfd497e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-has-no-dataview-internal.js @@ -0,0 +1,36 @@ +// 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.getbigint64 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [DataView, ArrayBuffer, Int8Array, BigInt, arrow-function] +---*/ + +var getBigInt64 = DataView.prototype.getBigInt64; + +assert.throws(TypeError, () => getBigInt64.call({}), "{}"); + +assert.throws(TypeError, () => getBigInt64.call([]), "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, () => getBigInt64.call(ab), "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, () => getBigInt64.call(ta), "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-is-not-object.js new file mode 100644 index 0000000000..a4d2f6007b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/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.getbigint64 +description: Throws a TypeError if this is not Object +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [DataView, ArrayBuffer, Symbol, BigInt, arrow-function] +---*/ + +var getBigInt64 = DataView.prototype.getBigInt64; + +assert.throws(TypeError, () => getBigInt64.call(undefined), + "undefined"); + +assert.throws(TypeError, () => getBigInt64.call(null), "null"); + +assert.throws(TypeError, () => getBigInt64.call(1), "1"); + +assert.throws(TypeError, () => getBigInt64.call("string"), "string"); + +assert.throws(TypeError, () => getBigInt64.call(true), "true"); + +assert.throws(TypeError, () => getBigInt64.call(false), "false"); + +var s = Symbol("1"); +assert.throws(TypeError, () => getBigInt64.call(s), "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/to-boolean-littleendian.js new file mode 100644 index 0000000000..7c86c4fc38 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/to-boolean-littleendian.js @@ -0,0 +1,69 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Boolean littleEndian argument coerced in ToBoolean +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 5. Set isLittleEndian to ToBoolean(isLittleEndian). + ... + 12. Let bufferIndex be getIndex + viewOffset. + 13. Return GetValueFromBuffer(buffer, bufferIndex, type, false, + "Unordered", isLittleEndian). + + 24.1.1.6 GetValueFromBuffer ( arrayBuffer, byteIndex, type, + isTypedArray, order [ , isLittleEndian ] ) + + ... + 9. Return RawBytesToNumber(type, rawValue, isLittleEndian). + + 24.1.1.5 RawBytesToNumber( type, rawBytes, isLittleEndian ) + + ... + 2. If isLittleEndian is false, reverse the order of the elements of rawBytes. + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); +sample.setUint8(7, 0xff); +assert.sameValue(sample.getBigInt64(0), 0xffn, "no argument"); + +assert.sameValue(sample.getBigInt64(0, false), 0xffn); +assert.sameValue(sample.getBigInt64(0, true), -0x100000000000000n); +assert.sameValue(sample.getBigInt64(0, 0), 0xffn, "ToBoolean: 0 => false"); +assert.sameValue(sample.getBigInt64(0, -0), 0xffn, "ToBoolean: -0 => false"); +assert.sameValue(sample.getBigInt64(0, 1), -0x100000000000000n, "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigInt64(0, -1), -0x100000000000000n, "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigInt64(0, 0.1), -0x100000000000000n, "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigInt64(0, Infinity), -0x100000000000000n, + "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigInt64(0, NaN), 0xffn, "ToBoolean: NaN => false"); +assert.sameValue(sample.getBigInt64(0, undefined), 0xffn, "ToBoolean: undefined => false"); +assert.sameValue(sample.getBigInt64(0, null), 0xffn, "ToBoolean: null => false"); +assert.sameValue(sample.getBigInt64(0, ""), 0xffn, "ToBoolean: String .length == 0 => false"); +assert.sameValue(sample.getBigInt64(0, "string"), -0x100000000000000n, + "ToBoolean: String .length > 0 => true"); +assert.sameValue(sample.getBigInt64(0, "false"), -0x100000000000000n, + "ToBoolean: String .length > 0 => true"); +assert.sameValue(sample.getBigInt64(0, " "), -0x100000000000000n, + "ToBoolean: String .length > 0 => true"); +assert.sameValue(sample.getBigInt64(0, Symbol("1")), -0x100000000000000n, + "ToBoolean: Symbol => true"); +assert.sameValue(sample.getBigInt64(0, 0n), 0xffn, "ToBoolean: 0n => false"); +assert.sameValue(sample.getBigInt64(0, 1n), -0x100000000000000n, "ToBoolean: BigInt != 0n => true"); +assert.sameValue(sample.getBigInt64(0, []), -0x100000000000000n, "ToBoolean: any object => true"); +assert.sameValue(sample.getBigInt64(0, {}), -0x100000000000000n, "ToBoolean: any object => true"); +assert.sameValue(sample.getBigInt64(0, Object(false)), -0x100000000000000n, + "ToBoolean: any object => true; no ToPrimitive"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-errors.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-errors.js new file mode 100644 index 0000000000..3161d42157 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-errors.js @@ -0,0 +1,109 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol, Symbol.toPrimitive, computed-property-names] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +assert.throws(RangeError, function() { + sample.getBigInt64(-1); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigInt64(-2.5); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigInt64("-2.5"); +}, "ToIndex: parse Number => throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigInt64(-Infinity); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigInt64(9007199254740992); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(RangeError, function() { + sample.getBigInt64(Infinity); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(TypeError, function() { + sample.getBigInt64(0n); +}, "ToIndex: BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64(Object(0n)); +}, "ToIndex: unbox object with internal slot => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return 0n; + } + }); +}, "ToIndex: @@toPrimitive => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: function() { + return 0n; + } + }); +}, "ToIndex: valueOf => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + toString: function() { + return 0n; + } + }); +}, "ToIndex: toString => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64(Symbol("1")); +}, "ToIndex: Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64(Object(Symbol("1"))); +}, "ToIndex: unbox object with internal slot => Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return Symbol("1"); + } + }); +}, "ToIndex: @@toPrimitive => Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: function() { + return Symbol("1"); + } + }); +}, "ToIndex: valueOf => Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + toString: function() { + return Symbol("1"); + } + }); +}, "ToIndex: toString => Symbol => TypeError"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-toprimitive.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-toprimitive.js new file mode 100644 index 0000000000..8e9aa91906 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-toprimitive.js @@ -0,0 +1,190 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol.toPrimitive, computed-property-names] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return 1; + }, + valueOf: err, + toString: err +}), 0x20602800080017fn, "ToPrimitive: @@toPrimitive takes precedence"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return 1; + }, + toString: err +}), 0x20602800080017fn, "ToPrimitive: valueOf takes precedence over toString"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: toString with no valueOf"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: undefined, + valueOf: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip @@toPrimitive when it's undefined"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: null, + valueOf: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip @@toPrimitive when it's null"); +assert.sameValue(sample.getBigInt64({ + valueOf: null, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(sample.getBigInt64({ + valueOf: 1, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(sample.getBigInt64({ + valueOf: {}, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return {}; + }, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it returns an object"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return Object(12345); + }, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it returns an object"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: 1 + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: {} + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return {}; + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(MyError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from @@toPrimitive"); +assert.throws(MyError, function() { + sample.getBigInt64({ + valueOf: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from valueOf"); +assert.throws(MyError, function() { + sample.getBigInt64({ + toString: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: null, + toString: null + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: 1, + toString: 1 + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: {}, + toString: {} + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: function() { + return Object(1); + }, + toString: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-wrapped-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-wrapped-values.js new file mode 100644 index 0000000000..3531b14a11 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-wrapped-values.js @@ -0,0 +1,135 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol.toPrimitive, computed-property-names] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +assert.sameValue(sample.getBigInt64(Object(0)), 0x2702060280008001n, + "ToPrimitive: unbox object with internal slot"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return 0; + } +}), 0x2702060280008001n, "ToPrimitive: @@toPrimitive"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return 0; + } +}), 0x2702060280008001n, "ToPrimitive: valueOf"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return 0; + } +}), 0x2702060280008001n, "ToPrimitive: toString"); +assert.sameValue(sample.getBigInt64(Object(NaN)), 0x2702060280008001n, + "ToIndex: unbox object with internal slot => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return NaN; + } +}), 0x2702060280008001n, "ToIndex: @@toPrimitive => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return NaN; + } +}), 0x2702060280008001n, "ToIndex: valueOf => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return NaN; + } +}), 0x2702060280008001n, "ToIndex: toString => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return undefined; + } +}), 0x2702060280008001n, "ToIndex: @@toPrimitive => undefined => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return undefined; + } +}), 0x2702060280008001n, "ToIndex: valueOf => undefined => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return undefined; + } +}), 0x2702060280008001n, "ToIndex: toString => undefined => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return null; + } +}), 0x2702060280008001n, "ToIndex: @@toPrimitive => null => 0"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return null; + } +}), 0x2702060280008001n, "ToIndex: valueOf => null => 0"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return null; + } +}), 0x2702060280008001n, "ToIndex: toString => null => 0"); +assert.sameValue(sample.getBigInt64(Object(true)), 0x20602800080017fn, + "ToIndex: unbox object with internal slot => true => 1"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return true; + } +}), 0x20602800080017fn, "ToIndex: @@toPrimitive => true => 1"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return true; + } +}), 0x20602800080017fn, "ToIndex: valueOf => true => 1"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return true; + } +}), 0x20602800080017fn, "ToIndex: toString => true => 1"); +assert.sameValue(sample.getBigInt64(Object("1")), 0x20602800080017fn, + "ToIndex: unbox object with internal slot => parse Number"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return "1"; + } +}), 0x20602800080017fn, "ToIndex: @@toPrimitive => parse Number"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return "1"; + } +}), 0x20602800080017fn, "ToIndex: valueOf => parse Number"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return "1"; + } +}), 0x20602800080017fn, "ToIndex: toString => parse Number"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset.js new file mode 100644 index 0000000000..99df43ec2c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset.js @@ -0,0 +1,72 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +assert.sameValue(sample.getBigInt64(0), 0x2702060280008001n); +assert.sameValue(sample.getBigInt64(1), 0x20602800080017fn); +assert.sameValue(sample.getBigInt64(-0.9), 0x2702060280008001n, "ToIndex: truncate towards 0"); +assert.sameValue(sample.getBigInt64(0.9), 0x2702060280008001n, "ToIndex: truncate towards 0"); +assert.sameValue(sample.getBigInt64(NaN), 0x2702060280008001n, "ToIndex: NaN => 0"); +assert.sameValue(sample.getBigInt64(undefined), 0x2702060280008001n, + "ToIndex: undefined => NaN => 0"); +assert.sameValue(sample.getBigInt64(null), 0x2702060280008001n, "ToIndex: null => 0"); +assert.sameValue(sample.getBigInt64(false), 0x2702060280008001n, "ToIndex: false => 0"); +assert.sameValue(sample.getBigInt64(true), 0x20602800080017fn, "ToIndex: true => 1"); +assert.sameValue(sample.getBigInt64("0"), 0x2702060280008001n, "ToIndex: parse Number"); +assert.sameValue(sample.getBigInt64("1"), 0x20602800080017fn, "ToIndex: parse Number"); +assert.sameValue(sample.getBigInt64(""), 0x2702060280008001n, "ToIndex: parse Number => NaN => 0"); +assert.sameValue(sample.getBigInt64("foo"), 0x2702060280008001n, + "ToIndex: parse Number => NaN => 0"); +assert.sameValue(sample.getBigInt64("true"), 0x2702060280008001n, + "ToIndex: parse Number => NaN => 0"); +assert.sameValue(sample.getBigInt64(2), 0x602800080017F00n); +assert.sameValue(sample.getBigInt64("2"), 0x602800080017F00n, "toIndex: parse Number"); +assert.sameValue(sample.getBigInt64(2.9), 0x602800080017F00n, "toIndex: truncate towards 0"); +assert.sameValue(sample.getBigInt64("2.9"), 0x602800080017F00n, + "toIndex: parse Number => truncate towards 0"); +assert.sameValue(sample.getBigInt64(3), 0x2800080017F0001n); +assert.sameValue(sample.getBigInt64("3"), 0x2800080017F0001n, "toIndex: parse Number"); +assert.sameValue(sample.getBigInt64(3.9), 0x2800080017F0001n, "toIndex: truncate towards 0"); +assert.sameValue(sample.getBigInt64("3.9"), 0x2800080017F0001n, + "toIndex: parse Number => truncate towards 0"); +assert.sameValue(sample.getBigInt64([0]), 0x2702060280008001n, + 'ToIndex: [0].toString() => "0" => 0'); +assert.sameValue(sample.getBigInt64(["1"]), 0x20602800080017fn, + 'ToIndex: ["1"].toString() => "1" => 1'); +assert.sameValue(sample.getBigInt64({}), 0x2702060280008001n, + 'ToIndex: ({}).toString() => "[object Object]" => NaN => 0'); +assert.sameValue(sample.getBigInt64([]), 0x2702060280008001n, + 'ToIndex: [].toString() => "" => NaN => 0'); + +reportCompare(0, 0); |