Bug 888225 - Check for child window naming collisions before defining global properties in GlobalResolve. r=bz, a=bajaj
authorBobby Holley <bobbyholley@gmail.com>
Tue, 02 Jul 2013 18:35:36 -0600
changeset 147865 0e435f315f3a584c1094187da95d3ae5c474a509
parent 147864 3967f5179aabec839d11847e3a01e0b9194b97dd
child 147866 13e7544dc81dc8415f4f8be2048cbef58886d20b
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, bajaj
bugs888225
milestone24.0a2
Bug 888225 - Check for child window naming collisions before defining global properties in GlobalResolve. r=bz, a=bajaj
dom/base/nsDOMClassInfo.cpp
dom/tests/mochitest/bugs/test_bug857555.html
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -4121,16 +4121,22 @@ nsWindowSH::GlobalResolve(nsGlobalWindow
 
     return NS_OK;
   }
 
   if (name_struct->mType == nsGlobalNameStruct::eTypeProperty) {
     if (name_struct->mChromeOnly && !nsContentUtils::IsCallerChrome())
       return NS_OK;
 
+    // Before defining a global property, check for a named subframe of the
+    // same name. If it exists, we don't want to shadow it.
+    nsCOMPtr<nsIDOMWindow> childWin = aWin->GetChildWindow(name);
+    if (childWin)
+      return NS_OK;
+
     nsCOMPtr<nsISupports> native(do_CreateInstance(name_struct->mCID, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
 
     JS::Rooted<JS::Value> prop_val(cx, JS::UndefinedValue()); // Property value.
 
     nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
     nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi(do_QueryInterface(native));
     if (gpi) {
--- a/dom/tests/mochitest/bugs/test_bug857555.html
+++ b/dom/tests/mochitest/bugs/test_bug857555.html
@@ -10,22 +10,26 @@ https://bugzilla.mozilla.org/show_bug.cg
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
 
   /** Test for Bug 857555 **/
   SimpleTest.waitForExplicitFinish();
 
   addLoadEvent(function() {
     is(content, $("t").contentWindow, "'content' as iframe name should work");
+    is(sidebar, $("u").contentWindow, "'sidebar' as iframe name should work");
+    is(external, $("v").contentWindow, "'external' as iframe name should work");
     SimpleTest.finish();
   });
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=857555">Mozilla Bug 857555</a>
 <p id="display"></p>
 <div id="content" style="display: none">
   <iframe name="content" id="t"></iframe>
+  <iframe name="sidebar" id="u"></iframe>
+  <iframe name="external" id="v"></iframe>
 </div>
 <pre id="test">
 </pre>
 </body>
 </html>