Title: [233333] trunk/Websites/perf.webkit.org
Revision
233333
Author
[email protected]
Date
2018-06-28 15:14:39 -0700 (Thu, 28 Jun 2018)

Log Message

Fix a bug ComponentBase that wrong content template may be used.
https://bugs.webkit.org/show_bug.cgi?id=187159

Reviewed by Ryosuke Niwa.

ComponentBase uses '_parsed' to mark whether content and style templates of a class
is parsed. However, derived class parsing will be skipped as 'Derive._parsed' is available
via prototype chain whenever the base class is parsed.

* browser-tests/component-base-tests.js: Added unit tests.
* public/v3/components/base.js: Added 'hasOwnProperty' to make sure current class is parsed.
(ComponentBase.prototype._ensureShadowTree):

Modified Paths

Diff

Modified: trunk/Websites/perf.webkit.org/ChangeLog (233332 => 233333)


--- trunk/Websites/perf.webkit.org/ChangeLog	2018-06-28 22:13:04 UTC (rev 233332)
+++ trunk/Websites/perf.webkit.org/ChangeLog	2018-06-28 22:14:39 UTC (rev 233333)
@@ -1,3 +1,18 @@
+2018-06-28  Dewei Zhu  <[email protected]>
+
+        Fix a bug ComponentBase that wrong content template may be used.
+        https://bugs.webkit.org/show_bug.cgi?id=187159
+
+        Reviewed by Ryosuke Niwa.
+
+        ComponentBase uses '_parsed' to mark whether content and style templates of a class
+        is parsed. However, derived class parsing will be skipped as 'Derive._parsed' is available
+        via prototype chain whenever the base class is parsed.
+
+        * browser-tests/component-base-tests.js: Added unit tests.
+        * public/v3/components/base.js: Added 'hasOwnProperty' to make sure current class is parsed.
+        (ComponentBase.prototype._ensureShadowTree):
+
 2018-06-25  Dewei Zhu  <[email protected]>
 
         MeasurementSetAnalyzer should check triggerable availability before creating confirming A/B tests.

Modified: trunk/Websites/perf.webkit.org/browser-tests/component-base-tests.js (233332 => 233333)


--- trunk/Websites/perf.webkit.org/browser-tests/component-base-tests.js	2018-06-28 22:13:04 UTC (rev 233332)
+++ trunk/Websites/perf.webkit.org/browser-tests/component-base-tests.js	2018-06-28 22:14:39 UTC (rev 233333)
@@ -195,6 +195,27 @@
             expect(container.textContent).to.be('hello, world');
         });
 
+        it('it must create content using derived class content template', async () => {
+            const context = new BrowsingContext();
+            const ComponentBase = await importComponentBase(context);
+
+            class BaseClass extends ComponentBase { };
+            BaseClass.contentTemplate = ['div', {id: 'container'}, 'base-class'];
+            const baseInstance = new BaseClass('base-class');
+
+            class DerivedClass extends BaseClass {};
+            DerivedClass.contentTemplate = ['div', {id: 'container'}, 'derived-class'];
+            const derivedInstance = new DerivedClass('derived-class');
+
+            const baseContainer = baseInstance.content('container');
+            expect(baseContainer).to.be.a(context.global.HTMLDivElement);
+            expect(baseContainer.textContent).to.be('base-class');
+
+            const derivedContainer = derivedInstance.content('container');
+            expect(derivedContainer).to.be.a(context.global.HTMLDivElement);
+            expect(derivedContainer.textContent).to.be('derived-class');
+        });
+
         it('it must create stylsheet from styleTemplate', async () => {
             const context = new BrowsingContext();
             const ComponentBase = await importComponentBase(context);
@@ -699,4 +720,28 @@
 
     });
 
+    describe('_ensureShadowTree', () => {
+        it('should parse derived component after parsing base component', async () => {
+            const context = new BrowsingContext();
+            const ComponentBase = await importComponentBase(context);
+            class DerivedComponent extends ComponentBase {};
+            const baseInstance = new ComponentBase;
+            expect(ComponentBase.hasOwnProperty('_parsed')).to.be(false);
+            expect(DerivedComponent.hasOwnProperty('_parsed')).to.be(false);
+
+            baseInstance._ensureShadowTree();
+            expect(ComponentBase.hasOwnProperty('_parsed')).to.be(true);
+            expect(DerivedComponent.hasOwnProperty('_parsed')).to.be(false);
+            expect(!!ComponentBase._parsed).to.be(true);
+            expect(!!DerivedComponent._parsed).to.be(true);
+
+            const derivedInstance = new DerivedComponent;
+            derivedInstance._ensureShadowTree();
+            expect(ComponentBase.hasOwnProperty('_parsed')).to.be(true);
+            expect(DerivedComponent.hasOwnProperty('_parsed')).to.be(true);
+            expect(!!ComponentBase._parsed).to.be(true);
+            expect(!!DerivedComponent._parsed).to.be(true);
+        });
+    });
+
 });

Modified: trunk/Websites/perf.webkit.org/public/v3/components/base.js (233332 => 233333)


--- trunk/Websites/perf.webkit.org/public/v3/components/base.js	2018-06-28 22:13:04 UTC (rev 233332)
+++ trunk/Websites/perf.webkit.org/public/v3/components/base.js	2018-06-28 22:14:39 UTC (rev 233333)
@@ -154,7 +154,7 @@
 
         let content;
         let stylesheet;
-        if (!thisClass._parsed) {
+        if (!thisClass.hasOwnProperty('_parsed') || !thisClass._parsed) {
             thisClass._parsed = true;
 
             const contentTemplate = thisClass['contentTemplate'];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to