66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { patchEventTargetMethods } from '../common/utils' ;
9+ import { FALSE_STR , globalSources , patchEventTargetMethods , TRUE_STR , ZONE_SYMBOL_PREFIX , zoneSymbolEventNames } from '../common/events' ;
10+ import { attachOriginToPatched , isIEOrEdge , zoneSymbol } from '../common/utils' ;
1011
11- const WTF_ISSUE_555 =
12- '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' ;
13- const NO_EVENT_TARGET =
14- '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,WebSocket'
15- . split ( ',' ) ;
16- const EVENT_TARGET = 'EventTarget' ;
12+ import { eventNames } from './property-descriptor' ;
13+
14+ export function eventTargetPatch ( _global : any , api : _ZonePrivate ) {
15+ const WTF_ISSUE_555 =
16+ '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' ;
17+ const NO_EVENT_TARGET =
18+ '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,WebSocket'
19+ . split ( ',' ) ;
20+ const EVENT_TARGET = 'EventTarget' ;
1721
18- export function eventTargetPatch ( _global : any ) {
1922 let apis = [ ] ;
2023 const isWtf = _global [ 'wtf' ] ;
24+ const WTF_ISSUE_555_ARRAY = WTF_ISSUE_555 . split ( ',' ) ;
25+
2126 if ( isWtf ) {
2227 // Workaround for: https://github.com/google/tracing-framework/issues/555
23- apis = WTF_ISSUE_555 . split ( ',' ) . map ( ( v ) => 'HTML' + v + 'Element' ) . concat ( NO_EVENT_TARGET ) ;
28+ apis = WTF_ISSUE_555_ARRAY . map ( ( v ) => 'HTML' + v + 'Element' ) . concat ( NO_EVENT_TARGET ) ;
2429 } else if ( _global [ EVENT_TARGET ] ) {
2530 apis . push ( EVENT_TARGET ) ;
2631 } else {
@@ -29,8 +34,73 @@ export function eventTargetPatch(_global: any) {
2934 apis = NO_EVENT_TARGET ;
3035 }
3136
37+ const isDisableIECheck = _global [ '__Zone_disable_IE_check' ] || false ;
38+ const isEnableCrossContextCheck = _global [ '__Zone_enable_cross_context_check' ] || false ;
39+ const ieOrEdge = isIEOrEdge ( ) ;
40+
41+ const ADD_EVENT_LISTENER_SOURCE = '.addEventListener:' ;
42+ const FUNCTION_WRAPPER = '[object FunctionWrapper]' ;
43+ const BROWSER_TOOLS = 'function __BROWSERTOOLS_CONSOLE_SAFEFUNC() { [native code] }' ;
44+
45+ // predefine all __zone_symbol__ + eventName + true/false string
46+ for ( let i = 0 ; i < eventNames . length ; i ++ ) {
47+ const eventName = eventNames [ i ] ;
48+ const falseEventName = eventName + FALSE_STR ;
49+ const trueEventName = eventName + TRUE_STR ;
50+ const symbol = ZONE_SYMBOL_PREFIX + falseEventName ;
51+ const symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName ;
52+ zoneSymbolEventNames [ eventName ] = { } ;
53+ zoneSymbolEventNames [ eventName ] [ FALSE_STR ] = symbol ;
54+ zoneSymbolEventNames [ eventName ] [ TRUE_STR ] = symbolCapture ;
55+ }
56+
57+ // predefine all task.source string
58+ for ( let i = 0 ; i < WTF_ISSUE_555 . length ; i ++ ) {
59+ const target : any = WTF_ISSUE_555_ARRAY [ i ] ;
60+ const targets : any = globalSources [ target ] = { } ;
61+ for ( let j = 0 ; j < eventNames . length ; j ++ ) {
62+ const eventName = eventNames [ j ] ;
63+ targets [ eventName ] = target + ADD_EVENT_LISTENER_SOURCE + eventName ;
64+ }
65+ }
66+
67+ const checkIEAndCrossContext = function (
68+ nativeDelegate : any , delegate : any , target : any , args : any ) {
69+ if ( ! isDisableIECheck && ieOrEdge ) {
70+ if ( isEnableCrossContextCheck ) {
71+ try {
72+ const testString = delegate . toString ( ) ;
73+ if ( ( testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS ) ) {
74+ nativeDelegate . apply ( target , args ) ;
75+ return false ;
76+ }
77+ } catch ( error ) {
78+ nativeDelegate . apply ( target , args ) ;
79+ return false ;
80+ }
81+ } else {
82+ const testString = delegate . toString ( ) ;
83+ if ( ( testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS ) ) {
84+ nativeDelegate . apply ( target , args ) ;
85+ return false ;
86+ }
87+ }
88+ } else if ( isEnableCrossContextCheck ) {
89+ try {
90+ delegate . toString ( ) ;
91+ } catch ( error ) {
92+ nativeDelegate . apply ( target , args ) ;
93+ return false ;
94+ }
95+ }
96+ return true ;
97+ } ;
98+
3299 for ( let i = 0 ; i < apis . length ; i ++ ) {
33100 const type = _global [ apis [ i ] ] ;
34- patchEventTargetMethods ( type && type . prototype ) ;
101+ patchEventTargetMethods ( type && type . prototype , { validateHandler : checkIEAndCrossContext } ) ;
35102 }
103+
104+ api . patchEventTargetMethods = patchEventTargetMethods ;
105+ return true ;
36106}
0 commit comments