@@ -5,25 +5,28 @@ 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
8+ if ( utils . isNode ( ) ) {
109 return ;
1110 }
12-
11+
1312 var supportsWebSocket = typeof WebSocket !== 'undefined' ;
1413 if ( canPatchViaPropertyDescriptor ( ) ) {
1514 // 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 ) ;
15+ if ( ! utils . isWebWorker ( ) ) {
16+ var onEventNames = eventNames . map ( function ( property ) {
17+ return 'on' + property ;
18+ } ) ;
19+ utils . patchProperties ( HTMLElement . prototype , onEventNames ) ;
20+ }
2021 utils . patchProperties ( XMLHttpRequest . prototype ) ;
2122 if ( supportsWebSocket ) {
2223 utils . patchProperties ( WebSocket . prototype ) ;
2324 }
2425 } else {
2526 // Safari, Android browsers (Jelly Bean)
26- patchViaCapturingAllTheEvents ( ) ;
27+ if ( ! utils . isWebWorker ( ) ) {
28+ patchViaCapturingAllTheEvents ( ) ;
29+ }
2730 utils . patchClass ( 'XMLHttpRequest' ) ;
2831 if ( supportsWebSocket ) {
2932 webSocketPatch . apply ( ) ;
@@ -32,21 +35,22 @@ export function apply() {
3235}
3336
3437function canPatchViaPropertyDescriptor ( ) {
35- if ( ! Object . getOwnPropertyDescriptor ( HTMLElement . prototype , 'onclick' ) && typeof Element !== 'undefined' ) {
38+ if ( ! utils . isWebWorker ( ) && ! Object . getOwnPropertyDescriptor ( HTMLElement . prototype , 'onclick' )
39+ && typeof Element !== 'undefined' ) {
3640 // WebKit https://bugs.webkit.org/show_bug.cgi?id=134364
3741 // IDL interface attributes are not configurable
3842 var desc = Object . getOwnPropertyDescriptor ( Element . prototype , 'onclick' ) ;
3943 if ( desc && ! desc . configurable ) return false ;
4044 }
4145
42- Object . defineProperty ( HTMLElement . prototype , 'onclick ' , {
46+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange ' , {
4347 get : function ( ) {
4448 return true ;
4549 }
4650 } ) ;
47- var elt = document . createElement ( 'div' ) ;
48- var result = ! ! elt . onclick ;
49- Object . defineProperty ( HTMLElement . prototype , 'onclick ' , { } ) ;
51+ var req = new XMLHttpRequest ( ) ;
52+ var result = ! ! req . onreadystatechange ;
53+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange ' , { } ) ;
5054 return result ;
5155} ;
5256
0 commit comments