Bug 1341693 - Don't need to check GetDocShell() when creating CustomElementRegistry; r=wchen
authorEdgar Chen <echen@mozilla.com>
Thu, 23 Feb 2017 18:24:05 +0800
changeset 344938 2dd1002e793bbce35bbd3e39e906028e4acd0107
parent 344937 85e40ef81409ff7f4188407b160aa80a3745a7d3
child 344940 a08ec245fa24d573fc99e81210ecc09de734cdd3
child 344964 4fbd0ba0c3d7a3c1a97af834157d52d1be1f188f
push id37977
push userphilringnalda@gmail.com
push dateSat, 25 Feb 2017 21:34:46 +0000
treeherderautoland@10bfa931c92f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen
bugs1341693
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1341693 - Don't need to check GetDocShell() when creating CustomElementRegistry; r=wchen MozReview-Commit-ID: 7k3MQBEMpnV
dom/base/CustomElementRegistry.cpp
dom/base/CustomElementRegistry.h
dom/base/crashtests/1341693.html
dom/base/crashtests/crashtests.list
dom/base/nsGlobalWindow.cpp
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -170,40 +170,16 @@ NS_INTERFACE_MAP_END
 
 /* static */ bool
 CustomElementRegistry::IsCustomElementEnabled(JSContext* aCx, JSObject* aObject)
 {
   return Preferences::GetBool("dom.webcomponents.customelements.enabled") ||
          nsContentUtils::IsWebComponentsEnabled();
 }
 
-/* static */ already_AddRefed<CustomElementRegistry>
-CustomElementRegistry::Create(nsPIDOMWindowInner* aWindow)
-{
-  MOZ_ASSERT(aWindow);
-  MOZ_ASSERT(aWindow->IsInnerWindow());
-
-  if (!aWindow->GetDocShell()) {
-    return nullptr;
-  }
-
-  if (!IsCustomElementEnabled()) {
-    return nullptr;
-  }
-
-  RefPtr<CustomElementRegistry> customElementRegistry =
-    new CustomElementRegistry(aWindow);
-
-  if (!customElementRegistry->Init()) {
-    return nullptr;
-  }
-
-  return customElementRegistry.forget();
-}
-
 /* static */ void
 CustomElementRegistry::ProcessTopElementQueue()
 {
   MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
 
   nsTArray<RefPtr<CustomElementData>>& stack = *sProcessingStack;
   uint32_t firstQueue = stack.LastIndexOf((CustomElementData*) nullptr);
 
@@ -236,36 +212,34 @@ CustomElementRegistry::XPCOMShutdown()
 /* static */ Maybe<nsTArray<RefPtr<CustomElementData>>>
 CustomElementRegistry::sProcessingStack;
 
 CustomElementRegistry::CustomElementRegistry(nsPIDOMWindowInner* aWindow)
  : mWindow(aWindow)
  , mIsCustomDefinitionRunning(false)
  , mIsBackupQueueProcessing(false)
 {
+  MOZ_ASSERT(aWindow);
+  MOZ_ASSERT(aWindow->IsInnerWindow());
+  MOZ_ALWAYS_TRUE(mConstructors.init());
+
   mozilla::HoldJSObjects(this);
 
   if (!sProcessingStack) {
     sProcessingStack.emplace();
     // Add the base queue sentinel to the processing stack.
     sProcessingStack->AppendElement((CustomElementData*) nullptr);
   }
 }
 
 CustomElementRegistry::~CustomElementRegistry()
 {
   mozilla::DropJSObjects(this);
 }
 
-bool
-CustomElementRegistry::Init()
-{
-  return mConstructors.init();
-}
-
 CustomElementDefinition*
 CustomElementRegistry::LookupCustomElementDefinition(const nsAString& aLocalName,
                                                      const nsAString* aIs) const
 {
   nsCOMPtr<nsIAtom> localNameAtom = NS_Atomize(aLocalName);
   nsCOMPtr<nsIAtom> typeAtom = aIs ? NS_Atomize(*aIs) : localNameAtom;
 
   CustomElementDefinition* data = mCustomDefinitions.Get(typeAtom);
--- a/dom/base/CustomElementRegistry.h
+++ b/dom/base/CustomElementRegistry.h
@@ -173,21 +173,23 @@ class CustomElementRegistry final : publ
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CustomElementRegistry)
 
 public:
   static bool IsCustomElementEnabled(JSContext* aCx = nullptr,
                                      JSObject* aObject = nullptr);
-  static already_AddRefed<CustomElementRegistry> Create(nsPIDOMWindowInner* aWindow);
+
   static void ProcessTopElementQueue();
 
   static void XPCOMShutdown();
 
+  explicit CustomElementRegistry(nsPIDOMWindowInner* aWindow);
+
   /**
    * Looking up a custom element definition.
    * https://html.spec.whatwg.org/#look-up-a-custom-element-definition
    */
   CustomElementDefinition* LookupCustomElementDefinition(
     const nsAString& aLocalName, const nsAString* aIs = nullptr) const;
 
   CustomElementDefinition* LookupCustomElementDefinition(
@@ -222,21 +224,18 @@ public:
   void CreateAndPushElementQueue();
 
   // [CEReactions] After executing the algorithm's steps
   // Pop the element queue from the custom element reactions stack,
   // and invoke custom element reactions in that queue.
   void PopAndInvokeElementQueue();
 
 private:
-  explicit CustomElementRegistry(nsPIDOMWindowInner* aWindow);
   ~CustomElementRegistry();
 
-  bool Init();
-
   /**
    * Registers an unresolved custom element that is a candidate for
    * upgrade when the definition is registered via registerElement.
    * |aTypeName| is the name of the custom element type, if it is not
    * provided, then element name is used. |aTypeName| should be provided
    * when registering a custom element that extends an existing
    * element. e.g. <button is="x-button">.
    */
new file mode 100644
--- /dev/null
+++ b/dom/base/crashtests/1341693.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+  var o1 = document.documentElement;
+  var o2 = document.createElement("frame");
+  document.documentElement.appendChild(o2);
+  var o3 = o2.contentWindow;
+  o1.parentNode.removeChild(o1);
+  o3.customElements;
+</script>
+</body>
+</html>
--- a/dom/base/crashtests/crashtests.list
+++ b/dom/base/crashtests/crashtests.list
@@ -207,8 +207,9 @@ load xhr_empty_datauri.html
 load xhr_html_nullresponse.html
 load 1230422.html
 load 1251361.html
 load 1304437.html
 pref(dom.IntersectionObserver.enabled,true) load 1324209.html
 pref(dom.IntersectionObserver.enabled,true) load 1326194-1.html
 pref(dom.IntersectionObserver.enabled,true) load 1326194-2.html
 pref(dom.IntersectionObserver.enabled,true) load 1332939.html
+pref(dom.webcomponents.enabled,true) load 1341693.html
\ No newline at end of file
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -4092,18 +4092,19 @@ nsGlobalWindow::GetHistory(ErrorResult& 
 
   return mHistory;
 }
 
 CustomElementRegistry*
 nsGlobalWindow::CustomElements()
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
+
   if (!mCustomElements) {
-      mCustomElements = CustomElementRegistry::Create(AsInner());
+    mCustomElements = new CustomElementRegistry(AsInner());
   }
 
   return mCustomElements;
 }
 
 Performance*
 nsPIDOMWindowInner::GetPerformance()
 {