1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sw=2 et tw=80:
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef mozilla_jsipc_JavaScriptBase_h__
9 #define mozilla_jsipc_JavaScriptBase_h__
11 #include "WrapperAnswer.h"
12 #include "WrapperOwner.h"
13 #include "mozilla/dom/DOMTypes.h"
14 #include "mozilla/jsipc/PJavaScript.h"
20 class JavaScriptBase
: public WrapperOwner
, public WrapperAnswer
, public Base
{
21 typedef WrapperAnswer Answer
;
24 virtual ~JavaScriptBase() {}
26 virtual void ActorDestroy(WrapperOwner::ActorDestroyReason why
) override
{
27 WrapperOwner::ActorDestroy(why
);
30 /*** IPC handlers ***/
32 mozilla::ipc::IPCResult
RecvPreventExtensions(const uint64_t& objId
,
33 ReturnStatus
* rs
) override
{
34 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
35 if (obj
.isNothing() || !Answer::RecvPreventExtensions(obj
.value(), rs
)) {
36 return IPC_FAIL_NO_REASON(this);
40 mozilla::ipc::IPCResult
RecvGetOwnPropertyDescriptor(
41 const uint64_t& objId
, const JSIDVariant
& id
, ReturnStatus
* rs
,
42 PPropertyDescriptor
* out
) override
{
43 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
44 if (obj
.isNothing() ||
45 !Answer::RecvGetOwnPropertyDescriptor(obj
.value(), id
, rs
, out
)) {
46 return IPC_FAIL_NO_REASON(this);
50 mozilla::ipc::IPCResult
RecvDefineProperty(const uint64_t& objId
,
51 const JSIDVariant
& id
,
52 const PPropertyDescriptor
& flags
,
53 ReturnStatus
* rs
) override
{
54 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
55 if (obj
.isNothing() ||
56 !Answer::RecvDefineProperty(obj
.value(), id
, flags
, rs
)) {
57 return IPC_FAIL_NO_REASON(this);
61 mozilla::ipc::IPCResult
RecvDelete(const uint64_t& objId
,
62 const JSIDVariant
& id
,
63 ReturnStatus
* rs
) override
{
64 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
65 if (obj
.isNothing() || !Answer::RecvDelete(obj
.value(), id
, rs
)) {
66 return IPC_FAIL_NO_REASON(this);
71 mozilla::ipc::IPCResult
RecvHas(const uint64_t& objId
, const JSIDVariant
& id
,
72 ReturnStatus
* rs
, bool* bp
) override
{
73 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
74 if (obj
.isNothing() || !Answer::RecvHas(obj
.value(), id
, rs
, bp
)) {
75 return IPC_FAIL_NO_REASON(this);
79 mozilla::ipc::IPCResult
RecvHasOwn(const uint64_t& objId
,
80 const JSIDVariant
& id
, ReturnStatus
* rs
,
82 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
83 if (obj
.isNothing() || !Answer::RecvHasOwn(obj
.value(), id
, rs
, bp
)) {
84 return IPC_FAIL_NO_REASON(this);
88 mozilla::ipc::IPCResult
RecvGet(const uint64_t& objId
,
89 const JSVariant
& receiverVar
,
90 const JSIDVariant
& id
, ReturnStatus
* rs
,
91 JSVariant
* result
) override
{
92 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
93 if (obj
.isNothing() ||
94 !Answer::RecvGet(obj
.value(), receiverVar
, id
, rs
, result
)) {
95 return IPC_FAIL_NO_REASON(this);
99 mozilla::ipc::IPCResult
RecvSet(const uint64_t& objId
, const JSIDVariant
& id
,
100 const JSVariant
& value
,
101 const JSVariant
& receiverVar
,
102 ReturnStatus
* rs
) override
{
103 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
104 if (obj
.isNothing() ||
105 !Answer::RecvSet(obj
.value(), id
, value
, receiverVar
, rs
)) {
106 return IPC_FAIL_NO_REASON(this);
111 mozilla::ipc::IPCResult
RecvIsExtensible(const uint64_t& objId
,
113 bool* result
) override
{
114 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
115 if (obj
.isNothing() || !Answer::RecvIsExtensible(obj
.value(), rs
, result
)) {
116 return IPC_FAIL_NO_REASON(this);
120 mozilla::ipc::IPCResult
RecvCallOrConstruct(
121 const uint64_t& objId
, nsTArray
<JSParam
>&& argv
, const bool& construct
,
122 ReturnStatus
* rs
, JSVariant
* result
,
123 nsTArray
<JSParam
>* outparams
) override
{
124 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
125 if (obj
.isNothing() ||
126 !Answer::RecvCallOrConstruct(obj
.value(), std::move(argv
), construct
,
127 rs
, result
, outparams
)) {
128 return IPC_FAIL_NO_REASON(this);
132 mozilla::ipc::IPCResult
RecvHasInstance(const uint64_t& objId
,
133 const JSVariant
& v
, ReturnStatus
* rs
,
135 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
136 if (obj
.isNothing() || !Answer::RecvHasInstance(obj
.value(), v
, rs
, bp
)) {
137 return IPC_FAIL_NO_REASON(this);
141 mozilla::ipc::IPCResult
RecvGetBuiltinClass(const uint64_t& objId
,
143 uint32_t* classValue
) override
{
144 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
145 if (obj
.isNothing() ||
146 !Answer::RecvGetBuiltinClass(obj
.value(), rs
, classValue
)) {
147 return IPC_FAIL_NO_REASON(this);
151 mozilla::ipc::IPCResult
RecvIsArray(const uint64_t& objId
, ReturnStatus
* rs
,
152 uint32_t* answer
) override
{
153 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
154 if (obj
.isNothing() || !Answer::RecvIsArray(obj
.value(), rs
, answer
)) {
155 return IPC_FAIL_NO_REASON(this);
159 mozilla::ipc::IPCResult
RecvClassName(const uint64_t& objId
,
160 nsCString
* result
) override
{
161 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
162 if (obj
.isNothing() || !Answer::RecvClassName(obj
.value(), result
)) {
163 return IPC_FAIL_NO_REASON(this);
167 mozilla::ipc::IPCResult
RecvGetPrototype(
168 const uint64_t& objId
, ReturnStatus
* rs
,
169 ObjectOrNullVariant
* result
) override
{
170 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
171 if (obj
.isNothing() || !Answer::RecvGetPrototype(obj
.value(), rs
, result
)) {
172 return IPC_FAIL_NO_REASON(this);
176 mozilla::ipc::IPCResult
RecvGetPrototypeIfOrdinary(
177 const uint64_t& objId
, ReturnStatus
* rs
, bool* isOrdinary
,
178 ObjectOrNullVariant
* result
) override
{
179 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
180 if (obj
.isNothing() || !Answer::RecvGetPrototypeIfOrdinary(
181 obj
.value(), rs
, isOrdinary
, result
)) {
182 return IPC_FAIL_NO_REASON(this);
186 mozilla::ipc::IPCResult
RecvRegExpToShared(const uint64_t& objId
,
187 ReturnStatus
* rs
, nsString
* source
,
188 uint32_t* flags
) override
{
189 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
190 if (obj
.isNothing() ||
191 !Answer::RecvRegExpToShared(obj
.value(), rs
, source
, flags
)) {
192 return IPC_FAIL_NO_REASON(this);
197 mozilla::ipc::IPCResult
RecvGetPropertyKeys(
198 const uint64_t& objId
, const uint32_t& flags
, ReturnStatus
* rs
,
199 nsTArray
<JSIDVariant
>* ids
) override
{
200 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
201 if (obj
.isNothing() ||
202 !Answer::RecvGetPropertyKeys(obj
.value(), flags
, rs
, ids
)) {
203 return IPC_FAIL_NO_REASON(this);
207 mozilla::ipc::IPCResult
RecvInstanceOf(const uint64_t& objId
,
208 const JSIID
& iid
, ReturnStatus
* rs
,
209 bool* instanceof
) override
{
210 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
211 if (obj
.isNothing() ||
212 !Answer::RecvInstanceOf(obj
.value(), iid
, rs
, instanceof
)) {
213 return IPC_FAIL_NO_REASON(this);
217 mozilla::ipc::IPCResult
RecvDOMInstanceOf(const uint64_t& objId
,
218 const int& prototypeID
,
219 const int& depth
, ReturnStatus
* rs
,
220 bool* instanceof
) override
{
221 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
222 if (obj
.isNothing() ||
223 !Answer::RecvDOMInstanceOf(obj
.value(), prototypeID
, depth
, rs
,
225 return IPC_FAIL_NO_REASON(this);
230 mozilla::ipc::IPCResult
RecvDropObject(const uint64_t& objId
) override
{
231 Maybe
<ObjectId
> obj(ObjectId::deserialize(objId
));
232 if (obj
.isNothing() || !Answer::RecvDropObject(obj
.value())) {
233 return IPC_FAIL_NO_REASON(this);
238 /*** Dummy call handlers ***/
240 bool SendDropObject(const ObjectId
& objId
) override
{
241 return Base::SendDropObject(objId
.serialize());
243 bool SendPreventExtensions(const ObjectId
& objId
, ReturnStatus
* rs
) override
{
244 return Base::SendPreventExtensions(objId
.serialize(), rs
);
246 bool SendGetOwnPropertyDescriptor(const ObjectId
& objId
,
247 const JSIDVariant
& id
, ReturnStatus
* rs
,
248 PPropertyDescriptor
* out
) override
{
249 return Base::SendGetOwnPropertyDescriptor(objId
.serialize(), id
, rs
, out
);
251 bool SendDefineProperty(const ObjectId
& objId
, const JSIDVariant
& id
,
252 const PPropertyDescriptor
& flags
,
253 ReturnStatus
* rs
) override
{
254 return Base::SendDefineProperty(objId
.serialize(), id
, flags
, rs
);
256 bool SendDelete(const ObjectId
& objId
, const JSIDVariant
& id
,
257 ReturnStatus
* rs
) override
{
258 return Base::SendDelete(objId
.serialize(), id
, rs
);
261 bool SendHas(const ObjectId
& objId
, const JSIDVariant
& id
, ReturnStatus
* rs
,
263 return Base::SendHas(objId
.serialize(), id
, rs
, bp
);
265 bool SendHasOwn(const ObjectId
& objId
, const JSIDVariant
& id
,
266 ReturnStatus
* rs
, bool* bp
) override
{
267 return Base::SendHasOwn(objId
.serialize(), id
, rs
, bp
);
269 bool SendGet(const ObjectId
& objId
, const JSVariant
& receiverVar
,
270 const JSIDVariant
& id
, ReturnStatus
* rs
,
271 JSVariant
* result
) override
{
272 return Base::SendGet(objId
.serialize(), receiverVar
, id
, rs
, result
);
274 bool SendSet(const ObjectId
& objId
, const JSIDVariant
& id
,
275 const JSVariant
& value
, const JSVariant
& receiverVar
,
276 ReturnStatus
* rs
) override
{
277 return Base::SendSet(objId
.serialize(), id
, value
, receiverVar
, rs
);
280 bool SendIsExtensible(const ObjectId
& objId
, ReturnStatus
* rs
,
281 bool* result
) override
{
282 return Base::SendIsExtensible(objId
.serialize(), rs
, result
);
284 bool SendCallOrConstruct(const ObjectId
& objId
, const nsTArray
<JSParam
>& argv
,
285 const bool& construct
, ReturnStatus
* rs
,
287 nsTArray
<JSParam
>* outparams
) override
{
288 return Base::SendCallOrConstruct(objId
.serialize(), argv
, construct
, rs
,
291 bool SendHasInstance(const ObjectId
& objId
, const JSVariant
& v
,
292 ReturnStatus
* rs
, bool* bp
) override
{
293 return Base::SendHasInstance(objId
.serialize(), v
, rs
, bp
);
295 bool SendGetBuiltinClass(const ObjectId
& objId
, ReturnStatus
* rs
,
296 uint32_t* classValue
) override
{
297 return Base::SendGetBuiltinClass(objId
.serialize(), rs
, classValue
);
299 bool SendIsArray(const ObjectId
& objId
, ReturnStatus
* rs
,
300 uint32_t* answer
) override
{
301 return Base::SendIsArray(objId
.serialize(), rs
, answer
);
303 bool SendClassName(const ObjectId
& objId
, nsCString
* result
) override
{
304 return Base::SendClassName(objId
.serialize(), result
);
306 bool SendGetPrototype(const ObjectId
& objId
, ReturnStatus
* rs
,
307 ObjectOrNullVariant
* result
) override
{
308 return Base::SendGetPrototype(objId
.serialize(), rs
, result
);
310 bool SendGetPrototypeIfOrdinary(const ObjectId
& objId
, ReturnStatus
* rs
,
312 ObjectOrNullVariant
* result
) override
{
313 return Base::SendGetPrototypeIfOrdinary(objId
.serialize(), rs
, isOrdinary
,
317 bool SendRegExpToShared(const ObjectId
& objId
, ReturnStatus
* rs
,
318 nsString
* source
, uint32_t* flags
) override
{
319 return Base::SendRegExpToShared(objId
.serialize(), rs
, source
, flags
);
322 bool SendGetPropertyKeys(const ObjectId
& objId
, const uint32_t& flags
,
324 nsTArray
<JSIDVariant
>* ids
) override
{
325 return Base::SendGetPropertyKeys(objId
.serialize(), flags
, rs
, ids
);
327 bool SendInstanceOf(const ObjectId
& objId
, const JSIID
& iid
, ReturnStatus
* rs
,
328 bool* instanceof
) override
{
329 return Base::SendInstanceOf(objId
.serialize(), iid
, rs
, instanceof
);
331 bool SendDOMInstanceOf(const ObjectId
& objId
, const int& prototypeID
,
332 const int& depth
, ReturnStatus
* rs
,
333 bool* instanceof
) override
{
334 return Base::SendDOMInstanceOf(objId
.serialize(), prototypeID
, depth
, rs
,
338 /* The following code is needed to suppress a bogus MSVC warning (C4250). */
340 virtual bool toObjectVariant(JSContext
* cx
, JSObject
* obj
,
341 ObjectVariant
* objVarp
) override
{
342 return WrapperOwner::toObjectVariant(cx
, obj
, objVarp
);
344 virtual JSObject
* fromObjectVariant(JSContext
* cx
,
345 const ObjectVariant
& objVar
) override
{
346 return WrapperOwner::fromObjectVariant(cx
, objVar
);
351 } // namespace mozilla