[gjs/april-maintenance: 2/5] function: Improve format_function_name()



commit 60e1b193dadf83b1324487c1fdceb640928d7b4f
Author: Philip Chimento <philip chimento gmail com>
Date:   Thu Apr 30 21:28:58 2020 -0700

    function: Improve format_function_name()
    
    It's not necessary to pass in the information about whether the function
    is a method or not, it's available from the function's GICallableInfo.
    
    Fix the type of function->info to be GICallableInfo. In some cases it's
    not a GIFunctionInfo, as can be found out by trying to call a
    GIFunctionInfo method on it unconditionally.

 gi/function.cpp | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 137a7895..89346fff 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -72,7 +72,7 @@
 #define GJS_ARG_INDEX_INVALID G_MAXUINT8
 
 typedef struct {
-    GIFunctionInfo *info;
+    GICallableInfo* info;
 
     GjsParamType *param_types;
 
@@ -756,19 +756,15 @@ gjs_fill_method_instance(JSContext       *context,
 
 /* Intended for error messages. Return value must be freed */
 GJS_USE
-static char *
-format_function_name(Function *function,
-                     bool      is_method)
-{
-    auto baseinfo = static_cast<GIBaseInfo *>(function->info);
-    if (is_method)
-        return g_strdup_printf("method %s.%s.%s",
-                               g_base_info_get_namespace(baseinfo),
-                               g_base_info_get_name(g_base_info_get_container(baseinfo)),
-                               g_base_info_get_name(baseinfo));
+static char* format_function_name(Function* function) {
+    if (g_callable_info_is_method(function->info))
+        return g_strdup_printf(
+            "method %s.%s.%s", g_base_info_get_namespace(function->info),
+            g_base_info_get_name(g_base_info_get_container(function->info)),
+            g_base_info_get_name(function->info));
     return g_strdup_printf("function %s.%s",
-                           g_base_info_get_namespace(baseinfo),
-                           g_base_info_get_name(baseinfo));
+                           g_base_info_get_namespace(function->info),
+                           g_base_info_get_name(function->info));
 }
 
 static void
@@ -852,7 +848,7 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
      *
      * @args.length() is the number of arguments that were actually passed.
      */
-    GjsAutoChar name = format_function_name(function, is_method);
+    GjsAutoChar name = format_function_name(function);
     if (args.length() > function->expected_js_argc) {
         if (!JS::WarnUTF8(
                 context, "Too many arguments to %s: expected %d, got %u",


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