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

Commit

Permalink
fix(event): fix #911, in IE, event handler event maybe undefined (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion authored and mhevery committed Sep 27, 2017
1 parent 418a583 commit 4ba5d97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export function patchEventTarget(

// global shared zoneAwareCallback to handle all event callback with capture = false
const globalZoneAwareCallback = function(event: Event) {
// https://github.com/angular/zone.js/issues/911, in IE, sometimes
// event will be undefined, so we need to use window.event
event = event || _global.event;
if (!event) {
return;
}
Expand Down Expand Up @@ -123,6 +126,9 @@ export function patchEventTarget(

// global shared zoneAwareCallback to handle all event callback with capture = true
const globalZoneAwareCaptureCallback = function(event: Event) {
// https://github.com/angular/zone.js/issues/911, in IE, sometimes
// event will be undefined, so we need to use window.event
event = event || _global.event;
if (!event) {
return;
}
Expand Down
9 changes: 7 additions & 2 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,20 @@ export const isMix: boolean = typeof _global.process !== 'undefined' &&
{}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
!!(typeof window !== 'undefined' && (window as any)['HTMLElement']);

const ON_PROPERTY_HANDLER_SYMBOL = zoneSymbol('onPropertyHandler');
const zoneSymbolEventNames: {[eventName: string]: string} = {};

const wrapFn = function(event: Event) {
// https://github.com/angular/zone.js/issues/911, in IE, sometimes
// event will be undefined, so we need to use window.event
event = event || _global.event;
if (!event) {
return;
}
let eventNameSymbol = zoneSymbolEventNames[event.type];
if (!eventNameSymbol) {
eventNameSymbol = zoneSymbolEventNames[event.type] = zoneSymbol('ON_PROPERTY' + event.type);
}
const target = this || event && event.target || _global;
const target = this || event.target || _global;
const listener = target[eventNameSymbol];
let result = listener && listener.apply(this, arguments);

Expand Down

0 comments on commit 4ba5d97

Please sign in to comment.