зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
b365dd613c
Коммит
6c66488de0
|
@ -330,12 +330,11 @@ XPCConvert::NativeData2JS(XPCCallContext& ccx, jsval* d, const void* s,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if(!p->IsVoid()) {
|
if(!p->IsVoid()) {
|
||||||
JSString *str =
|
jsval str = XPCStringConvert::ReadableToJSVal(cx, *p);
|
||||||
XPCStringConvert::ReadableToJSString(cx, *p);
|
|
||||||
if(!str)
|
if(!str)
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
|
|
||||||
*d = STRING_TO_JSVAL(str);
|
*d = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *d is defaulted to JSVAL_NULL so no need to set it
|
// *d is defaulted to JSVAL_NULL so no need to set it
|
||||||
|
|
|
@ -2935,8 +2935,7 @@ class XPCStringConvert
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static JSString *ReadableToJSString(JSContext *cx,
|
static jsval ReadableToJSVal(JSContext *cx, const nsAString &readable);
|
||||||
const nsAString &readable);
|
|
||||||
|
|
||||||
static XPCReadableJSStringWrapper *JSStringToReadable(XPCCallContext& ccx,
|
static XPCReadableJSStringWrapper *JSStringToReadable(XPCCallContext& ccx,
|
||||||
JSString *str);
|
JSString *str);
|
||||||
|
|
|
@ -1081,10 +1081,10 @@ xpc_qsStringToJsval(JSContext *cx, const nsAString &str, jsval *rval)
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSString *jsstr = XPCStringConvert::ReadableToJSString(cx, str);
|
jsval jsstr = XPCStringConvert::ReadableToJSVal(cx, str);
|
||||||
if(!jsstr)
|
if(!jsstr)
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
*rval = STRING_TO_JSVAL(jsstr);
|
*rval = jsstr;
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,14 +75,21 @@ XPCStringConvert::ShutdownDOMStringFinalizer()
|
||||||
|
|
||||||
// convert a readable to a JSString, copying string data
|
// convert a readable to a JSString, copying string data
|
||||||
// static
|
// static
|
||||||
JSString *
|
jsval
|
||||||
XPCStringConvert::ReadableToJSString(JSContext *cx,
|
XPCStringConvert::ReadableToJSVal(JSContext *cx,
|
||||||
const nsAString &readable)
|
const nsAString &readable)
|
||||||
{
|
{
|
||||||
JSString *str;
|
JSString *str;
|
||||||
|
|
||||||
PRUint32 length = readable.Length();
|
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);
|
nsStringBuffer *buf = nsStringBuffer::FromString(readable);
|
||||||
if (buf)
|
if (buf)
|
||||||
{
|
{
|
||||||
|
@ -93,7 +100,7 @@ XPCStringConvert::ReadableToJSString(JSContext *cx,
|
||||||
sDOMStringFinalizerIndex =
|
sDOMStringFinalizerIndex =
|
||||||
JS_AddExternalStringFinalizer(DOMStringFinalizer);
|
JS_AddExternalStringFinalizer(DOMStringFinalizer);
|
||||||
if (sDOMStringFinalizerIndex == -1)
|
if (sDOMStringFinalizerIndex == -1)
|
||||||
return NULL;
|
return JSVAL_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = JS_NewExternalString(cx,
|
str = JS_NewExternalString(cx,
|
||||||
|
@ -111,14 +118,14 @@ XPCStringConvert::ReadableToJSString(JSContext *cx,
|
||||||
(JS_malloc(cx, (length + 1) *
|
(JS_malloc(cx, (length + 1) *
|
||||||
sizeof(jschar)));
|
sizeof(jschar)));
|
||||||
if (!chars)
|
if (!chars)
|
||||||
return NULL;
|
return JSVAL_NULL;
|
||||||
|
|
||||||
if (length && !CopyUnicodeTo(readable, 0,
|
if (length && !CopyUnicodeTo(readable, 0,
|
||||||
reinterpret_cast<PRUnichar *>(chars),
|
reinterpret_cast<PRUnichar *>(chars),
|
||||||
length))
|
length))
|
||||||
{
|
{
|
||||||
JS_free(cx, chars);
|
JS_free(cx, chars);
|
||||||
return NULL;
|
return JSVAL_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
chars[length] = 0;
|
chars[length] = 0;
|
||||||
|
@ -127,7 +134,7 @@ XPCStringConvert::ReadableToJSString(JSContext *cx,
|
||||||
if (!str)
|
if (!str)
|
||||||
JS_free(cx, chars);
|
JS_free(cx, chars);
|
||||||
}
|
}
|
||||||
return str;
|
return STRING_TO_JSVAL(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -620,12 +620,12 @@ nsXPCWrappedJS::GetProperty(const nsAString & name, nsIVariant **_retval)
|
||||||
if(!ccx.IsValid())
|
if(!ccx.IsValid())
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
|
||||||
JSString* jsstr = XPCStringConvert::ReadableToJSString(ccx, name);
|
jsval jsstr = XPCStringConvert::ReadableToJSVal(ccx, name);
|
||||||
if(!jsstr)
|
if(!jsstr)
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
return nsXPCWrappedJSClass::
|
return nsXPCWrappedJSClass::
|
||||||
GetNamedPropertyAsVariant(ccx, mJSObj, STRING_TO_JSVAL(jsstr), _retval);
|
GetNamedPropertyAsVariant(ccx, mJSObj, jsstr, _retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
Загрузка…
Ссылка в новой задаче