Bug 742893 - Part a: Make xpc_qsValueTo{Uint,Int}64 public; r=bholley
authorMs2ger <ms2ger@gmail.com>
Sat, 14 Apr 2012 15:07:31 +0200
changeset 94988 72de47174ed6889f0bf42c40415a4f7926fdffc4
parent 94987 0c881bf654b63a9a2ea2ecb1ffb55e71e18f0bb5
child 94989 36ec415f775f78e0e9805847a29a915930305b93
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs742893
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 742893 - Part a: Make xpc_qsValueTo{Uint,Int}64 public; r=bholley
dom/bindings/Codegen.py
js/xpconnect/src/XPCQuickStubs.h
js/xpconnect/src/codegen.py
js/xpconnect/src/qsgen.py
js/xpconnect/src/xpcpublic.h
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -1319,23 +1319,23 @@ def getArgumentConversionTemplate(type, 
             replacements["intermediateCast"] = "(uint8_t)"
         elif tag is IDLType.Tags.int16:
             replacements["intermediateCast"] = "(uint16_t)"
         else:
             replacements["intermediateCast"] = ""
     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"
     else:
         raise TypeError("Unknown primitive type '%s'" % type);
 
     # We substitute the %(name)s things here.  Our caller will
     # substitute the ${name} things.
--- a/js/xpconnect/src/XPCQuickStubs.h
+++ b/js/xpconnect/src/XPCQuickStubs.h
@@ -648,60 +648,16 @@ xpc_qsXPCOMObjectToJsval(XPCLazyCallCont
 /**
  * Convert a variant to jsval. Return true on success.
  */
 JSBool
 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);
 
 inline bool
 xpc_qsSameResult(nsISupports *result1, nsISupports *result2)
 {
     return SameCOMIdentity(result1, result2);
--- a/js/xpconnect/src/codegen.py
+++ b/js/xpconnect/src/codegen.py
@@ -122,23 +122,23 @@ argumentUnboxingTemplates = {
         "        return JS_FALSE;\n",
 
     'unsigned long':
         "    uint32_t ${name};\n"
         "    if (!JS_ValueToECMAUint32(cx, ${argVal}, &${name}))\n"
         "        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':
         "    double ${name}_dbl;\n"
         "    if (!JS_ValueToNumber(cx, ${argVal}, &${name}_dbl))\n"
         "        return JS_FALSE;\n"
         "    float ${name} = (float) ${name}_dbl;\n",
 
--- a/js/xpconnect/src/qsgen.py
+++ b/js/xpconnect/src/qsgen.py
@@ -451,23 +451,23 @@ argumentUnboxingTemplates = {
         "        return JS_FALSE;\n",
 
     'unsigned long':
         "    uint32_t ${name};\n"
         "    if (!JS_ValueToECMAUint32(cx, ${argVal}, &${name}))\n"
         "        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':
         "    double ${name}_dbl;\n"
         "    if (!JS_ValueToNumber(cx, ${argVal}, &${name}_dbl))\n"
         "        return JS_FALSE;\n"
         "    float ${name} = (float) ${name}_dbl;\n",
 
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -255,16 +255,56 @@ DOM_DefineQuickStubs(JSContext *cx, JSOb
 // This reports all the stats in |rtStats| that belong in the "explicit" tree,
 // (which isn't all of them).
 nsresult
 ReportJSRuntimeExplicitTreeStats(const JS::RuntimeStats &rtStats,
                                  const nsACString &pathPrefix,
                                  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 {
 namespace dom {
 namespace binding {
 
 extern int HandlerFamily;
 inline void* ProxyFamily() { return &HandlerFamily; }