[gjs: 6/7] compat: Remove use of JS_NewNumberValue shim



commit b4ce35da621aca2ac9190b1c156baf2ebf98ac37
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Sep 18 08:57:08 2016 -0700

    compat: Remove use of JS_NewNumberValue shim
    
    This shim was not necessary as it checked for failure of a function that
    can't fail according to the SpiderMonkey documentation. Instead switch to
    the newer JS::NumberValue() API. This allows simplifying the code in a
    few places since a point is now removed where it was necessary to check
    for errors.
    
    Unfortunately we can't remove the shim itself as it's part of the libgjs
    API, but we can add a note that it's deprecated.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742249

 gi/arg.cpp                |   38 ++++++++++++++++++++++----------------
 gi/enumeration.cpp        |    4 ++--
 gi/object.cpp             |    8 +-------
 gi/value.cpp              |   24 +++++++++++-------------
 gjs/byteArray.cpp         |   15 ++++++---------
 gjs/compat.h              |    2 +-
 modules/cairo-context.cpp |   21 +++++++++------------
 7 files changed, 52 insertions(+), 60 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 20cee3d..9dd30f5 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -2498,34 +2498,44 @@ gjs_value_from_g_argument (JSContext  *context,
         break;
 
     case GI_TYPE_TAG_INT32:
-        return JS_NewNumberValue(context, arg->v_int, value_p);
+        *value_p = JS::NumberValue(arg->v_int);
+        break;
 
     case GI_TYPE_TAG_UINT32:
-        return JS_NewNumberValue(context, arg->v_uint, value_p);
+        *value_p = JS::NumberValue(arg->v_uint);
+        break;
 
     case GI_TYPE_TAG_INT64:
-        return JS_NewNumberValue(context, arg->v_int64, value_p);
+        *value_p = JS::NumberValue(arg->v_int64);
+        break;
 
     case GI_TYPE_TAG_UINT64:
-        return JS_NewNumberValue(context, arg->v_uint64, value_p);
+        *value_p = JS::NumberValue(arg->v_uint64);
+        break;
 
     case GI_TYPE_TAG_UINT16:
-        return JS_NewNumberValue(context, arg->v_uint16, value_p);
+        *value_p = JS::NumberValue(arg->v_uint16);
+        break;
 
     case GI_TYPE_TAG_INT16:
-        return JS_NewNumberValue(context, arg->v_int16, value_p);
+        *value_p = JS::NumberValue(arg->v_int16);
+        break;
 
     case GI_TYPE_TAG_UINT8:
-        return JS_NewNumberValue(context, arg->v_uint8, value_p);
+        *value_p = JS::NumberValue(arg->v_uint8);
+        break;
 
     case GI_TYPE_TAG_INT8:
-        return JS_NewNumberValue(context, arg->v_int8, value_p);
+        *value_p = JS::NumberValue(arg->v_int8);
+        break;
 
     case GI_TYPE_TAG_FLOAT:
-        return JS_NewNumberValue(context, arg->v_float, value_p);
+        *value_p = JS::NumberValue(arg->v_float);
+        break;
 
     case GI_TYPE_TAG_DOUBLE:
-        return JS_NewNumberValue(context, arg->v_double, value_p);
+        *value_p = JS::NumberValue(arg->v_double);
+        break;
 
     case GI_TYPE_TAG_GTYPE:
         {
@@ -2613,9 +2623,7 @@ gjs_value_from_g_argument (JSContext  *context,
                 gint64 value_int64 = _gjs_enum_from_int ((GIEnumInfo *)interface_info, arg->v_int);
 
                 if (_gjs_enum_value_is_valid(context, (GIEnumInfo *)interface_info, value_int64)) {
-                    JS::Value tmp;
-                    if (JS_NewNumberValue(context, value_int64, &tmp))
-                        value = tmp;
+                    value = JS::NumberValue(value_int64);
                 }
 
                 goto out;
@@ -2624,9 +2632,7 @@ gjs_value_from_g_argument (JSContext  *context,
 
                 gtype = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*)interface_info);
                 if (_gjs_flags_value_is_valid(context, gtype, value_int64)) {
-                    JS::Value tmp;
-                    if (JS_NewNumberValue(context, value_int64, &tmp))
-                        value = tmp;
+                    value = JS::NumberValue(value_int64);
                 }
 
                 goto out;
diff --git a/gi/enumeration.cpp b/gi/enumeration.cpp
index 05a0471..32e3013 100644
--- a/gi/enumeration.cpp
+++ b/gi/enumeration.cpp
@@ -91,8 +91,8 @@ gjs_define_enum_value(JSContext    *context,
               "Defining enum value %s (fixed from %s) %" G_GINT64_MODIFIER "d",
               fixed_name, value_name, value_val);
 
-    if (!JS_NewNumberValue(context, value_val, &value_js) ||
-        !JS_DefineProperty(context, in_object,
+    value_js = JS::NumberValue(value_val);
+    if (!JS_DefineProperty(context, in_object,
                            fixed_name, value_js,
                            NULL, NULL,
                            GJS_MODULE_PROP_FLAGS)) {
diff --git a/gi/object.cpp b/gi/object.cpp
index cec50a6..cfca5d3 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1572,7 +1572,6 @@ real_connect_func(JSContext *context,
     guint signal_id;
     char *signal_name;
     GQuark signal_detail;
-    JS::Value retval;
     ConnectData *connect_data;
     JSBool ret = JS_FALSE;
 
@@ -1637,12 +1636,7 @@ real_connect_func(JSContext *context,
                                         closure,
                                         after);
 
-    if (!JS_NewNumberValue(context, id, &retval)) {
-        g_signal_handler_disconnect(priv->gobj, id);
-        goto out;
-    }
-    
-    argv.rval().set(retval);
+    argv.rval().setDouble(id);
 
     ret = JS_TRUE;
  out:
diff --git a/gi/value.cpp b/gi/value.cpp
index f93a0fe..be2c2c2 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -776,11 +776,9 @@ gjs_value_to_g_value_no_copy(JSContext    *context,
     return gjs_value_to_g_value_internal(context, value, gvalue, TRUE);
 }
 
-static JSBool
-convert_int_to_enum (JSContext *context,
-                     JS::Value *value_p,
-                     GType      gtype,
-                     int        v)
+static JS::Value
+convert_int_to_enum (GType  gtype,
+                     int    v)
 {
     double v_double;
 
@@ -799,7 +797,7 @@ convert_int_to_enum (JSContext *context,
         g_base_info_unref(info);
     }
 
-    return JS_NewNumberValue(context, v_double, value_p);
+    return JS::NumberValue(v_double);
 }
 
 static JSBool
@@ -840,19 +838,19 @@ gjs_value_from_g_value_internal(JSContext    *context,
     } else if (gtype == G_TYPE_INT) {
         int v;
         v = g_value_get_int(gvalue);
-        return JS_NewNumberValue(context, v, value_p);
+        *value_p = JS::NumberValue(v);
     } else if (gtype == G_TYPE_UINT) {
         guint v;
         v = g_value_get_uint(gvalue);
-        return JS_NewNumberValue(context, v, value_p);
+        *value_p = JS::NumberValue(v);
     } else if (gtype == G_TYPE_DOUBLE) {
         double d;
         d = g_value_get_double(gvalue);
-        return JS_NewNumberValue(context, d, value_p);
+        *value_p = JS::NumberValue(d);
     } else if (gtype == G_TYPE_FLOAT) {
         double d;
         d = g_value_get_float(gvalue);
-        return JS_NewNumberValue(context, d, value_p);
+        *value_p = JS::NumberValue(d);
     } else if (gtype == G_TYPE_BOOLEAN) {
         gboolean v;
         v = g_value_get_boolean(gvalue);
@@ -943,7 +941,7 @@ gjs_value_from_g_value_internal(JSContext    *context,
         *value_p = JS::ObjectOrNullValue(obj);
         g_base_info_unref(info);
     } else if (g_type_is_a(gtype, G_TYPE_ENUM)) {
-        return convert_int_to_enum(context, value_p, gtype, g_value_get_enum(gvalue));
+        *value_p = convert_int_to_enum(gtype, g_value_get_enum(gvalue));
     } else if (g_type_is_a(gtype, G_TYPE_PARAM)) {
         GParamSpec *gparam;
         JSObject *obj;
@@ -1007,14 +1005,14 @@ gjs_value_from_g_value_internal(JSContext    *context,
         g_value_init(&double_value, G_TYPE_DOUBLE);
         g_value_transform(gvalue, &double_value);
         v = g_value_get_double(&double_value);
-        return JS_NewNumberValue(context, v, value_p);
+        *value_p = JS::NumberValue(v);
     } else if (g_value_type_transformable(gtype, G_TYPE_INT)) {
         GValue int_value = { 0, };
         int v;
         g_value_init(&int_value, G_TYPE_INT);
         g_value_transform(gvalue, &int_value);
         v = g_value_get_int(&int_value);
-        return JS_NewNumberValue(context, v, value_p);
+        *value_p = JS::NumberValue(v);
     } else if (G_TYPE_IS_INSTANTIATABLE(gtype)) {
         /* The gtype is none of the above, it should be a custom
            fundamental type. */
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index 3ebe84b..a06b11d 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -78,17 +78,13 @@ gjs_typecheck_bytearray(JSContext     *context,
     return do_base_typecheck(context, object, throw_error);
 }
 
-static JSBool
-gjs_value_from_gsize(JSContext         *context,
-                     gsize              v,
-                     JS::MutableHandleValue value_p)
+static JS::Value
+gjs_value_from_gsize(gsize v)
 {
     if (v <= (gsize) JSVAL_INT_MAX) {
-        value_p.setInt32(v);
-        return JS_TRUE;
-    } else {
-        return JS_NewNumberValue(context, v, value_p.address());
+        return JS::Int32Value(v);
     }
+    return JS::NumberValue(v);
 }
 
 static void
@@ -246,7 +242,8 @@ byte_array_length_getter(JSContext *context,
         len = priv->array->len;
     else if (priv->bytes != NULL)
         len = g_bytes_get_size (priv->bytes);
-    return gjs_value_from_gsize(context, len, value_p);
+    value_p.set(gjs_value_from_gsize(len));
+    return true;
 }
 
 static JSBool
diff --git a/gjs/compat.h b/gjs/compat.h
index b82877b..89c2415 100644
--- a/gjs/compat.h
+++ b/gjs/compat.h
@@ -59,7 +59,7 @@ G_BEGIN_DECLS
     _Pragma("GCC warning \"JS_GetGlobalObject is deprecated. Use JS_GetGlobalForObject() or 
JS_GetGlobalForScopeChain() instead.\"") \
     gjs_get_global_object(cx)
 
-static JSBool G_GNUC_UNUSED
+static JSBool G_GNUC_UNUSED G_GNUC_DEPRECATED_FOR(JS::NumberValue)
 JS_NewNumberValue(JSContext *cx,
                   double     d,
                   JS::Value *rval)
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index ca9f3c7..e3adfbd 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -90,9 +90,9 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                               \
       if (!array)                                                          \
         return JS_FALSE;                                                   \
       JS::Value r;                                                         \
-      if (!JS_NewNumberValue(context, arg1, &r)) return JS_FALSE;          \
+      r = JS::NumberValue(arg1);                                           \
       if (!JS_SetElement(context, array, 0, &r)) return JS_FALSE;          \
-      if (!JS_NewNumberValue(context, arg2, &r)) return JS_FALSE;          \
+      r = JS::NumberValue(arg2);                                           \
       if (!JS_SetElement(context, array, 1, &r)) return JS_FALSE;          \
       argv.rval().setObject(*array);                                       \
     }                                                                      \
@@ -109,9 +109,9 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                               \
       if (!array)                                                          \
         return JS_FALSE;                                                   \
       JS::Value r;                                                         \
-      if (!JS_NewNumberValue(context, arg1, &r)) return JS_FALSE;          \
+      r = JS::NumberValue(arg1);                                           \
       if (!JS_SetElement(context, array, 0, &r)) return JS_FALSE;          \
-      if (!JS_NewNumberValue(context, arg2, &r)) return JS_FALSE;          \
+      r = JS::NumberValue(arg2);                                           \
       if (!JS_SetElement(context, array, 1, &r)) return JS_FALSE;          \
       argv.rval().setObject(*array);                                       \
     }                                                                      \
@@ -128,13 +128,13 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                               \
       if (!array)                                                          \
         return JS_FALSE;                                                   \
       JS::Value r;                                                         \
-      if (!JS_NewNumberValue(context, arg1, &r)) return JS_FALSE;          \
+      r = JS::NumberValue(arg1);                                           \
       if (!JS_SetElement(context, array, 0, &r)) return JS_FALSE;          \
-      if (!JS_NewNumberValue(context, arg2, &r)) return JS_FALSE;          \
+      r = JS::NumberValue(arg2);                                           \
       if (!JS_SetElement(context, array, 1, &r)) return JS_FALSE;          \
-      if (!JS_NewNumberValue(context, arg3, &r)) return JS_FALSE;          \
+      r = JS::NumberValue(arg3);                                           \
       if (!JS_SetElement(context, array, 2, &r)) return JS_FALSE;          \
-      if (!JS_NewNumberValue(context, arg4, &r)) return JS_FALSE;          \
+      r = JS::NumberValue(arg4);                                           \
       if (!JS_SetElement(context, array, 3, &r)) return JS_FALSE;          \
       argv.rval().setObject(*array);                                       \
     }                                                                      \
@@ -143,13 +143,10 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
 #define _GJS_CAIRO_CONTEXT_DEFINE_FUNC0F(method, cfunc)                    \
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(method)                               \
     double ret;                                                            \
-    JS::Value retval;                                                      \
    _GJS_CAIRO_CONTEXT_CHECK_NO_ARGS(method)                                \
     cr = gjs_cairo_context_get_context(context, obj);                      \
     ret = cfunc(cr);                                                       \
-    if (!JS_NewNumberValue(context, ret, &retval))                         \
-        return JS_FALSE;                                                   \
-    argv.rval().set(retval);                                      \
+    argv.rval().setNumber(ret);                                            \
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END
 
 #define _GJS_CAIRO_CONTEXT_DEFINE_FUNC1(method, cfunc, fmt, t1, n1)        \


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