[gjs/wip/ptomato/mozjs31prep: 2/3] WIP - Root gjs_string_from_utf8()



commit e6b212c3d3d2b74bd3ecb2a18eb223be095bdbd3
Author: Philip Chimento <philip endlessm com>
Date:   Wed Oct 12 19:40:21 2016 -0700

    WIP - Root gjs_string_from_utf8()

 gi/arg.cpp                |  152 +++++++++++++++++++++------------------------
 gi/arg.h                  |   17 +++---
 gi/foreign.cpp            |    8 +-
 gi/foreign.h              |   16 +++--
 gi/function.cpp           |    5 +-
 gi/gerror.cpp             |   16 +----
 gi/gtype.cpp              |   13 +---
 gi/interface.cpp          |    8 +-
 gi/interface.h            |    6 +-
 gi/ns.cpp                 |   13 +---
 gi/object.cpp             |    8 +-
 gi/object.h               |    8 ++-
 gi/proxyutils.cpp         |   14 ++--
 gi/proxyutils.h           |   14 ++--
 gi/value.cpp              |   46 +++++++-------
 gjs/byteArray.cpp         |   12 +---
 gjs/importer.cpp          |    3 +-
 gjs/jsapi-util-error.cpp  |    5 +-
 gjs/jsapi-util-string.cpp |   25 ++++----
 gjs/jsapi-util.h          |   18 +++---
 20 files changed, 186 insertions(+), 221 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 8a9fb47..59d808d 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -435,40 +435,32 @@ gjs_object_to_g_hash(JSContext   *context,
 }
 
 bool
-gjs_array_from_strv(JSContext   *context,
-                    JS::Value   *value_p,
-                    const char **strv)
+gjs_array_from_strv(JSContext             *context,
+                    JS::MutableHandleValue value_p,
+                    const char           **strv)
 {
     JSObject *obj;
-    JS::Value elem;
     guint i;
-    bool result = false;
 
     obj = JS_NewArrayObject(context, 0, NULL);
     if (obj == NULL)
         return false;
 
-    *value_p = JS::ObjectValue(*obj);
+    value_p.setObject(*obj);
 
-    elem = JS::UndefinedValue();
-    JS_AddValueRoot(context, &elem);
+    JS::RootedValue elem(context);
 
     for (i = 0; strv[i] != NULL; i++) {
         if (!gjs_string_from_utf8 (context, strv[i], -1, &elem))
-            goto out;
+            return false;
 
         if (!JS_DefineElement(context, obj, i, elem,
                               NULL, NULL, JSPROP_ENUMERATE)) {
-            goto out;
+            return false;
         }
     }
 
-    result = true;
-
-out:
-    JS_RemoveValueRoot(context, &elem);
-
-    return result;
+    return true;
 }
 
 bool
@@ -792,10 +784,10 @@ gjs_array_to_flat_gvalue_array(JSContext   *context,
 }
 
 static bool
