mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Fix for bug 503166 (XPCStringConvert::ReadableToJSString shouldn't allocate for empty string). r/sr=jst.
--HG-- extra : rebase_source : 76c08ffb3bced708ad8af9626b7dfcb3c3fae28f
This commit is contained in:
parent
68137e029c
commit
2f1f9cb597
@ -330,12 +330,11 @@ XPCConvert::NativeData2JS(XPCCallContext& ccx, jsval* d, const void* s,
|
||||
break;
|
||||
|
||||
if(!p->IsVoid()) {
|
||||
JSString *str =
|
||||
XPCStringConvert::ReadableToJSString(cx, *p);
|
||||
jsval str = XPCStringConvert::ReadableToJSVal(cx, *p);
|
||||
if(!str)
|
||||
return JS_FALSE;
|
||||
|
||||
*d = STRING_TO_JSVAL(str);
|
||||
*d = str;
|
||||
}
|
||||
|
||||
// *d is defaulted to JSVAL_NULL so no need to set it
|
||||
|
@ -2935,8 +2935,7 @@ class XPCStringConvert
|
||||
{
|
||||
public:
|
||||
|
||||
static JSString *ReadableToJSString(JSContext *cx,
|
||||
const nsAString &readable);
|
||||
static jsval ReadableToJSVal(JSContext *cx, const nsAString &readable);
|
||||
|
||||
static XPCReadableJSStringWrapper *JSStringToReadable(XPCCallContext& ccx,
|
||||
JSString *str);
|
||||
|
@ -1081,10 +1081,10 @@ xpc_qsStringToJsval(JSContext *cx, const nsAString &str, jsval *rval)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSString *jsstr = XPCStringConvert::ReadableToJSString(cx, str);
|
||||
jsval jsstr = XPCStringConvert::ReadableToJSVal(cx, str);
|
||||
if(!jsstr)
|
||||
return JS_FALSE;
|
||||
*rval = STRING_TO_JSVAL(jsstr);
|
||||
*rval = jsstr;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
@ -75,14 +75,21 @@ XPCStringConvert::ShutdownDOMStringFinalizer()
|
||||
|
||||
// convert a readable to a JSString, copying string data
|
||||
// static
|
||||
JSString *
|
||||
XPCStringConvert::ReadableToJSString(JSContext *cx,
|
||||
const nsAString &readable)
|
||||
jsval
|
||||
XPCStringConvert::ReadableToJSVal(JSContext *cx,
|
||||
const nsAString &readable)
|
||||
{
|
||||
JSString *str;
|
||||
|
||||
PRUint32 length = readable.Length();
|
||||
|
||||
JSAtom *atom;
|
||||
if (length == 0 && (atom = cx->runtime->atomState.emptyAtom))
|
||||
{
|
||||
NS_ASSERTION(ATOM_IS_STRING(atom), "What kind of atom is this?");
|
||||
return ATOM_KEY(atom);
|
||||
}
|
||||
|
||||
nsStringBuffer *buf = nsStringBuffer::FromString(readable);
|
||||
if (buf)
|
||||
{
|
||||
@ -93,7 +100,7 @@ XPCStringConvert::ReadableToJSString(JSContext *cx,
|
||||
sDOMStringFinalizerIndex =
|
||||
JS_AddExternalStringFinalizer(DOMStringFinalizer);
|
||||
if (sDOMStringFinalizerIndex == -1)
|
||||
return NULL;
|
||||
return JSVAL_NULL;
|
||||
}
|
||||
|
||||
str = JS_NewExternalString(cx,
|
||||
@ -111,14 +118,14 @@ XPCStringConvert::ReadableToJSString(JSContext *cx,
|
||||
(JS_malloc(cx, (length + 1) *
|
||||
sizeof(jschar)));
|
||||
if (!chars)
|
||||
return NULL;
|
||||
return JSVAL_NULL;
|
||||
|
||||
if (length && !CopyUnicodeTo(readable, 0,
|
||||
reinterpret_cast<PRUnichar *>(chars),
|
||||
length))
|
||||
{
|
||||
JS_free(cx, chars);
|
||||
return NULL;
|
||||
return JSVAL_NULL;
|
||||
}
|
||||
|
||||
chars[length] = 0;
|
||||
@ -127,7 +134,7 @@ XPCStringConvert::ReadableToJSString(JSContext *cx,
|
||||
if (!str)
|
||||
JS_free(cx, chars);
|
||||
}
|
||||
return str;
|
||||
return STRING_TO_JSVAL(str);
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -620,12 +620,12 @@ nsXPCWrappedJS::GetProperty(const nsAString & name, nsIVariant **_retval)
|
||||
if(!ccx.IsValid())
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
JSString* jsstr = XPCStringConvert::ReadableToJSString(ccx, name);
|
||||
jsval jsstr = XPCStringConvert::ReadableToJSVal(ccx, name);
|
||||
if(!jsstr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return nsXPCWrappedJSClass::
|
||||
GetNamedPropertyAsVariant(ccx, mJSObj, STRING_TO_JSVAL(jsstr), _retval);
|
||||
GetNamedPropertyAsVariant(ccx, mJSObj, jsstr, _retval);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user