Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
lib: lazy loading and cleanup#20734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -47,15 +47,16 @@ const { | ||
| makeRequireFunction, | ||
| addBuiltinLibsToObject | ||
| } = require('internal/modules/cjs/helpers'); | ||
| const internalUtil = require('internal/util'); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I am not mistaken it will not (easily) be possible to lazy load | ||
| const { isTypedArray } = require('internal/util/types'); | ||
| const util = require('util'); | ||
| const utilBinding = process.binding('util'); | ||
| const { | ||
| startSigintWatchdog, | ||
| stopSigintWatchdog | ||
| } = process.binding('util'); | ||
| const { inherits } = util; | ||
| const Stream = require('stream'); | ||
| const vm = require('vm'); | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
| const { Interface } = require('readline'); | ||
| const { Console } = require('console'); | ||
| const CJSModule = require('internal/modules/cjs/loader'); | ||
| @@ -72,6 +73,13 @@ const { experimentalREPLAwait } = process.binding('config'); | ||
| // Lazy-loaded. | ||
| let processTopLevelAwait; | ||
| let fs; | ||
| function lazyFs() { | ||
| if (!fs) | ||
| fs = require('fs'); | ||
| return fs; | ||
| } | ||
| const parentModule = module; | ||
| const replMap = new WeakMap(); | ||
| @@ -301,7 +309,7 @@ function REPLServer(prompt, | ||
| if (self.breakEvalOnSigint) { | ||
| // Start the SIGINT watchdog before entering raw mode so that a very | ||
| // quick Ctrl+C doesn't lead to aborting the process completely. | ||
| if (!utilBinding.startSigintWatchdog()) | ||
| if (!startSigintWatchdog()) | ||
| throw new ERR_CANNOT_WATCH_SIGINT(); | ||
| previouslyInRawMode = self._setRawMode(false); | ||
| } | ||
| @@ -325,7 +333,7 @@ function REPLServer(prompt, | ||
| // Returns true if there were pending SIGINTs *after* the script | ||
| // has terminated without being interrupted itself. | ||
| if (utilBinding.stopSigintWatchdog()) { | ||
| if (stopSigintWatchdog()) { | ||
| self.emit('SIGINT'); | ||
| } | ||
| } | ||
| @@ -397,14 +405,15 @@ function REPLServer(prompt, | ||
| self.eval = self._domain.bind(eval_); | ||
| self._domain.on('error', function debugDomainError(e) { | ||
| const { decorateErrorStack, isError: _isError } = require('internal/util'); | ||
| debug('domain error'); | ||
| const top = replMap.get(self); | ||
| const pstrace = Error.prepareStackTrace; | ||
| Error.prepareStackTrace = prepareStackTrace(pstrace); | ||
| if (typeof e === 'object') | ||
| internalUtil.decorateErrorStack(e); | ||
| decorateErrorStack(e); | ||
| Error.prepareStackTrace = pstrace; | ||
| const isError = internalUtil.isError(e); | ||
| const isError = _isError(e); | ||
| if (!self.underscoreErrAssigned) | ||
| self.lastError = e; | ||
| if (e instanceof SyntaxError && e.stack) { | ||
| @@ -1020,6 +1029,7 @@ function complete(line, callback) { | ||
| } | ||
| for (i = 0; i < paths.length; i++) { | ||
| const fs = lazyFs(); | ||
| dir = path.resolve(paths[i], subdir); | ||
| try { | ||
| files = fs.readdirSync(dir); | ||
| @@ -1428,7 +1438,7 @@ function defineDefaultCommands(repl) { | ||
| help: 'Save all evaluated commands in this REPL session to a file', | ||
| action: function(file) { | ||
| try { | ||
| fs.writeFileSync(file, this.lines.join('\n') + '\n'); | ||
| lazyFs().writeFileSync(file, this.lines.join('\n') + '\n'); | ||
| this.outputStream.write('Session saved to: ' + file + '\n'); | ||
| } catch (e) { | ||
| this.outputStream.write('Failed to save: ' + file + '\n'); | ||
| @@ -1441,6 +1451,7 @@ function defineDefaultCommands(repl) { | ||
| help: 'Load JS from a file into the REPL session', | ||
| action: function(file) { | ||
| try { | ||
| const fs = lazyFs(); | ||
| var stats = fs.statSync(file); | ||
| if (stats && stats.isFile()) { | ||
| _turnOnEditorMode(this); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pathis definitely always loaded eager and I do not see how we can prevent that as it is necessary during bootstrapping. So this should probably not be lazy loaded.