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

Commit

Permalink
fix(memory): Add protection against excessive on prop patching
Browse files Browse the repository at this point in the history
  This caused memory leaks in Jest JSDOM environment
  • Loading branch information
FreeleX committed Jul 3, 2018
1 parent 0a2f6ff commit 465f1c2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
return;
}

const onPropPatchedSymbol = zoneSymbol('on' + prop + 'patched');
if (obj[onPropPatchedSymbol]) {
// return;
}

// A property descriptor cannot have getter/setter and be writable
// deleting the writable and value properties avoids this error:
//
Expand Down Expand Up @@ -240,6 +245,8 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
};

ObjectDefineProperty(obj, prop, desc);

obj[onPropPatchedSymbol] = true;
}

export function patchOnProperties(obj: any, properties: string[]|null, prototype?: any) {
Expand Down

0 comments on commit 465f1c2

Please sign in to comment.