@@ -5,25 +5,24 @@ import * as keys from '../keys';
5
5
var eventNames = 'copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart message mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror' . split ( ' ' ) ;
6
6
7
7
export function apply ( ) {
8
- if ( utils . isWebWorker ( ) ) {
9
- // on WebWorker so don't apply patch
10
- return ;
11
- }
12
-
13
8
var supportsWebSocket = typeof WebSocket !== 'undefined' ;
14
9
if ( canPatchViaPropertyDescriptor ( ) ) {
15
10
// for browsers that we can patch the descriptor: Chrome & Firefox
16
- var onEventNames = eventNames . map ( function ( property ) {
17
- return 'on' + property ;
18
- } ) ;
19
- utils . patchProperties ( HTMLElement . prototype , onEventNames ) ;
11
+ if ( ! utils . isWebWorker ( ) ) {
12
+ var onEventNames = eventNames . map ( function ( property ) {
13
+ return 'on' + property ;
14
+ } ) ;
15
+ utils . patchProperties ( HTMLElement . prototype , onEventNames ) ;
16
+ }
20
17
utils . patchProperties ( XMLHttpRequest . prototype ) ;
21
18
if ( supportsWebSocket ) {
22
19
utils . patchProperties ( WebSocket . prototype ) ;
23
20
}
24
21
} else {
25
22
// Safari, Android browsers (Jelly Bean)
26
- patchViaCapturingAllTheEvents ( ) ;
23
+ if ( ! utils . isWebWorker ( ) ) {
24
+ patchViaCapturingAllTheEvents ( ) ;
25
+ }
27
26
utils . patchClass ( 'XMLHttpRequest' ) ;
28
27
if ( supportsWebSocket ) {
29
28
webSocketPatch . apply ( ) ;
@@ -32,21 +31,22 @@ export function apply() {
32
31
}
33
32
34
33
function canPatchViaPropertyDescriptor ( ) {
35
- if ( ! Object . getOwnPropertyDescriptor ( HTMLElement . prototype , 'onclick' ) && typeof Element !== 'undefined' ) {
34
+ if ( ! utils . isWebWorker ( ) && ! Object . getOwnPropertyDescriptor ( HTMLElement . prototype , 'onclick' )
35
+ && typeof Element !== 'undefined' ) {
36
36
// WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
37
37
// IDL interface attributes are not configurable
38
38
var desc = Object . getOwnPropertyDescriptor ( Element . prototype , 'onclick' ) ;
39
39
if ( desc && ! desc . configurable ) return false ;
40
40
}
41
41
42
- Object . defineProperty ( HTMLElement . prototype , 'onclick ' , {
42
+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange ' , {
43
43
get : function ( ) {
44
44
return true ;
45
45
}
46
46
} ) ;
47
- var elt = document . createElement ( 'div' ) ;
48
- var result = ! ! elt . onclick ;
49
- Object . defineProperty ( HTMLElement . prototype , 'onclick ' , { } ) ;
47
+ var req = new XMLHttpRequest ( ) ;
48
+ var result = ! ! req . onreadystatechange ;
49
+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange ' , { } ) ;
50
50
return result ;
51
51
} ;
52
52
0 commit comments