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
5 changes: 5 additions & 0 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 20 additions & 1 deletion test/common/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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');
Expand Down