Bug 742893 - Part a: Make xpc_qsValueTo{Uint,Int}64 public; r=bholley

This commit is contained in:
Ms2ger 2012-04-14 15:07:31 +02:00
parent 9989b037f1
commit 7164d44025
5 changed files with 52 additions and 56 deletions

View File

@ -1324,13 +1324,13 @@ def getArgumentConversionTemplate(type, descriptor):
elif tag is IDLType.Tags.int64:
# XXXbz this may not match what WebIDL says to do in terms of reducing
# mod 2^64. Should we check?
replacements["jstype"] = "PRInt64"
replacements["converter"] = "xpc_qsValueToInt64"
replacements["jstype"] = "int64_t"
replacements["converter"] = "xpc::ValueToInt64"
elif tag is IDLType.Tags.uint64:
# XXXbz this may not match what WebIDL says to do in terms of reducing
# mod 2^64. Should we check?
replacements["jstype"] = "PRUint64"
replacements["converter"] = "xpc_qsValueToUint64"
replacements["jstype"] = "uint64_t"
replacements["converter"] = "xpc::ValueToUint64"
elif tag in [IDLType.Tags.float, IDLType.Tags.double]:
replacements["jstype"] = "double"
replacements["converter"] = "JS::ToNumber"

View File

@ -653,50 +653,6 @@ xpc_qsVariantToJsval(XPCLazyCallContext &ccx,
nsIVariant *p,
jsval *rval);
/**
* Convert a jsval to PRInt64. Return true on success.
*/
inline JSBool
xpc_qsValueToInt64(JSContext *cx,
jsval v,
PRInt64 *result)
{
if (JSVAL_IS_INT(v)) {
int32_t intval;
if (!JS_ValueToECMAInt32(cx, v, &intval))
return false;
*result = static_cast<PRInt64>(intval);
} else {
double doubleval;
if (!JS_ValueToNumber(cx, v, &doubleval))
return false;
*result = static_cast<PRInt64>(doubleval);
}
return true;
}
/**
* Convert a jsval to PRUint64. Return true on success.
*/
inline JSBool
xpc_qsValueToUint64(JSContext *cx,
jsval v,
PRUint64 *result)
{
if (JSVAL_IS_INT(v)) {
uint32_t intval;
if (!JS_ValueToECMAUint32(cx, v, &intval))
return false;
*result = static_cast<PRUint64>(intval);
} else {
double doubleval;
if (!JS_ValueToNumber(cx, v, &doubleval))
return false;
*result = static_cast<PRUint64>(doubleval);
}
return true;
}
#ifdef DEBUG
void
xpc_qsAssertContextOK(JSContext *cx);

View File

@ -127,13 +127,13 @@ argumentUnboxingTemplates = {
" return JS_FALSE;\n",
'long long':
" PRInt64 ${name};\n"
" if (!xpc_qsValueToInt64(cx, ${argVal}, &${name}))\n"
" int64_t ${name};\n"
" if (!xpc::ValueToInt64(cx, ${argVal}, &${name}))\n"
" return JS_FALSE;\n",
'unsigned long long':
" PRUint64 ${name};\n"
" if (!xpc_qsValueToUint64(cx, ${argVal}, &${name}))\n"
" uint64_t ${name};\n"
" if (!xpc::ValueToUint64(cx, ${argVal}, &${name}))\n"
" return JS_FALSE;\n",
'float':

View File

@ -456,13 +456,13 @@ argumentUnboxingTemplates = {
" return JS_FALSE;\n",
'long long':
" PRInt64 ${name};\n"
" if (!xpc_qsValueToInt64(cx, ${argVal}, &${name}))\n"
" int64_t ${name};\n"
" if (!xpc::ValueToInt64(cx, ${argVal}, &${name}))\n"
" return JS_FALSE;\n",
'unsigned long long':
" PRUint64 ${name};\n"
" if (!xpc_qsValueToUint64(cx, ${argVal}, &${name}))\n"
" uint64_t ${name};\n"
" if (!xpc::ValueToUint64(cx, ${argVal}, &${name}))\n"
" return JS_FALSE;\n",
'float':

View File

@ -260,6 +260,46 @@ ReportJSRuntimeExplicitTreeStats(const JS::RuntimeStats &rtStats,
nsIMemoryMultiReporterCallback *cb,
nsISupports *closure);
/**
* Convert a jsval to PRInt64. Return true on success.
*/
inline bool
ValueToInt64(JSContext *cx, JS::Value v, int64_t *result)
{
if (JSVAL_IS_INT(v)) {
int32_t intval;
if (!JS_ValueToECMAInt32(cx, v, &intval))
return false;
*result = static_cast<int64_t>(intval);
} else {
double doubleval;
if (!JS_ValueToNumber(cx, v, &doubleval))
return false;
*result = static_cast<int64_t>(doubleval);
}
return true;
}
/**
* Convert a jsval to uint64_t. Return true on success.
*/
inline bool
ValueToUint64(JSContext *cx, JS::Value v, uint64_t *result)
{
if (JSVAL_IS_INT(v)) {
uint32_t intval;
if (!JS_ValueToECMAUint32(cx, v, &intval))
return false;
*result = static_cast<uint64_t>(intval);
} else {
double doubleval;
if (!JS_ValueToNumber(cx, v, &doubleval))
return false;
*result = static_cast<uint64_t>(doubleval);
}
return true;
}
} // namespace xpc
namespace mozilla {