Skip to content

Commit 11144ab

Browse files
bartlomiejuruyadorno
authored andcommitted
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 1cfa31f commit 11144ab

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
@@ -343,6 +343,11 @@ export default [
343343
name: 'SubtleCrypto',
344344
message: "Use `const { SubtleCrypto } = require('internal/crypto/webcrypto');` instead of the global.",
345345
},
346+
// Float16Array is not available in primordials because it's only available with --js-float16array CLI flag.
347+
{
348+
name: 'Float16Array',
349+
message: 'Use `const { Float16Array } = globalThis;` instead of the global.',
350+
},
346351
],
347352
'no-restricted-modules': [
348353
'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
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

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
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy