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 <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>
1 parent f6acf9a commit 5d2ae05

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎lib/internal/bootstrap/pre_execution.js‎

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

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

412411
functioninitializeCJSLoader(){

‎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",
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+
constassert=require('assert');
6+
7+
assert.throws(()=>{
8+
require('wasi');
9+
},/^Error:Cannotfindmodule'wasi'/);

0 commit comments

Comments
 (0)