jscomponentloader-gc
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 57 230d3f80e0bb18f55c4df42e2baefcd98e436b3d
permissions -rw-r--r--
State as of now

* * *
* * *

diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
--- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
@@ -595,7 +595,7 @@ mozJSComponentLoader::LoadModule(nsILoca
     if (!entry)
         return NS_ERROR_OUT_OF_MEMORY;
 
-    rv = GlobalForLocation(aComponentFile, &entry->global, &entry->location);
+    rv = GlobalForLocation(aComponentFile, &entry->global);
     if (NS_FAILED(rv)) {
 #ifdef DEBUG_shaver
         fprintf(stderr, "GlobalForLocation failed!\n");
@@ -763,21 +763,23 @@ class FastLoadStateHolder
     void pop();
 
  private:
-    nsCOMPtr<nsIFastLoadService> mService;
-    nsCOMPtr<nsIFastLoadFileIO> mIO;
-    nsCOMPtr<nsIObjectInputStream> mInputStream;
-    nsCOMPtr<nsIObjectOutputStream> mOutputStream;
+    nsIFastLoadService* mService;
+    nsIFastLoadFileIO* mIO;
+    nsIObjectInputStream* mInputStream;
+    nsIObjectOutputStream* mOutputStream;
 };
 
 FastLoadStateHolder::FastLoadStateHolder(nsIFastLoadService *service)
 {
+    ASSERT_StackObject(this);
+
     if (!service)
         return;
 
     mService = service;
-    service->GetFileIO(getter_AddRefs(mIO));
-    service->GetInputStream(getter_AddRefs(mInputStream));
-    service->GetOutputStream(getter_AddRefs(mOutputStream));
+    service->GetFileIO(&mIO);
+    service->GetInputStream(&mInputStream);
+    service->GetOutputStream(&mOutputStream);
 }
 
 void
@@ -1017,8 +1019,7 @@ mozJSComponentLoader::WriteScript(nsIFas
 
 nsresult
 mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponent,
-                                        JSObject **aGlobal,
-                                        char **aLocation)
+                                        JSObject **aGlobal)
 {
     nsresult rv;
 
@@ -1269,13 +1270,7 @@ mozJSComponentLoader::GlobalForLocation(
     /* Freed when we remove from the table. */
     nsCAutoString path;
     aComponent->GetNativePath(path);
-    *aLocation = ToNewCString(path);
-    if (!*aLocation) {
-        *aGlobal = nsnull;
-        return NS_ERROR_OUT_OF_MEMORY;
-    }
-
-    JS_AddNamedRoot(cx, aGlobal, *aLocation);
+
     return NS_OK;
 }
 
@@ -1439,8 +1434,7 @@ mozJSComponentLoader::ImportInto(const n
         if (!newEntry || !mInProgressImports.Put(lfhash, newEntry))
             return NS_ERROR_OUT_OF_MEMORY;
 
-        rv = GlobalForLocation(componentFile, &newEntry->global,
-                               &newEntry->location);
+        rv = GlobalForLocation(componentFile, &newEntry->global);
 
         mInProgressImports.Remove(lfhash);
 
diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.h b/js/src/xpconnect/loader/mozJSComponentLoader.h
--- a/js/src/xpconnect/loader/mozJSComponentLoader.h
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.h
@@ -53,7 +53,7 @@
 #include "nsITimer.h"
 #include "nsIObserver.h"
 #include "xpcIJSModuleLoader.h"
-#include "nsClassHashtable.h"
+#include "nsInterfaceHashtable.h"
 #include "nsDataHashtable.h"
 #ifndef XPCONNECT_STANDALONE
 #include "nsIPrincipal.h"
@@ -109,8 +109,7 @@ class mozJSComponentLoader : public XPCO
     void UnloadModules();
 
     nsresult GlobalForLocation(nsILocalFile *aComponent,
-                               JSObject **aGlobal,
-                               char **location);
+                               JSObject **aGlobal);
 
     nsresult StartFastLoad(nsIFastLoadService *flSvc);
     nsresult ReadScript(nsIFastLoadService *flSvc, const char *nativePath,
@@ -136,37 +135,22 @@ class mozJSComponentLoader : public XPCO
     JSRuntime *mRuntime;
     JSContext *mContext;
 
-    class ModuleEntry
+    class ModuleEntry : public XPCOMGCObject
     {
     public:
         ModuleEntry() {
             global = nsnull;
-            location = nsnull;
-        }
-
-        ~ModuleEntry() {
-            module = nsnull;
-
-            if (global) {
-                JSAutoRequest ar(sSelf->mContext);
-                JS_ClearScope(sSelf->mContext, global);
-                JS_RemoveRoot(sSelf->mContext, &global);
-            }
-
-            if (location)
-                NS_Free(location);
         }
 
         nsCOMPtr<nsIModule>  module;
         JSObject            *global;
-        char                *location;
     };
 
     friend class ModuleEntry;
 
-    nsClassHashtable<nsHashableHashKey, ModuleEntry> mModules;
-    nsClassHashtable<nsHashableHashKey, ModuleEntry> mImports;
-    nsDataHashtable<nsHashableHashKey, ModuleEntry*> mInProgressImports;
+    nsInterfaceHashtable<nsHashableHashKey, ModuleEntry, GCAllocator> mModules;
+    nsInterfaceHashtable<nsHashableHashKey, ModuleEntry, GCAllocator> mImports;
+    nsDataHashtable<nsHashableHashKey, ModuleEntry*, GCAllocator> mInProgressImports;
 
     PRBool mInitialized;
 };