зеркало из https://github.com/mozilla/pjs.git
Bug 763848 - Expose the path to libxul at OS.Constants.Sys. r=khuey
This commit is contained in:
Родитель
1129aada2a
Коммит
d10793c683
|
@ -29,6 +29,9 @@ ifdef MOZ_B2G_RIL
|
|||
DIRS += gonk
|
||||
endif
|
||||
|
||||
DEFINES += -DDLL_PREFIX=\"$(DLL_PREFIX)\" -DDLL_SUFFIX=\"$(DLL_SUFFIX)\"
|
||||
|
||||
|
||||
CPPSRCS = \
|
||||
nsDeviceSensors.cpp \
|
||||
OSFileConstants.cpp \
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "fcntl.h"
|
||||
#include "errno.h"
|
||||
|
||||
#include "prsystem.h"
|
||||
|
||||
#if defined(XP_UNIX)
|
||||
#include "unistd.h"
|
||||
#endif // defined(XP_UNIX)
|
||||
|
@ -23,6 +25,8 @@
|
|||
|
||||
// Used to provide information on the OS
|
||||
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsIXULRuntime.h"
|
||||
#include "nsXPCOMCIDInternal.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
@ -35,8 +39,65 @@
|
|||
* etc.) used by OS.File and possibly other OS-bound JavaScript libraries.
|
||||
*/
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
// Use an anonymous namespace to hide the symbols and avoid any collision
|
||||
// with, for instance, |extern bool gInitialized;|
|
||||
namespace {
|
||||
/**
|
||||
* |true| if this module has been initialized, |false| otherwise
|
||||
*/
|
||||
bool gInitialized = false;
|
||||
|
||||
/**
|
||||
* The name of the directory holding all the libraries (libxpcom, libnss, etc.)
|
||||
*/
|
||||
nsString* gLibDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the part of initialization that can only be
|
||||
* executed on the main thread.
|
||||
*/
|
||||
nsresult InitOSFileConstants()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (gInitialized) {
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
}
|
||||
|
||||
gInitialized = true;
|
||||
|
||||
// Initialize gLibDirectory
|
||||
nsCOMPtr<nsIFile> xpcomLib;
|
||||
nsresult rv = NS_GetSpecialDirectory("XpcomLib", getter_AddRefs(xpcomLib));
|
||||
if (NS_FAILED(rv) || !xpcomLib) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> libDir;
|
||||
rv = xpcomLib->GetParent(getter_AddRefs(libDir));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
gLibDirectory = new nsString();
|
||||
return libDir->GetPath(*gLibDirectory);
|
||||
}
|
||||
|
||||
nsresult CleanupOSFileConstants()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (!gInitialized) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
delete gLibDirectory;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Define a simple read-only property holding an integer.
|
||||
*
|
||||
|
@ -321,6 +382,8 @@ JSObject *GetOrCreateObjectProperty(JSContext *cx, JSObject *aObject,
|
|||
*/
|
||||
bool DefineOSFileConstants(JSContext *cx, JSObject *global)
|
||||
{
|
||||
MOZ_ASSERT(gInitialized);
|
||||
|
||||
JSObject *objOS;
|
||||
if (!(objOS = GetOrCreateObjectProperty(cx, global, "OS"))) {
|
||||
return false;
|
||||
|
@ -329,6 +392,9 @@ bool DefineOSFileConstants(JSContext *cx, JSObject *global)
|
|||
if (!(objConstants = GetOrCreateObjectProperty(cx, objOS, "Constants"))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Build OS.Constants.libc
|
||||
|
||||
JSObject *objLibc;
|
||||
if (!(objLibc = GetOrCreateObjectProperty(cx, objConstants, "libc"))) {
|
||||
return false;
|
||||
|
@ -336,7 +402,10 @@ bool DefineOSFileConstants(JSContext *cx, JSObject *global)
|
|||
if (!dom::DefineConstants(cx, objLibc, gLibcProperties)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
// Build OS.Constants.Win
|
||||
|
||||
JSObject *objWin;
|
||||
if (!(objWin = GetOrCreateObjectProperty(cx, objConstants, "Win"))) {
|
||||
return false;
|
||||
|
@ -345,6 +414,9 @@ bool DefineOSFileConstants(JSContext *cx, JSObject *global)
|
|||
return false;
|
||||
}
|
||||
#endif // defined(XP_WIN)
|
||||
|
||||
// Build OS.Constants.Sys
|
||||
|
||||
JSObject *objSys;
|
||||
if (!(objSys = GetOrCreateObjectProperty(cx, objConstants, "Sys"))) {
|
||||
return false;
|
||||
|
@ -353,7 +425,7 @@ bool DefineOSFileConstants(JSContext *cx, JSObject *global)
|
|||
nsCOMPtr<nsIXULRuntime> runtime = do_GetService(XULRUNTIME_SERVICE_CONTRACTID);
|
||||
if (runtime) {
|
||||
nsCAutoString os;
|
||||
nsresult rv = runtime->GetOS(os);
|
||||
DebugOnly<nsresult> rv = runtime->GetOS(os);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
JSString* strVersion = JS_NewStringCopyZ(cx, os.get());
|
||||
|
@ -367,6 +439,30 @@ bool DefineOSFileConstants(JSContext *cx, JSObject *global)
|
|||
}
|
||||
}
|
||||
|
||||
// Locate libxul
|
||||
{
|
||||
nsAutoString xulPath(*gLibDirectory);
|
||||
|
||||
xulPath.Append(PR_GetDirectorySeparator());
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
// Under MacOS X, for some reason, libxul is called simply "XUL"
|
||||
xulPath.Append(NS_LITERAL_STRING("XUL"));
|
||||
#else
|
||||
// On other platforms, libxul is a library "xul" with regular
|
||||
// library prefix/suffix
|
||||
xulPath.Append(NS_LITERAL_STRING(DLL_PREFIX));
|
||||
xulPath.Append(NS_LITERAL_STRING("xul"));
|
||||
xulPath.Append(NS_LITERAL_STRING(DLL_SUFFIX));
|
||||
#endif // defined(XP_MACOSX)
|
||||
|
||||
JSString* strPathToLibXUL = JS_NewUCStringCopyZ(cx, xulPath.get());
|
||||
jsval valXul = STRING_TO_JSVAL(strPathToLibXUL);
|
||||
if (!JS_SetProperty(cx, objSys, "libxulpath", &valXul)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,26 @@
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
/**
|
||||
* Perform initialization of this module.
|
||||
*
|
||||
* This function _must_ be called:
|
||||
* - from the main thread;
|
||||
* - only once;
|
||||
* - before any Chrome Worker is created.
|
||||
*/
|
||||
nsresult InitOSFileConstants();
|
||||
|
||||
/**
|
||||
* Perform cleanup of this module.
|
||||
*
|
||||
* This function _must_ be called:
|
||||
* - from the main thread;
|
||||
* - only once;
|
||||
* - after all Chrome Workers are dead.
|
||||
*/
|
||||
nsresult CleanupOSFileConstants();
|
||||
|
||||
/**
|
||||
* Define OS-specific constants.
|
||||
*
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include "Worker.h"
|
||||
#include "WorkerPrivate.h"
|
||||
|
||||
#include "OSFileConstants.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
|
@ -929,6 +931,11 @@ RuntimeService::Init()
|
|||
mSystemCharset);
|
||||
}
|
||||
|
||||
rv = InitOSFileConstants();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1043,6 +1050,11 @@ RuntimeService::Cleanup()
|
|||
mObserved = NS_FAILED(rv);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult rv = CleanupOSFileConstants();
|
||||
if (NS_FAILED(rv)) {
|
||||
MOZ_NOT_REACHED("Could not cleanup OSFileConstants");
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
Загрузка…
Ссылка в новой задаче