[gjs] xulrunner 1.9.3: Use JS_AddValueRoot if available



commit 48de8e53d4965d0a0e418a3bddd84e462f934cb1
Author: Colin Walters <walters verbum org>
Date:   Thu Sep 16 14:21:27 2010 -0400

    xulrunner 1.9.3: Use JS_AddValueRoot if available
    
    https://bugzilla.gnome.org/show_bug.cgi?id=622896

 configure.ac            |    7 +++++
 gi/arg.c                |   26 +++++++++---------
 gi/boxed.c              |    4 +-
 gi/closure.c            |    8 +++---
 gi/function.c           |    4 +-
 gi/value.c              |    4 +-
 gjs/compat.h            |   14 +++++++++
 gjs/context.c           |    4 +-
 gjs/jsapi-util-array.c  |   10 +++---
 gjs/jsapi-util-error.c  |    4 +-
 gjs/jsapi-util-string.c |    4 +-
 gjs/jsapi-util.c        |    4 +-
 modules/dbus-exports.c  |   40 ++++++++++++++--------------
 modules/dbus-values.c   |   68 +++++++++++++++++++++++-----------------------
 modules/dbus.c          |   36 ++++++++++++------------
 modules/mainloop.c      |    4 +-
 16 files changed, 131 insertions(+), 110 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 722e847..6e0b92a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -144,6 +144,13 @@ AC_CHECK_LIB([mozjs], [JS_CallTracer], :,
 AC_CHECK_LIB([mozjs], [JS_DefinePropertyById], :,
              [AC_MSG_ERROR([SpiderMonkey is too old, xulrunner 1.9.1 is required])],
              [$JS_LIBS])
+AC_CHECK_LIB([mozjs], [JS_AddValueRoot], [have_js_addvalueroot=true],
+             [have_js_addvalueroot=false],
+             [$JS_LIBS])
+if test "x$have_js_addvalueroot" = xtrue; then
+  AC_DEFINE(HAVE_JS_ADDVALUEROOT, 1,
+    [Define if using xulrunner 1.9.3 or later])
+fi
 
 ## workaround for Ubuntu Hardy bug where mozilla-js.pc gives CFLAGS
 ## -I.../stable while jsapi.h is in .../unstable
diff --git a/gi/arg.c b/gi/arg.c
index ede9650..9035731 100644
--- a/gi/arg.c
+++ b/gi/arg.c
@@ -371,7 +371,7 @@ gjs_array_from_strv(JSContext   *context,
     *value_p = OBJECT_TO_JSVAL(obj);
 
     elem = JSVAL_VOID;
-    JS_AddRoot(context, &elem);
+    JS_AddValueRoot(context, &elem);
 
     for (i = 0; strv[i] != NULL; i++) {
         if (!gjs_string_from_utf8 (context, strv[i], -1, &elem))
@@ -386,7 +386,7 @@ gjs_array_from_strv(JSContext   *context,
     result = JS_TRUE;
 
 out:
-    JS_RemoveRoot(context, &elem);
+    JS_RemoveValueRoot(context, &elem);
 
     return result;
 }
@@ -1381,7 +1381,7 @@ gjs_array_from_g_list (JSContext  *context,
     *value_p = OBJECT_TO_JSVAL(obj);
 
     elem = JSVAL_VOID;
-    JS_AddRoot(context, &elem);
+    JS_AddValueRoot(context, &elem);
 
     result = JS_FALSE;
 
@@ -1421,7 +1421,7 @@ gjs_array_from_g_list (JSContext  *context,
     result = JS_TRUE;
 
  out:
-    JS_RemoveRoot(context, &elem);
+    JS_RemoveValueRoot(context, &elem);
 
     return result;
 }
@@ -1510,7 +1510,7 @@ gjs_array_from_g_array (JSContext  *context,
     result = JS_TRUE;
 
 finally:
-    JS_RemoveRoot(context, &elem);
+    JS_RemoveValueRoot(context, &elem);
 
     return result;
 }
@@ -1541,16 +1541,16 @@ gjs_object_from_g_hash (JSContext  *context,
         return JS_FALSE;
 
     *value_p = OBJECT_TO_JSVAL(obj);
-    JS_AddRoot(context, &obj);
+    JS_AddObjectRoot(context, &obj);
 
     keyjs = JSVAL_VOID;
-    JS_AddRoot(context, &keyjs);
+    JS_AddValueRoot(context, &keyjs);
 
     valjs = JSVAL_VOID;
-    JS_AddRoot(context, &valjs);
+    JS_AddValueRoot(context, &valjs);
 
     keystr = NULL;
-    JS_AddRoot(context, &keystr);
+    JS_AddStringRoot(context, &keystr);
 
     result = JS_FALSE;
 
@@ -1584,10 +1584,10 @@ gjs_object_from_g_hash (JSContext  *context,
 
  out:
     if (keyutf8) g_free(keyutf8);
-    JS_RemoveRoot(context, &obj);
-    JS_RemoveRoot(context, &keyjs);
-    JS_RemoveRoot(context, &valjs);
-    JS_RemoveRoot(context, &keystr);
+    JS_RemoveObjectRoot(context, &obj);
+    JS_RemoveValueRoot(context, &keyjs);
+    JS_RemoveValueRoot(context, &valjs);
+    JS_RemoveStringRoot(context, &keystr);
 
     return result;
 }
diff --git a/gi/boxed.c b/gi/boxed.c
index 7c8ffbb..4fb93c7 100644
--- a/gi/boxed.c
+++ b/gi/boxed.c
@@ -642,13 +642,13 @@ get_nested_interface_object (JSContext   *context,
     /* Rooting the object here is a little paranoid; the JSObject has to be kept
      * alive anyways by our caller; so this would matter only if there was an
      * aggressive GC that moved rooted objects */
-    JS_AddRoot(context, &unthreadsafe_template_for_constructor.parent_jsval);
+    JS_AddValueRoot(context, &unthreadsafe_template_for_constructor.parent_jsval);
     unthreadsafe_template_for_constructor.parent_jsval = OBJECT_TO_JSVAL(parent_obj);
 
     obj = gjs_construct_object_dynamic(context, proto,
                                        0, NULL);
 
-    JS_RemoveRoot(context, &unthreadsafe_template_for_constructor.parent_jsval);
+    JS_RemoveValueRoot(context, &unthreadsafe_template_for_constructor.parent_jsval);
 
     if (obj != NULL) {
         *value = OBJECT_TO_JSVAL(obj);
diff --git a/gi/closure.c b/gi/closure.c
index 096574f..1ae360b 100644
--- a/gi/closure.c
+++ b/gi/closure.c
@@ -310,14 +310,14 @@ gjs_closure_invoke_simple(JSContext   *context,
 
     argc = (int)strlen(format);
     for (i = 0; i < argc; i++)
-        JS_AddRoot(context, &argv[i]);
-    JS_AddRoot(context, retval);
+        JS_AddValueRoot(context, &argv[i]);
+    JS_AddValueRoot(context, retval);
 
     gjs_closure_invoke(closure, argc, argv, retval);
 
     for (i = 0; i < argc; i++)
-        JS_RemoveRoot(context, &argv[i]);
-    JS_RemoveRoot(context, retval);
+        JS_RemoveValueRoot(context, &argv[i]);
+    JS_RemoveValueRoot(context, retval);
 
     JS_PopArguments(context, stack_space);
 
diff --git a/gi/function.c b/gi/function.c
index 7985b12..2b908e3 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -128,7 +128,7 @@ function_new_resolve(JSContext *context,
 static void
 gjs_callback_trampoline_free(GjsCallbackTrampoline *trampoline)
 {
-    JS_RemoveRoot(trampoline->context, &trampoline->js_function);
+    JS_RemoveValueRoot(trampoline->context, &trampoline->js_function);
     g_callable_info_free_closure(trampoline->info, trampoline->closure);
     g_base_info_unref( (GIBaseInfo*) trampoline->info);
     g_slice_free(GjsCallbackTrampoline, trampoline);
@@ -272,7 +272,7 @@ gjs_callback_trampoline_new(JSContext      *context,
     trampoline->info = callable_info;
     g_base_info_ref((GIBaseInfo*)trampoline->info);
     trampoline->js_function = function;
-    JS_AddRoot(context, &trampoline->js_function);
+    JS_AddValueRoot(context, &trampoline->js_function);
     trampoline->closure = g_callable_info_prepare_closure(callable_info, &trampoline->cif,
                                                           gjs_callback_closure, trampoline);
 
diff --git a/gi/value.c b/gi/value.c
index 2abc2cd..39285c4 100644
--- a/gi/value.c
+++ b/gi/value.c
@@ -79,7 +79,7 @@ closure_marshal(GClosure        *closure,
 
     gjs_set_values(context, argv, argc, JSVAL_VOID);
     gjs_root_value_locations(context, argv, argc);
-    JS_AddRoot(context, &rval);
+    JS_AddValueRoot(context, &rval);
 
     if (marshal_data) {
         /* we are used for a signal handler */
@@ -139,7 +139,7 @@ closure_marshal(GClosure        *closure,
 
  cleanup:
     gjs_unroot_value_locations(context, argv, argc);
-    JS_RemoveRoot(context, &rval);
+    JS_RemoveValueRoot(context, &rval);
     JS_EndRequest(context);
 }
 
diff --git a/gjs/compat.h b/gjs/compat.h
index 4ac8f74..6e22626 100644
--- a/gjs/compat.h
+++ b/gjs/compat.h
@@ -28,6 +28,8 @@
 
 G_BEGIN_DECLS
 
+#include "config.h"
+
 #if !GLIB_CHECK_VERSION(2, 18, 0)
 
 #define g_set_error_literal(error, domain, code, message) g_set_error(error, domain, code, "%s", message)
@@ -35,6 +37,18 @@ G_BEGIN_DECLS
 
 #endif
 
+/* See https://bugzilla.gnome.org/show_bug.cgi?id=622896 */
+#ifndef HAVE_JS_ADDVALUEROOT
+#define JS_AddValueRoot JS_AddRoot
+#define JS_AddObjectRoot JS_AddRoot
+#define JS_AddStringRoot JS_AddRoot
+#define JS_AddGCThingRoot JS_AddRoot
+#define JS_RemoveValueRoot JS_RemoveRoot
+#define JS_RemoveObjectRoot JS_RemoveRoot
+#define JS_RemoveStringRoot JS_RemoveRoot
+#define JS_RemoveGCThingRoot JS_RemoveRoot
+#endif
+
 G_END_DECLS
 
 #endif  /* __GJS_MEM_H__ */
diff --git a/gjs/context.c b/gjs/context.c
index d42b030..8a9a4a4 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -353,7 +353,7 @@ gjs_context_dispose(GObject *object)
 
     if (js_context->global != NULL) {
         JS_BeginRequest(js_context->context);
-        JS_RemoveRoot(js_context->context, &js_context->global);
+        JS_RemoveObjectRoot(js_context->context, &js_context->global);
         JS_EndRequest(js_context->context);
         js_context->global = NULL;
     }
@@ -621,7 +621,7 @@ gjs_context_constructor (GType                  type,
      * context already roots it presumably? Could not find where it
      * does in a quick glance through spidermonkey source though.
      */
-    if (!JS_AddRoot(js_context->context, &js_context->global))
+    if (!JS_AddObjectRoot(js_context->context, &js_context->global))
         gjs_fatal("No memory to add global object as GC root");
 
     /* Define a global function called log() */
diff --git a/gjs/jsapi-util-array.c b/gjs/jsapi-util-array.c
index 2cef802..568971d 100644
--- a/gjs/jsapi-util-array.c
+++ b/gjs/jsapi-util-array.c
@@ -61,7 +61,7 @@ add_root_jsval(JSContext *context,
                jsval     *value_p)
 {
     JS_BeginRequest(context);
-    JS_AddRoot(context, value_p);
+    JS_AddValueRoot(context, value_p);
     JS_EndRequest(context);
 }
 
@@ -71,7 +71,7 @@ remove_root_jsval(JSContext *context,
                   jsval     *value_p)
 {
     JS_BeginRequest(context);
-    JS_RemoveRoot(context, value_p);
+    JS_RemoveValueRoot(context, value_p);
     JS_EndRequest(context);
 }
 
@@ -81,7 +81,7 @@ remove_root_jsval(JSContext *context,
  * @array: a #GjsRootedArray created by gjs_rooted_array_new()
  * @value: a jsval
  *
- * Appends @jsval to @array, calling JS_AddRoot on the location where it's stored.
+ * Appends @jsval to @array, calling JS_AddValueRoot on the location where it's stored.
  *
  **/
 void
@@ -181,7 +181,7 @@ gjs_rooted_array_get_length (JSContext        *context,
  * @locations: contiguous locations in memory that store jsvals (must be initialized)
  * @n_locations: the number of locations to root
  *
- * Calls JS_AddRoot() on each address in @locations.
+ * Calls JS_AddValueRoot() on each address in @locations.
  *
  **/
 void
@@ -208,7 +208,7 @@ gjs_root_value_locations(JSContext        *context,
  * @locations: contiguous locations in memory that store jsvals and have been added as GC roots
  * @n_locations: the number of locations to unroot
  *
- * Calls JS_RemoveRoot() on each address in @locations.
+ * Calls JS_RemoveValueRoot() on each address in @locations.
  *
  **/
 void
diff --git a/gjs/jsapi-util-error.c b/gjs/jsapi-util-error.c
index 7d89b07..7a4c0b6 100644
--- a/gjs/jsapi-util-error.c
+++ b/gjs/jsapi-util-error.c
@@ -234,7 +234,7 @@ gjstest_test_func_gjs_jsapi_util_error_throw(void)
 
     /* keep this around before we clear it */
     previous = exc;
-    JS_AddRoot(context, &previous);
+    JS_AddValueRoot(context, &previous);
 
     JS_ClearPendingException(context);
 
@@ -254,7 +254,7 @@ gjstest_test_func_gjs_jsapi_util_error_throw(void)
     g_assert(exc != JSVAL_VOID);
     g_assert(exc == previous);
 
-    JS_RemoveRoot(context, &previous);
+    JS_RemoveValueRoot(context, &previous);
 
     _gjs_unit_test_fixture_finish(&fixture);
 }
diff --git a/gjs/jsapi-util-string.c b/gjs/jsapi-util-string.c
index 729ac9c..e7caae0 100644
--- a/gjs/jsapi-util-string.c
+++ b/gjs/jsapi-util-string.c
@@ -512,7 +512,7 @@ gjstest_test_func_gjs_jsapi_util_string_get_binary(void)
     context = fixture.context;
 
     js_string = JSVAL_VOID;
-    JS_AddRoot(context, &js_string);
+    JS_AddValueRoot(context, &js_string);
 
     /* Even-length string (maps nicely to len/2 jschar) */
     if (!gjs_string_from_binary_data(context,
@@ -543,7 +543,7 @@ gjstest_test_func_gjs_jsapi_util_string_get_binary(void)
     g_assert(memcmp(data, binary_string_odd, len) == 0);
     g_free(data);
 
-    JS_RemoveRoot(context, &js_string);
+    JS_RemoveValueRoot(context, &js_string);
 
     void_value = JSVAL_VOID;
     g_assert(!JS_IsExceptionPending(context));
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index 3ee95ab..aea99cb 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -850,7 +850,7 @@ log_and_maybe_keep_exception(JSContext  *context,
     if (message_p)
         *message_p = NULL;
 
-    JS_AddRoot(context, &exc);
+    JS_AddValueRoot(context, &exc);
     if (!JS_GetPendingException(context, &exc))
         goto out;
 
@@ -891,7 +891,7 @@ log_and_maybe_keep_exception(JSContext  *context,
     retval = JS_TRUE;
 
  out:
-    JS_RemoveRoot(context, &exc);
+    JS_RemoveValueRoot(context, &exc);
 
     JS_EndRequest(context);
 
diff --git a/modules/dbus-exports.c b/modules/dbus-exports.c
index 0503401..2938d73 100644
--- a/modules/dbus-exports.c
+++ b/modules/dbus-exports.c
@@ -322,7 +322,7 @@ invoke_js_from_dbus(JSContext   *context,
     argv = gjs_rooted_array_get_data(context, values);
 
     rval = JSVAL_VOID;
-    JS_AddRoot(context, &rval);
+    JS_AddValueRoot(context, &rval);
 
     gjs_js_push_current_message(method_call);
     if (!gjs_call_function_value(context,
@@ -335,7 +335,7 @@ invoke_js_from_dbus(JSContext   *context,
         gjs_debug(GJS_DEBUG_DBUS,
                   "dbus method invocation failed");
 
-        JS_RemoveRoot(context, &rval);
+        JS_RemoveValueRoot(context, &rval);
 
         if (!dbus_reply_from_exception(context, method_call, &reply))
             gjs_debug(GJS_DEBUG_DBUS,
@@ -368,7 +368,7 @@ invoke_js_from_dbus(JSContext   *context,
 
  out:
     gjs_rooted_array_free(context, values, TRUE);
-    JS_RemoveRoot(context, &rval);
+    JS_RemoveValueRoot(context, &rval);
 
     gjs_js_pop_current_message();
 
@@ -1057,12 +1057,12 @@ handle_get_property(JSContext      *context,
     }
 
     value = JSVAL_VOID;
-    JS_AddRoot(context, &value);
+    JS_AddValueRoot(context, &value);
     if (!gjs_object_require_property(context, obj,
                                      "DBus GetProperty callee",
                                      prop_name, &value)) {
 
-        JS_RemoveRoot(context, &value);
+        JS_RemoveValueRoot(context, &value);
         property_details_clear(&details);
 
         dbus_reply_from_exception(context, message,
@@ -1085,7 +1085,7 @@ handle_get_property(JSContext      *context,
                                   &variant_iter, &sig_iter)) {
 
         property_details_clear(&details);
-        JS_RemoveRoot(context, &value);
+        JS_RemoveValueRoot(context, &value);
 
         dbus_message_unref(reply);
         reply = NULL;
@@ -1097,7 +1097,7 @@ handle_get_property(JSContext      *context,
 
     dbus_message_iter_close_container(&iter, &variant_iter);
 
-    JS_RemoveRoot(context, &value);
+    JS_RemoveValueRoot(context, &value);
 
     property_details_clear(&details);
 
@@ -1176,13 +1176,13 @@ handle_get_all_properties(JSContext      *context,
             }
 
             value = JSVAL_VOID;
-            JS_AddRoot(context, &value);
+            JS_AddValueRoot(context, &value);
             if (!gjs_object_require_property(context, obj,
                                              "DBus GetAllProperties callee",
                                              details.name, &value)) {
 
                 property_details_clear(&details);
-                JS_RemoveRoot(context, &value);
+                JS_RemoveValueRoot(context, &value);
 
                 goto js_exception;
             }
@@ -1203,13 +1203,13 @@ handle_get_all_properties(JSContext      *context,
 #ifdef HAVE_DBUS_MESSAGE_ITER_ABANDON_CONTAINER
                 dbus_message_iter_abandon_container(&entry_iter, &entry_value_iter);
 #endif
-                JS_RemoveRoot(context, &value);
+                JS_RemoveValueRoot(context, &value);
                 property_details_clear(&details);
                 goto js_exception;
             }
             dbus_message_iter_close_container(&entry_iter, &entry_value_iter);
 
-            JS_RemoveRoot(context, &value);
+            JS_RemoveValueRoot(context, &value);
 
             dbus_message_iter_close_container(&dict_iter, &entry_iter);
             property_details_clear(&details);
@@ -1311,18 +1311,18 @@ handle_set_property(JSContext      *context,
     property_details_clear(&details);
 
     value = JSVAL_VOID;
-    JS_AddRoot(context, &value);
+    JS_AddValueRoot(context, &value);
     gjs_js_one_value_from_dbus(context, &iter, &value);
 
     if (dbus_reply_from_exception(context, message, &reply)) {
-        JS_RemoveRoot(context, &value);
+        JS_RemoveValueRoot(context, &value);
         return reply;
     }
 
     /* this throws on oom or if prop is read-only for example */
     JS_SetProperty(context, obj, prop_name, &value);
 
-    JS_RemoveRoot(context, &value);
+    JS_RemoveValueRoot(context, &value);
 
     if (!dbus_reply_from_exception(context, message, &reply)) {
         g_assert(reply == NULL);
@@ -1404,8 +1404,8 @@ handle_introspect(JSContext      *context,
                                children[i]);
     }
 
-    JS_AddRoot(context, &props_iter);
-    JS_AddRoot(context, &key_str);
+    JS_AddObjectRoot(context, &props_iter);
+    JS_AddStringRoot(context, &key_str);
     props_iter = JS_NewPropertyIterator(context, dir_obj);
 
     prop_id = JSVAL_VOID;
@@ -1494,8 +1494,8 @@ handle_introspect(JSContext      *context,
     dbus_connection_send(connection, reply, NULL);
 
  out:
-    JS_RemoveRoot(context, &key_str);
-    JS_RemoveRoot(context, &props_iter);
+    JS_RemoveStringRoot(context, &key_str);
+    JS_RemoveObjectRoot(context, &props_iter);
 
     if (reply != NULL)
         dbus_message_unref(reply);
@@ -1532,7 +1532,7 @@ on_message(DBusConnection *connection,
 
     JS_BeginRequest(priv->context);
     method_value = JSVAL_VOID;
-    JS_AddRoot(priv->context, &method_value);
+    JS_AddValueRoot(priv->context, &method_value);
 
     result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
@@ -1639,7 +1639,7 @@ on_message(DBusConnection *connection,
  out:
     if (async_method_name)
         g_free(async_method_name);
-    JS_RemoveRoot(priv->context, &method_value);
+    JS_RemoveValueRoot(priv->context, &method_value);
     JS_EndRequest(priv->context);
     return result;
 }
diff --git a/modules/dbus-values.c b/modules/dbus-values.c
index 45e3303..31f6424 100644
--- a/modules/dbus-values.c
+++ b/modules/dbus-values.c
@@ -62,20 +62,20 @@ gjs_js_one_value_from_dbus(JSContext       *context,
                 jsval prop_value;
 
                 prop_value = JSVAL_VOID;
-                JS_AddRoot(context, &prop_value);
+                JS_AddValueRoot(context, &prop_value);
                 if (!gjs_js_one_value_from_dbus(context, &struct_iter, &prop_value)) {
-                    JS_RemoveRoot(context, &prop_value);
+                    JS_RemoveValueRoot(context, &prop_value);
                     return JS_FALSE;
                 }
 
                 if (!JS_DefineElement(context, obj,
                                       index, prop_value,
                                       NULL, NULL, JSPROP_ENUMERATE)) {
-                    JS_RemoveRoot(context, &prop_value);
+                    JS_RemoveValueRoot(context, &prop_value);
                     return JS_FALSE;
                 }
 
-                JS_RemoveRoot(context, &prop_value);
+                JS_RemoveValueRoot(context, &prop_value);
                 dbus_message_iter_next(&struct_iter);
                 index ++;
             }
@@ -95,7 +95,7 @@ gjs_js_one_value_from_dbus(JSContext       *context,
                 if (obj == NULL)
                     return JS_FALSE;
 
-                JS_AddRoot(context, &obj);
+                JS_AddObjectRoot(context, &obj);
                 dbus_message_iter_recurse(iter, &array_iter);
                 while (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID) {
                     DBusMessageIter entry_iter;
@@ -107,20 +107,20 @@ gjs_js_one_value_from_dbus(JSContext       *context,
 
                     if (!dbus_type_is_basic(dbus_message_iter_get_arg_type(&entry_iter))) {
                         gjs_throw(context, "Dictionary keys are not a basic type, can't convert to JavaScript");
-                        JS_RemoveRoot(context, &obj);
+                        JS_RemoveObjectRoot(context, &obj);
                         return JS_FALSE;
                     }
 
                     entry_value = JSVAL_VOID;
-                    JS_AddRoot(context, &entry_value);
+                    JS_AddValueRoot(context, &entry_value);
                     if (!gjs_js_one_value_from_dbus(context, &entry_iter, &key_value)) {
-                        JS_RemoveRoot(context, &key_value);
-                        JS_RemoveRoot(context, &obj);
+                        JS_RemoveValueRoot(context, &key_value);
+                        JS_RemoveObjectRoot(context, &obj);
                         return JS_FALSE;
                     }
 
                     key_str = JS_ValueToString(context, key_value);
-                    JS_AddRoot(context, &key_str);
+                    JS_AddStringRoot(context, &key_str);
                     key = JS_GetStringBytes(key_str);
 
                     dbus_message_iter_next(&entry_iter);
@@ -128,33 +128,33 @@ gjs_js_one_value_from_dbus(JSContext       *context,
                     gjs_debug_dbus_marshal("Defining dict entry %s in jsval dict", key);
 
                     entry_value = JSVAL_VOID;
-                    JS_AddRoot(context, &entry_value);
+                    JS_AddValueRoot(context, &entry_value);
                     if (!gjs_js_one_value_from_dbus(context, &entry_iter, &entry_value)) {
-                        JS_RemoveRoot(context, &key_value);
-                        JS_RemoveRoot(context, &key_str);
-                        JS_RemoveRoot(context, &entry_value);
-                        JS_RemoveRoot(context, &obj);
+                        JS_RemoveValueRoot(context, &key_value);
+                        JS_RemoveStringRoot(context, &key_str);
+                        JS_RemoveValueRoot(context, &entry_value);
+                        JS_RemoveObjectRoot(context, &obj);
                         return JS_FALSE;
                     }
 
                     if (!JS_DefineProperty(context, obj,
                                            key, entry_value,
                                            NULL, NULL, JSPROP_ENUMERATE)) {
-                        JS_RemoveRoot(context, &key_value);
-                        JS_RemoveRoot(context, &key_str);
-                        JS_RemoveRoot(context, &entry_value);
-                        JS_RemoveRoot(context, &obj);
+                        JS_RemoveValueRoot(context, &key_value);
+                        JS_RemoveStringRoot(context, &key_str);
+                        JS_RemoveValueRoot(context, &entry_value);
+                        JS_RemoveObjectRoot(context, &obj);
                         return JS_FALSE;
                     }
 
-                    JS_RemoveRoot(context, &key_value);
-                    JS_RemoveRoot(context, &key_str);
-                    JS_RemoveRoot(context, &entry_value);
+                    JS_RemoveValueRoot(context, &key_value);
+                    JS_RemoveStringRoot(context, &key_str);
+                    JS_RemoveValueRoot(context, &entry_value);
                     dbus_message_iter_next(&array_iter);
                 }
 
                 *value_p = OBJECT_TO_JSVAL(obj);
-                JS_RemoveRoot(context, &obj);
+                JS_RemoveObjectRoot(context, &obj);
             } else if (elem_type == DBUS_TYPE_BYTE) {
                 /* byte arrays go to a string */
                 const char *v_BYTES;
@@ -176,34 +176,34 @@ gjs_js_one_value_from_dbus(JSContext       *context,
                 if (obj == NULL)
                     return JS_FALSE;
 
-                JS_AddRoot(context, &obj);
+                JS_AddObjectRoot(context, &obj);
                 dbus_message_iter_recurse(iter, &array_iter);
                 index = 0;
                 while (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID) {
                     jsval prop_value;
 
                     prop_value = JSVAL_VOID;
-                    JS_AddRoot(context, &prop_value);
+                    JS_AddValueRoot(context, &prop_value);
                     if (!gjs_js_one_value_from_dbus(context, &array_iter, &prop_value)) {
-                        JS_RemoveRoot(context, &prop_value);
-                        JS_RemoveRoot(context, &obj);
+                        JS_RemoveValueRoot(context, &prop_value);
+                        JS_RemoveObjectRoot(context, &obj);
                         return JS_FALSE;
                     }
 
                     if (!JS_DefineElement(context, obj,
                                           index, prop_value,
                                           NULL, NULL, JSPROP_ENUMERATE)) {
-                        JS_RemoveRoot(context, &prop_value);
-                        JS_RemoveRoot(context, &obj);
+                        JS_RemoveValueRoot(context, &prop_value);
+                        JS_RemoveObjectRoot(context, &obj);
                         return JS_FALSE;
                     }
 
-                    JS_RemoveRoot(context, &prop_value);
+                    JS_RemoveValueRoot(context, &prop_value);
                     dbus_message_iter_next(&array_iter);
                     index ++;
                 }
                 *value_p = OBJECT_TO_JSVAL(obj);
-                JS_RemoveRoot(context, &obj);
+                JS_RemoveObjectRoot(context, &obj);
             }
         }
         break;
@@ -309,7 +309,7 @@ gjs_js_values_from_dbus(JSContext          *context,
     jsval value;
 
     value = JSVAL_VOID;
-    JS_AddRoot(context, &value);
+    JS_AddValueRoot(context, &value);
 
     *array_p = NULL;
 
@@ -319,7 +319,7 @@ gjs_js_values_from_dbus(JSContext          *context,
         do {
             if (!gjs_js_one_value_from_dbus(context, iter, &value)) {
                 gjs_rooted_array_free(context, array, TRUE);
-                JS_RemoveRoot(context, &value);
+                JS_RemoveValueRoot(context, &value);
                 return JS_FALSE; /* error message already set */
             }
 
@@ -329,7 +329,7 @@ gjs_js_values_from_dbus(JSContext          *context,
 
     *array_p = array;
 
-    JS_RemoveRoot(context, &value);
+    JS_RemoveValueRoot(context, &value);
 
     return JS_TRUE;
 }
diff --git a/modules/dbus.c b/modules/dbus.c
index 652c0d9..d717834 100644
--- a/modules/dbus.c
+++ b/modules/dbus.c
@@ -1019,16 +1019,16 @@ on_name_acquired(DBusConnection *connection,
     argc = 1;
 
     argv[0] = STRING_TO_JSVAL(JS_NewStringCopyZ(context, name));
-    JS_AddRoot(context, &argv[0]);
+    JS_AddValueRoot(context, &argv[0]);
 
     rval = JSVAL_VOID;
-    JS_AddRoot(context, &rval);
+    JS_AddValueRoot(context, &rval);
 
     gjs_closure_invoke(owner->acquired_closure,
                        argc, argv, &rval);
 
-    JS_RemoveRoot(context, &argv[0]);
-    JS_RemoveRoot(context, &rval);
+    JS_RemoveValueRoot(context, &argv[0]);
+    JS_RemoveValueRoot(context, &rval);
 
     JS_EndRequest(context);
 }
@@ -1058,16 +1058,16 @@ on_name_lost(DBusConnection *connection,
     argc = 1;
 
     argv[0] = STRING_TO_JSVAL(JS_NewStringCopyZ(context, name));
-    JS_AddRoot(context, &argv[0]);
+    JS_AddValueRoot(context, &argv[0]);
 
     rval = JSVAL_VOID;
-    JS_AddRoot(context, &rval);
+    JS_AddValueRoot(context, &rval);
 
     gjs_closure_invoke(owner->lost_closure,
                           argc, argv, &rval);
 
-    JS_RemoveRoot(context, &argv[0]);
-    JS_RemoveRoot(context, &rval);
+    JS_RemoveValueRoot(context, &argv[0]);
+    JS_RemoveValueRoot(context, &rval);
 
     JS_EndRequest(context);
 }
@@ -1245,12 +1245,12 @@ on_name_appeared(DBusConnection *connection,
     argv[1] = STRING_TO_JSVAL(JS_NewStringCopyZ(context, owner_unique_name));
 
     rval = JSVAL_VOID;
-    JS_AddRoot(context, &rval);
+    JS_AddValueRoot(context, &rval);
 
     gjs_closure_invoke(watcher->appeared_closure,
                           argc, argv, &rval);
 
-    JS_RemoveRoot(context, &rval);
+    JS_RemoveValueRoot(context, &rval);
     gjs_unroot_value_locations(context, argv, argc);
 
     JS_EndRequest(context);
@@ -1288,12 +1288,12 @@ on_name_vanished(DBusConnection *connection,
     argv[1] = STRING_TO_JSVAL(JS_NewStringCopyZ(context, owner_unique_name));
 
     rval = JSVAL_VOID;
-    JS_AddRoot(context, &rval);
+    JS_AddValueRoot(context, &rval);
 
     gjs_closure_invoke(watcher->vanished_closure,
                           argc, argv, &rval);
 
-    JS_RemoveRoot(context, &rval);
+    JS_RemoveValueRoot(context, &rval);
     gjs_unroot_value_locations(context, argv, argc);
 
     JS_EndRequest(context);
@@ -1574,7 +1574,7 @@ gjs_js_dbus_get_current_message_context(JSContext  *context,
         return JS_FALSE;
 
     context_val = OBJECT_TO_JSVAL(context_obj);
-    JS_AddRoot(context, &context_val);
+    JS_AddValueRoot(context, &context_val);
 
     sender = dbus_message_get_sender(current_message);
     if (sender)
@@ -1599,7 +1599,7 @@ gjs_js_dbus_get_current_message_context(JSContext  *context,
     *retval = context_val;
 
 out:
-    JS_RemoveRoot(context, &context_val);
+    JS_RemoveValueRoot(context, &context_val);
     return result;
 }
 
@@ -1616,7 +1616,7 @@ define_bus_proto(JSContext *context,
     result = JS_FALSE;
 
     bus_proto_val = JSVAL_VOID;
-    JS_AddRoot(context, &bus_proto_val);
+    JS_AddValueRoot(context, &bus_proto_val);
 
     bus_proto_obj = JS_ConstructObject(context, NULL, NULL, NULL);
     if (bus_proto_obj == NULL)
@@ -1710,7 +1710,7 @@ define_bus_proto(JSContext *context,
     result = JS_TRUE;
 
  out:
-    JS_RemoveRoot(context, &bus_proto_val);
+    JS_RemoveValueRoot(context, &bus_proto_val);
 
     return result;
 }
@@ -1735,7 +1735,7 @@ define_bus_object(JSContext  *context,
     result = JS_FALSE;
 
     bus_val = JSVAL_VOID;
-    JS_AddRoot(context, &bus_val);
+    JS_AddValueRoot(context, &bus_val);
 
     bus_obj = JS_ConstructObject(context, NULL, proto_obj, NULL);
     if (bus_obj == NULL)
@@ -1771,7 +1771,7 @@ define_bus_object(JSContext  *context,
     result = JS_TRUE;
 
  out:
-    JS_RemoveRoot(context, &bus_val);
+    JS_RemoveValueRoot(context, &bus_val);
 
     return result;
 }
diff --git a/modules/mainloop.c b/modules/mainloop.c
index d0df03f..0dde3d5 100644
--- a/modules/mainloop.c
+++ b/modules/mainloop.c
@@ -127,7 +127,7 @@ closure_source_func(void *data)
     JS_BeginRequest(context);
 
     retval = JSVAL_VOID;
-    JS_AddRoot(context, &retval);
+    JS_AddValueRoot(context, &retval);
 
     gjs_closure_invoke(closure,
                           0, NULL,
@@ -141,7 +141,7 @@ closure_source_func(void *data)
                            retval, &bool_val))
         bool_val = FALSE;
 
-    JS_RemoveRoot(context, &retval);
+    JS_RemoveValueRoot(context, &retval);
 
     JS_EndRequest(context);
     return bool_val;



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