[gjs/wip/xulrunner-1.9.3: 2/5] xulrunner 1.9.3: Use JS_AddValueRoot if available



commit 9b02a637ac0dbb34ee083122b9b2eaf24f653d7e
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            |   12 ++++++++
 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, 129 insertions(+), 110 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 57e21dd..a6a381f 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 c17a2b9..e00c90d 100644
--- a/gi/arg.c
+++ b/gi/arg.c
@@ -370,7 +370,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))
@@ -385,7 +385,7 @@ gjs_array_from_strv(JSContext   *context,
     result = JS_TRUE;
 
 out:
-    JS_RemoveRoot(context, &elem);
+    JS_RemoveValueRoot(context, &elem);
 
     return result;
 }
@@ -1380,7 +1380,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;
 
@@ -1420,7 +1420,7 @@ gjs_array_from_g_list (JSContext  *context,
     result = JS_TRUE;
 
  out:
-    JS_RemoveRoot(context, &elem);
+    JS_RemoveValueRoot(context, &elem);
 
     return result;
 }
@@ -1509,7 +1509,7 @@ gjs_array_from_g_array (JSContext  *context,
     result = JS_TRUE;
 
 finally:
-    JS_RemoveRoot(context, &elem);
+    JS_RemoveValueRoot(context, &elem);
 
     return result;
 }
@@ -1540,16 +1540,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;
 
@@ -1583,10 +1583,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 adc9bd7..89eaab4 100644
--- a/gi/boxed.c
+++ b/gi/boxed.c
@@ -641,13 +641,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 7cf084c..4385c40 100644
--- a/gi/closure.c
+++ b/gi/closure.c
@@ -308,14 +308,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 b8aa2a0..fe1e3c8 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -127,7 +127,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);
@@ -271,7 +271,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 f1b8a59..f57a25b 100644
--- a/gi/value.c
+++ b/gi/value.c
@@ -78,7 +78,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 */
@@ -138,7 +138,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..793ab5c 100644
--- a/gjs/compat.h
+++ b/gjs/compat.h
@@ -35,6 +35,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 635e31d..96f7bb5 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -352,7 +352,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;
     }
@@ -620,7 +620,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 b4c7360..ecd6ea3 100644
--- a/gjs/jsapi-util-array.c
+++ b/gjs/jsapi-util-array.c
@@ -60,7 +60,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);
 }
 
@@ -70,7 +70,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);
 }
 
@@ -80,7 +80,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
@@ -180,7 +180,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
@@ -207,7 +207,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 50d4449..f5fa228 100644
--- a/gjs/jsapi-util-error.c
+++ b/gjs/jsapi-util-error.c
@@ -251,7 +251,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);
 
@@ -271,7 +271,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);
 
     JS_EndRequest(context);
 
diff --git a/gjs/jsapi-util-string.c b/gjs/jsapi-util-string.c
index 4a57176..a6453d4 100644
--- a/gjs/jsapi-util-string.c
+++ b/gjs/jsapi-util-string.c
@@ -543,7 +543,7 @@ gjstest_test_func_gjs_jsapi_util_string_get_binary(void)
     JS_SetErrorReporter(context, test_error_reporter);
 
     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,
@@ -574,7 +574,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 e2f7f14..88361de 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -849,7 +849,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;
 
@@ -890,7 +890,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 99259a0..319f609 100644
--- a/modules/dbus-exports.c
+++ b/modules/dbus-exports.c
@@ -321,7 +321,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,
@@ -334,7 +334,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,
@@ -367,7 +367,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();
 
@@ -1056,12 +1056,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,
@@ -1084,7 +1084,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;
@@ -1096,7 +1096,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);
 
@@ -1175,13 +1175,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;
             }
@@ -1202,13 +1202,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);
@@ -1310,18 +1310,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);
@@ -1403,8 +1403,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;
@@ -1493,8 +1493,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);
@@ -1531,7 +1531,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;
 
@@ -1638,7 +1638,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 0ec22f2..aebb2de 100644
--- a/modules/dbus-values.c
+++ b/modules/dbus-values.c
@@ -61,20 +61,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 ++;
             }
@@ -94,7 +94,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;
@@ -106,20 +106,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);
@@ -127,33 +127,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;
@@ -175,34 +175,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;
@@ -308,7 +308,7 @@ gjs_js_values_from_dbus(JSContext          *context,
     jsval value;
 
     value = JSVAL_VOID;
-    JS_AddRoot(context, &value);
+    JS_AddValueRoot(context, &value);
 
     *array_p = NULL;
 
@@ -317,7 +317,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 */
         }
 
@@ -326,7 +326,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 2322a7c..d5eacb5 100644
--- a/modules/dbus.c
+++ b/modules/dbus.c
@@ -1015,16 +1015,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);
 }
@@ -1054,16 +1054,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);
 }
@@ -1241,12 +1241,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);
@@ -1284,12 +1284,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);
@@ -1570,7 +1570,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)
@@ -1595,7 +1595,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;
 }
 
@@ -1612,7 +1612,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)
@@ -1706,7 +1706,7 @@ define_bus_proto(JSContext *context,
     result = JS_TRUE;
 
  out:
-    JS_RemoveRoot(context, &bus_proto_val);
+    JS_RemoveValueRoot(context, &bus_proto_val);
 
     return result;
 }
@@ -1731,7 +1731,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)
@@ -1767,7 +1767,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 7208e45..a3e11c6 100644
--- a/modules/mainloop.c
+++ b/modules/mainloop.c
@@ -126,7 +126,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,
@@ -140,7 +140,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]