[gjs/gnome-40: 1/30] wrapperutils: Use native ostringstream pointer to string conversion




commit 7297e70e3f63c41eaf60cba128e102e2ce4f34ea
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Apr 12 19:52:17 2021 +0200

    wrapperutils: Use native ostringstream pointer to string conversion
    
    We were casting the object pointers to integer values and then printing
    as such. So we were never printing the actual object addresses in hex
    form (as the prefix suggested).
    
    Add a test checking this.
    
    (cherry-picked from commit 31da89044)

 gi/wrapperutils.cpp               | 4 ++--
 installed-tests/js/testGObject.js | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/gi/wrapperutils.cpp b/gi/wrapperutils.cpp
index 88f8330c..a84c5580 100644
--- a/gi/wrapperutils.cpp
+++ b/gi/wrapperutils.cpp
@@ -37,9 +37,9 @@ bool gjs_wrapper_to_string_func(JSContext* context, JSObject* this_obj,
         out << " GType:" << g_type_name(gtype);
     }
 
-    out << " jsobj@0x" << uintptr_t(this_obj);
+    out << " jsobj@" << this_obj;
     if (native_address)
-        out << " native@0x" << uintptr_t(native_address);
+        out << " native@" << native_address;
 
     out << ']';
 
diff --git a/installed-tests/js/testGObject.js b/installed-tests/js/testGObject.js
index bbea88a0..885a93fb 100644
--- a/installed-tests/js/testGObject.js
+++ b/installed-tests/js/testGObject.js
@@ -7,6 +7,7 @@
 // which are big enough to get their own files.
 
 const {GLib, GObject} = imports.gi;
+const {system: System} = imports;
 
 describe('GObject overrides', function () {
     const TestObj = GObject.registerClass({
@@ -51,6 +52,13 @@ describe('GObject overrides', function () {
             expect(handler).not.toHaveBeenCalled();
         });
     });
+
+    it('toString() shows the native object address', function () {
+        const o = new TestObj();
+        const address = System.addressOfGObject(o);
+        expect(o.toString()).toMatch(
+            new RegExp(`[object instance wrapper .* jsobj@0x[a-f0-9]+ native@${address}`));
+    });
 });
 
 describe('GObject should', function () {


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