add tests for get/setFloat16

This commit is contained in:
Kevin Gibbons 2024-03-12 23:22:15 -07:00 committed by Philip Chimento
parent 435dcc9f6e
commit 4f7a43afbd
45 changed files with 1275 additions and 2 deletions

View File

@ -0,0 +1,23 @@
// 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");

View File

@ -0,0 +1,21 @@
// 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");

View File

@ -0,0 +1,18 @@
// 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);
});

View File

@ -0,0 +1,60 @@
// 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)");

View File

@ -0,0 +1,16 @@
// 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]
---*/
assert.sameValue(DataView.prototype.getFloat16.length, 1);
verifyNotEnumerable(DataView.prototype.getFloat16, "length");
verifyNotWritable(DataView.prototype.getFloat16, "length");
verifyConfigurable(DataView.prototype.getFloat16, "length");

View File

@ -0,0 +1,18 @@
// 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);

View File

@ -0,0 +1,16 @@
// 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]
---*/
assert.sameValue(DataView.prototype.getFloat16.name, "getFloat16");
verifyNotEnumerable(DataView.prototype.getFloat16, "name");
verifyNotWritable(DataView.prototype.getFloat16, "name");
verifyConfigurable(DataView.prototype.getFloat16, "name");

View File

@ -0,0 +1,20 @@
// 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");

View File

@ -0,0 +1,21 @@
// 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);
}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getFloat16(0, 0)` throws TypeError');

View File

@ -0,0 +1,41 @@
// 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');
});

View File

@ -0,0 +1,18 @@
// 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);
});

View File

@ -0,0 +1,32 @@
// 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");

View File

@ -0,0 +1,20 @@
// 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);

View File

@ -0,0 +1,20 @@
// 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);

View File

@ -0,0 +1,23 @@
// 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)");

View File

@ -0,0 +1,26 @@
// 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

View File

@ -0,0 +1,37 @@
// 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

View File

@ -0,0 +1,29 @@
// 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");

View File

@ -0,0 +1,39 @@
// 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");

View File

@ -0,0 +1,28 @@
// 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");

View File

@ -0,0 +1,50 @@
// 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");

View File

@ -0,0 +1,24 @@
// 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);
});

View File

@ -0,0 +1,23 @@
// 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);
});

View File

@ -0,0 +1,21 @@
// 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");

View File

@ -0,0 +1,18 @@
// 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);
});

View File

@ -0,0 +1,33 @@
// 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)");

View File

@ -0,0 +1,68 @@
// 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");

View File

@ -0,0 +1,16 @@
// 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]
---*/
assert.sameValue(DataView.prototype.setFloat16.length, 2);
verifyNotEnumerable(DataView.prototype.setFloat16, "length");
verifyNotWritable(DataView.prototype.setFloat16, "length");
verifyConfigurable(DataView.prototype.setFloat16, "length");

View File

@ -0,0 +1,16 @@
// 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]
---*/
assert.sameValue(DataView.prototype.setFloat16.name, "setFloat16");
verifyNotEnumerable(DataView.prototype.setFloat16, "name");
verifyNotWritable(DataView.prototype.setFloat16, "name");
verifyConfigurable(DataView.prototype.setFloat16, "name");

View File

@ -0,0 +1,22 @@
// 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");

View File

@ -0,0 +1,17 @@
// 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);

View File

@ -0,0 +1,21 @@
// 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);
}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setFloat16(0, 0)` throws TypeError');

View File

@ -0,0 +1,25 @@
// 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)");

View File

@ -0,0 +1,41 @@
// 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');
});

View File

@ -0,0 +1,18 @@
// 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);
});

View File

@ -0,0 +1,32 @@
// 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");

View File

@ -0,0 +1,18 @@
// 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);
});

View File

@ -0,0 +1,32 @@
// 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");

View File

@ -0,0 +1,22 @@
// 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);

View File

@ -0,0 +1,33 @@
// 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
);
});

View File

@ -0,0 +1,29 @@
// 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");

View File

@ -0,0 +1,39 @@
// 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");

View File

@ -0,0 +1,34 @@
// 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

View File

@ -0,0 +1,96 @@
// 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");

View File

@ -5,9 +5,8 @@
esid: sec-ecmascript-standard-built-in-objects
description: >
Math.f16round does not implement [[Construct]], is not new-able
features: [Float16Array]
includes: [isConstructor.js]
features: [Reflect.construct]
features: [Float16Array, Reflect.construct]
---*/
assert(!isConstructor(Math.f16round), "Math.f16round is not a constructor");