From 465f1c22637509e1d23e513953a1e96a7691fef2 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..0af2559b6 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[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) {