Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 33a0ad6

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(node): fix#1164, don't patch uncaughtException to prevent endless loop (#1170)
update yarn
1 parent 9ed5712 commit 33a0ad6

4 files changed

Lines changed: 981 additions & 8 deletions

File tree

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sudo: false
33
dist: trusty
44
cache: yarn
55
node_js:
6-
- 8
6+
- 10
77
env:
88
global:
99
- BROWSER_PROVIDER_READY_FILE=/tmp/sauce-connect-ready

‎lib/common/events.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @suppress {missingRequire}
1111
*/
1212

13-
import{ADD_EVENT_LISTENER_STR,attachOriginToPatched,FALSE_STR,ObjectGetPrototypeOf,REMOVE_EVENT_LISTENER_STR,TRUE_STR,ZONE_SYMBOL_PREFIX,zoneSymbol}from'./utils';
13+
import{ADD_EVENT_LISTENER_STR,attachOriginToPatched,FALSE_STR,isNode,ObjectGetPrototypeOf,REMOVE_EVENT_LISTENER_STR,TRUE_STR,ZONE_SYMBOL_PREFIX,zoneSymbol}from'./utils';
1414

1515
/** @internal **/
1616
interfaceEventTaskDataextendsTaskData{
@@ -330,10 +330,15 @@ export function patchEventTarget(
330330
returnTarget=false,prepend=false){
331331
returnfunction(){
332332
consttarget=this||_global;
333+
consteventName=arguments[0];
333334
letdelegate=arguments[1];
334335
if(!delegate){
335336
returnnativeListener.apply(this,arguments);
336337
}
338+
if(isNode&&eventName==='uncaughtException'){
339+
// don't patch uncaughtException of nodejs to prevent endless loop
340+
returnnativeListener.apply(this,arguments);
341+
}
337342

338343
// don't create the bind delegate function for handleEvent
339344
// case here to improve addEventListener performance
@@ -350,7 +355,6 @@ export function patchEventTarget(
350355
return;
351356
}
352357

353-
consteventName=arguments[0];
354358
constoptions=arguments[2];
355359

356360
if(blackListedEvents){

‎test/node/events.spec.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,10 @@ describe('nodejs EventEmitter', () => {
183183
expect(emitter.listeners('removeListener').length).toBe(0);
184184
});
185185
});
186-
});
186+
it('should not enter endless loop when register uncaughtException to process',()=>{
187+
require('domain');
188+
zoneA.run(()=>{
189+
process.on('uncaughtException',function(){});
190+
});
191+
});
192+
});

0 commit comments

Comments
 (0)