@@ -17,22 +17,17 @@ const realRunInThisContext = Script.prototype.runInThisContext;
17
17
const realRunInContext = Script . prototype . runInContext ;
18
18
19
19
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 ] ) ;
25
22
} else {
26
23
return realRunInThisContext . call ( this , options ) ;
27
24
}
28
25
} ;
29
26
30
27
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 ] ) ;
36
31
} else {
37
32
return realRunInContext . call ( this , contextifiedSandbox , options ) ;
38
33
}
@@ -83,19 +78,20 @@ exports.isContext = binding.isContext;
83
78
84
79
// Remove all SIGINT listeners and re-attach them after the wrapped function
85
80
// has executed, so that caught SIGINT are handled by the listeners again.
86
- function sigintHandlersWrap ( fn ) {
81
+ function sigintHandlersWrap ( fn , thisArg , argsArray ) {
87
82
// Using the internal list here to make sure `.once()` wrappers are used,
88
83
// not the original ones.
89
84
let sigintListeners = process . _events . SIGINT ;
90
- if ( ! Array . isArray ( sigintListeners ) )
91
- sigintListeners = sigintListeners ? [ sigintListeners ] : [ ] ;
92
- else
85
+
86
+ if ( Array . isArray ( sigintListeners ) )
93
87
sigintListeners = sigintListeners . slice ( ) ;
88
+ else
89
+ sigintListeners = [ sigintListeners ] ;
94
90
95
91
process . removeAllListeners ( 'SIGINT' ) ;
96
92
97
93
try {
98
- return fn ( ) ;
94
+ return fn . apply ( thisArg , argsArray ) ;
99
95
} finally {
100
96
// Add using the public methods so that the `newListener` handler of
101
97
// process can re-attach the listeners.
0 commit comments