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

Commit

Permalink
fix(browser): patch Window when EventTarget is missing.
Browse files Browse the repository at this point in the history
In browsers without EventTarget, window.addEventListener() is not patched.

Fixes #367.
  • Loading branch information
alxhub committed Jun 28, 2016
1 parent bf77fbb commit f81e7b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/browser/event-target.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {patchEventTargetMethods} from '../common/utils';

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';
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(',');
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(',');
const EVENT_TARGET = 'EventTarget';

export function eventTargetPatch(_global) {
Expand Down
22 changes: 22 additions & 0 deletions test/browser/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ describe('Zone', function () {
expect(eventListenerSpy).toHaveBeenCalled();
});

it('should support addEventListener on window', function () {
var hookSpy = jasmine.createSpy('hook');
var eventListenerSpy = jasmine.createSpy('eventListener');
var zone = rootZone.fork({
name: 'spy',
onScheduleTask: (parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
task: Task): any => {
hookSpy();
return parentZoneDelegate.scheduleTask(targetZone, task);
}
});

zone.run(function() {
window.addEventListener('click', eventListenerSpy);
});

window.dispatchEvent(clickEvent);

expect(hookSpy).toHaveBeenCalled();
expect(eventListenerSpy).toHaveBeenCalled();
});

it('should support removeEventListener', function () {
var hookSpy = jasmine.createSpy('hook');
var eventListenerSpy = jasmine.createSpy('eventListener');
Expand Down

0 comments on commit f81e7b0

Please sign in to comment.