@@ -81,8 +81,17 @@ export function patchProperty(obj: any, prop: string) {
81
81
const _prop = zoneSymbol ( '_' + prop ) ;
82
82
83
83
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 ] ) ;
86
95
}
87
96
88
97
if ( typeof fn === 'function' ) {
@@ -96,17 +105,26 @@ export function patchProperty(obj: any, prop: string) {
96
105
return result ;
97
106
} ;
98
107
99
- this [ _prop ] = wrapFn ;
100
- this . addEventListener ( eventName , wrapFn , false ) ;
108
+ target [ _prop ] = wrapFn ;
109
+ target . addEventListener ( eventName , wrapFn , false ) ;
101
110
} else {
102
- this [ _prop ] = null ;
111
+ target [ _prop ] = null ;
103
112
}
104
113
} ;
105
114
106
115
// The getter would return undefined for unassigned properties but the default value of an
107
116
// unassigned property is null
108
117
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 ;
110
128
// result will be null when use inline event attribute,
111
129
// such as <button onclick="func();">OK</button>
112
130
// because the onclick function is internal raw uncompiled handler
@@ -118,13 +136,13 @@ export function patchProperty(obj: any, prop: string) {
118
136
r = originalDesc . get . apply ( this , arguments ) ;
119
137
if ( r ) {
120
138
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 ) ;
123
141
}
124
142
}
125
143
}
126
144
}
127
- return this [ _prop ] || null ;
145
+ return target [ _prop ] || null ;
128
146
} ;
129
147
130
148
Object . defineProperty ( obj , prop , desc ) ;
0 commit comments