summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/public/xpc_make_class.h
blob: f612d3056eb9a6554f02ca75da8dd59c5176b59a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=8 sts=4 et sw=4 tw=99: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef xpc_make_class_h
#define xpc_make_class_h

// This file should be used to create js::Class instances for nsIXPCScriptable
// instances. This includes any file that uses xpc_map_end.h.

#include "xpcpublic.h"
#include "mozilla/dom/DOMJSClass.h"

bool
XPC_WN_MaybeResolvingPropertyStub(JSContext* cx, JS::HandleObject obj,
                                  JS::HandleId id, JS::HandleValue v);
bool
XPC_WN_CannotModifyPropertyStub(JSContext* cx, JS::HandleObject obj,
                                JS::HandleId id, JS::HandleValue v);

bool
XPC_WN_MaybeResolvingDeletePropertyStub(JSContext* cx, JS::HandleObject obj,
                                        JS::HandleId id,
                                        JS::ObjectOpResult& result);
bool
XPC_WN_CantDeletePropertyStub(JSContext* cx, JS::HandleObject obj,
                              JS::HandleId id, JS::ObjectOpResult& result);

bool
XPC_WN_Helper_GetProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
                          JS::MutableHandleValue vp);

bool
XPC_WN_Helper_SetProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
                          JS::MutableHandleValue vp,
                          JS::ObjectOpResult& result);
bool
XPC_WN_MaybeResolvingSetPropertyStub(JSContext* cx, JS::HandleObject obj,
                                     JS::HandleId id, JS::MutableHandleValue vp,
                                     JS::ObjectOpResult& result);
bool
XPC_WN_CannotModifySetPropertyStub(JSContext* cx, JS::HandleObject obj,
                                   JS::HandleId id, JS::MutableHandleValue vp,
                                   JS::ObjectOpResult& result);

bool
XPC_WN_Helper_Enumerate(JSContext* cx, JS::HandleObject obj);
bool
XPC_WN_Shared_Enumerate(JSContext* cx, JS::HandleObject obj);

bool
XPC_WN_Helper_Resolve(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
                      bool* resolvedp);

void
XPC_WN_Helper_Finalize(js::FreeOp* fop, JSObject* obj);
void
XPC_WN_NoHelper_Finalize(js::FreeOp* fop, JSObject* obj);

bool
XPC_WN_Helper_Call(JSContext* cx, unsigned argc, JS::Value* vp);

bool
XPC_WN_Helper_HasInstance(JSContext* cx, JS::HandleObject obj,
                          JS::MutableHandleValue valp, bool* bp);

bool
XPC_WN_Helper_Construct(JSContext* cx, unsigned argc, JS::Value* vp);

void
XPCWrappedNative_Trace(JSTracer* trc, JSObject* obj);

extern const js::ClassExtension XPC_WN_JSClassExtension;

extern const js::ObjectOps XPC_WN_ObjectOpsWithEnumerate;

#define XPC_MAKE_CLASS_OPS(_flags) { \
    /* addProperty */ \
    ((_flags) & nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY) \
    ? nullptr \
    : ((_flags) & nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE) \
      ? XPC_WN_MaybeResolvingPropertyStub \
      : XPC_WN_CannotModifyPropertyStub, \
    \
    /* delProperty */ \
    ((_flags) & nsIXPCScriptable::USE_JSSTUB_FOR_DELPROPERTY) \
    ? nullptr \
    : ((_flags) & nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE) \
      ? XPC_WN_MaybeResolvingDeletePropertyStub \
      : XPC_WN_CantDeletePropertyStub, \
    \
    /* getProperty */ \
    ((_flags) & nsIXPCScriptable::WANT_GETPROPERTY) \
    ? XPC_WN_Helper_GetProperty \
    : nullptr, \
    \
    /* setProperty */ \
    ((_flags) & nsIXPCScriptable::WANT_SETPROPERTY) \
    ? XPC_WN_Helper_SetProperty \
    : ((_flags) & nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY) \
      ? nullptr \
      : ((_flags) & nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE) \
        ? XPC_WN_MaybeResolvingSetPropertyStub \
        : XPC_WN_CannotModifySetPropertyStub, \
    \
    /* enumerate */ \
    ((_flags) & nsIXPCScriptable::WANT_NEWENUMERATE) \
    ? nullptr /* We will use oOps->enumerate set below in this case */ \
    : ((_flags) & nsIXPCScriptable::WANT_ENUMERATE) \
      ? XPC_WN_Helper_Enumerate \
      : XPC_WN_Shared_Enumerate, \
    \
    /* resolve */ \
    /* We have to figure out resolve strategy at call time */ \
    XPC_WN_Helper_Resolve, \
    \
    /* mayResolve */ \
    nullptr, \
    \
    /* finalize */ \
    ((_flags) & nsIXPCScriptable::WANT_FINALIZE) \
    ? XPC_WN_Helper_Finalize \
    : XPC_WN_NoHelper_Finalize, \
    \
    /* call */ \
    ((_flags) & nsIXPCScriptable::WANT_CALL) \
    ? XPC_WN_Helper_Call \
    : nullptr, \
    \
    /* hasInstance */ \
    ((_flags) & nsIXPCScriptable::WANT_HASINSTANCE) \
    ? XPC_WN_Helper_HasInstance \
    : nullptr, \
    \
    /* construct */ \
    ((_flags) & nsIXPCScriptable::WANT_CONSTRUCT) \
    ? XPC_WN_Helper_Construct \
    : nullptr, \
    \
    /* trace */ \
    ((_flags) & nsIXPCScriptable::IS_GLOBAL_OBJECT) \
    ? JS_GlobalObjectTraceHook \
    : XPCWrappedNative_Trace, \
}

#define XPC_MAKE_CLASS(_name, _flags, _classOps) { \
    /* name */ \
    _name, \
    \
    /* flags */ \
    XPC_WRAPPER_FLAGS | \
    JSCLASS_PRIVATE_IS_NSISUPPORTS | \
    JSCLASS_IS_WRAPPED_NATIVE | \
    (((_flags) & nsIXPCScriptable::IS_GLOBAL_OBJECT) \
     ? XPCONNECT_GLOBAL_FLAGS \
     : 0), \
    \
    /* cOps */ \
    _classOps, \
    \
    /* spec */ \
    nullptr, \
    \
    /* ext */ \
    &XPC_WN_JSClassExtension, \
    \
    /* oOps */ \
    ((_flags) & nsIXPCScriptable::WANT_NEWENUMERATE) \
    ? &XPC_WN_ObjectOpsWithEnumerate \
    : nullptr, \
}

#endif