Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasi: require CLI flag to require() wasi module #30963

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'/);