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

Commit fcef80d

Browse files
alxhubmhevery
authored andcommitted
fix(browser): patch Window when EventTarget is missing. (#368)
In browsers without EventTarget, window.addEventListener() is not patched. Fixes #367.
1 parent 0da535f commit fcef80d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/browser/event-target.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {patchEventTargetMethods} from '../common/utils';
22

33
const WTF_ISSUE_555 = 'Anchor,Area,Audio,BR,Base,BaseFont,Body,Button,Canvas,Content,DList,Directory,Div,Embed,FieldSet,Font,Form,Frame,FrameSet,HR,Head,Heading,Html,IFrame,Image,Input,Keygen,LI,Label,Legend,Link,Map,Marquee,Media,Menu,Meta,Meter,Mod,OList,Object,OptGroup,Option,Output,Paragraph,Pre,Progress,Quote,Script,Select,Source,Span,Style,TableCaption,TableCell,TableCol,Table,TableRow,TableSection,TextArea,Title,Track,UList,Unknown,Video';
4-
const NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload,IDBRequest,IDBOpenDBRequest,IDBDatabase,IDBTransaction,IDBCursor,DBIndex'.split(',');
4+
const NO_EVENT_TARGET = 'ApplicationCache,EventSource,FileReader,InputMethodContext,MediaController,MessagePort,Node,Performance,SVGElementInstance,SharedWorker,TextTrack,TextTrackCue,TextTrackList,WebKitNamedFlow,Window,Worker,WorkerGlobalScope,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload,IDBRequest,IDBOpenDBRequest,IDBDatabase,IDBTransaction,IDBCursor,DBIndex'.split(',');
55
const EVENT_TARGET = 'EventTarget';
66

77
export function eventTargetPatch(_global) {

test/browser/browser.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import {ifEnvSupports} from '../test-util';
2+
3+
function windowPrototype() {
4+
return !!(global['Window'] && global['Window'].prototype);
5+
}
6+
17
describe('Zone', function () {
28
var rootZone = Zone.current;
39

@@ -72,6 +78,28 @@ describe('Zone', function () {
7278
expect(eventListenerSpy).toHaveBeenCalled();
7379
});
7480

81+
it('should support addEventListener on window', ifEnvSupports(windowPrototype, function () {
82+
var hookSpy = jasmine.createSpy('hook');
83+
var eventListenerSpy = jasmine.createSpy('eventListener');
84+
var zone = rootZone.fork({
85+
name: 'spy',
86+
onScheduleTask: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
87+
task: Task): any => {
88+
hookSpy();
89+
return parentZoneDelegate.scheduleTask(targetZone, task);
90+
}
91+
});
92+
93+
zone.run(function() {
94+
window.addEventListener('click', eventListenerSpy);
95+
});
96+
97+
window.dispatchEvent(clickEvent);
98+
99+
expect(hookSpy).toHaveBeenCalled();
100+
expect(eventListenerSpy).toHaveBeenCalled();
101+
}));
102+
75103
it('should support removeEventListener', function () {
76104
var hookSpy = jasmine.createSpy('hook');
77105
var eventListenerSpy = jasmine.createSpy('eventListener');

0 commit comments

Comments
 (0)