| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 29104f5 commit 640353a
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ const { addBuiltinLibsToObject } = require('internal/modules/cjs/helpers'); | |||
| 16 | 16 | const { getOptionValue } = require('internal/options'); | |
| 17 | 17 | ||
| 18 | 18 | prepareMainThreadExecution(); | |
| 19 | - addBuiltinLibsToObject(globalThis); | ||
| 19 | + addBuiltinLibsToObject(globalThis, '<eval>'); | ||
| 20 | 20 | markBootstrapComplete(); | |
| 21 | 21 | ||
| 22 | 22 | const source = getOptionValue('--eval'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -131,9 +131,16 @@ function stripBOM(content) { | |||
| 131 | 131 | return content; | |
| 132 | 132 | } | |
| 133 | 133 | ||
| 134 | - function addBuiltinLibsToObject(object) { | ||
| 134 | + function addBuiltinLibsToObject(object, dummyModuleName) { | ||
| 135 | 135 | // Make built-in modules available directly (loaded lazily). | |
| 136 | - const { builtinModules } = require('internal/modules/cjs/loader').Module; | ||
| 136 | + const Module = require('internal/modules/cjs/loader').Module; | ||
| 137 | + const { builtinModules } = Module; | ||
| 138 | + | ||
| 139 | + // To require built-in modules in user-land and ignore modules whose | ||
| 140 | + // `canBeRequiredByUsers` is false. So we create a dummy module object and not | ||
| 141 | + // use `require()` directly. | ||
| 142 | + const dummyModule = new Module(dummyModuleName); | ||
| 143 | + | ||
| 137 | 144 | ArrayPrototypeForEach(builtinModules, (name) => { | |
| 138 | 145 | // Neither add underscored modules, nor ones that contain slashes (e.g., | |
| 139 | 146 | // 'fs/promises') or ones that are already defined. | |
@@ -157,7 +164,7 @@ function addBuiltinLibsToObject(object) { | |||
| 157 | 164 | ||
| 158 | 165 | ObjectDefineProperty(object, name, { | |
| 159 | 166 | get: () => { | |
| 160 | - const lib = require(name); | ||
| 167 | + const lib = dummyModule.require(name); | ||
| 161 | 168 | ||
| 162 | 169 | // Disable the current getter/setter and set up a new | |
| 163 | 170 | // non-enumerable property. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1098,7 +1098,7 @@ REPLServer.prototype.createContext = function() { | |||
| 1098 | 1098 | value: makeRequireFunction(replModule) | |
| 1099 | 1099 | }); | |
| 1100 | 1100 | ||
| 1101 | - addBuiltinLibsToObject(context); | ||
| 1101 | + addBuiltinLibsToObject(context, '<REPL>'); | ||
| 1102 | 1102 | ||
| 1103 | 1103 | return context; | |
| 1104 | 1104 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,32 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const cp = require('child_process'); | ||
| 6 | + | ||
| 7 | + function runREPLWithAdditionalFlags(flags) { | ||
| 8 | + // Use -i to force node into interactive mode, despite stdout not being a TTY | ||
| 9 | + const args = ['-i'].concat(flags); | ||
| 10 | + const ret = cp.execFileSync(process.execPath, args, { | ||
| 11 | + input: 'require(\'events\');\nrequire(\'wasi\');', | ||
| 12 | + encoding: 'utf8', | ||
| 13 | + }); | ||
| 14 | + return ret; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + // Run REPL in normal mode. | ||
| 18 | + let stdout = runREPLWithAdditionalFlags([]); | ||
| 19 | + assert.match(stdout, /\[Function: EventEmitter\] {/); | ||
| 20 | + assert.match( | ||
| 21 | + stdout, | ||
| 22 | + /Uncaught Error: Cannot find module 'wasi'[\w\W]+- <repl>\n/); | ||
| 23 | + | ||
| 24 | + // Run REPL with '--experimental-wasi-unstable-preview1' | ||
| 25 | + stdout = runREPLWithAdditionalFlags([ | ||
| 26 | + '--experimental-wasi-unstable-preview1', | ||
| 27 | + ]); | ||
| 28 | + assert.match(stdout, /\[Function: EventEmitter\] {/); | ||
| 29 | + assert.doesNotMatch( | ||
| 30 | + stdout, | ||
| 31 | + /Uncaught Error: Cannot find module 'wasi'[\w\W]+- <repl>\n/); | ||
| 32 | + assert.match(stdout, /{ WASI: \[class WASI\] }/); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments