From 35d4b8215ea5b7cdf4094627a6d86249dbfcb01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 26 Nov 2024 02:49:26 +0100 Subject: [PATCH 01/11] lib: handle Float16Array in node:v8 serdes --- lib/v8.js | 3 +++ test/parallel/test-http-url.parse-post.js | 2 +- test/parallel/test-v8-serdes.js | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/v8.js b/lib/v8.js index 7a8979887bab49..89e16c7092133a 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -289,6 +289,7 @@ function arrayBufferViewTypeToIndex(abView) { // Index 10 is FastBuffer. if (type === '[object BigInt64Array]') return 11; if (type === '[object BigUint64Array]') return 12; + if (type === '[object Float16Array]') return 13; return -1; } @@ -306,6 +307,8 @@ function arrayBufferViewIndexToType(index) { if (index === 10) return FastBuffer; if (index === 11) return BigInt64Array; if (index === 12) return BigUint64Array; + // TODO(bartlomieju): use a primordial, once `Float16Array` is available in stable V8 + if (index === 13) return Float16Array; return undefined; } diff --git a/test/parallel/test-http-url.parse-post.js b/test/parallel/test-http-url.parse-post.js index db5ee78fe6ebe2..2c899d49772354 100644 --- a/test/parallel/test-http-url.parse-post.js +++ b/test/parallel/test-http-url.parse-post.js @@ -29,7 +29,7 @@ let testURL; function check(request) { // url.parse should not mess with the method - assert.strictEqual(request.method, 'POST'); + assert.strictEqual(request.method, 'POST1'); // Everything else should be right assert.strictEqual(request.url, '/asdf?qwer=zxcv'); // The host header should use the url.parse.hostname diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 296e076a9f760d..077e87a6b32dbf 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -1,4 +1,4 @@ -// Flags: --expose-internals +// Flags: --expose-internals --js-float16array 'use strict'; @@ -26,6 +26,7 @@ const objects = [ Buffer.from([1, 2, 3, 4]), new BigInt64Array([42n]), new BigUint64Array([42n]), + new Float16Array([1, 2, 3, 4]), undefined, null, 42, From c8d043572a9d0287f347ce4985c0354edb538fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 26 Nov 2024 03:46:50 +0100 Subject: [PATCH 02/11] revert unrelated change --- test/parallel/test-http-url.parse-post.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-http-url.parse-post.js b/test/parallel/test-http-url.parse-post.js index 2c899d49772354..db5ee78fe6ebe2 100644 --- a/test/parallel/test-http-url.parse-post.js +++ b/test/parallel/test-http-url.parse-post.js @@ -29,7 +29,7 @@ let testURL; function check(request) { // url.parse should not mess with the method - assert.strictEqual(request.method, 'POST1'); + assert.strictEqual(request.method, 'POST'); // Everything else should be right assert.strictEqual(request.url, '/asdf?qwer=zxcv'); // The host header should use the url.parse.hostname From efd3cffc1140f9ad3ced3fa09f95dfe66a976d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 26 Nov 2024 03:48:41 +0100 Subject: [PATCH 03/11] lints --- lib/v8.js | 1 + test/parallel/test-v8-serdes.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/v8.js b/lib/v8.js index 89e16c7092133a..37c0ecae9bfd1a 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -308,6 +308,7 @@ function arrayBufferViewIndexToType(index) { if (index === 11) return BigInt64Array; if (index === 12) return BigUint64Array; // TODO(bartlomieju): use a primordial, once `Float16Array` is available in stable V8 + // eslint-disable-line no-undef if (index === 13) return Float16Array; return undefined; } diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 077e87a6b32dbf..8cde462fa37599 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -26,6 +26,8 @@ const objects = [ Buffer.from([1, 2, 3, 4]), new BigInt64Array([42n]), new BigUint64Array([42n]), + // TODO(bartlomieju): once `Float16Array` is available in stable V8, remove the lint below and `--js-float16array` flag up top + // eslint-disable-line no-undef new Float16Array([1, 2, 3, 4]), undefined, null, From 5ed61e1c2f16b3658c774deb5bc0e1f93c72df23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 26 Nov 2024 20:03:52 +0100 Subject: [PATCH 04/11] Update test/parallel/test-v8-serdes.js Co-authored-by: Ben Noordhuis --- test/parallel/test-v8-serdes.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 8cde462fa37599..aa2e6e0433484d 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -26,7 +26,8 @@ const objects = [ Buffer.from([1, 2, 3, 4]), new BigInt64Array([42n]), new BigUint64Array([42n]), - // TODO(bartlomieju): once `Float16Array` is available in stable V8, remove the lint below and `--js-float16array` flag up top + // TODO(bartlomieju): once `Float16Array` is available in stable V8, + // remove the lint below and `--js-float16array` flag up top // eslint-disable-line no-undef new Float16Array([1, 2, 3, 4]), undefined, From b50cbcd832742176dad475723a60d0b70c6d800d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 27 Nov 2024 15:33:23 +0100 Subject: [PATCH 05/11] fix eslint --- lib/v8.js | 2 +- test/parallel/test-v8-serdes.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/v8.js b/lib/v8.js index 37c0ecae9bfd1a..0cd8902f2279ff 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -308,7 +308,7 @@ function arrayBufferViewIndexToType(index) { if (index === 11) return BigInt64Array; if (index === 12) return BigUint64Array; // TODO(bartlomieju): use a primordial, once `Float16Array` is available in stable V8 - // eslint-disable-line no-undef + // eslint-disable-next-line no-undef if (index === 13) return Float16Array; return undefined; } diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index aa2e6e0433484d..60593240f73dfa 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -28,7 +28,7 @@ const objects = [ new BigUint64Array([42n]), // TODO(bartlomieju): once `Float16Array` is available in stable V8, // remove the lint below and `--js-float16array` flag up top - // eslint-disable-line no-undef + // eslint-disable-next-line no-undef new Float16Array([1, 2, 3, 4]), undefined, null, From 6ea8d1e70f03db969cf02e3fc89563131c9db4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 30 Nov 2024 00:19:13 +0100 Subject: [PATCH 06/11] use @aduh95's suggestion --- lib/eslint.config_partial.mjs | 5 +++++ lib/v8.js | 3 +++ test/parallel/test-v8-serdes.js | 1 + 3 files changed, 9 insertions(+) diff --git a/lib/eslint.config_partial.mjs b/lib/eslint.config_partial.mjs index 78d9f409a37956..520df40aecbc90 100644 --- a/lib/eslint.config_partial.mjs +++ b/lib/eslint.config_partial.mjs @@ -347,6 +347,11 @@ export default [ name: 'SubtleCrypto', message: "Use `const { SubtleCrypto } = require('internal/crypto/webcrypto');` instead of the global.", }, + // Float16Array is not available in primordials because it's only available with --js-float16array CLI flag. + { + name: 'Float16Array', + message: 'Use `const { Float16Array } = globalThis;` instead of the global.', + }, ], 'no-restricted-modules': [ 'error', diff --git a/lib/v8.js b/lib/v8.js index 0cd8902f2279ff..70d987906ff0ae 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -63,6 +63,9 @@ const { } = require('internal/heap_utils'); const promiseHooks = require('internal/promise_hooks'); const { getOptionValue } = require('internal/options'); +// TODO(bartlomieju): move to destructuring from `primordials`, once available in stable V8. +const { Float16Array } = globalThis; + /** * Generates a snapshot of the current V8 heap * and writes it to a JSON file. diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 60593240f73dfa..a82df132bfb5a0 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -7,6 +7,7 @@ const { internalBinding } = require('internal/test/binding'); const assert = require('assert'); const v8 = require('v8'); const os = require('os'); +const { Float16Array } = globalThis; const circular = {}; circular.circular = circular; From 488b02c08128269e4fce999818307f8f5b5eb52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 30 Nov 2024 00:25:49 +0100 Subject: [PATCH 07/11] lint --- lib/v8.js | 3 +-- test/parallel/test-v8-serdes.js | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/v8.js b/lib/v8.js index 70d987906ff0ae..ce3316c43ec68b 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -22,6 +22,7 @@ const { Error, Float32Array, Float64Array, + globalThis, Int16Array, Int32Array, Int8Array, @@ -310,8 +311,6 @@ function arrayBufferViewIndexToType(index) { if (index === 10) return FastBuffer; if (index === 11) return BigInt64Array; if (index === 12) return BigUint64Array; - // TODO(bartlomieju): use a primordial, once `Float16Array` is available in stable V8 - // eslint-disable-next-line no-undef if (index === 13) return Float16Array; return undefined; } diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index a82df132bfb5a0..c87ed89353af3b 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -7,6 +7,8 @@ const { internalBinding } = require('internal/test/binding'); const assert = require('assert'); const v8 = require('v8'); const os = require('os'); +// TODO(bartlomieju): once `Float16Array` is available in stable V8, +// remove this line and `--js-float16array` flag up top const { Float16Array } = globalThis; const circular = {}; @@ -27,9 +29,6 @@ const objects = [ Buffer.from([1, 2, 3, 4]), new BigInt64Array([42n]), new BigUint64Array([42n]), - // TODO(bartlomieju): once `Float16Array` is available in stable V8, - // remove the lint below and `--js-float16array` flag up top - // eslint-disable-next-line no-undef new Float16Array([1, 2, 3, 4]), undefined, null, From 29cbbfb567dd178bfcd421c50ba417f75cdddae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 30 Nov 2024 00:32:09 +0100 Subject: [PATCH 08/11] sort --- lib/v8.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/v8.js b/lib/v8.js index ce3316c43ec68b..5e914958e76682 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -22,11 +22,11 @@ const { Error, Float32Array, Float64Array, - globalThis, Int16Array, Int32Array, Int8Array, JSONParse, + globalThis, ObjectPrototypeToString, Uint16Array, Uint32Array, From 81040c094357abd7accf424d32cc4a26096d6616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 30 Nov 2024 00:38:34 +0100 Subject: [PATCH 09/11] ASCIIbetical sort --- lib/v8.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/v8.js b/lib/v8.js index 5e914958e76682..d47e415590d86e 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -26,12 +26,12 @@ const { Int32Array, Int8Array, JSONParse, - globalThis, ObjectPrototypeToString, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray, + globalThis, } = primordials; const { Buffer } = require('buffer'); From 58c8d51090e77cec96255356ffc91f5a7389fa65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 3 Dec 2024 04:25:35 +0100 Subject: [PATCH 10/11] review --- lib/v8.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/v8.js b/lib/v8.js index d47e415590d86e..7455f7cc0a0cc3 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -31,7 +31,9 @@ const { Uint32Array, Uint8Array, Uint8ClampedArray, - globalThis, + globalThis: { + Float16Array + }, } = primordials; const { Buffer } = require('buffer'); @@ -64,8 +66,6 @@ const { } = require('internal/heap_utils'); const promiseHooks = require('internal/promise_hooks'); const { getOptionValue } = require('internal/options'); -// TODO(bartlomieju): move to destructuring from `primordials`, once available in stable V8. -const { Float16Array } = globalThis; /** * Generates a snapshot of the current V8 heap From bce30a47ef181a1863f9b6c574427f89bc5b4505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 3 Dec 2024 05:17:22 +0100 Subject: [PATCH 11/11] lint --- lib/v8.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/v8.js b/lib/v8.js index 7455f7cc0a0cc3..e379233ea49e0d 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -32,7 +32,7 @@ const { Uint8Array, Uint8ClampedArray, globalThis: { - Float16Array + Float16Array, }, } = primordials;