Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2641cd4

Browse filesBrowse files
TrottItalo A. Casas
authored andcommitted
vm: improve performance of vm.runIn*()
Optimize for common cases in vm.runInContext() and vm.runInThisContext(). PR-URL: #10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
1 parent 47c0953 commit 2641cd4
Copy full SHA for 2641cd4

File tree

Expand file treeCollapse file tree

1 file changed

+11
-15
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-15
lines changed
Open diff view settings
Collapse file

‎lib/vm.js‎

Copy file name to clipboardExpand all lines: lib/vm.js
+11-15Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,17 @@ const realRunInThisContext = Script.prototype.runInThisContext;
1717
const realRunInContext = Script.prototype.runInContext;
1818

1919
Script.prototype.runInThisContext = function(options) {
20-
if (options && options.breakOnSigint) {
21-
const realRunInThisContextScript = () => {
22-
return realRunInThisContext.call(this, options);
23-
};
24-
return sigintHandlersWrap(realRunInThisContextScript);
20+
if (options && options.breakOnSigint && process._events.SIGINT) {
21+
return sigintHandlersWrap(realRunInThisContext, this, [options]);
2522
} else {
2623
return realRunInThisContext.call(this, options);
2724
}
2825
};
2926

3027
Script.prototype.runInContext = function(contextifiedSandbox, options) {
31-
if (options && options.breakOnSigint) {
32-
const realRunInContextScript = () => {
33-
return realRunInContext.call(this, contextifiedSandbox, options);
34-
};
35-
return sigintHandlersWrap(realRunInContextScript);
28+
if (options && options.breakOnSigint && process._events.SIGINT) {
29+
return sigintHandlersWrap(realRunInContext, this,
30+
[contextifiedSandbox, options]);
3631
} else {
3732
return realRunInContext.call(this, contextifiedSandbox, options);
3833
}
@@ -83,19 +78,20 @@ exports.isContext = binding.isContext;
8378

8479
// Remove all SIGINT listeners and re-attach them after the wrapped function
8580
// has executed, so that caught SIGINT are handled by the listeners again.
86-
function sigintHandlersWrap(fn) {
81+
function sigintHandlersWrap(fn, thisArg, argsArray) {
8782
// Using the internal list here to make sure `.once()` wrappers are used,
8883
// not the original ones.
8984
let sigintListeners = process._events.SIGINT;
90-
if (!Array.isArray(sigintListeners))
91-
sigintListeners = sigintListeners ? [sigintListeners] : [];
92-
else
85+
86+
if (Array.isArray(sigintListeners))
9387
sigintListeners = sigintListeners.slice();
88+
else
89+
sigintListeners = [sigintListeners];
9490

9591
process.removeAllListeners('SIGINT');
9692

9793
try {
98-
return fn();
94+
return fn.apply(thisArg, argsArray);
9995
} finally {
10096
// Add using the public methods so that the `newListener` handler of
10197
// process can re-attach the listeners.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.