Skip to content

Commit ac7fea6

Browse files
authored
lib: handle Float16Array in node:v8 serdes
PR-URL: #55996 Fixes: #55574 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
1 parent 7fdeeac commit ac7fea6

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/eslint.config_partial.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ export default [
347347
name: 'SubtleCrypto',
348348
message: "Use `const { SubtleCrypto } = require('internal/crypto/webcrypto');` instead of the global.",
349349
},
350+
// Float16Array is not available in primordials because it's only available with --js-float16array CLI flag.
351+
{
352+
name: 'Float16Array',
353+
message: 'Use `const { Float16Array } = globalThis;` instead of the global.',
354+
},
350355
],
351356
'no-restricted-modules': [
352357
'error',

lib/v8.js

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const {
3131
Uint32Array,
3232
Uint8Array,
3333
Uint8ClampedArray,
34+
globalThis: {
35+
Float16Array,
36+
},
3437
} = primordials;
3538

3639
const { Buffer } = require('buffer');
@@ -63,6 +66,7 @@ const {
6366
} = require('internal/heap_utils');
6467
const promiseHooks = require('internal/promise_hooks');
6568
const { getOptionValue } = require('internal/options');
69+
6670
/**
6771
* Generates a snapshot of the current V8 heap
6872
* and writes it to a JSON file.
@@ -289,6 +293,7 @@ function arrayBufferViewTypeToIndex(abView) {
289293
// Index 10 is FastBuffer.
290294
if (type === '[object BigInt64Array]') return 11;
291295
if (type === '[object BigUint64Array]') return 12;
296+
if (type === '[object Float16Array]') return 13;
292297
return -1;
293298
}
294299

@@ -306,6 +311,7 @@ function arrayBufferViewIndexToType(index) {
306311
if (index === 10) return FastBuffer;
307312
if (index === 11) return BigInt64Array;
308313
if (index === 12) return BigUint64Array;
314+
if (index === 13) return Float16Array;
309315
return undefined;
310316
}
311317

test/parallel/test-v8-serdes.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --expose-internals
1+
// Flags: --expose-internals --js-float16array
22

33
'use strict';
44

@@ -7,6 +7,9 @@ const { internalBinding } = require('internal/test/binding');
77
const assert = require('assert');
88
const v8 = require('v8');
99
const os = require('os');
10+
// TODO(bartlomieju): once `Float16Array` is available in stable V8,
11+
// remove this line and `--js-float16array` flag up top
12+
const { Float16Array } = globalThis;
1013

1114
const circular = {};
1215
circular.circular = circular;
@@ -26,6 +29,7 @@ const objects = [
2629
Buffer.from([1, 2, 3, 4]),
2730
new BigInt64Array([42n]),
2831
new BigUint64Array([42n]),
32+
new Float16Array([1, 2, 3, 4]),
2933
undefined,
3034
null,
3135
42,

0 commit comments

Comments
 (0)