work with service to manage JSRuntimes

This commit is contained in:
shaver%netscape.com 1999-09-05 00:43:39 +00:00
Родитель f4df3a45be
Коммит 97cca12af5
1 изменённых файлов: 25 добавлений и 4 удалений

Просмотреть файл

@ -38,6 +38,7 @@
#include "nsIXPConnect.h" #include "nsIXPConnect.h"
#include "nsIXPCSecurityManager.h" #include "nsIXPCSecurityManager.h"
#include "nsIJSContextStack.h" #include "nsIJSContextStack.h"
#include "nsIJSRuntimeService.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#if defined(OJI) #if defined(OJI)
@ -424,12 +425,26 @@ nsJSEnvironment::GetScriptingEnvironment()
nsJSEnvironment::nsJSEnvironment() nsJSEnvironment::nsJSEnvironment()
{ {
mRuntime = JS_Init(gGCSize); nsresult result;
NS_WITH_SERVICE(nsIJSRuntimeService, rtsvc, "nsJSRuntimeService", &result);
// get the JSRuntime from the runtime svc, if possible
if (NS_SUCCEEDED(result)) {
result = rtsvc->GetRuntime(&mRuntime);
if (NS_FAILED(result) || !mRuntime) {
mRuntime = JS_NewRuntime(gGCSize);
if (NS_SUCCEEDED(result)) // got service, so set it back
rtsvc->SetRuntime(mRuntime);
}
} else {
mRuntime = JS_NewRuntime(gGCSize);
}
#if defined(OJI) #if defined(OJI)
// Initialize LiveConnect. // Initialize LiveConnect.
nsILiveConnectManager* manager = NULL; nsILiveConnectManager* manager = NULL;
nsresult result = nsServiceManager::GetService(nsIJVMManager::GetCID(), result = nsServiceManager::GetService(nsIJVMManager::GetCID(),
nsILiveConnectManager::GetIID(), nsILiveConnectManager::GetIID(),
(nsISupports **)&manager); (nsISupports **)&manager);
@ -440,11 +455,17 @@ nsJSEnvironment::nsJSEnvironment()
result = nsServiceManager::ReleaseService(nsIJVMManager::GetCID(), manager); result = nsServiceManager::ReleaseService(nsIJVMManager::GetCID(), manager);
} }
#endif #endif
} }
nsJSEnvironment::~nsJSEnvironment() nsJSEnvironment::~nsJSEnvironment()
{ {
JS_Finish(mRuntime); nsresult result;
NS_WITH_SERVICE(nsIJSRuntimeService, rtsvc, "nsJSRuntimeService", &result);
if (NS_SUCCEEDED(result)) {
rtsvc->SetRuntime(0);
}
JS_DestroyRuntime(mRuntime);
} }
nsIScriptContext* nsJSEnvironment::GetNewContext() nsIScriptContext* nsJSEnvironment::GetNewContext()