Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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