Changeset 197612 in webkit
- Timestamp:
- Mar 5, 2016 12:31:38 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r197611 r197612 1 2016-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 1 33 2016-03-04 Ryosuke Niwa <rniwa@webkit.org> 2 34 -
trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp
r197611 r197612 45 45 namespace WebCore { 46 46 47 JSCustomElementInterface::JSCustomElementInterface( JSObject* constructor, JSDOMGlobalObject* globalObject)47 JSCustomElementInterface::JSCustomElementInterface(const QualifiedName& name, JSObject* constructor, JSDOMGlobalObject* globalObject) 48 48 : ActiveDOMCallback(globalObject->scriptExecutionContext()) 49 , m_name(name) 49 50 , m_constructor(constructor) 50 51 , m_isolatedWorld(&globalObject->world()) -
trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h
r197611 r197612 31 31 32 32 #include "ActiveDOMCallback.h" 33 #include "QualifiedName.h" 33 34 #include <heap/Weak.h> 34 35 #include <heap/WeakInlines.h> … … 51 52 class JSDOMGlobalObject; 52 53 class MathMLElement; 53 class QualifiedName;54 54 class SVGElement; 55 55 56 56 class JSCustomElementInterface : public RefCounted<JSCustomElementInterface>, public ActiveDOMCallback { 57 57 public: 58 static Ref<JSCustomElementInterface> create( JSC::JSObject* callback, JSDOMGlobalObject* globalObject)58 static Ref<JSCustomElementInterface> create(const QualifiedName& name, JSC::JSObject* callback, JSDOMGlobalObject* globalObject) 59 59 { 60 return adoptRef(*new JSCustomElementInterface( callback, globalObject));60 return adoptRef(*new JSCustomElementInterface(name, callback, globalObject)); 61 61 } 62 62 … … 69 69 JSC::JSObject* constructor() { return m_constructor.get(); } 70 70 71 const QualifiedName& name() const { return m_name; } 72 71 73 virtual ~JSCustomElementInterface(); 72 74 73 75 private: 74 JSCustomElementInterface( JSC::JSObject* callback, JSDOMGlobalObject*);76 JSCustomElementInterface(const QualifiedName&, JSC::JSObject* callback, JSDOMGlobalObject*); 75 77 78 QualifiedName m_name; 76 79 mutable JSC::Weak<JSC::JSObject> m_constructor; 77 80 RefPtr<DOMWrapperWorld> m_isolatedWorld; -
trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp
r197602 r197612 182 182 183 183 QualifiedName name(nullAtom, tagName, HTMLNames::xhtmlNamespaceURI); 184 definitions. defineElement(name, JSCustomElementInterface::create(object, globalObject()));184 definitions.addElementDefinition(JSCustomElementInterface::create(name, object, globalObject())); 185 185 PrivateName uniquePrivateName; 186 186 globalObject()->putDirect(globalObject()->vm(), uniquePrivateName, object); -
trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp
r197602 r197612 54 54 JSValue newTargetValue = state->thisValue(); 55 55 JSObject* newTarget = newTargetValue.getObject(); 56 QualifiedName fullName = definitions->findName(newTarget);57 if ( fullName == nullQName())56 auto* interface = definitions->findInterface(newTarget); 57 if (!interface) 58 58 return throwVMTypeError(state, "new.target does not define a custom element"); 59 59 … … 64 64 return JSValue::encode(jsUndefined()); 65 65 66 Ref<HTMLElement> element = HTMLElement::create( fullName, document);66 Ref<HTMLElement> element = HTMLElement::create(interface->name(), document); 67 67 auto* jsElement = JSHTMLElement::create(newElementStructure, globalObject, element.get()); 68 68 cacheWrapper(globalObject->world(), element.ptr(), jsElement); -
trunk/Source/WebCore/dom/CustomElementDefinitions.cpp
r197602 r197612 70 70 } 71 71 72 bool CustomElementDefinitions::defineElement(const QualifiedName& fullName,Ref<JSCustomElementInterface>&& interface)72 void CustomElementDefinitions::addElementDefinition(Ref<JSCustomElementInterface>&& interface) 73 73 { 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)); 83 78 } 84 79 … … 86 81 { 87 82 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(); 89 84 } 90 85 … … 92 87 { 93 88 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 92 JSCustomElementInterface* CustomElementDefinitions::findInterface(const JSC::JSObject* constructor) const 93 { 94 auto it = m_constructorMap.find(constructor); 95 return it->value; 95 96 } 96 97 … … 100 101 } 101 102 102 const QualifiedName& CustomElementDefinitions::findName(const JSC::JSObject* constructor) const103 {104 auto it = m_constructorMap.find(constructor);105 return it == m_constructorMap.end() ? nullQName() : it->value;106 }107 108 103 } 109 104 -
trunk/Source/WebCore/dom/CustomElementDefinitions.h
r197602 r197612 49 49 WTF_MAKE_FAST_ALLOCATED; 50 50 public: 51 bool defineElement(const QualifiedName&,Ref<JSCustomElementInterface>&&);51 void addElementDefinition(Ref<JSCustomElementInterface>&&); 52 52 53 53 JSCustomElementInterface* findInterface(const QualifiedName&) const; 54 54 JSCustomElementInterface* findInterface(const AtomicString&) const; 55 JSCustomElementInterface* findInterface(const JSC::JSObject*) const; 55 56 bool containsConstructor(const JSC::JSObject*) const; 56 const QualifiedName& findName(const JSC::JSObject*) const;57 57 58 58 enum class NameStatus { Valid, ConflictsWithBuiltinNames, NoHyphen, ContainsUpperCase }; … … 60 60 61 61 private: 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; 80 64 }; 81 65
Note: See TracChangeset
for help on using the changeset viewer.