Bug 680937, part 3 - implement and set preserve wrapper callback. r=jst
authorAndrew McCreight <amccreight@mozilla.com>
Thu, 15 Dec 2011 17:45:49 -0800
changeset 84382 21e2e05a8d8eb1334d306e5802f9f4cad2a3a75e
parent 84381 9a966139c3fe33e47c4f4a8bcc2cd0967778672e
child 84383 39f25929ceeaf9471e693f5b971ca97a652623aa
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
bugs680937
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 680937, part 3 - implement and set preserve wrapper callback. r=jst
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -53,16 +53,18 @@
 #include "jsscope.h"
 #include "nsIMemoryReporter.h"
 #include "nsPrintfCString.h"
 #include "mozilla/FunctionTimer.h"
 #include "prsystem.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 
+#include "nsContentUtils.h"
+
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::xpconnect::memory;
 
 /***************************************************************************/
@@ -2123,16 +2125,30 @@ AccumulateTelemetryCallback(int id, JSUi
       case JS_TELEMETRY_GC_SWEEP_MS:
         Telemetry::Accumulate(Telemetry::GC_SWEEP_MS, sample);
         break;
     }
 }
 
 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);
+    if (NS_FAILED(rv))
+        return false;
+    nsContentUtils::PreserveWrapper(native, wc);
+    return true;
+}
+
 XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
  : mXPConnect(aXPConnect),
    mJSRuntime(nsnull),
    mJSCycleCollectionContext(nsnull),
    mWrappedJSMap(JSObject2WrappedJSMap::newMap(XPC_JS_MAP_SIZE)),
    mWrappedJSClassMap(IID2WrappedJSClassMap::newMap(XPC_JS_CLASS_MAP_SIZE)),
    mIID2NativeInterfaceMap(IID2NativeInterfaceMap::newMap(XPC_NATIVE_INTERFACE_MAP_SIZE)),
    mClassInfo2NativeSetMap(ClassInfo2NativeSetMap::newMap(XPC_NATIVE_SET_MAP_SIZE)),
@@ -2185,16 +2201,18 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* 
         JS_SetContextCallback(mJSRuntime, ContextCallback);
         JS_SetCompartmentCallback(mJSRuntime, CompartmentCallback);
         JS_SetGCCallbackRT(mJSRuntime, GCCallback);
         JS_SetExtraGCRootsTracer(mJSRuntime, TraceBlackJS, this);
         JS_SetGrayGCRootsTracer(mJSRuntime, TraceGrayJS, this);
         JS_SetWrapObjectCallbacks(mJSRuntime,
                                   xpc::WrapperFactory::Rewrap,
                                   xpc::WrapperFactory::PrepareForWrapping);
+        js::SetPreserveWrapperCallback(mJSRuntime, PreserveWrapper);
+
 #ifdef MOZ_CRASHREPORTER
         JS_EnumerateDiagnosticMemoryRegions(DiagnosticMemoryCallback);
 #endif
         JS_SetAccumulateTelemetryCallback(mJSRuntime, AccumulateTelemetryCallback);
         mWatchdogWakeup = JS_NEW_CONDVAR(mJSRuntime->gcLock);
         if (!mWatchdogWakeup)
             NS_RUNTIMEABORT("JS_NEW_CONDVAR failed.");