diff --git a/lib/common/utils.ts b/lib/common/utils.ts index dc1c3e91a..db645b51f 100644 --- a/lib/common/utils.ts +++ b/lib/common/utils.ts @@ -61,6 +61,11 @@ export const isMix: boolean = typeof process !== 'undefined' && export function patchProperty(obj: any, prop: string) { const desc = Object.getOwnPropertyDescriptor(obj, prop) || {enumerable: true, configurable: true}; + // if the descriptor is not configurable + // just return + if (!desc.configurable) { + return; + } const originalDesc = Object.getOwnPropertyDescriptor(obj, 'original' + prop); if (!originalDesc && desc.get) { diff --git a/test/common/util.spec.ts b/test/common/util.spec.ts index 238ec1755..b56ac7efa 100644 --- a/test/common/util.spec.ts +++ b/test/common/util.spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {patchMethod, zoneSymbol} from '../../lib/common/utils'; +import {patchMethod, patchProperty, zoneSymbol} from '../../lib/common/utils'; describe('utils', function() { @@ -61,6 +61,25 @@ describe('utils', function() { expect(pMethod).toBe(Type.prototype.method); }); + it('should not patch property which is not configurable', () => { + const TestType = function() {}; + const originalDefineProperty = (Object as any)[zoneSymbol('defineProperty')]; + if (originalDefineProperty) { + originalDefineProperty( + TestType.prototype, 'nonConfigurableProperty', + {configurable: false, writable: true, value: 'test'}); + } else { + Object.defineProperty( + TestType.prototype, 'nonConfigurableProperty', + {configurable: false, writable: true, value: 'test'}); + } + patchProperty(TestType.prototype, 'nonConfigurableProperty'); + const desc = Object.getOwnPropertyDescriptor(TestType.prototype, 'nonConfigurableProperty'); + expect(desc.writable).toBeTruthy(); + expect(!desc.get).toBeTruthy(); + }); + + it('should have a method name in the stacktrace', () => { const fn = function someOtherName() { throw new Error('MyError');