File tree Expand file tree Collapse file tree 6 files changed +22
-62
lines changed Expand file tree Collapse file tree 6 files changed +22
-62
lines changed Original file line number Diff line number Diff line change 22
33const {
44 ObjectDefineProperty,
5+ ObjectPrototypeHasOwnProperty,
56 SafeMap,
67} = primordials ;
78const {
@@ -109,55 +110,17 @@ function stripBOM(content) {
109110 return content ;
110111}
111112
112- const builtinLibs = [
113- 'assert' ,
114- 'async_hooks' ,
115- 'buffer' ,
116- 'child_process' ,
117- 'cluster' ,
118- 'crypto' ,
119- 'dgram' ,
120- 'dns' ,
121- 'domain' ,
122- 'events' ,
123- 'fs' ,
124- 'http' ,
125- 'http2' ,
126- 'https' ,
127- 'net' ,
128- 'os' ,
129- 'path' ,
130- 'perf_hooks' ,
131- 'punycode' ,
132- 'querystring' ,
133- 'readline' ,
134- 'repl' ,
135- 'stream' ,
136- 'string_decoder' ,
137- 'tls' ,
138- 'trace_events' ,
139- 'tty' ,
140- 'url' ,
141- 'util' ,
142- 'v8' ,
143- 'vm' ,
144- 'worker_threads' ,
145- 'zlib' ,
146- ] ;
147-
148- if ( internalBinding ( 'config' ) . experimentalWasi ) {
149- builtinLibs . push ( 'wasi' ) ;
150- builtinLibs . sort ( ) ;
151- }
152-
153- if ( typeof internalBinding ( 'inspector' ) . open === 'function' ) {
154- builtinLibs . push ( 'inspector' ) ;
155- builtinLibs . sort ( ) ;
156- }
157-
158113function addBuiltinLibsToObject ( object ) {
159114 // Make built-in modules available directly (loaded lazily).
160- builtinLibs . forEach ( ( name ) => {
115+ const { builtinModules } = require ( 'internal/modules/cjs/loader' ) . Module ;
116+ builtinModules . forEach ( ( name ) => {
117+ // Neither add underscored modules, nor ones that contain slashes (e.g.,
118+ // 'fs/promises') or ones that are already defined.
119+ if ( name . startsWith ( '_' ) ||
120+ name . includes ( '/' ) ||
121+ ObjectPrototypeHasOwnProperty ( object , name ) ) {
122+ return ;
123+ }
161124 // Goals of this mechanism are:
162125 // - Lazy loading of built-in modules
163126 // - Having all built-in modules available as non-enumerable properties
@@ -203,7 +166,6 @@ function normalizeReferrerURL(referrer) {
203166
204167module . exports = {
205168 addBuiltinLibsToObject,
206- builtinLibs,
207169 loadNativeModule,
208170 makeRequireFunction,
209171 normalizeReferrerURL,
Original file line number Diff line number Diff line change @@ -63,7 +63,6 @@ const {
6363} = primordials ;
6464
6565const {
66- builtinLibs,
6766 makeRequireFunction,
6867 addBuiltinLibsToObject
6968} = require ( 'internal/modules/cjs/helpers' ) ;
@@ -86,6 +85,8 @@ const {
8685} = require ( 'internal/readline/utils' ) ;
8786const { Console } = require ( 'console' ) ;
8887const CJSModule = require ( 'internal/modules/cjs/loader' ) . Module ;
88+ const builtinModules = [ ...CJSModule . builtinModules ]
89+ . filter ( ( e ) => ! e . startsWith ( '_' ) ) ;
8990const domain = require ( 'domain' ) ;
9091const debug = require ( 'internal/util/debuglog' ) . debuglog ( 'repl' ) ;
9192const {
@@ -158,7 +159,7 @@ module.paths = CJSModule._nodeModulePaths(module.filename);
158159const writer = exports . writer = ( obj ) => inspect ( obj , writer . options ) ;
159160writer . options = { ...inspect . defaultOptions , showProxy : true } ;
160161
161- exports . _builtinLibs = builtinLibs ;
162+ exports . _builtinLibs = builtinModules ;
162163
163164function REPLServer ( prompt ,
164165 stream ,
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ const expectedModules = new Set([
1717 'Internal Binding credentials' ,
1818 'Internal Binding fs' ,
1919 'Internal Binding fs_dir' ,
20- 'Internal Binding inspector' ,
2120 'Internal Binding module_wrap' ,
2221 'Internal Binding native_module' ,
2322 'Internal Binding options' ,
@@ -116,6 +115,7 @@ if (common.hasIntl) {
116115}
117116
118117if ( process . features . inspector ) {
118+ expectedModules . add ( 'Internal Binding inspector' ) ;
119119 expectedModules . add ( 'NativeModule internal/inspector_async_hook' ) ;
120120 expectedModules . add ( 'NativeModule internal/util/inspector' ) ;
121121}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ function testStrictMode() {
3939}
4040
4141function testStrictModeTerminal ( ) {
42+ if ( ! process . features . inspector ) {
43+ console . warn ( 'Test skipped: V8 inspector is disabled' ) ;
44+ return ;
45+ }
4246 // Verify that ReferenceErrors are reported in strict mode previews.
4347 const cli = initRepl ( repl . REPL_MODE_STRICT , {
4448 terminal : true
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ const {
3030const assert = require ( 'assert' ) ;
3131const path = require ( 'path' ) ;
3232const fixtures = require ( '../common/fixtures' ) ;
33+ const { builtinModules } = require ( 'module' ) ;
3334const hasInspector = process . features . inspector ;
3435
3536if ( ! common . isMainThread )
@@ -222,8 +223,9 @@ putIn.run(['.clear']);
222223
223224testMe . complete ( 'require(\'' , common . mustCall ( function ( error , data ) {
224225 assert . strictEqual ( error , null ) ;
225- repl . _builtinLibs . forEach ( function ( lib ) {
226- assert ( data [ 0 ] . includes ( lib ) , `${ lib } not found` ) ;
226+ builtinModules . forEach ( ( lib ) => {
227+ if ( ! lib . startsWith ( '_' ) )
228+ assert ( data [ 0 ] . includes ( lib ) , `${ lib } not found` ) ;
227229 } ) ;
228230} ) ) ;
229231
You can’t perform that action at this time.
0 commit comments