@@ -54,6 +54,15 @@ export const isBrowser: boolean =
54
54
export function patchProperty ( obj , prop ) {
55
55
const desc = Object . getOwnPropertyDescriptor ( obj , prop ) || { enumerable : true , configurable : true } ;
56
56
57
+ const originalDesc = Object . getOwnPropertyDescriptor ( obj , 'original' + prop ) ;
58
+ if ( ! originalDesc && desc . get ) {
59
+ Object . defineProperty ( obj , 'original' + prop , {
60
+ enumerable : false ,
61
+ configurable : true ,
62
+ get : desc . get
63
+ } ) ;
64
+ }
65
+
57
66
// A property descriptor cannot have getter/setter and be writable
58
67
// deleting the writable and value properties avoids this error:
59
68
//
@@ -89,6 +98,23 @@ export function patchProperty(obj, prop) {
89
98
// The getter would return undefined for unassigned properties but the default value of an
90
99
// unassigned property is null
91
100
desc . get = function ( ) {
101
+ let r = this [ _prop ] || null ;
102
+ // result will be null when use inline event attribute,
103
+ // such as <button onclick="func();">OK</button>
104
+ // because the onclick function is internal raw uncompiled handler
105
+ // the onclick will be evaluated when first time event was triggered or
106
+ // the property is accessed, https://github.com/angular/zone.js/issues/525
107
+ // so we should use original native get to retrive the handler
108
+ if ( r === null ) {
109
+ let oriDesc = Object . getOwnPropertyDescriptor ( obj , 'original' + prop ) ;
110
+ if ( oriDesc && oriDesc . get ) {
111
+ r = oriDesc . get . apply ( this , arguments ) ;
112
+ if ( r ) {
113
+ desc . set . apply ( this , [ r ] ) ;
114
+ this . removeAttribute ( prop ) ;
115
+ }
116
+ }
117
+ }
92
118
return this [ _prop ] || null ;
93
119
} ;
94
120
0 commit comments