From 32c6df97992930d4a73820c719be02c44b6cdefe Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 6 Oct 2015 10:13:06 -0700 Subject: [PATCH] fix(EventTarget): apply the patch even if `Window` is not defined --- lib/patch/event-target.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/patch/event-target.js b/lib/patch/event-target.js index 441f8c810..c419587a4 100644 --- a/lib/patch/event-target.js +++ b/lib/patch/event-target.js @@ -10,7 +10,7 @@ function apply() { // Note: EventTarget is not available in all browsers, // if it's not available, we instead patch the APIs in the IDL that inherit from EventTarget } else { - var apis = [ + var apis = [ 'ApplicationCache', 'EventSource', 'FileReader', @@ -25,7 +25,6 @@ function apply() { 'TextTrackCue', 'TextTrackList', 'WebKitNamedFlow', - 'Window', 'Worker', 'WorkerGlobalScope', 'XMLHttpRequest', @@ -33,16 +32,22 @@ function apply() { 'XMLHttpRequestUpload' ]; - apis.forEach(function(thing) { - var obj = global[thing] && global[thing].prototype; + apis.forEach(function(api) { + var proto = global[api] && global[api].prototype; // Some browsers e.g. Android 4.3's don't actually implement // the EventTarget methods for all of these e.g. FileReader. - // In this case, there is nothing to patch. - if (obj && obj.addEventListener) { - utils.patchEventTargetMethods(obj); + // In this case, there is nothing to patch. + if (proto && proto.addEventListener) { + utils.patchEventTargetMethods(proto); } }); + + // Patch the methods on `window` instead of `Window.prototype` + // `Window` is not accessible on Android 4.3 + if (typeof(window) !== 'undefined') { + utils.patchEventTargetMethods(window); + } } }