Changeset 197612 in webkit


Ignore:
Timestamp:
Mar 5, 2016 12:31:38 AM (8 years ago)
Author:
rniwa@webkit.org
Message:

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.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r197611 r197612  
     12016-03-05  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Move QualifiedName from CustomElementInfo to JSCustomElementInterface
     4        https://bugs.webkit.org/show_bug.cgi?id=155061
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Store QualifiedName of custom elements in JSCustomElementInterface instead of CustomElementInfo
     9        now that each interface is associated with exactly one custom element as of r197602.
     10
     11        No new tests since this is a refactoring.
     12
     13        * bindings/js/JSCustomElementInterface.cpp:
     14        (WebCore::JSCustomElementInterface::JSCustomElementInterface): Now takes QualifiedName as the
     15        first argument.
     16        * bindings/js/JSCustomElementInterface.h:
     17        (WebCore::JSCustomElementInterface::create):
     18        (WebCore::JSCustomElementInterface::name): Added.
     19        * bindings/js/JSDocumentCustom.cpp:
     20        (WebCore::JSDocument::defineElement):
     21        * bindings/js/JSHTMLElementCustom.cpp:
     22        (WebCore::constructJSHTMLElement): Use findInterface instead of the deleted findName.
     23        * dom/CustomElementDefinitions.cpp:
     24        (WebCore::CustomElementDefinitions::checkName):
     25        (WebCore::CustomElementDefinitions::addElementDefinition): Renamed from defineElement.
     26        (WebCore::CustomElementDefinitions::findInterface): Add a variant that finds the interface object
     27        by a JS constructor.
     28        (WebCore::CustomElementDefinitions::containsConstructor):
     29        (WebCore::CustomElementDefinitions::findName): Deleted.
     30        * dom/CustomElementDefinitions.h:
     31        (WebCore::CustomElementDefinitions::CustomElementInfo::CustomElementInfo): Deleted.
     32
    1332016-03-04  Ryosuke Niwa  <rniwa@webkit.org>
    234
  • trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp

    r197611 r197612  
    4545namespace WebCore {
    4646
    47 JSCustomElementInterface::JSCustomElementInterface(JSObject* constructor, JSDOMGlobalObject* globalObject)
     47JSCustomElementInterface::JSCustomElementInterface(const QualifiedName& name, JSObject* constructor, JSDOMGlobalObject* globalObject)
    4848    : ActiveDOMCallback(globalObject->scriptExecutionContext())
     49    , m_name(name)
    4950    , m_constructor(constructor)
    5051    , m_isolatedWorld(&globalObject->world())
  • trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h

    r197611 r197612  
    3131
    3232#include "ActiveDOMCallback.h"
     33#include "QualifiedName.h"
    3334#include <heap/Weak.h>
    3435#include <heap/WeakInlines.h>
     
    5152class JSDOMGlobalObject;
    5253class MathMLElement;
    53 class QualifiedName;
    5454class SVGElement;
    5555
    5656class JSCustomElementInterface : public RefCounted<JSCustomElementInterface>, public ActiveDOMCallback {
    5757public:
    58     static Ref<JSCustomElementInterface> create(JSC::JSObject* callback, JSDOMGlobalObject* globalObject)
     58    static Ref<JSCustomElementInterface> create(const QualifiedName& name, JSC::JSObject* callback, JSDOMGlobalObject* globalObject)
    5959    {
    60         return adoptRef(*new JSCustomElementInterface(callback, globalObject));
     60        return adoptRef(*new JSCustomElementInterface(name, callback, globalObject));
    6161    }
    6262
     
    6969    JSC::JSObject* constructor() { return m_constructor.get(); }
    7070
     71    const QualifiedName& name() const { return m_name; }
     72
    7173    virtual ~JSCustomElementInterface();
    7274
    7375private:
    74     JSCustomElementInterface(JSC::JSObject* callback, JSDOMGlobalObject*);
     76    JSCustomElementInterface(const QualifiedName&, JSC::JSObject* callback, JSDOMGlobalObject*);
    7577
     78    QualifiedName m_name;
    7679    mutable JSC::Weak<JSC::JSObject> m_constructor;
    7780    RefPtr<DOMWrapperWorld> m_isolatedWorld;
  • trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp

    r197602 r197612  
    182182
    183183    QualifiedName name(nullAtom, tagName, HTMLNames::xhtmlNamespaceURI);
    184     definitions.defineElement(name, JSCustomElementInterface::create(object, globalObject()));
     184    definitions.addElementDefinition(JSCustomElementInterface::create(name, object, globalObject()));
    185185    PrivateName uniquePrivateName;
    186186    globalObject()->putDirect(globalObject()->vm(), uniquePrivateName, object);
  • trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp

    r197602 r197612  
    5454    JSValue newTargetValue = state->thisValue();
    5555    JSObject* newTarget = newTargetValue.getObject();
    56     QualifiedName fullName = definitions->findName(newTarget);
    57     if (fullName == nullQName())
     56    auto* interface = definitions->findInterface(newTarget);
     57    if (!interface)
    5858        return throwVMTypeError(state, "new.target does not define a custom element");
    5959
     
    6464        return JSValue::encode(jsUndefined());
    6565
    66     Ref<HTMLElement> element = HTMLElement::create(fullName, document);
     66    Ref<HTMLElement> element = HTMLElement::create(interface->name(), document);
    6767    auto* jsElement = JSHTMLElement::create(newElementStructure, globalObject, element.get());
    6868    cacheWrapper(globalObject->world(), element.ptr(), jsElement);
  • trunk/Source/WebCore/dom/CustomElementDefinitions.cpp

    r197602 r197612  
    7070}
    7171
    72 bool CustomElementDefinitions::defineElement(const QualifiedName& fullName, Ref<JSCustomElementInterface>&& interface)
     72void CustomElementDefinitions::addElementDefinition(Ref<JSCustomElementInterface>&& interface)
    7373{
    74     ASSERT(!m_nameMap.contains(fullName.localName()));
    75     auto* constructor = interface->constructor();
    76     m_nameMap.add(fullName.localName(), CustomElementInfo(fullName, WTFMove(interface)));
    77 
    78     auto addResult = m_constructorMap.add(constructor, fullName);
    79     if (!addResult.isNewEntry)
    80         addResult.iterator->value = nullQName(); // The interface has multiple tag names associated with it.
    81 
    82     return true;
     74    AtomicString localName = interface->name().localName();
     75    ASSERT(!m_nameMap.contains(localName));
     76    m_constructorMap.add(interface->constructor(), interface.ptr());
     77    m_nameMap.add(localName, WTFMove(interface));
    8378}
    8479
     
    8681{
    8782    auto it = m_nameMap.find(name.localName());
    88     return it == m_nameMap.end() || it->value.fullName != name ? nullptr : it->value.interface.get();
     83    return it == m_nameMap.end() || it->value->name() != name ? nullptr : it->value.get();
    8984}
    9085
     
    9287{
    9388    auto it = m_nameMap.find(name);
    94     return it == m_nameMap.end() ? nullptr : it->value.interface.get();
     89    return it == m_nameMap.end() ? nullptr : it->value.get();
     90}
     91
     92JSCustomElementInterface* CustomElementDefinitions::findInterface(const JSC::JSObject* constructor) const
     93{
     94    auto it = m_constructorMap.find(constructor);
     95    return it->value;
    9596}
    9697
     
    100101}
    101102
    102 const QualifiedName& CustomElementDefinitions::findName(const JSC::JSObject* constructor) const
    103 {
    104     auto it = m_constructorMap.find(constructor);
    105     return it == m_constructorMap.end() ? nullQName() : it->value;
    106 }
    107 
    108103}
    109104
  • trunk/Source/WebCore/dom/CustomElementDefinitions.h

    r197602 r197612  
    4949    WTF_MAKE_FAST_ALLOCATED;
    5050public:
    51     bool defineElement(const QualifiedName&, Ref<JSCustomElementInterface>&&);
     51    void addElementDefinition(Ref<JSCustomElementInterface>&&);
    5252
    5353    JSCustomElementInterface* findInterface(const QualifiedName&) const;
    5454    JSCustomElementInterface* findInterface(const AtomicString&) const;
     55    JSCustomElementInterface* findInterface(const JSC::JSObject*) const;
    5556    bool containsConstructor(const JSC::JSObject*) const;
    56     const QualifiedName& findName(const JSC::JSObject*) const;
    5757
    5858    enum class NameStatus { Valid, ConflictsWithBuiltinNames, NoHyphen, ContainsUpperCase };
     
    6060
    6161private:
    62     class CustomElementInfo {
    63         WTF_MAKE_FAST_ALLOCATED;
    64     public:
    65         QualifiedName fullName;
    66         RefPtr<JSCustomElementInterface> interface;
    67 
    68         CustomElementInfo()
    69             : fullName(nullQName())
    70         { }
    71 
    72         CustomElementInfo(const QualifiedName& name, Ref<JSCustomElementInterface>&& interface)
    73             : fullName(name)
    74             , interface(WTFMove(interface))
    75         { }
    76     };
    77 
    78     HashMap<AtomicString, CustomElementInfo> m_nameMap;
    79     HashMap<const JSC::JSObject*, QualifiedName> m_constructorMap;
     62    HashMap<AtomicString, RefPtr<JSCustomElementInterface>> m_nameMap;
     63    HashMap<const JSC::JSObject*, JSCustomElementInterface*> m_constructorMap;
    8064};
    8165   
Note: See TracChangeset for help on using the changeset viewer.