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

Commit

Permalink
fix(node): fix #1164, don't patch uncaughtException to prevent endles…
Browse files Browse the repository at this point in the history
…s loop (#1170)

update yarn
  • Loading branch information
JiaLiPassion authored and mhevery committed Dec 12, 2018
1 parent 9ed5712 commit 33a0ad6
Show file tree
Hide file tree
Showing 4 changed files with 981 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: false
dist: trusty
cache: yarn
node_js:
- 8
- 10
env:
global:
- BROWSER_PROVIDER_READY_FILE=/tmp/sauce-connect-ready
Expand Down
8 changes: 6 additions & 2 deletions lib/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @suppress {missingRequire}
*/

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

/** @internal **/
interface EventTaskData extends TaskData {
Expand Down Expand Up @@ -330,10 +330,15 @@ export function patchEventTarget(
returnTarget = false, prepend = false) {
return function() {
const target = this || _global;
const eventName = arguments[0];
let delegate = arguments[1];
if (!delegate) {
return nativeListener.apply(this, arguments);
}
if (isNode && eventName === 'uncaughtException') {
// don't patch uncaughtException of nodejs to prevent endless loop
return nativeListener.apply(this, arguments);
}

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

const eventName = arguments[0];
const options = arguments[2];

if (blackListedEvents) {
Expand Down
8 changes: 7 additions & 1 deletion test/node/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,10 @@ describe('nodejs EventEmitter', () => {
expect(emitter.listeners('removeListener').length).toBe(0);
});
});
});
it('should not enter endless loop when register uncaughtException to process', () => {
require('domain');
zoneA.run(() => {
process.on('uncaughtException', function() {});
});
});
});
Loading

0 comments on commit 33a0ad6

Please sign in to comment.