Skip to content

Commit 5d2ae05

Browse files
cjihrigtargos
authored andcommitted
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 #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]>
1 parent f6acf9a commit 5d2ae05

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

lib/internal/bootstrap/pre_execution.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,10 @@ function initializePolicy() {
402402
}
403403

404404
function initializeWASI() {
405-
if (getOptionValue('--experimental-wasi-unstable-preview0')) {
406-
const { NativeModule } = require('internal/bootstrap/loaders');
407-
const mod = NativeModule.map.get('wasi');
408-
mod.canBeRequiredByUsers = true;
409-
}
405+
const { NativeModule } = require('internal/bootstrap/loaders');
406+
const mod = NativeModule.map.get('wasi');
407+
mod.canBeRequiredByUsers =
408+
getOptionValue('--experimental-wasi-unstable-preview0');
410409
}
411410

412411
function initializeCJSLoader() {

src/node_native_module.cc

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void NativeModuleLoader::InitializeModuleCategories() {
9898
#endif // !HAVE_OPENSSL
9999

100100
"sys", // Deprecated.
101+
"wasi", // Experimental.
101102
"internal/test/binding",
102103
"internal/v8_prof_polyfill",
103104
"internal/v8_prof_processor",

test/wasi/test-wasi-require-flag.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
// This test verifies that the WASI module cannot be require()'ed without a
3+
// CLI flag while it is still experimental.
4+
require('../common');
5+
const assert = require('assert');
6+
7+
assert.throws(() => {
8+
require('wasi');
9+
}, /^Error: Cannot find module 'wasi'/);

0 commit comments

Comments
 (0)