Bug 711616 - QI wrapped native weak map keys to nsINode. r=jst
authorAndrew McCreight <amccreight@mozilla.com>
Sat, 17 Dec 2011 22:11:04 -0800
changeset 84542 b0b4b0ce8ad56bdcf585b39647dc0a23e1ca3b93
parent 84541 e75f1076eab075cc26e2e8d194af21ef158d12f2
child 84543 015286abfd066ce877964c0cedc003d933464443
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs711616
milestone11.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 711616 - QI wrapped native weak map keys to nsINode. r=jst
js/xpconnect/src/XPCJSRuntime.cpp
js/xpconnect/tests/chrome/test_weakmaps.xul
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -2131,21 +2131,21 @@ AccumulateTelemetryCallback(int id, uint
 bool XPCJSRuntime::gNewDOMBindingsEnabled;
 
 bool PreserveWrapper(JSContext *cx, JSObject *obj)
 {
     JS_ASSERT(obj->getClass()->ext.isWrappedNative);
     nsISupports *native = nsXPConnect::GetXPConnect()->GetNativeOfWrapper(cx, obj);
     if (!native)
         return false;
-    nsWrapperCache *wc;
-    nsresult rv = CallQueryInterface(native, &wc);
+    nsresult rv;
+    nsCOMPtr<nsINode> node = nsQueryInterfaceWithError(native, &rv);
     if (NS_FAILED(rv))
         return false;
-    nsContentUtils::PreserveWrapper(native, wc);
+    nsContentUtils::PreserveWrapper(native, node);
     return true;
 }
 
 XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
  : mXPConnect(aXPConnect),
    mJSRuntime(nsnull),
    mJSCycleCollectionContext(nsnull),
    mWrappedJSMap(JSObject2WrappedJSMap::newMap(XPC_JS_MAP_SIZE)),
--- a/js/xpconnect/tests/chrome/test_weakmaps.xul
+++ b/js/xpconnect/tests/chrome/test_weakmaps.xul
@@ -209,16 +209,24 @@ https://bugzilla.mozilla.org/show_bug.cg
   let make_live_map = function () {
     let live = get_live_dom();
     wn_live_map.set(live, {});
   }
 
   make_live_map();
 
 
+  let dummy_test_map = new WeakMap;
+  // bug 711616: should be able to do this without crashing. JS warning is expected.
+  dummy_test_map.set(document.createElement("div").style, 1);
+
+  // JS warning is expected.
+  dummy_test_map.set(window.navigator, 1);
+
+
   /* set up for running precise GC/CC then checking the results */
 
   SimpleTest.waitForExplicitFinish();
 
   Cu.schedulePreciseGC(function () {
     window.QueryInterface(Ci.nsIInterfaceRequestor)
          .getInterface(Ci.nsIDOMWindowUtils)
          .cycleCollect();