document.createElement should be able to create a custom element
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jan 2016 17:23:42 +0000 (17:23 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jan 2016 17:23:42 +0000 (17:23 +0000)
commit2f51aa69103ab5e3183d292533e4a39759405415
tree7c6ab46bd7234c8a1c11ca3686883210dafb71d0
parentf92c11d2ac3627e788b208851a3a5f389e53e653
document.createElement should be able to create a custom element
https://bugs.webkit.org/show_bug.cgi?id=153173

Reviewed by Darin Adler.

Source/WebCore:

Added the support for constructing a custom element via document.createElement.

Extracted HTMLElementFactory::createKnownElement, which returns nullptr when the specified name doesn't match
any builtin element instead of out of HTMLUnknownElement, out of HTMLElementFactory::createElement.

Test: fast/custom-elements/Document-createElement.html

* bindings/js/JSCustomElementInterface.cpp:
(WebCore::JSCustomElementInterface::constructHTMLElement): Added. Constructs a custom element by invoking its
constructor. We allow exceptions to be thrown by the constructor so the caller is responsible for checking
any exceptions in the ExecState before preceeding if the returned value is null.

* bindings/js/JSCustomElementInterface.h:
(WebCore::JSCustomElementInterface::constructSVGElement): Added.
* bindings/js/JSElementCustom.cpp:
(WebCore::toJSNewlyCreated): Exit early if the element is a custom element as the wrapper had already been
created by super() call inside the custom element'c constructor.

* bindings/js/JSMainThreadExecState.h:
(WebCore::JSMainThreadExecState):
* bindings/js/JSMainThreadExecStateInstrumentation.h:
(WebCore::JSMainThreadExecState::instrumentFunctionInternal): Generalized from instrumentFunctionCall so that
we can use it for both call and construct.
(WebCore::JSMainThreadExecState::instrumentFunctionCall): Specialized the above function for call.
(WebCore::JSMainThreadExecState::instrumentFunctionConstruct): Ditto for construct.

* dom/CustomElementDefinitions.cpp:
(WebCore::CustomElementDefinitions::findInterface): Added.
* dom/CustomElementDefinitions.h:

* dom/Document.cpp:
(WebCore::createHTMLElementWithNameValidation): Extracted from createElement.
(WebCore::Document::createElementForBindings): Renamed from createElement. Specifies
ShouldCreateCustomElement::Create to create a custom element before using fallback elements.
* dom/Document.h:
* dom/Document.idl:

* dom/Node.h:
(WebCore::Node::isCustomElement): Added. This flag is used to identify a custom element.
(WebCore::Node::setIsCustomElement): Added.

* dom/make_names.pl: Extracted createKnownElement from createElement for createHTMLElementWithNameValidation.

* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::createInspectorStyleSheetForDocument): Use qualified name object to instantiate
a style element and set type content attribute.
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::setNodeName): Use createElementForBindings here since we might be creating an
arbitrary element here. Also use RefPtr instead of raw pointers while mutating DOM for safety.

Source/WebKit/win:

Use createElementForBindings here since this is a C++ binding for Windows.

* DOMCoreClasses.cpp:
(DOMDocument::createElement):

Source/WebKit2:

Use createElementForBindings here since this is for SPI.

* WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm:
(-[WKDOMDocument createElement:]):
(-[WKDOMDocument createTextNode:]):

LayoutTests:

Add a test for creating a custom elemnet via document.createElement.
The behavior is to be documented later.

* fast/custom-elements/Document-createElement-expected.txt: Added.
* fast/custom-elements/Document-createElement.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@195538 268f45cc-cd09-0410-ab3c-d52691b4dbfc
22 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/custom-elements/Document-createElement-expected.txt [new file with mode: 0644]
LayoutTests/fast/custom-elements/Document-createElement.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCustomElementInterface.cpp
Source/WebCore/bindings/js/JSCustomElementInterface.h
Source/WebCore/bindings/js/JSElementCustom.cpp
Source/WebCore/bindings/js/JSMainThreadExecState.h
Source/WebCore/bindings/js/JSMainThreadExecStateInstrumentation.h
Source/WebCore/dom/CustomElementDefinitions.cpp
Source/WebCore/dom/CustomElementDefinitions.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Document.idl
Source/WebCore/dom/Node.h
Source/WebCore/dom/make_names.pl
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebKit/win/ChangeLog
Source/WebKit/win/DOMCoreClasses.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm