Skip to content

Commit 2e9b3a2

Browse files
committed
add a runtime existential test for Float16Array
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
1 parent b5c8fd1 commit 2e9b3a2

File tree

1 file changed

+7
-2
lines changed
  • tests/js-native-api/test_typedarray

1 file changed

+7
-2
lines changed

tests/js-native-api/test_typedarray/test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ assert.strictEqual(externalResult[0], 0);
3636
assert.strictEqual(externalResult[1], 1);
3737
assert.strictEqual(externalResult[2], 2);
3838

39+
// Float16Array is an ES2025 addition; not exposed by default in older V8
40+
// versions (e.g. those shipped with Node 20.x / 22.x). Detect at runtime and
41+
// only exercise the Float16Array code paths when the engine supports it.
42+
const hasFloat16Array = typeof Float16Array !== "undefined";
43+
3944
// Validate creation of all kinds of TypedArrays
4045
const buffer = new ArrayBuffer(128);
4146
const arrayTypes = [
@@ -46,7 +51,7 @@ const arrayTypes = [
4651
Uint16Array,
4752
Int32Array,
4853
Uint32Array,
49-
Float16Array,
54+
...(hasFloat16Array ? [Float16Array] : []),
5055
Float32Array,
5156
Float64Array,
5257
BigInt64Array,
@@ -79,7 +84,7 @@ const nonByteArrayTypes = [
7984
Uint16Array,
8085
Int32Array,
8186
Uint32Array,
82-
Float16Array,
87+
...(hasFloat16Array ? [Float16Array] : []),
8388
Float32Array,
8489
Float64Array,
8590
BigInt64Array,

0 commit comments

Comments
 (0)