LCOV - code coverage report
Current view: top level - gi - union.h (source / functions) Coverage Total Hit
Test: gjs- Code Coverage Lines: 100.0 % 4 4
Test Date: 2024-03-26 02:45:07 Functions: 100.0 % 3 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
       2                 :             : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
       3                 :             : // SPDX-FileCopyrightText: 2008 litl, LLC
       4                 :             : 
       5                 :             : #ifndef GI_UNION_H_
       6                 :             : #define GI_UNION_H_
       7                 :             : 
       8                 :             : #include <config.h>
       9                 :             : 
      10                 :             : #include <girepository.h>
      11                 :             : #include <glib-object.h>
      12                 :             : 
      13                 :             : #include <js/TypeDecls.h>
      14                 :             : 
      15                 :             : #include "gi/cwrapper.h"
      16                 :             : #include "gi/wrapperutils.h"
      17                 :             : #include "gjs/macros.h"
      18                 :             : #include "util/log.h"
      19                 :             : 
      20                 :             : namespace JS {
      21                 :             : class CallArgs;
      22                 :             : }
      23                 :             : struct JSClass;
      24                 :             : struct JSClassOps;
      25                 :             : class UnionPrototype;
      26                 :             : class UnionInstance;
      27                 :             : 
      28                 :             : class UnionBase
      29                 :             :     : public GIWrapperBase<UnionBase, UnionPrototype, UnionInstance> {
      30                 :             :     friend class CWrapperPointerOps<UnionBase>;
      31                 :             :     friend class GIWrapperBase<UnionBase, UnionPrototype, UnionInstance>;
      32                 :             : 
      33                 :             :  protected:
      34                 :           4 :     explicit UnionBase(UnionPrototype* proto = nullptr)
      35                 :           4 :         : GIWrapperBase(proto) {}
      36                 :             : 
      37                 :             :     static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_GBOXED;
      38                 :             :     static constexpr const char* DEBUG_TAG = "union";
      39                 :             : 
      40                 :             :     static const JSClassOps class_ops;
      41                 :             :     static const JSClass klass;
      42                 :             : };
      43                 :             : 
      44                 :             : class UnionPrototype : public GIWrapperPrototype<UnionBase, UnionPrototype,
      45                 :             :                                                  UnionInstance, GIUnionInfo> {
      46                 :             :     friend class GIWrapperPrototype<UnionBase, UnionPrototype, UnionInstance,
      47                 :             :                                     GIUnionInfo>;
      48                 :             :     friend class GIWrapperBase<UnionBase, UnionPrototype, UnionInstance>;
      49                 :             : 
      50                 :             :     static constexpr InfoType::Tag info_type_tag = InfoType::Union;
      51                 :             : 
      52                 :             :     explicit UnionPrototype(GIUnionInfo* info, GType gtype);
      53                 :             :     ~UnionPrototype(void);
      54                 :             : 
      55                 :             :     GJS_JSAPI_RETURN_CONVENTION
      56                 :             :     bool resolve_impl(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
      57                 :             :                       bool* resolved);
      58                 :             : 
      59                 :             :     // Overrides GIWrapperPrototype::constructor_nargs().
      60                 :           2 :     [[nodiscard]] unsigned constructor_nargs(void) const { return 0; }
      61                 :             : 
      62                 :             :  public:
      63                 :             :     GJS_JSAPI_RETURN_CONVENTION
      64                 :             :     static bool define_class(JSContext* cx, JS::HandleObject in_object,
      65                 :             :                              GIUnionInfo* info);
      66                 :             : };
      67                 :             : 
      68                 :             : class UnionInstance
      69                 :             :     : public GIWrapperInstance<UnionBase, UnionPrototype, UnionInstance> {
      70                 :             :     friend class GIWrapperInstance<UnionBase, UnionPrototype, UnionInstance>;
      71                 :             :     friend class GIWrapperBase<UnionBase, UnionPrototype, UnionInstance>;
      72                 :             : 
      73                 :             :     explicit UnionInstance(UnionPrototype* prototype, JS::HandleObject obj);
      74                 :             :     ~UnionInstance(void);
      75                 :             : 
      76                 :             :     GJS_JSAPI_RETURN_CONVENTION
      77                 :             :     bool constructor_impl(JSContext* cx, JS::HandleObject obj,
      78                 :             :                           const JS::CallArgs& args);
      79                 :             : 
      80                 :             :  public:
      81                 :             :     GJS_JSAPI_RETURN_CONVENTION
      82                 :             :     static JSObject* new_for_c_union(JSContext* cx, GIUnionInfo* info,
      83                 :             :                                      void* gboxed);
      84                 :             : 
      85                 :             :     /*
      86                 :             :      * UnionInstance::copy_union:
      87                 :             :      *
      88                 :             :      * Allocate a new union pointer using g_boxed_copy(), from a raw union
      89                 :             :      * pointer.
      90                 :             :      */
      91                 :           2 :     void copy_union(void* ptr) { m_ptr = g_boxed_copy(gtype(), ptr); }
      92                 :             : 
      93                 :             :     GJS_JSAPI_RETURN_CONVENTION
      94                 :             :     static void* copy_ptr(JSContext* cx, GType gtype, void* ptr);
      95                 :             : };
      96                 :             : 
      97                 :             : #endif  // GI_UNION_H_
        

Generated by: LCOV version 2.0-1