Move QualifiedName from CustomElementInfo to JSCustomElementInterface
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Mar 2016 08:31:38 +0000 (08:31 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Mar 2016 08:31:38 +0000 (08:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155061

Reviewed by Antti Koivisto.

Store QualifiedName of custom elements in JSCustomElementInterface instead of CustomElementInfo
now that each interface is associated with exactly one custom element as of r197602.

No new tests since this is a refactoring.

* bindings/js/JSCustomElementInterface.cpp:
(WebCore::JSCustomElementInterface::JSCustomElementInterface): Now takes QualifiedName as the
first argument.
* bindings/js/JSCustomElementInterface.h:
(WebCore::JSCustomElementInterface::create):
(WebCore::JSCustomElementInterface::name): Added.
* bindings/js/JSDocumentCustom.cpp:
(WebCore::JSDocument::defineElement):
* bindings/js/JSHTMLElementCustom.cpp:
(WebCore::constructJSHTMLElement): Use findInterface instead of the deleted findName.
* dom/CustomElementDefinitions.cpp:
(WebCore::CustomElementDefinitions::checkName):
(WebCore::CustomElementDefinitions::addElementDefinition): Renamed from defineElement.
(WebCore::CustomElementDefinitions::findInterface): Add a variant that finds the interface object
by a JS constructor.
(WebCore::CustomElementDefinitions::containsConstructor):
(WebCore::CustomElementDefinitions::findName): Deleted.
* dom/CustomElementDefinitions.h:
(WebCore::CustomElementDefinitions::CustomElementInfo::CustomElementInfo): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197612 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCustomElementInterface.cpp
Source/WebCore/bindings/js/JSCustomElementInterface.h
Source/WebCore/bindings/js/JSDocumentCustom.cpp
Source/WebCore/bindings/js/JSHTMLElementCustom.cpp
Source/WebCore/dom/CustomElementDefinitions.cpp
Source/WebCore/dom/CustomElementDefinitions.h

index 68c47b1..434daaa 100644 (file)
@@ -1,3 +1,35 @@
+2016-03-05  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Move QualifiedName from CustomElementInfo to JSCustomElementInterface
+        https://bugs.webkit.org/show_bug.cgi?id=155061
+
+        Reviewed by Antti Koivisto.
+
+        Store QualifiedName of custom elements in JSCustomElementInterface instead of CustomElementInfo
+        now that each interface is associated with exactly one custom element as of r197602.
+
+        No new tests since this is a refactoring.
+
+        * bindings/js/JSCustomElementInterface.cpp:
+        (WebCore::JSCustomElementInterface::JSCustomElementInterface): Now takes QualifiedName as the
+        first argument.
+        * bindings/js/JSCustomElementInterface.h:
+        (WebCore::JSCustomElementInterface::create):
+        (WebCore::JSCustomElementInterface::name): Added.
+        * bindings/js/JSDocumentCustom.cpp:
+        (WebCore::JSDocument::defineElement):
+        * bindings/js/JSHTMLElementCustom.cpp:
+        (WebCore::constructJSHTMLElement): Use findInterface instead of the deleted findName.
+        * dom/CustomElementDefinitions.cpp:
+        (WebCore::CustomElementDefinitions::checkName):
+        (WebCore::CustomElementDefinitions::addElementDefinition): Renamed from defineElement.
+        (WebCore::CustomElementDefinitions::findInterface): Add a variant that finds the interface object
+        by a JS constructor.
+        (WebCore::CustomElementDefinitions::containsConstructor):
+        (WebCore::CustomElementDefinitions::findName): Deleted.
+        * dom/CustomElementDefinitions.h:
+        (WebCore::CustomElementDefinitions::CustomElementInfo::CustomElementInfo): Deleted.
+
 2016-03-04  Ryosuke Niwa  <rniwa@webkit.org>
 
         Add basic support for attributeChanged lifecycle callback
index 5a19bc1..515b6de 100644 (file)
@@ -44,8 +44,9 @@ using namespace JSC;
 
 namespace WebCore {
 
-JSCustomElementInterface::JSCustomElementInterface(JSObject* constructor, JSDOMGlobalObject* globalObject)
+JSCustomElementInterface::JSCustomElementInterface(const QualifiedName& name, JSObject* constructor, JSDOMGlobalObject* globalObject)
     : ActiveDOMCallback(globalObject->scriptExecutionContext())
+    , m_name(name)
     , m_constructor(constructor)
     , m_isolatedWorld(&globalObject->world())
 {
index 175c3b8..6c5544a 100644 (file)
@@ -30,6 +30,7 @@
 #if ENABLE(CUSTOM_ELEMENTS)
 
 #include "ActiveDOMCallback.h"
+#include "QualifiedName.h"
 #include <heap/Weak.h>
 #include <heap/WeakInlines.h>
 #include <runtime/JSObject.h>
@@ -50,14 +51,13 @@ class DOMWrapperWorld;
 class Element;
 class JSDOMGlobalObject;
 class MathMLElement;
-class QualifiedName;
 class SVGElement;
 
 class JSCustomElementInterface : public RefCounted<JSCustomElementInterface>, public ActiveDOMCallback {
 public:
-    static Ref<JSCustomElementInterface> create(JSC::JSObject* callback, JSDOMGlobalObject* globalObject)
+    static Ref<JSCustomElementInterface> create(const QualifiedName& name, JSC::JSObject* callback, JSDOMGlobalObject* globalObject)
     {
-        return adoptRef(*new JSCustomElementInterface(callback, globalObject));
+        return adoptRef(*new JSCustomElementInterface(name, callback, globalObject));
     }
 
     enum class ShouldClearException { Clear, DoNotClear };
@@ -68,11 +68,14 @@ public:
     ScriptExecutionContext* scriptExecutionContext() const { return ContextDestructionObserver::scriptExecutionContext(); }
     JSC::JSObject* constructor() { return m_constructor.get(); }
 
+    const QualifiedName& name() const { return m_name; }
+
     virtual ~JSCustomElementInterface();
 
 private:
-    JSCustomElementInterface(JSC::JSObject* callback, JSDOMGlobalObject*);
+    JSCustomElementInterface(const QualifiedName&, JSC::JSObject* callback, JSDOMGlobalObject*);
 
+    QualifiedName m_name;
     mutable JSC::Weak<JSC::JSObject> m_constructor;
     RefPtr<DOMWrapperWorld> m_isolatedWorld;
 };
index d634887..7f57f08 100644 (file)
@@ -181,7 +181,7 @@ JSValue JSDocument::defineElement(ExecState& state)
     // FIXME: 14. Let attributeChangedCallback be Get(prototype, "attributeChangedCallback"). Rethrow any exceptions.
 
     QualifiedName name(nullAtom, tagName, HTMLNames::xhtmlNamespaceURI);
-    definitions.defineElement(name, JSCustomElementInterface::create(object, globalObject()));
+    definitions.addElementDefinition(JSCustomElementInterface::create(name, object, globalObject()));
     PrivateName uniquePrivateName;
     globalObject()->putDirect(globalObject()->vm(), uniquePrivateName, object);
 
index bd5ab13..245e28f 100644 (file)
@@ -53,8 +53,8 @@ EncodedJSValue JSC_HOST_CALL constructJSHTMLElement(ExecState* state)
     VM& vm = state->vm();
     JSValue newTargetValue = state->thisValue();
     JSObject* newTarget = newTargetValue.getObject();
-    QualifiedName fullName = definitions->findName(newTarget);
-    if (fullName == nullQName())
+    auto* interface = definitions->findInterface(newTarget);
+    if (!interface)
         return throwVMTypeError(state, "new.target does not define a custom element");
 
     auto* globalObject = jsConstructor->globalObject();
@@ -63,7 +63,7 @@ EncodedJSValue JSC_HOST_CALL constructJSHTMLElement(ExecState* state)
     if (UNLIKELY(state->hadException()))
         return JSValue::encode(jsUndefined());
 
-    Ref<HTMLElement> element = HTMLElement::create(fullName, document);
+    Ref<HTMLElement> element = HTMLElement::create(interface->name(), document);
     auto* jsElement = JSHTMLElement::create(newElementStructure, globalObject, element.get());
     cacheWrapper(globalObject->world(), element.ptr(), jsElement);
     return JSValue::encode(jsElement);
index 9fe19a4..9a67016 100644 (file)
@@ -69,40 +69,35 @@ CustomElementDefinitions::NameStatus CustomElementDefinitions::checkName(const A
     return NameStatus::Valid;
 }
 
-bool CustomElementDefinitions::defineElement(const QualifiedName& fullName, Ref<JSCustomElementInterface>&& interface)
+void CustomElementDefinitions::addElementDefinition(Ref<JSCustomElementInterface>&& interface)
 {
-    ASSERT(!m_nameMap.contains(fullName.localName()));
-    auto* constructor = interface->constructor();
-    m_nameMap.add(fullName.localName(), CustomElementInfo(fullName, WTFMove(interface)));
-
-    auto addResult = m_constructorMap.add(constructor, fullName);
-    if (!addResult.isNewEntry)
-        addResult.iterator->value = nullQName(); // The interface has multiple tag names associated with it.
-
-    return true;
+    AtomicString localName = interface->name().localName();
+    ASSERT(!m_nameMap.contains(localName));
+    m_constructorMap.add(interface->constructor(), interface.ptr());
+    m_nameMap.add(localName, WTFMove(interface));
 }
 
 JSCustomElementInterface* CustomElementDefinitions::findInterface(const QualifiedName& name) const
 {
     auto it = m_nameMap.find(name.localName());
-    return it == m_nameMap.end() || it->value.fullName != name ? nullptr : it->value.interface.get();
+    return it == m_nameMap.end() || it->value->name() != name ? nullptr : it->value.get();
 }
 
 JSCustomElementInterface* CustomElementDefinitions::findInterface(const AtomicString& name) const
 {
     auto it = m_nameMap.find(name);
-    return it == m_nameMap.end() ? nullptr : it->value.interface.get();
+    return it == m_nameMap.end() ? nullptr : it->value.get();
 }
 
-bool CustomElementDefinitions::containsConstructor(const JSC::JSObject* constructor) const
+JSCustomElementInterface* CustomElementDefinitions::findInterface(const JSC::JSObject* constructor) const
 {
-    return m_constructorMap.contains(constructor);
+    auto it = m_constructorMap.find(constructor);
+    return it->value;
 }
 
-const QualifiedName& CustomElementDefinitions::findName(const JSC::JSObject* constructor) const
+bool CustomElementDefinitions::containsConstructor(const JSC::JSObject* constructor) const
 {
-    auto it = m_constructorMap.find(constructor);
-    return it == m_constructorMap.end() ? nullQName() : it->value;
+    return m_constructorMap.contains(constructor);
 }
 
 }
index 893181f..d2498f4 100644 (file)
@@ -48,35 +48,19 @@ class QualifiedName;
 class CustomElementDefinitions {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    bool defineElement(const QualifiedName&, Ref<JSCustomElementInterface>&&);
+    void addElementDefinition(Ref<JSCustomElementInterface>&&);
 
     JSCustomElementInterface* findInterface(const QualifiedName&) const;
     JSCustomElementInterface* findInterface(const AtomicString&) const;
+    JSCustomElementInterface* findInterface(const JSC::JSObject*) const;
     bool containsConstructor(const JSC::JSObject*) const;
-    const QualifiedName& findName(const JSC::JSObject*) const;
 
     enum class NameStatus { Valid, ConflictsWithBuiltinNames, NoHyphen, ContainsUpperCase };
     static NameStatus checkName(const AtomicString& tagName);
 
 private:
-    class CustomElementInfo {
-        WTF_MAKE_FAST_ALLOCATED;
-    public:
-        QualifiedName fullName;
-        RefPtr<JSCustomElementInterface> interface;
-
-        CustomElementInfo()
-            : fullName(nullQName())
-        { }
-
-        CustomElementInfo(const QualifiedName& name, Ref<JSCustomElementInterface>&& interface)
-            : fullName(name)
-            , interface(WTFMove(interface))
-        { }
-    };
-
-    HashMap<AtomicString, CustomElementInfo> m_nameMap;
-    HashMap<const JSC::JSObject*, QualifiedName> m_constructorMap;
+    HashMap<AtomicString, RefPtr<JSCustomElementInterface>> m_nameMap;
+    HashMap<const JSC::JSObject*, JSCustomElementInterface*> m_constructorMap;
 };
     
 }