Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 12f1bf5

Browse files
vikermanmhevery
authored andcommitted
fix: resolve errors with closure
Also don't patch all "on" properties if a list of properties is being passed in. Otherwise various global variables in window get clobbered. Closes #722
1 parent 7d4d07f commit 12f1bf5

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

Diff for: lib/browser/property-descriptor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export function propertyDescriptorPatch(_global: any) {
2525
if (isBrowser) {
2626
patchOnProperties(window, eventNames);
2727
patchOnProperties(Document.prototype, eventNames);
28-
if (typeof SVGElement !== 'undefined') {
29-
patchOnProperties(SVGElement.prototype, eventNames);
28+
if (typeof(<any>window)['SVGElement'] !== 'undefined') {
29+
patchOnProperties((<any>window)['SVGElement'].prototype, eventNames);
3030
}
3131
patchOnProperties(HTMLElement.prototype, eventNames);
3232
}

Diff for: lib/common/utils.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
declare const WorkerGlobalScope: any;
1616

1717
export const zoneSymbol: (name: string) => string = (n) => `__zone_symbol__${n}`;
18+
const VALUE = zoneSymbol('value');
1819
const _global: any =
1920
typeof window === 'object' && window || typeof self === 'object' && self || global;
2021

@@ -99,6 +100,12 @@ export function patchProperty(obj: any, prop: string) {
99100
target.removeEventListener(eventName, target[_prop]);
100101
}
101102

103+
if (typeof fn === 'string') {
104+
var src: string = fn;
105+
fn = new Function(src);
106+
fn[VALUE] = src;
107+
}
108+
102109
if (typeof fn === 'function') {
103110
const wrapFn = function(event: Event) {
104111
let result;
@@ -147,26 +154,28 @@ export function patchProperty(obj: any, prop: string) {
147154
}
148155
}
149156
}
150-
return target[_prop] || null;
157+
const value = target[_prop] || null;
158+
return value && value.hasOwnProperty(VALUE) ? value[value] : value;
151159
};
152160

153161
Object.defineProperty(obj, prop, desc);
154162
}
155163

156164
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-
}
166165
if (properties) {
167166
for (let i = 0; i < properties.length; i++) {
168167
patchProperty(obj, 'on' + properties[i]);
169168
}
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+
}
170179
}
171180
}
172181

Diff for: test/browser/browser.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ describe('Zone', function() {
530530

531531
zone.run(function() {
532532
button.setAttribute('onclick', 'return');
533-
expect(button.onclick).not.toBe(null);
533+
expect(button.onclick).not.toBe('return');
534534
});
535535
});
536536

0 commit comments

Comments
 (0)