From f576d8f0fe2a2203e6ad5fdd1a319b8991322756 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Mon, 20 Jan 2020 19:49:20 -0500 Subject: Bug 1396620 - Part 1: Remove created callback for custom elements Tag UXP Issue #1344 --- dom/base/CustomElementRegistry.cpp | 77 ++-------------------- dom/base/CustomElementRegistry.h | 11 +--- dom/base/nsIDocument.h | 1 - dom/base/test/chrome/registerElement_ep.js | 4 +- .../test/chrome/test_registerElement_content.xul | 23 +++---- dom/base/test/chrome/test_registerElement_ep.xul | 4 +- dom/tests/mochitest/webcomponents/mochitest.ini | 3 - .../test_custom_element_adopt_callbacks.html | 29 -------- ...st_custom_element_clone_callbacks_extended.html | 40 ----------- ...ustom_element_import_node_created_callback.html | 34 ---------- ..._custom_element_register_invalid_callbacks.html | 1 - .../test_document_shared_registry.html | 33 ---------- dom/webidl/WebComponents.webidl | 2 - 13 files changed, 22 insertions(+), 240 deletions(-) delete mode 100644 dom/tests/mochitest/webcomponents/test_custom_element_adopt_callbacks.html delete mode 100644 dom/tests/mochitest/webcomponents/test_custom_element_clone_callbacks_extended.html delete mode 100644 dom/tests/mochitest/webcomponents/test_custom_element_import_node_created_callback.html diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index 3d5432b07..2d7907bd7 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -21,39 +21,6 @@ CustomElementCallback::Call() { IgnoredErrorResult rv; switch (mType) { - case nsIDocument::eCreated: - { - // For the duration of this callback invocation, the element is being created - // flag must be set to true. - mOwnerData->mElementIsBeingCreated = true; - - // The callback hasn't actually been invoked yet, but we need to flip - // this now in order to enqueue the connected callback. This is a spec - // bug (w3c bug 27437). - mOwnerData->mCreatedCallbackInvoked = true; - - // If ELEMENT is connected, enqueue connected callback for ELEMENT. - nsIDocument* document = mThisObject->GetComposedDoc(); - if (document) { - NodeInfo* ni = mThisObject->NodeInfo(); - - // We need to do this because at this point, CustomElementDefinition is - // not set to CustomElementData yet, so EnqueueLifecycleCallback will - // fail to find the CE definition for this custom element. - // This will go away eventually since there is no created callback in v1. - CustomElementDefinition* definition = - nsContentUtils::LookupCustomElementDefinition(document, - ni->LocalName(), ni->NamespaceID(), - mOwnerData->GetCustomElementType()); - - nsContentUtils::EnqueueLifecycleCallback( - nsIDocument::eConnected, mThisObject, nullptr, nullptr, definition); - } - - static_cast(mCallback.get())->Call(mThisObject, rv); - mOwnerData->mElementIsBeingCreated = false; - break; - } case nsIDocument::eConnected: static_cast(mCallback.get())->Call(mThisObject, rv); break; @@ -83,12 +50,10 @@ CustomElementCallback::Traverse(nsCycleCollectionTraversalCallback& aCb) const CustomElementCallback::CustomElementCallback(Element* aThisObject, nsIDocument::ElementCallbackType aCallbackType, - mozilla::dom::CallbackFunction* aCallback, - CustomElementData* aOwnerData) + mozilla::dom::CallbackFunction* aCallback) : mThisObject(aThisObject), mCallback(aCallback), - mType(aCallbackType), - mOwnerData(aOwnerData) + mType(aCallbackType) { } @@ -131,9 +96,7 @@ CustomElementData::CustomElementData(nsIAtom* aType) } CustomElementData::CustomElementData(nsIAtom* aType, State aState) - : mElementIsBeingCreated(false) - , mCreatedCallbackInvoked(true) - , mState(aState) + : mState(aState) , mType(aType) { } @@ -359,18 +322,12 @@ CustomElementRegistry::CreateCustomElementCallback( { MOZ_ASSERT(aDefinition, "CustomElementDefinition should not be null"); - RefPtr elementData = aCustomElement->GetCustomElementData(); - MOZ_ASSERT(elementData, "CustomElementData should exist"); + MOZ_ASSERT(aCustomElement->GetCustomElementData(), + "CustomElementData should exist"); // Let CALLBACK be the callback associated with the key NAME in CALLBACKS. CallbackFunction* func = nullptr; switch (aType) { - case nsIDocument::eCreated: - if (aDefinition->mCallbacks->mCreatedCallback.WasPassed()) { - func = aDefinition->mCallbacks->mCreatedCallback.Value(); - } - break; - case nsIDocument::eConnected: if (aDefinition->mCallbacks->mConnectedCallback.WasPassed()) { func = aDefinition->mCallbacks->mConnectedCallback.Value(); @@ -401,17 +358,9 @@ CustomElementRegistry::CreateCustomElementCallback( return nullptr; } - if (aType == nsIDocument::eCreated) { - elementData->mCreatedCallbackInvoked = false; - } else if (!elementData->mCreatedCallbackInvoked) { - // Callbacks other than created callback must not be enqueued - // until after the created callback has been invoked. - return nullptr; - } - // Add CALLBACK to ELEMENT's callback queue. auto callback = - MakeUnique(aCustomElement, aType, func, elementData); + MakeUnique(aCustomElement, aType, func); if (aArgs) { callback->SetArgs(*aArgs); @@ -520,9 +469,7 @@ static const char* kLifeCycleCallbackNames[] = { "connectedCallback", "disconnectedCallback", "adoptedCallback", - "attributeChangedCallback", - // The life cycle callbacks from v0 spec. - "createdCallback" + "attributeChangedCallback" }; static void @@ -986,11 +933,6 @@ CustomElementRegistry::Upgrade(Element* aElement, // Step 9. aElement->SetCustomElementDefinition(aDefinition); - - // This is for old spec. - nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eCreated, - aElement, nullptr, - nullptr, aDefinition); } //----------------------------------------------------- @@ -1162,11 +1104,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CustomElementDefinition) cb.NoteXPCOMChild(callbacks->mAttributeChangedCallback.Value()); } - if (callbacks->mCreatedCallback.WasPassed()) { - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mCreatedCallback"); - cb.NoteXPCOMChild(callbacks->mCreatedCallback.Value()); - } - if (callbacks->mConnectedCallback.WasPassed()) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mConnectedCallback"); cb.NoteXPCOMChild(callbacks->mConnectedCallback.Value()); diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index eb4285fd2..c180a10af 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -49,8 +49,7 @@ class CustomElementCallback public: CustomElementCallback(Element* aThisObject, nsIDocument::ElementCallbackType aCallbackType, - CallbackFunction* aCallback, - CustomElementData* aOwnerData); + CallbackFunction* aCallback); void Traverse(nsCycleCollectionTraversalCallback& aCb) const; void Call(); void SetArgs(LifecycleCallbackArgs& aArgs) @@ -77,9 +76,6 @@ private: // used by the attribute changed callback. LifecycleCallbackArgs mArgs; LifecycleAdoptedCallbackArgs mAdoptedCallbackArgs; - // CustomElementData that contains this callback in the - // callback queue. - CustomElementData* mOwnerData; }; class CustomElementConstructor final : public CallbackFunction @@ -113,11 +109,6 @@ struct CustomElementData explicit CustomElementData(nsIAtom* aType); CustomElementData(nsIAtom* aType, State aState); - // 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; // Custom element state as described in the custom element spec. State mState; // custom element reaction queue as described in the custom element spec. diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 364583c88..125816c95 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -2579,7 +2579,6 @@ public: } enum ElementCallbackType { - eCreated, eConnected, eDisconnected, eAdopted, diff --git a/dom/base/test/chrome/registerElement_ep.js b/dom/base/test/chrome/registerElement_ep.js index de32ba51c..9189593c0 100644 --- a/dom/base/test/chrome/registerElement_ep.js +++ b/dom/base/test/chrome/registerElement_ep.js @@ -1,8 +1,8 @@ var proto = Object.create(HTMLElement.prototype); proto.magicNumber = 42; -proto.createdCallback = function() { +proto.connectedCallback = function() { finishTest(this.magicNumber === 42); }; document.registerElement("x-foo", { prototype: proto }); -document.createElement("x-foo"); +document.firstChild.appendChild(document.createElement("x-foo")); diff --git a/dom/base/test/chrome/test_registerElement_content.xul b/dom/base/test/chrome/test_registerElement_content.xul index 9a918f2d7..bf00ed53d 100644 --- a/dom/base/test/chrome/test_registerElement_content.xul +++ b/dom/base/test/chrome/test_registerElement_content.xul @@ -21,19 +21,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1130028 diff --git a/dom/base/test/chrome/test_registerElement_ep.xul b/dom/base/test/chrome/test_registerElement_ep.xul index 6f1745268..b6a160c2e 100644 --- a/dom/base/test/chrome/test_registerElement_ep.xul +++ b/dom/base/test/chrome/test_registerElement_ep.xul @@ -26,8 +26,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1130028 SimpleTest.waitForExplicitFinish(); function finishTest(canSeePrototype) { - ok(true, "createdCallback called when reigsterElement was called with an extended principal."); - ok(canSeePrototype, "createdCallback should be able to see custom prototype."); + ok(true, "connectedCallback called when reigsterElement was called with an extended principal."); + ok(canSeePrototype, "connectedCallback should be able to see custom prototype."); SimpleTest.finish(); } diff --git a/dom/tests/mochitest/webcomponents/mochitest.ini b/dom/tests/mochitest/webcomponents/mochitest.ini index b32e9999e..3559f33c1 100644 --- a/dom/tests/mochitest/webcomponents/mochitest.ini +++ b/dom/tests/mochitest/webcomponents/mochitest.ini @@ -8,16 +8,13 @@ support-files = [test_bug1176757.html] [test_bug1276240.html] [test_content_element.html] -[test_custom_element_adopt_callbacks.html] [test_custom_element_callback_innerhtml.html] skip-if = true # disabled - See bug 1390396 -[test_custom_element_clone_callbacks_extended.html] [test_custom_element_htmlconstructor.html] skip-if = os == 'android' # bug 1323645 support-files = htmlconstructor_autonomous_tests.js htmlconstructor_builtin_tests.js -[test_custom_element_import_node_created_callback.html] [test_custom_element_in_shadow.html] skip-if = true || stylo # disabled - See bug 1390396 and 1293844 [test_custom_element_register_invalid_callbacks.html] diff --git a/dom/tests/mochitest/webcomponents/test_custom_element_adopt_callbacks.html b/dom/tests/mochitest/webcomponents/test_custom_element_adopt_callbacks.html deleted file mode 100644 index 28597b7c6..000000000 --- a/dom/tests/mochitest/webcomponents/test_custom_element_adopt_callbacks.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - Test callbacks for adopted custom elements. - - - - - -Bug 1081039 - - - diff --git a/dom/tests/mochitest/webcomponents/test_custom_element_clone_callbacks_extended.html b/dom/tests/mochitest/webcomponents/test_custom_element_clone_callbacks_extended.html deleted file mode 100644 index b3531b0ea..000000000 --- a/dom/tests/mochitest/webcomponents/test_custom_element_clone_callbacks_extended.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - Test callbacks for cloned extended custom elements. - - - - -Bug 1081039 - - - diff --git a/dom/tests/mochitest/webcomponents/test_custom_element_import_node_created_callback.html b/dom/tests/mochitest/webcomponents/test_custom_element_import_node_created_callback.html deleted file mode 100644 index f533b507c..000000000 --- a/dom/tests/mochitest/webcomponents/test_custom_element_import_node_created_callback.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - Test created callback order for imported custom element. - - - - - -Bug 1093680 - - - diff --git a/dom/tests/mochitest/webcomponents/test_custom_element_register_invalid_callbacks.html b/dom/tests/mochitest/webcomponents/test_custom_element_register_invalid_callbacks.html index d1b1b1e04..572579ba8 100644 --- a/dom/tests/mochitest/webcomponents/test_custom_element_register_invalid_callbacks.html +++ b/dom/tests/mochitest/webcomponents/test_custom_element_register_invalid_callbacks.html @@ -19,7 +19,6 @@ const testWindow = iframe.contentDocument.defaultView; // This is for backward compatibility. // We should do the same checks for the callbacks from v0 spec. [ - 'createdCallback', 'attributeChangedCallback', ].forEach(callback => { var c = class {}; diff --git a/dom/tests/mochitest/webcomponents/test_document_shared_registry.html b/dom/tests/mochitest/webcomponents/test_document_shared_registry.html index 76c2ea8ec..db72e1e6c 100644 --- a/dom/tests/mochitest/webcomponents/test_document_shared_registry.html +++ b/dom/tests/mochitest/webcomponents/test_document_shared_registry.html @@ -14,37 +14,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=783129