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>
This commit is contained in:
cjihrig authored and Myles Borins committed 2019-12-17 18:21:12 -05:00
1 parent 5ca29d860b
commit 54d51dbe4c
3 files changed
+14 -5

No files matched your search

+4 -5
View File
@@ -401,11 +401,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() {
+1
View File
@@ -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",
+9
View File
@@ -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'/);