Diff
Modified: trunk/Source/WebCore/ChangeLog (197611 => 197612)
--- trunk/Source/WebCore/ChangeLog 2016-03-05 07:50:54 UTC (rev 197611)
+++ trunk/Source/WebCore/ChangeLog 2016-03-05 08:31:38 UTC (rev 197612)
@@ -1,3 +1,35 @@
+2016-03-05 Ryosuke Niwa <[email protected]>
+
+ 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 <[email protected]>
Add basic support for attributeChanged lifecycle callback
Modified: trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp (197611 => 197612)
--- trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp 2016-03-05 07:50:54 UTC (rev 197611)
+++ trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp 2016-03-05 08:31:38 UTC (rev 197612)
@@ -44,8 +44,9 @@
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())
{
Modified: trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h (197611 => 197612)
--- trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h 2016-03-05 07:50:54 UTC (rev 197611)
+++ trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h 2016-03-05 08:31:38 UTC (rev 197612)
@@ -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 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 @@
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;
};
Modified: trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp (197611 => 197612)
--- trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp 2016-03-05 07:50:54 UTC (rev 197611)
+++ trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp 2016-03-05 08:31:38 UTC (rev 197612)
@@ -181,7 +181,7 @@
// 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);
Modified: trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp (197611 => 197612)
--- trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp 2016-03-05 07:50:54 UTC (rev 197611)
+++ trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp 2016-03-05 08:31:38 UTC (rev 197612)
@@ -53,8 +53,8 @@
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 @@
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);
Modified: trunk/Source/WebCore/dom/CustomElementDefinitions.cpp (197611 => 197612)
--- trunk/Source/WebCore/dom/CustomElementDefinitions.cpp 2016-03-05 07:50:54 UTC (rev 197611)
+++ trunk/Source/WebCore/dom/CustomElementDefinitions.cpp 2016-03-05 08:31:38 UTC (rev 197612)
@@ -69,40 +69,35 @@
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);
}
}
Modified: trunk/Source/WebCore/dom/CustomElementDefinitions.h (197611 => 197612)
--- trunk/Source/WebCore/dom/CustomElementDefinitions.h 2016-03-05 07:50:54 UTC (rev 197611)
+++ trunk/Source/WebCore/dom/CustomElementDefinitions.h 2016-03-05 08:31:38 UTC (rev 197612)
@@ -48,35 +48,19 @@
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;
};
}