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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: David Carlier <[email protected]>
  • Loading branch information
cjihrig authored and targos committed Jan 14, 2020
1 parent f6acf9a commit 5d2ae05
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 @@ -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() {
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 5d2ae05

Please sign in to comment.