@@ -81,8 +81,17 @@ export function patchProperty(obj: any, prop: string) {
8181 const _prop = zoneSymbol ( '_' + prop ) ;
8282
8383 desc . set = function ( fn ) {
84- if ( this [ _prop ] ) {
85- this . removeEventListener ( eventName , this [ _prop ] ) ;
84+ // in some of windows's onproperty callback, this is undefined
85+ // so we need to check it
86+ let target = this ;
87+ if ( ! target && obj === _global ) {
88+ target = _global ;
89+ }
90+ if ( ! target ) {
91+ return ;
92+ }
93+ if ( target [ _prop ] ) {
94+ target . removeEventListener ( eventName , target [ _prop ] ) ;
8695 }
8796
8897 if ( typeof fn === 'function' ) {
@@ -96,17 +105,26 @@ export function patchProperty(obj: any, prop: string) {
96105 return result ;
97106 } ;
98107
99- this [ _prop ] = wrapFn ;
100- this . addEventListener ( eventName , wrapFn , false ) ;
108+ target [ _prop ] = wrapFn ;
109+ target . addEventListener ( eventName , wrapFn , false ) ;
101110 } else {
102- this [ _prop ] = null ;
111+ target [ _prop ] = null ;
103112 }
104113 } ;
105114
106115 // The getter would return undefined for unassigned properties but the default value of an
107116 // unassigned property is null
108117 desc . get = function ( ) {
109- let r = this [ _prop ] || null ;
118+ // in some of windows's onproperty callback, this is undefined
119+ // so we need to check it
120+ let target = this ;
121+ if ( ! target && obj === _global ) {
122+ target = _global ;
123+ }
124+ if ( ! target ) {
125+ return null ;
126+ }
127+ let r = target [ _prop ] || null ;
110128 // result will be null when use inline event attribute,
111129 // such as <button onclick="func();">OK</button>
112130 // because the onclick function is internal raw uncompiled handler
@@ -118,13 +136,13 @@ export function patchProperty(obj: any, prop: string) {
118136 r = originalDesc . get . apply ( this , arguments ) ;
119137 if ( r ) {
120138 desc . set . apply ( this , [ r ] ) ;
121- if ( typeof this [ 'removeAttribute' ] === 'function' ) {
122- this . removeAttribute ( prop ) ;
139+ if ( typeof target [ 'removeAttribute' ] === 'function' ) {
140+ target . removeAttribute ( prop ) ;
123141 }
124142 }
125143 }
126144 }
127- return this [ _prop ] || null ;
145+ return target [ _prop ] || null ;
128146 } ;
129147
130148 Object . defineProperty ( obj , prop , desc ) ;
0 commit comments