Bug 589413 - Failure to open libnss3.so when Firefox path contains UTF-8 characters. Part 2: consumers. r=bsmedberg, a=final+

This commit is contained in:
Dan Witte 2010-09-13 10:54:02 -07:00
parent d5efec9b20
commit 825c6d51ae
3 changed files with 88 additions and 0 deletions

View File

@ -58,6 +58,7 @@
#include "nsJSUtils.h"
#include "nsProxyRelease.h"
#include "nsThreadUtils.h"
#include "nsNativeCharsetUtils.h"
#include "nsDOMThreadService.h"
#include "nsDOMWorkerEvents.h"
@ -425,6 +426,29 @@ nsDOMWorkerFunctions::MakeNewWorker(JSContext* aCx,
}
#ifdef BUILD_CTYPES
static char*
UnicodeToNative(JSContext *cx, const jschar *source, size_t slen)
{
nsCAutoString native;
nsDependentString unicode(reinterpret_cast<const PRUnichar*>(source), slen);
nsresult rv = NS_CopyUnicodeToNative(unicode, native);
if (NS_FAILED(rv)) {
JS_ReportError(cx, "could not convert string to native charset");
return NULL;
}
char* result = static_cast<char*>(JS_malloc(cx, native.Length() + 1));
if (!result)
return NULL;
memcpy(result, native.get(), native.Length() + 1);
return result;
}
static JSCTypesCallbacks sCallbacks = {
UnicodeToNative
};
JSBool
nsDOMWorkerFunctions::CTypesLazyGetter(JSContext* aCx,
JSObject* aObj,
@ -447,8 +471,11 @@ nsDOMWorkerFunctions::CTypesLazyGetter(JSContext* aCx,
return JS_FALSE;
}
jsval ctypes;
return JS_DeletePropertyById(aCx, aObj, aId) &&
JS_InitCTypesClass(aCx, aObj) &&
JS_GetProperty(aCx, aObj, "ctypes", &ctypes) &&
JS_SetCTypesCallbacks(aCx, JSVAL_TO_OBJECT(ctypes), &sCallbacks) &&
JS_GetPropertyById(aCx, aObj, aId, aVp);
}
#endif

View File

@ -38,6 +38,7 @@
#include "base/basictypes.h"
#include "jscntxt.h"
#include "nsXULAppAPI.h"
#include "nsNativeCharsetUtils.h"
#include "mozilla/jetpack/JetpackChild.h"
#include "mozilla/jetpack/Handle.h"
@ -87,6 +88,31 @@ JetpackChild::sGlobalClass = {
JSCLASS_NO_OPTIONAL_MEMBERS
};
#ifdef BUILD_CTYPES
static char*
UnicodeToNative(JSContext *cx, const jschar *source, size_t slen)
{
nsCAutoString native;
nsDependentString unicode(reinterpret_cast<const PRUnichar*>(source), slen);
nsresult rv = NS_CopyUnicodeToNative(unicode, native);
if (NS_FAILED(rv)) {
JS_ReportError(cx, "could not convert string to native charset");
return NULL;
}
char* result = static_cast<char*>(JS_malloc(cx, native.Length() + 1));
if (!result)
return NULL;
memcpy(result, native.get(), native.Length() + 1);
return result;
}
static JSCTypesCallbacks sCallbacks = {
UnicodeToNative
};
#endif
bool
JetpackChild::Init(base::ProcessHandle aParentProcessHandle,
MessageLoop* aIOLoop,
@ -111,10 +137,13 @@ JetpackChild::Init(base::ProcessHandle aParentProcessHandle,
JS_SetContextPrivate(mCx, this);
JSObject* implGlobal =
JS_NewCompartmentAndGlobalObject(mCx, const_cast<JSClass*>(&sGlobalClass), NULL);
jsval ctypes;
if (!implGlobal ||
!JS_InitStandardClasses(mCx, implGlobal) ||
#ifdef BUILD_CTYPES
!JS_InitCTypesClass(mCx, implGlobal) ||
!JS_GetProperty(mCx, implGlobal, "ctypes", &ctypes) ||
!JS_SetCTypesCallbacks(mCx, JSVAL_TO_OBJECT(ctypes), &sCallbacks) ||
#endif
!JS_DefineFunctions(mCx, implGlobal,
const_cast<JSFunctionSpec*>(sImplMethods)))

View File

@ -41,16 +41,42 @@
#include "jsapi.h"
#include "mozilla/ModuleUtils.h"
#include "nsMemory.h"
#include "nsString.h"
#include "nsNativeCharsetUtils.h"
#define JSCTYPES_CONTRACTID \
"@mozilla.org/jsctypes;1"
#define JSCTYPES_CID \
{ 0xc797702, 0x1c60, 0x4051, { 0x9d, 0xd7, 0x4d, 0x74, 0x5, 0x60, 0x56, 0x42 } }
namespace mozilla {
namespace ctypes {
static char*
UnicodeToNative(JSContext *cx, const jschar *source, size_t slen)
{
nsCAutoString native;
nsDependentString unicode(reinterpret_cast<const PRUnichar*>(source), slen);
nsresult rv = NS_CopyUnicodeToNative(unicode, native);
if (NS_FAILED(rv)) {
JS_ReportError(cx, "could not convert string to native charset");
return NULL;
}
char* result = static_cast<char*>(JS_malloc(cx, native.Length() + 1));
if (!result)
return NULL;
memcpy(result, native.get(), native.Length() + 1);
return result;
}
static JSCTypesCallbacks sCallbacks = {
UnicodeToNative
};
NS_GENERIC_FACTORY_CONSTRUCTOR(Module)
NS_IMPL_ISUPPORTS1(Module, nsIXPCScriptable)
@ -92,6 +118,12 @@ InitAndSealCTypesClass(JSContext* cx, JSObject* global)
if (!JS_InitCTypesClass(cx, global))
return false;
// Set callbacks for charset conversion and such.
jsval ctypes;
if (!JS_GetProperty(cx, global, "ctypes", &ctypes) ||
!JS_SetCTypesCallbacks(cx, JSVAL_TO_OBJECT(ctypes), &sCallbacks))
return false;
// Seal up Object, Function, and Array and their prototypes. (This single
// object instance is shared amongst everyone who imports the ctypes module.)
if (!SealObjectAndPrototype(cx, global, "Object") ||