[gjs: 12/18] jsapi-util: Add out operator to get the double pointer




commit f7d36e7c6a2ce729ac3d375f7d5d94b7a6c908d4
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Oct 14 02:43:31 2020 +0200

    jsapi-util: Add out operator to get the double pointer

 gjs/jsapi-util.h              | 1 +
 test/gjs-test-jsapi-utils.cpp | 9 +++++++++
 2 files changed, 10 insertions(+)
---
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index cfe7ec76..0ae3e0c8 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -123,6 +123,7 @@ struct GjsAutoPointer {
 
     constexpr Ptr get() { return m_ptr; }
     constexpr ConstPtr get() const { return m_ptr; }
+    constexpr Ptr* out() { return &m_ptr; }
 
     constexpr Ptr release() {
         auto* ptr = m_ptr;
diff --git a/test/gjs-test-jsapi-utils.cpp b/test/gjs-test-jsapi-utils.cpp
index 6d3f0dd6..f9ed9adb 100644
--- a/test/gjs-test-jsapi-utils.cpp
+++ b/test/gjs-test-jsapi-utils.cpp
@@ -369,6 +369,13 @@ static void test_gjs_autopointer_get() {
     g_assert(ptr == autoptr.get());
 }
 
+static void test_gjs_autopointer_out() {
+    auto* ptr = gjs_test_object_new();
+    GjsAutoTestObject autoptr(ptr);
+
+    g_assert(ptr == *(autoptr.out()));
+}
+
 static void test_gjs_autopointer_release() {
     auto* ptr = gjs_test_object_new();
     GjsAutoTestObject autoptr(ptr);
@@ -615,6 +622,8 @@ void gjs_test_add_tests_for_jsapi_utils(void) {
                     test_gjs_autopointer_assign_operator_array);
     g_test_add_func("/gjs/jsapi-utils/gjs-autopointer/method/get",
                     test_gjs_autopointer_get);
+    g_test_add_func("/gjs/jsapi-utils/gjs-autopointer/method/out",
+                    test_gjs_autopointer_out);
     g_test_add_func("/gjs/jsapi-utils/gjs-autopointer/method/release",
                     test_gjs_autopointer_release);
     g_test_add_func("/gjs/jsapi-utils/gjs-autopointer/method/reset/nullptr",


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