From cc95390d8b64795750f421d1ad9f63157a4c25ff Mon Sep 17 00:00:00 2001 From: Alexander Korenev Date: Tue, 3 Jul 2018 10:41:24 +0300 Subject: [PATCH] fix(memory): Add protection against excessive on prop patching This caused memory leaks in Jest JSDOM environment --- lib/common/utils.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/common/utils.ts b/lib/common/utils.ts index e7bbed307..6647df6c6 100644 --- a/lib/common/utils.ts +++ b/lib/common/utils.ts @@ -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: // @@ -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) {