diff options
author | cjihrig <cjihrig@gmail.com> | 2019-12-14 11:14:02 -0500 |
---|---|---|
committer | Beth Griggs <Bethany.Griggs@uk.ibm.com> | 2020-02-06 02:49:30 +0000 |
commit | d31e6d9ee6231e5c5b9210f20d1c28c5e7080565 (patch) | |
tree | 335c79356c1ccb172419188a29292206e4589b72 | |
parent | 3872a020201712546ccc9d775066097eb7c3f4c5 (diff) | |
download | node-new-d31e6d9ee6231e5c5b9210f20d1c28c5e7080565.tar.gz |
wasi: require CLI flag to require() wasi module
This commit ensures that the WASI module cannot be require()'ed
without a CLI flag while the module is still experimental.
This fixes a regression from
https://github.com/nodejs/node/pull/30778.
PR-URL: https://github.com/nodejs/node/pull/30963
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
-rw-r--r-- | lib/internal/bootstrap/pre_execution.js | 9 | ||||
-rw-r--r-- | src/node_native_module.cc | 1 | ||||
-rw-r--r-- | test/wasi/test-wasi-require-flag.js | 9 |
3 files changed, 14 insertions, 5 deletions
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 81002a3e3c..67fcfc8fbf 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -402,11 +402,10 @@ function initializePolicy() { } function initializeWASI() { - if (getOptionValue('--experimental-wasi-unstable-preview0')) { - const { NativeModule } = require('internal/bootstrap/loaders'); - const mod = NativeModule.map.get('wasi'); - mod.canBeRequiredByUsers = true; - } + const { NativeModule } = require('internal/bootstrap/loaders'); + const mod = NativeModule.map.get('wasi'); + mod.canBeRequiredByUsers = + getOptionValue('--experimental-wasi-unstable-preview0'); } function initializeCJSLoader() { diff --git a/src/node_native_module.cc b/src/node_native_module.cc index 814adb620d..43c13ea30a 100644 --- a/src/node_native_module.cc +++ b/src/node_native_module.cc @@ -98,6 +98,7 @@ void NativeModuleLoader::InitializeModuleCategories() { #endif // !HAVE_OPENSSL "sys", // Deprecated. + "wasi", // Experimental. "internal/test/binding", "internal/v8_prof_polyfill", "internal/v8_prof_processor", diff --git a/test/wasi/test-wasi-require-flag.js b/test/wasi/test-wasi-require-flag.js new file mode 100644 index 0000000000..0a52ea952d --- /dev/null +++ b/test/wasi/test-wasi-require-flag.js @@ -0,0 +1,9 @@ +'use strict'; +// This test verifies that the WASI module cannot be require()'ed without a +// CLI flag while it is still experimental. +require('../common'); +const assert = require('assert'); + +assert.throws(() => { + require('wasi'); +}, /^Error: Cannot find module 'wasi'/); |