|
15 | 15 | declare const WorkerGlobalScope: any; |
16 | 16 |
|
17 | 17 | export const zoneSymbol: (name: string) => string = (n) => `__zone_symbol__${n}`; |
| 18 | +const VALUE = zoneSymbol('value'); |
18 | 19 | const _global: any = |
19 | 20 | typeof window === 'object' && window || typeof self === 'object' && self || global; |
20 | 21 |
|
@@ -99,6 +100,12 @@ export function patchProperty(obj: any, prop: string) { |
99 | 100 | target.removeEventListener(eventName, target[_prop]); |
100 | 101 | } |
101 | 102 |
|
| 103 | + if (typeof fn === 'string') { |
| 104 | + const src: string = fn; |
| 105 | + fn = new Function(src); |
| 106 | + fn[VALUE] = src; |
| 107 | + } |
| 108 | + |
102 | 109 | if (typeof fn === 'function') { |
103 | 110 | const wrapFn = function(event: Event) { |
104 | 111 | let result; |
@@ -147,26 +154,28 @@ export function patchProperty(obj: any, prop: string) { |
147 | 154 | } |
148 | 155 | } |
149 | 156 | } |
150 | | - return target[_prop] || null; |
| 157 | + const value = target[_prop] || null; |
| 158 | + return value && value.hasOwnProperty(VALUE) ? value[value] : value; |
151 | 159 | }; |
152 | 160 |
|
153 | 161 | Object.defineProperty(obj, prop, desc); |
154 | 162 | } |
155 | 163 |
|
156 | 164 | export function patchOnProperties(obj: any, properties: string[]) { |
157 | | - const onProperties = []; |
158 | | - for (const prop in obj) { |
159 | | - if (prop.substr(0, 2) == 'on') { |
160 | | - onProperties.push(prop); |
161 | | - } |
162 | | - } |
163 | | - for (let j = 0; j < onProperties.length; j++) { |
164 | | - patchProperty(obj, onProperties[j]); |
165 | | - } |
166 | 165 | if (properties) { |
167 | 166 | for (let i = 0; i < properties.length; i++) { |
168 | 167 | patchProperty(obj, 'on' + properties[i]); |
169 | 168 | } |
| 169 | + } else { |
| 170 | + const onProperties = []; |
| 171 | + for (const prop in obj) { |
| 172 | + if (prop.substr(0, 2) == 'on') { |
| 173 | + onProperties.push(prop); |
| 174 | + } |
| 175 | + } |
| 176 | + for (let j = 0; j < onProperties.length; j++) { |
| 177 | + patchProperty(obj, onProperties[j]); |
| 178 | + } |
170 | 179 | } |
171 | 180 | } |
172 | 181 |
|
|
0 commit comments