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

Commit 68aa03e

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(toString): fix #802, fix ios 9 MutationObserver toString error (#803)
1 parent 7bd1418 commit 68aa03e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/common/to-string.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ Zone.__load_patch('toString', (global: any, Zone: ZoneType, api: _ZonePrivate) =
1414
const originalFunctionToString = Function.prototype.toString;
1515
Function.prototype.toString = function() {
1616
if (typeof this === 'function') {
17-
if (this[zoneSymbol('OriginalDelegate')]) {
18-
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
17+
const originalDelegate = this[zoneSymbol('OriginalDelegate')];
18+
if (originalDelegate) {
19+
if (typeof originalDelegate === 'function') {
20+
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
21+
} else {
22+
return Object.prototype.toString.call(originalDelegate);
23+
}
1924
}
2025
if (this === Promise) {
2126
const nativePromise = global[zoneSymbol('Promise')];

test/common/toString.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ describe('global function patch', () => {
1717
expect(Function.prototype.toString.call(setTimeout))
1818
.toEqual(Function.prototype.toString.call(g[zoneSymbol('setTimeout')]));
1919
});
20+
21+
it('MutationObserver toString should be the same with native version',
22+
ifEnvSupports('MutationObserver', () => {
23+
const nativeMutationObserver = g[zoneSymbol('MutationObserver')];
24+
if (typeof nativeMutationObserver === 'function') {
25+
expect(Function.prototype.toString.call(g['MutationObserver']))
26+
.toEqual(Function.prototype.toString.call(nativeMutationObserver));
27+
} else {
28+
expect(Function.prototype.toString.call(g['MutationObserver']))
29+
.toEqual(Object.prototype.toString.call(nativeMutationObserver));
30+
}
31+
}));
2032
});
2133

2234
describe('isNative', () => {

0 commit comments

Comments
 (0)