[gjs] Fix JS types in more callbacks



commit c7689ebba066a5028bab7202b515a482d63a5e25
Author: Michel Dänzer <michel daenzer net>
Date:   Sat Aug 23 13:04:21 2014 +0900

    Fix JS types in more callbacks
    
    Fixes the following JSUnit tests on PPC:
    
    test0040mainloop.js
    testByteArray.js
    testCairo.js
    testEverythingBasic.js
    testFundamental.js
    testGDBus.js
    testGObjectClass.js
    testMainloop.js
    testParamSpec.js
    testTweener.js
    
    Signed-off-by: Michel Dänzer <michel daenzer net>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=729554

 gi/param.cpp     |   18 ++++++++----------
 gjs/importer.cpp |   42 +++++++++++++++++-------------------------
 2 files changed, 25 insertions(+), 35 deletions(-)
---
diff --git a/gi/param.cpp b/gi/param.cpp
index 7b4b5b5..27918b2 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -59,10 +59,10 @@ GJS_DEFINE_PRIV_FROM_JS(Param, gjs_param_class)
  */
 static JSBool
 param_new_resolve(JSContext *context,
-                  JSObject **obj,
-                  jsid      *id,
-                  unsigned   flags,
-                  JSObject **objp)
+                  JS::HandleObject obj,
+                  JS::HandleId id,
+                  unsigned flags,
+                  JS::MutableHandleObject objp)
 {
     GIObjectInfo *info = NULL;
     GIFunctionInfo *method_info;
@@ -70,12 +70,10 @@ param_new_resolve(JSContext *context,
     char *name;
     JSBool ret = JS_FALSE;
 
-    *objp = NULL;
-
-    if (!gjs_get_string_id(context, *id, &name))
+    if (!gjs_get_string_id(context, id, &name))
         return JS_TRUE; /* not resolved, but no error */
 
-    priv = priv_from_js(context, *obj);
+    priv = priv_from_js(context, obj);
 
     if (priv != NULL) {
         /* instance, not prototype */
@@ -99,12 +97,12 @@ param_new_resolve(JSContext *context,
                   "Defining method %s in prototype for GObject.ParamSpec",
                   g_base_info_get_name( (GIBaseInfo*) method_info));
 
-        if (gjs_define_function(context, *obj, G_TYPE_PARAM, method_info) == NULL) {
+        if (gjs_define_function(context, obj, G_TYPE_PARAM, method_info) == NULL) {
             g_base_info_unref( (GIBaseInfo*) method_info);
             goto out;
         }
 
-        *objp = *obj; /* we defined the prop in obj */
+        objp.set(obj); /* we defined the prop in obj */
     }
 
     g_base_info_unref( (GIBaseInfo*) method_info);
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 5bf922f..f4ab160 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -662,10 +662,10 @@ importer_iterator_free(ImporterIterator *iter)
  */
 static JSBool
 importer_new_enumerate(JSContext  *context,
-                       JSObject  **object,
+                       JS::HandleObject object,
                        JSIterateOp enum_op,
-                       jsval      *state_p,
-                       jsid       *id_p)
+                       JS::MutableHandleValue statep,
+                       JS::MutableHandleId idp)
 {
     ImporterIterator *iter;
 
@@ -679,20 +679,18 @@ importer_new_enumerate(JSContext  *context,
         guint32 i;
         jsid search_path_name;
 
-        if (state_p)
-            *state_p = JSVAL_NULL;
+        statep.set(JSVAL_NULL);
 
-        if (id_p)
-            *id_p = INT_TO_JSID(0);
+        idp.set(INT_TO_JSID(0));
 
-        priv = priv_from_js(context, *object);
+        priv = priv_from_js(context, object);
 
         if (!priv)
             /* we are enumerating the prototype properties */
             return JS_TRUE;
 
         search_path_name = gjs_context_get_const_string(context, GJS_STRING_SEARCH_PATH);
-        if (!gjs_object_require_property(context, *object, "importer", search_path_name, &search_path_val))
+        if (!gjs_object_require_property(context, object, "importer", search_path_name, &search_path_val))
             return JS_FALSE;
 
         if (!JSVAL_IS_OBJECT(search_path_val)) {
@@ -747,7 +745,7 @@ importer_new_enumerate(JSContext  *context,
             init_path = g_build_filename(dirname, MODULE_INIT_FILENAME,
                                          NULL);
 
-            load_module_elements(context, *object, iter, init_path);
+            load_module_elements(context, object, iter, init_path);
 
             g_free(init_path);
 
@@ -788,11 +786,9 @@ importer_new_enumerate(JSContext  *context,
             g_free(dirname);
         }
 
-        if (state_p)
-            *state_p = PRIVATE_TO_JSVAL(iter);
+        statep.set(PRIVATE_TO_JSVAL(iter));
 
-        if (id_p)
-            *id_p = INT_TO_JSID(iter->elements->len);
+        idp.set(INT_TO_JSID(iter->elements->len));
 
         break;
     }
@@ -800,15 +796,10 @@ importer_new_enumerate(JSContext  *context,
     case JSENUMERATE_NEXT: {
         jsval element_val;
 
-        if (!state_p) {
-            gjs_throw(context, "Enumerate with no iterator set?");
-            return JS_FALSE;
-        }
-
-        if (JSVAL_IS_NULL(*state_p)) /* Iterating prototype */
+        if (JSVAL_IS_NULL(statep)) /* Iterating prototype */
             return JS_TRUE;
 
-        iter = (ImporterIterator*) JSVAL_TO_PRIVATE(*state_p);
+        iter = (ImporterIterator*) JSVAL_TO_PRIVATE(statep);
 
         if (iter->index < iter->elements->len) {
             if (!gjs_string_from_utf8(context,
@@ -818,7 +809,8 @@ importer_new_enumerate(JSContext  *context,
                                          &element_val))
                 return JS_FALSE;
 
-            if (!JS_ValueToId(context, element_val, id_p))
+            jsid id = idp;
+            if (!JS_ValueToId(context, element_val, &id))
                 return JS_FALSE;
 
             break;
@@ -827,12 +819,12 @@ importer_new_enumerate(JSContext  *context,
     }
 
     case JSENUMERATE_DESTROY: {
-        if (state_p && !JSVAL_IS_NULL(*state_p)) {
-            iter = (ImporterIterator*) JSVAL_TO_PRIVATE(*state_p);
+        if (!JSVAL_IS_NULL(statep)) {
+            iter = (ImporterIterator*) JSVAL_TO_PRIVATE(statep);
 
             importer_iterator_free(iter);
 
-            *state_p = JSVAL_NULL;
+            statep.set(JSVAL_NULL);
         }
     }
     }


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