Skip to content

Commit

Permalink
wasi: require CLI flag to require() wasi module
Browse files Browse the repository at this point in the history
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
#30778.

PR-URL: #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>
  • Loading branch information
cjihrig authored and danbev committed Dec 17, 2019
1 parent ce49f90 commit efb9084
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/node_native_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions test/wasi/test-wasi-require-flag.js
Original file line number Diff line number Diff line change
@@ -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'/);

0 comments on commit efb9084

Please sign in to comment.