diff options
-rw-r--r-- | gjs/jsapi-util.h | 1 | ||||
-rw-r--r-- | test/gjs-test-jsapi-utils.cpp | 9 |
2 files changed, 10 insertions, 0 deletions
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", |