From 376f44c4d2989a17b701dcd5ec8683fc2e9b504c Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Mon, 23 Jul 2018 22:48:25 -0700 Subject: [PATCH] More updates based on code review. --- lib/legacy/class.js | 7 +- lib/mixins/element-mixin.js | 8 +- lib/utils/templatize.js | 2 +- test/unit/behaviors.html | 105 ++++++++++++++++++++++- test/unit/strict-template-policy.html | 118 +++++++++++++++++++++++--- 5 files changed, 216 insertions(+), 24 deletions(-) diff --git a/lib/legacy/class.js b/lib/legacy/class.js index ba28ec6ed5..d8ff532a3e 100644 --- a/lib/legacy/class.js +++ b/lib/legacy/class.js @@ -345,10 +345,5 @@ export const Class = function(info) { LegacyElementMixin(HTMLElement)); // decorate klass with registration info klass.is = info.is; - // if user provided template on info, make sure the static _template - // is set so the static template getter uses it - if (info._template !== undefined) { - klass._template = info._template; - } -return klass; + return klass; }; diff --git a/lib/mixins/element-mixin.js b/lib/mixins/element-mixin.js index 4840331ce3..4336256176 100644 --- a/lib/mixins/element-mixin.js +++ b/lib/mixins/element-mixin.js @@ -403,14 +403,14 @@ export const ElementMixin = dedupingMixin(base => { static get template() { if (!this.hasOwnProperty(JSCompiler_renameProperty('_template', this))) { this._template = + // Take any template set on the prototype, including null (for legacy + // support, setting in registered callback, etc.) + this.prototype._template !== undefined ? this.prototype._template : // Look in dom-module associated with this element's is getTemplateFromDomModule(/** @type {PolymerElementConstructor}*/ (this).is) || // Next look for superclass template (call the super impl this // way so that `this` points to the superclass) - Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.template || - // Finally, fall back to any _template set on prototype, e.g. - // via registered callback - this.prototype._template; + Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.template; } return this._template; } diff --git a/lib/utils/templatize.js b/lib/utils/templatize.js index 36d531fd4b..2ba7636d06 100644 --- a/lib/utils/templatize.js +++ b/lib/utils/templatize.js @@ -499,7 +499,7 @@ export function templatize(template, owner, options) { // Under strictTemplatePolicy, the templatized element must be owned // by a (trusted) Polymer element, indicated by existence of _methodHost; // e.g. for dom-if & dom-repeat in main document, _methodHost is null - if (strictTemplatePolicy && !owner._methodHost) { + if (strictTemplatePolicy && !findMethodHost(template)) { throw new Error('strictTemplatePolicy: template owner not trusted'); } options = /** @type {!TemplatizeOptions} */(options || {}); diff --git a/test/unit/behaviors.html b/test/unit/behaviors.html index a96f4f067c..916d138440 100644 --- a/test/unit/behaviors.html +++ b/test/unit/behaviors.html @@ -23,8 +23,14 @@ + + + + @@ -309,6 +359,31 @@ + + + + + + + + + + + + + + + + + diff --git a/test/unit/strict-template-policy.html b/test/unit/strict-template-policy.html index cc49b721a6..84aab00452 100644 --- a/test/unit/strict-template-policy.html +++ b/test/unit/strict-template-policy.html @@ -78,7 +78,7 @@