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 (#1106)
Browse files Browse the repository at this point in the history
This caused memory leaks in Jest JSDOM environment
  • Loading branch information
FreeleX authored and mhevery committed Jul 17, 2018
1 parent 34c12e5 commit 875086f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/common/utils.ts
Expand Up @@ -158,6 +158,11 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
return;
}

const onPropPatchedSymbol = zoneSymbol('on' + prop + 'patched');
if (obj.hasOwnProperty(onPropPatchedSymbol) && 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 875086f

Please sign in to comment.