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

Commit

Permalink
fix(EventTarget): apply the patch even if Window is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Oct 6, 2015
1 parent a23d61a commit 32c6df9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/patch/event-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -25,24 +25,29 @@ function apply() {
'TextTrackCue',
'TextTrackList',
'WebKitNamedFlow',
'Window',
'Worker',
'WorkerGlobalScope',
'XMLHttpRequest',
'XMLHttpRequestEventTarget',
'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);
}
}
}

Expand Down

0 comments on commit 32c6df9

Please sign in to comment.