6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
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' ;
10
11
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' ;
17
21
18
- export function eventTargetPatch ( _global : any ) {
19
22
let apis = [ ] ;
20
23
const isWtf = _global [ 'wtf' ] ;
24
+ const WTF_ISSUE_555_ARRAY = WTF_ISSUE_555 . split ( ',' ) ;
25
+
21
26
if ( isWtf ) {
22
27
// 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 ) ;
24
29
} else if ( _global [ EVENT_TARGET ] ) {
25
30
apis . push ( EVENT_TARGET ) ;
26
31
} else {
@@ -29,8 +34,73 @@ export function eventTargetPatch(_global: any) {
29
34
apis = NO_EVENT_TARGET ;
30
35
}
31
36
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
+
32
99
for ( let i = 0 ; i < apis . length ; i ++ ) {
33
100
const type = _global [ apis [ i ] ] ;
34
- patchEventTargetMethods ( type && type . prototype ) ;
101
+ patchEventTargetMethods ( type && type . prototype , { validateHandler : checkIEAndCrossContext } ) ;
35
102
}
103
+
104
+ api . patchEventTargetMethods = patchEventTargetMethods ;
105
+ return true ;
36
106
}
0 commit comments