-gjs_array_from_flat_gvalue_array(JSContext   *context,
-                                 gpointer     array,
-                                 unsigned int length,
-                                 JS::Value   *value)
+gjs_array_from_flat_gvalue_array(JSContext             *context,
+                                 gpointer               array,
+                                 unsigned               length,
+                                 JS::MutableHandleValue value)
 {
     GValue *values = (GValue *)array;
     unsigned int i;
@@ -812,7 +804,7 @@ gjs_array_from_flat_gvalue_array(JSContext   *context,
     if (result) {
         JSObject *jsarray;
         jsarray = JS_NewArrayObject(context, length, elems);
-        *value = JS::ObjectOrNullValue(jsarray);
+        value.setObjectOrNull(jsarray);
     }
 
     return result;
@@ -1990,12 +1982,12 @@ gjs_value_to_explicit_array (JSContext  *context,
 }
 
 static bool
-gjs_array_from_g_list (JSContext  *context,
-                       JS::Value  *value_p,
-                       GITypeTag   list_tag,
-                       GITypeInfo *param_info,
-                       GList      *list,
-                       GSList     *slist)
+gjs_array_from_g_list (JSContext             *context,
+                       JS::MutableHandleValue value_p,
+                       GITypeTag              list_tag,
+                       GITypeInfo            *param_info,
+                       GList                 *list,
+                       GSList                *slist)
 {
     JSObject *obj;
     unsigned int i;
@@ -2007,7 +1999,7 @@ gjs_array_from_g_list (JSContext  *context,
     if (obj == NULL)
         return false;
 
-    *value_p = JS::ObjectValue(*obj);
+    value_p.setObject(*obj);
 
     elem = JS::UndefinedValue();
     JS_AddValueRoot(context, &elem);
@@ -2058,11 +2050,11 @@ gjs_array_from_g_list (JSContext  *context,
 }
 
 static bool
-gjs_array_from_carray_internal (JSContext  *context,
-                                JS::Value  *value_p,
-                                GITypeInfo *param_info,
-                                guint       length,
-                                gpointer    array)
+gjs_array_from_carray_internal (JSContext             *context,
+                                JS::MutableHandleValue value_p,
+                                GITypeInfo            *param_info,
+                                guint                  length,
+                                gpointer               array)
 {
     JSObject *obj;
     JS::Value elem;
@@ -2088,7 +2080,7 @@ gjs_array_from_carray_internal (JSContext  *context,
         obj = gjs_byte_array_from_byte_array (context, &gbytearray);
         if (obj == NULL)
             return false;
-        *value_p = JS::ObjectValue(*obj);
+        value_p.setObject(*obj);
         return true;
     } 
 
@@ -2096,7 +2088,7 @@ gjs_array_from_carray_internal (JSContext  *context,
     if (obj == NULL)
         return false;
 
-    *value_p = JS::ObjectValue(*obj);
+    value_p.setObject(*obj);
 
     elem = JS::UndefinedValue();
     JS_AddValueRoot(context, &elem);
@@ -2200,10 +2192,10 @@ finally:
 }
 
 static bool
-gjs_array_from_fixed_size_array (JSContext  *context,
-                                 JS::Value  *value_p,
-                                 GITypeInfo *type_info,
-                                 gpointer    array)
+gjs_array_from_fixed_size_array (JSContext             *context,
+                                 JS::MutableHandleValue value_p,
+                                 GITypeInfo            *type_info,
+                                 gpointer               array)
 {
     gint length;
     GITypeInfo *param_info;
@@ -2242,11 +2234,11 @@ gjs_value_from_explicit_array(JSContext  *context,
 }
 
 static bool
-gjs_array_from_boxed_array (JSContext   *context,
-                            JS::Value   *value_p,
-                            GIArrayType  array_type,
-                            GITypeInfo  *param_info,
-                            GArgument   *arg)
+gjs_array_from_boxed_array (JSContext             *context,
+                            JS::MutableHandleValue value_p,
+                            GIArrayType            array_type,
+                            GITypeInfo            *param_info,
+                            GArgument             *arg)
 {
     GArray *array;
     GPtrArray *ptr_array;
@@ -2254,7 +2246,7 @@ gjs_array_from_boxed_array (JSContext   *context,
     gsize length = 0;
 
     if (arg->v_pointer == NULL) {
-        *value_p = JS::NullValue();
+        value_p.setNull();
         return true;
     }
 
@@ -2279,10 +2271,10 @@ gjs_array_from_boxed_array (JSContext   *context,
 }
 
 static bool
-gjs_array_from_zero_terminated_c_array (JSContext  *context,
-                                        JS::Value  *value_p,
-                                        GITypeInfo *param_info,
-                                        gpointer    c_array)
+gjs_array_from_zero_terminated_c_array (JSContext             *context,
+                                        JS::MutableHandleValue value_p,
+                                        GITypeInfo            *param_info,
+                                        gpointer               c_array)
 {
     JSObject *obj;
     JS::Value elem;
@@ -2305,7 +2297,7 @@ gjs_array_from_zero_terminated_c_array (JSContext  *context,
         obj = gjs_byte_array_from_byte_array (context, &gbytearray);
         if (obj == NULL)
             return false;
-        *value_p = JS::ObjectValue(*obj);
+        value_p.setObject(*obj);
         return true;
     } 
 
@@ -2313,7 +2305,7 @@ gjs_array_from_zero_terminated_c_array (JSContext  *context,
     if (obj == NULL)
         return false;
 
-    *value_p = JS::ObjectValue(*obj);
+    value_p.setObject(*obj);
 
     elem = JS::UndefinedValue();
     JS_AddValueRoot(context, &elem);
@@ -2388,11 +2380,11 @@ finally:
 
 
 static bool
-gjs_object_from_g_hash (JSContext  *context,
-                        JS::Value  *value_p,
-                        GITypeInfo *key_param_info,
-                        GITypeInfo *val_param_info,
-                        GHashTable *hash)
+gjs_object_from_g_hash (JSContext             *context,
+                        JS::MutableHandleValue value_p,
+                        GITypeInfo            *key_param_info,
+                        GITypeInfo            *val_param_info,
+                        GHashTable            *hash)
 {
     GHashTableIter iter;
     JSObject *obj;
@@ -2404,7 +2396,7 @@ gjs_object_from_g_hash (JSContext  *context,
 
     // a NULL hash table becomes a null JS value
     if (hash==NULL) {
-        *value_p = JS::NullValue();
+        value_p.setNull();
         return true;
     }
 
@@ -2412,7 +2404,7 @@ gjs_object_from_g_hash (JSContext  *context,
     if (obj == NULL)
         return false;
 
-    *value_p = JS::ObjectValue(*obj);
+    value_p.setObject(*obj);
     JS_AddObjectRoot(context, &obj);
 
     keyjs = JS::UndefinedValue();
@@ -2467,11 +2459,11 @@ gjs_object_from_g_hash (JSContext  *context,
 }
 
 bool
-gjs_value_from_g_argument (JSContext  *context,
-                           JS::Value  *value_p,
-                           GITypeInfo *type_info,
-                           GArgument  *arg,
-                           bool        copy_structs)
+gjs_value_from_g_argument (JSContext             *context,
+                           JS::MutableHandleValue value_p,
+                           GITypeInfo            *type_info,
+                           GArgument             *arg,
+                           bool                   copy_structs)
 {
     GITypeTag type_tag;
 
@@ -2481,62 +2473,62 @@ gjs_value_from_g_argument (JSContext  *context,
                       "Converting GArgument %s to JS::Value",
                       g_type_tag_to_string(type_tag));
 
-    *value_p = JS::NullValue();
+    value_p.setNull();
 
     switch (type_tag) {
     case GI_TYPE_TAG_VOID:
-        *value_p = JS::UndefinedValue(); /* or JS::NullValue() ? */
+        value_p.setUndefined(); /* or .setNull() ? */
         break;
 
     case GI_TYPE_TAG_BOOLEAN:
-        *value_p = JS::BooleanValue(!!arg->v_int);
+        value_p.setBoolean(!!arg->v_int);
         break;
 
     case GI_TYPE_TAG_INT32:
-        *value_p = JS::NumberValue(arg->v_int);
+        value_p.setInt32(arg->v_int);
         break;
 
     case GI_TYPE_TAG_UINT32:
-        *value_p = JS::NumberValue(arg->v_uint);
+        value_p.setNumber(arg->v_uint);
         break;
 
     case GI_TYPE_TAG_INT64:
-        *value_p = JS::NumberValue(arg->v_int64);
+        value_p.set(JS::NumberValue(arg->v_int64));
         break;
 
     case GI_TYPE_TAG_UINT64:
-        *value_p = JS::NumberValue(arg->v_uint64);
+        value_p.set(JS::NumberValue(arg->v_uint64));
         break;
 
     case GI_TYPE_TAG_UINT16:
-        *value_p = JS::NumberValue(arg->v_uint16);
+        value_p.setInt32(arg->v_uint16);
         break;
 
     case GI_TYPE_TAG_INT16:
-        *value_p = JS::NumberValue(arg->v_int16);
+        value_p.setInt32(arg->v_int16);
         break;
 
     case GI_TYPE_TAG_UINT8:
-        *value_p = JS::NumberValue(arg->v_uint8);
+        value_p.setInt32(arg->v_uint8);
         break;
 
     case GI_TYPE_TAG_INT8:
-        *value_p = JS::NumberValue(arg->v_int8);
+        value_p.setInt32(arg->v_int8);
         break;
 
     case GI_TYPE_TAG_FLOAT:
-        *value_p = JS::NumberValue(arg->v_float);
+        value_p.setNumber(arg->v_float);
         break;
 
     case GI_TYPE_TAG_DOUBLE:
-        *value_p = JS::NumberValue(arg->v_double);
+        value_p.setNumber(arg->v_double);
         break;
 
     case GI_TYPE_TAG_GTYPE:
         {
             JSObject *obj;
             obj = gjs_gtype_create_gtype_wrapper(context, arg->v_ssize);
-            *value_p = JS::ObjectOrNullValue(obj);
+            value_p.setObjectOrNull(obj);
         }
         break;
 
@@ -2583,7 +2575,7 @@ gjs_value_from_g_argument (JSContext  *context,
             if (arg->v_pointer) {
                 JSObject *obj = gjs_error_from_gerror(context, (GError *) arg->v_pointer, false);
                 if (obj) {
-                    *value_p = JS::ObjectValue(*obj);
+                    value_p.setObject(*obj);
                     return true;
                 }
 
@@ -2758,7 +2750,7 @@ gjs_value_from_g_argument (JSContext  *context,
             if (value.isUndefined())
                 return false;
 
-            *value_p = value;
+            value_p.set(value);
         }
         break;
 
@@ -2795,7 +2787,7 @@ gjs_value_from_g_argument (JSContext  *context,
                 gjs_throw(context, "Couldn't convert GByteArray to a ByteArray");
                 return false;
             }
-            *value_p = JS::ObjectValue(*array);
+            value_p.setObject(*array);
         } else {
             /* this assumes the array type is one of GArray, GPtrArray or
              * GByteArray */
diff --git a/gi/arg.h b/gi/arg.h
index ca6fdcf..d3a6746 100644
--- a/gi/arg.h
+++ b/gi/arg.h
@@ -67,11 +67,12 @@ bool gjs_value_to_g_argument (JSContext      *context,
                               bool            may_be_null,
                               GArgument      *arg);
 
-bool gjs_value_from_g_argument (JSContext  *context,
-                                JS::Value  *value_p,
-                                GITypeInfo *type_info,
-                                GArgument  *arg,
-                                bool        copy_structs);
+bool gjs_value_from_g_argument(JSContext             *context,
+                               JS::MutableHandleValue value_p,
+                               GITypeInfo            *type_info,
+                               GIArgument            *arg,
+                               bool                   copy_structs);
+
 bool gjs_value_from_explicit_array (JSContext  *context,
                                     JS::Value  *value_p,
                                     GITypeInfo *type_info,
@@ -108,9 +109,9 @@ bool _gjs_enum_value_is_valid (JSContext  *context,
 gint64 _gjs_enum_from_int (GIEnumInfo *enum_info,
                            int         int_value);
 
-bool gjs_array_from_strv (JSContext   *context,
-                          JS::Value   *value_p,
-                          const char **strv);
+bool gjs_array_from_strv(JSContext             *context,
+                         JS::MutableHandleValue value_p,
+                         const char           **strv);
 
 bool gjs_array_to_strv (JSContext   *context,
                         JS::Value    array_value,
diff --git a/gi/foreign.cpp b/gi/foreign.cpp
index c65431f..83fe572 100644
--- a/gi/foreign.cpp
+++ b/gi/foreign.cpp
@@ -161,10 +161,10 @@ gjs_struct_foreign_convert_to_g_argument(JSContext      *context,
 }
 
 bool
-gjs_struct_foreign_convert_from_g_argument(JSContext  *context,
-                                           JS::Value  *value_p,
-                                           GIBaseInfo *interface_info,
-                                           GArgument  *arg)
+gjs_struct_foreign_convert_from_g_argument(JSContext             *context,
+                                           JS::MutableHandleValue value_p,
+                                           GIBaseInfo            *interface_info,
+                                           GIArgument            *arg)
 {
     GjsForeignInfo *foreign;
 
diff --git a/gi/foreign.h b/gi/foreign.h
index afd3884..f7050d7 100644
--- a/gi/foreign.h
+++ b/gi/foreign.h
@@ -37,9 +37,10 @@ typedef bool (*GjsArgOverrideToGArgumentFunc) (JSContext      *context,
                                                bool            may_be_null,
                                                GArgument      *arg);
 
-typedef bool (*GjsArgOverrideFromGArgumentFunc)    (JSContext *context,
-                                                    JS::Value *value_p,
-                                                    GArgument *arg);
+typedef bool (*GjsArgOverrideFromGArgumentFunc) (JSContext             *context,
+                                                 JS::MutableHandleValue value_p,
+                                                 GIArgument            *arg);
+
 typedef bool (*GjsArgOverrideReleaseGArgumentFunc) (JSContext *context,
                                                     GITransfer transfer,
                                                     GArgument *arg);
@@ -62,10 +63,11 @@ bool  gjs_struct_foreign_convert_to_g_argument   (JSContext      *context,
                                                   GITransfer      transfer,
                                                   bool            may_be_null,
                                                   GArgument      *arg);
-bool  gjs_struct_foreign_convert_from_g_argument (JSContext      *context,
-                                                  JS::Value      *value_p,
-                                                  GIBaseInfo     *interface_info,
-                                                  GArgument      *arg);
+bool gjs_struct_foreign_convert_from_g_argument(JSContext             *context,
+                                                JS::MutableHandleValue value_p,
+                                                GIBaseInfo            *interface_info,
+                                                GIArgument            *arg);
+
 bool  gjs_struct_foreign_release_g_argument      (JSContext      *context,
                                                   GITransfer      transfer,
                                                   GIBaseInfo     *interface_info,
diff --git a/gi/function.cpp b/gi/function.cpp
index d75dd0f..2de0953 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1391,7 +1391,6 @@ function_to_string (JSContext *context,
     GJS_GET_PRIV(context, argc, vp, rec, to, Function, priv);
     gchar *string;
     bool free;
-    JS::Value retval;
     bool ret = false;
     int i, n_args, n_jsargs;
     GString *arg_names_str;
@@ -1441,10 +1440,8 @@ function_to_string (JSContext *context,
     g_free(arg_names);
 
  out:
-    if (gjs_string_from_utf8(context, string, -1, &retval)) {
-        rec.rval().set(retval);
+    if (gjs_string_from_utf8(context, string, -1, rec.rval()))
         ret = true;
-    }
 
     if (free)
         g_free(string);
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index da89c94..fb1cda5 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -163,8 +163,6 @@ error_get_message(JSContext *context,
                   JS::Value *vp)
 {
     GJS_GET_PRIV(context, argc, vp, args, obj, Error, priv);
-    JS::Value retval;
-    bool ret = false;
 
     if (priv == NULL)
         return false;
@@ -175,11 +173,7 @@ error_get_message(JSContext *context,
         return false;
     }
 
-    // FIXME: root gjs_string_from_utf8()
-    ret = gjs_string_from_utf8(context, priv->gerror->message, -1, &retval);
-    if (ret)
-        args.rval().set(retval);
-    return ret;
+    return gjs_string_from_utf8(context, priv->gerror->message, -1, args.rval());
 }
 
 static JSBool
@@ -208,14 +202,13 @@ error_to_string(JSContext *context,
                 JS::Value *vp)
 {
     GJS_GET_PRIV(context, argc, vp, rec, self, Error, priv);
-    JS::Value v_out;
     gchar *descr;
     bool retval;
 
     if (priv == NULL)
         return false;
 
-    v_out = JS::UndefinedValue();
+    rec.rval().setUndefined();
     retval = false;
 
     /* We follow the same pattern as standard JS errors, at the expense of
@@ -226,7 +219,7 @@ error_to_string(JSContext *context,
                                 g_base_info_get_namespace(priv->info),
                                 g_base_info_get_name(priv->info));
 
-        if (!gjs_string_from_utf8(context, descr, -1, &v_out))
+        if (!gjs_string_from_utf8(context, descr, -1, rec.rval()))
             goto out;
     } else {
         descr = g_strdup_printf("%s.%s: %s",
@@ -234,11 +227,10 @@ error_to_string(JSContext *context,
                                 g_base_info_get_name(priv->info),
                                 priv->gerror->message);
 
-        if (!gjs_string_from_utf8(context, descr, -1, &v_out))
+        if (!gjs_string_from_utf8(context, descr, -1, rec.rval()))
             goto out;
     }
 
-    rec.rval().set(v_out);
     retval = true;
 
  out:
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index 06d02f7..6d379c5 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -70,7 +70,6 @@ to_string_func(JSContext *context,
     GType gtype;
     gchar *strval;
     bool ret;
-    JS::Value retval;
 
     gtype = GPOINTER_TO_SIZE(priv);
 
@@ -79,9 +78,7 @@ to_string_func(JSContext *context,
     else
         strval = g_strdup_printf("[object GType for '%s']",
                                  g_type_name(gtype));
-    ret = gjs_string_from_utf8(context, strval, -1, &retval);
-    if (ret)
-        rec.rval().set(retval);
+    ret = gjs_string_from_utf8(context, strval, -1, rec.rval());
     g_free(strval);
     return ret;
 }
@@ -93,20 +90,14 @@ get_name_func (JSContext *context,
 {
     GJS_GET_PRIV(context, argc, vp, rec, obj, void, priv);
     GType gtype;
-    bool ret;
-    JS::Value retval;
 
     gtype = GPOINTER_TO_SIZE(priv);
 
     if (gtype == 0) {
         rec.rval().setNull();
         return true;
-    } else {
-        ret = gjs_string_from_utf8(context, g_type_name(gtype), -1, &retval);
-        if (ret)
-            rec.rval().set(retval);
-        return ret;
     }
+    return gjs_string_from_utf8(context, g_type_name(gtype), -1, rec.rval());
 }
 
 /* Properties */
diff --git a/gi/interface.cpp b/gi/interface.cpp
index b27a6b2..80b2ae7 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -239,9 +239,9 @@ gjs_define_interface_class(JSContext       *context,
 }
 
 bool
-gjs_lookup_interface_constructor(JSContext *context,
-                                 GType      gtype,
-                                 JS::Value *value_p)
+gjs_lookup_interface_constructor(JSContext             *context,
+                                 GType                  gtype,
+                                 JS::MutableHandleValue value_p)
 {
     JSObject *constructor;
     GIBaseInfo *interface_info;
@@ -263,6 +263,6 @@ gjs_lookup_interface_constructor(JSContext *context,
 
     g_base_info_unref(interface_info);
 
-    *value_p = JS::ObjectValue(*constructor);
+    value_p.setObject(*constructor);
     return true;
 }
diff --git a/gi/interface.h b/gi/interface.h
index 4640f8a..0dc5e56 100644
--- a/gi/interface.h
+++ b/gi/interface.h
@@ -38,9 +38,9 @@ bool gjs_define_interface_class (JSContext       *context,
                                  GType            gtype,
                                  JSObject       **constructor_p);
 
-bool gjs_lookup_interface_constructor (JSContext     *context,
-                                       GType          gtype,
-                                       JS::Value     *value_p);
+bool gjs_lookup_interface_constructor(JSContext             *context,
+                                      GType                  gtype,
+                                      JS::MutableHandleValue value_p);
 
 G_END_DECLS
 
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 70ad6a8..8cc18ef 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -132,19 +132,14 @@ get_name (JSContext *context,
           JS::Value *vp)
 {
     GJS_GET_PRIV(context, argc, vp, args, obj, Ns, priv);
-    JS::Value retval;
-    bool ret = false;
 
     if (priv == NULL)
-        goto out;
+        return false;
 
-    if (gjs_string_from_utf8(context, priv->gi_namespace, -1, &retval)) {
-        args.rval().set(retval);
-        ret = true;
-    }
+    if (!gjs_string_from_utf8(context, priv->gi_namespace, -1, args.rval()))
+        return false;
 
- out:
-    return ret;
+    return true;
 }
 
 GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT(ns)
diff --git a/gi/object.cpp b/gi/object.cpp
index c5587d1..5ef4fd1 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -3052,9 +3052,9 @@ gjs_define_private_gi_stuff(JSContext *context,
 }
 
 bool
-gjs_lookup_object_constructor(JSContext *context,
-                              GType      gtype,
-                              JS::Value *value_p)
+gjs_lookup_object_constructor(JSContext             *context,
+                              GType                  gtype,
+                              JS::MutableHandleValue value_p)
 {
     JSObject *constructor;
     GIObjectInfo *object_info;
@@ -3073,6 +3073,6 @@ gjs_lookup_object_constructor(JSContext *context,
     if (object_info)
         g_base_info_unref((GIBaseInfo*)object_info);
 
-    *value_p = JS::ObjectValue(*constructor);
+    value_p.setObject(*constructor);
     return true;
 }
diff --git a/gi/object.h b/gi/object.h
index 4eb77a5..f09d473 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -36,9 +36,11 @@ void      gjs_define_object_class       (JSContext     *context,
                                          GIObjectInfo  *info,
                                          GType          gtype,
                                          JSObject     **constructor_p);
-bool      gjs_lookup_object_constructor (JSContext     *context,
-                                         GType          gtype,
-                                         JS::Value     *value_p);
+
+bool gjs_lookup_object_constructor(JSContext             *context,
+                                   GType                  gtype,
+                                   JS::MutableHandleValue value_p);
+
 JSObject* gjs_object_from_g_object      (JSContext     *context,
                                          GObject       *gobj);
 
diff --git a/gi/proxyutils.cpp b/gi/proxyutils.cpp
index d7fe5cc..df0063a 100644
--- a/gi/proxyutils.cpp
+++ b/gi/proxyutils.cpp
@@ -32,13 +32,13 @@
  * and a memory address.
  */
 bool
-_gjs_proxy_to_string_func(JSContext  *context,
-                          JSObject   *this_obj,
-                          const char *objtype,
-                          GIBaseInfo *info,
-                          GType       gtype,
-                          gpointer    native_address,
-                          JS::Value  *rval)
+_gjs_proxy_to_string_func(JSContext             *context,
+                          JSObject              *this_obj,
+                          const char            *objtype,
+                          GIBaseInfo            *info,
+                          GType                  gtype,
+                          gpointer               native_address,
+                          JS::MutableHandleValue rval)
 {
     GString *buf;
     bool ret = false;
diff --git a/gi/proxyutils.h b/gi/proxyutils.h
index 6161f3b..20f79d9 100644
--- a/gi/proxyutils.h
+++ b/gi/proxyutils.h
@@ -29,13 +29,13 @@
 
 G_BEGIN_DECLS
 
-bool _gjs_proxy_to_string_func (JSContext  *context,
-                                JSObject   *this_obj,
-                                const char *objtype,
-                                GIBaseInfo *info,
-                                GType       gtype,
-                                gpointer    native_address,
-                                JS::Value  *ret);
+bool _gjs_proxy_to_string_func(JSContext             *context,
+                               JSObject              *this_obj,
+                               const char            *objtype,
+                               GIBaseInfo            *info,
+                               GType                  gtype,
+                               gpointer               native_address,
+                               JS::MutableHandleValue ret);
 
 G_END_DECLS
 
diff --git a/gi/value.cpp b/gi/value.cpp
index 1c5cc34..f776a14 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -777,12 +777,12 @@ convert_int_to_enum (GType  gtype,
 }
 
 static bool
-gjs_value_from_g_value_internal(JSContext    *context,
-                                JS::Value    *value_p,
-                                const GValue *gvalue,
-                                bool          no_copy,
-                                GSignalQuery *signal_query,
-                                gint          arg_n)
+gjs_value_from_g_value_internal(JSContext             *context,
+                                JS::MutableHandleValue value_p,
+                                const GValue          *gvalue,
+                                bool                   no_copy,
+                                GSignalQuery          *signal_query,
+                                int                    arg_n)
 {
     GType gtype;
 
@@ -798,7 +798,7 @@ gjs_value_from_g_value_internal(JSContext    *context,
         if (v == NULL) {
             gjs_debug_marshal(GJS_DEBUG_GCLOSURE,
                               "Converting NULL string to JS::NullValue()");
-            *value_p = JS::NullValue();
+            value_p.setNull();
         } else {
             if (!gjs_string_from_utf8(context, v, -1, value_p))
                 return false;
@@ -806,31 +806,31 @@ gjs_value_from_g_value_internal(JSContext    *context,
     } else if (gtype == G_TYPE_CHAR) {
         char v;
         v = g_value_get_schar(gvalue);
-        *value_p = JS::Int32Value(v);
+        value_p.setInt32(v);
     } else if (gtype == G_TYPE_UCHAR) {
         unsigned char v;
         v = g_value_get_uchar(gvalue);
-        *value_p = JS::Int32Value(v);
+        value_p.setInt32(v);
     } else if (gtype == G_TYPE_INT) {
         int v;
         v = g_value_get_int(gvalue);
-        *value_p = JS::NumberValue(v);
+        value_p.set(JS::NumberValue(v));
     } else if (gtype == G_TYPE_UINT) {
         guint v;
         v = g_value_get_uint(gvalue);
-        *value_p = JS::NumberValue(v);
+        value_p.set(JS::NumberValue(v));
     } else if (gtype == G_TYPE_DOUBLE) {
         double d;
         d = g_value_get_double(gvalue);
-        *value_p = JS::NumberValue(d);
+        value_p.setNumber(d);
     } else if (gtype == G_TYPE_FLOAT) {
         double d;
         d = g_value_get_float(gvalue);
-        *value_p = JS::NumberValue(d);
+        value_p.setNumber(d);
     } else if (gtype == G_TYPE_BOOLEAN) {
         bool v;
         v = g_value_get_boolean(gvalue);
-        *value_p = JS::BooleanValue(!!v);
+        value_p.setBoolean(!!v);
     } else if (g_type_is_a(gtype, G_TYPE_OBJECT) || g_type_is_a(gtype, G_TYPE_INTERFACE)) {
         GObject *gobj;
         JSObject *obj;
@@ -838,7 +838,7 @@ gjs_value_from_g_value_internal(JSContext    *context,
         gobj = (GObject*) g_value_get_object(gvalue);
 
         obj = gjs_object_from_g_object(context, gobj);
-        *value_p = JS::ObjectOrNullValue(obj);
+        value_p.setObjectOrNull(obj);
     } else if (gtype == G_TYPE_STRV) {
         if (!gjs_array_from_strv (context,
                                   value_p,
@@ -869,7 +869,7 @@ gjs_value_from_g_value_internal(JSContext    *context,
         /* special case GError */
         if (g_type_is_a(gtype, G_TYPE_ERROR)) {
             obj = gjs_error_from_gerror(context, (GError*) gboxed, false);
-            *value_p = JS::ObjectOrNullValue(obj);
+            value_p.setObjectOrNull(obj);
 
             return true;
         }
@@ -914,10 +914,10 @@ gjs_value_from_g_value_internal(JSContext    *context,
             return false;
         }
 
-        *value_p = JS::ObjectOrNullValue(obj);
+        value_p.setObjectOrNull(obj);
         g_base_info_unref(info);
     } else if (g_type_is_a(gtype, G_TYPE_ENUM)) {
-        *value_p = convert_int_to_enum(gtype, g_value_get_enum(gvalue));
+        value_p.set(convert_int_to_enum(gtype, g_value_get_enum(gvalue)));
     } else if (g_type_is_a(gtype, G_TYPE_PARAM)) {
         GParamSpec *gparam;
         JSObject *obj;
@@ -925,7 +925,7 @@ gjs_value_from_g_value_internal(JSContext    *context,
         gparam = g_value_get_param(gvalue);
 
         obj = gjs_param_from_g_param(context, gparam);
-        *value_p = JS::ObjectOrNullValue(obj);
+        value_p.setObjectOrNull(obj);
     } else if (signal_query && g_type_is_a(gtype, G_TYPE_POINTER)) {
         bool res;
         GArgument arg;
@@ -969,7 +969,7 @@ gjs_value_from_g_value_internal(JSContext    *context,
         pointer = g_value_get_pointer(gvalue);
 
         if (pointer == NULL) {
-            *value_p = JS::NullValue();
+            value_p.setNull();
         } else {
             gjs_throw(context,
                       "Can't convert non-null pointer to JS value");
@@ -981,14 +981,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);
-        *value_p = JS::NumberValue(v);
+        value_p.setNumber(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);
-        *value_p = JS::NumberValue(v);
+        value_p.set(JS::NumberValue(v));
     } else if (G_TYPE_IS_INSTANTIATABLE(gtype)) {
         /* The gtype is none of the above, it should be a custom
            fundamental type. */
@@ -997,7 +997,7 @@ gjs_value_from_g_value_internal(JSContext    *context,
         if (obj == NULL)
             return false;
         else
-            *value_p = JS::ObjectValue(*obj);
+            value_p.setObject(*obj);
     } else {
         gjs_throw(context,
                   "Don't know how to convert GType %s to JavaScript object",
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index b9955a7..2882ab9 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -444,16 +444,8 @@ to_string_func(JSContext *context,
         /* optimization, avoids iconv overhead and runs
          * libmozjs hardwired utf8-to-utf16
          */
-        JS::Value retval;
-        bool ok;
-
-        ok = gjs_string_from_utf8(context,
-                                  data,
-                                  priv->array->len,
-                                  &retval);
-        if (ok)
-            argv.rval().set(retval);
-        return ok;
+        return gjs_string_from_utf8(context, data, priv->array->len,
+                                    argv.rval());
     } else {
         bool ok = false;
         gsize bytes_written;
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index afcb1bc..05f79f8 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -790,14 +790,13 @@ importer_new_enumerate(JSContext  *context,
     }
 
     case JSENUMERATE_NEXT: {
-        JS::Value element_val;
-
         if (statep.isNull()) /* Iterating prototype */
             return true;
 
         iter = (ImporterIterator*) statep.get().toPrivate();
 
         if (iter->index < iter->elements->len) {
+            JS::RootedValue element_val(context);
             if (!gjs_string_from_utf8(context,
                                          (const char*) g_ptr_array_index(iter->elements,
                                                            iter->index++),
diff --git a/gjs/jsapi-util-error.cpp b/gjs/jsapi-util-error.cpp
index c6849a7..8888b9b 100644
--- a/gjs/jsapi-util-error.cpp
+++ b/gjs/jsapi-util-error.cpp
@@ -49,7 +49,7 @@ gjs_throw_valist(JSContext       *context,
 {
     char *s;
     bool result;
-    JS::Value v_constructor, v_message;
+    JS::Value v_constructor;
     JSObject *err_obj;
 
     s = g_strdup_vprintf(format, args);
@@ -75,6 +75,7 @@ gjs_throw_valist(JSContext       *context,
         return;
     }
 
+    JS::RootedValue v_message(context);
     result = false;
 
     if (!gjs_string_from_utf8(context, s, -1, &v_message)) {
@@ -89,7 +90,7 @@ gjs_throw_valist(JSContext       *context,
     }
 
     /* throw new Error(message) */
-    err_obj = JS_New(context, &v_constructor.toObject(), 1, &v_message);
+    err_obj = JS_New(context, &v_constructor.toObject(), 1, v_message.address());
     JS_SetPendingException(context, JS::ObjectOrNullValue(err_obj));
 
     result = true;
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index f845d15..1987ae0 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -65,14 +65,13 @@ gjs_string_to_utf8 (JSContext      *context,
 }
 
 bool
-gjs_string_from_utf8(JSContext  *context,
-                     const char *utf8_string,
-                     gssize      n_bytes,
-                     JS::Value  *value_p)
+gjs_string_from_utf8(JSContext             *context,
+                     const char            *utf8_string,
+                     ssize_t                n_bytes,
+                     JS::MutableHandleValue value_p)
 {
     jschar *u16_string;
     glong u16_string_length;
-    JSString *str;
     GError *error;
 
     /* intentionally using n_bytes even though glib api suggests n_chars; with
@@ -97,10 +96,10 @@ gjs_string_from_utf8(JSContext  *context,
     JS_BeginRequest(context);
 
     /* Avoid a copy - assumes that g_malloc == js_malloc == malloc */
-    str = JS_NewUCString(context, u16_string, u16_string_length);
-
-    if (str && value_p)
-        *value_p = JS::StringValue(str);
+    JS::RootedString str(context,
+                         JS_NewUCString(context, u16_string, u16_string_length));
+    if (str)
+        value_p.setString(str);
 
     JS_EndRequest(context);
     return str != NULL;
@@ -135,10 +134,10 @@ gjs_string_to_filename(JSContext      *context,
 }
 
 bool
-gjs_string_from_filename(JSContext  *context,
-                         const char *filename_string,
-                         gssize      n_bytes,
-                         JS::Value  *value_p)
+gjs_string_from_filename(JSContext             *context,
+                         const char            *filename_string,
+                         ssize_t                n_bytes,
+                         JS::MutableHandleValue value_p)
 {
     gsize written;
     GError *error;
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 6e7a6f2..f873b33 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -411,17 +411,19 @@ bool        gjs_delete_prop_verbose_stub     (JSContext       *context,
 JSBool      gjs_string_to_utf8               (JSContext       *context,
                                               const JS::Value  string_val,
                                               char           **utf8_string_p);
-bool        gjs_string_from_utf8             (JSContext       *context,
-                                              const char      *utf8_string,
-                                              gssize           n_bytes,
-                                              JS::Value       *value_p);
+bool gjs_string_from_utf8(JSContext             *context,
+                          const char            *utf8_string,
+                          ssize_t                n_bytes,
+                          JS::MutableHandleValue value_p);
+
 JSBool      gjs_string_to_filename           (JSContext       *context,
                                               const JS::Value  string_val,
                                               char           **filename_string_p);
-bool        gjs_string_from_filename         (JSContext       *context,
-                                              const char      *filename_string,
-                                              gssize           n_bytes,
-                                              JS::Value       *value_p);
+bool gjs_string_from_filename(JSContext             *context,
+                              const char            *filename_string,
+                              ssize_t                n_bytes,
+                              JS::MutableHandleValue value_p);
+
 bool        gjs_string_get_uint16_data       (JSContext       *context,
                                               JS::Value        value,
                                               guint16        **data_p,



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