From 19ce38f29d73b5750f563e9c974ff04a7535d901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Sat, 26 Jan 2019 23:21:40 +0100 Subject: [PATCH] qweb: only protect context if necessary --- web/static/src/ts/core/qweb_vdom.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/static/src/ts/core/qweb_vdom.ts b/web/static/src/ts/core/qweb_vdom.ts index 45524bc1..73589475 100644 --- a/web/static/src/ts/core/qweb_vdom.ts +++ b/web/static/src/ts/core/qweb_vdom.ts @@ -28,6 +28,7 @@ export class Context { rootContext: Context; caller: Element | undefined; shouldDefineOwner: boolean = false; + shouldProtectContext: boolean = false; constructor() { this.rootContext = this; @@ -199,7 +200,6 @@ export class QWeb { const doc = this.parsedTemplates[name]; const ctx = new Context(); - ctx.addLine("context = Object.create(context);"); const mainNode = doc.firstChild!; this._compileNode(mainNode, ctx); @@ -208,6 +208,9 @@ export class QWeb { // pollute the rendering context by adding some keys in it. ctx.code.unshift("let owner = context;"); } + if (ctx.shouldProtectContext) { + ctx.code.unshift("context = Object.create(context);"); + } if (!ctx.rootNode) { throw new Error("A template should have one root node"); @@ -620,6 +623,7 @@ const forEachDirective: Directive = { name: "foreach", priority: 10, atNodeEncounter({ node, qweb, ctx }): boolean { + ctx.rootContext.shouldProtectContext = true; const elems = node.getAttribute("t-foreach")!; const name = node.getAttribute("t-as")!; let arrayID = ctx.generateID();