| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 052e095 commit fe66e9d
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2985,6 +2985,12 @@ An attempt was made to use something that was already closed. | |||
| 2985 | 2985 | While using the Performance Timing API (`perf_hooks`), no valid performance | |
| 2986 | 2986 | entry types are found. | |
| 2987 | 2987 | ||
| 2988 | + <a id="ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG"></a> | ||
| 2989 | + | ||
| 2990 | + ### `ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG` | ||
| 2991 | + | ||
| 2992 | + A dynamic import callback was invoked without `--experimental-vm-modules`. | ||
| 2993 | + | ||
| 2988 | 2994 | <a id="ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING"></a> | |
| 2989 | 2995 | ||
| 2990 | 2996 | ### `ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,7 +98,9 @@ changes: | |||
| 98 | 98 | when `import()` is called. If this option is not specified, calls to | |
| 99 | 99 | `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. | |
| 100 | 100 | This option is part of the experimental modules API. We do not recommend | |
| 101 | - using it in a production environment. | ||
| 101 | + using it in a production environment. If `--experimental-vm-modules` isn't | ||
| 102 | + set, this callback will be ignored and calls to `import()` will reject with | ||
| 103 | + [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][]. | ||
| 102 | 104 | * `specifier` {string} specifier passed to `import()` | |
| 103 | 105 | * `script` {vm.Script} | |
| 104 | 106 | * `importAttributes` {Object} The `"assert"` value passed to the | |
@@ -765,6 +767,9 @@ changes: | |||
| 765 | 767 | * `importModuleDynamically` {Function} Called during evaluation of this module | |
| 766 | 768 | when `import()` is called. If this option is not specified, calls to | |
| 767 | 769 | `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. | |
| 770 | + If `--experimental-vm-modules` isn't set, this callback will be ignored | ||
| 771 | + and calls to `import()` will reject with | ||
| 772 | + [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][]. | ||
| 768 | 773 | * `specifier` {string} specifier passed to `import()` | |
| 769 | 774 | * `module` {vm.Module} | |
| 770 | 775 | * `importAttributes` {Object} The `"assert"` value passed to the | |
@@ -1022,7 +1027,9 @@ changes: | |||
| 1022 | 1027 | when `import()` is called. If this option is not specified, calls to | |
| 1023 | 1028 | `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. | |
| 1024 | 1029 | This option is part of the experimental modules API, and should not be | |
| 1025 | - considered stable. | ||
| 1030 | + considered stable. If `--experimental-vm-modules` isn't | ||
| 1031 | + set, this callback will be ignored and calls to `import()` will reject with | ||
| 1032 | + [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][]. | ||
| 1026 | 1033 | * `specifier` {string} specifier passed to `import()` | |
| 1027 | 1034 | * `function` {Function} | |
| 1028 | 1035 | * `importAttributes` {Object} The `"assert"` value passed to the | |
@@ -1246,7 +1253,9 @@ changes: | |||
| 1246 | 1253 | when `import()` is called. If this option is not specified, calls to | |
| 1247 | 1254 | `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. | |
| 1248 | 1255 | This option is part of the experimental modules API. We do not recommend | |
| 1249 | - using it in a production environment. | ||
| 1256 | + using it in a production environment. If `--experimental-vm-modules` isn't | ||
| 1257 | + set, this callback will be ignored and calls to `import()` will reject with | ||
| 1258 | + [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][]. | ||
| 1250 | 1259 | * `specifier` {string} specifier passed to `import()` | |
| 1251 | 1260 | * `script` {vm.Script} | |
| 1252 | 1261 | * `importAttributes` {Object} The `"assert"` value passed to the | |
@@ -1345,7 +1354,9 @@ changes: | |||
| 1345 | 1354 | when `import()` is called. If this option is not specified, calls to | |
| 1346 | 1355 | `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. | |
| 1347 | 1356 | This option is part of the experimental modules API. We do not recommend | |
| 1348 | - using it in a production environment. | ||
| 1357 | + using it in a production environment. If `--experimental-vm-modules` isn't | ||
| 1358 | + set, this callback will be ignored and calls to `import()` will reject with | ||
| 1359 | + [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][]. | ||
| 1349 | 1360 | * `specifier` {string} specifier passed to `import()` | |
| 1350 | 1361 | * `script` {vm.Script} | |
| 1351 | 1362 | * `importAttributes` {Object} The `"assert"` value passed to the | |
@@ -1425,7 +1436,9 @@ changes: | |||
| 1425 | 1436 | when `import()` is called. If this option is not specified, calls to | |
| 1426 | 1437 | `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. | |
| 1427 | 1438 | This option is part of the experimental modules API. We do not recommend | |
| 1428 | - using it in a production environment. | ||
| 1439 | + using it in a production environment. If `--experimental-vm-modules` isn't | ||
| 1440 | + set, this callback will be ignored and calls to `import()` will reject with | ||
| 1441 | + [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][]. | ||
| 1429 | 1442 | * `specifier` {string} specifier passed to `import()` | |
| 1430 | 1443 | * `script` {vm.Script} | |
| 1431 | 1444 | * `importAttributes` {Object} The `"assert"` value passed to the | |
@@ -1589,6 +1602,7 @@ are not controllable through the timeout either. | |||
| 1589 | 1602 | [Source Text Module Record]: https://tc39.es/ecma262/#sec-source-text-module-records | |
| 1590 | 1603 | [Synthetic Module Record]: https://heycam.github.io/webidl/#synthetic-module-records | |
| 1591 | 1604 | [V8 Embedder's Guide]: https://v8.dev/docs/embed#contexts | |
| 1605 | + [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`]: errors.md#err_vm_dynamic_import_callback_missing_flag | ||
| 1592 | 1606 | [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`]: errors.md#err_vm_dynamic_import_callback_missing | |
| 1593 | 1607 | [`ERR_VM_MODULE_STATUS`]: errors.md#err_vm_module_status | |
| 1594 | 1608 | [`Error`]: errors.md#class-error | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1716,6 +1716,9 @@ E('ERR_VALID_PERFORMANCE_ENTRY_TYPE', | |||
| 1716 | 1716 | 'At least one valid performance entry type is required', Error); | |
| 1717 | 1717 | E('ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING', | |
| 1718 | 1718 | 'A dynamic import callback was not specified.', TypeError); | |
| 1719 | + E('ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG', | ||
| 1720 | + 'A dynamic import callback was invoked without --experimental-vm-modules', | ||
| 1721 | + TypeError); | ||
| 1719 | 1722 | E('ERR_VM_MODULE_ALREADY_LINKED', 'Module has already been linked', Error); | |
| 1720 | 1723 | E('ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA', | |
| 1721 | 1724 | 'Cached data cannot be created for a module which has been evaluated', Error); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,9 +14,11 @@ const { | |||
| 14 | 14 | } = internalBinding('util'); | |
| 15 | 15 | const { | |
| 16 | 16 | default_host_defined_options, | |
| 17 | + vm_dynamic_import_missing_flag, | ||
| 17 | 18 | } = internalBinding('symbols'); | |
| 18 | 19 | ||
| 19 | 20 | const { | |
| 21 | + ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG, | ||
| 20 | 22 | ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING, | |
| 21 | 23 | ERR_INVALID_ARG_VALUE, | |
| 22 | 24 | } = require('internal/errors').codes; | |
@@ -132,7 +134,8 @@ const moduleRegistries = new SafeWeakMap(); | |||
| 132 | 134 | */ | |
| 133 | 135 | function registerModule(referrer, registry) { | |
| 134 | 136 | const idSymbol = referrer[host_defined_option_symbol]; | |
| 135 | - if (idSymbol === default_host_defined_options) { | ||
| 137 | + if (idSymbol === default_host_defined_options || | ||
| 138 | + idSymbol === vm_dynamic_import_missing_flag) { | ||
| 136 | 139 | // The referrer is compiled without custom callbacks, so there is | |
| 137 | 140 | // no registry to hold on to. We'll throw | |
| 138 | 141 | // ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING when a callback is | |
@@ -173,6 +176,9 @@ async function importModuleDynamicallyCallback(symbol, specifier, attributes) { | |||
| 173 | 176 | return importModuleDynamically(specifier, callbackReferrer, attributes); | |
| 174 | 177 | } | |
| 175 | 178 | } | |
| 179 | + if (symbol === vm_dynamic_import_missing_flag) { | ||
| 180 | + throw new ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG(); | ||
| 181 | + } | ||
| 176 | 182 | throw new ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING(); | |
| 177 | 183 | } | |
| 178 | 184 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,12 +15,18 @@ const { | |||
| 15 | 15 | } = ContextifyScript.prototype; | |
| 16 | 16 | const { | |
| 17 | 17 | default_host_defined_options, | |
| 18 | + vm_dynamic_import_missing_flag, | ||
| 18 | 19 | } = internalBinding('symbols'); | |
| 19 | 20 | const { | |
| 20 | 21 | validateFunction, | |
| 21 | 22 | validateObject, | |
| 22 | 23 | } = require('internal/validators'); | |
| 23 | 24 | ||
| 25 | + const { | ||
| 26 | + getOptionValue, | ||
| 27 | + } = require('internal/options'); | ||
| 28 | + | ||
| 29 | + | ||
| 24 | 30 | function isContext(object) { | |
| 25 | 31 | validateObject(object, 'object', { __proto__: null, allowArray: true }); | |
| 26 | 32 | ||
@@ -40,6 +46,16 @@ function getHostDefinedOptionId(importModuleDynamically, filename) { | |||
| 40 | 46 | // compilation cache can be hit. | |
| 41 | 47 | return default_host_defined_options; | |
| 42 | 48 | } | |
| 49 | + // We should've thrown here immediately when we introduced | ||
| 50 | + // --experimental-vm-modules and importModuleDynamically, but since | ||
| 51 | + // users are already using this callback to throw a similar error, | ||
| 52 | + // we also defer the error to the time when an actual import() is called | ||
| 53 | + // to avoid breaking them. To ensure that the isolate compilation | ||
| 54 | + // cache can still be hit, use a constant sentinel symbol here. | ||
| 55 | + if (!getOptionValue('--experimental-vm-modules')) { | ||
| 56 | + return vm_dynamic_import_missing_flag; | ||
| 57 | + } | ||
| 58 | + | ||
| 43 | 59 | return Symbol(filename); | |
| 44 | 60 | } | |
| 45 | 61 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,8 @@ | |||
| 44 | 44 | V(owner_symbol, "owner_symbol") \ | |
| 45 | 45 | V(onpskexchange_symbol, "onpskexchange") \ | |
| 46 | 46 | V(resource_symbol, "resource_symbol") \ | |
| 47 | - V(trigger_async_id_symbol, "trigger_async_id_symbol") | ||
| 47 | + V(trigger_async_id_symbol, "trigger_async_id_symbol") \ | ||
| 48 | + V(vm_dynamic_import_missing_flag, "vm_dynamic_import_missing_flag") | ||
| 48 | 49 | ||
| 49 | 50 | // Strings are per-isolate primitives but Environment proxies them | |
| 50 | 51 | // for the sake of convenience. Strings should be ASCII-only. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const { Script, compileFunction } = require('vm'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + assert( | ||
| 8 | + !process.execArgv.includes('--experimental-vm-modules'), | ||
| 9 | + 'This test must be run without --experimental-vm-modules'); | ||
| 10 | + | ||
| 11 | + assert.rejects(async () => { | ||
| 12 | + const script = new Script('import("fs")', { | ||
| 13 | + importModuleDynamically: common.mustNotCall(), | ||
| 14 | + }); | ||
| 15 | + const imported = script.runInThisContext(); | ||
| 16 | + await imported; | ||
| 17 | + }, { | ||
| 18 | + code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG' | ||
| 19 | + }).then(common.mustCall()); | ||
| 20 | + | ||
| 21 | + assert.rejects(async () => { | ||
| 22 | + const imported = compileFunction('return import("fs")', [], { | ||
| 23 | + importModuleDynamically: common.mustNotCall(), | ||
| 24 | + })(); | ||
| 25 | + await imported; | ||
| 26 | + }, { | ||
| 27 | + code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG' | ||
| 28 | + }).then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments