[seed] Implementing the gjs/system addressOf method



commit 6295f62bc1447f2e7aa93a865567e9656bfb0f55
Author: Danilo Cesar Lemes de Paula <danilo cesar collabora co uk>
Date:   Thu Jan 14 13:28:05 2016 -0200

    Implementing the gjs/system addressOf method

 modules/gjs/system/seed-system.c |   35 +++++++++++++++--------------------
 1 files changed, 15 insertions(+), 20 deletions(-)
---
diff --git a/modules/gjs/system/seed-system.c b/modules/gjs/system/seed-system.c
index d80e14f..6caeb0c 100644
--- a/modules/gjs/system/seed-system.c
+++ b/modules/gjs/system/seed-system.c
@@ -34,6 +34,10 @@
 
 #define GJS_COMPAT_VERSION (1 * 100 + 40) * 100 + 0
 
+#define NUMARG_EXPECTED_EXCEPTION(name, argc) \
+    seed_make_exception (ctx, exception, "ArgumentError", name " expected " argc  " but got %zd", 
argumentCount); \
+    return seed_make_undefined(ctx);
+
 static SeedValue
 gjs_address_of (SeedContext ctx,
                        SeedObject function,
@@ -41,30 +45,21 @@ gjs_address_of (SeedContext ctx,
                        size_t argumentCount,
                        const SeedValue arguments[], SeedException * exception)
 {
-/*static SeedValue
-gjs_address_of(SeedContext context,
-               unsigned   argc,
-               SeedValue      *vp)
-{
-    JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
-    SeedObject  *target_obj;
-    bool ret;
-    char *pointer_string;
-    SeedValue  retval;
-
-    if (!gjs_parse_call_args(context, "addressOf", "o", argv, "object", &target_obj))
-        return FALSE;
-
-    pointer_string = g_strdup_printf("%p", target_obj);
-
-    ret = gjs_string_from_utf8(context, pointer_string, -1, &retval);
+    if (argumentCount != 1) {
+        NUMARG_EXPECTED_EXCEPTION("addressOf", "1 argument")
+    }
+
+    SeedValue targetValue = arguments[0];
+    if (!seed_value_is_object(ctx, targetValue)) {
+        seed_make_exception (ctx, exception, "ArgumentError", "addressOf expects an object");
+        return seed_make_undefined(ctx);
+    }
+
+    char *pointer_string = g_strdup_printf("%p", targetValue);
+    SeedValue ret = seed_value_from_string(ctx, pointer_string, exception);
     g_free(pointer_string);
 
-    if (ret)
-        argv.rval().set(retval);
-
-    return ret;*/
-       return seed_value_from_boolean (ctx, TRUE, exception);
+    return ret;
 }
 
 static SeedValue


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