Bug 1274159 - Part 1: Support looking up definitions by using constructor as a key;

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-02 21:24:22 -05:00 committed by Roy Tam
commit 516fe49cb2
5 changed files with 50 additions and 36 deletions

View file

@ -103,6 +103,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(CustomElementRegistry)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CustomElementRegistry)
tmp->mCustomDefinitions.Clear();
tmp->mConstructors.clear();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWhenDefinedPromiseMap)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
@ -149,6 +150,11 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(CustomElementRegistry)
"mCustomDefinitions prototype",
aClosure);
}
for (ConstructorMap::Enum iter(tmp->mConstructors); !iter.empty(); iter.popFront()) {
aCallbacks.Trace(&iter.front().mutableKey(),
"mConstructors key",
aClosure);
}
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
@ -183,6 +189,11 @@ CustomElementRegistry::Create(nsPIDOMWindowInner* aWindow)
RefPtr<CustomElementRegistry> customElementRegistry =
new CustomElementRegistry(aWindow);
if (!customElementRegistry->Init()) {
return nullptr;
}
return customElementRegistry.forget();
}
@ -241,6 +252,12 @@ CustomElementRegistry::~CustomElementRegistry()
mozilla::DropJSObjects(this);
}
bool
CustomElementRegistry::Init()
{
return mConstructors.init();
}
CustomElementDefinition*
CustomElementRegistry::LookupCustomElementDefinition(const nsAString& aLocalName,
const nsAString* aIs) const
@ -609,9 +626,13 @@ CustomElementRegistry::Define(const nsAString& aName,
* 4. If this CustomElementRegistry contains an entry with constructor constructor,
* then throw a "NotSupportedError" DOMException and abort these steps.
*/
// TODO: Step 3 of HTMLConstructor also needs a way to look up definition by
// using constructor. So I plans to figure out a solution to support both of
// them in bug 1274159.
const auto& ptr = mConstructors.lookup(constructorUnwrapped);
if (ptr) {
MOZ_ASSERT(mCustomDefinitions.Get(ptr->value()),
"Definition must be found in mCustomDefinitions");
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return;
}
/**
* 5. Let localName be name.
@ -767,8 +788,16 @@ CustomElementRegistry::Define(const nsAString& aName,
/**
* 12. Add definition to this CustomElementRegistry.
*/
if (!mConstructors.put(constructorUnwrapped, nameAtom)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
mCustomDefinitions.Put(nameAtom, definition);
MOZ_ASSERT(mCustomDefinitions.Count() == mConstructors.count(),
"Number of entries should be the same");
/**
* 13. 14. 15. Upgrade candidates
*/
@ -853,4 +882,4 @@ CustomElementDefinition::CustomElementDefinition(nsIAtom* aType,
}
} // namespace dom
} // namespace mozilla
} // namespace mozilla