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

File tree

4 files changed

+981
-8
lines changed

4 files changed

+981
-8
lines changed

.travis.yml

+1-1
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

+6-2
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
interface EventTaskData extends TaskData {
@@ -330,10 +330,15 @@ export function patchEventTarget(
330330
returnTarget = false, prepend = false) {
331331
return function() {
332332
const target = this || _global;
333+
const eventName = arguments[0];
333334
let delegate = arguments[1];
334335
if (!delegate) {
335336
return nativeListener.apply(this, arguments);
336337
}
338+
if (isNode && eventName === 'uncaughtException') {
339+
// don't patch uncaughtException of nodejs to prevent endless loop
340+
return nativeListener.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-
const eventName = arguments[0];
354358
const options = arguments[2];
355359

356360
if (blackListedEvents) {

test/node/events.spec.ts

+7-1
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)