Skip to content

Commit 889094f

Browse files
bartlomiejuaduh95
authored andcommitted
lib: handle Float16Array in node:v8 serdes
PR-URL: #55996Fixes: #55574 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]>
1 parent a6f0cfa commit 889094f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

‎lib/eslint.config_partial.mjs‎

Lines changed: 5 additions & 0 deletions
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‎

Lines changed: 6 additions & 0 deletions
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
constpromiseHooks=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]')return11;
291295
if(type==='[object BigUint64Array]')return12;
296+
if(type==='[object Float16Array]')return13;
292297
return-1;
293298
}
294299

@@ -306,6 +311,7 @@ function arrayBufferViewIndexToType(index){
306311
if(index===10)returnFastBuffer;
307312
if(index===11)returnBigInt64Array;
308313
if(index===12)returnBigUint64Array;
314+
if(index===13)returnFloat16Array;
309315
returnundefined;
310316
}
311317

‎test/parallel/test-v8-serdes.js‎

Lines changed: 5 additions & 1 deletion
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
constassert=require('assert');
88
constv8=require('v8');
99
constos=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
constcircular={};
1215
circular.circular=circular;
@@ -26,6 +29,7 @@ const objects = [
2629
Buffer.from([1,2,3,4]),
2730
newBigInt64Array([42n]),
2831
newBigUint64Array([42n]),
32+
newFloat16Array([1,2,3,4]),
2933
undefined,
3034
null,
3135
42,

0 commit comments

Comments
(0)