Add document.defineCustomElement
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jan 2016 02:59:03 +0000 (02:59 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jan 2016 02:59:03 +0000 (02:59 +0000)
commit2bca0bc6a05922f1bd26f3ddccad9121b7442905
tree728df88643fbe3df11ff6c1bf1fc4e07bbca2a29
parent0b7a9961292b125bb66edd18bf24b31e6bfb1b39
Add document.defineCustomElement
https://bugs.webkit.org/show_bug.cgi?id=153092

Reviewed by Chris Dumez.

Source/WebCore:

Added document.defineCustomElement and added a constructor to HTMLElement which can be called
as "super" in a subclass of HTMLElement. This is a prototype of new custom elements API and
willfully violates the current specification at http://w3c.github.io/webcomponents/spec/custom/

Each author defined class can define multiple elements using distinct tag names. In such cases,
the super call must specify the tag name. e.g.

class SomeCustomElement extends HTMLElement { constructor(name) { super(name); } }
document.defineCustomElement('some-custom-element', SomeCustomElement);
document.defineCustomElement('other-custom-element', SomeCustomElement);
new SomeCustomElement('some-custom-element');

When a class is associated with exactly one tag name, the argument can be omitted. e.g.

class AnotherCustomElement extends HTMLElement {}
document.defineCustomElement('another-custom-element', AnotherCustomElement);
new AnotherCustomElement();

We allow only subclassing of HTMLElement and only in (X)HTML namespace.

Tests: fast/custom-elements/Document-defineCustomElement.html
       fast/custom-elements/HTMLElement-constructor.html

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:

* bindings/js/JSCustomElementInterface.cpp: Added. Abstracts an author-defined class associated
with a custom element. It's a Active DOM object and lives until the associated document dies.
(WebCore::JSCustomElementInterface::JSCustomElementInterface):
(WebCore::JSCustomElementInterface::~JSCustomElementInterface):
* bindings/js/JSCustomElementInterface.h: Added.
(WebCore::JSCustomElementInterface::create):
(WebCore::JSCustomElementInterface::scriptExecutionContext):
(WebCore::JSCustomElementInterface::constructor):

* bindings/js/JSDocumentCustom.cpp:
(WebCore::JSDocument::defineCustomElement): Added. Define a custom element by associating a tag
name with an author defined JS class after validating arguments.

* bindings/js/JSHTMLElementCustom.cpp:
(WebCore::constructJSHTMLElement): Added. Look up the tag name based on new.target if one is not
specified. If a tag name is specified, check that new.target is associated with the tag name.

* dom/CustomElementDefinitions.cpp: Added.
(WebCore::CustomElementDefinitions::checkName): Added. Restricts tag names similarly to
http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type
(WebCore::CustomElementDefinitions::defineElement): Added. Associates a JS class with a tag name.
(WebCore::CustomElementDefinitions::findInterface): Added. Finds a JS class by a tag name.
(WebCore::CustomElementDefinitions::findName): Added. Finds a tag name by a JS class.
* dom/CustomElementDefinitions.h: Added.
(WebCore::CustomElementDefinitions::CustomElementInfo): Added.

* dom/Document.cpp:
(WebCore::Document::ensureCustomElementDefinitions): Added.
* dom/Document.h:
(WebCore::Document::customElementDefinitions): Added.

* dom/Document.idl:
* html/HTMLElement.idl:

LayoutTests:

Added tests for document.defineCustomElement and instantiating custom elements.

* TestExpectations: Skipped the tests on non-Mac ports.
* fast/custom-elements: Added.
* fast/custom-elements/Document-defineCustomElement-expected.txt: Added.
* fast/custom-elements/Document-defineCustomElement.html: Added.
* fast/custom-elements/HTMLElement-constructor-expected.txt: Added.
* fast/custom-elements/HTMLElement-constructor.html: Added.
* platform/mac/TestExpectations:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@195087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
20 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/custom-elements/Document-defineCustomElement-expected.txt [new file with mode: 0644]
LayoutTests/fast/custom-elements/Document-defineCustomElement.html [new file with mode: 0644]
LayoutTests/fast/custom-elements/HTMLElement-constructor-expected.txt [new file with mode: 0644]
LayoutTests/fast/custom-elements/HTMLElement-constructor.html [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSCustomElementInterface.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/JSCustomElementInterface.h [new file with mode: 0644]
Source/WebCore/bindings/js/JSDocumentCustom.cpp
Source/WebCore/bindings/js/JSHTMLElementCustom.cpp
Source/WebCore/dom/CustomElementDefinitions.cpp [new file with mode: 0644]
Source/WebCore/dom/CustomElementDefinitions.h [new file with mode: 0644]
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Document.idl
Source/WebCore/html/HTMLElement.idl