From 9c6f94fa0661aa449b176301161f87aa8159f3c1 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Fri, 26 Jan 2024 14:20:40 -0800 Subject: [PATCH 1/4] deps: V8: backport ae5a4db8ad86 Original commit message: [import-attributes] Deprecate 'assert' for removal in 12.6 See https://groups.google.com/a/chromium.org/g/blink-dev/c/ZHvzLaJZRvo/m/FgNDBjrtBQAJ Bug: v8:10958 Change-Id: I4d21c9f7aad1024b198b4a1cdfb4792a011da464 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5055681 Reviewed-by: Rezvan Mahdavi Hezaveh Auto-Submit: Shu-yu Guo Commit-Queue: Shu-yu Guo Cr-Commit-Position: refs/heads/main@{#92044} Refs: https://github.com/v8/v8/commit/ae5a4db8ad86c817f80856901ea121829f8b5184 Co-authored-by: Antoine du Hamel --- common.gypi | 2 +- deps/v8/src/common/message-template.h | 3 ++ deps/v8/src/parsing/parser.cc | 3 ++ .../fail/modules-import-assertions-fail-1.out | 1 + .../fail/modules-import-assertions-fail-2.out | 3 +- .../PrivateAccessorAccess.golden | 8 ++--- .../PrivateMethodAccess.golden | 4 +-- .../StaticPrivateMethodAccess.golden | 30 +++++++++---------- 8 files changed, 31 insertions(+), 23 deletions(-) diff --git a/common.gypi b/common.gypi index 1ece4f5e494533..c56785cbadfa2d 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.23', + 'v8_embedder_string': '-node.24', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/common/message-template.h b/deps/v8/src/common/message-template.h index 99c9230107368d..fe26746d806def 100644 --- a/deps/v8/src/common/message-template.h +++ b/deps/v8/src/common/message-template.h @@ -113,6 +113,9 @@ namespace internal { T(IllegalInvocation, "Illegal invocation") \ T(ImmutablePrototypeSet, \ "Immutable prototype object '%' cannot have their prototype set") \ + T(ImportAssertDeprecated, \ + "'assert' is deprecated in import statements and support will be removed " \ + "in %; use 'with' instead") \ T(ImportAssertionDuplicateKey, "Import assertion has duplicate key '%'") \ T(ImportCallNotNewExpression, "Cannot use new with import") \ T(ImportOutsideModule, "Cannot use import statement outside a module") \ diff --git a/deps/v8/src/parsing/parser.cc b/deps/v8/src/parsing/parser.cc index 4a3fceed6af7c6..0d9085af752618 100644 --- a/deps/v8/src/parsing/parser.cc +++ b/deps/v8/src/parsing/parser.cc @@ -1365,6 +1365,9 @@ ImportAssertions* Parser::ParseImportAssertClause() { !scanner()->HasLineTerminatorBeforeNext() && CheckContextualKeyword(ast_value_factory()->assert_string())) { // 'assert' keyword consumed + info_->pending_error_handler()->ReportWarningAt( + position(), end_position(), MessageTemplate::kImportAssertDeprecated, + "a future version"); } else { return import_assertions; } diff --git a/deps/v8/test/message/fail/modules-import-assertions-fail-1.out b/deps/v8/test/message/fail/modules-import-assertions-fail-1.out index 1b3be22192a342..2ba99a283f69bc 100644 --- a/deps/v8/test/message/fail/modules-import-assertions-fail-1.out +++ b/deps/v8/test/message/fail/modules-import-assertions-fail-1.out @@ -1 +1,2 @@ +*%(basename)s:9: 'assert' is deprecated in import statements and support will be removed in a future version; use 'with' instead undefined:0: Error: Invalid module type was asserted \ No newline at end of file diff --git a/deps/v8/test/message/fail/modules-import-assertions-fail-2.out b/deps/v8/test/message/fail/modules-import-assertions-fail-2.out index 47ac5621187d97..0a82154d871ddc 100644 --- a/deps/v8/test/message/fail/modules-import-assertions-fail-2.out +++ b/deps/v8/test/message/fail/modules-import-assertions-fail-2.out @@ -1,4 +1,5 @@ +*%(basename)s:9: 'assert' is deprecated in import statements and support will be removed in a future version; use 'with' instead undefined:1: SyntaxError: Unexpected token '/', "// Copyrig"... is not valid JSON // Copyright 2021 the V8 project authors. All rights reserved. ^ -SyntaxError: Unexpected token '/', "// Copyrig"... is not valid JSON \ No newline at end of file +SyntaxError: Unexpected token '/', "// Copyrig"... is not valid JSON diff --git a/deps/v8/test/unittests/interpreter/bytecode_expectations/PrivateAccessorAccess.golden b/deps/v8/test/unittests/interpreter/bytecode_expectations/PrivateAccessorAccess.golden index 3594623033d02b..d6091fbf9b7fdc 100644 --- a/deps/v8/test/unittests/interpreter/bytecode_expectations/PrivateAccessorAccess.golden +++ b/deps/v8/test/unittests/interpreter/bytecode_expectations/PrivateAccessorAccess.golden @@ -83,7 +83,7 @@ bytecodes: [ /* 48 E> */ B(DefineKeyedOwnProperty), R(this), R(0), U8(0), U8(0), /* 53 S> */ B(LdaImmutableCurrentContextSlot), U8(3), /* 58 E> */ B(GetKeyedProperty), R(this), U8(2), - B(Wide), B(LdaSmi), I16(311), + B(Wide), B(LdaSmi), I16(312), B(Star2), B(LdaConstant), U8(0), B(Star3), @@ -115,7 +115,7 @@ bytecodes: [ /* 41 E> */ B(DefineKeyedOwnProperty), R(this), R(0), U8(0), U8(0), /* 46 S> */ B(LdaImmutableCurrentContextSlot), U8(3), /* 51 E> */ B(GetKeyedProperty), R(this), U8(2), - B(Wide), B(LdaSmi), I16(310), + B(Wide), B(LdaSmi), I16(311), B(Star2), B(LdaConstant), U8(0), B(Star3), @@ -149,7 +149,7 @@ bytecodes: [ B(Star2), B(LdaImmutableCurrentContextSlot), U8(3), /* 58 E> */ B(GetKeyedProperty), R(this), U8(2), - B(Wide), B(LdaSmi), I16(311), + B(Wide), B(LdaSmi), I16(312), B(Star3), B(LdaConstant), U8(0), B(Star4), @@ -181,7 +181,7 @@ bytecodes: [ /* 41 E> */ B(DefineKeyedOwnProperty), R(this), R(0), U8(0), U8(0), /* 46 S> */ B(LdaImmutableCurrentContextSlot), U8(3), /* 51 E> */ B(GetKeyedProperty), R(this), U8(2), - B(Wide), B(LdaSmi), I16(310), + B(Wide), B(LdaSmi), I16(311), B(Star2), B(LdaConstant), U8(0), B(Star3), diff --git a/deps/v8/test/unittests/interpreter/bytecode_expectations/PrivateMethodAccess.golden b/deps/v8/test/unittests/interpreter/bytecode_expectations/PrivateMethodAccess.golden index b7bb831e618647..1c8dc4d9e9a6dd 100644 --- a/deps/v8/test/unittests/interpreter/bytecode_expectations/PrivateMethodAccess.golden +++ b/deps/v8/test/unittests/interpreter/bytecode_expectations/PrivateMethodAccess.golden @@ -58,7 +58,7 @@ bytecodes: [ B(Star2), B(LdaImmutableCurrentContextSlot), U8(3), /* 54 E> */ B(GetKeyedProperty), R(this), U8(2), - B(Wide), B(LdaSmi), I16(309), + B(Wide), B(LdaSmi), I16(310), B(Star3), B(LdaConstant), U8(0), B(Star4), @@ -91,7 +91,7 @@ bytecodes: [ /* 44 E> */ B(DefineKeyedOwnProperty), R(this), R(0), U8(0), U8(0), /* 49 S> */ B(LdaImmutableCurrentContextSlot), U8(3), /* 54 E> */ B(GetKeyedProperty), R(this), U8(2), - B(Wide), B(LdaSmi), I16(309), + B(Wide), B(LdaSmi), I16(311), B(Star2), B(LdaConstant), U8(0), B(Star3), diff --git a/deps/v8/test/unittests/interpreter/bytecode_expectations/StaticPrivateMethodAccess.golden b/deps/v8/test/unittests/interpreter/bytecode_expectations/StaticPrivateMethodAccess.golden index e8350d6b7b42ca..2b21d2260fc0ff 100644 --- a/deps/v8/test/unittests/interpreter/bytecode_expectations/StaticPrivateMethodAccess.golden +++ b/deps/v8/test/unittests/interpreter/bytecode_expectations/StaticPrivateMethodAccess.golden @@ -24,7 +24,7 @@ bytecodes: [ B(TestReferenceEqual), R(this), B(Mov), R(this), R(1), B(JumpIfTrue), U8(16), - B(Wide), B(LdaSmi), I16(303), + B(Wide), B(LdaSmi), I16(304), B(Star2), B(LdaConstant), U8(0), B(Star3), @@ -61,13 +61,13 @@ bytecodes: [ B(TestReferenceEqual), R(this), B(Mov), R(this), R(0), B(JumpIfTrue), U8(16), - B(Wide), B(LdaSmi), I16(303), + B(Wide), B(LdaSmi), I16(304), B(Star2), B(LdaConstant), U8(0), B(Star3), /* 61 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(2), U8(2), B(Throw), - B(Wide), B(LdaSmi), I16(309), + B(Wide), B(LdaSmi), I16(310), B(Star2), B(LdaConstant), U8(1), B(Star3), @@ -99,13 +99,13 @@ bytecodes: [ B(TestReferenceEqual), R(this), B(Mov), R(this), R(0), B(JumpIfTrue), U8(16), - B(Wide), B(LdaSmi), I16(303), + B(Wide), B(LdaSmi), I16(304), B(Star1), B(LdaConstant), U8(0), B(Star2), /* 61 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2), B(Throw), - B(Wide), B(LdaSmi), I16(309), + B(Wide), B(LdaSmi), I16(310), B(Star1), B(LdaConstant), U8(1), B(Star2), @@ -145,7 +145,7 @@ bytecodes: [ B(TestReferenceEqual), R(this), B(Mov), R(this), R(0), B(JumpIfTrue), U8(16), - B(Wide), B(LdaSmi), I16(303), + B(Wide), B(LdaSmi), I16(304), B(Star2), B(LdaConstant), U8(0), B(Star3), @@ -167,7 +167,7 @@ bytecodes: [ B(TestReferenceEqual), R(this), B(Mov), R(this), R(0), B(JumpIfTrue), U8(16), - B(Wide), B(LdaSmi), I16(303), + B(Wide), B(LdaSmi), I16(304), B(Star3), B(LdaConstant), U8(0), B(Star4), @@ -182,7 +182,7 @@ bytecodes: [ B(TestReferenceEqual), R(this), B(Mov), R(this), R(0), B(JumpIfTrue), U8(16), - B(Wide), B(LdaSmi), I16(303), + B(Wide), B(LdaSmi), I16(304), B(Star2), B(LdaConstant), U8(0), B(Star3), @@ -216,13 +216,13 @@ bytecodes: [ B(TestReferenceEqual), R(this), B(Mov), R(this), R(0), B(JumpIfTrue), U8(16), - B(Wide), B(LdaSmi), I16(303), + B(Wide), B(LdaSmi), I16(304), B(Star1), B(LdaConstant), U8(0), B(Star2), /* 65 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2), B(Throw), - B(Wide), B(LdaSmi), I16(311), + B(Wide), B(LdaSmi), I16(312), B(Star1), B(LdaConstant), U8(1), B(Star2), @@ -253,13 +253,13 @@ bytecodes: [ B(TestReferenceEqual), R(this), B(Mov), R(this), R(0), B(JumpIfTrue), U8(16), - B(Wide), B(LdaSmi), I16(303), + B(Wide), B(LdaSmi), I16(304), B(Star1), B(LdaConstant), U8(0), B(Star2), /* 58 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2), B(Throw), - B(Wide), B(LdaSmi), I16(310), + B(Wide), B(LdaSmi), I16(311), B(Star1), B(LdaConstant), U8(1), B(Star2), @@ -292,13 +292,13 @@ bytecodes: [ B(TestReferenceEqual), R(this), B(Mov), R(this), R(0), B(JumpIfTrue), U8(16), - B(Wide), B(LdaSmi), I16(303), + B(Wide), B(LdaSmi), I16(304), B(Star2), B(LdaConstant), U8(0), B(Star3), /* 65 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(2), U8(2), B(Throw), - B(Wide), B(LdaSmi), I16(311), + B(Wide), B(LdaSmi), I16(312), B(Star2), B(LdaConstant), U8(1), B(Star3), @@ -327,7 +327,7 @@ bytecode array length: 19 bytecodes: [ /* 46 S> */ B(LdaImmutableCurrentContextSlot), U8(3), /* 51 E> */ B(GetKeyedProperty), R(this), U8(0), - B(Wide), B(LdaSmi), I16(310), + B(Wide), B(LdaSmi), I16(311), B(Star1), B(LdaConstant), U8(0), B(Star2), From 87a719a6f57e3d6ca748684bdde32dd7dfdf5c93 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Tue, 30 Jan 2024 16:28:06 -0800 Subject: [PATCH 2/4] deps: V8: cherry-pick 26fd1dfa9cd6 Original commit message: [import-attributes] Deprecate 'assert' for dynamic import as well Bug: v8:10958 Change-Id: I7847bdb5d2c79f057f4e1df99f8f5889788f09cb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5249778 Commit-Queue: Shu-yu Guo Reviewed-by: Leszek Swirski Cr-Commit-Position: refs/heads/main@{#92123} Refs: https://github.com/v8/v8/commit/26fd1dfa9cd6d56eae8ecfc7a136fd6709fba161 --- common.gypi | 2 +- deps/v8/src/execution/isolate.cc | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index c56785cbadfa2d..04852d81103ef8 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.24', + 'v8_embedder_string': '-node.25', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/execution/isolate.cc b/deps/v8/src/execution/isolate.cc index 33ff1348f58989..242c611f7582aa 100644 --- a/deps/v8/src/execution/isolate.cc +++ b/deps/v8/src/execution/isolate.cc @@ -5193,6 +5193,20 @@ MaybeHandle Isolate::GetImportAssertionsFromArgument( // an error. return MaybeHandle(); } + + if (V8_UNLIKELY(!import_assertions_object->IsUndefined())) { + MessageLocation* location = nullptr; + MessageLocation computed_location; + if (ComputeLocation(&computed_location)) { + location = &computed_location; + } + Handle message = MessageHandler::MakeMessageObject( + this, MessageTemplate::kImportAssertDeprecated, location, + factory()->NewStringFromAsciiChecked("a future version"), + Handle::null()); + message->set_error_level(v8::Isolate::kMessageWarning); + MessageHandler::ReportMessage(this, location, message); + } } // If there is no 'with' or 'assert' option in the options bag, it's not an From acbfd1697ff5a04867112f1ea752e9ce20a9b9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sat, 12 Oct 2024 13:21:09 +0200 Subject: [PATCH 3/4] esm: mark import attributes and JSON module as stable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two proposals reached stage 4 at the October 2024 meeting. PR-URL: https://github.com/nodejs/node/pull/55333 Reviewed-By: Yagiz Nizipli Reviewed-By: Antoine du Hamel Reviewed-By: Marco Ippolito Reviewed-By: Michaƫl Zasso Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca --- doc/api/esm.md | 17 +++++++---------- lib/internal/modules/esm/translators.js | 1 - test/es-module/test-esm-json.mjs | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 47e60084a94845..0eea9ad4991054 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -262,13 +262,9 @@ changes: description: Switch from Import Assertions to Import Attributes. --> -> Stability: 1.1 - Active development - -> This feature was previously named "Import assertions", and using the `assert` -> keyword instead of `with`. Any uses in code of the prior `assert` keyword -> should be updated to use `with` instead. +> Stability: 2 - Stable -The [Import Attributes proposal][] adds an inline syntax for module import +[Import attributes][Import Attributes MDN] are an inline syntax for module import statements to pass on more information alongside the module specifier. ```js @@ -278,13 +274,14 @@ const { default: barData } = await import('./bar.json', { with: { type: 'json' } }); ``` -Node.js supports the following `type` values, for which the attribute is -mandatory: +Node.js only supports the `type` attribute, for which it supports the following values: | Attribute `type` | Needed for | | ---------------- | ---------------- | | `'json'` | [JSON modules][] | +The `type: 'json'` attribute is mandatory when importing JSON modules. + ## Built-in modules [Built-in modules][] provide named exports of their public API. A @@ -591,7 +588,7 @@ separate cache. ## JSON modules -> Stability: 1 - Experimental +> Stability: 2 - Stable JSON files can be referenced by `import`: @@ -1129,7 +1126,7 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][]. [Dynamic `import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import [ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration [Import Attributes]: #import-attributes -[Import Attributes proposal]: https://github.com/tc39/proposal-import-attributes +[Import Attributes MDN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with [JSON modules]: #json-modules [Loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require [Module customization hooks]: module.md#customization-hooks diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 8f4b6b25d88896..044d820161a5f9 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -450,7 +450,6 @@ translators.set('builtin', function builtinStrategy(url) { // Strategy for loading a JSON file const isWindows = process.platform === 'win32'; translators.set('json', function jsonStrategy(url, source) { - emitExperimentalWarning('Importing JSON modules'); assertBufferSource(source, true, 'load'); debug(`Loading JSONModule ${url}`); const pathname = StringPrototypeStartsWith(url, 'file:') ? diff --git a/test/es-module/test-esm-json.mjs b/test/es-module/test-esm-json.mjs index 8be7b60d322573..083194ab4237b0 100644 --- a/test/es-module/test-esm-json.mjs +++ b/test/es-module/test-esm-json.mjs @@ -16,12 +16,12 @@ describe('ESM: importing JSON', () => { assert.strictEqual(secret.ofLife, 42); }); - it('should print an experimental warning', async () => { + it('should not print an experimental warning', async () => { const { code, signal, stderr } = await spawnPromisified(execPath, [ fixtures.path('/es-modules/json-modules.mjs'), ]); - assert.match(stderr, /ExperimentalWarning: Importing JSON modules/); + assert.strictEqual(stderr, ''); assert.strictEqual(code, 0); assert.strictEqual(signal, null); }); From e44f6d8dc2640ad25fa4077abcdc0a096a8e5d2d Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 16 Nov 2024 16:36:27 +0000 Subject: [PATCH 4/4] doc: add history entries for JSON modules stabilization PR-URL: https://github.com/nodejs/node/pull/55855 Refs: https://github.com/nodejs/node/pull/55333 Reviewed-By: Luigi Pinca Reviewed-By: Jacob Smith --- doc/api/esm.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/api/esm.md b/doc/api/esm.md index 0eea9ad4991054..ff5945843f324e 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -7,6 +7,9 @@ + > Stability: 2 - Stable JSON files can be referenced by `import`: