diff --git a/lib/common/to-string.ts b/lib/common/to-string.ts index 12c75320d..ac3fab2e6 100644 --- a/lib/common/to-string.ts +++ b/lib/common/to-string.ts @@ -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')]; diff --git a/test/common/toString.spec.ts b/test/common/toString.spec.ts index ae96ad266..48e7474f0 100644 --- a/test/common/toString.spec.ts +++ b/test/common/toString.spec.ts @@ -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', () => {