Created
July 20, 2018 08:36
-
-
Save juliandescottes/60cbeabb4259cc240f2eea7ec290bce3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp | |
--- a/dom/base/CustomElementRegistry.cpp | |
+++ b/dom/base/CustomElementRegistry.cpp | |
@@ -1,22 +1,26 @@ | |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |
/* vim: set ts=8 sts=2 et sw=2 tw=80: */ | |
/* 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/. */ | |
+ | |
+ | |
#include "mozilla/dom/CustomElementRegistry.h" | |
+#include "mozilla/AsyncEventDispatcher.h" | |
#include "mozilla/CycleCollectedJSContext.h" | |
#include "mozilla/dom/CustomElementRegistryBinding.h" | |
#include "mozilla/dom/HTMLElementBinding.h" | |
#include "mozilla/dom/Promise.h" | |
#include "mozilla/dom/WebComponentsBinding.h" | |
#include "mozilla/dom/DocGroup.h" | |
+#include "mozilla/dom/CustomEvent.h" | |
#include "nsHTMLTags.h" | |
#include "jsapi.h" | |
#include "nsGlobalWindow.h" | |
namespace mozilla { | |
namespace dom { | |
//----------------------------------------------------- | |
@@ -952,16 +956,39 @@ CustomElementRegistry::Define(JSContext* | |
* when-defined promise map. | |
*/ | |
RefPtr<Promise> promise; | |
mWhenDefinedPromiseMap.Remove(nameAtom, getter_AddRefs(promise)); | |
if (promise) { | |
promise->MaybeResolveWithUndefined(); | |
} | |
+ // Dispatch a "customelementdefined" event for devtools. | |
+ { | |
+ JSString* nameJsStr = JS_NewUCStringCopyN(aCx, | |
+ aName.BeginReading(), | |
+ aName.Length()); | |
+ | |
+ JS::Rooted<JS::Value> detail(aCx, JS::StringValue(nameJsStr)); | |
+ RefPtr<CustomEvent> event = NS_NewDOMCustomEvent(doc, nullptr, nullptr); | |
+ event->InitCustomEvent(aCx, | |
+ NS_LITERAL_STRING("customelementdefined"), | |
+ false, | |
+ false, | |
+ detail); | |
+ event->SetTrusted(true); | |
+ | |
+ AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(doc, event); | |
+ dispatcher->mOnlyChromeDispatch = ChromeOnlyDispatch::eYes; | |
+ dispatcher->mCanBubble = CanBubble::eYes; | |
+ dispatcher->mComposed = Composed::eYes; | |
+ | |
+ dispatcher->PostDOMEvent(); | |
+ } | |
+ | |
/** | |
* Clean-up mElementCreationCallbacks (if it exists) | |
*/ | |
mElementCreationCallbacks.Remove(nameAtom); | |
} | |
void |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment