@@ -17,22 +17,17 @@ const realRunInThisContext = Script.prototype.runInThisContext;
1717const realRunInContext = Script . prototype . runInContext ;
1818
1919Script . 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
3027Script . 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