diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/DataView/prototype/getFloat16')
23 files changed, 641 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/browser.js diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..58d6f5547b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/detached-buffer-after-toindex-byteoffset.js @@ -0,0 +1,26 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +features: [Float16Array] +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(6); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.getFloat16(-1); +}); + +assert.throws(RangeError, function() { + sample.getFloat16(Infinity); +}, "Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..07c76080e1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/detached-buffer-before-outofrange-byteoffset.js @@ -0,0 +1,24 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Detached buffer is checked before out of range byteOffset's value +features: [Float16Array] +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getFloat16(13); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/detached-buffer.js new file mode 100644 index 0000000000..f7c59cb29c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/detached-buffer.js @@ -0,0 +1,21 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Throws a TypeError if buffer is detached +features: [Float16Array] +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getFloat16(0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/index-is-out-of-range.js new file mode 100644 index 0000000000..7781bde810 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/index-is-out-of-range.js @@ -0,0 +1,63 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +features: [Float16Array] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getFloat16(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getFloat16(13); +}, "13 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat16(12); +}, "12 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat16(11); +}, "11 + 2 > 12"); + +sample = new DataView(buffer, 10); +assert.throws(RangeError, function() { + sample.getFloat16(1); +}, "1 + 2 > 2 (offset)"); + +sample = new DataView(buffer, 11); +assert.throws(RangeError, function() { + sample.getFloat16(0); +}, "0 + 2 > 1 (offset)"); + +sample = new DataView(buffer, 0, 2); +assert.throws(RangeError, function() { + sample.getFloat16(1); +}, "1 + 2 > 2 (length)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.getFloat16(0); +}, "0 + 2 > 1 (length)"); + +sample = new DataView(buffer, 4, 2); +assert.throws(RangeError, function() { + sample.getFloat16(1); +}, "1 + 2 > 2 (offset+length)"); + +sample = new DataView(buffer, 4, 1); +assert.throws(RangeError, function() { + sample.getFloat16(0); +}, "0 + 2 > 1 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/length.js new file mode 100644 index 0000000000..bd71c6cbda --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/length.js @@ -0,0 +1,20 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + DataView.prototype.getFloat16.length is 1. +features: [Float16Array] +includes: [propertyHelper.js] +---*/ + +verifyProperty(DataView.prototype.getFloat16, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/minus-zero.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/minus-zero.js new file mode 100644 index 0000000000..2279538fd7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/minus-zero.js @@ -0,0 +1,21 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Return -0 +features: [Float16Array] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 128); +sample.setUint8(1, 0); + +var result = sample.getFloat16(0); +assert.sameValue(result, -0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/name.js new file mode 100644 index 0000000000..df100772a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/name.js @@ -0,0 +1,20 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + DataView.prototype.getFloat16.name is "getFloat16". +features: [Float16Array] +includes: [propertyHelper.js] +---*/ + +verifyProperty(DataView.prototype.getFloat16, "name", { + value: "getFloat16", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/negative-byteoffset-throws.js new file mode 100644 index 0000000000..ada6286fd5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/negative-byteoffset-throws.js @@ -0,0 +1,23 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Throws a RangeError if ToInteger(byteOffset) < 0 +features: [Float16Array] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getFloat16(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getFloat16(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/not-a-constructor.js new file mode 100644 index 0000000000..af811a5e30 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/not-a-constructor.js @@ -0,0 +1,24 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. 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.getFloat16 does not implement [[Construct]], is not new-able +includes: [isConstructor.js] +features: [Float16Array, Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getFloat16), + false, + 'isConstructor(DataView.prototype.getFloat16) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getFloat16(0, 0); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/resizable-buffer.js new file mode 100644 index 0000000000..ef1bbcdb4e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| shell-option(--enable-arraybuffer-resizable) shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- Float16Array,resizable-arraybuffer is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-dataview.prototype.getfloat16 +description: Throws a TypeError if buffer is out-of-bounds +features: [Float16Array, 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.getFloat16(0), 0, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getFloat16(0), 0, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getFloat16(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..1643b832b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-abrupt-from-tonumber-byteoffset-symbol.js @@ -0,0 +1,21 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Return abrupt from ToNumber(symbol byteOffset) +features: [Float16Array, Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getFloat16(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..1c5088df49 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,35 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Return abrupt from ToNumber(byteOffset) +features: [Float16Array] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getFloat16(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getFloat16(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-infinity.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-infinity.js new file mode 100644 index 0000000000..26c0fcecd8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-infinity.js @@ -0,0 +1,23 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Return Infinity values +features: [Float16Array, DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 124); // 0b01111100 +sample.setUint8(1, 0); +sample.setUint8(2, 252); // 0b11111100 +sample.setUint8(3, 0); + +assert.sameValue(sample.getFloat16(0), Infinity); +assert.sameValue(sample.getFloat16(2), -Infinity); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-nan.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-nan.js new file mode 100644 index 0000000000..56af38b203 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-nan.js @@ -0,0 +1,23 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Return NaN values +features: [Float16Array, DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 126); // 0b01111110 +sample.setUint8(1, 0); +sample.setUint8(2, 254); // 0b11111110 +sample.setUint8(3, 0); + +assert.sameValue(sample.getFloat16(0), NaN); +assert.sameValue(sample.getFloat16(2), NaN); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..bf8b2b0685 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-value-clean-arraybuffer.js @@ -0,0 +1,26 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Return value from Buffer using a clean ArrayBuffer +features: [Float16Array] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getFloat16(0, true), 0, "sample.getFloat16(0, true)"); +assert.sameValue(sample.getFloat16(1, true), 0, "sample.getFloat16(1, true)"); +assert.sameValue(sample.getFloat16(2, true), 0, "sample.getFloat16(2, true)"); +assert.sameValue(sample.getFloat16(3, true), 0, "sample.getFloat16(3, true)"); +assert.sameValue(sample.getFloat16(4, true), 0, "sample.getFloat16(4, true)"); +assert.sameValue(sample.getFloat16(0, false), 0, "sample.getFloat16(0, false)"); +assert.sameValue(sample.getFloat16(1, false), 0, "sample.getFloat16(1, false)"); +assert.sameValue(sample.getFloat16(2, false), 0, "sample.getFloat16(2, false)"); +assert.sameValue(sample.getFloat16(3, false), 0, "sample.getFloat16(3, false)"); +assert.sameValue(sample.getFloat16(4, false), 0, "sample.getFloat16(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-values-custom-offset.js new file mode 100644 index 0000000000..c121bd316c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-values-custom-offset.js @@ -0,0 +1,29 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Return values from Buffer using a custom offset +features: [Float16Array, DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(4, 75); // 01001011 +sample.setUint8(5, 75); // 01001011 +sample.setUint8(6, 76); // 01001100 +sample.setUint8(7, 77); // 01001101 + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getFloat16(0, false), 14.5859375, "0, false"); // 01001011 01001011 +assert.sameValue(sample.getFloat16(1, false), 14.59375, "1, false"); // 01001011 01001100 +assert.sameValue(sample.getFloat16(2, false), 17.203125, "2, false"); // 01001100 01001101 +assert.sameValue(sample.getFloat16(0, true), 14.5859375, "0, true"); // 01001011 01001011 +assert.sameValue(sample.getFloat16(1, true), 17.171875, "1, true"); // 01001100 01001011 +assert.sameValue(sample.getFloat16(2, true), 21.1875, "2, true"); // 01001101 01001100 + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-values.js new file mode 100644 index 0000000000..51b3b874cd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/return-values.js @@ -0,0 +1,40 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Return values from Buffer +features: [Float16Array, DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 66); // 01000010 +sample.setUint8(1, 40); // 00101000 +sample.setUint8(2, 64); // 01000000 +sample.setUint8(3, 224); // 11100000 + +assert.sameValue(sample.getFloat16(0, false), 3.078125, "0, false"); // 01000010 00101000 +assert.sameValue(sample.getFloat16(1, false), 0.033203125, "1, false"); // 00101000 01000000 +assert.sameValue(sample.getFloat16(2, false), 2.4375, "2, false"); // 01000000 11100000 + +assert.sameValue(sample.getFloat16(0, true), 0.03326416015625, "0, true"); // 00101000 01000010 +assert.sameValue(sample.getFloat16(1, true), 2.078125, "1, true"); // 01000000 00101000 +assert.sameValue(sample.getFloat16(2, true), -544, "2, true"); // 11100000 01000000 + +sample.setUint8(0, 75); // 01001011 +sample.setUint8(1, 75); // 01001011 +sample.setUint8(2, 76); // 01001100 +sample.setUint8(3, 76); // 01001101 + +assert.sameValue(sample.getFloat16(0, false), 14.5859375, "0, false"); // 01001011 01001011 +assert.sameValue(sample.getFloat16(1, false), 14.59375, "1, false"); // 01001011 01001100 +assert.sameValue(sample.getFloat16(2, false), 17.1875, "2, false"); // 01001100 01001101 +assert.sameValue(sample.getFloat16(0, true), 14.5859375, "0, true"); // 01001011 01001011 +assert.sameValue(sample.getFloat16(1, true), 17.171875, "1, true"); // 01001100 01001011 +assert.sameValue(sample.getFloat16(2, true), 17.1875, "2, true"); // 01001100 01001101 + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/shell.js diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..3b77b7f5b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/this-has-no-dataview-internal.js @@ -0,0 +1,32 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +features: [Float16Array, Int8Array] +---*/ + +var getFloat16 = DataView.prototype.getFloat16; + +assert.throws(TypeError, function() { + getFloat16.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getFloat16.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getFloat16.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getFloat16.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/this-is-not-object.js new file mode 100644 index 0000000000..917dc61dc8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/this-is-not-object.js @@ -0,0 +1,42 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: Throws a TypeError if this is not Object +features: [Float16Array, Symbol] +---*/ + +var getFloat16 = DataView.prototype.getFloat16; + +assert.throws(TypeError, function() { + getFloat16.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getFloat16.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getFloat16.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getFloat16.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getFloat16.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getFloat16.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getFloat16.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/to-boolean-littleendian.js new file mode 100644 index 0000000000..793f95477c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/to-boolean-littleendian.js @@ -0,0 +1,31 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat16 +description: > + Boolean littleEndian argument coerced in ToBoolean +features: [Float16Array, DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(2); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 75); +sample.setUint8(1, 76); + +// False +assert.sameValue(sample.getFloat16(0), 14.59375, "no arg"); +assert.sameValue(sample.getFloat16(0, undefined), 14.59375, "undefined"); +assert.sameValue(sample.getFloat16(0, null), 14.59375, "null"); +assert.sameValue(sample.getFloat16(0, 0), 14.59375, "0"); +assert.sameValue(sample.getFloat16(0, ""), 14.59375, "the empty string"); + +// True +assert.sameValue(sample.getFloat16(0, {}), 17.171875, "{}"); +assert.sameValue(sample.getFloat16(0, Symbol("1")), 17.171875, "symbol"); +assert.sameValue(sample.getFloat16(0, 1), 17.171875, "1"); +assert.sameValue(sample.getFloat16(0, "string"), 17.171875, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/toindex-byteoffset.js new file mode 100644 index 0000000000..ae51364d35 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/toindex-byteoffset.js @@ -0,0 +1,53 @@ +// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getFloat16 +description: > + ToIndex conversions on byteOffset +features: [Float16Array, DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(6); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 75); +sample.setUint8(1, 76); +sample.setUint8(2, 77); +sample.setUint8(3, 78); +sample.setUint8(4, 79); +sample.setUint8(5, 80); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 2; + } +}; + +assert.sameValue(sample.getFloat16(-0), 14.59375, "-0"); +assert.sameValue(sample.getFloat16(obj1), 25.234375, "object's valueOf"); +assert.sameValue(sample.getFloat16(obj2), 21.21875, "object's toString"); +assert.sameValue(sample.getFloat16(""), 14.59375, "the Empty string"); +assert.sameValue(sample.getFloat16("0"), 14.59375, "string '0'"); +assert.sameValue(sample.getFloat16("2"), 21.21875, "string '2'"); +assert.sameValue(sample.getFloat16(true), 17.203125, "true"); +assert.sameValue(sample.getFloat16(false), 14.59375, "false"); +assert.sameValue(sample.getFloat16(NaN), 14.59375, "NaN"); +assert.sameValue(sample.getFloat16(null), 14.59375, "null"); +assert.sameValue(sample.getFloat16(0.1), 14.59375, "0.1"); +assert.sameValue(sample.getFloat16(0.9), 14.59375, "0.9"); +assert.sameValue(sample.getFloat16(1.1), 17.203125, "1.1"); +assert.sameValue(sample.getFloat16(1.9), 17.203125, "1.9"); +assert.sameValue(sample.getFloat16(-0.1), 14.59375, "-0.1"); +assert.sameValue(sample.getFloat16(-0.99999), 14.59375, "-0.99999"); +assert.sameValue(sample.getFloat16(undefined), 14.59375, "undefined"); +assert.sameValue(sample.getFloat16(), 14.59375, "no arg"); + +reportCompare(0, 0); |