diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /js/src/tests/test262/built-ins/DataView/prototype/setFloat16 | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/DataView/prototype/setFloat16')
25 files changed, 769 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/browser.js diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/detached-buffer-after-number-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/detached-buffer-after-number-value.js new file mode 100644 index 0000000000..7978099dcd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/detached-buffer-after-number-value.js @@ -0,0 +1,27 @@ +// |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.setfloat16 +description: > + Detached buffer is checked after ToNumber(value) +features: [Float16Array] +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf: function() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setFloat16(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..864850f787 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +features: [Float16Array] +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setFloat16(Infinity, 0); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.setFloat16(-1, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..1d9d289e63 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +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.setFloat16(13, 0); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/detached-buffer.js new file mode 100644 index 0000000000..11e71b7cb8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +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.setFloat16(0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/index-check-before-value-conversion.js new file mode 100644 index 0000000000..e1b2b18b35 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/index-check-before-value-conversion.js @@ -0,0 +1,36 @@ +// |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.setfloat16 +description: > + RangeError exception for negative index is thrown before the value conversion. +features: [Float16Array] +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setFloat16(-1.5, poisoned); +}, "setFloat16(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setFloat16(-1, poisoned); +}, "setFloat16(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setFloat16(-Infinity, poisoned); +}, "setFloat16(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setFloat16(Infinity, poisoned); +}, "setFloat16(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/index-is-out-of-range.js new file mode 100644 index 0000000000..11f0e02a03 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/index-is-out-of-range.js @@ -0,0 +1,71 @@ +// |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.setfloat16 +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.setFloat16(Infinity, 39); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setFloat16(13, 39); +}, "13 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat16(12, 39); +}, "12 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat16(11, 39); +}, "11 + 2 > 12"); + +sample = new DataView(buffer, 10); +assert.throws(RangeError, function() { + sample.setFloat16(1, 39); +}, "1 + 2 > 2 (offset)"); + +sample = new DataView(buffer, 11); +assert.throws(RangeError, function() { + sample.setFloat16(0, 39); +}, "0 + 2 > 1 (offset)"); + +sample = new DataView(buffer, 0, 2); +assert.throws(RangeError, function() { + sample.setFloat16(1, 39); +}, "1 + 2 > 2 (length)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.setFloat16(0, 39); +}, "0 + 2 > 1 (length)"); + +sample = new DataView(buffer, 4, 2); +assert.throws(RangeError, function() { + sample.setFloat16(1, 39); +}, "1 + 2 > 2 (offset+length)"); + +sample = new DataView(buffer, 4, 1); +assert.throws(RangeError, function() { + sample.setFloat16(0, 39); +}, "0 + 2 > 1 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getFloat16(0), 0, "[0] no value was set"); +assert.sameValue(sample.getFloat16(2), 0, "[1] no value was set"); +assert.sameValue(sample.getFloat16(4), 0, "[2] no value was set"); +assert.sameValue(sample.getFloat16(6), 0, "[3] no value was set"); +assert.sameValue(sample.getFloat16(8), 0, "[4] no value was set"); +assert.sameValue(sample.getFloat16(10), 0, "[5] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/length.js new file mode 100644 index 0000000000..d6e2809511 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +description: > + DataView.prototype.setFloat16.length is 2. +features: [Float16Array] +includes: [propertyHelper.js] +---*/ + +verifyProperty(DataView.prototype.setFloat16, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/name.js new file mode 100644 index 0000000000..41ef3bb195 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +description: > + DataView.prototype.setFloat16.name is "setFloat16". +features: [Float16Array] +includes: [propertyHelper.js] +---*/ + +verifyProperty(DataView.prototype.setFloat16, "name", { + value: "setFloat16", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/negative-byteoffset-throws.js new file mode 100644 index 0000000000..84722723ad --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/negative-byteoffset-throws.js @@ -0,0 +1,25 @@ +// |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.setfloat16 +description: > + Throws a RangeError if getIndex < 0 +features: [Float16Array] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setFloat16(-1, 39); +}, "-1"); +assert.sameValue(sample.getFloat32(0), 0, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setFloat16(-Infinity, 39); +}, "-Infinity"); +assert.sameValue(sample.getFloat32(0), 0, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/no-value-arg.js new file mode 100644 index 0000000000..75f634b0a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/no-value-arg.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.setfloat16 +description: > + Set value as undefined (cast to NaN) when value argument is not present +features: [Float16Array] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result = sample.setFloat16(0); + +assert.sameValue(sample.getFloat16(0), NaN); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/not-a-constructor.js new file mode 100644 index 0000000000..549f33ba39 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setFloat16 does not implement [[Construct]], is not new-able +includes: [isConstructor.js] +features: [Float16Array, Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setFloat16), + false, + 'isConstructor(DataView.prototype.setFloat16) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setFloat16(0, 0); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/range-check-after-value-conversion.js new file mode 100644 index 0000000000..04e87fc18c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/range-check-after-value-conversion.js @@ -0,0 +1,28 @@ +// |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.setFloat16 +description: > + Index bounds checks are performed after value conversion. +features: [Float16Array] +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setFloat16(100, poisoned); +}, "setFloat16(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setFloat16('100', poisoned); +}, "setFloat16('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/resizable-buffer.js new file mode 100644 index 0000000000..17b09d9b13 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +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.setFloat16(0, 10), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setFloat16(0, 20), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setFloat16(0, 30); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..d56fea3aa5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +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.setFloat16(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..4c70428fc1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +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.setFloat16(bo1, 1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setFloat16(bo2, 1); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-value-symbol.js new file mode 100644 index 0000000000..01639d1e10 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-value-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.setfloat16 +description: > + Return abrupt from ToNumber(symbol value) +features: [Float16Array, Symbol] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setFloat16(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-value.js new file mode 100644 index 0000000000..802757cffc --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/return-abrupt-from-tonumber-value.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.setfloat16 +description: > + Return abrupt from ToNumber(value) +features: [Float16Array] +---*/ + +var buffer = new ArrayBuffer(4); +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.setFloat16(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setFloat16(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/set-values-little-endian-order.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/set-values-little-endian-order.js new file mode 100644 index 0000000000..dcbdd57594 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/set-values-little-endian-order.js @@ -0,0 +1,25 @@ +// |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.setfloat16 +description: > + Set values with little endian order. +features: [Float16Array] +---*/ + +var buffer = new ArrayBuffer(2); +var sample = new DataView(buffer, 0); + +var result; + +result = sample.setFloat16(0, 42, true); // 01010001 01000000 +assert.sameValue(result, undefined, "returns undefined #1"); +assert.sameValue(sample.getFloat16(0), 2.158203125); // 01000000 01010001 + +result = sample.setFloat16(0, 2.158203125, true); +assert.sameValue(result, undefined, "returns undefined #2"); +assert.sameValue(sample.getFloat16(0), 42); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/set-values-return-undefined.js new file mode 100644 index 0000000000..52212f556a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/set-values-return-undefined.js @@ -0,0 +1,36 @@ +// |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.setfloat16 +description: > + Set values and return undefined +features: [Float16Array] +includes: [byteConversionValues.js] +---*/ + +var buffer = new ArrayBuffer(2); +var sample = new DataView(buffer, 0); +var values = byteConversionValues.values; +var expectedValues = byteConversionValues.expected.Float16; + +values.forEach(function(value, i) { + var result; + var expected = expectedValues[i]; + + result = sample.setFloat16(0, value, false); + + assert.sameValue( + sample.getFloat16(0), + expected, + "value: " + value + ); + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/shell.js diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..e0d2c72daa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +features: [Float16Array, Int8Array] +---*/ + +var setFloat16 = DataView.prototype.setFloat16; + +assert.throws(TypeError, function() { + setFloat16.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setFloat16.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setFloat16.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setFloat16.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/this-is-not-object.js new file mode 100644 index 0000000000..182647f76f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/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.setfloat16 +description: Throws a TypeError if this is not Object +features: [Float16Array, Symbol] +---*/ + +var setFloat16 = DataView.prototype.setFloat16; + +assert.throws(TypeError, function() { + setFloat16.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setFloat16.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setFloat16.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setFloat16.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setFloat16.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setFloat16.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setFloat16.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/to-boolean-littleendian.js new file mode 100644 index 0000000000..1840009be6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/to-boolean-littleendian.js @@ -0,0 +1,37 @@ +// |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.setfloat16 +description: > + Boolean littleEndian argument coerced in ToBoolean +features: [Float16Array, Symbol] +---*/ + +var buffer = new ArrayBuffer(2); +var sample = new DataView(buffer, 0); + +// False +sample.setFloat16(0, 1); +assert.sameValue(sample.getFloat16(0), 1, "no arg"); +sample.setFloat16(0, 2, undefined); +assert.sameValue(sample.getFloat16(0), 2, "undefined"); +sample.setFloat16(0, 3, null); +assert.sameValue(sample.getFloat16(0), 3, "null"); +sample.setFloat16(0, 4, 0); +assert.sameValue(sample.getFloat16(0), 4, "0"); +sample.setFloat16(0, 5, ""); +assert.sameValue(sample.getFloat16(0), 5, "the empty string"); + +// True +sample.setFloat16(0, 6, {}); // 01000110 00000000 +assert.sameValue(sample.getFloat16(0), 0.000004172325134277344, "{}"); // 00000000 01000110 +sample.setFloat16(0, 7, Symbol("1")); // 01000111 00000000 +assert.sameValue(sample.getFloat16(0), 0.000004231929779052734, "symbol"); // 00000000 01000111 +sample.setFloat16(0, 8, 1); // 01001000 00000000 +assert.sameValue(sample.getFloat16(0), 0.000004291534423828125, "1"); // 00000000 01001000 +sample.setFloat16(0, 9, "string"); // 01001000 10000000 +assert.sameValue(sample.getFloat16(0), -0.000004291534423828125, "string"); // 10000000 01001000 + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/toindex-byteoffset.js new file mode 100644 index 0000000000..2e637768de --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/toindex-byteoffset.js @@ -0,0 +1,99 @@ +// |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.setfloat16 +description: > + ToIndex conversions on byteOffset +features: [Float16Array] +---*/ + +var buffer = new ArrayBuffer(6); +var sample = new DataView(buffer, 0); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +sample.setFloat16(0, 0); +sample.setFloat16(-0, 42); +assert.sameValue(sample.getFloat16(0), 42, "-0"); + +sample.setFloat16(3, 0); +sample.setFloat16(obj1, 42); +assert.sameValue(sample.getFloat16(3), 42, "object's valueOf"); + +sample.setFloat16(4, 0); +sample.setFloat16(obj2, 42); +assert.sameValue(sample.getFloat16(4), 42, "object's toString"); + +sample.setFloat16(0, 0); +sample.setFloat16("", 42); +assert.sameValue(sample.getFloat16(0), 42, "the Empty string"); + +sample.setFloat16(0, 0); +sample.setFloat16("0", 42); +assert.sameValue(sample.getFloat16(0), 42, "string '0'"); + +sample.setFloat16(2, 0); +sample.setFloat16("2", 42); +assert.sameValue(sample.getFloat16(2), 42, "string '2'"); + +sample.setFloat16(1, 0); +sample.setFloat16(true, 42); +assert.sameValue(sample.getFloat16(1), 42, "true"); + +sample.setFloat16(0, 0); +sample.setFloat16(false, 42); +assert.sameValue(sample.getFloat16(0), 42, "false"); + +sample.setFloat16(0, 0); +sample.setFloat16(NaN, 42); +assert.sameValue(sample.getFloat16(0), 42, "NaN"); + +sample.setFloat16(0, 0); +sample.setFloat16(null, 42); +assert.sameValue(sample.getFloat16(0), 42, "null"); + +sample.setFloat16(0, 0); +sample.setFloat16(0.1, 42); +assert.sameValue(sample.getFloat16(0), 42, "0.1"); + +sample.setFloat16(0, 0); +sample.setFloat16(0.9, 42); +assert.sameValue(sample.getFloat16(0), 42, "0.9"); + +sample.setFloat16(1, 0); +sample.setFloat16(1.1, 42); +assert.sameValue(sample.getFloat16(1), 42, "1.1"); + +sample.setFloat16(1, 0); +sample.setFloat16(1.9, 42); +assert.sameValue(sample.getFloat16(1), 42, "1.9"); + +sample.setFloat16(0, 0); +sample.setFloat16(-0.1, 42); +assert.sameValue(sample.getFloat16(0), 42, "-0.1"); + +sample.setFloat16(0, 0); +sample.setFloat16(-0.99999, 42); +assert.sameValue(sample.getFloat16(0), 42, "-0.99999"); + +sample.setFloat16(0, 0); +sample.setFloat16(undefined, 42); +assert.sameValue(sample.getFloat16(0), 42, "undefined"); + +sample.setFloat16(0, 7); +sample.setFloat16(); +assert.sameValue(sample.getFloat16(0), NaN, "no arg"); + +reportCompare(0, 0); |