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
nodejs#30778.
  • Loading branch information
cjihrig committed Dec 15, 2019
1 parent ba29e27 commit 909a870
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/internal/bootstrap/pre_execution.js
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
9 changes: 9 additions & 0 deletions test/wasi/test-wasi-require-flag.js
@@ -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 909a870

Please sign in to comment.