[gjs/wip/ptomato/mozjs31prep] WIP - JS_ValueToInt32



commit 0bd06f7d4f26ee4ecb9c978b2f01c5c3e98865dd
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri Sep 30 16:59:32 2016 -0700

    WIP - JS_ValueToInt32

 NEWS         |    6 ++++++
 gi/arg.cpp   |    6 +++---
 gi/value.cpp |    6 +++---
 3 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/NEWS b/NEWS
index 330db9d..df034c6 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+NEXT
+----
+- Changed rounding of signed integers to match JavaScript standard: instead of
+  floor(x + 0.5), we now round as signum(x) * floor(abs(x)).
+  http://www.ecma-international.org/ecma-262/7.0/index.html#sec-toint32
+
 Version 1.46.0
 --------------
 
diff --git a/gi/arg.cpp b/gi/arg.cpp
index b7ea873..af3a9a7 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1173,7 +1173,7 @@ gjs_value_to_g_argument(JSContext      *context,
 
     case GI_TYPE_TAG_INT8: {
         gint32 i;
-        if (!JS_ValueToInt32(context, value, &i))
+        if (!JS::ToInt32(context, value, &i))
             wrong = true;
         if (i > G_MAXINT8 || i < G_MININT8)
             out_of_range = true;
@@ -1191,7 +1191,7 @@ gjs_value_to_g_argument(JSContext      *context,
     }
     case GI_TYPE_TAG_INT16: {
         gint32 i;
-        if (!JS_ValueToInt32(context, value, &i))
+        if (!JS::ToInt32(context, value, &i))
             wrong = true;
         if (i > G_MAXINT16 || i < G_MININT16)
             out_of_range = true;
@@ -1210,7 +1210,7 @@ gjs_value_to_g_argument(JSContext      *context,
     }
 
     case GI_TYPE_TAG_INT32:
-        if (!JS_ValueToInt32(context, value, &arg->v_int))
+        if (!JS::ToInt32(context, value, &arg->v_int))
             wrong = true;
         break;
 
diff --git a/gi/value.cpp b/gi/value.cpp
index d5c2282..46f5117 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -414,7 +414,7 @@ gjs_value_to_g_value_internal(JSContext    *context,
         }
     } else if (gtype == G_TYPE_CHAR) {
         gint32 i;
-        if (JS_ValueToInt32(context, value, &i) && i >= SCHAR_MIN && i <= SCHAR_MAX) {
+        if (JS::ToInt32(context, value, &i) && i >= SCHAR_MIN && i <= SCHAR_MAX) {
             g_value_set_schar(gvalue, (signed char)i);
         } else {
             gjs_throw(context,
@@ -434,7 +434,7 @@ gjs_value_to_g_value_internal(JSContext    *context,
         }
     } else if (gtype == G_TYPE_INT) {
         gint32 i;
-        if (JS_ValueToInt32(context, value, &i)) {
+        if (JS::ToInt32(context, value, &i)) {
             g_value_set_int(gvalue, i);
         } else {
             gjs_throw(context,
@@ -717,7 +717,7 @@ gjs_value_to_g_value_internal(JSContext    *context,
          * e.g. ClutterUnit.
          */
         gint32 i;
-        if (JS_ValueToInt32(context, value, &i)) {
+        if (JS::ToInt32(context, value, &i)) {
             GValue int_value = { 0, };
             g_value_init(&int_value, G_TYPE_INT);
             g_value_set_int(&int_value, i);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]