@@ -5,25 +5,24 @@ import * as keys from '../keys';
55var 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 ( ' ' ) ;
66
77export function apply ( ) {
8- if ( utils . isWebWorker ( ) ) {
9- // on WebWorker so don't apply patch
10- return ;
11- }
12-
138 var supportsWebSocket = typeof WebSocket !== 'undefined' ;
149 if ( canPatchViaPropertyDescriptor ( ) ) {
1510 // 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+ }
2017 utils . patchProperties ( XMLHttpRequest . prototype ) ;
2118 if ( supportsWebSocket ) {
2219 utils . patchProperties ( WebSocket . prototype ) ;
2320 }
2421 } else {
2522 // Safari, Android browsers (Jelly Bean)
26- patchViaCapturingAllTheEvents ( ) ;
23+ if ( ! utils . isWebWorker ( ) ) {
24+ patchViaCapturingAllTheEvents ( ) ;
25+ }
2726 utils . patchClass ( 'XMLHttpRequest' ) ;
2827 if ( supportsWebSocket ) {
2928 webSocketPatch . apply ( ) ;
@@ -32,21 +31,22 @@ export function apply() {
3231}
3332
3433function canPatchViaPropertyDescriptor ( ) {
35- if ( ! Object . getOwnPropertyDescriptor ( HTMLElement . prototype , 'onclick' ) && typeof Element !== 'undefined' ) {
34+ if ( ! utils . isWebWorker ( ) && ! Object . getOwnPropertyDescriptor ( HTMLElement . prototype , 'onclick' )
35+ && typeof Element !== 'undefined' ) {
3636 // WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
3737 // IDL interface attributes are not configurable
3838 var desc = Object . getOwnPropertyDescriptor ( Element . prototype , 'onclick' ) ;
3939 if ( desc && ! desc . configurable ) return false ;
4040 }
4141
42- Object . defineProperty ( HTMLElement . prototype , 'onclick ' , {
42+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange ' , {
4343 get : function ( ) {
4444 return true ;
4545 }
4646 } ) ;
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 ' , { } ) ;
5050 return result ;
5151} ;
5252
0 commit comments