tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

xpc_make_class.h (7179B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef xpc_make_class_h
      8 #define xpc_make_class_h
      9 
     10 // This file should be used to create JSClass instances for nsIXPCScriptable
     11 // instances. This includes any file that uses xpc_map_end.h.
     12 
     13 #include "xpcpublic.h"
     14 #include "mozilla/dom/DOMJSClass.h"
     15 
     16 bool XPC_WN_MaybeResolvingPropertyStub(JSContext* cx, JS::HandleObject obj,
     17                                       JS::HandleId id, JS::HandleValue v);
     18 bool XPC_WN_CannotModifyPropertyStub(JSContext* cx, JS::HandleObject obj,
     19                                     JS::HandleId id, JS::HandleValue v);
     20 
     21 bool XPC_WN_MaybeResolvingDeletePropertyStub(JSContext* cx,
     22                                             JS::HandleObject obj,
     23                                             JS::HandleId id,
     24                                             JS::ObjectOpResult& result);
     25 bool XPC_WN_CannotDeletePropertyStub(JSContext* cx, JS::HandleObject obj,
     26                                     JS::HandleId id,
     27                                     JS::ObjectOpResult& result);
     28 
     29 bool XPC_WN_Shared_Enumerate(JSContext* cx, JS::HandleObject obj);
     30 
     31 bool XPC_WN_NewEnumerate(JSContext* cx, JS::HandleObject obj,
     32                         JS::MutableHandleIdVector properties,
     33                         bool enumerableOnly);
     34 
     35 bool XPC_WN_Helper_Resolve(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
     36                           bool* resolvedp);
     37 
     38 void XPC_WN_Helper_Finalize(JS::GCContext* gcx, JSObject* obj);
     39 void XPC_WN_NoHelper_Finalize(JS::GCContext* gcx, JSObject* obj);
     40 
     41 bool XPC_WN_Helper_Call(JSContext* cx, unsigned argc, JS::Value* vp);
     42 
     43 bool XPC_WN_Helper_Construct(JSContext* cx, unsigned argc, JS::Value* vp);
     44 
     45 void XPCWrappedNative_Trace(JSTracer* trc, JSObject* obj);
     46 
     47 extern const js::ClassExtension XPC_WN_JSClassExtension;
     48 
     49 #define XPC_MAKE_CLASS_OPS(_flags)                                            \
     50  {                                                                           \
     51      /* addProperty */                                                       \
     52      ((_flags) & XPC_SCRIPTABLE_USE_JSSTUB_FOR_ADDPROPERTY) ? nullptr        \
     53      : ((_flags) & XPC_SCRIPTABLE_ALLOW_PROP_MODS_DURING_RESOLVE)            \
     54          ? XPC_WN_MaybeResolvingPropertyStub                                 \
     55          : XPC_WN_CannotModifyPropertyStub,                                  \
     56                                                                              \
     57      /* delProperty */                                                       \
     58      ((_flags) & XPC_SCRIPTABLE_USE_JSSTUB_FOR_DELPROPERTY) ? nullptr        \
     59      : ((_flags) & XPC_SCRIPTABLE_ALLOW_PROP_MODS_DURING_RESOLVE)            \
     60          ? XPC_WN_MaybeResolvingDeletePropertyStub                           \
     61          : XPC_WN_CannotDeletePropertyStub,                                  \
     62                                                                              \
     63      /* enumerate */                                                         \
     64      ((_flags) & XPC_SCRIPTABLE_WANT_NEWENUMERATE)                           \
     65          ? nullptr /* We will use newEnumerate set below in this case */     \
     66          : XPC_WN_Shared_Enumerate,                                          \
     67                                                                              \
     68      /* newEnumerate */                                                      \
     69      ((_flags) & XPC_SCRIPTABLE_WANT_NEWENUMERATE) ? XPC_WN_NewEnumerate     \
     70                                                    : nullptr,                \
     71                                                                              \
     72      /* resolve */ /* We have to figure out resolve strategy at call time    \
     73                     */                                                       \
     74      XPC_WN_Helper_Resolve,                                                  \
     75                                                                              \
     76      /* mayResolve */                                                        \
     77      nullptr,                                                                \
     78                                                                              \
     79      /* finalize */                                                          \
     80      ((_flags) & XPC_SCRIPTABLE_WANT_FINALIZE) ? XPC_WN_Helper_Finalize      \
     81                                                : XPC_WN_NoHelper_Finalize,   \
     82                                                                              \
     83      /* call */                                                              \
     84      ((_flags) & XPC_SCRIPTABLE_WANT_CALL) ? XPC_WN_Helper_Call : nullptr,   \
     85                                                                              \
     86      /* construct */                                                         \
     87      ((_flags) & XPC_SCRIPTABLE_WANT_CONSTRUCT) ? XPC_WN_Helper_Construct    \
     88                                                 : nullptr,                   \
     89                                                                              \
     90      /* trace */                                                             \
     91      ((_flags) & XPC_SCRIPTABLE_IS_GLOBAL_OBJECT) ? JS_GlobalObjectTraceHook \
     92                                                   : XPCWrappedNative_Trace,  \
     93  }
     94 
     95 #define XPC_MAKE_CLASS(_name, _flags, _classOps)                 \
     96  {                                                              \
     97      /* name */                                                 \
     98      _name,                                                     \
     99                                                                 \
    100      /* flags */                                                \
    101      JSCLASS_SLOT0_IS_NSISUPPORTS | JSCLASS_IS_WRAPPED_NATIVE | \
    102          JSCLASS_FOREGROUND_FINALIZE |                          \
    103          (((_flags) & XPC_SCRIPTABLE_IS_GLOBAL_OBJECT)          \
    104               ? XPCONNECT_GLOBAL_FLAGS                          \
    105               : JSCLASS_HAS_RESERVED_SLOTS(1)),                 \
    106                                                                 \
    107      /* cOps */                                                 \
    108      _classOps,                                                 \
    109                                                                 \
    110      /* spec */                                                 \
    111      nullptr,                                                   \
    112                                                                 \
    113      /* ext */                                                  \
    114      &XPC_WN_JSClassExtension,                                  \
    115                                                                 \
    116      /* oOps */                                                 \
    117      nullptr,                                                   \
    118  }
    119 
    120 #endif