Bug 650161 - Root JSRuntimeWrapper::mGlobal r=sworkman
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 24 Oct 2014 08:49:33 +0100
changeset 212229 21b64777a90ea279fc658e780dad193bebb297b8
parent 212228 128fd9cbc29bcec8e325ad247dfebe569bdc8a65
child 212230 c275c8e2fe0a8cbf0f7f30869ec6dc0eecb0b2fc
push id9560
push userkwierso@gmail.com
push dateFri, 24 Oct 2014 22:09:23 +0000
treeherderfx-team@c70f62375f7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman
bugs650161
milestone36.0a1
Bug 650161 - Root JSRuntimeWrapper::mGlobal r=sworkman
netwerk/base/src/ProxyAutoConfig.cpp
--- a/netwerk/base/src/ProxyAutoConfig.cpp
+++ b/netwerk/base/src/ProxyAutoConfig.cpp
@@ -497,18 +497,21 @@ static const JSFunctionSpec PACGlobalFun
 // JSRuntimeWrapper is a c++ object that manages the runtime and context
 // for the JS engine used on the PAC thread. It is initialized and destroyed
 // on the PAC thread.
 class JSRuntimeWrapper
 {
  public:
   static JSRuntimeWrapper *Create()
   {
-    JSRuntimeWrapper *entry = new JSRuntimeWrapper();
+    JSRuntime *runtime = JS_NewRuntime(sRuntimeHeapSize);
+    if (NS_WARN_IF(!runtime))
+      return nullptr;
 
+    JSRuntimeWrapper *entry = new JSRuntimeWrapper(runtime);
     if (NS_FAILED(entry->Init())) {
       delete entry;
       return nullptr;
     }
 
     return entry;
   }
 
@@ -519,16 +522,18 @@ class JSRuntimeWrapper
 
   JSObject *Global() const
   {
     return mGlobal;
   }
 
   ~JSRuntimeWrapper()
   {
+    mGlobal = nullptr;
+
     MOZ_COUNT_DTOR(JSRuntimeWrapper);
     if (mContext) {
       JS_DestroyContext(mContext);
     }
 
     if (mRuntime) {
       JS_DestroyRuntime(mRuntime);
     }
@@ -544,32 +549,29 @@ class JSRuntimeWrapper
     return mOK;
   }
 
 private:
   static const unsigned sRuntimeHeapSize = 2 << 20;
 
   JSRuntime *mRuntime;
   JSContext *mContext;
-  JSObject  *mGlobal;
+  JS::PersistentRooted<JSObject*> mGlobal;
   bool      mOK;
 
   static const JSClass sGlobalClass;
 
-  JSRuntimeWrapper()
-    : mRuntime(nullptr), mContext(nullptr), mGlobal(nullptr), mOK(false)
+  JSRuntimeWrapper(JSRuntime* rt)
+     : mRuntime(rt), mContext(nullptr), mGlobal(rt, nullptr), mOK(false)
   {
       MOZ_COUNT_CTOR(JSRuntimeWrapper);
   }
 
   nsresult Init()
   {
-    mRuntime = JS_NewRuntime(sRuntimeHeapSize);
-    NS_ENSURE_TRUE(mRuntime, NS_ERROR_OUT_OF_MEMORY);
-
     /*
      * Not setting this will cause JS_CHECK_RECURSION to report false
      * positives
      */
     JS_SetNativeStackQuota(mRuntime, 128 * sizeof(size_t) * 1024); 
 
     JS_SetErrorReporter(mRuntime, PACErrorReporter);