Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 11144ab

Browse filesBrowse 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
Copy full SHA for 11144ab

File tree

Expand file treeCollapse file tree

3 files changed

+16
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-1
lines changed
Open diff view settings
Collapse file

‎lib/eslint.config_partial.mjs‎

Copy file name to clipboardExpand all lines: lib/eslint.config_partial.mjs
+5Lines 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',
Collapse file

‎lib/v8.js‎

Copy file name to clipboardExpand all lines: lib/v8.js
+6Lines 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

Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-v8-serdes.js
+5-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.