JavaScriptBase.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  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. #ifndef mozilla_jsipc_JavaScriptBase_h__
  7. #define mozilla_jsipc_JavaScriptBase_h__
  8. #include "WrapperAnswer.h"
  9. #include "WrapperOwner.h"
  10. #include "mozilla/dom/DOMTypes.h"
  11. #include "mozilla/jsipc/PJavaScript.h"
  12. namespace mozilla {
  13. namespace jsipc {
  14. template<class Base>
  15. class JavaScriptBase : public WrapperOwner, public WrapperAnswer, public Base
  16. {
  17. typedef WrapperAnswer Answer;
  18. public:
  19. virtual ~JavaScriptBase() {}
  20. virtual void ActorDestroy(WrapperOwner::ActorDestroyReason why) {
  21. WrapperOwner::ActorDestroy(why);
  22. }
  23. /*** IPC handlers ***/
  24. bool RecvPreventExtensions(const uint64_t& objId, ReturnStatus* rs) {
  25. return Answer::RecvPreventExtensions(ObjectId::deserialize(objId), rs);
  26. }
  27. bool RecvGetPropertyDescriptor(const uint64_t& objId, const JSIDVariant& id,
  28. ReturnStatus* rs,
  29. PPropertyDescriptor* out) {
  30. return Answer::RecvGetPropertyDescriptor(ObjectId::deserialize(objId), id, rs, out);
  31. }
  32. bool RecvGetOwnPropertyDescriptor(const uint64_t& objId,
  33. const JSIDVariant& id,
  34. ReturnStatus* rs,
  35. PPropertyDescriptor* out) {
  36. return Answer::RecvGetOwnPropertyDescriptor(ObjectId::deserialize(objId), id, rs, out);
  37. }
  38. bool RecvDefineProperty(const uint64_t& objId, const JSIDVariant& id,
  39. const PPropertyDescriptor& flags, ReturnStatus* rs) {
  40. return Answer::RecvDefineProperty(ObjectId::deserialize(objId), id, flags, rs);
  41. }
  42. bool RecvDelete(const uint64_t& objId, const JSIDVariant& id,
  43. ReturnStatus* rs) {
  44. return Answer::RecvDelete(ObjectId::deserialize(objId), id, rs);
  45. }
  46. bool RecvHas(const uint64_t& objId, const JSIDVariant& id,
  47. ReturnStatus* rs, bool* bp) {
  48. return Answer::RecvHas(ObjectId::deserialize(objId), id, rs, bp);
  49. }
  50. bool RecvHasOwn(const uint64_t& objId, const JSIDVariant& id,
  51. ReturnStatus* rs, bool* bp) {
  52. return Answer::RecvHasOwn(ObjectId::deserialize(objId), id, rs, bp);
  53. }
  54. bool RecvGet(const uint64_t& objId, const JSVariant& receiverVar, const JSIDVariant& id,
  55. ReturnStatus* rs, JSVariant* result) {
  56. return Answer::RecvGet(ObjectId::deserialize(objId), receiverVar, id, rs, result);
  57. }
  58. bool RecvSet(const uint64_t& objId, const JSIDVariant& id, const JSVariant& value,
  59. const JSVariant& receiverVar, ReturnStatus* rs) {
  60. return Answer::RecvSet(ObjectId::deserialize(objId), id, value, receiverVar, rs);
  61. }
  62. bool RecvIsExtensible(const uint64_t& objId, ReturnStatus* rs,
  63. bool* result) {
  64. return Answer::RecvIsExtensible(ObjectId::deserialize(objId), rs, result);
  65. }
  66. bool RecvCallOrConstruct(const uint64_t& objId, InfallibleTArray<JSParam>&& argv,
  67. const bool& construct, ReturnStatus* rs, JSVariant* result,
  68. nsTArray<JSParam>* outparams) {
  69. return Answer::RecvCallOrConstruct(ObjectId::deserialize(objId), Move(argv), construct, rs, result, outparams);
  70. }
  71. bool RecvHasInstance(const uint64_t& objId, const JSVariant& v, ReturnStatus* rs, bool* bp) {
  72. return Answer::RecvHasInstance(ObjectId::deserialize(objId), v, rs, bp);
  73. }
  74. bool RecvGetBuiltinClass(const uint64_t& objId, ReturnStatus* rs, uint32_t* classValue) {
  75. return Answer::RecvGetBuiltinClass(ObjectId::deserialize(objId), rs, classValue);
  76. }
  77. bool RecvIsArray(const uint64_t& objId, ReturnStatus* rs, uint32_t* answer) {
  78. return Answer::RecvIsArray(ObjectId::deserialize(objId), rs, answer);
  79. }
  80. bool RecvClassName(const uint64_t& objId, nsCString* result) {
  81. return Answer::RecvClassName(ObjectId::deserialize(objId), result);
  82. }
  83. bool RecvGetPrototype(const uint64_t& objId, ReturnStatus* rs, ObjectOrNullVariant* result) {
  84. return Answer::RecvGetPrototype(ObjectId::deserialize(objId), rs, result);
  85. }
  86. bool RecvGetPrototypeIfOrdinary(const uint64_t& objId, ReturnStatus* rs, bool* isOrdinary,
  87. ObjectOrNullVariant* result)
  88. {
  89. return Answer::RecvGetPrototypeIfOrdinary(ObjectId::deserialize(objId), rs, isOrdinary, result);
  90. }
  91. bool RecvRegExpToShared(const uint64_t& objId, ReturnStatus* rs, nsString* source, uint32_t* flags) {
  92. return Answer::RecvRegExpToShared(ObjectId::deserialize(objId), rs, source, flags);
  93. }
  94. bool RecvGetPropertyKeys(const uint64_t& objId, const uint32_t& flags,
  95. ReturnStatus* rs, nsTArray<JSIDVariant>* ids) {
  96. return Answer::RecvGetPropertyKeys(ObjectId::deserialize(objId), flags, rs, ids);
  97. }
  98. bool RecvInstanceOf(const uint64_t& objId, const JSIID& iid,
  99. ReturnStatus* rs, bool* instanceof) {
  100. return Answer::RecvInstanceOf(ObjectId::deserialize(objId), iid, rs, instanceof);
  101. }
  102. bool RecvDOMInstanceOf(const uint64_t& objId, const int& prototypeID, const int& depth,
  103. ReturnStatus* rs, bool* instanceof) {
  104. return Answer::RecvDOMInstanceOf(ObjectId::deserialize(objId), prototypeID, depth, rs, instanceof);
  105. }
  106. bool RecvDropObject(const uint64_t& objId) {
  107. return Answer::RecvDropObject(ObjectId::deserialize(objId));
  108. }
  109. /*** Dummy call handlers ***/
  110. bool SendDropObject(const ObjectId& objId) {
  111. return Base::SendDropObject(objId.serialize());
  112. }
  113. bool SendPreventExtensions(const ObjectId& objId, ReturnStatus* rs) {
  114. return Base::SendPreventExtensions(objId.serialize(), rs);
  115. }
  116. bool SendGetPropertyDescriptor(const ObjectId& objId, const JSIDVariant& id,
  117. ReturnStatus* rs,
  118. PPropertyDescriptor* out) {
  119. return Base::SendGetPropertyDescriptor(objId.serialize(), id, rs, out);
  120. }
  121. bool SendGetOwnPropertyDescriptor(const ObjectId& objId,
  122. const JSIDVariant& id,
  123. ReturnStatus* rs,
  124. PPropertyDescriptor* out) {
  125. return Base::SendGetOwnPropertyDescriptor(objId.serialize(), id, rs, out);
  126. }
  127. bool SendDefineProperty(const ObjectId& objId, const JSIDVariant& id,
  128. const PPropertyDescriptor& flags,
  129. ReturnStatus* rs) {
  130. return Base::SendDefineProperty(objId.serialize(), id, flags, rs);
  131. }
  132. bool SendDelete(const ObjectId& objId, const JSIDVariant& id, ReturnStatus* rs) {
  133. return Base::SendDelete(objId.serialize(), id, rs);
  134. }
  135. bool SendHas(const ObjectId& objId, const JSIDVariant& id,
  136. ReturnStatus* rs, bool* bp) {
  137. return Base::SendHas(objId.serialize(), id, rs, bp);
  138. }
  139. bool SendHasOwn(const ObjectId& objId, const JSIDVariant& id,
  140. ReturnStatus* rs, bool* bp) {
  141. return Base::SendHasOwn(objId.serialize(), id, rs, bp);
  142. }
  143. bool SendGet(const ObjectId& objId, const JSVariant& receiverVar, const JSIDVariant& id,
  144. ReturnStatus* rs, JSVariant* result) {
  145. return Base::SendGet(objId.serialize(), receiverVar, id, rs, result);
  146. }
  147. bool SendSet(const ObjectId& objId, const JSIDVariant& id, const JSVariant& value,
  148. const JSVariant& receiverVar, ReturnStatus* rs) {
  149. return Base::SendSet(objId.serialize(), id, value, receiverVar, rs);
  150. }
  151. bool SendIsExtensible(const ObjectId& objId, ReturnStatus* rs,
  152. bool* result) {
  153. return Base::SendIsExtensible(objId.serialize(), rs, result);
  154. }
  155. bool SendCallOrConstruct(const ObjectId& objId, const nsTArray<JSParam>& argv,
  156. const bool& construct, ReturnStatus* rs, JSVariant* result,
  157. nsTArray<JSParam>* outparams) {
  158. return Base::SendCallOrConstruct(objId.serialize(), argv, construct, rs, result, outparams);
  159. }
  160. bool SendHasInstance(const ObjectId& objId, const JSVariant& v, ReturnStatus* rs, bool* bp) {
  161. return Base::SendHasInstance(objId.serialize(), v, rs, bp);
  162. }
  163. bool SendGetBuiltinClass(const ObjectId& objId, ReturnStatus* rs, uint32_t* classValue) {
  164. return Base::SendGetBuiltinClass(objId.serialize(), rs, classValue);
  165. }
  166. bool SendIsArray(const ObjectId& objId, ReturnStatus* rs, uint32_t* answer)
  167. {
  168. return Base::SendIsArray(objId.serialize(), rs, answer);
  169. }
  170. bool SendClassName(const ObjectId& objId, nsCString* result) {
  171. return Base::SendClassName(objId.serialize(), result);
  172. }
  173. bool SendGetPrototype(const ObjectId& objId, ReturnStatus* rs, ObjectOrNullVariant* result) {
  174. return Base::SendGetPrototype(objId.serialize(), rs, result);
  175. }
  176. bool SendGetPrototypeIfOrdinary(const ObjectId& objId, ReturnStatus* rs, bool* isOrdinary,
  177. ObjectOrNullVariant* result)
  178. {
  179. return Base::SendGetPrototypeIfOrdinary(objId.serialize(), rs, isOrdinary, result);
  180. }
  181. bool SendRegExpToShared(const ObjectId& objId, ReturnStatus* rs,
  182. nsString* source, uint32_t* flags) {
  183. return Base::SendRegExpToShared(objId.serialize(), rs, source, flags);
  184. }
  185. bool SendGetPropertyKeys(const ObjectId& objId, const uint32_t& flags,
  186. ReturnStatus* rs, nsTArray<JSIDVariant>* ids) {
  187. return Base::SendGetPropertyKeys(objId.serialize(), flags, rs, ids);
  188. }
  189. bool SendInstanceOf(const ObjectId& objId, const JSIID& iid,
  190. ReturnStatus* rs, bool* instanceof) {
  191. return Base::SendInstanceOf(objId.serialize(), iid, rs, instanceof);
  192. }
  193. bool SendDOMInstanceOf(const ObjectId& objId, const int& prototypeID, const int& depth,
  194. ReturnStatus* rs, bool* instanceof) {
  195. return Base::SendDOMInstanceOf(objId.serialize(), prototypeID, depth, rs, instanceof);
  196. }
  197. /* The following code is needed to suppress a bogus MSVC warning (C4250). */
  198. virtual bool toObjectVariant(JSContext* cx, JSObject* obj, ObjectVariant* objVarp) {
  199. return WrapperOwner::toObjectVariant(cx, obj, objVarp);
  200. }
  201. virtual JSObject* fromObjectVariant(JSContext* cx, const ObjectVariant& objVar) {
  202. return WrapperOwner::fromObjectVariant(cx, objVar);
  203. }
  204. };
  205. } // namespace jsipc
  206. } // namespace mozilla
  207. #endif