[gjs/april-maintenance: 2/14] function: Improve format_function_name()
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/april-maintenance: 2/14] function: Improve format_function_name()
- Date: Tue, 5 May 2020 15:30:20 +0000 (UTC)
commit 0ab3db5fd978187230c586bcad685a3658722207
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 2e2e491a..bc460a84 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -71,7 +71,7 @@
#define GJS_ARG_INDEX_INVALID G_MAXUINT8
typedef struct {
- GIFunctionInfo *info;
+ GICallableInfo* info;
GjsParamType *param_types;
@@ -755,19 +755,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
@@ -851,7 +847,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]