Skip to content

Commit efb9084

Browse files
cjihrigdanbev
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 ce49f90 commit efb9084

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

lib/internal/bootstrap/pre_execution.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,10 @@ function initializePolicy() {
401401
}
402402

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

411410
function initializeCJSLoader() {

src/node_native_module.cc

Lines changed: 1 addition & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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)