File: gi-function-Implement-name-property-for-functions.patch

package info (click to toggle)
gjs 1.82.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,380 kB
  • sloc: cpp: 34,404; javascript: 27,796; ansic: 13,034; sh: 1,607; python: 780; xml: 116; makefile: 36
file content (57 lines) | stat: -rw-r--r-- 2,250 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From: =?utf-8?b?Ik1hcmNvIFRyZXZpc2FuIChUcmV2acOxbyki?= <mail@3v1n0.net>
Date: Wed, 10 Sep 2025 07:23:58 +0200
Subject: gi/function: Implement name property for functions

JS functions have a name properties by default, but we did not implement
it for our function wrappers.

Given that there's no a defined specification for it and that it can be
used for debugging purposes, use it to store the original C function
name.

[smcv: Adjust for gjs 1.82 based on the change that Marco contributed to cjs]

Origin: backport, 1.86.0, commit:d9a77a804eff1942e4aa9235ed43167d7f2240c3
---
 gi/function.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/gi/function.cpp b/gi/function.cpp
index f88cbdb..dc07374 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -116,6 +116,9 @@ class Function : public CWrapper<Function> {
     GJS_JSAPI_RETURN_CONVENTION
     static bool get_length(JSContext* cx, unsigned argc, JS::Value* vp);
 
+    GJS_JSAPI_RETURN_CONVENTION
+    static bool get_name(JSContext* cx, unsigned argc, JS::Value* vp);
+
     GJS_JSAPI_RETURN_CONVENTION
     static bool to_string(JSContext* cx, unsigned argc, JS::Value* vp);
 
@@ -1251,6 +1254,16 @@ bool Function::get_length(JSContext* cx, unsigned argc, JS::Value* vp) {
     return true;
 }
 
+bool Function::get_name(JSContext* cx, unsigned argc, JS::Value* vp) {
+    GJS_CHECK_WRAPPER_PRIV(cx, argc, vp, rec, this_obj, Function, priv);
+
+    if (priv->m_info.type() == GI_INFO_TYPE_FUNCTION)
+        return gjs_string_from_utf8(cx, g_function_info_get_symbol(priv->m_info),
+                                    rec.rval());
+
+    return gjs_string_from_utf8(cx, priv->format_name().c_str(), rec.rval());
+}
+
 bool Function::to_string(JSContext* context, unsigned argc, JS::Value* vp) {
     GJS_CHECK_WRAPPER_PRIV(context, argc, vp, rec, this_obj, Function, priv);
     return priv->to_string_impl(context, rec.rval());
@@ -1302,6 +1315,7 @@ const JSClassOps Function::class_ops = {
 
 const JSPropertySpec Function::proto_props[] = {
     JS_PSG("length", &Function::get_length, JSPROP_PERMANENT),
+    JS_PSG("name", &Function::get_name, JSPROP_PERMANENT),
     JS_STRING_SYM_PS(toStringTag, "GIRepositoryFunction", JSPROP_READONLY),
     JS_PS_END};