summaryrefslogtreecommitdiffstats
path: root/dom/base/CustomElementRegistry.h
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2020-01-04 23:29:10 -0500
committerGaming4JC <g4jc@hyperbola.info>2020-01-26 15:50:22 -0500
commit53c9b77ed41aebb157012eff5e57cad3a962d18e (patch)
tree774cec41db2f86d1621497b7df20899bc9255622 /dom/base/CustomElementRegistry.h
parente6733c9278d0e9687be83de5b5f409a43653fbee (diff)
downloadUXP-53c9b77ed41aebb157012eff5e57cad3a962d18e.tar
UXP-53c9b77ed41aebb157012eff5e57cad3a962d18e.tar.gz
UXP-53c9b77ed41aebb157012eff5e57cad3a962d18e.tar.lz
UXP-53c9b77ed41aebb157012eff5e57cad3a962d18e.tar.xz
UXP-53c9b77ed41aebb157012eff5e57cad3a962d18e.zip
Bug 1315885 - Part 4: Implement callback reaction for custom element reactions.
Note: Skipped SyncInvokeReactions since it is removed in CE v1, waste of time. Tag UXP Issue #1344
Diffstat (limited to 'dom/base/CustomElementRegistry.h')
-rw-r--r--dom/base/CustomElementRegistry.h67
1 files changed, 40 insertions, 27 deletions
diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h
index cb7bd67a5..33f2a95ff 100644
--- a/dom/base/CustomElementRegistry.h
+++ b/dom/base/CustomElementRegistry.h
@@ -84,23 +84,14 @@ struct CustomElementData
explicit CustomElementData(nsIAtom* aType);
CustomElementData(nsIAtom* aType, State aState);
- // Objects in this array are transient and empty after each microtask
- // checkpoint.
- nsTArray<nsAutoPtr<CustomElementCallback>> mCallbackQueue;
// Custom element type, for <button is="x-button"> or <x-button>
// this would be x-button.
nsCOMPtr<nsIAtom> mType;
- // The callback that is next to be processed upon calling RunCallbackQueue.
- int32_t mCurrentCallback;
// Element is being created flag as described in the custom elements spec.
bool mElementIsBeingCreated;
// Flag to determine if the created callback has been invoked, thus it
// determines if other callbacks can be enqueued.
bool mCreatedCallbackInvoked;
- // The microtask level associated with the callbacks in the callback queue,
- // it is used to determine if a new queue needs to be pushed onto the
- // processing stack.
- int32_t mAssociatedMicroTask;
// Custom element state as described in the custom element spec.
State mState;
// custom element reaction queue as described in the custom element spec.
@@ -109,10 +100,7 @@ struct CustomElementData
// appended, removed, or replaced.
// There are 3 reactions in reaction queue when doing upgrade operation,
// e.g., create an element, insert a node.
- AutoTArray<nsAutoPtr<CustomElementReaction>, 3> mReactionQueue;
-
- // Empties the callback queue.
- void RunCallbackQueue();
+ AutoTArray<UniquePtr<CustomElementReaction>, 3> mReactionQueue;
private:
virtual ~CustomElementData() {}
@@ -142,7 +130,7 @@ struct CustomElementDefinition
JS::Heap<JSObject *> mPrototype;
// The lifecycle callbacks to call for this custom element.
- nsAutoPtr<mozilla::dom::LifecycleCallbacks> mCallbacks;
+ UniquePtr<mozilla::dom::LifecycleCallbacks> mCallbacks;
// A construction stack.
// TODO: Bug 1287348 - Implement construction stack for upgrading an element
@@ -163,10 +151,13 @@ public:
: mRegistry(aRegistry)
, mDefinition(aDefinition)
{
- };
+ }
virtual ~CustomElementReaction() = default;
virtual void Invoke(Element* aElement) = 0;
+ virtual void Traverse(nsCycleCollectionTraversalCallback& aCb) const
+ {
+ }
protected:
CustomElementRegistry* mRegistry;
@@ -186,6 +177,27 @@ private:
virtual void Invoke(Element* aElement) override;
};
+class CustomElementCallbackReaction final : public CustomElementReaction
+{
+ public:
+ CustomElementCallbackReaction(CustomElementRegistry* aRegistry,
+ CustomElementDefinition* aDefinition,
+ UniquePtr<CustomElementCallback> aCustomElementCallback)
+ : CustomElementReaction(aRegistry, aDefinition)
+ , mCustomElementCallback(Move(aCustomElementCallback))
+ {
+ }
+
+ virtual void Traverse(nsCycleCollectionTraversalCallback& aCb) const override
+ {
+ mCustomElementCallback->Traverse(aCb);
+ }
+
+ private:
+ virtual void Invoke(Element* aElement) override;
+ UniquePtr<CustomElementCallback> mCustomElementCallback;
+};
+
// https://html.spec.whatwg.org/multipage/scripting.html#custom-element-reactions-stack
class CustomElementReactionsStack
{
@@ -211,6 +223,15 @@ public:
Element* aElement,
CustomElementDefinition* aDefinition);
+ /**
+ * Enqueue a custom element callback reaction
+ * https://html.spec.whatwg.org/multipage/scripting.html#enqueue-a-custom-element-callback-reaction
+ */
+ void EnqueueCallbackReaction(CustomElementRegistry* aRegistry,
+ Element* aElement,
+ CustomElementDefinition* aDefinition,
+ UniquePtr<CustomElementCallback> aCustomElementCallback);
+
// [CEReactions] Before executing the algorithm's steps
// Push a new element queue onto the custom element reactions stack.
void CreateAndPushElementQueue();
@@ -276,10 +297,6 @@ public:
static bool IsCustomElementEnabled(JSContext* aCx = nullptr,
JSObject* aObject = nullptr);
- static void ProcessTopElementQueue();
-
- static void XPCOMShutdown();
-
explicit CustomElementRegistry(nsPIDOMWindowInner* aWindow);
/**
@@ -312,6 +329,10 @@ public:
private:
~CustomElementRegistry();
+ UniquePtr<CustomElementCallback> CreateCustomElementCallback(
+ nsIDocument::ElementCallbackType aType, Element* aCustomElement,
+ LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition);
+
/**
* Registers an unresolved custom element that is a candidate for
* upgrade when the definition is registered via registerElement.
@@ -358,14 +379,6 @@ private:
nsCOMPtr<nsPIDOMWindowInner> mWindow;
- // Array representing the processing stack in the custom elements
- // specification. The processing stack is conceptually a stack of
- // element queues. Each queue is represented by a sequence of
- // CustomElementData in this array, separated by nullptr that
- // represent the boundaries of the items in the stack. The first
- // queue in the stack is the base element queue.
- static mozilla::Maybe<nsTArray<RefPtr<CustomElementData>>> sProcessingStack;
-
// It is used to prevent reentrant invocations of element definition.
bool mIsCustomDefinitionRunning;