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

Commit

Permalink
fix(toString): fix #802, fix ios 9 MutationObserver toString error (#803
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JiaLiPassion authored and mhevery committed Jun 7, 2017
1 parent 7bd1418 commit 68aa03e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/common/to-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ Zone.__load_patch('toString', (global: any, Zone: ZoneType, api: _ZonePrivate) =
const originalFunctionToString = Function.prototype.toString;
Function.prototype.toString = function() {
if (typeof this === 'function') {
if (this[zoneSymbol('OriginalDelegate')]) {
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
const originalDelegate = this[zoneSymbol('OriginalDelegate')];
if (originalDelegate) {
if (typeof originalDelegate === 'function') {
return originalFunctionToString.apply(this[zoneSymbol('OriginalDelegate')], arguments);
} else {
return Object.prototype.toString.call(originalDelegate);
}
}
if (this === Promise) {
const nativePromise = global[zoneSymbol('Promise')];
Expand Down
12 changes: 12 additions & 0 deletions test/common/toString.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ describe('global function patch', () => {
expect(Function.prototype.toString.call(setTimeout))
.toEqual(Function.prototype.toString.call(g[zoneSymbol('setTimeout')]));
});

it('MutationObserver toString should be the same with native version',
ifEnvSupports('MutationObserver', () => {
const nativeMutationObserver = g[zoneSymbol('MutationObserver')];
if (typeof nativeMutationObserver === 'function') {
expect(Function.prototype.toString.call(g['MutationObserver']))
.toEqual(Function.prototype.toString.call(nativeMutationObserver));
} else {
expect(Function.prototype.toString.call(g['MutationObserver']))
.toEqual(Object.prototype.toString.call(nativeMutationObserver));
}
}));
});

describe('isNative', () => {
Expand Down

0 comments on commit 68aa03e

Please sign in to comment.