LCOV - code coverage report
Current view: top level - xpcom/reflect/xptcall - xptcall.h (source / functions) Hit Total Coverage
Test: output.info Lines: 9 9 100.0 %
Date: 2017-07-14 16:53:18 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : /* Public declarations for xptcall. */
       7             : 
       8             : #ifndef xptcall_h___
       9             : #define xptcall_h___
      10             : 
      11             : #include "nscore.h"
      12             : #include "nsISupports.h"
      13             : #include "xpt_struct.h"
      14             : #include "xptinfo.h"
      15             : #include "js/Value.h"
      16             : #include "mozilla/MemoryReporting.h"
      17             : 
      18       39670 : struct nsXPTCMiniVariant
      19             : {
      20             : // No ctors or dtors so that we can use arrays of these on the stack
      21             : // with no penalty.
      22             :     union
      23       39670 :     {
      24             :         int8_t    i8;
      25             :         int16_t   i16;
      26             :         int32_t   i32;
      27             :         int64_t   i64;
      28             :         uint8_t   u8;
      29             :         uint16_t  u16;
      30             :         uint32_t  u32;
      31             :         uint64_t  u64;
      32             :         float     f;
      33             :         double    d;
      34             :         bool      b;
      35             :         char      c;
      36             :         char16_t wc;
      37             :         void*     p;
      38             : 
      39             :         // Types below here are unknown to the assembly implementations, and
      40             :         // therefore _must_ be passed with indirect semantics. We put them in
      41             :         // the union here for type safety, so that we can avoid void* tricks.
      42             :         JS::Value j;
      43             :     } val;
      44             : };
      45             : 
      46       28433 : struct nsXPTCVariant : public nsXPTCMiniVariant
      47             : {
      48             : // No ctors or dtors so that we can use arrays of these on the stack
      49             : // with no penalty.
      50             : 
      51             :     // inherits 'val' here
      52             :     void*     ptr;
      53             :     nsXPTType type;
      54             :     uint8_t   flags;
      55             : 
      56             :     enum
      57             :     {
      58             :         //
      59             :         // Bitflag definitions
      60             :         //
      61             : 
      62             :         // Indicates that ptr (above, and distinct from val.p) is the value that
      63             :         // should be passed on the stack.
      64             :         //
      65             :         // In theory, ptr could point anywhere. But in practice it always points
      66             :         // to &val. So this flag is used to pass 'val' by reference, letting us
      67             :         // avoid the extra allocation we would incur if we were to use val.p.
      68             :         //
      69             :         // Various parts of XPConnect assume that ptr==&val, so we enforce it
      70             :         // explicitly with SetIndirect() and IsIndirect().
      71             :         //
      72             :         // Since ptr always points to &val, the semantics of this flag are kind of
      73             :         // dumb, since the ptr field is unnecessary. But changing them would
      74             :         // require changing dozens of assembly files, so they're likely to stay
      75             :         // the way they are.
      76             :         PTR_IS_DATA    = 0x1,
      77             : 
      78             :         // Indicates that the value we hold requires some sort of cleanup (memory
      79             :         // deallocation, interface release, JS::Value unrooting, etc). The precise
      80             :         // cleanup that is performed depends on the 'type' field above.
      81             :         // If the value is an array, this flag specifies whether the elements
      82             :         // within the array require cleanup (we always clean up the array itself,
      83             :         // so this flag would be redundant for that purpose).
      84             :         VAL_NEEDS_CLEANUP = 0x2
      85             :     };
      86             : 
      87       28433 :     void ClearFlags()         {flags = 0;}
      88       11589 :     void SetIndirect()        {ptr = &val; flags |= PTR_IS_DATA;}
      89       20467 :     void SetValNeedsCleanup() {flags |= VAL_NEEDS_CLEANUP;}
      90             : 
      91             :     bool IsIndirect()         const  {return 0 != (flags & PTR_IS_DATA);}
      92       25027 :     bool DoesValNeedCleanup() const  {return 0 != (flags & VAL_NEEDS_CLEANUP);}
      93             : 
      94             :     // Internal use only. Use IsIndirect() instead.
      95       85344 :     bool IsPtrData()       const  {return 0 != (flags & PTR_IS_DATA);}
      96             : 
      97             :     void Init(const nsXPTCMiniVariant& mv, const nsXPTType& t, uint8_t f)
      98             :     {
      99             :         type = t;
     100             :         flags = f;
     101             : 
     102             :         if(f & PTR_IS_DATA)
     103             :         {
     104             :             ptr = mv.val.p;
     105             :             val.p = nullptr;
     106             :         }
     107             :         else
     108             :         {
     109             :             ptr = nullptr;
     110             :             val.p = nullptr; // make sure 'val.p' is always initialized
     111             :             switch(t.TagPart()) {
     112             :               case nsXPTType::T_I8:                val.i8  = mv.val.i8;  break;
     113             :               case nsXPTType::T_I16:               val.i16 = mv.val.i16; break;
     114             :               case nsXPTType::T_I32:               val.i32 = mv.val.i32; break;
     115             :               case nsXPTType::T_I64:               val.i64 = mv.val.i64; break;
     116             :               case nsXPTType::T_U8:                val.u8  = mv.val.u8;  break;
     117             :               case nsXPTType::T_U16:               val.u16 = mv.val.u16; break;
     118             :               case nsXPTType::T_U32:               val.u32 = mv.val.u32; break;
     119             :               case nsXPTType::T_U64:               val.u64 = mv.val.u64; break;
     120             :               case nsXPTType::T_FLOAT:             val.f   = mv.val.f;   break;
     121             :               case nsXPTType::T_DOUBLE:            val.d   = mv.val.d;   break;
     122             :               case nsXPTType::T_BOOL:              val.b   = mv.val.b;   break;
     123             :               case nsXPTType::T_CHAR:              val.c   = mv.val.c;   break;
     124             :               case nsXPTType::T_WCHAR:             val.wc  = mv.val.wc;  break;
     125             :               case nsXPTType::T_VOID:              /* fall through */
     126             :               case nsXPTType::T_IID:               /* fall through */
     127             :               case nsXPTType::T_DOMSTRING:         /* fall through */
     128             :               case nsXPTType::T_CHAR_STR:          /* fall through */
     129             :               case nsXPTType::T_WCHAR_STR:         /* fall through */
     130             :               case nsXPTType::T_INTERFACE:         /* fall through */
     131             :               case nsXPTType::T_INTERFACE_IS:      /* fall through */
     132             :               case nsXPTType::T_ARRAY:             /* fall through */
     133             :               case nsXPTType::T_PSTRING_SIZE_IS:   /* fall through */
     134             :               case nsXPTType::T_PWSTRING_SIZE_IS:  /* fall through */
     135             :               case nsXPTType::T_UTF8STRING:        /* fall through */
     136             :               case nsXPTType::T_CSTRING:           /* fall through */
     137             :               default:                             val.p   = mv.val.p;   break;
     138             :             }
     139             :         }
     140             :     }
     141             : };
     142             : 
     143         939 : class nsIXPTCProxy : public nsISupports
     144             : {
     145             : public:
     146             :     NS_IMETHOD CallMethod(uint16_t aMethodIndex,
     147             :                           const XPTMethodDescriptor *aInfo,
     148             :                           nsXPTCMiniVariant *aParams) = 0;
     149             : };
     150             : 
     151             : /**
     152             :  * This is a typedef to avoid confusion between the canonical
     153             :  * nsISupports* that provides object identity and an interface pointer
     154             :  * for inheriting interfaces that aren't known at compile-time.
     155             :  */
     156             : typedef nsISupports nsISomeInterface;
     157             : 
     158             : /**
     159             :  * Get a proxy object to implement the specified interface.
     160             :  *
     161             :  * @param aIID    The IID of the interface to implement.
     162             :  * @param aOuter  An object to receive method calls from the proxy object.
     163             :  *                The stub forwards QueryInterface/AddRef/Release to the
     164             :  *                outer object. The proxy object does not hold a reference to
     165             :  *                the outer object; it is the caller's responsibility to
     166             :  *                ensure that this pointer remains valid until the stub has
     167             :  *                been destroyed.
     168             :  * @param aStub   Out parameter for the new proxy object. The object is
     169             :  *                not addrefed. The object never destroys itself. It must be
     170             :  *                explicitly destroyed by calling
     171             :  *                NS_DestroyXPTCallStub when it is no longer needed.
     172             :  */
     173             : XPCOM_API(nsresult)
     174             : NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
     175             :                   nsISomeInterface* *aStub);
     176             : 
     177             : /**
     178             :  * Destroys an XPTCall stub previously created with NS_GetXPTCallStub.
     179             :  */
     180             : XPCOM_API(void)
     181             : NS_DestroyXPTCallStub(nsISomeInterface* aStub);
     182             : 
     183             : /**
     184             :  * Measures the size of an XPTCall stub previously created with NS_GetXPTCallStub.
     185             :  */
     186             : XPCOM_API(size_t)
     187             : NS_SizeOfIncludingThisXPTCallStub(const nsISomeInterface* aStub, mozilla::MallocSizeOf aMallocSizeOf);
     188             : 
     189             : // this is extern "C" because on some platforms it is implemented in assembly
     190             : extern "C" nsresult
     191             : NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
     192             :                  uint32_t paramCount, nsXPTCVariant* params);
     193             : 
     194             : #endif /* xptcall_h___ */

Generated by: LCOV version 1.13