2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2016-07-25 00:38:00 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-10-12 10:26:02 +03:00
|
|
|
#include "mozilla/dom/CustomElementRegistry.h"
|
2016-08-30 06:48:53 +03:00
|
|
|
|
2017-10-05 18:34:12 +03:00
|
|
|
#include "mozilla/CycleCollectedJSContext.h"
|
2016-10-12 10:26:02 +03:00
|
|
|
#include "mozilla/dom/CustomElementRegistryBinding.h"
|
2016-09-01 10:11:32 +03:00
|
|
|
#include "mozilla/dom/HTMLElementBinding.h"
|
2017-10-12 15:50:23 +03:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2016-07-25 00:38:00 +03:00
|
|
|
#include "mozilla/dom/WebComponentsBinding.h"
|
2017-03-21 07:42:00 +03:00
|
|
|
#include "mozilla/dom/DocGroup.h"
|
2017-09-05 13:19:06 +03:00
|
|
|
#include "nsHTMLTags.h"
|
2016-09-01 10:11:32 +03:00
|
|
|
#include "jsapi.h"
|
2016-07-25 00:38:00 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2016-08-30 06:48:53 +03:00
|
|
|
void
|
|
|
|
CustomElementCallback::Call()
|
|
|
|
{
|
2017-08-13 11:40:37 +03:00
|
|
|
IgnoredErrorResult rv;
|
2016-08-30 06:48:53 +03:00
|
|
|
switch (mType) {
|
2017-09-26 08:55:58 +03:00
|
|
|
case nsIDocument::eConnected:
|
|
|
|
static_cast<LifecycleConnectedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
2016-08-30 06:48:53 +03:00
|
|
|
break;
|
2017-09-26 08:56:11 +03:00
|
|
|
case nsIDocument::eDisconnected:
|
|
|
|
static_cast<LifecycleDisconnectedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
2016-08-30 06:48:53 +03:00
|
|
|
break;
|
2017-10-02 07:42:00 +03:00
|
|
|
case nsIDocument::eAdopted:
|
|
|
|
static_cast<LifecycleAdoptedCallback *>(mCallback.get())->Call(mThisObject,
|
|
|
|
mAdoptedCallbackArgs.mOldDocument, mAdoptedCallbackArgs.mNewDocument, rv);
|
|
|
|
break;
|
2016-08-30 06:48:53 +03:00
|
|
|
case nsIDocument::eAttributeChanged:
|
|
|
|
static_cast<LifecycleAttributeChangedCallback *>(mCallback.get())->Call(mThisObject,
|
2017-08-28 06:25:00 +03:00
|
|
|
mArgs.name, mArgs.oldValue, mArgs.newValue, mArgs.namespaceURI, rv);
|
2016-08-30 06:48:53 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CustomElementCallback::Traverse(nsCycleCollectionTraversalCallback& aCb) const
|
|
|
|
{
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mThisObject");
|
|
|
|
aCb.NoteXPCOMChild(mThisObject);
|
|
|
|
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mCallback");
|
|
|
|
aCb.NoteXPCOMChild(mCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomElementCallback::CustomElementCallback(Element* aThisObject,
|
|
|
|
nsIDocument::ElementCallbackType aCallbackType,
|
2017-10-13 18:36:54 +03:00
|
|
|
mozilla::dom::CallbackFunction* aCallback)
|
2016-08-30 06:48:53 +03:00
|
|
|
: mThisObject(aThisObject),
|
|
|
|
mCallback(aCallback),
|
2017-10-13 18:36:54 +03:00
|
|
|
mType(aCallbackType)
|
2016-08-30 06:48:53 +03:00
|
|
|
{
|
|
|
|
}
|
2017-08-13 11:40:37 +03:00
|
|
|
//-----------------------------------------------------
|
|
|
|
// CustomElementConstructor
|
|
|
|
|
|
|
|
already_AddRefed<Element>
|
|
|
|
CustomElementConstructor::Construct(const char* aExecutionReason,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
CallSetup s(this, aRv, aExecutionReason,
|
|
|
|
CallbackFunction::eRethrowExceptions);
|
|
|
|
|
|
|
|
JSContext* cx = s.GetContext();
|
|
|
|
if (!cx) {
|
|
|
|
MOZ_ASSERT(aRv.Failed());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> result(cx);
|
|
|
|
JS::Rooted<JS::Value> constructor(cx, JS::ObjectValue(*mCallback));
|
|
|
|
if (!JS::Construct(cx, constructor, JS::HandleValueArray::empty(), &result)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-08-30 06:48:53 +03:00
|
|
|
|
2017-08-13 11:40:37 +03:00
|
|
|
RefPtr<Element> element;
|
|
|
|
if (NS_FAILED(UNWRAP_OBJECT(Element, &result, element))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return element.forget();
|
|
|
|
}
|
2016-12-28 06:43:29 +03:00
|
|
|
//-----------------------------------------------------
|
|
|
|
// CustomElementData
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
CustomElementData::CustomElementData(nsAtom* aType)
|
2016-12-28 06:43:29 +03:00
|
|
|
: CustomElementData(aType, CustomElementData::State::eUndefined)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
CustomElementData::CustomElementData(nsAtom* aType, State aState)
|
2017-10-13 18:36:54 +03:00
|
|
|
: mState(aState)
|
2017-11-14 14:23:00 +03:00
|
|
|
, mType(aType)
|
2016-08-30 06:48:53 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-13 06:54:46 +03:00
|
|
|
void
|
|
|
|
CustomElementData::SetCustomElementDefinition(CustomElementDefinition* aDefinition)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mState == State::eCustom);
|
|
|
|
MOZ_ASSERT(!mCustomElementDefinition);
|
|
|
|
MOZ_ASSERT(aDefinition->mType == mType);
|
|
|
|
|
|
|
|
mCustomElementDefinition = aDefinition;
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomElementDefinition*
|
|
|
|
CustomElementData::GetCustomElementDefinition()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCustomElementDefinition ? mState == State::eCustom
|
|
|
|
: mState != State::eCustom);
|
|
|
|
|
|
|
|
return mCustomElementDefinition;
|
|
|
|
}
|
|
|
|
|
2017-11-14 14:23:00 +03:00
|
|
|
nsAtom*
|
|
|
|
CustomElementData::GetCustomElementType()
|
|
|
|
{
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
2017-10-13 06:54:46 +03:00
|
|
|
void
|
|
|
|
CustomElementData::Traverse(nsCycleCollectionTraversalCallback& aCb) const
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mReactionQueue.Length(); i++) {
|
|
|
|
if (mReactionQueue[i]) {
|
|
|
|
mReactionQueue[i]->Traverse(aCb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCustomElementDefinition) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mCustomElementDefinition");
|
|
|
|
aCb.NoteNativeChild(mCustomElementDefinition,
|
|
|
|
NS_CYCLE_COLLECTION_PARTICIPANT(CustomElementDefinition));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CustomElementData::Unlink()
|
|
|
|
{
|
|
|
|
mReactionQueue.Clear();
|
|
|
|
mCustomElementDefinition = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-12-28 06:43:29 +03:00
|
|
|
//-----------------------------------------------------
|
|
|
|
// CustomElementRegistry
|
|
|
|
|
2017-08-13 11:40:37 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class MOZ_RAII AutoConstructionStackEntry final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoConstructionStackEntry(nsTArray<RefPtr<nsGenericHTMLElement>>& aStack,
|
|
|
|
nsGenericHTMLElement* aElement)
|
|
|
|
: mStack(aStack)
|
|
|
|
{
|
|
|
|
mIndex = mStack.Length();
|
|
|
|
mStack.AppendElement(aElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoConstructionStackEntry()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIndex == mStack.Length() - 1,
|
|
|
|
"Removed element should be the last element");
|
|
|
|
mStack.RemoveElementAt(mIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsTArray<RefPtr<nsGenericHTMLElement>>& mStack;
|
|
|
|
uint32_t mIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace anonymous
|
|
|
|
|
2016-07-25 00:38:00 +03:00
|
|
|
// Only needed for refcounted objects.
|
2016-10-12 10:26:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CustomElementRegistry)
|
2016-08-30 06:48:53 +03:00
|
|
|
|
2016-10-12 10:26:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CustomElementRegistry)
|
2016-09-07 12:55:21 +03:00
|
|
|
tmp->mConstructors.clear();
|
2017-09-25 09:46:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCustomDefinitions)
|
2016-10-07 09:16:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWhenDefinedPromiseMap)
|
2016-08-30 06:48:53 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2016-10-12 10:26:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CustomElementRegistry)
|
2017-09-25 09:46:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCustomDefinitions)
|
2016-10-07 09:16:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWhenDefinedPromiseMap)
|
2016-08-30 06:48:53 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2016-10-12 10:26:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(CustomElementRegistry)
|
2016-08-30 06:48:53 +03:00
|
|
|
for (auto iter = tmp->mCustomDefinitions.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
aCallbacks.Trace(&iter.UserData()->mPrototype,
|
|
|
|
"mCustomDefinitions prototype",
|
|
|
|
aClosure);
|
|
|
|
}
|
2016-09-07 12:55:21 +03:00
|
|
|
|
|
|
|
for (ConstructorMap::Enum iter(tmp->mConstructors); !iter.empty(); iter.popFront()) {
|
|
|
|
aCallbacks.Trace(&iter.front().mutableKey(),
|
|
|
|
"mConstructors key",
|
|
|
|
aClosure);
|
|
|
|
}
|
2016-08-30 06:48:53 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2016-10-12 10:26:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(CustomElementRegistry)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(CustomElementRegistry)
|
2016-08-30 06:48:53 +03:00
|
|
|
|
2016-10-12 10:26:02 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CustomElementRegistry)
|
2016-07-25 00:38:00 +03:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2016-10-12 10:26:02 +03:00
|
|
|
CustomElementRegistry::CustomElementRegistry(nsPIDOMWindowInner* aWindow)
|
2016-07-25 00:38:00 +03:00
|
|
|
: mWindow(aWindow)
|
2016-09-01 10:11:32 +03:00
|
|
|
, mIsCustomDefinitionRunning(false)
|
2016-07-25 00:38:00 +03:00
|
|
|
{
|
2017-02-23 13:24:05 +03:00
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
MOZ_ALWAYS_TRUE(mConstructors.init());
|
|
|
|
|
2016-08-30 06:48:53 +03:00
|
|
|
mozilla::HoldJSObjects(this);
|
2016-07-25 00:38:00 +03:00
|
|
|
}
|
|
|
|
|
2016-10-12 10:26:02 +03:00
|
|
|
CustomElementRegistry::~CustomElementRegistry()
|
2016-07-25 00:38:00 +03:00
|
|
|
{
|
2016-08-30 06:48:53 +03:00
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomElementDefinition*
|
2016-10-12 10:26:02 +03:00
|
|
|
CustomElementRegistry::LookupCustomElementDefinition(const nsAString& aLocalName,
|
2017-11-14 14:23:00 +03:00
|
|
|
nsAtom* aTypeAtom) const
|
2016-08-30 06:48:53 +03:00
|
|
|
{
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> localNameAtom = NS_Atomize(aLocalName);
|
2017-11-14 14:23:00 +03:00
|
|
|
CustomElementDefinition* data = mCustomDefinitions.GetWeak(aTypeAtom);
|
2016-08-30 06:48:53 +03:00
|
|
|
if (data && data->mLocalName == localNameAtom) {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-11-17 18:31:50 +03:00
|
|
|
CustomElementDefinition*
|
|
|
|
CustomElementRegistry::LookupCustomElementDefinition(JSContext* aCx,
|
|
|
|
JSObject* aConstructor) const
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> constructor(aCx, js::CheckedUnwrap(aConstructor));
|
|
|
|
|
|
|
|
const auto& ptr = mConstructors.lookup(constructor);
|
|
|
|
if (!ptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:46:00 +03:00
|
|
|
CustomElementDefinition* definition = mCustomDefinitions.GetWeak(ptr->value());
|
2016-11-17 18:31:50 +03:00
|
|
|
MOZ_ASSERT(definition, "Definition must be found in mCustomDefinitions");
|
|
|
|
|
|
|
|
return definition;
|
|
|
|
}
|
|
|
|
|
2016-08-30 06:48:53 +03:00
|
|
|
void
|
2017-10-03 01:05:19 +03:00
|
|
|
CustomElementRegistry::RegisterUnresolvedElement(Element* aElement, nsAtom* aTypeName)
|
2016-08-30 06:48:53 +03:00
|
|
|
{
|
|
|
|
mozilla::dom::NodeInfo* info = aElement->NodeInfo();
|
|
|
|
|
|
|
|
// Candidate may be a custom element through extension,
|
|
|
|
// in which case the custom element type name will not
|
|
|
|
// match the element tag name. e.g. <button is="x-button">.
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> typeName = aTypeName;
|
2016-08-30 06:48:53 +03:00
|
|
|
if (!typeName) {
|
|
|
|
typeName = info->NameAtom();
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:46:00 +03:00
|
|
|
if (mCustomDefinitions.GetWeak(typeName)) {
|
2016-08-30 06:48:53 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-01 10:11:32 +03:00
|
|
|
nsTArray<nsWeakPtr>* unresolved = mCandidatesMap.LookupOrAdd(typeName);
|
2016-08-30 06:48:53 +03:00
|
|
|
nsWeakPtr* elem = unresolved->AppendElement();
|
|
|
|
*elem = do_GetWeakReference(aElement);
|
|
|
|
aElement->AddStates(NS_EVENT_STATE_UNRESOLVED);
|
|
|
|
}
|
|
|
|
|
2017-11-14 14:25:00 +03:00
|
|
|
void
|
|
|
|
CustomElementRegistry::UnregisterUnresolvedElement(Element* aElement,
|
|
|
|
nsAtom* aTypeName)
|
|
|
|
{
|
|
|
|
nsTArray<nsWeakPtr>* candidates;
|
|
|
|
if (mCandidatesMap.Get(aTypeName, &candidates)) {
|
|
|
|
MOZ_ASSERT(candidates);
|
|
|
|
// We don't need to iterate the candidates array and remove the element from
|
|
|
|
// the array for performance reason. It'll be handled by bug 1396620.
|
|
|
|
for (size_t i = 0; i < candidates->Length(); ++i) {
|
|
|
|
nsCOMPtr<Element> elem = do_QueryReferent(candidates->ElementAt(i));
|
|
|
|
if (elem && elem.get() == aElement) {
|
|
|
|
candidates->RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 08:56:00 +03:00
|
|
|
/* static */ UniquePtr<CustomElementCallback>
|
2017-07-19 03:30:00 +03:00
|
|
|
CustomElementRegistry::CreateCustomElementCallback(
|
|
|
|
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
|
2017-10-02 07:42:00 +03:00
|
|
|
LifecycleCallbackArgs* aArgs,
|
|
|
|
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
|
|
|
|
CustomElementDefinition* aDefinition)
|
2016-08-30 06:48:53 +03:00
|
|
|
{
|
2017-09-25 09:47:00 +03:00
|
|
|
MOZ_ASSERT(aDefinition, "CustomElementDefinition should not be null");
|
2017-10-13 18:36:54 +03:00
|
|
|
MOZ_ASSERT(aCustomElement->GetCustomElementData(),
|
|
|
|
"CustomElementData should exist");
|
2016-08-30 06:48:53 +03:00
|
|
|
|
|
|
|
// Let CALLBACK be the callback associated with the key NAME in CALLBACKS.
|
|
|
|
CallbackFunction* func = nullptr;
|
|
|
|
switch (aType) {
|
2017-09-26 08:55:58 +03:00
|
|
|
case nsIDocument::eConnected:
|
|
|
|
if (aDefinition->mCallbacks->mConnectedCallback.WasPassed()) {
|
|
|
|
func = aDefinition->mCallbacks->mConnectedCallback.Value();
|
2016-08-30 06:48:53 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-09-26 08:56:11 +03:00
|
|
|
case nsIDocument::eDisconnected:
|
|
|
|
if (aDefinition->mCallbacks->mDisconnectedCallback.WasPassed()) {
|
|
|
|
func = aDefinition->mCallbacks->mDisconnectedCallback.Value();
|
2016-08-30 06:48:53 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-10-02 07:42:00 +03:00
|
|
|
case nsIDocument::eAdopted:
|
|
|
|
if (aDefinition->mCallbacks->mAdoptedCallback.WasPassed()) {
|
|
|
|
func = aDefinition->mCallbacks->mAdoptedCallback.Value();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-08-30 06:48:53 +03:00
|
|
|
case nsIDocument::eAttributeChanged:
|
2017-09-25 09:47:00 +03:00
|
|
|
if (aDefinition->mCallbacks->mAttributeChangedCallback.WasPassed()) {
|
|
|
|
func = aDefinition->mCallbacks->mAttributeChangedCallback.Value();
|
2016-08-30 06:48:53 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no such callback, stop.
|
|
|
|
if (!func) {
|
2017-07-19 03:30:00 +03:00
|
|
|
return nullptr;
|
2016-08-30 06:48:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add CALLBACK to ELEMENT's callback queue.
|
2017-07-19 03:30:00 +03:00
|
|
|
auto callback =
|
2017-10-13 18:36:54 +03:00
|
|
|
MakeUnique<CustomElementCallback>(aCustomElement, aType, func);
|
2017-07-19 03:30:00 +03:00
|
|
|
|
2016-08-30 06:48:53 +03:00
|
|
|
if (aArgs) {
|
|
|
|
callback->SetArgs(*aArgs);
|
|
|
|
}
|
|
|
|
|
2017-10-02 07:42:00 +03:00
|
|
|
if (aAdoptedCallbackArgs) {
|
|
|
|
callback->SetAdoptedCallbackArgs(*aAdoptedCallbackArgs);
|
|
|
|
}
|
2017-07-19 03:30:00 +03:00
|
|
|
return Move(callback);
|
|
|
|
}
|
2016-08-30 06:48:53 +03:00
|
|
|
|
2017-09-26 08:56:00 +03:00
|
|
|
/* static */ void
|
2017-07-19 03:30:00 +03:00
|
|
|
CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
|
|
|
|
Element* aCustomElement,
|
|
|
|
LifecycleCallbackArgs* aArgs,
|
2017-10-02 07:42:00 +03:00
|
|
|
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
|
2017-07-19 03:30:00 +03:00
|
|
|
CustomElementDefinition* aDefinition)
|
|
|
|
{
|
2017-08-28 06:25:00 +03:00
|
|
|
CustomElementDefinition* definition = aDefinition;
|
|
|
|
if (!definition) {
|
2017-09-25 09:47:00 +03:00
|
|
|
definition = aCustomElement->GetCustomElementDefinition();
|
|
|
|
if (!definition ||
|
|
|
|
definition->mLocalName != aCustomElement->NodeInfo()->NameAtom()) {
|
2017-08-28 06:25:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 03:30:00 +03:00
|
|
|
auto callback =
|
2017-10-02 07:42:00 +03:00
|
|
|
CreateCustomElementCallback(aType, aCustomElement, aArgs,
|
|
|
|
aAdoptedCallbackArgs, definition);
|
2017-07-19 03:30:00 +03:00
|
|
|
if (!callback) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-26 08:56:00 +03:00
|
|
|
DocGroup* docGroup = aCustomElement->OwnerDoc()->GetDocGroup();
|
2017-07-19 03:30:00 +03:00
|
|
|
if (!docGroup) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:25:00 +03:00
|
|
|
if (aType == nsIDocument::eAttributeChanged) {
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> attrName = NS_Atomize(aArgs->name);
|
2017-08-28 06:25:00 +03:00
|
|
|
if (definition->mObservedAttributes.IsEmpty() ||
|
|
|
|
!definition->mObservedAttributes.Contains(attrName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 03:30:00 +03:00
|
|
|
CustomElementReactionsStack* reactionsStack =
|
|
|
|
docGroup->CustomElementReactionsStack();
|
2017-10-12 12:01:41 +03:00
|
|
|
reactionsStack->EnqueueCallbackReaction(aCustomElement, Move(callback));
|
2016-08-30 06:48:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-10-03 01:05:19 +03:00
|
|
|
CustomElementRegistry::GetCustomPrototype(nsAtom* aAtom,
|
2016-10-12 10:26:02 +03:00
|
|
|
JS::MutableHandle<JSObject*> aPrototype)
|
2016-08-30 06:48:53 +03:00
|
|
|
{
|
2017-09-25 09:46:00 +03:00
|
|
|
mozilla::dom::CustomElementDefinition* definition =
|
|
|
|
mCustomDefinitions.GetWeak(aAtom);
|
2016-08-30 06:48:53 +03:00
|
|
|
if (definition) {
|
|
|
|
aPrototype.set(definition->mPrototype);
|
|
|
|
} else {
|
|
|
|
aPrototype.set(nullptr);
|
|
|
|
}
|
2016-07-25 00:38:00 +03:00
|
|
|
}
|
|
|
|
|
2016-09-01 10:11:32 +03:00
|
|
|
void
|
2017-10-03 01:05:19 +03:00
|
|
|
CustomElementRegistry::UpgradeCandidates(nsAtom* aKey,
|
2017-03-21 07:42:00 +03:00
|
|
|
CustomElementDefinition* aDefinition,
|
|
|
|
ErrorResult& aRv)
|
2016-09-01 10:11:32 +03:00
|
|
|
{
|
2017-03-21 07:42:00 +03:00
|
|
|
DocGroup* docGroup = mWindow->GetDocGroup();
|
|
|
|
if (!docGroup) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-13 11:40:37 +03:00
|
|
|
// TODO: Bug 1326028 - Upgrade custom element in shadow-including tree order
|
2016-09-01 10:11:32 +03:00
|
|
|
nsAutoPtr<nsTArray<nsWeakPtr>> candidates;
|
2017-07-05 03:01:45 +03:00
|
|
|
if (mCandidatesMap.Remove(aKey, &candidates)) {
|
|
|
|
MOZ_ASSERT(candidates);
|
2017-03-21 07:42:00 +03:00
|
|
|
CustomElementReactionsStack* reactionsStack =
|
|
|
|
docGroup->CustomElementReactionsStack();
|
2016-09-01 10:11:32 +03:00
|
|
|
for (size_t i = 0; i < candidates->Length(); ++i) {
|
|
|
|
nsCOMPtr<Element> elem = do_QueryReferent(candidates->ElementAt(i));
|
|
|
|
if (!elem) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-09-26 08:56:00 +03:00
|
|
|
reactionsStack->EnqueueUpgradeReaction(elem, aDefinition);
|
2016-09-01 10:11:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 00:38:00 +03:00
|
|
|
JSObject*
|
2016-10-12 10:26:02 +03:00
|
|
|
CustomElementRegistry::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2016-07-25 00:38:00 +03:00
|
|
|
{
|
2016-10-12 10:26:02 +03:00
|
|
|
return CustomElementRegistryBinding::Wrap(aCx, this, aGivenProto);
|
2016-07-25 00:38:00 +03:00
|
|
|
}
|
|
|
|
|
2016-10-12 10:26:02 +03:00
|
|
|
nsISupports* CustomElementRegistry::GetParentObject() const
|
2016-07-25 00:38:00 +03:00
|
|
|
{
|
|
|
|
return mWindow;
|
|
|
|
}
|
|
|
|
|
2016-09-01 10:11:32 +03:00
|
|
|
static const char* kLifeCycleCallbackNames[] = {
|
|
|
|
"connectedCallback",
|
|
|
|
"disconnectedCallback",
|
|
|
|
"adoptedCallback",
|
2017-10-13 18:36:54 +03:00
|
|
|
"attributeChangedCallback"
|
2016-09-01 10:11:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
CheckLifeCycleCallbacks(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aConstructor,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < ArrayLength(kLifeCycleCallbackNames); ++i) {
|
|
|
|
const char* callbackName = kLifeCycleCallbackNames[i];
|
|
|
|
JS::Rooted<JS::Value> callbackValue(aCx);
|
|
|
|
if (!JS_GetProperty(aCx, aConstructor, callbackName, &callbackValue)) {
|
|
|
|
aRv.StealExceptionFromJSContext(aCx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!callbackValue.isUndefined()) {
|
|
|
|
if (!callbackValue.isObject()) {
|
|
|
|
aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_ConvertASCIItoUTF16(callbackName));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JS::Rooted<JSObject*> callback(aCx, &callbackValue.toObject());
|
|
|
|
if (!JS::IsCallable(callback)) {
|
|
|
|
aRv.ThrowTypeError<MSG_NOT_CALLABLE>(NS_ConvertASCIItoUTF16(callbackName));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/scripting.html#element-definition
|
2016-08-30 06:48:53 +03:00
|
|
|
void
|
2016-10-12 10:26:02 +03:00
|
|
|
CustomElementRegistry::Define(const nsAString& aName,
|
|
|
|
Function& aFunctionConstructor,
|
|
|
|
const ElementDefinitionOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2016-07-25 00:38:00 +03:00
|
|
|
{
|
2016-09-01 10:11:32 +03:00
|
|
|
aRv.MightThrowJSException();
|
|
|
|
|
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *cx = jsapi.cx();
|
2017-09-05 03:21:06 +03:00
|
|
|
// Note: No calls that might run JS or trigger CC before this point, or
|
|
|
|
// there's a (vanishingly small) chance of our constructor being nulled
|
|
|
|
// before we access it.
|
2016-11-15 08:25:37 +03:00
|
|
|
JS::Rooted<JSObject*> constructor(cx, aFunctionConstructor.CallableOrNull());
|
2016-09-01 10:11:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 1. If IsConstructor(constructor) is false, then throw a TypeError and abort
|
|
|
|
* these steps.
|
|
|
|
*/
|
|
|
|
// For now, all wrappers are constructable if they are callable. So we need to
|
|
|
|
// unwrap constructor to check it is really constructable.
|
|
|
|
JS::Rooted<JSObject*> constructorUnwrapped(cx, js::CheckedUnwrap(constructor));
|
|
|
|
if (!constructorUnwrapped) {
|
|
|
|
// If the caller's compartment does not have permission to access the
|
|
|
|
// unwrapped constructor then throw.
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS::IsConstructor(constructorUnwrapped)) {
|
2016-10-12 10:26:02 +03:00
|
|
|
aRv.ThrowTypeError<MSG_NOT_CONSTRUCTOR>(NS_LITERAL_STRING("Argument 2 of CustomElementRegistry.define"));
|
2016-09-01 10:11:32 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 2. If name is not a valid custom element name, then throw a "SyntaxError"
|
|
|
|
* DOMException and abort these steps.
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> nameAtom(NS_Atomize(aName));
|
2016-09-01 10:11:32 +03:00
|
|
|
if (!nsContentUtils::IsCustomElementName(nameAtom)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-12 10:26:02 +03:00
|
|
|
* 3. If this CustomElementRegistry contains an entry with name name, then
|
2016-09-01 10:11:32 +03:00
|
|
|
* throw a "NotSupportedError" DOMException and abort these steps.
|
|
|
|
*/
|
2017-09-25 09:46:00 +03:00
|
|
|
if (mCustomDefinitions.GetWeak(nameAtom)) {
|
2016-09-01 10:11:32 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-12 10:26:02 +03:00
|
|
|
* 4. If this CustomElementRegistry contains an entry with constructor constructor,
|
2016-09-01 10:11:32 +03:00
|
|
|
* then throw a "NotSupportedError" DOMException and abort these steps.
|
|
|
|
*/
|
2016-09-07 12:55:21 +03:00
|
|
|
const auto& ptr = mConstructors.lookup(constructorUnwrapped);
|
|
|
|
if (ptr) {
|
2017-09-25 09:46:00 +03:00
|
|
|
MOZ_ASSERT(mCustomDefinitions.GetWeak(ptr->value()),
|
2016-09-07 12:55:21 +03:00
|
|
|
"Definition must be found in mCustomDefinitions");
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2016-09-01 10:11:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 5. Let localName be name.
|
|
|
|
* 6. Let extends be the value of the extends member of options, or null if
|
|
|
|
* no such member exists.
|
|
|
|
* 7. If extends is not null, then:
|
|
|
|
* 1. If extends is a valid custom element name, then throw a
|
|
|
|
* "NotSupportedError" DOMException.
|
|
|
|
* 2. If the element interface for extends and the HTML namespace is
|
|
|
|
* HTMLUnknownElement (e.g., if extends does not indicate an element
|
|
|
|
* definition in this specification), then throw a "NotSupportedError"
|
|
|
|
* DOMException.
|
|
|
|
* 3. Set localName to extends.
|
|
|
|
*/
|
|
|
|
nsAutoString localName(aName);
|
|
|
|
if (aOptions.mExtends.WasPassed()) {
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> extendsAtom(NS_Atomize(aOptions.mExtends.Value()));
|
2016-09-01 10:11:32 +03:00
|
|
|
if (nsContentUtils::IsCustomElementName(extendsAtom)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// bgsound and multicol are unknown html element.
|
2017-09-05 13:19:06 +03:00
|
|
|
int32_t tag = nsHTMLTags::CaseSensitiveAtomTagToId(extendsAtom);
|
2016-09-01 10:11:32 +03:00
|
|
|
if (tag == eHTMLTag_userdefined ||
|
|
|
|
tag == eHTMLTag_bgsound ||
|
|
|
|
tag == eHTMLTag_multicol) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
localName.Assign(aOptions.mExtends.Value());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 8. If this CustomElementRegistry's element definition is running flag is set,
|
|
|
|
* then throw a "NotSupportedError" DOMException and abort these steps.
|
|
|
|
*/
|
|
|
|
if (mIsCustomDefinitionRunning) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> constructorPrototype(cx);
|
|
|
|
nsAutoPtr<LifecycleCallbacks> callbacksHolder(new LifecycleCallbacks());
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<RefPtr<nsAtom>> observedAttributes;
|
2016-09-01 10:11:32 +03:00
|
|
|
{ // Set mIsCustomDefinitionRunning.
|
|
|
|
/**
|
|
|
|
* 9. Set this CustomElementRegistry's element definition is running flag.
|
|
|
|
*/
|
|
|
|
AutoSetRunningFlag as(this);
|
|
|
|
|
|
|
|
{ // Enter constructor's compartment.
|
|
|
|
/**
|
|
|
|
* 10.1. Let prototype be Get(constructor, "prototype"). Rethrow any exceptions.
|
|
|
|
*/
|
|
|
|
JSAutoCompartment ac(cx, constructor);
|
|
|
|
JS::Rooted<JS::Value> prototypev(cx);
|
|
|
|
// The .prototype on the constructor passed from document.registerElement
|
|
|
|
// is the "expando" of a wrapper. So we should get it from wrapper instead
|
|
|
|
// instead of underlying object.
|
|
|
|
if (!JS_GetProperty(cx, constructor, "prototype", &prototypev)) {
|
|
|
|
aRv.StealExceptionFromJSContext(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 10.2. If Type(prototype) is not Object, then throw a TypeError exception.
|
|
|
|
*/
|
|
|
|
if (!prototypev.isObject()) {
|
|
|
|
aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("constructor.prototype"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructorPrototype = &prototypev.toObject();
|
|
|
|
} // Leave constructor's compartment.
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> constructorProtoUnwrapped(cx, js::CheckedUnwrap(constructorPrototype));
|
|
|
|
if (!constructorProtoUnwrapped) {
|
|
|
|
// If the caller's compartment does not have permission to access the
|
|
|
|
// unwrapped prototype then throw.
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // Enter constructorProtoUnwrapped's compartment
|
|
|
|
JSAutoCompartment ac(cx, constructorProtoUnwrapped);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 10.3. Let lifecycleCallbacks be a map with the four keys
|
|
|
|
* "connectedCallback", "disconnectedCallback", "adoptedCallback", and
|
|
|
|
* "attributeChangedCallback", each of which belongs to an entry whose
|
|
|
|
* value is null.
|
|
|
|
* 10.4. For each of the four keys callbackName in lifecycleCallbacks:
|
|
|
|
* 1. Let callbackValue be Get(prototype, callbackName). Rethrow any
|
|
|
|
* exceptions.
|
|
|
|
* 2. If callbackValue is not undefined, then set the value of the
|
|
|
|
* entry in lifecycleCallbacks with key callbackName to the result
|
|
|
|
* of converting callbackValue to the Web IDL Function callback type.
|
|
|
|
* Rethrow any exceptions from the conversion.
|
|
|
|
*/
|
|
|
|
// Will do the same checking for the life cycle callbacks from v0 spec.
|
|
|
|
CheckLifeCycleCallbacks(cx, constructorProtoUnwrapped, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:25:00 +03:00
|
|
|
// Note: We call the init from the constructorProtoUnwrapped's compartment
|
|
|
|
// here.
|
|
|
|
JS::RootedValue rootedv(cx, JS::ObjectValue(*constructorProtoUnwrapped));
|
|
|
|
if (!JS_WrapValue(cx, &rootedv) || !callbacksHolder->Init(cx, rootedv)) {
|
|
|
|
aRv.StealExceptionFromJSContext(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-01 10:11:32 +03:00
|
|
|
/**
|
|
|
|
* 10.5. Let observedAttributes be an empty sequence<DOMString>.
|
|
|
|
* 10.6. If the value of the entry in lifecycleCallbacks with key
|
|
|
|
* "attributeChangedCallback" is not null, then:
|
|
|
|
* 1. Let observedAttributesIterable be Get(constructor,
|
|
|
|
* "observedAttributes"). Rethrow any exceptions.
|
|
|
|
* 2. If observedAttributesIterable is not undefined, then set
|
|
|
|
* observedAttributes to the result of converting
|
|
|
|
* observedAttributesIterable to a sequence<DOMString>. Rethrow
|
|
|
|
* any exceptions from the conversion.
|
|
|
|
*/
|
2017-08-28 06:25:00 +03:00
|
|
|
if (callbacksHolder->mAttributeChangedCallback.WasPassed()) {
|
|
|
|
// Enter constructor's compartment.
|
|
|
|
JSAutoCompartment ac(cx, constructor);
|
|
|
|
JS::Rooted<JS::Value> observedAttributesIterable(cx);
|
|
|
|
|
|
|
|
if (!JS_GetProperty(cx, constructor, "observedAttributes",
|
|
|
|
&observedAttributesIterable)) {
|
|
|
|
aRv.StealExceptionFromJSContext(cx);
|
|
|
|
return;
|
|
|
|
}
|
2016-09-01 10:11:32 +03:00
|
|
|
|
2017-08-28 06:25:00 +03:00
|
|
|
if (!observedAttributesIterable.isUndefined()) {
|
2017-11-03 05:50:05 +03:00
|
|
|
if (!observedAttributesIterable.isObject()) {
|
|
|
|
aRv.ThrowTypeError<MSG_NOT_SEQUENCE>(NS_LITERAL_STRING("observedAttributes"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:25:00 +03:00
|
|
|
JS::ForOfIterator iter(cx);
|
2017-11-03 05:50:05 +03:00
|
|
|
if (!iter.init(observedAttributesIterable, JS::ForOfIterator::AllowNonIterable)) {
|
2017-08-28 06:25:00 +03:00
|
|
|
aRv.StealExceptionFromJSContext(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-03 05:50:05 +03:00
|
|
|
if (!iter.valueIsIterable()) {
|
|
|
|
aRv.ThrowTypeError<MSG_NOT_SEQUENCE>(NS_LITERAL_STRING("observedAttributes"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:25:00 +03:00
|
|
|
JS::Rooted<JS::Value> attribute(cx);
|
|
|
|
while (true) {
|
|
|
|
bool done;
|
|
|
|
if (!iter.next(&attribute, &done)) {
|
|
|
|
aRv.StealExceptionFromJSContext(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-03 05:50:05 +03:00
|
|
|
nsAutoString attrStr;
|
|
|
|
if (!ConvertJSValueToString(cx, attribute, eStringify, eStringify, attrStr)) {
|
2017-08-28 06:25:00 +03:00
|
|
|
aRv.StealExceptionFromJSContext(cx);
|
|
|
|
return;
|
|
|
|
}
|
2017-11-03 05:50:05 +03:00
|
|
|
|
|
|
|
if (!observedAttributes.AppendElement(NS_Atomize(attrStr))) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
2017-08-28 06:25:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // Leave constructor's compartment.
|
2016-09-01 10:11:32 +03:00
|
|
|
} // Leave constructorProtoUnwrapped's compartment.
|
|
|
|
} // Unset mIsCustomDefinitionRunning
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 11. Let definition be a new custom element definition with name name,
|
|
|
|
* local name localName, constructor constructor, prototype prototype,
|
|
|
|
* observed attributes observedAttributes, and lifecycle callbacks
|
|
|
|
* lifecycleCallbacks.
|
|
|
|
*/
|
|
|
|
// Associate the definition with the custom element.
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> localNameAtom(NS_Atomize(localName));
|
2016-09-01 10:11:32 +03:00
|
|
|
LifecycleCallbacks* callbacks = callbacksHolder.forget();
|
|
|
|
|
|
|
|
/**
|
2016-10-12 10:26:02 +03:00
|
|
|
* 12. Add definition to this CustomElementRegistry.
|
2016-09-01 10:11:32 +03:00
|
|
|
*/
|
2016-09-07 12:55:21 +03:00
|
|
|
if (!mConstructors.put(constructorUnwrapped, nameAtom)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:46:00 +03:00
|
|
|
RefPtr<CustomElementDefinition> definition =
|
2017-01-19 15:31:33 +03:00
|
|
|
new CustomElementDefinition(nameAtom,
|
|
|
|
localNameAtom,
|
2017-08-13 11:40:37 +03:00
|
|
|
&aFunctionConstructor,
|
2017-08-28 06:25:00 +03:00
|
|
|
Move(observedAttributes),
|
2017-01-19 15:31:33 +03:00
|
|
|
constructorPrototype,
|
|
|
|
callbacks,
|
|
|
|
0 /* TODO dependent on HTML imports. Bug 877072 */);
|
|
|
|
|
2017-09-25 09:46:00 +03:00
|
|
|
CustomElementDefinition* def = definition.get();
|
|
|
|
mCustomDefinitions.Put(nameAtom, definition.forget());
|
2016-09-01 10:11:32 +03:00
|
|
|
|
2016-09-07 12:55:21 +03:00
|
|
|
MOZ_ASSERT(mCustomDefinitions.Count() == mConstructors.count(),
|
|
|
|
"Number of entries should be the same");
|
|
|
|
|
2016-09-01 10:11:32 +03:00
|
|
|
/**
|
|
|
|
* 13. 14. 15. Upgrade candidates
|
|
|
|
*/
|
2017-09-25 09:46:00 +03:00
|
|
|
UpgradeCandidates(nameAtom, def, aRv);
|
2016-09-01 10:11:32 +03:00
|
|
|
|
|
|
|
/**
|
2016-10-12 10:26:02 +03:00
|
|
|
* 16. If this CustomElementRegistry's when-defined promise map contains an
|
2016-09-01 10:11:32 +03:00
|
|
|
* entry with key name:
|
|
|
|
* 1. Let promise be the value of that entry.
|
|
|
|
* 2. Resolve promise with undefined.
|
2016-10-12 10:26:02 +03:00
|
|
|
* 3. Delete the entry with key name from this CustomElementRegistry's
|
2016-09-01 10:11:32 +03:00
|
|
|
* when-defined promise map.
|
|
|
|
*/
|
2016-10-07 09:16:00 +03:00
|
|
|
RefPtr<Promise> promise;
|
|
|
|
mWhenDefinedPromiseMap.Remove(nameAtom, getter_AddRefs(promise));
|
|
|
|
if (promise) {
|
|
|
|
promise->MaybeResolveWithUndefined();
|
|
|
|
}
|
|
|
|
|
2016-07-25 00:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-12 10:26:02 +03:00
|
|
|
CustomElementRegistry::Get(JSContext* aCx, const nsAString& aName,
|
|
|
|
JS::MutableHandle<JS::Value> aRetVal)
|
2016-07-25 00:38:00 +03:00
|
|
|
{
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> nameAtom(NS_Atomize(aName));
|
2017-09-25 09:46:00 +03:00
|
|
|
CustomElementDefinition* data = mCustomDefinitions.GetWeak(nameAtom);
|
2016-09-22 02:40:00 +03:00
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
aRetVal.setUndefined();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-05 03:21:06 +03:00
|
|
|
aRetVal.setObject(*data->mConstructor->Callback(aCx));
|
2016-07-25 00:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2016-10-12 10:26:02 +03:00
|
|
|
CustomElementRegistry::WhenDefined(const nsAString& aName, ErrorResult& aRv)
|
2016-07-25 00:38:00 +03:00
|
|
|
{
|
2016-10-07 09:16:00 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
|
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
|
|
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> nameAtom(NS_Atomize(aName));
|
2016-10-07 09:16:00 +03:00
|
|
|
if (!nsContentUtils::IsCustomElementName(nameAtom)) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:46:00 +03:00
|
|
|
if (mCustomDefinitions.GetWeak(nameAtom)) {
|
2016-10-07 09:16:00 +03:00
|
|
|
promise->MaybeResolve(JS::UndefinedHandleValue);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2017-06-14 17:11:21 +03:00
|
|
|
auto entry = mWhenDefinedPromiseMap.LookupForAdd(nameAtom);
|
|
|
|
if (entry) {
|
|
|
|
promise = entry.Data();
|
2016-10-07 09:16:00 +03:00
|
|
|
} else {
|
2017-06-14 17:11:21 +03:00
|
|
|
entry.OrInsert([&promise](){ return promise; });
|
2016-10-07 09:16:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return promise.forget();
|
2016-07-25 00:38:00 +03:00
|
|
|
}
|
|
|
|
|
2017-08-13 11:40:37 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
static void
|
|
|
|
DoUpgrade(Element* aElement,
|
|
|
|
CustomElementConstructor* aConstructor,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Rethrow the exception since it might actually throw the exception from the
|
|
|
|
// upgrade steps back out to the caller of document.createElement.
|
|
|
|
RefPtr<Element> constructResult =
|
|
|
|
aConstructor->Construct("Custom Element Upgrade", aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-12 11:25:00 +03:00
|
|
|
if (!constructResult || constructResult.get() != aElement) {
|
2017-08-13 11:40:37 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/scripting.html#upgrades
|
2017-09-25 08:33:00 +03:00
|
|
|
/* static */ void
|
2017-01-06 02:38:00 +03:00
|
|
|
CustomElementRegistry::Upgrade(Element* aElement,
|
2017-08-13 11:40:37 +03:00
|
|
|
CustomElementDefinition* aDefinition,
|
|
|
|
ErrorResult& aRv)
|
2017-01-06 02:38:00 +03:00
|
|
|
{
|
|
|
|
aElement->RemoveStates(NS_EVENT_STATE_UNRESOLVED);
|
|
|
|
|
2017-08-13 11:40:37 +03:00
|
|
|
RefPtr<CustomElementData> data = aElement->GetCustomElementData();
|
|
|
|
MOZ_ASSERT(data, "CustomElementData should exist");
|
|
|
|
|
|
|
|
// Step 1 and step 2.
|
|
|
|
if (data->mState == CustomElementData::State::eCustom ||
|
|
|
|
data->mState == CustomElementData::State::eFailed) {
|
2017-01-06 02:38:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:25:00 +03:00
|
|
|
// Step 3.
|
|
|
|
if (!aDefinition->mObservedAttributes.IsEmpty()) {
|
|
|
|
uint32_t count = aElement->GetAttrCount();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
mozilla::dom::BorrowedAttrInfo info = aElement->GetAttrInfoAt(i);
|
|
|
|
|
|
|
|
const nsAttrName* name = info.mName;
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* attrName = name->LocalName();
|
2017-08-28 06:25:00 +03:00
|
|
|
|
|
|
|
if (aDefinition->IsInObservedAttributeList(attrName)) {
|
|
|
|
int32_t namespaceID = name->NamespaceID();
|
|
|
|
nsAutoString attrValue, namespaceURI;
|
|
|
|
info.mValue->ToString(attrValue);
|
|
|
|
nsContentUtils::NameSpaceManager()->GetNameSpaceURI(namespaceID,
|
|
|
|
namespaceURI);
|
|
|
|
|
|
|
|
LifecycleCallbackArgs args = {
|
|
|
|
nsDependentAtomString(attrName),
|
2017-09-22 07:35:46 +03:00
|
|
|
VoidString(),
|
|
|
|
(attrValue.IsEmpty() ? VoidString() : attrValue),
|
|
|
|
(namespaceURI.IsEmpty() ? VoidString() : namespaceURI)
|
2017-08-28 06:25:00 +03:00
|
|
|
};
|
2017-09-26 08:56:00 +03:00
|
|
|
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAttributeChanged,
|
2017-09-25 08:33:00 +03:00
|
|
|
aElement,
|
2017-10-02 07:42:00 +03:00
|
|
|
&args, nullptr, aDefinition);
|
2017-08-28 06:25:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 4.
|
2017-09-26 08:55:58 +03:00
|
|
|
if (aElement->IsInComposedDoc()) {
|
2017-09-26 08:56:00 +03:00
|
|
|
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, aElement,
|
2017-10-02 07:42:00 +03:00
|
|
|
nullptr, nullptr, aDefinition);
|
2017-09-26 08:55:58 +03:00
|
|
|
}
|
2017-01-06 02:38:00 +03:00
|
|
|
|
2017-08-13 11:40:37 +03:00
|
|
|
// Step 5.
|
|
|
|
AutoConstructionStackEntry acs(aDefinition->mConstructionStack,
|
|
|
|
nsGenericHTMLElement::FromContent(aElement));
|
|
|
|
|
|
|
|
// Step 6 and step 7.
|
|
|
|
DoUpgrade(aElement, aDefinition->mConstructor, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
data->mState = CustomElementData::State::eFailed;
|
|
|
|
// Empty element's custom element reaction queue.
|
|
|
|
data->mReactionQueue.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 8.
|
|
|
|
data->mState = CustomElementData::State::eCustom;
|
|
|
|
|
2017-09-25 09:46:00 +03:00
|
|
|
// Step 9.
|
|
|
|
aElement->SetCustomElementDefinition(aDefinition);
|
2017-01-06 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
2017-03-21 07:42:00 +03:00
|
|
|
//-----------------------------------------------------
|
|
|
|
// CustomElementReactionsStack
|
2017-01-06 02:38:00 +03:00
|
|
|
|
|
|
|
void
|
2017-03-21 07:42:00 +03:00
|
|
|
CustomElementReactionsStack::CreateAndPushElementQueue()
|
2017-01-06 02:38:00 +03:00
|
|
|
{
|
|
|
|
// Push a new element queue onto the custom element reactions stack.
|
2017-01-09 17:12:57 +03:00
|
|
|
mReactionsStack.AppendElement(MakeUnique<ElementQueue>());
|
2017-01-06 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-21 07:42:00 +03:00
|
|
|
CustomElementReactionsStack::PopAndInvokeElementQueue()
|
2017-01-06 02:38:00 +03:00
|
|
|
{
|
|
|
|
// Pop the element queue from the custom element reactions stack,
|
|
|
|
// and invoke custom element reactions in that queue.
|
|
|
|
MOZ_ASSERT(!mReactionsStack.IsEmpty(),
|
|
|
|
"Reaction stack shouldn't be empty");
|
|
|
|
|
2017-01-09 17:12:57 +03:00
|
|
|
const uint32_t lastIndex = mReactionsStack.Length() - 1;
|
|
|
|
ElementQueue* elementQueue = mReactionsStack.ElementAt(lastIndex).get();
|
2017-03-30 12:35:59 +03:00
|
|
|
// Check element queue size in order to reduce function call overhead.
|
2017-01-09 17:12:57 +03:00
|
|
|
if (!elementQueue->IsEmpty()) {
|
2017-08-13 11:40:37 +03:00
|
|
|
// It is still not clear what error reporting will look like in custom
|
|
|
|
// element, see https://github.com/w3c/webcomponents/issues/635.
|
|
|
|
// We usually report the error to entry global in gecko, so just follow the
|
|
|
|
// same behavior here.
|
2017-10-26 09:55:41 +03:00
|
|
|
// This may be null if it's called from parser, see the case of
|
|
|
|
// attributeChangedCallback in
|
|
|
|
// https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token
|
|
|
|
// In that case, the exception of callback reactions will be automatically
|
|
|
|
// reported in CallSetup.
|
2017-08-13 11:40:37 +03:00
|
|
|
nsIGlobalObject* global = GetEntryGlobal();
|
|
|
|
InvokeReactions(elementQueue, global);
|
2017-03-30 12:35:59 +03:00
|
|
|
}
|
|
|
|
|
2017-01-09 17:12:57 +03:00
|
|
|
// InvokeReactions() might create other custom element reactions, but those
|
|
|
|
// new reactions should be already consumed and removed at this point.
|
|
|
|
MOZ_ASSERT(lastIndex == mReactionsStack.Length() - 1,
|
|
|
|
"reactions created by InvokeReactions() should be consumed and removed");
|
|
|
|
|
|
|
|
mReactionsStack.RemoveElementAt(lastIndex);
|
2017-01-06 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-09-26 08:56:00 +03:00
|
|
|
CustomElementReactionsStack::EnqueueUpgradeReaction(Element* aElement,
|
2017-03-21 07:42:00 +03:00
|
|
|
CustomElementDefinition* aDefinition)
|
|
|
|
{
|
2017-09-26 08:56:00 +03:00
|
|
|
Enqueue(aElement, new CustomElementUpgradeReaction(aDefinition));
|
2017-03-21 07:42:00 +03:00
|
|
|
}
|
|
|
|
|
2017-07-19 03:30:00 +03:00
|
|
|
void
|
2017-09-26 08:56:00 +03:00
|
|
|
CustomElementReactionsStack::EnqueueCallbackReaction(Element* aElement,
|
2017-07-19 03:30:00 +03:00
|
|
|
UniquePtr<CustomElementCallback> aCustomElementCallback)
|
|
|
|
{
|
2017-10-12 12:01:41 +03:00
|
|
|
Enqueue(aElement, new CustomElementCallbackReaction(Move(aCustomElementCallback)));
|
2017-07-19 03:30:00 +03:00
|
|
|
}
|
|
|
|
|
2017-03-21 07:42:00 +03:00
|
|
|
void
|
|
|
|
CustomElementReactionsStack::Enqueue(Element* aElement,
|
|
|
|
CustomElementReaction* aReaction)
|
2017-01-06 02:38:00 +03:00
|
|
|
{
|
2017-03-21 12:02:21 +03:00
|
|
|
RefPtr<CustomElementData> elementData = aElement->GetCustomElementData();
|
|
|
|
MOZ_ASSERT(elementData, "CustomElementData should exist");
|
|
|
|
|
2017-01-06 02:38:00 +03:00
|
|
|
// Add element to the current element queue.
|
|
|
|
if (!mReactionsStack.IsEmpty()) {
|
2017-09-26 08:56:11 +03:00
|
|
|
mReactionsStack.LastElement()->AppendElement(aElement);
|
2017-03-21 12:02:21 +03:00
|
|
|
elementData->mReactionQueue.AppendElement(aReaction);
|
2017-01-06 02:38:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the custom element reactions stack is empty, then:
|
|
|
|
// Add element to the backup element queue.
|
2017-10-17 12:55:08 +03:00
|
|
|
MOZ_ASSERT(!aReaction->IsUpgradeReaction(),
|
|
|
|
"Upgrade reaction should not be scheduled to backup queue");
|
2017-09-26 08:56:11 +03:00
|
|
|
mBackupQueue.AppendElement(aElement);
|
2017-03-21 12:02:21 +03:00
|
|
|
elementData->mReactionQueue.AppendElement(aReaction);
|
2017-01-06 02:38:00 +03:00
|
|
|
|
|
|
|
if (mIsBackupQueueProcessing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
|
|
|
|
RefPtr<ProcessBackupQueueRunnable> processBackupQueueRunnable =
|
|
|
|
new ProcessBackupQueueRunnable(this);
|
|
|
|
context->DispatchToMicroTask(processBackupQueueRunnable.forget());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-21 07:42:00 +03:00
|
|
|
CustomElementReactionsStack::InvokeBackupQueue()
|
2017-01-06 02:38:00 +03:00
|
|
|
{
|
2017-03-30 12:35:59 +03:00
|
|
|
// Check backup queue size in order to reduce function call overhead.
|
|
|
|
if (!mBackupQueue.IsEmpty()) {
|
2017-08-13 11:40:37 +03:00
|
|
|
// Upgrade reactions won't be scheduled in backup queue and the exception of
|
|
|
|
// callback reactions will be automatically reported in CallSetup.
|
|
|
|
// If the reactions are invoked from backup queue (in microtask check point),
|
|
|
|
// we don't need to pass global object for error reporting.
|
|
|
|
InvokeReactions(&mBackupQueue, nullptr);
|
2017-03-30 12:35:59 +03:00
|
|
|
}
|
2017-01-06 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-13 11:40:37 +03:00
|
|
|
CustomElementReactionsStack::InvokeReactions(ElementQueue* aElementQueue,
|
|
|
|
nsIGlobalObject* aGlobal)
|
2017-01-06 02:38:00 +03:00
|
|
|
{
|
2017-08-13 11:40:37 +03:00
|
|
|
// This is used for error reporting.
|
|
|
|
Maybe<AutoEntryScript> aes;
|
|
|
|
if (aGlobal) {
|
|
|
|
aes.emplace(aGlobal, "custom elements reaction invocation");
|
|
|
|
}
|
|
|
|
|
2017-07-10 08:40:00 +03:00
|
|
|
// Note: It's possible to re-enter this method.
|
2017-01-09 17:12:57 +03:00
|
|
|
for (uint32_t i = 0; i < aElementQueue->Length(); ++i) {
|
2017-09-26 08:56:11 +03:00
|
|
|
Element* element = aElementQueue->ElementAt(i);
|
2017-01-06 02:38:00 +03:00
|
|
|
|
|
|
|
if (!element) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-21 12:02:21 +03:00
|
|
|
RefPtr<CustomElementData> elementData = element->GetCustomElementData();
|
2017-09-26 08:56:11 +03:00
|
|
|
if (!elementData) {
|
|
|
|
// This happens when the document is destroyed and the element is already
|
|
|
|
// unlinked, no need to fire the callbacks in this case.
|
|
|
|
return;
|
|
|
|
}
|
2017-01-06 02:38:00 +03:00
|
|
|
|
2017-07-10 08:40:00 +03:00
|
|
|
auto& reactions = elementData->mReactionQueue;
|
2017-03-21 12:02:21 +03:00
|
|
|
for (uint32_t j = 0; j < reactions.Length(); ++j) {
|
2017-07-10 08:40:00 +03:00
|
|
|
// Transfer the ownership of the entry due to reentrant invocation of
|
|
|
|
// this funciton. The entry will be removed when bug 1379573 is landed.
|
|
|
|
auto reaction(Move(reactions.ElementAt(j)));
|
|
|
|
if (reaction) {
|
2017-08-13 11:40:37 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
reaction->Invoke(element, rv);
|
|
|
|
if (aes) {
|
|
|
|
JSContext* cx = aes->cx();
|
|
|
|
if (rv.MaybeSetPendingException(cx)) {
|
|
|
|
aes->ReportException();
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(!JS_IsExceptionPending(cx));
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
2017-07-10 08:40:00 +03:00
|
|
|
}
|
2017-01-06 02:38:00 +03:00
|
|
|
}
|
2017-03-21 12:02:21 +03:00
|
|
|
reactions.Clear();
|
2017-01-06 02:38:00 +03:00
|
|
|
}
|
2017-01-09 17:12:57 +03:00
|
|
|
aElementQueue->Clear();
|
2017-01-06 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
// CustomElementDefinition
|
|
|
|
|
2017-09-25 09:46:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CustomElementDefinition)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CustomElementDefinition)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mConstructor)
|
|
|
|
tmp->mPrototype = nullptr;
|
|
|
|
tmp->mCallbacks = nullptr;
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CustomElementDefinition)
|
|
|
|
mozilla::dom::LifecycleCallbacks* callbacks = tmp->mCallbacks.get();
|
|
|
|
|
|
|
|
if (callbacks->mAttributeChangedCallback.WasPassed()) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
|
|
|
|
"mCallbacks->mAttributeChangedCallback");
|
|
|
|
cb.NoteXPCOMChild(callbacks->mAttributeChangedCallback.Value());
|
|
|
|
}
|
|
|
|
|
2017-09-26 08:55:58 +03:00
|
|
|
if (callbacks->mConnectedCallback.WasPassed()) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mConnectedCallback");
|
|
|
|
cb.NoteXPCOMChild(callbacks->mConnectedCallback.Value());
|
2017-09-25 09:46:00 +03:00
|
|
|
}
|
|
|
|
|
2017-09-26 08:56:11 +03:00
|
|
|
if (callbacks->mDisconnectedCallback.WasPassed()) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mDisconnectedCallback");
|
|
|
|
cb.NoteXPCOMChild(callbacks->mDisconnectedCallback.Value());
|
2017-09-25 09:46:00 +03:00
|
|
|
}
|
|
|
|
|
2017-10-02 07:42:00 +03:00
|
|
|
if (callbacks->mAdoptedCallback.WasPassed()) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mAdoptedCallback");
|
|
|
|
cb.NoteXPCOMChild(callbacks->mAdoptedCallback.Value());
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:46:00 +03:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mConstructor");
|
|
|
|
cb.NoteXPCOMChild(tmp->mConstructor);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(CustomElementDefinition)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mPrototype)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(CustomElementDefinition, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(CustomElementDefinition, Release)
|
|
|
|
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
CustomElementDefinition::CustomElementDefinition(nsAtom* aType,
|
|
|
|
nsAtom* aLocalName,
|
2017-08-13 11:40:37 +03:00
|
|
|
Function* aConstructor,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<RefPtr<nsAtom>>&& aObservedAttributes,
|
2017-10-09 20:59:02 +03:00
|
|
|
JS::Handle<JSObject*> aPrototype,
|
2016-07-22 00:42:00 +03:00
|
|
|
LifecycleCallbacks* aCallbacks,
|
|
|
|
uint32_t aDocOrder)
|
2016-09-01 10:11:32 +03:00
|
|
|
: mType(aType),
|
2016-07-22 00:42:00 +03:00
|
|
|
mLocalName(aLocalName),
|
2017-08-13 11:40:37 +03:00
|
|
|
mConstructor(new CustomElementConstructor(aConstructor)),
|
2017-08-28 06:25:00 +03:00
|
|
|
mObservedAttributes(Move(aObservedAttributes)),
|
2016-09-01 10:11:32 +03:00
|
|
|
mPrototype(aPrototype),
|
2016-07-22 00:42:00 +03:00
|
|
|
mCallbacks(aCallbacks),
|
|
|
|
mDocOrder(aDocOrder)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-06 02:38:00 +03:00
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
// CustomElementUpgradeReaction
|
|
|
|
|
|
|
|
/* virtual */ void
|
2017-08-13 11:40:37 +03:00
|
|
|
CustomElementUpgradeReaction::Invoke(Element* aElement, ErrorResult& aRv)
|
2017-01-06 02:38:00 +03:00
|
|
|
{
|
2017-09-26 08:56:00 +03:00
|
|
|
CustomElementRegistry::Upgrade(aElement, mDefinition, aRv);
|
2017-01-06 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
2017-07-19 03:30:00 +03:00
|
|
|
//-----------------------------------------------------
|
|
|
|
// CustomElementCallbackReaction
|
|
|
|
|
|
|
|
/* virtual */ void
|
2017-08-13 11:40:37 +03:00
|
|
|
CustomElementCallbackReaction::Invoke(Element* aElement, ErrorResult& aRv)
|
2017-07-19 03:30:00 +03:00
|
|
|
{
|
|
|
|
mCustomElementCallback->Call();
|
|
|
|
}
|
|
|
|
|
2016-07-25 00:38:00 +03:00
|
|
|
} // namespace dom
|
2016-09-07 12:55:21 +03:00
|
|
|
} // namespace mozilla
|