johnson 1.2.0 → 2.0.0.pre0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (782) hide show
  1. data/CHANGELOG.rdoc +8 -0
  2. data/Manifest.txt +762 -48
  3. data/README.rdoc +2 -1
  4. data/Rakefile +90 -18
  5. data/ext/spidermonkey/conversions.c +9 -2
  6. data/ext/spidermonkey/ruby_land_proxy.c +1 -1
  7. data/ext/spidermonkey/runtime.h +1 -1
  8. data/ext/tracemonkey/context.cc +125 -0
  9. data/ext/tracemonkey/context.h +19 -0
  10. data/ext/tracemonkey/conversions.cc +365 -0
  11. data/ext/tracemonkey/conversions.h +32 -0
  12. data/ext/tracemonkey/debugger.cc +234 -0
  13. data/ext/tracemonkey/debugger.h +10 -0
  14. data/ext/tracemonkey/extconf.rb +37 -0
  15. data/ext/tracemonkey/extensions.cc +37 -0
  16. data/ext/tracemonkey/extensions.h +12 -0
  17. data/ext/tracemonkey/global.cc +40 -0
  18. data/ext/tracemonkey/global.h +11 -0
  19. data/ext/tracemonkey/idhash.cc +16 -0
  20. data/ext/tracemonkey/idhash.h +8 -0
  21. data/ext/tracemonkey/immutable_node.cc +1199 -0
  22. data/ext/tracemonkey/immutable_node.cc.erb +559 -0
  23. data/ext/tracemonkey/immutable_node.h +22 -0
  24. data/ext/tracemonkey/jroot.h +215 -0
  25. data/ext/tracemonkey/js_land_proxy.cc +620 -0
  26. data/ext/tracemonkey/js_land_proxy.h +20 -0
  27. data/ext/tracemonkey/ruby_land_proxy.cc +618 -0
  28. data/ext/tracemonkey/ruby_land_proxy.h +38 -0
  29. data/ext/tracemonkey/runtime.cc +454 -0
  30. data/ext/tracemonkey/runtime.h +27 -0
  31. data/ext/tracemonkey/split_global.cc +392 -0
  32. data/ext/tracemonkey/split_global.h +11 -0
  33. data/ext/tracemonkey/tracemonkey.cc +23 -0
  34. data/ext/tracemonkey/tracemonkey.h +32 -0
  35. data/lib/johnson.rb +12 -4
  36. data/lib/johnson/error.rb +5 -0
  37. data/lib/johnson/js/prelude.js +16 -1
  38. data/lib/johnson/parser.rb +2 -1
  39. data/lib/johnson/runtime.rb +87 -26
  40. data/lib/johnson/spidermonkey/runtime.rb +7 -16
  41. data/lib/johnson/tracemonkey.rb +13 -0
  42. data/lib/johnson/tracemonkey/context.rb +10 -0
  43. data/lib/johnson/tracemonkey/debugger.rb +67 -0
  44. data/lib/johnson/tracemonkey/immutable_node.rb +282 -0
  45. data/lib/johnson/tracemonkey/js_land_proxy.rb +64 -0
  46. data/lib/johnson/tracemonkey/mutable_tree_visitor.rb +242 -0
  47. data/lib/johnson/tracemonkey/ruby_land_proxy.rb +17 -0
  48. data/lib/johnson/tracemonkey/runtime.rb +80 -0
  49. data/test/{johnson_test.rb → generic/johnson_test.rb} +1 -1
  50. data/test/{parser_test.rb → generic/parser_test.rb} +1 -1
  51. data/test/helper.rb +23 -4
  52. data/test/johnson/{browser_test.rb → generic/browser_test.rb} +1 -1
  53. data/test/johnson/{conversions → generic/conversions}/array_test.rb +1 -1
  54. data/test/johnson/{conversions → generic/conversions}/boolean_test.rb +1 -1
  55. data/test/johnson/{conversions → generic/conversions}/callable_test.rb +1 -1
  56. data/test/johnson/{conversions → generic/conversions}/file_test.rb +1 -1
  57. data/test/johnson/generic/conversions/helper.rb +1 -0
  58. data/test/johnson/{conversions → generic/conversions}/nil_test.rb +1 -1
  59. data/test/johnson/{conversions → generic/conversions}/number_test.rb +1 -1
  60. data/test/johnson/{conversions → generic/conversions}/regexp_test.rb +1 -1
  61. data/test/johnson/{conversions → generic/conversions}/string_test.rb +1 -1
  62. data/test/johnson/{conversions → generic/conversions}/struct_test.rb +1 -1
  63. data/test/johnson/{conversions → generic/conversions}/symbol_test.rb +1 -1
  64. data/test/johnson/{conversions → generic/conversions}/thread_test.rb +1 -1
  65. data/test/johnson/{custom_conversions_test.rb → generic/custom_conversions_test.rb} +1 -1
  66. data/test/johnson/generic/default_test.rb +12 -0
  67. data/test/johnson/{error_test.rb → generic/error_test.rb} +1 -1
  68. data/test/johnson/{extensions_test.rb → generic/extensions_test.rb} +1 -1
  69. data/test/johnson/generic/helper.rb +1 -0
  70. data/test/johnson/{nodes → generic/nodes}/array_literal_test.rb +1 -1
  71. data/test/johnson/{nodes → generic/nodes}/array_node_test.rb +1 -1
  72. data/test/johnson/{nodes → generic/nodes}/binary_node_test.rb +1 -1
  73. data/test/johnson/{nodes → generic/nodes}/bracket_access_test.rb +1 -1
  74. data/test/johnson/{nodes → generic/nodes}/delete_test.rb +1 -1
  75. data/test/johnson/{nodes → generic/nodes}/do_while_test.rb +1 -1
  76. data/test/johnson/{nodes → generic/nodes}/dot_accessor_test.rb +1 -1
  77. data/test/johnson/generic/nodes/export_test.rb +11 -0
  78. data/test/johnson/{nodes → generic/nodes}/for_test.rb +1 -1
  79. data/test/johnson/{nodes → generic/nodes}/function_test.rb +1 -1
  80. data/test/johnson/generic/nodes/helper.rb +1 -0
  81. data/test/johnson/{nodes → generic/nodes}/if_test.rb +16 -6
  82. data/test/johnson/generic/nodes/import_test.rb +15 -0
  83. data/test/johnson/{nodes → generic/nodes}/label_test.rb +1 -1
  84. data/test/johnson/{nodes → generic/nodes}/let_test.rb +1 -1
  85. data/test/johnson/{nodes → generic/nodes}/object_literal_test.rb +1 -1
  86. data/test/johnson/{nodes → generic/nodes}/return_test.rb +1 -1
  87. data/test/johnson/{nodes → generic/nodes}/semi_test.rb +1 -1
  88. data/test/johnson/{nodes → generic/nodes}/switch_test.rb +1 -1
  89. data/test/johnson/{nodes → generic/nodes}/ternary_test.rb +1 -1
  90. data/test/johnson/{nodes → generic/nodes}/throw_test.rb +1 -1
  91. data/test/johnson/{nodes → generic/nodes}/try_node_test.rb +36 -6
  92. data/test/johnson/{nodes → generic/nodes}/typeof_test.rb +1 -1
  93. data/test/johnson/{nodes → generic/nodes}/unary_node_test.rb +1 -1
  94. data/test/johnson/{nodes → generic/nodes}/void_test.rb +1 -1
  95. data/test/johnson/{nodes → generic/nodes}/while_test.rb +1 -1
  96. data/test/johnson/{nodes → generic/nodes}/with_test.rb +1 -1
  97. data/test/johnson/{prelude_test.rb → generic/prelude_test.rb} +1 -1
  98. data/test/johnson/{runtime_test.rb → generic/runtime_test.rb} +3 -6
  99. data/test/johnson/generic/version_test.rb +13 -0
  100. data/test/johnson/{visitors → generic/visitors}/dot_visitor_test.rb +1 -1
  101. data/test/johnson/{visitors → generic/visitors}/enumerating_visitor_test.rb +1 -1
  102. data/test/johnson/generic/visitors/helper.rb +1 -0
  103. data/test/johnson/spidermonkey/js_land_proxy_test.rb +1 -5
  104. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +11 -7
  105. data/test/johnson/tracemonkey/context_test.rb +21 -0
  106. data/test/johnson/tracemonkey/immutable_node_test.rb +34 -0
  107. data/test/johnson/tracemonkey/js_land_proxy_test.rb +273 -0
  108. data/test/johnson/tracemonkey/ruby_land_proxy_test.rb +274 -0
  109. data/test/johnson/tracemonkey/runtime_test.rb +41 -0
  110. data/test/johnson/tracemonkey/split_global_test.rb +32 -0
  111. data/vendor/spidermonkey/js.pkg +2 -0
  112. data/vendor/tracemonkey/Makefile.in +668 -0
  113. data/vendor/tracemonkey/Makefile.ref +483 -0
  114. data/vendor/tracemonkey/README.html +54 -0
  115. data/vendor/tracemonkey/SpiderMonkey.rsp +11 -0
  116. data/vendor/tracemonkey/Y.js +19 -0
  117. data/vendor/tracemonkey/aclocal.m4 +9 -0
  118. data/vendor/tracemonkey/bench.sh +5 -0
  119. data/vendor/tracemonkey/build/autoconf/acoutput-fast.pl +202 -0
  120. data/vendor/tracemonkey/build/autoconf/altoptions.m4 +154 -0
  121. data/vendor/tracemonkey/build/autoconf/config.guess +1537 -0
  122. data/vendor/tracemonkey/build/autoconf/config.sub +1595 -0
  123. data/vendor/tracemonkey/build/autoconf/install-sh +119 -0
  124. data/vendor/tracemonkey/build/autoconf/make-makefile +315 -0
  125. data/vendor/tracemonkey/build/autoconf/match-dir.sh +101 -0
  126. data/vendor/tracemonkey/build/autoconf/moznbytetype.m4 +136 -0
  127. data/vendor/tracemonkey/build/autoconf/nspr.m4 +82 -0
  128. data/vendor/tracemonkey/build/autoconf/pkg.m4 +59 -0
  129. data/vendor/tracemonkey/build/autoconf/update-makefile.sh +118 -0
  130. data/vendor/tracemonkey/build/cygwin-wrapper +75 -0
  131. data/vendor/tracemonkey/build/hcc +111 -0
  132. data/vendor/tracemonkey/build/hcpp +155 -0
  133. data/vendor/tracemonkey/build/unix/mddepend.pl +165 -0
  134. data/vendor/tracemonkey/build/unix/uniq.pl +63 -0
  135. data/vendor/tracemonkey/build/win32/pgomerge.py +40 -0
  136. data/vendor/tracemonkey/builtins.tbl +91 -0
  137. data/vendor/tracemonkey/call.js +13 -0
  138. data/vendor/tracemonkey/config.mk +206 -0
  139. data/vendor/tracemonkey/config/Makefile.in +106 -0
  140. data/vendor/tracemonkey/config/Moz/Milestone.pm +232 -0
  141. data/vendor/tracemonkey/config/autoconf.mk.in +362 -0
  142. data/vendor/tracemonkey/config/check-sync-dirs.py +103 -0
  143. data/vendor/tracemonkey/config/check-sync-exceptions +7 -0
  144. data/vendor/tracemonkey/config/config.mk +881 -0
  145. data/vendor/tracemonkey/config/fastcwd.pl +66 -0
  146. data/vendor/tracemonkey/config/gcc_hidden.h +2 -0
  147. data/vendor/tracemonkey/config/insure.mk +53 -0
  148. data/vendor/tracemonkey/config/make-system-wrappers.pl +59 -0
  149. data/vendor/tracemonkey/config/milestone.pl +112 -0
  150. data/vendor/tracemonkey/config/milestone.txt +13 -0
  151. data/vendor/tracemonkey/config/mkdepend/Makefile.in +84 -0
  152. data/vendor/tracemonkey/config/mkdepend/cppsetup.c +233 -0
  153. data/vendor/tracemonkey/config/mkdepend/def.h +184 -0
  154. data/vendor/tracemonkey/config/mkdepend/ifparser.c +551 -0
  155. data/vendor/tracemonkey/config/mkdepend/ifparser.h +83 -0
  156. data/vendor/tracemonkey/config/mkdepend/imakemdep.h +733 -0
  157. data/vendor/tracemonkey/config/mkdepend/include.c +337 -0
  158. data/vendor/tracemonkey/config/mkdepend/main.c +860 -0
  159. data/vendor/tracemonkey/config/mkdepend/mkdepend.man +382 -0
  160. data/vendor/tracemonkey/config/mkdepend/parse.c +686 -0
  161. data/vendor/tracemonkey/config/mkdepend/pr.c +124 -0
  162. data/vendor/tracemonkey/config/nfspwd.pl +50 -0
  163. data/vendor/tracemonkey/config/nsinstall.c +481 -0
  164. data/vendor/tracemonkey/config/nsinstall.py +155 -0
  165. data/vendor/tracemonkey/config/pathsub.c +247 -0
  166. data/vendor/tracemonkey/config/pathsub.h +74 -0
  167. data/vendor/tracemonkey/config/preprocessor.pl +671 -0
  168. data/vendor/tracemonkey/config/revdepth-nt.pl +48 -0
  169. data/vendor/tracemonkey/config/revdepth.pl +51 -0
  170. data/vendor/tracemonkey/config/rules.mk +2310 -0
  171. data/vendor/tracemonkey/config/static-checking-config.mk +21 -0
  172. data/vendor/tracemonkey/config/static-checking.js +92 -0
  173. data/vendor/tracemonkey/config/string-format.js +61 -0
  174. data/vendor/tracemonkey/config/system-headers +1035 -0
  175. data/vendor/tracemonkey/config/version.mk +85 -0
  176. data/vendor/tracemonkey/config/version_win.pl +442 -0
  177. data/vendor/tracemonkey/configure +14183 -0
  178. data/vendor/tracemonkey/configure.in +5363 -0
  179. data/vendor/tracemonkey/correct.sh +23 -0
  180. data/vendor/tracemonkey/correct/check-3d-morph.js +55 -0
  181. data/vendor/tracemonkey/correct/check-3d-raytrace.js +445 -0
  182. data/vendor/tracemonkey/correct/check-access-binary-trees.js +52 -0
  183. data/vendor/tracemonkey/correct/check-access-fannkuch.js +66 -0
  184. data/vendor/tracemonkey/correct/check-access-nbody.js +171 -0
  185. data/vendor/tracemonkey/correct/check-access-nsieve.js +40 -0
  186. data/vendor/tracemonkey/correct/check-bitops-3bit-bits-in-byte.js +35 -0
  187. data/vendor/tracemonkey/correct/check-bitops-bits-in-byte.js +24 -0
  188. data/vendor/tracemonkey/correct/check-bitops-bitwise-and.js +29 -0
  189. data/vendor/tracemonkey/correct/check-bitops-nsieve-bits.js +40 -0
  190. data/vendor/tracemonkey/correct/check-controlflow-recursive.js +27 -0
  191. data/vendor/tracemonkey/correct/check-date-format-tofte.js +302 -0
  192. data/vendor/tracemonkey/correct/check-date-format-xparb.js +421 -0
  193. data/vendor/tracemonkey/correct/check-mont.js +119 -0
  194. data/vendor/tracemonkey/dtoa.c +3335 -0
  195. data/vendor/tracemonkey/editline/Makefile.in +55 -0
  196. data/vendor/tracemonkey/editline/Makefile.ref +143 -0
  197. data/vendor/tracemonkey/editline/README +83 -0
  198. data/vendor/tracemonkey/editline/editline.3 +175 -0
  199. data/vendor/tracemonkey/editline/editline.c +1371 -0
  200. data/vendor/tracemonkey/editline/editline.h +135 -0
  201. data/vendor/tracemonkey/editline/sysunix.c +182 -0
  202. data/vendor/tracemonkey/editline/unix.h +82 -0
  203. data/vendor/tracemonkey/if.js +13 -0
  204. data/vendor/tracemonkey/imacro_asm.js.in +396 -0
  205. data/vendor/tracemonkey/imacros.c.out +1034 -0
  206. data/vendor/tracemonkey/imacros.jsasm +770 -0
  207. data/vendor/tracemonkey/javascript-trace.d +73 -0
  208. data/vendor/tracemonkey/jitstats.tbl +55 -0
  209. data/vendor/tracemonkey/js-config.h.in +82 -0
  210. data/vendor/tracemonkey/js-config.in +111 -0
  211. data/vendor/tracemonkey/js.mdp +0 -0
  212. data/vendor/tracemonkey/js.msg +312 -0
  213. data/vendor/tracemonkey/js3240.rc +79 -0
  214. data/vendor/tracemonkey/jsOS240.def +654 -0
  215. data/vendor/tracemonkey/jsapi.cpp +6005 -0
  216. data/vendor/tracemonkey/jsapi.h +2727 -0
  217. data/vendor/tracemonkey/jsarena.cpp +450 -0
  218. data/vendor/tracemonkey/jsarena.h +318 -0
  219. data/vendor/tracemonkey/jsarray.cpp +3664 -0
  220. data/vendor/tracemonkey/jsarray.h +238 -0
  221. data/vendor/tracemonkey/jsatom.cpp +1244 -0
  222. data/vendor/tracemonkey/jsatom.h +493 -0
  223. data/vendor/tracemonkey/jsbit.h +249 -0
  224. data/vendor/tracemonkey/jsbool.cpp +184 -0
  225. data/vendor/tracemonkey/jsbool.h +88 -0
  226. data/vendor/tracemonkey/jsbuiltins.cpp +415 -0
  227. data/vendor/tracemonkey/jsbuiltins.h +456 -0
  228. data/vendor/tracemonkey/jsclist.h +139 -0
  229. data/vendor/tracemonkey/jscntxt.cpp +1816 -0
  230. data/vendor/tracemonkey/jscntxt.h +1541 -0
  231. data/vendor/tracemonkey/jscompat.h +57 -0
  232. data/vendor/tracemonkey/jsconfig.mk +181 -0
  233. data/vendor/tracemonkey/jscpucfg.cpp +194 -0
  234. data/vendor/tracemonkey/jscpucfg.h +91 -0
  235. data/vendor/tracemonkey/jsdate.cpp +2465 -0
  236. data/vendor/tracemonkey/jsdate.h +129 -0
  237. data/vendor/tracemonkey/jsdbgapi.cpp +2017 -0
  238. data/vendor/tracemonkey/jsdbgapi.h +500 -0
  239. data/vendor/tracemonkey/jsdhash.cpp +876 -0
  240. data/vendor/tracemonkey/jsdhash.h +588 -0
  241. data/vendor/tracemonkey/jsdtoa.cpp +572 -0
  242. data/vendor/tracemonkey/jsdtoa.h +131 -0
  243. data/vendor/tracemonkey/jsdtracef.c +318 -0
  244. data/vendor/tracemonkey/jsdtracef.h +81 -0
  245. data/vendor/tracemonkey/jsemit.cpp +7292 -0
  246. data/vendor/tracemonkey/jsemit.h +802 -0
  247. data/vendor/tracemonkey/jsexn.cpp +1337 -0
  248. data/vendor/tracemonkey/jsexn.h +96 -0
  249. data/vendor/tracemonkey/jsfile.cpp +2747 -0
  250. data/vendor/tracemonkey/jsfile.h +56 -0
  251. data/vendor/tracemonkey/jsfile.msg +90 -0
  252. data/vendor/tracemonkey/jsfun.cpp +3089 -0
  253. data/vendor/tracemonkey/jsfun.h +366 -0
  254. data/vendor/tracemonkey/jsgc.cpp +3816 -0
  255. data/vendor/tracemonkey/jsgc.h +429 -0
  256. data/vendor/tracemonkey/jshash.cpp +477 -0
  257. data/vendor/tracemonkey/jshash.h +151 -0
  258. data/vendor/tracemonkey/jsify.pl +483 -0
  259. data/vendor/tracemonkey/jsinterp.cpp +7441 -0
  260. data/vendor/tracemonkey/jsinterp.h +666 -0
  261. data/vendor/tracemonkey/jsinvoke.cpp +42 -0
  262. data/vendor/tracemonkey/jsiter.cpp +1040 -0
  263. data/vendor/tracemonkey/jsiter.h +140 -0
  264. data/vendor/tracemonkey/jskeyword.tbl +124 -0
  265. data/vendor/tracemonkey/jskwgen.cpp +460 -0
  266. data/vendor/tracemonkey/jslibmath.h +69 -0
  267. data/vendor/tracemonkey/jslock.cpp +1512 -0
  268. data/vendor/tracemonkey/jslock.h +325 -0
  269. data/vendor/tracemonkey/jslocko.asm +60 -0
  270. data/vendor/tracemonkey/jslog2.cpp +111 -0
  271. data/vendor/tracemonkey/jslong.h +167 -0
  272. data/vendor/tracemonkey/jsmath.cpp +806 -0
  273. data/vendor/tracemonkey/jsmath.h +63 -0
  274. data/vendor/tracemonkey/jsnum.cpp +1374 -0
  275. data/vendor/tracemonkey/jsnum.h +280 -0
  276. data/vendor/tracemonkey/jsobj.cpp +6165 -0
  277. data/vendor/tracemonkey/jsobj.h +870 -0
  278. data/vendor/tracemonkey/json.cpp +1338 -0
  279. data/vendor/tracemonkey/json.h +108 -0
  280. data/vendor/tracemonkey/jsopcode.cpp +5484 -0
  281. data/vendor/tracemonkey/jsopcode.h +434 -0
  282. data/vendor/tracemonkey/jsopcode.tbl +591 -0
  283. data/vendor/tracemonkey/jsoplengen.cpp +121 -0
  284. data/vendor/tracemonkey/jsotypes.h +202 -0
  285. data/vendor/tracemonkey/jsparse.cpp +9257 -0
  286. data/vendor/tracemonkey/jsparse.h +900 -0
  287. data/vendor/tracemonkey/jsprf.cpp +1262 -0
  288. data/vendor/tracemonkey/jsprf.h +150 -0
  289. data/vendor/tracemonkey/jsproto.tbl +117 -0
  290. data/vendor/tracemonkey/jsprvtd.h +366 -0
  291. data/vendor/tracemonkey/jspubtd.h +585 -0
  292. data/vendor/tracemonkey/jsregexp.cpp +5051 -0
  293. data/vendor/tracemonkey/jsregexp.h +199 -0
  294. data/vendor/tracemonkey/jsreops.tbl +145 -0
  295. data/vendor/tracemonkey/jsscan.cpp +2040 -0
  296. data/vendor/tracemonkey/jsscan.h +467 -0
  297. data/vendor/tracemonkey/jsscope.cpp +1966 -0
  298. data/vendor/tracemonkey/jsscope.h +487 -0
  299. data/vendor/tracemonkey/jsscript.cpp +1932 -0
  300. data/vendor/tracemonkey/jsscript.h +345 -0
  301. data/vendor/tracemonkey/jsshell.msg +54 -0
  302. data/vendor/tracemonkey/jsstack.js +167 -0
  303. data/vendor/tracemonkey/jsstaticcheck.h +69 -0
  304. data/vendor/tracemonkey/jsstddef.h +87 -0
  305. data/vendor/tracemonkey/jsstdint.h +96 -0
  306. data/vendor/tracemonkey/jsstr.cpp +5277 -0
  307. data/vendor/tracemonkey/jsstr.h +702 -0
  308. data/vendor/tracemonkey/jstracer.cpp +10991 -0
  309. data/vendor/tracemonkey/jstracer.h +794 -0
  310. data/vendor/tracemonkey/jstypes.h +481 -0
  311. data/vendor/tracemonkey/jsutil.cpp +361 -0
  312. data/vendor/tracemonkey/jsutil.h +178 -0
  313. data/vendor/tracemonkey/jsversion.h +243 -0
  314. data/vendor/tracemonkey/jswince.asm +44 -0
  315. data/vendor/tracemonkey/jsxdrapi.cpp +800 -0
  316. data/vendor/tracemonkey/jsxdrapi.h +220 -0
  317. data/vendor/tracemonkey/jsxml.cpp +8327 -0
  318. data/vendor/tracemonkey/jsxml.h +305 -0
  319. data/vendor/tracemonkey/liveconnect/LiveConnect.dsp +157 -0
  320. data/vendor/tracemonkey/liveconnect/LiveConnectShell.dsp +120 -0
  321. data/vendor/tracemonkey/liveconnect/LiveConnectShell.dsw +44 -0
  322. data/vendor/tracemonkey/liveconnect/Makefile.in +105 -0
  323. data/vendor/tracemonkey/liveconnect/Makefile.ref +169 -0
  324. data/vendor/tracemonkey/liveconnect/README.html +712 -0
  325. data/vendor/tracemonkey/liveconnect/_jni/netscape_javascript_JSException.h +14 -0
  326. data/vendor/tracemonkey/liveconnect/_jni/netscape_javascript_JSObject.h +155 -0
  327. data/vendor/tracemonkey/liveconnect/classes/Makefile.in +89 -0
  328. data/vendor/tracemonkey/liveconnect/classes/Makefile.ref +57 -0
  329. data/vendor/tracemonkey/liveconnect/classes/netscape/Makefile.ref +47 -0
  330. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSException.java +140 -0
  331. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSObject.java +183 -0
  332. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSProxy.java +58 -0
  333. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSRunnable.java +70 -0
  334. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSUtil.java +59 -0
  335. data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/Makefile.ref +53 -0
  336. data/vendor/tracemonkey/liveconnect/config/AIX4.1.mk +45 -0
  337. data/vendor/tracemonkey/liveconnect/config/AIX4.2.mk +45 -0
  338. data/vendor/tracemonkey/liveconnect/config/AIX4.3.mk +50 -0
  339. data/vendor/tracemonkey/liveconnect/config/HP-UXB.10.10.mk +43 -0
  340. data/vendor/tracemonkey/liveconnect/config/HP-UXB.10.20.mk +43 -0
  341. data/vendor/tracemonkey/liveconnect/config/HP-UXB.11.00.mk +43 -0
  342. data/vendor/tracemonkey/liveconnect/config/IRIX6.2.mk +43 -0
  343. data/vendor/tracemonkey/liveconnect/config/IRIX6.3.mk +43 -0
  344. data/vendor/tracemonkey/liveconnect/config/IRIX6.5.mk +43 -0
  345. data/vendor/tracemonkey/liveconnect/config/Linux_All.mk +73 -0
  346. data/vendor/tracemonkey/liveconnect/config/OSF1V4.0.mk +65 -0
  347. data/vendor/tracemonkey/liveconnect/config/OSF1V5.0.mk +62 -0
  348. data/vendor/tracemonkey/liveconnect/config/SunOS5.5.1.mk +55 -0
  349. data/vendor/tracemonkey/liveconnect/config/SunOS5.6.mk +39 -0
  350. data/vendor/tracemonkey/liveconnect/config/SunOS5.7.mk +39 -0
  351. data/vendor/tracemonkey/liveconnect/config/SunOS5.8.mk +39 -0
  352. data/vendor/tracemonkey/liveconnect/config/WINNT4.0.mk +53 -0
  353. data/vendor/tracemonkey/liveconnect/jsj.c +886 -0
  354. data/vendor/tracemonkey/liveconnect/jsj.msg +98 -0
  355. data/vendor/tracemonkey/liveconnect/jsj_JSObject.c +1377 -0
  356. data/vendor/tracemonkey/liveconnect/jsj_JavaArray.c +474 -0
  357. data/vendor/tracemonkey/liveconnect/jsj_JavaClass.c +737 -0
  358. data/vendor/tracemonkey/liveconnect/jsj_JavaMember.c +191 -0
  359. data/vendor/tracemonkey/liveconnect/jsj_JavaObject.c +1079 -0
  360. data/vendor/tracemonkey/liveconnect/jsj_JavaPackage.c +569 -0
  361. data/vendor/tracemonkey/liveconnect/jsj_array.c +207 -0
  362. data/vendor/tracemonkey/liveconnect/jsj_class.c +770 -0
  363. data/vendor/tracemonkey/liveconnect/jsj_convert.c +902 -0
  364. data/vendor/tracemonkey/liveconnect/jsj_field.c +421 -0
  365. data/vendor/tracemonkey/liveconnect/jsj_hash.c +488 -0
  366. data/vendor/tracemonkey/liveconnect/jsj_hash.h +161 -0
  367. data/vendor/tracemonkey/liveconnect/jsj_method.c +1825 -0
  368. data/vendor/tracemonkey/liveconnect/jsj_nodl.c +1 -0
  369. data/vendor/tracemonkey/liveconnect/jsj_private.h +677 -0
  370. data/vendor/tracemonkey/liveconnect/jsj_simpleapi.c +219 -0
  371. data/vendor/tracemonkey/liveconnect/jsj_utils.c +513 -0
  372. data/vendor/tracemonkey/liveconnect/jsjava.h +316 -0
  373. data/vendor/tracemonkey/liveconnect/netscape_javascript_JSObject.h +155 -0
  374. data/vendor/tracemonkey/liveconnect/nsCLiveconnect.cpp +785 -0
  375. data/vendor/tracemonkey/liveconnect/nsCLiveconnect.h +197 -0
  376. data/vendor/tracemonkey/liveconnect/nsCLiveconnectFactory.cpp +118 -0
  377. data/vendor/tracemonkey/liveconnect/nsCLiveconnectFactory.h +76 -0
  378. data/vendor/tracemonkey/liveconnect/nsILiveconnect.h +197 -0
  379. data/vendor/tracemonkey/liveconnect/nsISecureLiveconnect.h +94 -0
  380. data/vendor/tracemonkey/liveconnect/nsISecurityContext.h +136 -0
  381. data/vendor/tracemonkey/lock_SunOS.s +119 -0
  382. data/vendor/tracemonkey/mandelbrot-results.js +3 -0
  383. data/vendor/tracemonkey/math-partial-sums.js +32 -0
  384. data/vendor/tracemonkey/math-trace-tests.js +507 -0
  385. data/vendor/tracemonkey/md5.js +289 -0
  386. data/vendor/tracemonkey/nanojit/Assembler.cpp +1984 -0
  387. data/vendor/tracemonkey/nanojit/Assembler.h +375 -0
  388. data/vendor/tracemonkey/nanojit/Fragmento.cpp +651 -0
  389. data/vendor/tracemonkey/nanojit/Fragmento.h +237 -0
  390. data/vendor/tracemonkey/nanojit/LIR.cpp +2314 -0
  391. data/vendor/tracemonkey/nanojit/LIR.h +879 -0
  392. data/vendor/tracemonkey/nanojit/LIRopcode.tbl +252 -0
  393. data/vendor/tracemonkey/nanojit/Native.h +127 -0
  394. data/vendor/tracemonkey/nanojit/NativeARM.cpp +1742 -0
  395. data/vendor/tracemonkey/nanojit/NativeARM.h +844 -0
  396. data/vendor/tracemonkey/nanojit/NativeSparc.cpp +1130 -0
  397. data/vendor/tracemonkey/nanojit/NativeSparc.h +948 -0
  398. data/vendor/tracemonkey/nanojit/NativeThumb.cpp +1322 -0
  399. data/vendor/tracemonkey/nanojit/NativeThumb.h +525 -0
  400. data/vendor/tracemonkey/nanojit/Nativei386.cpp +1748 -0
  401. data/vendor/tracemonkey/nanojit/Nativei386.h +857 -0
  402. data/vendor/tracemonkey/nanojit/RegAlloc.cpp +183 -0
  403. data/vendor/tracemonkey/nanojit/RegAlloc.h +95 -0
  404. data/vendor/tracemonkey/nanojit/TraceTreeDrawer.cpp +306 -0
  405. data/vendor/tracemonkey/nanojit/TraceTreeDrawer.h +88 -0
  406. data/vendor/tracemonkey/nanojit/avmplus.cpp +56 -0
  407. data/vendor/tracemonkey/nanojit/avmplus.h +1016 -0
  408. data/vendor/tracemonkey/nanojit/nanojit.h +253 -0
  409. data/vendor/tracemonkey/perfect.js +39 -0
  410. data/vendor/tracemonkey/plify_jsdhash.sed +35 -0
  411. data/vendor/tracemonkey/prmjtime.cpp +869 -0
  412. data/vendor/tracemonkey/prmjtime.h +103 -0
  413. data/vendor/tracemonkey/ref-config/AIX4.1.mk +65 -0
  414. data/vendor/tracemonkey/ref-config/AIX4.2.mk +64 -0
  415. data/vendor/tracemonkey/ref-config/AIX4.3.mk +65 -0
  416. data/vendor/tracemonkey/ref-config/Darwin.mk +85 -0
  417. data/vendor/tracemonkey/ref-config/Darwin1.3.mk +81 -0
  418. data/vendor/tracemonkey/ref-config/Darwin1.4.mk +41 -0
  419. data/vendor/tracemonkey/ref-config/Darwin5.2.mk +81 -0
  420. data/vendor/tracemonkey/ref-config/Darwin5.3.mk +81 -0
  421. data/vendor/tracemonkey/ref-config/Darwin64.mk +72 -0
  422. data/vendor/tracemonkey/ref-config/HP-UXB.10.10.mk +77 -0
  423. data/vendor/tracemonkey/ref-config/HP-UXB.10.20.mk +77 -0
  424. data/vendor/tracemonkey/ref-config/HP-UXB.11.00.mk +80 -0
  425. data/vendor/tracemonkey/ref-config/IRIX.mk +87 -0
  426. data/vendor/tracemonkey/ref-config/IRIX5.3.mk +44 -0
  427. data/vendor/tracemonkey/ref-config/IRIX6.1.mk +44 -0
  428. data/vendor/tracemonkey/ref-config/IRIX6.2.mk +44 -0
  429. data/vendor/tracemonkey/ref-config/IRIX6.3.mk +44 -0
  430. data/vendor/tracemonkey/ref-config/IRIX6.5.mk +44 -0
  431. data/vendor/tracemonkey/ref-config/Linux_All.mk +105 -0
  432. data/vendor/tracemonkey/ref-config/Mac_OS10.0.mk +82 -0
  433. data/vendor/tracemonkey/ref-config/OSF1V4.0.mk +72 -0
  434. data/vendor/tracemonkey/ref-config/OSF1V5.0.mk +69 -0
  435. data/vendor/tracemonkey/ref-config/SunOS4.1.4.mk +101 -0
  436. data/vendor/tracemonkey/ref-config/SunOS5.10.mk +50 -0
  437. data/vendor/tracemonkey/ref-config/SunOS5.3.mk +91 -0
  438. data/vendor/tracemonkey/ref-config/SunOS5.4.mk +92 -0
  439. data/vendor/tracemonkey/ref-config/SunOS5.5.1.mk +44 -0
  440. data/vendor/tracemonkey/ref-config/SunOS5.5.mk +87 -0
  441. data/vendor/tracemonkey/ref-config/SunOS5.6.mk +89 -0
  442. data/vendor/tracemonkey/ref-config/SunOS5.7.mk +44 -0
  443. data/vendor/tracemonkey/ref-config/SunOS5.8.mk +44 -0
  444. data/vendor/tracemonkey/ref-config/SunOS5.9.mk +44 -0
  445. data/vendor/tracemonkey/ref-config/WINNT4.0.mk +118 -0
  446. data/vendor/tracemonkey/ref-config/WINNT5.0.mk +118 -0
  447. data/vendor/tracemonkey/ref-config/WINNT5.1.mk +118 -0
  448. data/vendor/tracemonkey/ref-config/WINNT5.2.mk +118 -0
  449. data/vendor/tracemonkey/ref-config/WINNT6.0.mk +118 -0
  450. data/vendor/tracemonkey/ref-config/dgux.mk +64 -0
  451. data/vendor/tracemonkey/resource.h +15 -0
  452. data/vendor/tracemonkey/rules.mk +206 -0
  453. data/vendor/tracemonkey/shell/Makefile.in +72 -0
  454. data/vendor/tracemonkey/shell/js.cpp +4719 -0
  455. data/vendor/tracemonkey/t/3d-cube.js +337 -0
  456. data/vendor/tracemonkey/t/3d-morph.js +54 -0
  457. data/vendor/tracemonkey/t/3d-raytrace.js +441 -0
  458. data/vendor/tracemonkey/t/access-binary-trees.js +50 -0
  459. data/vendor/tracemonkey/t/access-fannkuch.js +66 -0
  460. data/vendor/tracemonkey/t/access-nbody.js +169 -0
  461. data/vendor/tracemonkey/t/access-nsieve.js +38 -0
  462. data/vendor/tracemonkey/t/bitops-3bit-bits-in-byte.js +32 -0
  463. data/vendor/tracemonkey/t/bitops-bits-in-byte.js +21 -0
  464. data/vendor/tracemonkey/t/bitops-bitwise-and.js +28 -0
  465. data/vendor/tracemonkey/t/bitops-nsieve-bits.js +32 -0
  466. data/vendor/tracemonkey/t/controlflow-recursive.js +25 -0
  467. data/vendor/tracemonkey/t/crypto-aes.js +422 -0
  468. data/vendor/tracemonkey/t/crypto-md5.js +286 -0
  469. data/vendor/tracemonkey/t/crypto-sha1.js +224 -0
  470. data/vendor/tracemonkey/t/date-format-tofte.js +299 -0
  471. data/vendor/tracemonkey/t/date-format-xparb.js +417 -0
  472. data/vendor/tracemonkey/t/math-cordic.js +95 -0
  473. data/vendor/tracemonkey/t/math-partial-sums.js +33 -0
  474. data/vendor/tracemonkey/t/math-spectral-norm.js +51 -0
  475. data/vendor/tracemonkey/t/regexp-dna.js +1712 -0
  476. data/vendor/tracemonkey/t/string-base64.js +135 -0
  477. data/vendor/tracemonkey/t/string-fasta.js +85 -0
  478. data/vendor/tracemonkey/t/string-tagcloud.js +265 -0
  479. data/vendor/tracemonkey/t/string-unpack-code.js +68 -0
  480. data/vendor/tracemonkey/t/string-validate-input.js +89 -0
  481. data/vendor/tracemonkey/time.sh +13 -0
  482. data/vendor/tracemonkey/trace-test.js +5564 -0
  483. data/vendor/tracemonkey/v8/base.js +187 -0
  484. data/vendor/tracemonkey/v8/crypto.js +1689 -0
  485. data/vendor/tracemonkey/v8/deltablue.js +880 -0
  486. data/vendor/tracemonkey/v8/earley-boyer.js +4682 -0
  487. data/vendor/tracemonkey/v8/raytrace.js +3418 -0
  488. data/vendor/tracemonkey/v8/richards.js +539 -0
  489. data/vendor/tracemonkey/v8/run-crypto.js +44 -0
  490. data/vendor/tracemonkey/v8/run-deltablue.js +44 -0
  491. data/vendor/tracemonkey/v8/run-earley-boyer.js +44 -0
  492. data/vendor/tracemonkey/v8/run-raytrace.js +44 -0
  493. data/vendor/tracemonkey/v8/run-richards.js +44 -0
  494. data/vendor/tracemonkey/v8/run.js +49 -0
  495. data/vendor/tracemonkey/vprof/readme.txt +93 -0
  496. data/vendor/tracemonkey/vprof/vprof.cpp +360 -0
  497. data/vendor/tracemonkey/vprof/vprof.h +245 -0
  498. data/vendor/tracemonkey/xpconnect/Makefile.in +67 -0
  499. data/vendor/tracemonkey/xpconnect/crashtests/117307-1.html +20 -0
  500. data/vendor/tracemonkey/xpconnect/crashtests/193710.html +11 -0
  501. data/vendor/tracemonkey/xpconnect/crashtests/290162-1.html +5 -0
  502. data/vendor/tracemonkey/xpconnect/crashtests/326615-1.html +16 -0
  503. data/vendor/tracemonkey/xpconnect/crashtests/328553-1.html +13 -0
  504. data/vendor/tracemonkey/xpconnect/crashtests/346258-1.html +12 -0
  505. data/vendor/tracemonkey/xpconnect/crashtests/346512-1-frame1.xhtml +16 -0
  506. data/vendor/tracemonkey/xpconnect/crashtests/346512-1-frame2.xhtml +15 -0
  507. data/vendor/tracemonkey/xpconnect/crashtests/346512-1.xhtml +30 -0
  508. data/vendor/tracemonkey/xpconnect/crashtests/382133-1.html +3 -0
  509. data/vendor/tracemonkey/xpconnect/crashtests/386680-1.html +22 -0
  510. data/vendor/tracemonkey/xpconnect/crashtests/394810-1.html +4 -0
  511. data/vendor/tracemonkey/xpconnect/crashtests/400349-1.html +20 -0
  512. data/vendor/tracemonkey/xpconnect/crashtests/403356-1.html +13 -0
  513. data/vendor/tracemonkey/xpconnect/crashtests/418139-1.svg +22 -0
  514. data/vendor/tracemonkey/xpconnect/crashtests/420513-1.html +11 -0
  515. data/vendor/tracemonkey/xpconnect/crashtests/453935-1.html +37 -0
  516. data/vendor/tracemonkey/xpconnect/crashtests/462926.html +12 -0
  517. data/vendor/tracemonkey/xpconnect/crashtests/468552-1.html +18 -0
  518. data/vendor/tracemonkey/xpconnect/crashtests/471366-1.html +12 -0
  519. data/vendor/tracemonkey/xpconnect/crashtests/475185-1.html +13 -0
  520. data/vendor/tracemonkey/xpconnect/crashtests/475291-1.html +14 -0
  521. data/vendor/tracemonkey/xpconnect/crashtests/503286-1.html +23 -0
  522. data/vendor/tracemonkey/xpconnect/crashtests/crashtests.list +21 -0
  523. data/vendor/tracemonkey/xpconnect/idl/Makefile.in +78 -0
  524. data/vendor/tracemonkey/xpconnect/idl/XPCIDispatch.idl +51 -0
  525. data/vendor/tracemonkey/xpconnect/idl/mozIJSSubScriptLoader.idl +64 -0
  526. data/vendor/tracemonkey/xpconnect/idl/nsIActiveXSecurityPolicy.idl +67 -0
  527. data/vendor/tracemonkey/xpconnect/idl/nsIDispatchSupport.idl +119 -0
  528. data/vendor/tracemonkey/xpconnect/idl/nsIJSContextStack.idl +85 -0
  529. data/vendor/tracemonkey/xpconnect/idl/nsIJSRuntimeService.idl +51 -0
  530. data/vendor/tracemonkey/xpconnect/idl/nsIScriptError.idl +102 -0
  531. data/vendor/tracemonkey/xpconnect/idl/nsIScriptableInterfaces.idl +67 -0
  532. data/vendor/tracemonkey/xpconnect/idl/nsIXPCScriptNotify.idl +66 -0
  533. data/vendor/tracemonkey/xpconnect/idl/nsIXPCScriptable.idl +183 -0
  534. data/vendor/tracemonkey/xpconnect/idl/nsIXPCSecurityManager.idl +114 -0
  535. data/vendor/tracemonkey/xpconnect/idl/nsIXPConnect.idl +819 -0
  536. data/vendor/tracemonkey/xpconnect/idl/xpcIJSModuleLoader.idl +95 -0
  537. data/vendor/tracemonkey/xpconnect/idl/xpcIJSWeakReference.idl +49 -0
  538. data/vendor/tracemonkey/xpconnect/idl/xpccomponents.idl +254 -0
  539. data/vendor/tracemonkey/xpconnect/idl/xpcexception.idl +66 -0
  540. data/vendor/tracemonkey/xpconnect/idl/xpcjsid.idl +83 -0
  541. data/vendor/tracemonkey/xpconnect/loader/ISO8601DateUtils.jsm +176 -0
  542. data/vendor/tracemonkey/xpconnect/loader/Makefile.in +63 -0
  543. data/vendor/tracemonkey/xpconnect/loader/XPCOMUtils.jsm +267 -0
  544. data/vendor/tracemonkey/xpconnect/loader/mozJSComponentLoader.cpp +1717 -0
  545. data/vendor/tracemonkey/xpconnect/loader/mozJSComponentLoader.h +172 -0
  546. data/vendor/tracemonkey/xpconnect/loader/mozJSLoaderConstructors.h +101 -0
  547. data/vendor/tracemonkey/xpconnect/loader/mozJSSubScriptLoader.cpp +360 -0
  548. data/vendor/tracemonkey/xpconnect/loader/mozJSSubScriptLoader.h +66 -0
  549. data/vendor/tracemonkey/xpconnect/public/Makefile.in +54 -0
  550. data/vendor/tracemonkey/xpconnect/public/nsAXPCNativeCallContext.h +89 -0
  551. data/vendor/tracemonkey/xpconnect/public/nsAutoJSValHolder.h +168 -0
  552. data/vendor/tracemonkey/xpconnect/public/xpc_map_end.h +327 -0
  553. data/vendor/tracemonkey/xpconnect/sample/Makefile.in +71 -0
  554. data/vendor/tracemonkey/xpconnect/sample/README +39 -0
  555. data/vendor/tracemonkey/xpconnect/sample/xpcsample1.cpp +337 -0
  556. data/vendor/tracemonkey/xpconnect/sample/xpcsample1.idl +82 -0
  557. data/vendor/tracemonkey/xpconnect/sample/xpcsample1.js +21 -0
  558. data/vendor/tracemonkey/xpconnect/shell/Makefile.in +106 -0
  559. data/vendor/tracemonkey/xpconnect/shell/jsshell.msg +50 -0
  560. data/vendor/tracemonkey/xpconnect/shell/xpcshell.cpp +1817 -0
  561. data/vendor/tracemonkey/xpconnect/shell/xpcshellMacUtils.h +43 -0
  562. data/vendor/tracemonkey/xpconnect/shell/xpcshellMacUtils.mm +54 -0
  563. data/vendor/tracemonkey/xpconnect/src/Makefile.in +228 -0
  564. data/vendor/tracemonkey/xpconnect/src/README +3 -0
  565. data/vendor/tracemonkey/xpconnect/src/XPCCrossOriginWrapper.cpp +1186 -0
  566. data/vendor/tracemonkey/xpconnect/src/XPCDispConvert.cpp +593 -0
  567. data/vendor/tracemonkey/xpconnect/src/XPCDispInlines.h +667 -0
  568. data/vendor/tracemonkey/xpconnect/src/XPCDispInterface.cpp +383 -0
  569. data/vendor/tracemonkey/xpconnect/src/XPCDispObject.cpp +516 -0
  570. data/vendor/tracemonkey/xpconnect/src/XPCDispParamPropJSClass.cpp +223 -0
  571. data/vendor/tracemonkey/xpconnect/src/XPCDispParams.cpp +103 -0
  572. data/vendor/tracemonkey/xpconnect/src/XPCDispPrivate.h +1401 -0
  573. data/vendor/tracemonkey/xpconnect/src/XPCDispTearOff.cpp +547 -0
  574. data/vendor/tracemonkey/xpconnect/src/XPCDispTypeInfo.cpp +471 -0
  575. data/vendor/tracemonkey/xpconnect/src/XPCIDispatchClassInfo.cpp +139 -0
  576. data/vendor/tracemonkey/xpconnect/src/XPCIDispatchExtension.cpp +362 -0
  577. data/vendor/tracemonkey/xpconnect/src/XPCNativeWrapper.cpp +1350 -0
  578. data/vendor/tracemonkey/xpconnect/src/XPCNativeWrapper.h +88 -0
  579. data/vendor/tracemonkey/xpconnect/src/XPCSafeJSObjectWrapper.cpp +1148 -0
  580. data/vendor/tracemonkey/xpconnect/src/XPCSystemOnlyWrapper.cpp +718 -0
  581. data/vendor/tracemonkey/xpconnect/src/XPCWrapper.cpp +850 -0
  582. data/vendor/tracemonkey/xpconnect/src/XPCWrapper.h +394 -0
  583. data/vendor/tracemonkey/xpconnect/src/dom_quickstubs.qsconf +568 -0
  584. data/vendor/tracemonkey/xpconnect/src/nsDispatchSupport.cpp +348 -0
  585. data/vendor/tracemonkey/xpconnect/src/nsScriptError.cpp +201 -0
  586. data/vendor/tracemonkey/xpconnect/src/nsXPConnect.cpp +2609 -0
  587. data/vendor/tracemonkey/xpconnect/src/qsgen.py +1487 -0
  588. data/vendor/tracemonkey/xpconnect/src/xpc.msg +217 -0
  589. data/vendor/tracemonkey/xpconnect/src/xpcJSWeakReference.cpp +148 -0
  590. data/vendor/tracemonkey/xpconnect/src/xpcJSWeakReference.h +56 -0
  591. data/vendor/tracemonkey/xpconnect/src/xpccallcontext.cpp +579 -0
  592. data/vendor/tracemonkey/xpconnect/src/xpccomponents.cpp +4144 -0
  593. data/vendor/tracemonkey/xpconnect/src/xpccontext.cpp +115 -0
  594. data/vendor/tracemonkey/xpconnect/src/xpcconvert.cpp +2298 -0
  595. data/vendor/tracemonkey/xpconnect/src/xpcdebug.cpp +481 -0
  596. data/vendor/tracemonkey/xpconnect/src/xpcexception.cpp +502 -0
  597. data/vendor/tracemonkey/xpconnect/src/xpcforwards.h +114 -0
  598. data/vendor/tracemonkey/xpconnect/src/xpcinlines.h +772 -0
  599. data/vendor/tracemonkey/xpconnect/src/xpcjsid.cpp +1025 -0
  600. data/vendor/tracemonkey/xpconnect/src/xpcjsruntime.cpp +1342 -0
  601. data/vendor/tracemonkey/xpconnect/src/xpclog.cpp +128 -0
  602. data/vendor/tracemonkey/xpconnect/src/xpclog.h +101 -0
  603. data/vendor/tracemonkey/xpconnect/src/xpcmaps.cpp +761 -0
  604. data/vendor/tracemonkey/xpconnect/src/xpcmaps.h +713 -0
  605. data/vendor/tracemonkey/xpconnect/src/xpcmodule.cpp +136 -0
  606. data/vendor/tracemonkey/xpconnect/src/xpcprivate.h +4138 -0
  607. data/vendor/tracemonkey/xpconnect/src/xpcquickstubs.cpp +1128 -0
  608. data/vendor/tracemonkey/xpconnect/src/xpcquickstubs.h +480 -0
  609. data/vendor/tracemonkey/xpconnect/src/xpcruntimesvc.cpp +179 -0
  610. data/vendor/tracemonkey/xpconnect/src/xpcstack.cpp +342 -0
  611. data/vendor/tracemonkey/xpconnect/src/xpcstring.cpp +139 -0
  612. data/vendor/tracemonkey/xpconnect/src/xpcthreadcontext.cpp +599 -0
  613. data/vendor/tracemonkey/xpconnect/src/xpcthrower.cpp +399 -0
  614. data/vendor/tracemonkey/xpconnect/src/xpcvariant.cpp +850 -0
  615. data/vendor/tracemonkey/xpconnect/src/xpcwrappedjs.cpp +670 -0
  616. data/vendor/tracemonkey/xpconnect/src/xpcwrappedjsclass.cpp +2015 -0
  617. data/vendor/tracemonkey/xpconnect/src/xpcwrappednative.cpp +3482 -0
  618. data/vendor/tracemonkey/xpconnect/src/xpcwrappednativeinfo.cpp +945 -0
  619. data/vendor/tracemonkey/xpconnect/src/xpcwrappednativejsops.cpp +2003 -0
  620. data/vendor/tracemonkey/xpconnect/src/xpcwrappednativeproto.cpp +302 -0
  621. data/vendor/tracemonkey/xpconnect/src/xpcwrappednativescope.cpp +991 -0
  622. data/vendor/tracemonkey/xpconnect/tests/Makefile.in +75 -0
  623. data/vendor/tracemonkey/xpconnect/tests/TestXPC.cpp +785 -0
  624. data/vendor/tracemonkey/xpconnect/tests/chrome/Makefile.in +51 -0
  625. data/vendor/tracemonkey/xpconnect/tests/chrome/test_bug500931.xul +43 -0
  626. data/vendor/tracemonkey/xpconnect/tests/components/Makefile.in +85 -0
  627. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_array.cpp +388 -0
  628. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_attributes.cpp +305 -0
  629. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_calljs.cpp +135 -0
  630. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_child.cpp +225 -0
  631. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_const.cpp +76 -0
  632. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_domstring.cpp +118 -0
  633. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_echo.cpp +616 -0
  634. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_in.cpp +204 -0
  635. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_inout.cpp +171 -0
  636. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_module.cpp +77 -0
  637. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_multiple.cpp +554 -0
  638. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_noisy.cpp +154 -0
  639. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_out.cpp +335 -0
  640. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_overloaded.cpp +250 -0
  641. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_private.h +192 -0
  642. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_string.cpp +185 -0
  643. data/vendor/tracemonkey/xpconnect/tests/components/xpctest_variant.cpp +355 -0
  644. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/StdAfx.cpp +12 -0
  645. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/StdAfx.h +28 -0
  646. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCDispUtilities.h +28 -0
  647. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.cpp +86 -0
  648. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.def +9 -0
  649. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.dsp +318 -0
  650. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.dsw +29 -0
  651. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.idl +454 -0
  652. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.rc +145 -0
  653. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispSimple.cpp +44 -0
  654. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispSimple.h +56 -0
  655. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispSimple.rgs +23 -0
  656. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestArrays.cpp +221 -0
  657. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestArrays.h +53 -0
  658. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestArrays.rgs +23 -0
  659. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestMethods.cpp +699 -0
  660. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestMethods.h +138 -0
  661. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestMethods.rgs +23 -0
  662. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestNoIDispatch.cpp +23 -0
  663. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestNoIDispatch.h +41 -0
  664. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestNoIDispatch.rgs +23 -0
  665. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestProperties.cpp +256 -0
  666. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestProperties.h +88 -0
  667. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestProperties.rgs +23 -0
  668. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOff.cpp +23 -0
  669. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOff.h +43 -0
  670. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOff.rgs +23 -0
  671. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOn.cpp +29 -0
  672. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOn.h +45 -0
  673. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOn.rgs +23 -0
  674. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestWrappedJS.cpp +177 -0
  675. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestWrappedJS.h +50 -0
  676. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestWrappedJS.rgs +23 -0
  677. data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/resource.h +36 -0
  678. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/Arrays/XPCIDispatchArrayTests.js +54 -0
  679. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/Attributes/XPCIDispatchAttributeTests.js +150 -0
  680. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/General/XPCIDispatchInstantiations.js +122 -0
  681. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/General/XPCStress.js +58 -0
  682. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/Methods/XPCIDispatchMethodTests.js +376 -0
  683. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/shell.js +377 -0
  684. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedJS/General/XPCIDispatchTestWrappedJS.js +76 -0
  685. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedJS/shell.js +377 -0
  686. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/exectests.cmd +1 -0
  687. data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/jsDriver.pl +1288 -0
  688. data/vendor/tracemonkey/xpconnect/tests/idl/Makefile.in +61 -0
  689. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest.idl +312 -0
  690. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest2.idl +51 -0
  691. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_attributes.idl +67 -0
  692. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_calljs.idl +59 -0
  693. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_const.idl +61 -0
  694. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_domstring.idl +59 -0
  695. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_in.idl +88 -0
  696. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_inout.idl +86 -0
  697. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_multiple.idl +77 -0
  698. data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_out.idl +142 -0
  699. data/vendor/tracemonkey/xpconnect/tests/js/checkid.js +82 -0
  700. data/vendor/tracemonkey/xpconnect/tests/js/evaluate.js +311 -0
  701. data/vendor/tracemonkey/xpconnect/tests/js/exceptions-2.js +153 -0
  702. data/vendor/tracemonkey/xpconnect/tests/js/exceptions-3.js +194 -0
  703. data/vendor/tracemonkey/xpconnect/tests/js/exceptions-4.js +297 -0
  704. data/vendor/tracemonkey/xpconnect/tests/js/exceptions-5.js +343 -0
  705. data/vendor/tracemonkey/xpconnect/tests/js/exceptions.js +230 -0
  706. data/vendor/tracemonkey/xpconnect/tests/js/javascript.js +96 -0
  707. data/vendor/tracemonkey/xpconnect/tests/js/multiple-2.js +151 -0
  708. data/vendor/tracemonkey/xpconnect/tests/js/multiple-3.js +148 -0
  709. data/vendor/tracemonkey/xpconnect/tests/js/multiple-4.js +152 -0
  710. data/vendor/tracemonkey/xpconnect/tests/js/multiple.js +137 -0
  711. data/vendor/tracemonkey/xpconnect/tests/js/notscriptable.js +104 -0
  712. data/vendor/tracemonkey/xpconnect/tests/js/old/simpletest.js +36 -0
  713. data/vendor/tracemonkey/xpconnect/tests/js/old/speed.js +60 -0
  714. data/vendor/tracemonkey/xpconnect/tests/js/old/testxpc.js +464 -0
  715. data/vendor/tracemonkey/xpconnect/tests/js/old/threads.js +74 -0
  716. data/vendor/tracemonkey/xpconnect/tests/js/old/try.js +27 -0
  717. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_array.js +308 -0
  718. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_callcontext.js +68 -0
  719. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_echo.js +636 -0
  720. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_enum_and_sort.js +28 -0
  721. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_enum_constants.js +15 -0
  722. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_enum_create.js +200 -0
  723. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_exceptions.js +167 -0
  724. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_ids.js +135 -0
  725. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_observer.js +36 -0
  726. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_overloaded.js +14 -0
  727. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_primitives.js +141 -0
  728. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_propertybag.js +36 -0
  729. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_variant.js +339 -0
  730. data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_variant_array.js +30 -0
  731. data/vendor/tracemonkey/xpconnect/tests/js/readonlyattributes.js +74 -0
  732. data/vendor/tracemonkey/xpconnect/tests/js/readwriteattributes.js +101 -0
  733. data/vendor/tracemonkey/xpconnect/tests/js/scriptable.js +120 -0
  734. data/vendor/tracemonkey/xpconnect/tests/js/testin.js +203 -0
  735. data/vendor/tracemonkey/xpconnect/tests/js/xpcfun.js +234 -0
  736. data/vendor/tracemonkey/xpconnect/tests/js/xpctest_primitives.js +200 -0
  737. data/vendor/tracemonkey/xpconnect/tests/mochitest/Makefile.in +66 -0
  738. data/vendor/tracemonkey/xpconnect/tests/mochitest/bug500931_helper.html +7 -0
  739. data/vendor/tracemonkey/xpconnect/tests/mochitest/inner.html +7 -0
  740. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug361111.xul +29 -0
  741. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug384632.html +32 -0
  742. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug390488.html +65 -0
  743. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug393269.html +46 -0
  744. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug396851.html +43 -0
  745. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug428021.html +41 -0
  746. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug446584.html +49 -0
  747. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug448587.html +31 -0
  748. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug462428.html +42 -0
  749. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug478438.html +66 -0
  750. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug484107.html +100 -0
  751. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug484459.html +36 -0
  752. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug500691.html +28 -0
  753. data/vendor/tracemonkey/xpconnect/tests/mochitest/test_wrappers.html +116 -0
  754. data/vendor/tracemonkey/xpconnect/tests/unit/bogus_element_type.jsm +1 -0
  755. data/vendor/tracemonkey/xpconnect/tests/unit/bogus_exports_type.jsm +1 -0
  756. data/vendor/tracemonkey/xpconnect/tests/unit/bug451678_subscript.js +2 -0
  757. data/vendor/tracemonkey/xpconnect/tests/unit/component_import.js +144 -0
  758. data/vendor/tracemonkey/xpconnect/tests/unit/recursive_importA.jsm +44 -0
  759. data/vendor/tracemonkey/xpconnect/tests/unit/recursive_importB.jsm +45 -0
  760. data/vendor/tracemonkey/xpconnect/tests/unit/syntax_error.jsm +1 -0
  761. data/vendor/tracemonkey/xpconnect/tests/unit/test_bogus_files.js +88 -0
  762. data/vendor/tracemonkey/xpconnect/tests/unit/test_bug408412.js +51 -0
  763. data/vendor/tracemonkey/xpconnect/tests/unit/test_bug451678.js +52 -0
  764. data/vendor/tracemonkey/xpconnect/tests/unit/test_bug_442086.js +68 -0
  765. data/vendor/tracemonkey/xpconnect/tests/unit/test_import.js +127 -0
  766. data/vendor/tracemonkey/xpconnect/tests/unit/test_js_weak_references.js +63 -0
  767. data/vendor/tracemonkey/xpconnect/tests/unit/test_recursive_import.js +62 -0
  768. data/vendor/tracemonkey/xpconnect/tools/Makefile.in +49 -0
  769. data/vendor/tracemonkey/xpconnect/tools/idl/Makefile.in +53 -0
  770. data/vendor/tracemonkey/xpconnect/tools/idl/nsIXPCToolsCompiler.idl +60 -0
  771. data/vendor/tracemonkey/xpconnect/tools/idl/nsIXPCToolsProfiler.idl +57 -0
  772. data/vendor/tracemonkey/xpconnect/tools/js/CompileJSFiles.js +28 -0
  773. data/vendor/tracemonkey/xpconnect/tools/js/ListJSFiles.js +18 -0
  774. data/vendor/tracemonkey/xpconnect/tools/src/Makefile.in +76 -0
  775. data/vendor/tracemonkey/xpconnect/tools/src/nsXPCToolsCompiler.cpp +161 -0
  776. data/vendor/tracemonkey/xpconnect/tools/src/nsXPCToolsModule.cpp +65 -0
  777. data/vendor/tracemonkey/xpconnect/tools/src/nsXPCToolsProfiler.cpp +370 -0
  778. data/vendor/tracemonkey/xpconnect/tools/src/xpctools_private.h +236 -0
  779. metadata +782 -107
  780. data/test/johnson/nodes/export_test.rb +0 -9
  781. data/test/johnson/nodes/import_test.rb +0 -13
  782. data/test/johnson/version_test.rb +0 -13
@@ -0,0 +1,136 @@
1
+ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ *
3
+ * ***** BEGIN LICENSE BLOCK *****
4
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
+ *
6
+ * The contents of this file are subject to the Mozilla Public License Version
7
+ * 1.1 (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ * http://www.mozilla.org/MPL/
10
+ *
11
+ * Software distributed under the License is distributed on an "AS IS" basis,
12
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
+ * for the specific language governing rights and limitations under the
14
+ * License.
15
+ *
16
+ * The Original Code is Mozilla Communicator client code, released
17
+ * March 31, 1998.
18
+ *
19
+ * The Initial Developer of the Original Code is
20
+ * Netscape Communications Corporation.
21
+ * Portions created by the Initial Developer are Copyright (C) 1998
22
+ * the Initial Developer. All Rights Reserved.
23
+ *
24
+ * Contributor(s):
25
+ * John Bandhauer <jband@netscape.com> (original author)
26
+ *
27
+ * Alternatively, the contents of this file may be used under the terms of
28
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
29
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30
+ * in which case the provisions of the GPL or the LGPL are applicable instead
31
+ * of those above. If you wish to allow use of your version of this file only
32
+ * under the terms of either the GPL or the LGPL, and not to allow others to
33
+ * use your version of this file under the terms of the MPL, indicate your
34
+ * decision by deleting the provisions above and replace them with the notice
35
+ * and other provisions required by the GPL or the LGPL. If you do not delete
36
+ * the provisions above, a recipient may use your version of this file under
37
+ * the terms of any one of the MPL, the GPL or the LGPL.
38
+ *
39
+ * ***** END LICENSE BLOCK ***** */
40
+
41
+ /* Module level methods. */
42
+
43
+ #include "xpcprivate.h"
44
+ #ifdef MOZ_JSLOADER
45
+ #include "mozJSLoaderConstructors.h"
46
+ #endif
47
+
48
+ /* Module implementation for the xpconnect library. */
49
+
50
+ NS_DECL_CLASSINFO(XPCVariant)
51
+
52
+ // {DC524540-487E-4501-9AC7-AAA784B17C1C}
53
+ #define XPCVARIANT_CID \
54
+ {0xdc524540, 0x487e, 0x4501, \
55
+ { 0x9a, 0xc7, 0xaa, 0xa7, 0x84, 0xb1, 0x7c, 0x1c } }
56
+
57
+ #define XPCVARIANT_CONTRACTID "@mozilla.org/xpcvariant;1"
58
+ #define XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID "@mozilla.org/js/xpc/ContextStackIterator;1"
59
+
60
+ // {FE4F7592-C1FC-4662-AC83-538841318803}
61
+ #define SCRIPTABLE_INTERFACES_CID \
62
+ {0xfe4f7592, 0xc1fc, 0x4662, \
63
+ { 0xac, 0x83, 0x53, 0x88, 0x41, 0x31, 0x88, 0x3 } }
64
+
65
+ NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID)
66
+ NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCException)
67
+ NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCJSContextStackIterator)
68
+ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIXPConnect, nsXPConnect::GetSingleton)
69
+ NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError)
70
+ NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCComponents_Interfaces)
71
+
72
+ #ifdef XPC_IDISPATCH_SUPPORT
73
+ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDispatchSupport, nsDispatchSupport::GetSingleton)
74
+ #endif
75
+
76
+ NS_DECL_CLASSINFO(nsXPCException)
77
+
78
+ #ifdef XPCONNECT_STANDALONE
79
+ #define NO_SUBSCRIPT_LOADER
80
+ #endif
81
+
82
+ static const nsModuleComponentInfo components[] = {
83
+ {nsnull, NS_JS_ID_CID, XPC_ID_CONTRACTID, nsJSIDConstructor },
84
+ {nsnull, NS_XPCONNECT_CID, XPC_XPCONNECT_CONTRACTID, nsIXPConnectConstructor },
85
+ {nsnull, NS_XPC_THREAD_JSCONTEXT_STACK_CID, XPC_CONTEXT_STACK_CONTRACTID, nsIXPConnectConstructor },
86
+ {nsnull, NS_XPCEXCEPTION_CID, XPC_EXCEPTION_CONTRACTID, nsXPCExceptionConstructor, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(nsXPCException), nsnull, &NS_CLASSINFO_NAME(nsXPCException), nsIClassInfo::DOM_OBJECT },
87
+ {nsnull, NS_JS_RUNTIME_SERVICE_CID, XPC_RUNTIME_CONTRACTID, nsIXPConnectConstructor},
88
+ {NS_SCRIPTERROR_CLASSNAME, NS_SCRIPTERROR_CID, NS_SCRIPTERROR_CONTRACTID, nsScriptErrorConstructor },
89
+ {nsnull, SCRIPTABLE_INTERFACES_CID, NS_SCRIPTABLE_INTERFACES_CONTRACTID, nsXPCComponents_InterfacesConstructor, 0, 0, 0, 0, 0, 0, nsIClassInfo::THREADSAFE },
90
+ {nsnull, XPCVARIANT_CID, XPCVARIANT_CONTRACTID, nsnull, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(XPCVariant), nsnull, &NS_CLASSINFO_NAME(XPCVariant)},
91
+ {nsnull, NS_XPC_JSCONTEXT_STACK_ITERATOR_CID, XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID, nsXPCJSContextStackIteratorConstructor }
92
+
93
+ #ifdef MOZ_JSLOADER
94
+ // jsloader stuff
95
+ ,{ "JS component loader", MOZJSCOMPONENTLOADER_CID,
96
+ MOZJSCOMPONENTLOADER_CONTRACTID, mozJSComponentLoaderConstructor,
97
+ RegisterJSLoader, UnregisterJSLoader }
98
+ #ifndef NO_SUBSCRIPT_LOADER
99
+ ,{ "JS subscript loader", MOZ_JSSUBSCRIPTLOADER_CID,
100
+ mozJSSubScriptLoadContractID, mozJSSubScriptLoaderConstructor }
101
+ #endif
102
+ #endif
103
+ #ifdef XPC_IDISPATCH_SUPPORT
104
+ ,{ nsnull, NS_IDISPATCH_SUPPORT_CID, NS_IDISPATCH_SUPPORT_CONTRACTID,
105
+ nsIDispatchSupportConstructor }
106
+ #endif
107
+ };
108
+
109
+ static nsresult
110
+ xpcModuleCtor(nsIModule* self)
111
+ {
112
+ nsXPConnect::InitStatics();
113
+ nsXPCException::InitStatics();
114
+ XPCWrappedNativeScope::InitStatics();
115
+ XPCPerThreadData::InitStatics();
116
+
117
+ #ifdef XPC_IDISPATCH_SUPPORT
118
+ XPCIDispatchExtension::InitStatics();
119
+ #endif
120
+
121
+ return NS_OK;
122
+ }
123
+
124
+ static void
125
+ xpcModuleDtor(nsIModule* self)
126
+ {
127
+ // Release our singletons
128
+ nsXPConnect::ReleaseXPConnectSingleton();
129
+ xpc_DestroyJSxIDClassObjects();
130
+ #ifdef XPC_IDISPATCH_SUPPORT
131
+ nsDispatchSupport::FreeSingleton();
132
+ XPCIDispatchClassInfo::FreeSingleton();
133
+ #endif
134
+ }
135
+
136
+ NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(xpconnect, components, xpcModuleCtor, xpcModuleDtor)
@@ -0,0 +1,4138 @@
1
+ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ * vim: set ts=8 sw=4 et tw=78:
3
+ *
4
+ * ***** BEGIN LICENSE BLOCK *****
5
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6
+ *
7
+ * The contents of this file are subject to the Mozilla Public License Version
8
+ * 1.1 (the "License"); you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ * http://www.mozilla.org/MPL/
11
+ *
12
+ * Software distributed under the License is distributed on an "AS IS" basis,
13
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14
+ * for the specific language governing rights and limitations under the
15
+ * License.
16
+ *
17
+ * The Original Code is Mozilla Communicator client code, released
18
+ * March 31, 1998.
19
+ *
20
+ * The Initial Developer of the Original Code is
21
+ * Netscape Communications Corporation.
22
+ * Portions created by the Initial Developer are Copyright (C) 1998
23
+ * the Initial Developer. All Rights Reserved.
24
+ *
25
+ * Contributor(s):
26
+ * John Bandhauer <jband@netscape.com> (original author)
27
+ * Mike Shaver <shaver@mozilla.org>
28
+ * Mark Hammond <MarkH@ActiveState.com>
29
+ *
30
+ * Alternatively, the contents of this file may be used under the terms of
31
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
32
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
33
+ * in which case the provisions of the GPL or the LGPL are applicable instead
34
+ * of those above. If you wish to allow use of your version of this file only
35
+ * under the terms of either the GPL or the LGPL, and not to allow others to
36
+ * use your version of this file under the terms of the MPL, indicate your
37
+ * decision by deleting the provisions above and replace them with the notice
38
+ * and other provisions required by the GPL or the LGPL. If you do not delete
39
+ * the provisions above, a recipient may use your version of this file under
40
+ * the terms of any one of the MPL, the GPL or the LGPL.
41
+ *
42
+ * ***** END LICENSE BLOCK ***** */
43
+
44
+ /* All the XPConnect private declarations - only include locally. */
45
+
46
+ #ifndef xpcprivate_h___
47
+ #define xpcprivate_h___
48
+
49
+ #include <string.h>
50
+ #include <stdlib.h>
51
+ #include <stdarg.h>
52
+ #include <math.h>
53
+ #include "nscore.h"
54
+ #include "nsXPCOM.h"
55
+ #include "nsAutoPtr.h"
56
+ #include "nsCycleCollectionParticipant.h"
57
+ #include "nsCycleCollector.h"
58
+ #include "nsISupports.h"
59
+ #include "nsIServiceManager.h"
60
+ #include "nsIClassInfoImpl.h"
61
+ #include "nsIComponentManager.h"
62
+ #include "nsIComponentRegistrar.h"
63
+ #include "nsISupportsPrimitives.h"
64
+ #include "nsIGenericFactory.h"
65
+ #include "nsMemory.h"
66
+ #include "nsIXPConnect.h"
67
+ #include "nsIInterfaceInfo.h"
68
+ #include "nsIInterfaceInfoManager.h"
69
+ #include "nsIXPCScriptable.h"
70
+ #include "nsIXPCSecurityManager.h"
71
+ #include "nsIJSRuntimeService.h"
72
+ #include "nsWeakReference.h"
73
+ #include "nsCOMPtr.h"
74
+ #include "nsIModule.h"
75
+ #include "nsAutoLock.h"
76
+ #include "nsXPTCUtils.h"
77
+ #include "jsapi.h"
78
+ #include "jsdhash.h"
79
+ #include "jsprf.h"
80
+ #include "prprf.h"
81
+ #include "jsinterp.h"
82
+ #include "jscntxt.h"
83
+ #include "jsdbgapi.h"
84
+ #include "jsgc.h"
85
+ #include "xptinfo.h"
86
+ #include "xpcforwards.h"
87
+ #include "xpclog.h"
88
+ #include "xpccomponents.h"
89
+ #include "xpcexception.h"
90
+ #include "xpcjsid.h"
91
+ #include "prlong.h"
92
+ #include "prmem.h"
93
+ #include "prenv.h"
94
+ #include "prclist.h"
95
+ #include "nsString.h"
96
+ #include "nsReadableUtils.h"
97
+ #include "nsXPIDLString.h"
98
+ #include "nsAutoJSValHolder.h"
99
+
100
+ #include "nsThreadUtils.h"
101
+ #include "nsIJSContextStack.h"
102
+ #include "nsDeque.h"
103
+ #include "nsVoidArray.h"
104
+
105
+ #include "nsIConsoleService.h"
106
+ #include "nsIScriptError.h"
107
+ #include "nsIExceptionService.h"
108
+
109
+ #include "nsVariant.h"
110
+ #include "nsIPropertyBag.h"
111
+ #include "nsIProperty.h"
112
+ #include "nsSupportsArray.h"
113
+ #include "nsTArray.h"
114
+ #include "nsBaseHashtable.h"
115
+ #include "nsHashKeys.h"
116
+ #include "nsWrapperCache.h"
117
+
118
+ #include "nsIXPCScriptNotify.h" // used to notify: ScriptEvaluated
119
+
120
+ #ifndef XPCONNECT_STANDALONE
121
+ #define XPC_USE_SECURITY_CHECKED_COMPONENT
122
+ #include "nsIScriptObjectPrincipal.h"
123
+ #include "nsIPrincipal.h"
124
+ #endif
125
+
126
+ #ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
127
+ #include "nsISecurityCheckedComponent.h"
128
+ #endif
129
+
130
+ #ifdef XPC_TOOLS_SUPPORT
131
+ #include "nsIXPCToolsProfiler.h"
132
+ #endif
133
+
134
+ #include "nsIThreadInternal.h"
135
+
136
+ #ifdef XPC_IDISPATCH_SUPPORT
137
+ // This goop was added because of EXCEPINFO in ThrowCOMError
138
+ // This include is here, because it needs to occur before the undefines below
139
+ #include <atlbase.h>
140
+ #include "oaidl.h"
141
+ // Nasty MS defines
142
+ #undef GetClassInfo
143
+ #undef GetClassName
144
+ #endif
145
+
146
+ /***************************************************************************/
147
+ // Compile time switches for instrumentation and stuff....
148
+
149
+ // Note that one would not normally turn *any* of these on in a non-DEBUG build.
150
+
151
+ #if defined(DEBUG_jband) || defined(DEBUG_jst) || defined(DEBUG_dbradley) || defined(DEBUG_shaver_no) || defined(DEBUG_timeless)
152
+ #define DEBUG_xpc_hacker
153
+ #endif
154
+
155
+ #if defined(DEBUG_brendan)
156
+ #define DEBUG_XPCNativeWrapper 1
157
+ #endif
158
+
159
+ #ifdef DEBUG
160
+ #define XPC_DETECT_LEADING_UPPERCASE_ACCESS_ERRORS
161
+ #define XPC_CHECK_WRAPPER_THREADSAFETY
162
+ #endif
163
+
164
+ #if defined(DEBUG_xpc_hacker)
165
+ #define XPC_DUMP_AT_SHUTDOWN
166
+ #define XPC_TRACK_WRAPPER_STATS
167
+ #define XPC_TRACK_SCOPE_STATS
168
+ #define XPC_TRACK_PROTO_STATS
169
+ #define XPC_TRACK_DEFERRED_RELEASES
170
+ #define XPC_CHECK_WRAPPERS_AT_SHUTDOWN
171
+ #define XPC_REPORT_SHADOWED_WRAPPED_NATIVE_MEMBERS
172
+ #define XPC_CHECK_CLASSINFO_CLAIMS
173
+ #if defined(DEBUG_jst)
174
+ #define XPC_ASSERT_CLASSINFO_CLAIMS
175
+ #endif
176
+ //#define DEBUG_stats_jband 1
177
+ //#define XPC_REPORT_NATIVE_INTERFACE_AND_SET_FLUSHING
178
+ //#define XPC_REPORT_JSCLASS_FLUSHING
179
+ //#define XPC_TRACK_AUTOMARKINGPTR_STATS
180
+ #endif
181
+
182
+ #if defined(DEBUG_dbaron) || defined(DEBUG_bzbarsky) // only part of DEBUG_xpc_hacker!
183
+ #define XPC_DUMP_AT_SHUTDOWN
184
+ #endif
185
+
186
+ /***************************************************************************/
187
+ // conditional forward declarations....
188
+
189
+ #ifdef XPC_REPORT_SHADOWED_WRAPPED_NATIVE_MEMBERS
190
+ void DEBUG_ReportShadowedMembers(XPCNativeSet* set,
191
+ XPCWrappedNative* wrapper,
192
+ XPCWrappedNativeProto* proto);
193
+ #else
194
+ #define DEBUG_ReportShadowedMembers(set, wrapper, proto) ((void)0)
195
+ #endif
196
+
197
+ #ifdef XPC_CHECK_WRAPPER_THREADSAFETY
198
+ void DEBUG_ReportWrapperThreadSafetyError(XPCCallContext& ccx,
199
+ const char* msg,
200
+ const XPCWrappedNative* wrapper);
201
+ void DEBUG_CheckWrapperThreadSafety(const XPCWrappedNative* wrapper);
202
+ #else
203
+ #define DEBUG_CheckWrapperThreadSafety(w) ((void)0)
204
+ #endif
205
+
206
+ /***************************************************************************/
207
+
208
+ // Defeat possible Windows macro-mangling of the name
209
+ #ifdef GetClassInfo
210
+ #undef GetClassInfo
211
+ #endif
212
+
213
+ /***************************************************************************/
214
+ // default initial sizes for maps (hashtables)
215
+
216
+ #define XPC_CONTEXT_MAP_SIZE 16
217
+ #define XPC_JS_MAP_SIZE 64
218
+ #define XPC_JS_CLASS_MAP_SIZE 64
219
+
220
+ #define XPC_NATIVE_MAP_SIZE 64
221
+ #define XPC_NATIVE_PROTO_MAP_SIZE 16
222
+ #define XPC_DYING_NATIVE_PROTO_MAP_SIZE 16
223
+ #define XPC_DETACHED_NATIVE_PROTO_MAP_SIZE 32
224
+ #define XPC_NATIVE_INTERFACE_MAP_SIZE 64
225
+ #define XPC_NATIVE_SET_MAP_SIZE 64
226
+ #define XPC_NATIVE_JSCLASS_MAP_SIZE 32
227
+ #define XPC_THIS_TRANSLATOR_MAP_SIZE 8
228
+ #define XPC_NATIVE_WRAPPER_MAP_SIZE 16
229
+ #define XPC_WRAPPER_MAP_SIZE 8
230
+
231
+ /***************************************************************************/
232
+ // data declarations...
233
+ extern const char* XPC_ARG_FORMATTER_FORMAT_STRINGS[]; // format strings
234
+ extern const char XPC_CONTEXT_STACK_CONTRACTID[];
235
+ extern const char XPC_RUNTIME_CONTRACTID[];
236
+ extern const char XPC_EXCEPTION_CONTRACTID[];
237
+ extern const char XPC_CONSOLE_CONTRACTID[];
238
+ extern const char XPC_SCRIPT_ERROR_CONTRACTID[];
239
+ extern const char XPC_ID_CONTRACTID[];
240
+ extern const char XPC_XPCONNECT_CONTRACTID[];
241
+
242
+ /***************************************************************************/
243
+ // useful macros...
244
+
245
+ #define XPC_STRING_GETTER_BODY(dest, src) \
246
+ NS_ENSURE_ARG_POINTER(dest); \
247
+ char* result; \
248
+ if(src) \
249
+ result = (char*) nsMemory::Clone(src, \
250
+ sizeof(char)*(strlen(src)+1)); \
251
+ else \
252
+ result = nsnull; \
253
+ *dest = result; \
254
+ return (result || !src) ? NS_OK : NS_ERROR_OUT_OF_MEMORY
255
+
256
+
257
+ // NOTE!!!
258
+ //
259
+ // If this ever changes,
260
+ // nsScriptSecurityManager::doGetObjectPrincipal() *must* be updated
261
+ // also!
262
+ //
263
+ // NOTE!!!
264
+ #define IS_WRAPPER_CLASS(clazz) \
265
+ ((clazz) == &XPC_WN_NoHelper_JSClass.base || \
266
+ (clazz)->getObjectOps == XPC_WN_GetObjectOpsNoCall || \
267
+ (clazz)->getObjectOps == XPC_WN_GetObjectOpsWithCall)
268
+
269
+ /***************************************************************************/
270
+ // Auto locking support class...
271
+
272
+ // We PROMISE to never screw this up.
273
+ #ifdef _MSC_VER
274
+ #pragma warning(disable : 4355) // OK to pass "this" in member initializer
275
+ #endif
276
+
277
+ typedef PRMonitor XPCLock;
278
+
279
+ static inline void xpc_Wait(XPCLock* lock)
280
+ {
281
+ NS_ASSERTION(lock, "xpc_Wait called with null lock!");
282
+ #ifdef DEBUG
283
+ PRStatus result =
284
+ #endif
285
+ PR_Wait(lock, PR_INTERVAL_NO_TIMEOUT);
286
+ NS_ASSERTION(PR_SUCCESS == result, "bad result from PR_Wait!");
287
+ }
288
+
289
+ static inline void xpc_NotifyAll(XPCLock* lock)
290
+ {
291
+ NS_ASSERTION(lock, "xpc_NotifyAll called with null lock!");
292
+ #ifdef DEBUG
293
+ PRStatus result =
294
+ #endif
295
+ PR_NotifyAll(lock);
296
+ NS_ASSERTION(PR_SUCCESS == result, "bad result from PR_NotifyAll!");
297
+ }
298
+
299
+ // This is a cloned subset of nsAutoMonitor. We want the use of a monitor -
300
+ // mostly because we need reenterability - but we also want to support passing
301
+ // a null monitor in without things blowing up. This is used for wrappers that
302
+ // are guaranteed to be used only on one thread. We avoid lock overhead by
303
+ // using a null monitor. By changing this class we can avoid having multiplte
304
+ // code paths or (conditional) manual calls to PR_{Enter,Exit}Monitor.
305
+ //
306
+ // Note that xpconnect only makes *one* monitor and *mostly* holds it locked
307
+ // only through very small critical sections.
308
+
309
+ class XPCAutoLock : public nsAutoLockBase {
310
+ public:
311
+
312
+ static XPCLock* NewLock(const char* name)
313
+ {return nsAutoMonitor::NewMonitor(name);}
314
+ static void DestroyLock(XPCLock* lock)
315
+ {nsAutoMonitor::DestroyMonitor(lock);}
316
+
317
+ XPCAutoLock(XPCLock* lock)
318
+ #ifdef DEBUG_jband
319
+ : nsAutoLockBase(lock ? (void*) lock : (void*) this, eAutoMonitor),
320
+ #else
321
+ : nsAutoLockBase(lock, eAutoMonitor),
322
+ #endif
323
+ mLock(lock)
324
+ {
325
+ if(mLock)
326
+ PR_EnterMonitor(mLock);
327
+ }
328
+
329
+ ~XPCAutoLock()
330
+ {
331
+ if(mLock)
332
+ {
333
+ #ifdef DEBUG
334
+ PRStatus status =
335
+ #endif
336
+ PR_ExitMonitor(mLock);
337
+ NS_ASSERTION(status == PR_SUCCESS, "PR_ExitMonitor failed");
338
+ }
339
+ }
340
+
341
+ private:
342
+ XPCLock* mLock;
343
+
344
+ // Not meant to be implemented. This makes it a compiler error to
345
+ // construct or assign an XPCAutoLock object incorrectly.
346
+ XPCAutoLock(void) {}
347
+ XPCAutoLock(XPCAutoLock& /*aMon*/) {}
348
+ XPCAutoLock& operator =(XPCAutoLock& /*aMon*/) {
349
+ return *this;
350
+ }
351
+
352
+ // Not meant to be implemented. This makes it a compiler error to
353
+ // attempt to create an XPCAutoLock object on the heap.
354
+ static void* operator new(size_t /*size*/) CPP_THROW_NEW {
355
+ return nsnull;
356
+ }
357
+ static void operator delete(void* /*memory*/) {}
358
+ };
359
+
360
+ /************************************************/
361
+
362
+ class XPCAutoUnlock : public nsAutoUnlockBase {
363
+ public:
364
+ XPCAutoUnlock(XPCLock* lock)
365
+ : nsAutoUnlockBase(lock),
366
+ mLock(lock)
367
+ {
368
+ if(mLock)
369
+ {
370
+ #ifdef DEBUG
371
+ PRStatus status =
372
+ #endif
373
+ PR_ExitMonitor(mLock);
374
+ NS_ASSERTION(status == PR_SUCCESS, "PR_ExitMonitor failed");
375
+ }
376
+ }
377
+
378
+ ~XPCAutoUnlock()
379
+ {
380
+ if(mLock)
381
+ PR_EnterMonitor(mLock);
382
+ }
383
+
384
+ private:
385
+ XPCLock* mLock;
386
+
387
+ // Not meant to be implemented. This makes it a compiler error to
388
+ // construct or assign an XPCAutoUnlock object incorrectly.
389
+ XPCAutoUnlock(void) {}
390
+ XPCAutoUnlock(XPCAutoUnlock& /*aMon*/) {}
391
+ XPCAutoUnlock& operator =(XPCAutoUnlock& /*aMon*/) {
392
+ return *this;
393
+ }
394
+
395
+ // Not meant to be implemented. This makes it a compiler error to
396
+ // attempt to create an XPCAutoUnlock object on the heap.
397
+ static void* operator new(size_t /*size*/) CPP_THROW_NEW {
398
+ return nsnull;
399
+ }
400
+ static void operator delete(void* /*memory*/) {}
401
+ };
402
+
403
+ // A helper class to deal with temporary JS contexts. It destroys the context
404
+ // when it goes out of scope.
405
+ class XPCAutoJSContext
406
+ {
407
+ public:
408
+ XPCAutoJSContext(JSContext *aContext, PRBool aGCOnDestroy)
409
+ : mContext(aContext), mGCOnDestroy(aGCOnDestroy)
410
+ {
411
+ }
412
+
413
+ ~XPCAutoJSContext()
414
+ {
415
+ if(!mContext)
416
+ return;
417
+
418
+ if(mGCOnDestroy)
419
+ JS_DestroyContext(mContext);
420
+ else
421
+ JS_DestroyContextNoGC(mContext);
422
+ }
423
+
424
+ operator JSContext * () {return mContext;}
425
+
426
+ private:
427
+ JSContext *mContext;
428
+ PRBool mGCOnDestroy;
429
+ };
430
+
431
+ /***************************************************************************
432
+ ****************************************************************************
433
+ *
434
+ * Core runtime and context classes...
435
+ *
436
+ ****************************************************************************
437
+ ***************************************************************************/
438
+
439
+ // We have a general rule internally that getters that return addref'd interface
440
+ // pointer generally do so using an 'out' parm. When interface pointers are
441
+ // returned as function call result values they are not addref'd. Exceptions
442
+ // to this rule are noted explicitly.
443
+
444
+ const PRBool OBJ_IS_GLOBAL = PR_TRUE;
445
+ const PRBool OBJ_IS_NOT_GLOBAL = PR_FALSE;
446
+
447
+ #define NS_JS_RUNTIME_SERVICE_CID \
448
+ {0xb5e65b52, 0x1dd1, 0x11b2, \
449
+ { 0xae, 0x8f, 0xf0, 0x92, 0x8e, 0xd8, 0x84, 0x82 }}
450
+
451
+ #define NS_XPC_THREAD_JSCONTEXT_STACK_CID \
452
+ { 0xff8c4d10, 0x3194, 0x11d3, \
453
+ { 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
454
+
455
+ class nsXPConnect : public nsIXPConnect,
456
+ public nsIThreadObserver,
457
+ public nsSupportsWeakReference,
458
+ public nsCycleCollectionJSRuntime,
459
+ public nsCycleCollectionParticipant,
460
+ public nsIJSRuntimeService,
461
+ public nsIThreadJSContextStack
462
+ {
463
+ public:
464
+ // all the interface method declarations...
465
+ NS_DECL_ISUPPORTS
466
+ NS_DECL_NSIXPCONNECT
467
+ NS_DECL_NSITHREADOBSERVER
468
+ NS_DECL_NSIJSRUNTIMESERVICE
469
+ NS_DECL_NSIJSCONTEXTSTACK
470
+ NS_DECL_NSITHREADJSCONTEXTSTACK
471
+
472
+ // non-interface implementation
473
+ public:
474
+ // These get non-addref'd pointers
475
+ static nsXPConnect* GetXPConnect();
476
+ static XPCJSRuntime* GetRuntimeInstance();
477
+ XPCJSRuntime* GetRuntime() {return mRuntime;}
478
+
479
+ // Gets addref'd pointer
480
+ static nsresult GetInterfaceInfoManager(nsIInterfaceInfoSuperManager** iim,
481
+ nsXPConnect* xpc = nsnull);
482
+
483
+ static JSBool IsISupportsDescendant(nsIInterfaceInfo* info);
484
+
485
+ nsIXPCSecurityManager* GetDefaultSecurityManager() const
486
+ {return mDefaultSecurityManager;}
487
+
488
+ PRUint16 GetDefaultSecurityManagerFlags() const
489
+ {return mDefaultSecurityManagerFlags;}
490
+
491
+ // This returns an AddRef'd pointer. It does not do this with an 'out' param
492
+ // only because this form is required by the generic module macro:
493
+ // NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR
494
+ static nsXPConnect* GetSingleton();
495
+
496
+ // Called by module code in dll startup
497
+ static void InitStatics() { gSelf = nsnull; gOnceAliveNowDead = JS_FALSE; }
498
+ // Called by module code on dll shutdown.
499
+ static void ReleaseXPConnectSingleton();
500
+
501
+ virtual ~nsXPConnect();
502
+
503
+ JSBool IsShuttingDown() const {return mShuttingDown;}
504
+
505
+ nsresult GetInfoForIID(const nsIID * aIID, nsIInterfaceInfo** info);
506
+ nsresult GetInfoForName(const char * name, nsIInterfaceInfo** info);
507
+
508
+ // nsCycleCollectionParticipant
509
+ NS_IMETHOD RootAndUnlinkJSObjects(void *p);
510
+ NS_IMETHOD Unlink(void *p);
511
+ NS_IMETHOD Unroot(void *p);
512
+ NS_IMETHOD Traverse(void *p,
513
+ nsCycleCollectionTraversalCallback &cb);
514
+
515
+ // nsCycleCollectionLanguageRuntime
516
+ virtual nsresult BeginCycleCollection(nsCycleCollectionTraversalCallback &cb);
517
+ virtual nsresult FinishCycleCollection();
518
+ virtual nsCycleCollectionParticipant *ToParticipant(void *p);
519
+ virtual PRBool Collect();
520
+ #ifdef DEBUG_CC
521
+ virtual void PrintAllReferencesTo(void *p);
522
+ #endif
523
+
524
+ // We should not trace XPConnect JS roots when tracing the graph for the
525
+ // cycle collector. Those should be traced from the XPCOM objects that hold
526
+ // them when we know that they won't be collected by the cycle collector.
527
+ PRBool ShouldTraceRoots()
528
+ {
529
+ return !mCycleCollecting;
530
+ }
531
+
532
+ XPCCallContext* GetCycleCollectionContext()
533
+ {
534
+ return mCycleCollectionContext;
535
+ }
536
+
537
+ PRInt32 GetRequestDepth(JSContext* cx);
538
+
539
+ // This returns the singleton nsCycleCollectionParticipant for JSContexts.
540
+ static nsCycleCollectionParticipant *JSContextParticipant();
541
+
542
+ #ifndef XPCONNECT_STANDALONE
543
+ void RecordTraversal(void *p, nsISupports *s);
544
+ #endif
545
+ static PRBool ReportAllJSExceptions()
546
+ {
547
+ return gReportAllJSExceptions > 0;
548
+ }
549
+
550
+ #ifdef XPC_IDISPATCH_SUPPORT
551
+ public:
552
+ static PRBool IsIDispatchEnabled();
553
+ #endif
554
+ protected:
555
+ nsXPConnect();
556
+
557
+ private:
558
+ static PRThread* FindMainThread();
559
+
560
+ private:
561
+ // Singleton instance
562
+ static nsXPConnect* gSelf;
563
+ static JSBool gOnceAliveNowDead;
564
+
565
+ XPCJSRuntime* mRuntime;
566
+ nsCOMPtr<nsIInterfaceInfoSuperManager> mInterfaceInfoManager;
567
+ nsIXPCSecurityManager* mDefaultSecurityManager;
568
+ PRUint16 mDefaultSecurityManagerFlags;
569
+ JSBool mShuttingDown;
570
+ XPCCallContext* mCycleCollectionContext;
571
+ #ifdef DEBUG_CC
572
+ nsAutoPtr<XPCCallContext> mExplainCycleCollectionContext;
573
+ PLDHashTable mJSRoots;
574
+ #endif
575
+ PRBool mCycleCollecting;
576
+
577
+ #ifdef XPC_TOOLS_SUPPORT
578
+ nsCOMPtr<nsIXPCToolsProfiler> mProfiler;
579
+ nsCOMPtr<nsILocalFile> mProfilerOutputFile;
580
+ #endif
581
+
582
+ #ifndef XPCONNECT_STANDALONE
583
+ typedef nsBaseHashtable<nsVoidPtrHashKey, nsISupports*, nsISupports*> ScopeSet;
584
+ ScopeSet mScopes;
585
+ #endif
586
+ nsCOMPtr<nsIXPCScriptable> mBackstagePass;
587
+
588
+ static PRUint32 gReportAllJSExceptions;
589
+ };
590
+
591
+ /***************************************************************************/
592
+
593
+ class XPCRootSetElem
594
+ {
595
+ public:
596
+ XPCRootSetElem()
597
+ {
598
+ #ifdef DEBUG
599
+ mNext = nsnull;
600
+ mSelfp = nsnull;
601
+ #endif
602
+ }
603
+
604
+ ~XPCRootSetElem()
605
+ {
606
+ NS_ASSERTION(!mNext, "Must be unlinked");
607
+ NS_ASSERTION(!mSelfp, "Must be unlinked");
608
+ }
609
+
610
+ inline XPCRootSetElem* GetNextRoot() { return mNext; }
611
+ void AddToRootSet(JSRuntime* rt, XPCRootSetElem** listHead);
612
+ void RemoveFromRootSet(JSRuntime* rt);
613
+
614
+ private:
615
+ XPCRootSetElem *mNext;
616
+ XPCRootSetElem **mSelfp;
617
+ };
618
+
619
+ /***************************************************************************/
620
+
621
+ // In the current xpconnect system there can only be one XPCJSRuntime.
622
+ // So, xpconnect can only be used on one JSRuntime within the process.
623
+
624
+ // no virtuals. no refcounting.
625
+ class XPCJSRuntime
626
+ {
627
+ public:
628
+ static XPCJSRuntime* newXPCJSRuntime(nsXPConnect* aXPConnect);
629
+
630
+ JSRuntime* GetJSRuntime() const {return mJSRuntime;}
631
+ nsXPConnect* GetXPConnect() const {return mXPConnect;}
632
+
633
+ JSObject2WrappedJSMap* GetWrappedJSMap() const
634
+ {return mWrappedJSMap;}
635
+
636
+ IID2WrappedJSClassMap* GetWrappedJSClassMap() const
637
+ {return mWrappedJSClassMap;}
638
+
639
+ IID2NativeInterfaceMap* GetIID2NativeInterfaceMap() const
640
+ {return mIID2NativeInterfaceMap;}
641
+
642
+ ClassInfo2NativeSetMap* GetClassInfo2NativeSetMap() const
643
+ {return mClassInfo2NativeSetMap;}
644
+
645
+ NativeSetMap* GetNativeSetMap() const
646
+ {return mNativeSetMap;}
647
+
648
+ IID2ThisTranslatorMap* GetThisTranslatorMap() const
649
+ {return mThisTranslatorMap;}
650
+
651
+ XPCNativeScriptableSharedMap* GetNativeScriptableSharedMap() const
652
+ {return mNativeScriptableSharedMap;}
653
+
654
+ XPCWrappedNativeProtoMap* GetDyingWrappedNativeProtoMap() const
655
+ {return mDyingWrappedNativeProtoMap;}
656
+
657
+ XPCWrappedNativeProtoMap* GetDetachedWrappedNativeProtoMap() const
658
+ {return mDetachedWrappedNativeProtoMap;}
659
+
660
+ XPCNativeWrapperMap* GetExplicitNativeWrapperMap() const
661
+ {return mExplicitNativeWrapperMap;}
662
+
663
+ XPCLock* GetMapLock() const {return mMapLock;}
664
+
665
+ JSBool OnJSContextNew(JSContext* cx);
666
+
667
+ JSBool DeferredRelease(nsISupports* obj);
668
+
669
+ JSBool GetDoingFinalization() const {return mDoingFinalization;}
670
+
671
+ // Mapping of often used strings to jsid atoms that live 'forever'.
672
+ //
673
+ // To add a new string: add to this list and to XPCJSRuntime::mStrings
674
+ // at the top of xpcjsruntime.cpp
675
+ enum {
676
+ IDX_CONSTRUCTOR = 0 ,
677
+ IDX_TO_STRING ,
678
+ IDX_TO_SOURCE ,
679
+ IDX_LAST_RESULT ,
680
+ IDX_RETURN_CODE ,
681
+ IDX_VALUE ,
682
+ IDX_QUERY_INTERFACE ,
683
+ IDX_COMPONENTS ,
684
+ IDX_WRAPPED_JSOBJECT ,
685
+ IDX_OBJECT ,
686
+ IDX_FUNCTION ,
687
+ IDX_PROTOTYPE ,
688
+ IDX_CREATE_INSTANCE ,
689
+ IDX_ITEM ,
690
+ IDX_PROTO ,
691
+ IDX_ITERATOR ,
692
+ #ifdef XPC_IDISPATCH_SUPPORT
693
+ IDX_ACTIVEX_OBJECT ,
694
+ IDX_COM_OBJECT ,
695
+ IDX_ACTIVEX_SUPPORTS ,
696
+ #endif
697
+ IDX_TOTAL_COUNT // just a count of the above
698
+ };
699
+
700
+ jsid GetStringID(uintN index) const
701
+ {
702
+ NS_ASSERTION(index < IDX_TOTAL_COUNT, "index out of range");
703
+ return mStrIDs[index];
704
+ }
705
+ jsval GetStringJSVal(uintN index) const
706
+ {
707
+ NS_ASSERTION(index < IDX_TOTAL_COUNT, "index out of range");
708
+ return mStrJSVals[index];
709
+ }
710
+ const char* GetStringName(uintN index) const
711
+ {
712
+ NS_ASSERTION(index < IDX_TOTAL_COUNT, "index out of range");
713
+ return mStrings[index];
714
+ }
715
+
716
+ static void TraceJS(JSTracer* trc, void* data);
717
+ void TraceXPConnectRoots(JSTracer *trc, JSBool rootGlobals = JS_FALSE);
718
+ void AddXPConnectRoots(JSContext* cx,
719
+ nsCycleCollectionTraversalCallback& cb);
720
+
721
+ static JSBool GCCallback(JSContext *cx, JSGCStatus status);
722
+
723
+ inline void AddVariantRoot(XPCTraceableVariant* variant);
724
+ inline void AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS);
725
+ inline void AddObjectHolderRoot(XPCJSObjectHolder* holder);
726
+
727
+ nsresult AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer);
728
+ nsresult RemoveJSHolder(void* aHolder);
729
+
730
+ void UnrootContextGlobals();
731
+ #ifdef DEBUG_CC
732
+ void RootContextGlobals();
733
+ #endif
734
+
735
+ void DebugDump(PRInt16 depth);
736
+
737
+ void SystemIsBeingShutDown(JSContext* cx);
738
+
739
+ PRThread* GetThreadRunningGC() const {return mThreadRunningGC;}
740
+
741
+ ~XPCJSRuntime();
742
+
743
+ #ifdef XPC_CHECK_WRAPPERS_AT_SHUTDOWN
744
+ void DEBUG_AddWrappedNative(nsIXPConnectWrappedNative* wrapper)
745
+ {XPCAutoLock lock(GetMapLock());
746
+ JSDHashEntryHdr *entry =
747
+ JS_DHashTableOperate(DEBUG_WrappedNativeHashtable,
748
+ wrapper, JS_DHASH_ADD);
749
+ if(entry) ((JSDHashEntryStub *)entry)->key = wrapper;}
750
+
751
+ void DEBUG_RemoveWrappedNative(nsIXPConnectWrappedNative* wrapper)
752
+ {XPCAutoLock lock(GetMapLock());
753
+ JS_DHashTableOperate(DEBUG_WrappedNativeHashtable,
754
+ wrapper, JS_DHASH_REMOVE);}
755
+ private:
756
+ JSDHashTable* DEBUG_WrappedNativeHashtable;
757
+ public:
758
+ #endif
759
+
760
+ private:
761
+ XPCJSRuntime(); // no implementation
762
+ XPCJSRuntime(nsXPConnect* aXPConnect);
763
+
764
+ // The caller must be holding the GC lock
765
+ void RescheduleWatchdog(XPCContext* ccx);
766
+
767
+ static void WatchdogMain(void *arg);
768
+
769
+ static const char* mStrings[IDX_TOTAL_COUNT];
770
+ jsid mStrIDs[IDX_TOTAL_COUNT];
771
+ jsval mStrJSVals[IDX_TOTAL_COUNT];
772
+
773
+ nsXPConnect* mXPConnect;
774
+ JSRuntime* mJSRuntime;
775
+ JSObject2WrappedJSMap* mWrappedJSMap;
776
+ IID2WrappedJSClassMap* mWrappedJSClassMap;
777
+ IID2NativeInterfaceMap* mIID2NativeInterfaceMap;
778
+ ClassInfo2NativeSetMap* mClassInfo2NativeSetMap;
779
+ NativeSetMap* mNativeSetMap;
780
+ IID2ThisTranslatorMap* mThisTranslatorMap;
781
+ XPCNativeScriptableSharedMap* mNativeScriptableSharedMap;
782
+ XPCWrappedNativeProtoMap* mDyingWrappedNativeProtoMap;
783
+ XPCWrappedNativeProtoMap* mDetachedWrappedNativeProtoMap;
784
+ XPCNativeWrapperMap* mExplicitNativeWrapperMap;
785
+ XPCLock* mMapLock;
786
+ PRThread* mThreadRunningGC;
787
+ nsVoidArray mWrappedJSToReleaseArray;
788
+ nsVoidArray mNativesToReleaseArray;
789
+ JSBool mDoingFinalization;
790
+ XPCRootSetElem *mVariantRoots;
791
+ XPCRootSetElem *mWrappedJSRoots;
792
+ XPCRootSetElem *mObjectHolderRoots;
793
+ JSDHashTable mJSHolders;
794
+ uintN mUnrootedGlobalCount;
795
+ PRCondVar *mWatchdogWakeup;
796
+ PRThread *mWatchdogThread;
797
+ };
798
+
799
+ /***************************************************************************/
800
+ /***************************************************************************/
801
+ // XPCContext is mostly a dumb class to hold JSContext specific data and
802
+ // maps that let us find wrappers created for the given JSContext.
803
+
804
+ // no virtuals
805
+ class XPCContext
806
+ {
807
+ friend class XPCJSRuntime;
808
+ public:
809
+ static XPCContext* GetXPCContext(JSContext* aJSContext)
810
+ {
811
+ NS_ASSERTION(aJSContext->data2, "should already have XPCContext");
812
+ return static_cast<XPCContext *>(aJSContext->data2);
813
+ }
814
+
815
+ XPCJSRuntime* GetRuntime() const {return mRuntime;}
816
+ JSContext* GetJSContext() const {return mJSContext;}
817
+
818
+ enum LangType {LANG_UNKNOWN, LANG_JS, LANG_NATIVE};
819
+
820
+ LangType GetCallingLangType() const
821
+ {
822
+ return mCallingLangType;
823
+ }
824
+ LangType SetCallingLangType(LangType lt)
825
+ {
826
+ LangType tmp = mCallingLangType;
827
+ mCallingLangType = lt;
828
+ return tmp;
829
+ }
830
+ JSBool CallerTypeIsJavaScript() const
831
+ {
832
+ return LANG_JS == mCallingLangType;
833
+ }
834
+ JSBool CallerTypeIsNative() const
835
+ {
836
+ return LANG_NATIVE == mCallingLangType;
837
+ }
838
+ JSBool CallerTypeIsKnown() const
839
+ {
840
+ return LANG_UNKNOWN != mCallingLangType;
841
+ }
842
+
843
+ nsresult GetException(nsIException** e)
844
+ {
845
+ NS_IF_ADDREF(mException);
846
+ *e = mException;
847
+ return NS_OK;
848
+ }
849
+ void SetException(nsIException* e)
850
+ {
851
+ NS_IF_ADDREF(e);
852
+ NS_IF_RELEASE(mException);
853
+ mException = e;
854
+ }
855
+
856
+ nsresult GetLastResult() {return mLastResult;}
857
+ void SetLastResult(nsresult rc) {mLastResult = rc;}
858
+
859
+ nsresult GetPendingResult() {return mPendingResult;}
860
+ void SetPendingResult(nsresult rc) {mPendingResult = rc;}
861
+
862
+ nsIXPCSecurityManager* GetSecurityManager() const
863
+ {return mSecurityManager;}
864
+ void SetSecurityManager(nsIXPCSecurityManager* aSecurityManager)
865
+ {mSecurityManager = aSecurityManager;}
866
+
867
+ PRUint16 GetSecurityManagerFlags() const
868
+ {return mSecurityManagerFlags;}
869
+ void SetSecurityManagerFlags(PRUint16 f)
870
+ {mSecurityManagerFlags = f;}
871
+
872
+ nsIXPCSecurityManager* GetAppropriateSecurityManager(PRUint16 flags) const
873
+ {
874
+ NS_ASSERTION(CallerTypeIsKnown(),"missing caller type set somewhere");
875
+ if(!CallerTypeIsJavaScript())
876
+ return nsnull;
877
+ if(mSecurityManager)
878
+ {
879
+ if(flags & mSecurityManagerFlags)
880
+ return mSecurityManager;
881
+ }
882
+ else
883
+ {
884
+ nsIXPCSecurityManager* mgr;
885
+ nsXPConnect* xpc = mRuntime->GetXPConnect();
886
+ mgr = xpc->GetDefaultSecurityManager();
887
+ if(mgr && (flags & xpc->GetDefaultSecurityManagerFlags()))
888
+ return mgr;
889
+ }
890
+ return nsnull;
891
+ }
892
+
893
+ void DebugDump(PRInt16 depth);
894
+ void AddScope(PRCList *scope) { PR_INSERT_AFTER(scope, &mScopes); }
895
+ void RemoveScope(PRCList *scope) { PR_REMOVE_LINK(scope); }
896
+
897
+ ~XPCContext();
898
+
899
+ private:
900
+ XPCContext(); // no implementation
901
+ XPCContext(XPCJSRuntime* aRuntime, JSContext* aJSContext);
902
+
903
+ static XPCContext* newXPCContext(XPCJSRuntime* aRuntime,
904
+ JSContext* aJSContext);
905
+ private:
906
+ XPCJSRuntime* mRuntime;
907
+ JSContext* mJSContext;
908
+ nsresult mLastResult;
909
+ nsresult mPendingResult;
910
+ nsIXPCSecurityManager* mSecurityManager;
911
+ nsIException* mException;
912
+ LangType mCallingLangType;
913
+ PRUint16 mSecurityManagerFlags;
914
+
915
+ // A linked list of scopes to notify when we are destroyed.
916
+ PRCList mScopes;
917
+ };
918
+
919
+ /***************************************************************************/
920
+
921
+ #define NATIVE_CALLER XPCContext::LANG_NATIVE
922
+ #define JS_CALLER XPCContext::LANG_JS
923
+
924
+ // class to export a JSString as an const nsAString, no refcounting :(
925
+ class XPCReadableJSStringWrapper : public nsDependentString
926
+ {
927
+ public:
928
+ typedef nsDependentString::char_traits char_traits;
929
+
930
+ XPCReadableJSStringWrapper(const PRUnichar *chars, size_t length) :
931
+ nsDependentString(chars, length)
932
+ { }
933
+
934
+ XPCReadableJSStringWrapper() :
935
+ nsDependentString(char_traits::sEmptyBuffer, char_traits::sEmptyBuffer)
936
+ { SetIsVoid(PR_TRUE); }
937
+
938
+ explicit XPCReadableJSStringWrapper(JSString *str) :
939
+ nsDependentString((const PRUnichar *)::JS_GetStringChars(str),
940
+ ::JS_GetStringLength(str))
941
+ { }
942
+ };
943
+
944
+ // No virtuals
945
+ // XPCCallContext is ALWAYS declared as a local variable in some function;
946
+ // i.e. instance lifetime is always controled by some C++ function returning.
947
+ //
948
+ // These things are created frequently in many places. We *intentionally* do
949
+ // not inialialize all members in order to save on construction overhead.
950
+ // Some constructor pass more valid params than others. We init what must be
951
+ // init'd and leave other members undefined. In debug builds the accessors
952
+ // use a CHECK_STATE macro to track whether or not the object is in a valid
953
+ // state to answer the question a caller might be asking. As long as this
954
+ // class is maintained correctly it can do its job without a bunch of added
955
+ // overhead from useless initializations and non-DEBUG error checking.
956
+ //
957
+ // Note that most accessors are inlined.
958
+
959
+ class XPCCallContext : public nsAXPCNativeCallContext
960
+ {
961
+ public:
962
+ NS_IMETHOD GetCallee(nsISupports **aResult);
963
+ NS_IMETHOD GetCalleeMethodIndex(PRUint16 *aResult);
964
+ NS_IMETHOD GetCalleeWrapper(nsIXPConnectWrappedNative **aResult);
965
+ NS_IMETHOD GetJSContext(JSContext **aResult);
966
+ NS_IMETHOD GetArgc(PRUint32 *aResult);
967
+ NS_IMETHOD GetArgvPtr(jsval **aResult);
968
+ NS_IMETHOD GetRetValPtr(jsval **aResult);
969
+ NS_IMETHOD GetReturnValueWasSet(PRBool *aResult);
970
+ NS_IMETHOD SetReturnValueWasSet(PRBool aValue);
971
+ NS_IMETHOD GetCalleeInterface(nsIInterfaceInfo **aResult);
972
+ NS_IMETHOD GetCalleeClassInfo(nsIClassInfo **aResult);
973
+ NS_IMETHOD GetPreviousCallContext(nsAXPCNativeCallContext **aResult);
974
+ NS_IMETHOD GetLanguage(PRUint16 *aResult);
975
+
976
+ enum {NO_ARGS = (uintN) -1};
977
+
978
+ XPCCallContext(XPCContext::LangType callerLanguage,
979
+ JSContext* cx = nsnull,
980
+ JSObject* obj = nsnull,
981
+ JSObject* funobj = nsnull,
982
+ jsval id = 0,
983
+ uintN argc = NO_ARGS,
984
+ jsval *argv = nsnull,
985
+ jsval *rval = nsnull);
986
+
987
+ virtual ~XPCCallContext();
988
+
989
+ inline JSBool IsValid() const ;
990
+
991
+ inline nsXPConnect* GetXPConnect() const ;
992
+ inline XPCJSRuntime* GetRuntime() const ;
993
+ inline XPCPerThreadData* GetThreadData() const ;
994
+ inline XPCContext* GetXPCContext() const ;
995
+ inline JSContext* GetJSContext() const ;
996
+ inline JSContext* GetSafeJSContext() const ;
997
+ inline JSBool GetContextPopRequired() const ;
998
+ inline XPCContext::LangType GetCallerLanguage() const ;
999
+ inline XPCContext::LangType GetPrevCallerLanguage() const ;
1000
+ inline XPCCallContext* GetPrevCallContext() const ;
1001
+
1002
+ inline JSObject* GetOperandJSObject() const ;
1003
+ inline JSObject* GetCurrentJSObject() const ;
1004
+ inline JSObject* GetFlattenedJSObject() const ;
1005
+
1006
+ inline nsISupports* GetIdentityObject() const ;
1007
+ inline XPCWrappedNative* GetWrapper() const ;
1008
+
1009
+ inline JSBool CanGetTearOff() const ;
1010
+ inline XPCWrappedNativeTearOff* GetTearOff() const ;
1011
+
1012
+ inline XPCNativeScriptableInfo* GetScriptableInfo() const ;
1013
+ inline JSBool CanGetSet() const ;
1014
+ inline XPCNativeSet* GetSet() const ;
1015
+ inline JSBool CanGetInterface() const ;
1016
+ inline XPCNativeInterface* GetInterface() const ;
1017
+ inline XPCNativeMember* GetMember() const ;
1018
+ inline JSBool HasInterfaceAndMember() const ;
1019
+ inline jsval GetName() const ;
1020
+ inline JSBool GetStaticMemberIsLocal() const ;
1021
+ inline uintN GetArgc() const ;
1022
+ inline jsval* GetArgv() const ;
1023
+ inline jsval* GetRetVal() const ;
1024
+ inline JSBool GetReturnValueWasSet() const ;
1025
+
1026
+ inline PRUint16 GetMethodIndex() const ;
1027
+ inline void SetMethodIndex(PRUint16 index) ;
1028
+
1029
+ inline JSBool GetDestroyJSContextInDestructor() const;
1030
+ inline void SetDestroyJSContextInDestructor(JSBool b);
1031
+
1032
+ inline jsval GetResolveName() const;
1033
+ inline jsval SetResolveName(jsval name);
1034
+
1035
+ inline XPCWrappedNative* GetResolvingWrapper() const;
1036
+ inline XPCWrappedNative* SetResolvingWrapper(XPCWrappedNative* w);
1037
+
1038
+ inline void SetRetVal(jsval val);
1039
+
1040
+ inline JSObject* GetCallee() const;
1041
+ inline void SetCallee(JSObject* callee);
1042
+
1043
+ void SetName(jsval name);
1044
+ void SetArgsAndResultPtr(uintN argc, jsval *argv, jsval *rval);
1045
+ void SetCallInfo(XPCNativeInterface* iface, XPCNativeMember* member,
1046
+ JSBool isSetter);
1047
+
1048
+ nsresult CanCallNow();
1049
+
1050
+ void SystemIsBeingShutDown();
1051
+
1052
+ operator JSContext*() const {return GetJSContext();}
1053
+
1054
+ XPCReadableJSStringWrapper *NewStringWrapper(PRUnichar *str, PRUint32 len);
1055
+ void DeleteString(nsAString *string);
1056
+
1057
+ #ifdef XPC_IDISPATCH_SUPPORT
1058
+ /**
1059
+ * Sets the IDispatch information for the context
1060
+ * This has to be void* because of icky Microsoft macros that
1061
+ * would be introduced if we included the DispatchInterface header
1062
+ */
1063
+ void SetIDispatchInfo(XPCNativeInterface* iface, void * member);
1064
+ void* GetIDispatchMember() const { return mIDispatchMember; }
1065
+ #endif
1066
+ private:
1067
+
1068
+ // no copy ctor or assignment allowed
1069
+ XPCCallContext(const XPCCallContext& r); // not implemented
1070
+ XPCCallContext& operator= (const XPCCallContext& r); // not implemented
1071
+
1072
+ private:
1073
+ // posible values for mState
1074
+ enum State {
1075
+ INIT_FAILED,
1076
+ SYSTEM_SHUTDOWN,
1077
+ HAVE_CONTEXT,
1078
+ HAVE_OBJECT,
1079
+ HAVE_NAME,
1080
+ HAVE_ARGS,
1081
+ READY_TO_CALL,
1082
+ CALL_DONE
1083
+ };
1084
+
1085
+ #ifdef DEBUG
1086
+ inline void CHECK_STATE(int s) const {NS_ASSERTION(mState >= s, "bad state");}
1087
+ #else
1088
+ #define CHECK_STATE(s) ((void)0)
1089
+ #endif
1090
+
1091
+ private:
1092
+ State mState;
1093
+
1094
+ nsXPConnect* mXPC;
1095
+
1096
+ XPCPerThreadData* mThreadData;
1097
+ XPCContext* mXPCContext;
1098
+ JSContext* mJSContext;
1099
+ JSBool mContextPopRequired;
1100
+ JSBool mDestroyJSContextInDestructor;
1101
+
1102
+ XPCContext::LangType mCallerLanguage;
1103
+
1104
+ // ctor does not necessarily init the following. BEWARE!
1105
+
1106
+ XPCContext::LangType mPrevCallerLanguage;
1107
+
1108
+ XPCCallContext* mPrevCallContext;
1109
+
1110
+ JSObject* mOperandJSObject;
1111
+ JSObject* mCurrentJSObject;
1112
+ JSObject* mFlattenedJSObject;
1113
+ XPCWrappedNative* mWrapper;
1114
+ XPCWrappedNativeTearOff* mTearOff;
1115
+
1116
+ XPCNativeScriptableInfo* mScriptableInfo;
1117
+
1118
+ XPCNativeSet* mSet;
1119
+ XPCNativeInterface* mInterface;
1120
+ XPCNativeMember* mMember;
1121
+
1122
+ jsval mName;
1123
+ JSBool mStaticMemberIsLocal;
1124
+
1125
+ uintN mArgc;
1126
+ jsval* mArgv;
1127
+ jsval* mRetVal;
1128
+
1129
+ JSBool mReturnValueWasSet;
1130
+ #ifdef XPC_IDISPATCH_SUPPORT
1131
+ void* mIDispatchMember;
1132
+ #endif
1133
+ PRUint16 mMethodIndex;
1134
+
1135
+ // If not null, this is the function object of the function we're going to
1136
+ // call. This member only makes sense when CallerTypeIsNative() on our
1137
+ // XPCContext returns true. We're not responsible for rooting this object;
1138
+ // whoever sets it on us needs to deal with that.
1139
+ JSObject* mCallee;
1140
+
1141
+ #define XPCCCX_STRING_CACHE_SIZE 2
1142
+
1143
+ // String wrapper entry, holds a string, and a boolean that tells
1144
+ // whether the string is in use or not.
1145
+ struct StringWrapperEntry
1146
+ {
1147
+ StringWrapperEntry()
1148
+ : mInUse(PR_FALSE)
1149
+ {
1150
+ }
1151
+
1152
+ XPCReadableJSStringWrapper mString;
1153
+ PRBool mInUse;
1154
+ };
1155
+
1156
+ // Reserve space for XPCCCX_STRING_CACHE_SIZE string wrapper
1157
+ // entries for use on demand. It's important to not make this be
1158
+ // string class members since we don't want to pay the cost of
1159
+ // calling the constructors and destructors when the strings
1160
+ // aren't being used.
1161
+ char mStringWrapperData[sizeof(StringWrapperEntry) * XPCCCX_STRING_CACHE_SIZE];
1162
+ };
1163
+
1164
+ /***************************************************************************
1165
+ ****************************************************************************
1166
+ *
1167
+ * Core classes for wrapped native objects for use from JavaScript...
1168
+ *
1169
+ ****************************************************************************
1170
+ ***************************************************************************/
1171
+
1172
+ // These are the various JSClasses and callbacks whose use that required
1173
+ // visibility from more than one .cpp file.
1174
+
1175
+ extern JSExtendedClass XPC_WN_NoHelper_JSClass;
1176
+ extern JSClass XPC_WN_NoMods_WithCall_Proto_JSClass;
1177
+ extern JSClass XPC_WN_NoMods_NoCall_Proto_JSClass;
1178
+ extern JSClass XPC_WN_ModsAllowed_WithCall_Proto_JSClass;
1179
+ extern JSClass XPC_WN_ModsAllowed_NoCall_Proto_JSClass;
1180
+ extern JSClass XPC_WN_Tearoff_JSClass;
1181
+ extern JSClass XPC_WN_NoHelper_Proto_JSClass;
1182
+
1183
+ extern JSObjectOps *
1184
+ XPC_WN_GetObjectOpsNoCall(JSContext *cx, JSClass *clazz);
1185
+
1186
+ extern JSObjectOps *
1187
+ XPC_WN_GetObjectOpsWithCall(JSContext *cx, JSClass *clazz);
1188
+
1189
+ extern JSObjectOps *
1190
+ XPC_WN_Proto_GetObjectOps(JSContext *cx, JSClass *clazz);
1191
+
1192
+ extern JSBool
1193
+ XPC_WN_CallMethod(JSContext *cx, JSObject *obj,
1194
+ uintN argc, jsval *argv, jsval *vp);
1195
+
1196
+ extern JSBool
1197
+ XPC_WN_GetterSetter(JSContext *cx, JSObject *obj,
1198
+ uintN argc, jsval *argv, jsval *vp);
1199
+
1200
+ extern JSBool
1201
+ xpc_InitWrappedNativeJSOps();
1202
+
1203
+ // Maybe this macro should check for class->enumerate ==
1204
+ // XPC_WN_Shared_Proto_Enumerate or something rather than checking for
1205
+ // 4 classes?
1206
+ #define IS_PROTO_CLASS(clazz) \
1207
+ ((clazz) == &XPC_WN_NoMods_WithCall_Proto_JSClass || \
1208
+ (clazz) == &XPC_WN_NoMods_NoCall_Proto_JSClass || \
1209
+ (clazz) == &XPC_WN_ModsAllowed_WithCall_Proto_JSClass || \
1210
+ (clazz) == &XPC_WN_ModsAllowed_NoCall_Proto_JSClass)
1211
+
1212
+ // Comes from xpcwrappednativeops.cpp
1213
+ extern void
1214
+ xpc_TraceForValidWrapper(JSTracer *trc, XPCWrappedNative* wrapper);
1215
+
1216
+ /***************************************************************************/
1217
+
1218
+ /***************************************************************************/
1219
+ // XPCWrappedNativeScope is one-to-one with a JS global object.
1220
+
1221
+ class XPCWrappedNativeScope : public PRCList
1222
+ {
1223
+ public:
1224
+
1225
+ static XPCWrappedNativeScope*
1226
+ GetNewOrUsed(XPCCallContext& ccx, JSObject* aGlobal);
1227
+
1228
+ XPCJSRuntime*
1229
+ GetRuntime() const {return mRuntime;}
1230
+
1231
+ Native2WrappedNativeMap*
1232
+ GetWrappedNativeMap() const {return mWrappedNativeMap;}
1233
+
1234
+ WrappedNative2WrapperMap*
1235
+ GetWrapperMap() const {return mWrapperMap;}
1236
+
1237
+ ClassInfo2WrappedNativeProtoMap*
1238
+ GetWrappedNativeProtoMap() const {return mWrappedNativeProtoMap;}
1239
+
1240
+ nsXPCComponents*
1241
+ GetComponents() const {return mComponents;}
1242
+
1243
+ JSObject*
1244
+ GetGlobalJSObject() const {return mGlobalJSObject;}
1245
+
1246
+ JSObject*
1247
+ GetPrototypeJSObject() const {return mPrototypeJSObject;}
1248
+
1249
+ // Getter for the prototype that we use for wrappers that have no
1250
+ // helper.
1251
+ JSObject*
1252
+ GetPrototypeNoHelper(XPCCallContext& ccx);
1253
+
1254
+ #ifndef XPCONNECT_STANDALONE
1255
+ nsIPrincipal*
1256
+ GetPrincipal() const
1257
+ {return mScriptObjectPrincipal ?
1258
+ mScriptObjectPrincipal->GetPrincipal() : nsnull;}
1259
+ #endif
1260
+
1261
+ JSObject*
1262
+ GetPrototypeJSFunction() const {return mPrototypeJSFunction;}
1263
+
1264
+ void RemoveWrappedNativeProtos();
1265
+
1266
+ static XPCWrappedNativeScope*
1267
+ FindInJSObjectScope(JSContext* cx, JSObject* obj,
1268
+ JSBool OKIfNotInitialized = JS_FALSE,
1269
+ XPCJSRuntime* runtime = nsnull);
1270
+
1271
+ static XPCWrappedNativeScope*
1272
+ FindInJSObjectScope(XPCCallContext& ccx, JSObject* obj,
1273
+ JSBool OKIfNotInitialized = JS_FALSE)
1274
+ {
1275
+ return FindInJSObjectScope(ccx, obj, OKIfNotInitialized,
1276
+ ccx.GetRuntime());
1277
+ }
1278
+
1279
+ static void
1280
+ SystemIsBeingShutDown(JSContext* cx);
1281
+
1282
+ static void
1283
+ TraceJS(JSTracer* trc, XPCJSRuntime* rt);
1284
+
1285
+ static void
1286
+ SuspectAllWrappers(XPCJSRuntime* rt, JSContext* cx,
1287
+ nsCycleCollectionTraversalCallback &cb);
1288
+
1289
+ static void
1290
+ FinishedMarkPhaseOfGC(JSContext* cx, XPCJSRuntime* rt);
1291
+
1292
+ static void
1293
+ FinishedFinalizationPhaseOfGC(JSContext* cx);
1294
+
1295
+ static void
1296
+ MarkAllWrappedNativesAndProtos();
1297
+
1298
+ static nsresult
1299
+ ClearAllWrappedNativeSecurityPolicies(XPCCallContext& ccx);
1300
+
1301
+ #ifdef DEBUG
1302
+ static void
1303
+ ASSERT_NoInterfaceSetsAreMarked();
1304
+ #endif
1305
+
1306
+ static void
1307
+ SweepAllWrappedNativeTearOffs();
1308
+
1309
+ static void
1310
+ DebugDumpAllScopes(PRInt16 depth);
1311
+
1312
+ void
1313
+ DebugDump(PRInt16 depth);
1314
+
1315
+ JSBool
1316
+ IsValid() const {return mRuntime != nsnull;}
1317
+
1318
+ static JSBool
1319
+ IsDyingScope(XPCWrappedNativeScope *scope);
1320
+
1321
+ void SetComponents(nsXPCComponents* aComponents);
1322
+ void SetGlobal(XPCCallContext& ccx, JSObject* aGlobal);
1323
+
1324
+ static void InitStatics() { gScopes = nsnull; gDyingScopes = nsnull; }
1325
+
1326
+ XPCContext *GetContext() { return mContext; }
1327
+ void SetContext(XPCContext *xpcc) { mContext = nsnull; }
1328
+
1329
+ #ifndef XPCONNECT_STANDALONE
1330
+ /**
1331
+ * Fills the hash mapping global object to principal.
1332
+ */
1333
+ static void TraverseScopes(XPCCallContext& ccx);
1334
+ #endif
1335
+
1336
+ protected:
1337
+ XPCWrappedNativeScope(XPCCallContext& ccx, JSObject* aGlobal);
1338
+ virtual ~XPCWrappedNativeScope();
1339
+
1340
+ static void KillDyingScopes();
1341
+
1342
+ XPCWrappedNativeScope(); // not implemented
1343
+
1344
+ private:
1345
+ static XPCWrappedNativeScope* gScopes;
1346
+ static XPCWrappedNativeScope* gDyingScopes;
1347
+
1348
+ XPCJSRuntime* mRuntime;
1349
+ Native2WrappedNativeMap* mWrappedNativeMap;
1350
+ ClassInfo2WrappedNativeProtoMap* mWrappedNativeProtoMap;
1351
+ WrappedNative2WrapperMap* mWrapperMap;
1352
+ nsXPCComponents* mComponents;
1353
+ XPCWrappedNativeScope* mNext;
1354
+ // The JS global object for this scope. If non-null, this will be the
1355
+ // default parent for the XPCWrappedNatives that have us as the scope,
1356
+ // unless a PreCreate hook overrides it. Note that this _may_ be null (see
1357
+ // constructor).
1358
+ JSObject* mGlobalJSObject;
1359
+
1360
+ // Cached value of Object.prototype
1361
+ JSObject* mPrototypeJSObject;
1362
+ // Cached value of Function.prototype
1363
+ JSObject* mPrototypeJSFunction;
1364
+ // Prototype to use for wrappers with no helper.
1365
+ JSObject* mPrototypeNoHelper;
1366
+
1367
+ XPCContext* mContext;
1368
+
1369
+ #ifndef XPCONNECT_STANDALONE
1370
+ // The script object principal instance corresponding to our current global
1371
+ // JS object.
1372
+ // XXXbz what happens if someone calls JS_SetPrivate on mGlobalJSObject.
1373
+ // How do we deal? Do we need to? I suspect this isn't worth worrying
1374
+ // about, since all of our scope objects are verified as not doing that.
1375
+ nsCOMPtr<nsIScriptObjectPrincipal> mScriptObjectPrincipal;
1376
+ #endif
1377
+ };
1378
+
1379
+ JSObject* xpc_CloneJSFunction(XPCCallContext &ccx, JSObject *funobj,
1380
+ JSObject *parent);
1381
+
1382
+ /***************************************************************************/
1383
+ // XPCNativeMember represents a single idl declared method, attribute or
1384
+ // constant.
1385
+
1386
+ // Tight. No virtual methods. Can be bitwise copied (until any resolution done).
1387
+
1388
+ class XPCNativeMember
1389
+ {
1390
+ public:
1391
+ static JSBool GetCallInfo(XPCCallContext& ccx,
1392
+ JSObject* funobj,
1393
+ XPCNativeInterface** pInterface,
1394
+ XPCNativeMember** pMember);
1395
+
1396
+ jsval GetName() const {return mName;}
1397
+
1398
+ PRUint16 GetIndex() const {return mIndex;}
1399
+
1400
+ JSBool GetConstantValue(XPCCallContext& ccx, XPCNativeInterface* iface,
1401
+ jsval* pval)
1402
+ {NS_ASSERTION(IsConstant(),
1403
+ "Only call this if you're sure this is a constant!");
1404
+ if(!IsResolved() && !Resolve(ccx, iface)) return JS_FALSE;
1405
+ *pval = mVal; return JS_TRUE;}
1406
+
1407
+ JSBool NewFunctionObject(XPCCallContext& ccx, XPCNativeInterface* iface,
1408
+ JSObject *parent, jsval* pval);
1409
+
1410
+ JSBool IsMethod() const
1411
+ {return 0 != (mFlags & METHOD);}
1412
+
1413
+ JSBool IsConstant() const
1414
+ {return 0 != (mFlags & CONSTANT);}
1415
+
1416
+ JSBool IsAttribute() const
1417
+ {return 0 != (mFlags & GETTER);}
1418
+
1419
+ JSBool IsWritableAttribute() const
1420
+ {return 0 != (mFlags & SETTER_TOO);}
1421
+
1422
+ JSBool IsReadOnlyAttribute() const
1423
+ {return IsAttribute() && !IsWritableAttribute();}
1424
+
1425
+
1426
+ void SetName(jsval a) {mName = a;}
1427
+
1428
+ void SetMethod(PRUint16 index)
1429
+ {mVal = JSVAL_NULL; mFlags = METHOD; mIndex = index;}
1430
+
1431
+ void SetConstant(PRUint16 index)
1432
+ {mVal = JSVAL_NULL; mFlags = CONSTANT; mIndex = index;}
1433
+
1434
+ void SetReadOnlyAttribute(PRUint16 index)
1435
+ {mVal = JSVAL_NULL; mFlags = GETTER; mIndex = index;}
1436
+
1437
+ void SetWritableAttribute()
1438
+ {NS_ASSERTION(mFlags == GETTER,"bad"); mFlags = GETTER | SETTER_TOO;}
1439
+
1440
+ /* default ctor - leave random contents */
1441
+ XPCNativeMember() {MOZ_COUNT_CTOR(XPCNativeMember);}
1442
+ ~XPCNativeMember() {MOZ_COUNT_DTOR(XPCNativeMember);}
1443
+
1444
+ void DealWithDyingGCThings(JSContext* cx, XPCJSRuntime* rt)
1445
+ {if(IsResolved() && JSVAL_IS_GCTHING(mVal) &&
1446
+ JS_IsAboutToBeFinalized(cx, JSVAL_TO_GCTHING(mVal)))
1447
+ {mVal = JSVAL_NULL; mFlags &= ~RESOLVED;}}
1448
+
1449
+ private:
1450
+ JSBool IsResolved() const {return mFlags & RESOLVED;}
1451
+ JSBool Resolve(XPCCallContext& ccx, XPCNativeInterface* iface);
1452
+
1453
+ enum {
1454
+ RESOLVED = 0x01,
1455
+ METHOD = 0x02,
1456
+ CONSTANT = 0x04,
1457
+ GETTER = 0x08,
1458
+ SETTER_TOO = 0x10
1459
+ };
1460
+
1461
+ private:
1462
+ // our only data...
1463
+ jsval mName;
1464
+ jsval mVal;
1465
+ PRUint16 mIndex;
1466
+ PRUint16 mFlags;
1467
+ };
1468
+
1469
+ /***************************************************************************/
1470
+ // XPCNativeInterface represents a single idl declared interface. This is
1471
+ // primarily the set of XPCNativeMembers.
1472
+
1473
+ // Tight. No virtual methods.
1474
+
1475
+ class XPCNativeInterface
1476
+ {
1477
+ public:
1478
+ static XPCNativeInterface* GetNewOrUsed(XPCCallContext& ccx,
1479
+ const nsIID* iid);
1480
+ static XPCNativeInterface* GetNewOrUsed(XPCCallContext& ccx,
1481
+ nsIInterfaceInfo* info);
1482
+ static XPCNativeInterface* GetNewOrUsed(XPCCallContext& ccx,
1483
+ const char* name);
1484
+ static XPCNativeInterface* GetISupports(XPCCallContext& ccx);
1485
+
1486
+ inline nsIInterfaceInfo* GetInterfaceInfo() const {return mInfo.get();}
1487
+ inline jsval GetName() const {return mName;}
1488
+
1489
+ inline const nsIID* GetIID() const;
1490
+ inline const char* GetNameString() const;
1491
+ inline XPCNativeMember* FindMember(jsval name) const;
1492
+
1493
+ inline JSBool HasAncestor(const nsIID* iid) const;
1494
+
1495
+ const char* GetMemberName(XPCCallContext& ccx,
1496
+ const XPCNativeMember* member) const;
1497
+
1498
+ PRUint16 GetMemberCount() const
1499
+ {NS_ASSERTION(!IsMarked(), "bad"); return mMemberCount;}
1500
+ XPCNativeMember* GetMemberAt(PRUint16 i)
1501
+ {NS_ASSERTION(i < mMemberCount, "bad index"); return &mMembers[i];}
1502
+
1503
+ inline void DealWithDyingGCThings(JSContext* cx, XPCJSRuntime* rt);
1504
+
1505
+ void DebugDump(PRInt16 depth);
1506
+
1507
+ #define XPC_NATIVE_IFACE_MARK_FLAG ((PRUint16)JS_BIT(15)) // only high bit of 16 is set
1508
+
1509
+ void Mark() {mMemberCount |= XPC_NATIVE_IFACE_MARK_FLAG;}
1510
+ void Unmark() {mMemberCount &= ~XPC_NATIVE_IFACE_MARK_FLAG;}
1511
+ JSBool IsMarked() const
1512
+ {return 0 != (mMemberCount & XPC_NATIVE_IFACE_MARK_FLAG);}
1513
+
1514
+ // NOP. This is just here to make the AutoMarkingPtr code compile.
1515
+ inline void TraceJS(JSTracer* trc) {}
1516
+ inline void AutoTrace(JSTracer* trc) {}
1517
+
1518
+ static void DestroyInstance(JSContext* cx, XPCJSRuntime* rt,
1519
+ XPCNativeInterface* inst);
1520
+
1521
+ protected:
1522
+ static XPCNativeInterface* NewInstance(XPCCallContext& ccx,
1523
+ nsIInterfaceInfo* aInfo);
1524
+
1525
+ XPCNativeInterface(); // not implemented
1526
+ XPCNativeInterface(nsIInterfaceInfo* aInfo, jsval aName)
1527
+ : mInfo(aInfo), mName(aName), mMemberCount(0)
1528
+ {MOZ_COUNT_CTOR(XPCNativeInterface);}
1529
+ ~XPCNativeInterface() {MOZ_COUNT_DTOR(XPCNativeInterface);}
1530
+
1531
+ void* operator new(size_t, void* p) CPP_THROW_NEW {return p;}
1532
+
1533
+ XPCNativeInterface(const XPCNativeInterface& r); // not implemented
1534
+ XPCNativeInterface& operator= (const XPCNativeInterface& r); // not implemented
1535
+
1536
+ private:
1537
+ nsCOMPtr<nsIInterfaceInfo> mInfo;
1538
+ jsval mName;
1539
+ PRUint16 mMemberCount;
1540
+ XPCNativeMember mMembers[1]; // always last - object sized for array
1541
+ };
1542
+
1543
+ /***************************************************************************/
1544
+ // XPCNativeSetKey is used to key a XPCNativeSet in a NativeSetMap.
1545
+
1546
+ class XPCNativeSetKey
1547
+ {
1548
+ public:
1549
+ XPCNativeSetKey(XPCNativeSet* BaseSet = nsnull,
1550
+ XPCNativeInterface* Addition = nsnull,
1551
+ PRUint16 Position = 0)
1552
+ : mIsAKey(IS_A_KEY), mPosition(Position), mBaseSet(BaseSet),
1553
+ mAddition(Addition) {}
1554
+ ~XPCNativeSetKey() {}
1555
+
1556
+ XPCNativeSet* GetBaseSet() const {return mBaseSet;}
1557
+ XPCNativeInterface* GetAddition() const {return mAddition;}
1558
+ PRUint16 GetPosition() const {return mPosition;}
1559
+
1560
+ // This is a fun little hack...
1561
+ // We build these keys only on the stack. We use them for lookup in
1562
+ // NativeSetMap. Becasue we don't want to pay the cost of cloning a key and
1563
+ // sticking it into the hashtable, when the XPCNativeSet actually
1564
+ // gets added to the table the 'key' in the table is a pointer to the
1565
+ // set itself and not this key. Our key compare function expects to get
1566
+ // a key and a set. When we do external lookups in the map we pass in one
1567
+ // of these keys and our compare function gets passed a key and a set.
1568
+ // (see compare_NativeKeyToSet in xpcmaps.cpp). This is all well and good.
1569
+ // Except, when the table decides to resize itself. Then it tries to use
1570
+ // our compare function with the 'keys' that are in the hashtable (which are
1571
+ // really XPCNativeSet objects and not XPCNativeSetKey objects!
1572
+ //
1573
+ // So, the hack is to have the compare function assume it is getting a
1574
+ // XPCNativeSetKey pointer and call this IsAKey method. If that fails then
1575
+ // it realises that it really has a XPCNativeSet pointer and deals with that
1576
+ // fact. This is safe because we know that both of these classes have no
1577
+ // virtual methods and their first data member is a PRUint16. We are
1578
+ // confident that XPCNativeSet->mMemberCount will never be 0xffff.
1579
+
1580
+ JSBool IsAKey() const {return mIsAKey == IS_A_KEY;}
1581
+
1582
+ enum {IS_A_KEY = 0xffff};
1583
+
1584
+ // Allow shallow copy
1585
+
1586
+ private:
1587
+ PRUint16 mIsAKey; // must be first data member
1588
+ PRUint16 mPosition;
1589
+ XPCNativeSet* mBaseSet;
1590
+ XPCNativeInterface* mAddition;
1591
+ };
1592
+
1593
+ /***************************************************************************/
1594
+ // XPCNativeSet represents an ordered collection of XPCNativeInterface pointers.
1595
+
1596
+ class XPCNativeSet
1597
+ {
1598
+ public:
1599
+ static XPCNativeSet* GetNewOrUsed(XPCCallContext& ccx, const nsIID* iid);
1600
+ static XPCNativeSet* GetNewOrUsed(XPCCallContext& ccx,
1601
+ nsIClassInfo* classInfo);
1602
+ static XPCNativeSet* GetNewOrUsed(XPCCallContext& ccx,
1603
+ XPCNativeSet* otherSet,
1604
+ XPCNativeInterface* newInterface,
1605
+ PRUint16 position);
1606
+
1607
+ static void ClearCacheEntryForClassInfo(nsIClassInfo* classInfo);
1608
+
1609
+ inline JSBool FindMember(jsval name, XPCNativeMember** pMember,
1610
+ PRUint16* pInterfaceIndex) const;
1611
+
1612
+ inline JSBool FindMember(jsval name, XPCNativeMember** pMember,
1613
+ XPCNativeInterface** pInterface) const;
1614
+
1615
+ inline JSBool FindMember(jsval name,
1616
+ XPCNativeMember** pMember,
1617
+ XPCNativeInterface** pInterface,
1618
+ XPCNativeSet* protoSet,
1619
+ JSBool* pIsLocal) const;
1620
+
1621
+ inline JSBool HasInterface(XPCNativeInterface* aInterface) const;
1622
+ inline JSBool HasInterfaceWithAncestor(XPCNativeInterface* aInterface) const;
1623
+
1624
+ inline XPCNativeInterface* FindInterfaceWithIID(const nsIID& iid) const;
1625
+
1626
+ inline XPCNativeInterface* FindNamedInterface(jsval name) const;
1627
+
1628
+ PRUint16 GetMemberCount() const {return mMemberCount;}
1629
+ PRUint16 GetInterfaceCount() const
1630
+ {NS_ASSERTION(!IsMarked(), "bad"); return mInterfaceCount;}
1631
+ XPCNativeInterface** GetInterfaceArray() {return mInterfaces;}
1632
+
1633
+ XPCNativeInterface* GetInterfaceAt(PRUint16 i)
1634
+ {NS_ASSERTION(i < mInterfaceCount, "bad index"); return mInterfaces[i];}
1635
+
1636
+ inline JSBool MatchesSetUpToInterface(const XPCNativeSet* other,
1637
+ XPCNativeInterface* iface) const;
1638
+
1639
+ #define XPC_NATIVE_SET_MARK_FLAG ((PRUint16)JS_BIT(15)) // only high bit of 16 is set
1640
+
1641
+ inline void Mark();
1642
+
1643
+ // NOP. This is just here to make the AutoMarkingPtr code compile.
1644
+ inline void TraceJS(JSTracer* trc) {}
1645
+ inline void AutoTrace(JSTracer* trc) {}
1646
+
1647
+ private:
1648
+ void MarkSelfOnly() {mInterfaceCount |= XPC_NATIVE_SET_MARK_FLAG;}
1649
+ public:
1650
+ void Unmark() {mInterfaceCount &= ~XPC_NATIVE_SET_MARK_FLAG;}
1651
+ JSBool IsMarked() const
1652
+ {return 0 != (mInterfaceCount & XPC_NATIVE_SET_MARK_FLAG);}
1653
+
1654
+ #ifdef DEBUG
1655
+ inline void ASSERT_NotMarked();
1656
+ #endif
1657
+
1658
+ void DebugDump(PRInt16 depth);
1659
+
1660
+ static void DestroyInstance(XPCNativeSet* inst);
1661
+
1662
+ protected:
1663
+ static XPCNativeSet* NewInstance(XPCCallContext& ccx,
1664
+ XPCNativeInterface** array,
1665
+ PRUint16 count);
1666
+ static XPCNativeSet* NewInstanceMutate(XPCNativeSet* otherSet,
1667
+ XPCNativeInterface* newInterface,
1668
+ PRUint16 position);
1669
+ XPCNativeSet() {MOZ_COUNT_CTOR(XPCNativeSet);}
1670
+ ~XPCNativeSet() {MOZ_COUNT_DTOR(XPCNativeSet);}
1671
+ void* operator new(size_t, void* p) CPP_THROW_NEW {return p;}
1672
+
1673
+ private:
1674
+ PRUint16 mMemberCount;
1675
+ PRUint16 mInterfaceCount;
1676
+ XPCNativeInterface* mInterfaces[1]; // always last - object sized for array
1677
+ };
1678
+
1679
+ /***************************************************************************/
1680
+ // XPCNativeScriptableFlags is a wrapper class that holds the flags returned
1681
+ // from calls to nsIXPCScriptable::GetScriptableFlags(). It has convenience
1682
+ // methods to check for particular bitflags. Since we also use this class as
1683
+ // a member of the gc'd class XPCNativeScriptableShared, this class holds the
1684
+ // bit and exposes the inlined methods to support marking.
1685
+
1686
+ #define XPC_WN_SJSFLAGS_MARK_FLAG JS_BIT(31) // only high bit of 32 is set
1687
+
1688
+ class XPCNativeScriptableFlags
1689
+ {
1690
+ private:
1691
+ JSUint32 mFlags;
1692
+
1693
+ public:
1694
+
1695
+ XPCNativeScriptableFlags(JSUint32 flags = 0) : mFlags(flags) {}
1696
+
1697
+ JSUint32 GetFlags() const {return mFlags & ~XPC_WN_SJSFLAGS_MARK_FLAG;}
1698
+ void SetFlags(JSUint32 flags) {mFlags = flags;}
1699
+
1700
+ operator JSUint32() const {return GetFlags();}
1701
+
1702
+ XPCNativeScriptableFlags(const XPCNativeScriptableFlags& r)
1703
+ {mFlags = r.GetFlags();}
1704
+
1705
+ XPCNativeScriptableFlags& operator= (const XPCNativeScriptableFlags& r)
1706
+ {mFlags = r.GetFlags(); return *this;}
1707
+
1708
+ void Mark() {mFlags |= XPC_WN_SJSFLAGS_MARK_FLAG;}
1709
+ void Unmark() {mFlags &= ~XPC_WN_SJSFLAGS_MARK_FLAG;}
1710
+ JSBool IsMarked() const {return 0 != (mFlags & XPC_WN_SJSFLAGS_MARK_FLAG);}
1711
+
1712
+ #ifdef GET_IT
1713
+ #undef GET_IT
1714
+ #endif
1715
+ #define GET_IT(f_) const {return 0 != (mFlags & nsIXPCScriptable:: f_ );}
1716
+
1717
+ JSBool WantPreCreate() GET_IT(WANT_PRECREATE)
1718
+ JSBool WantCreate() GET_IT(WANT_CREATE)
1719
+ JSBool WantPostCreate() GET_IT(WANT_POSTCREATE)
1720
+ JSBool WantAddProperty() GET_IT(WANT_ADDPROPERTY)
1721
+ JSBool WantDelProperty() GET_IT(WANT_DELPROPERTY)
1722
+ JSBool WantGetProperty() GET_IT(WANT_GETPROPERTY)
1723
+ JSBool WantSetProperty() GET_IT(WANT_SETPROPERTY)
1724
+ JSBool WantEnumerate() GET_IT(WANT_ENUMERATE)
1725
+ JSBool WantNewEnumerate() GET_IT(WANT_NEWENUMERATE)
1726
+ JSBool WantNewResolve() GET_IT(WANT_NEWRESOLVE)
1727
+ JSBool WantConvert() GET_IT(WANT_CONVERT)
1728
+ JSBool WantFinalize() GET_IT(WANT_FINALIZE)
1729
+ JSBool WantCheckAccess() GET_IT(WANT_CHECKACCESS)
1730
+ JSBool WantCall() GET_IT(WANT_CALL)
1731
+ JSBool WantConstruct() GET_IT(WANT_CONSTRUCT)
1732
+ JSBool WantHasInstance() GET_IT(WANT_HASINSTANCE)
1733
+ JSBool WantTrace() GET_IT(WANT_TRACE)
1734
+ JSBool WantEquality() GET_IT(WANT_EQUALITY)
1735
+ JSBool WantOuterObject() GET_IT(WANT_OUTER_OBJECT)
1736
+ JSBool WantInnerObject() GET_IT(WANT_INNER_OBJECT)
1737
+ JSBool UseJSStubForAddProperty() GET_IT(USE_JSSTUB_FOR_ADDPROPERTY)
1738
+ JSBool UseJSStubForDelProperty() GET_IT(USE_JSSTUB_FOR_DELPROPERTY)
1739
+ JSBool UseJSStubForSetProperty() GET_IT(USE_JSSTUB_FOR_SETPROPERTY)
1740
+ JSBool DontEnumStaticProps() GET_IT(DONT_ENUM_STATIC_PROPS)
1741
+ JSBool DontEnumQueryInterface() GET_IT(DONT_ENUM_QUERY_INTERFACE)
1742
+ JSBool DontAskInstanceForScriptable() GET_IT(DONT_ASK_INSTANCE_FOR_SCRIPTABLE)
1743
+ JSBool ClassInfoInterfacesOnly() GET_IT(CLASSINFO_INTERFACES_ONLY)
1744
+ JSBool AllowPropModsDuringResolve() GET_IT(ALLOW_PROP_MODS_DURING_RESOLVE)
1745
+ JSBool AllowPropModsToPrototype() GET_IT(ALLOW_PROP_MODS_TO_PROTOTYPE)
1746
+ JSBool DontSharePrototype() GET_IT(DONT_SHARE_PROTOTYPE)
1747
+ JSBool DontReflectInterfaceNames() GET_IT(DONT_REFLECT_INTERFACE_NAMES)
1748
+
1749
+ #undef GET_IT
1750
+ };
1751
+
1752
+ /***************************************************************************/
1753
+
1754
+ // XPCNativeScriptableShared is used to hold the JSClass and the
1755
+ // associated scriptable flags for XPCWrappedNatives. These are shared across
1756
+ // the runtime and are garbage collected by xpconnect. We *used* to just store
1757
+ // this inside the XPCNativeScriptableInfo (usually owned by instances of
1758
+ // XPCWrappedNativeProto. This had two problems... It was wasteful, and it
1759
+ // was a big problem when wrappers are reparented to different scopes (and
1760
+ // thus different protos (the DOM does this).
1761
+
1762
+ class XPCNativeScriptableShared
1763
+ {
1764
+ public:
1765
+ const XPCNativeScriptableFlags& GetFlags() const {return mFlags;}
1766
+ JSClass* GetJSClass() {return &mJSClass.base;}
1767
+
1768
+ XPCNativeScriptableShared(JSUint32 aFlags = 0, char* aName = nsnull)
1769
+ : mFlags(aFlags)
1770
+ {memset(&mJSClass, 0, sizeof(mJSClass));
1771
+ mJSClass.base.name = aName; // take ownership
1772
+ MOZ_COUNT_CTOR(XPCNativeScriptableShared);}
1773
+
1774
+ ~XPCNativeScriptableShared()
1775
+ {if(mJSClass.base.name)nsMemory::Free((void*)mJSClass.base.name);
1776
+ MOZ_COUNT_DTOR(XPCNativeScriptableShared);}
1777
+
1778
+ char* TransferNameOwnership()
1779
+ {char* name=(char*)mJSClass.base.name; mJSClass.base.name = nsnull;
1780
+ return name;}
1781
+
1782
+ void PopulateJSClass(JSBool isGlobal);
1783
+
1784
+ void Mark() {mFlags.Mark();}
1785
+ void Unmark() {mFlags.Unmark();}
1786
+ JSBool IsMarked() const {return mFlags.IsMarked();}
1787
+
1788
+ private:
1789
+ XPCNativeScriptableFlags mFlags;
1790
+ JSExtendedClass mJSClass;
1791
+ };
1792
+
1793
+ /***************************************************************************/
1794
+ // XPCNativeScriptableInfo is used to hold the nsIXPCScriptable state for a
1795
+ // given class or instance.
1796
+
1797
+ class XPCNativeScriptableInfo
1798
+ {
1799
+ public:
1800
+ static XPCNativeScriptableInfo*
1801
+ Construct(XPCCallContext& ccx, JSBool isGlobal,
1802
+ const XPCNativeScriptableCreateInfo* sci);
1803
+
1804
+ nsIXPCScriptable*
1805
+ GetCallback() const {return mCallback;}
1806
+
1807
+ const XPCNativeScriptableFlags&
1808
+ GetFlags() const {return mShared->GetFlags();}
1809
+
1810
+ JSClass*
1811
+ GetJSClass() {return mShared->GetJSClass();}
1812
+
1813
+ XPCNativeScriptableShared*
1814
+ GetScriptableShared() {return mShared;}
1815
+
1816
+ void
1817
+ SetCallback(nsIXPCScriptable* s) {mCallback = s;}
1818
+
1819
+ void
1820
+ SetScriptableShared(XPCNativeScriptableShared* shared) {mShared = shared;}
1821
+
1822
+ void Mark() {if(mShared) mShared->Mark();}
1823
+
1824
+ protected:
1825
+ XPCNativeScriptableInfo(nsIXPCScriptable* scriptable = nsnull,
1826
+ XPCNativeScriptableShared* shared = nsnull)
1827
+ : mCallback(scriptable), mShared(shared)
1828
+ {MOZ_COUNT_CTOR(XPCNativeScriptableInfo);}
1829
+ public:
1830
+ ~XPCNativeScriptableInfo() {MOZ_COUNT_DTOR(XPCNativeScriptableInfo);}
1831
+ private:
1832
+
1833
+ // disable copy ctor and assignment
1834
+ XPCNativeScriptableInfo(const XPCNativeScriptableInfo& r); // not implemented
1835
+ XPCNativeScriptableInfo& operator= (const XPCNativeScriptableInfo& r); // not implemented
1836
+
1837
+ private:
1838
+ nsCOMPtr<nsIXPCScriptable> mCallback;
1839
+ XPCNativeScriptableShared* mShared;
1840
+ };
1841
+
1842
+ /***************************************************************************/
1843
+ // XPCNativeScriptableCreateInfo is used in creating new wrapper and protos.
1844
+ // it abstracts out the scriptable interface pointer and the flags. After
1845
+ // creation these are factored differently using XPCNativeScriptableInfo.
1846
+
1847
+ class XPCNativeScriptableCreateInfo
1848
+ {
1849
+ public:
1850
+
1851
+ XPCNativeScriptableCreateInfo(const XPCNativeScriptableInfo& si)
1852
+ : mCallback(si.GetCallback()), mFlags(si.GetFlags()) {}
1853
+
1854
+ XPCNativeScriptableCreateInfo(nsIXPCScriptable* callback = nsnull,
1855
+ XPCNativeScriptableFlags flags = 0)
1856
+ : mCallback(callback), mFlags(flags) {}
1857
+
1858
+ nsIXPCScriptable*
1859
+ GetCallback() const {return mCallback;}
1860
+
1861
+ const XPCNativeScriptableFlags&
1862
+ GetFlags() const {return mFlags;}
1863
+
1864
+ void
1865
+ SetCallback(nsIXPCScriptable* callback) {mCallback = callback;}
1866
+
1867
+ void
1868
+ SetFlags(const XPCNativeScriptableFlags& flags) {mFlags = flags;}
1869
+
1870
+ private:
1871
+ nsCOMPtr<nsIXPCScriptable> mCallback;
1872
+ XPCNativeScriptableFlags mFlags;
1873
+ };
1874
+
1875
+ /***********************************************/
1876
+ // XPCWrappedNativeProto hold the additional (potentially shared) wrapper data
1877
+ // for XPCWrappedNative whose native objects expose nsIClassInfo.
1878
+
1879
+ #define UNKNOWN_OFFSETS ((QITableEntry*)1)
1880
+
1881
+ class XPCWrappedNativeProto
1882
+ {
1883
+ public:
1884
+ static XPCWrappedNativeProto*
1885
+ GetNewOrUsed(XPCCallContext& ccx,
1886
+ XPCWrappedNativeScope* Scope,
1887
+ nsIClassInfo* ClassInfo,
1888
+ const XPCNativeScriptableCreateInfo* ScriptableCreateInfo,
1889
+ JSBool ForceNoSharing,
1890
+ JSBool isGlobal,
1891
+ QITableEntry* offsets = UNKNOWN_OFFSETS);
1892
+
1893
+ XPCWrappedNativeScope*
1894
+ GetScope() const {return mScope;}
1895
+
1896
+ XPCJSRuntime*
1897
+ GetRuntime() const {return mScope->GetRuntime();}
1898
+
1899
+ JSObject*
1900
+ GetJSProtoObject() const {return mJSProtoObject;}
1901
+
1902
+ nsIClassInfo*
1903
+ GetClassInfo() const {return mClassInfo;}
1904
+
1905
+ XPCNativeSet*
1906
+ GetSet() const {return mSet;}
1907
+
1908
+ XPCNativeScriptableInfo*
1909
+ GetScriptableInfo() {return mScriptableInfo;}
1910
+
1911
+ void**
1912
+ GetSecurityInfoAddr() {return &mSecurityInfo;}
1913
+
1914
+ JSUint32
1915
+ GetClassInfoFlags() const {return mClassInfoFlags;}
1916
+
1917
+ QITableEntry*
1918
+ GetOffsets()
1919
+ {
1920
+ return InitedOffsets() ? mOffsets : nsnull;
1921
+ }
1922
+ QITableEntry*
1923
+ GetOffsetsMasked()
1924
+ {
1925
+ return mOffsets;
1926
+ }
1927
+ void
1928
+ CacheOffsets(nsISupports* identity)
1929
+ {
1930
+ static NS_DEFINE_IID(kThisPtrOffsetsSID, NS_THISPTROFFSETS_SID);
1931
+
1932
+ #ifdef DEBUG
1933
+ if(InitedOffsets() && mOffsets)
1934
+ {
1935
+ QITableEntry* offsets;
1936
+ identity->QueryInterface(kThisPtrOffsetsSID, (void**)&offsets);
1937
+ NS_ASSERTION(offsets == mOffsets,
1938
+ "We can't deal with objects that have the same "
1939
+ "classinfo but different offset tables.");
1940
+ }
1941
+ #endif
1942
+
1943
+ if(!InitedOffsets())
1944
+ {
1945
+ if(mClassInfoFlags & nsIClassInfo::CONTENT_NODE)
1946
+ {
1947
+ identity->QueryInterface(kThisPtrOffsetsSID, (void**)&mOffsets);
1948
+ }
1949
+ else
1950
+ {
1951
+ mOffsets = nsnull;
1952
+ }
1953
+ }
1954
+ }
1955
+
1956
+ #ifdef GET_IT
1957
+ #undef GET_IT
1958
+ #endif
1959
+ #define GET_IT(f_) const {return !!(mClassInfoFlags & nsIClassInfo:: f_ );}
1960
+
1961
+ JSBool ClassIsSingleton() GET_IT(SINGLETON)
1962
+ JSBool ClassIsThreadSafe() GET_IT(THREADSAFE)
1963
+ JSBool ClassIsMainThreadOnly() GET_IT(MAIN_THREAD_ONLY)
1964
+ JSBool ClassIsDOMObject() GET_IT(DOM_OBJECT)
1965
+ JSBool ClassIsPluginObject() GET_IT(PLUGIN_OBJECT)
1966
+
1967
+ #undef GET_IT
1968
+
1969
+ #define XPC_PROTO_DONT_SHARE JS_BIT(31) // only high bit of 32 is set
1970
+
1971
+ JSBool
1972
+ IsShared() const {return !(mClassInfoFlags & XPC_PROTO_DONT_SHARE);}
1973
+
1974
+ XPCLock* GetLock() const
1975
+ {return ClassIsThreadSafe() ? GetRuntime()->GetMapLock() : nsnull;}
1976
+
1977
+ void SetScriptableInfo(XPCNativeScriptableInfo* si)
1978
+ {NS_ASSERTION(!mScriptableInfo, "leak here!"); mScriptableInfo = si;}
1979
+
1980
+ void JSProtoObjectFinalized(JSContext *cx, JSObject *obj);
1981
+
1982
+ void SystemIsBeingShutDown(JSContext* cx);
1983
+
1984
+ void DebugDump(PRInt16 depth);
1985
+
1986
+ void TraceJS(JSTracer* trc)
1987
+ {
1988
+ if(mJSProtoObject)
1989
+ {
1990
+ JS_CALL_OBJECT_TRACER(trc, mJSProtoObject,
1991
+ "XPCWrappedNativeProto::mJSProtoObject");
1992
+ }
1993
+ if(mScriptableInfo && JS_IsGCMarkingTracer(trc))
1994
+ mScriptableInfo->Mark();
1995
+ }
1996
+
1997
+ // NOP. This is just here to make the AutoMarkingPtr code compile.
1998
+ inline void AutoTrace(JSTracer* trc) {}
1999
+
2000
+ // Yes, we *do* need to mark the mScriptableInfo in both cases.
2001
+ void Mark() const
2002
+ {mSet->Mark();
2003
+ if(mScriptableInfo) mScriptableInfo->Mark();}
2004
+
2005
+ #ifdef DEBUG
2006
+ void ASSERT_SetNotMarked() const {mSet->ASSERT_NotMarked();}
2007
+ #endif
2008
+
2009
+ ~XPCWrappedNativeProto();
2010
+
2011
+ protected:
2012
+ // disable copy ctor and assignment
2013
+ XPCWrappedNativeProto(const XPCWrappedNativeProto& r); // not implemented
2014
+ XPCWrappedNativeProto& operator= (const XPCWrappedNativeProto& r); // not implemented
2015
+
2016
+ // hide ctor
2017
+ XPCWrappedNativeProto(XPCWrappedNativeScope* Scope,
2018
+ nsIClassInfo* ClassInfo,
2019
+ PRUint32 ClassInfoFlags,
2020
+ XPCNativeSet* Set,
2021
+ QITableEntry* offsets);
2022
+
2023
+ JSBool Init(XPCCallContext& ccx, JSBool isGlobal,
2024
+ const XPCNativeScriptableCreateInfo* scriptableCreateInfo);
2025
+
2026
+ private:
2027
+ #if defined(DEBUG_xpc_hacker) || defined(DEBUG)
2028
+ static PRInt32 gDEBUG_LiveProtoCount;
2029
+ #endif
2030
+
2031
+ private:
2032
+ PRBool
2033
+ InitedOffsets()
2034
+ {
2035
+ return mOffsets != UNKNOWN_OFFSETS;
2036
+ }
2037
+
2038
+ XPCWrappedNativeScope* mScope;
2039
+ JSObject* mJSProtoObject;
2040
+ nsCOMPtr<nsIClassInfo> mClassInfo;
2041
+ PRUint32 mClassInfoFlags;
2042
+ XPCNativeSet* mSet;
2043
+ void* mSecurityInfo;
2044
+ XPCNativeScriptableInfo* mScriptableInfo;
2045
+ QITableEntry* mOffsets;
2046
+ };
2047
+
2048
+
2049
+ /***********************************************/
2050
+ // XPCWrappedNativeTearOff represents the info needed to make calls to one
2051
+ // interface on the underlying native object of a XPCWrappedNative.
2052
+
2053
+ class XPCWrappedNativeTearOff
2054
+ {
2055
+ public:
2056
+ JSBool IsAvailable() const {return mInterface == nsnull;}
2057
+ JSBool IsReserved() const {return mInterface == (XPCNativeInterface*)1;}
2058
+ JSBool IsValid() const {return !IsAvailable() && !IsReserved();}
2059
+ void SetReserved() {mInterface = (XPCNativeInterface*)1;}
2060
+
2061
+ XPCNativeInterface* GetInterface() const {return mInterface;}
2062
+ nsISupports* GetNative() const {return mNative;}
2063
+ JSObject* GetJSObject() const;
2064
+ void SetInterface(XPCNativeInterface* Interface) {mInterface = Interface;}
2065
+ void SetNative(nsISupports* Native) {mNative = Native;}
2066
+ void SetJSObject(JSObject* JSObj);
2067
+
2068
+ void JSObjectFinalized() {SetJSObject(nsnull);}
2069
+
2070
+ XPCWrappedNativeTearOff()
2071
+ : mInterface(nsnull), mNative(nsnull), mJSObject(nsnull) {}
2072
+ ~XPCWrappedNativeTearOff();
2073
+
2074
+ // NOP. This is just here to make the AutoMarkingPtr code compile.
2075
+ inline void TraceJS(JSTracer* trc) {}
2076
+ inline void AutoTrace(JSTracer* trc) {}
2077
+
2078
+ void Mark() {mJSObject = (JSObject*)(((jsword)mJSObject) | 1);}
2079
+ void Unmark() {mJSObject = (JSObject*)(((jsword)mJSObject) & ~1);}
2080
+ JSBool IsMarked() const {return (JSBool)(((jsword)mJSObject) & 1);}
2081
+
2082
+ #ifdef XPC_IDISPATCH_SUPPORT
2083
+ enum JSObject_flags
2084
+ {
2085
+ IDISPATCH_BIT = 2,
2086
+ JSOBJECT_MASK = 3
2087
+ };
2088
+ void SetIDispatch(JSContext* cx);
2089
+ JSBool IsIDispatch() const;
2090
+ XPCDispInterface* GetIDispatchInfo() const;
2091
+ #endif
2092
+ private:
2093
+ XPCWrappedNativeTearOff(const XPCWrappedNativeTearOff& r); // not implemented
2094
+ XPCWrappedNativeTearOff& operator= (const XPCWrappedNativeTearOff& r); // not implemented
2095
+
2096
+ private:
2097
+ XPCNativeInterface* mInterface;
2098
+ nsISupports* mNative;
2099
+ JSObject* mJSObject;
2100
+ };
2101
+
2102
+ /***********************************************/
2103
+ // XPCWrappedNativeTearOffChunk is a collections of XPCWrappedNativeTearOff
2104
+ // objects. It lets us allocate a set of XPCWrappedNativeTearOff objects and
2105
+ // link the sets - rather than only having the option of linking single
2106
+ // XPCWrappedNativeTearOff objects.
2107
+ //
2108
+ // The value of XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK can be tuned at buildtime
2109
+ // to balance between the code of allocations of additional chunks and the waste
2110
+ // of space for ununsed XPCWrappedNativeTearOff objects.
2111
+
2112
+ #define XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK 1
2113
+
2114
+ class XPCWrappedNativeTearOffChunk
2115
+ {
2116
+ friend class XPCWrappedNative;
2117
+ private:
2118
+ XPCWrappedNativeTearOffChunk() : mNextChunk(nsnull) {}
2119
+ ~XPCWrappedNativeTearOffChunk() {delete mNextChunk;}
2120
+
2121
+ private:
2122
+ XPCWrappedNativeTearOff mTearOffs[XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK];
2123
+ XPCWrappedNativeTearOffChunk* mNextChunk;
2124
+ };
2125
+
2126
+ /***************************************************************************/
2127
+ // XPCWrappedNative the wrapper around one instance of a native xpcom object
2128
+ // to be used from JavaScript.
2129
+
2130
+ class XPCWrappedNative : public nsIXPConnectWrappedNative
2131
+ {
2132
+ public:
2133
+ NS_DECL_ISUPPORTS
2134
+ NS_DECL_NSIXPCONNECTJSOBJECTHOLDER
2135
+ NS_DECL_NSIXPCONNECTWRAPPEDNATIVE
2136
+ // No need to unlink the JS objects, if the XPCWrappedNative will be cycle
2137
+ // collected then its mFlatJSObject will be cycle collected too and
2138
+ // finalization of the mFlatJSObject will unlink the js objects (see
2139
+ // XPC_WN_NoHelper_Finalize and FlatJSObjectFinalized).
2140
+ // We also rely on NS_DECL_CYCLE_COLLECTION_CLASS_NO_UNLINK having empty
2141
+ // Root/Unroot methods, to avoid root/unrooting the JS objects from
2142
+ // addrefing/releasing the XPCWrappedNative during unlinking, which would
2143
+ // make the JS objects uncollectable to the JS GC.
2144
+ class NS_CYCLE_COLLECTION_INNERCLASS
2145
+ : public nsXPCOMCycleCollectionParticipant
2146
+ {
2147
+ NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(XPCWrappedNative,
2148
+ XPCWrappedNative)
2149
+ NS_IMETHOD RootAndUnlinkJSObjects(void *p);
2150
+ NS_IMETHOD Unlink(void *p) { return NS_OK; }
2151
+ NS_IMETHOD Unroot(void *p) { return NS_OK; }
2152
+ };
2153
+ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
2154
+ NS_DECL_CYCLE_COLLECTION_UNMARK_PURPLE_STUB(XPCWrappedNative)
2155
+
2156
+ #ifndef XPCONNECT_STANDALONE
2157
+ virtual nsIPrincipal* GetObjectPrincipal() const;
2158
+ #endif
2159
+
2160
+ JSBool
2161
+ IsValid() const {return nsnull != mFlatJSObject;}
2162
+
2163
+ #define XPC_SCOPE_WORD(s) ((jsword)(s))
2164
+ #define XPC_SCOPE_MASK ((jsword)0x3)
2165
+ #define XPC_SCOPE_TAG ((jsword)0x1)
2166
+ #define XPC_WRAPPER_EXPIRED ((jsword)0x2)
2167
+
2168
+ static inline JSBool
2169
+ IsTaggedScope(XPCWrappedNativeScope* s)
2170
+ {return XPC_SCOPE_WORD(s) & XPC_SCOPE_TAG;}
2171
+
2172
+ static inline XPCWrappedNativeScope*
2173
+ TagScope(XPCWrappedNativeScope* s)
2174
+ {NS_ASSERTION(!IsTaggedScope(s), "bad pointer!");
2175
+ return (XPCWrappedNativeScope*)(XPC_SCOPE_WORD(s) | XPC_SCOPE_TAG);}
2176
+
2177
+ static inline XPCWrappedNativeScope*
2178
+ UnTagScope(XPCWrappedNativeScope* s)
2179
+ {return (XPCWrappedNativeScope*)(XPC_SCOPE_WORD(s) & ~XPC_SCOPE_TAG);}
2180
+
2181
+ inline JSBool
2182
+ IsWrapperExpired() const
2183
+ {return XPC_SCOPE_WORD(mMaybeScope) & XPC_WRAPPER_EXPIRED;}
2184
+
2185
+ JSBool
2186
+ HasProto() const {return !IsTaggedScope(mMaybeScope);}
2187
+
2188
+ XPCWrappedNativeProto*
2189
+ GetProto() const
2190
+ {return HasProto() ?
2191
+ (XPCWrappedNativeProto*)
2192
+ (XPC_SCOPE_WORD(mMaybeProto) & ~XPC_SCOPE_MASK) : nsnull;}
2193
+
2194
+ void
2195
+ SetProto(XPCWrappedNativeProto* p)
2196
+ {NS_ASSERTION(!IsWrapperExpired(), "bad ptr!");
2197
+ mMaybeProto = p;}
2198
+
2199
+ XPCWrappedNativeScope*
2200
+ GetScope() const
2201
+ {return GetProto() ? GetProto()->GetScope() :
2202
+ (XPCWrappedNativeScope*)
2203
+ (XPC_SCOPE_WORD(mMaybeScope) & ~XPC_SCOPE_MASK);}
2204
+
2205
+ nsISupports*
2206
+ GetIdentityObject() const {return mIdentity;}
2207
+
2208
+ JSObject*
2209
+ GetFlatJSObject() const {return mFlatJSObject;}
2210
+
2211
+ XPCLock*
2212
+ GetLock() const {return IsValid() && HasProto() ?
2213
+ GetProto()->GetLock() : nsnull;}
2214
+
2215
+ XPCNativeSet*
2216
+ GetSet() const {XPCAutoLock al(GetLock()); return mSet;}
2217
+
2218
+ private:
2219
+ void
2220
+ SetSet(XPCNativeSet* set) {XPCAutoLock al(GetLock()); mSet = set;}
2221
+
2222
+ inline void
2223
+ ExpireWrapper()
2224
+ {mMaybeScope = (XPCWrappedNativeScope*)
2225
+ (XPC_SCOPE_WORD(mMaybeScope) | XPC_WRAPPER_EXPIRED);}
2226
+
2227
+ public:
2228
+
2229
+ XPCNativeScriptableInfo*
2230
+ GetScriptableInfo() const {return mScriptableInfo;}
2231
+
2232
+ nsIXPCScriptable* // call this wrong and you deserve to crash
2233
+ GetScriptableCallback() const {return mScriptableInfo->GetCallback();}
2234
+
2235
+ void**
2236
+ GetSecurityInfoAddr() {return HasProto() ?
2237
+ GetProto()->GetSecurityInfoAddr() : nsnull;}
2238
+
2239
+ nsIClassInfo*
2240
+ GetClassInfo() const {return IsValid() && HasProto() ?
2241
+ GetProto()->GetClassInfo() : nsnull;}
2242
+
2243
+ JSBool
2244
+ HasSharedProto() const {return IsValid() && HasProto() &&
2245
+ GetProto()->IsShared();}
2246
+
2247
+ JSBool
2248
+ HasMutatedSet() const {return IsValid() &&
2249
+ (!HasProto() ||
2250
+ GetSet() != GetProto()->GetSet());}
2251
+
2252
+ XPCJSRuntime*
2253
+ GetRuntime() const {XPCWrappedNativeScope* scope = GetScope();
2254
+ return scope ? scope->GetRuntime() : nsnull;}
2255
+
2256
+ /**
2257
+ * If Object has a nsWrapperCache it should be passed in. If a cache is
2258
+ * passed in then cache->GetWrapper() must be null.
2259
+ */
2260
+ static nsresult
2261
+ GetNewOrUsed(XPCCallContext& ccx,
2262
+ nsISupports* Object,
2263
+ XPCWrappedNativeScope* Scope,
2264
+ XPCNativeInterface* Interface,
2265
+ nsWrapperCache* cache,
2266
+ JSBool isGlobal,
2267
+ XPCWrappedNative** wrapper);
2268
+
2269
+ public:
2270
+ static nsresult
2271
+ GetUsedOnly(XPCCallContext& ccx,
2272
+ nsISupports* Object,
2273
+ XPCWrappedNativeScope* Scope,
2274
+ XPCNativeInterface* Interface,
2275
+ XPCWrappedNative** wrapper);
2276
+
2277
+ static XPCWrappedNative*
2278
+ GetWrappedNativeOfJSObject(JSContext* cx, JSObject* obj,
2279
+ JSObject* funobj = nsnull,
2280
+ JSObject** pobj2 = nsnull,
2281
+ XPCWrappedNativeTearOff** pTearOff = nsnull);
2282
+
2283
+ static nsresult
2284
+ ReparentWrapperIfFound(XPCCallContext& ccx,
2285
+ XPCWrappedNativeScope* aOldScope,
2286
+ XPCWrappedNativeScope* aNewScope,
2287
+ JSObject* aNewParent,
2288
+ nsISupports* aCOMObj,
2289
+ XPCWrappedNative** aWrapper);
2290
+
2291
+ void FlatJSObjectFinalized(JSContext *cx);
2292
+
2293
+ void SystemIsBeingShutDown(JSContext* cx);
2294
+
2295
+ #ifdef XPC_DETECT_LEADING_UPPERCASE_ACCESS_ERRORS
2296
+ // This will try to find a member that is of the form "camelCased"
2297
+ // but was accessed from JS using "CamelCased". This is here to catch
2298
+ // mistakes caused by the confusion magnet that JS methods are by
2299
+ // convention 'foo' while C++ members are by convention 'Foo'.
2300
+ static void
2301
+ HandlePossibleNameCaseError(XPCCallContext& ccx,
2302
+ XPCNativeSet* set,
2303
+ XPCNativeInterface* iface,
2304
+ jsval name);
2305
+ static void
2306
+ HandlePossibleNameCaseError(JSContext* cx,
2307
+ XPCNativeSet* set,
2308
+ XPCNativeInterface* iface,
2309
+ jsval name);
2310
+
2311
+ #define HANDLE_POSSIBLE_NAME_CASE_ERROR(context, set, iface, name) \
2312
+ XPCWrappedNative::HandlePossibleNameCaseError(context, set, iface, name)
2313
+ #else
2314
+ #define HANDLE_POSSIBLE_NAME_CASE_ERROR(context, set, iface, name) ((void)0)
2315
+ #endif
2316
+
2317
+ enum CallMode {CALL_METHOD, CALL_GETTER, CALL_SETTER};
2318
+
2319
+ static JSBool CallMethod(XPCCallContext& ccx,
2320
+ CallMode mode = CALL_METHOD);
2321
+
2322
+ static JSBool GetAttribute(XPCCallContext& ccx)
2323
+ {return CallMethod(ccx, CALL_GETTER);}
2324
+
2325
+ static JSBool SetAttribute(XPCCallContext& ccx)
2326
+ {return CallMethod(ccx, CALL_SETTER);}
2327
+
2328
+ inline JSBool HasInterfaceNoQI(XPCNativeInterface* aInterface);
2329
+ inline JSBool HasInterfaceNoQI(const nsIID& iid);
2330
+
2331
+ XPCWrappedNativeTearOff* LocateTearOff(XPCCallContext& ccx,
2332
+ XPCNativeInterface* aInterface);
2333
+ XPCWrappedNativeTearOff* FindTearOff(XPCCallContext& ccx,
2334
+ XPCNativeInterface* aInterface,
2335
+ JSBool needJSObject = JS_FALSE,
2336
+ nsresult* pError = nsnull);
2337
+ void Mark() const
2338
+ {
2339
+ mSet->Mark();
2340
+ if(mScriptableInfo) mScriptableInfo->Mark();
2341
+ if(HasProto()) GetProto()->Mark();
2342
+ }
2343
+
2344
+ // Yes, we *do* need to mark the mScriptableInfo in both cases.
2345
+ inline void TraceJS(JSTracer* trc)
2346
+ {
2347
+ if(mScriptableInfo && JS_IsGCMarkingTracer(trc))
2348
+ mScriptableInfo->Mark();
2349
+ if(HasProto()) GetProto()->TraceJS(trc);
2350
+ JSObject* wrapper = GetWrapper();
2351
+ if(wrapper)
2352
+ JS_CALL_OBJECT_TRACER(trc, wrapper, "XPCWrappedNative::mWrapper");
2353
+ TraceOtherWrapper(trc);
2354
+ }
2355
+
2356
+ inline void AutoTrace(JSTracer* trc)
2357
+ {
2358
+ // If this got called, we're being kept alive by someone who really
2359
+ // needs us alive and whole. Do not let our mFlatJSObject go away.
2360
+ // This is the only time we should be tracing our mFlatJSObject,
2361
+ // normally somebody else is doing that. Be careful not to trace the
2362
+ // bogus JSVAL_ONE value we can have during init, though.
2363
+ if(mFlatJSObject && mFlatJSObject != (JSObject*)JSVAL_ONE)
2364
+ {
2365
+ JS_CALL_OBJECT_TRACER(trc, mFlatJSObject,
2366
+ "XPCWrappedNative::mFlatJSObject");
2367
+ }
2368
+ }
2369
+
2370
+ #ifdef DEBUG
2371
+ void ASSERT_SetsNotMarked() const
2372
+ {mSet->ASSERT_NotMarked();
2373
+ if(HasProto()){GetProto()->ASSERT_SetNotMarked();}}
2374
+
2375
+ int DEBUG_CountOfTearoffChunks() const
2376
+ {int i = 0; const XPCWrappedNativeTearOffChunk* to;
2377
+ for(to = &mFirstChunk; to; to = to->mNextChunk) {i++;} return i;}
2378
+ #endif
2379
+
2380
+ inline void SweepTearOffs();
2381
+
2382
+ // Returns a string that shuld be free'd using JS_smprintf_free (or null).
2383
+ char* ToString(XPCCallContext& ccx,
2384
+ XPCWrappedNativeTearOff* to = nsnull) const;
2385
+
2386
+ static nsresult GatherProtoScriptableCreateInfo(
2387
+ nsIClassInfo* classInfo,
2388
+ XPCNativeScriptableCreateInfo* sciProto);
2389
+
2390
+ JSBool HasExternalReference() const {return mRefCnt > 1;}
2391
+
2392
+ JSBool NeedsChromeWrapper() { return !!(mWrapper & 1); }
2393
+ void SetNeedsChromeWrapper() { mWrapper |= 1; }
2394
+ JSObject* GetWrapper()
2395
+ {
2396
+ return (JSObject *)(mWrapper & ~1);
2397
+ }
2398
+ void SetWrapper(JSObject *obj)
2399
+ {
2400
+ JSBool reset = NeedsChromeWrapper();
2401
+ mWrapper = PRWord(obj) | reset;
2402
+ }
2403
+
2404
+ void NoteTearoffs(nsCycleCollectionTraversalCallback& cb);
2405
+
2406
+ QITableEntry* GetOffsets()
2407
+ {
2408
+ if(!HasProto() || !GetProto()->ClassIsDOMObject())
2409
+ return nsnull;
2410
+
2411
+ XPCWrappedNativeProto* proto = GetProto();
2412
+ QITableEntry* offsets = proto->GetOffsets();
2413
+ if(!offsets)
2414
+ {
2415
+ static NS_DEFINE_IID(kThisPtrOffsetsSID, NS_THISPTROFFSETS_SID);
2416
+ mIdentity->QueryInterface(kThisPtrOffsetsSID, (void**)&offsets);
2417
+ }
2418
+ return offsets;
2419
+ }
2420
+
2421
+ // Make ctor and dtor protected (rather than private) to placate nsCOMPtr.
2422
+ protected:
2423
+ XPCWrappedNative(); // not implemented
2424
+
2425
+ // This ctor is used if this object will have a proto.
2426
+ XPCWrappedNative(nsISupports* aIdentity,
2427
+ XPCWrappedNativeProto* aProto);
2428
+
2429
+ // This ctor is used if this object will NOT have a proto.
2430
+ XPCWrappedNative(nsISupports* aIdentity,
2431
+ XPCWrappedNativeScope* aScope,
2432
+ XPCNativeSet* aSet);
2433
+
2434
+ virtual ~XPCWrappedNative();
2435
+
2436
+ private:
2437
+ void TraceOtherWrapper(JSTracer* trc);
2438
+ JSBool Init(XPCCallContext& ccx, JSObject* parent, JSBool isGlobal,
2439
+ const XPCNativeScriptableCreateInfo* sci);
2440
+
2441
+ JSBool ExtendSet(XPCCallContext& ccx, XPCNativeInterface* aInterface);
2442
+
2443
+ nsresult InitTearOff(XPCCallContext& ccx,
2444
+ XPCWrappedNativeTearOff* aTearOff,
2445
+ XPCNativeInterface* aInterface,
2446
+ JSBool needJSObject);
2447
+
2448
+ JSBool InitTearOffJSObject(XPCCallContext& ccx,
2449
+ XPCWrappedNativeTearOff* to);
2450
+
2451
+ public:
2452
+ static nsresult GatherScriptableCreateInfo(
2453
+ nsISupports* obj,
2454
+ nsIClassInfo* classInfo,
2455
+ XPCNativeScriptableCreateInfo* sciProto,
2456
+ XPCNativeScriptableCreateInfo* sciWrapper);
2457
+
2458
+ private:
2459
+ union
2460
+ {
2461
+ XPCWrappedNativeScope* mMaybeScope;
2462
+ XPCWrappedNativeProto* mMaybeProto;
2463
+ };
2464
+ XPCNativeSet* mSet;
2465
+ JSObject* mFlatJSObject;
2466
+ XPCNativeScriptableInfo* mScriptableInfo;
2467
+ XPCWrappedNativeTearOffChunk mFirstChunk;
2468
+ PRWord mWrapper;
2469
+
2470
+ #ifdef XPC_CHECK_WRAPPER_THREADSAFETY
2471
+ public:
2472
+ nsCOMPtr<nsIThread> mThread; // Don't want to overload _mOwningThread
2473
+ #endif
2474
+ };
2475
+
2476
+ /***************************************************************************
2477
+ ****************************************************************************
2478
+ *
2479
+ * Core classes for wrapped JSObject for use from native code...
2480
+ *
2481
+ ****************************************************************************
2482
+ ***************************************************************************/
2483
+
2484
+ // this interfaces exists so we can refcount nsXPCWrappedJSClass
2485
+ // {2453EBA0-A9B8-11d2-BA64-00805F8A5DD7}
2486
+ #define NS_IXPCONNECT_WRAPPED_JS_CLASS_IID \
2487
+ { 0x2453eba0, 0xa9b8, 0x11d2, \
2488
+ { 0xba, 0x64, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
2489
+
2490
+ class nsIXPCWrappedJSClass : public nsISupports
2491
+ {
2492
+ public:
2493
+ NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_JS_CLASS_IID)
2494
+ NS_IMETHOD DebugDump(PRInt16 depth) = 0;
2495
+ };
2496
+
2497
+ NS_DEFINE_STATIC_IID_ACCESSOR(nsIXPCWrappedJSClass,
2498
+ NS_IXPCONNECT_WRAPPED_JS_CLASS_IID)
2499
+
2500
+ /*************************/
2501
+ // nsXPCWrappedJSClass represents the sharable factored out common code and
2502
+ // data for nsXPCWrappedJS instances for the same interface type.
2503
+
2504
+ class nsXPCWrappedJSClass : public nsIXPCWrappedJSClass
2505
+ {
2506
+ // all the interface method declarations...
2507
+ NS_DECL_ISUPPORTS
2508
+ NS_IMETHOD DebugDump(PRInt16 depth);
2509
+ public:
2510
+
2511
+ static nsresult
2512
+ GetNewOrUsed(XPCCallContext& ccx,
2513
+ REFNSIID aIID,
2514
+ nsXPCWrappedJSClass** clazz);
2515
+
2516
+ REFNSIID GetIID() const {return mIID;}
2517
+ XPCJSRuntime* GetRuntime() const {return mRuntime;}
2518
+ nsIInterfaceInfo* GetInterfaceInfo() const {return mInfo;}
2519
+ const char* GetInterfaceName();
2520
+
2521
+ static JSBool IsWrappedJS(nsISupports* aPtr);
2522
+
2523
+ NS_IMETHOD DelegatedQueryInterface(nsXPCWrappedJS* self, REFNSIID aIID,
2524
+ void** aInstancePtr);
2525
+
2526
+ JSObject* GetRootJSObject(XPCCallContext& ccx, JSObject* aJSObj);
2527
+
2528
+ NS_IMETHOD CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
2529
+ const XPTMethodDescriptor* info,
2530
+ nsXPTCMiniVariant* params);
2531
+
2532
+ JSObject* CallQueryInterfaceOnJSObject(XPCCallContext& ccx,
2533
+ JSObject* jsobj, REFNSIID aIID);
2534
+
2535
+ static nsresult BuildPropertyEnumerator(XPCCallContext& ccx,
2536
+ JSObject* aJSObj,
2537
+ nsISimpleEnumerator** aEnumerate);
2538
+
2539
+ static nsresult GetNamedPropertyAsVariant(XPCCallContext& ccx,
2540
+ JSObject* aJSObj,
2541
+ jsval aName,
2542
+ nsIVariant** aResult);
2543
+
2544
+ virtual ~nsXPCWrappedJSClass();
2545
+
2546
+ static nsresult CheckForException(XPCCallContext & ccx,
2547
+ const char * aPropertyName,
2548
+ const char * anInterfaceName,
2549
+ PRBool aForceReport);
2550
+ private:
2551
+ nsXPCWrappedJSClass(); // not implemented
2552
+ nsXPCWrappedJSClass(XPCCallContext& ccx, REFNSIID aIID,
2553
+ nsIInterfaceInfo* aInfo);
2554
+
2555
+ JSObject* NewOutObject(JSContext* cx, JSObject* scope);
2556
+
2557
+ JSBool IsReflectable(uint16 i) const
2558
+ {return (JSBool)(mDescriptors[i/32] & (1 << (i%32)));}
2559
+ void SetReflectable(uint16 i, JSBool b)
2560
+ {if(b) mDescriptors[i/32] |= (1 << (i%32));
2561
+ else mDescriptors[i/32] &= ~(1 << (i%32));}
2562
+
2563
+ enum SizeMode {GET_SIZE, GET_LENGTH};
2564
+
2565
+ JSBool GetArraySizeFromParam(JSContext* cx,
2566
+ const XPTMethodDescriptor* method,
2567
+ const nsXPTParamInfo& param,
2568
+ uint16 methodIndex,
2569
+ uint8 paramIndex,
2570
+ SizeMode mode,
2571
+ nsXPTCMiniVariant* params,
2572
+ JSUint32* result);
2573
+
2574
+ JSBool GetInterfaceTypeFromParam(JSContext* cx,
2575
+ const XPTMethodDescriptor* method,
2576
+ const nsXPTParamInfo& param,
2577
+ uint16 methodIndex,
2578
+ const nsXPTType& type,
2579
+ nsXPTCMiniVariant* params,
2580
+ nsID* result);
2581
+
2582
+ void CleanupPointerArray(const nsXPTType& datum_type,
2583
+ JSUint32 array_count,
2584
+ void** arrayp);
2585
+
2586
+ void CleanupPointerTypeObject(const nsXPTType& type,
2587
+ void** pp);
2588
+
2589
+ private:
2590
+ XPCJSRuntime* mRuntime;
2591
+ nsIInterfaceInfo* mInfo;
2592
+ char* mName;
2593
+ nsIID mIID;
2594
+ uint32* mDescriptors;
2595
+ };
2596
+
2597
+ /*************************/
2598
+ // nsXPCWrappedJS is a wrapper for a single JSObject for use from native code.
2599
+ // nsXPCWrappedJS objects are chained together to represent the various
2600
+ // interface on the single underlying (possibly aggregate) JSObject.
2601
+
2602
+ class nsXPCWrappedJS : protected nsAutoXPTCStub,
2603
+ public nsIXPConnectWrappedJS,
2604
+ public nsSupportsWeakReference,
2605
+ public nsIPropertyBag,
2606
+ public XPCRootSetElem
2607
+ {
2608
+ public:
2609
+ NS_DECL_ISUPPORTS
2610
+ NS_DECL_NSIXPCONNECTJSOBJECTHOLDER
2611
+ NS_DECL_NSIXPCONNECTWRAPPEDJS
2612
+ NS_DECL_NSISUPPORTSWEAKREFERENCE
2613
+ NS_DECL_NSIPROPERTYBAG
2614
+
2615
+ class NS_CYCLE_COLLECTION_INNERCLASS
2616
+ : public nsXPCOMCycleCollectionParticipant
2617
+ {
2618
+ NS_IMETHOD RootAndUnlinkJSObjects(void *p);
2619
+ NS_DECL_CYCLE_COLLECTION_CLASS_BODY(nsXPCWrappedJS, nsIXPConnectWrappedJS)
2620
+ };
2621
+ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
2622
+ NS_DECL_CYCLE_COLLECTION_UNMARK_PURPLE_STUB(nsXPCWrappedJS)
2623
+
2624
+ NS_IMETHOD CallMethod(PRUint16 methodIndex,
2625
+ const XPTMethodDescriptor *info,
2626
+ nsXPTCMiniVariant* params);
2627
+
2628
+ /*
2629
+ * This is rarely called directly. Instead one usually calls
2630
+ * XPCConvert::JSObject2NativeInterface which will handles cases where the
2631
+ * JS object is already a wrapped native or a DOM object.
2632
+ */
2633
+
2634
+ static nsresult
2635
+ GetNewOrUsed(XPCCallContext& ccx,
2636
+ JSObject* aJSObj,
2637
+ REFNSIID aIID,
2638
+ nsISupports* aOuter,
2639
+ nsXPCWrappedJS** wrapper);
2640
+
2641
+ nsISomeInterface* GetXPTCStub() { return mXPTCStub; }
2642
+ JSObject* GetJSObject() const {return mJSObj;}
2643
+ nsXPCWrappedJSClass* GetClass() const {return mClass;}
2644
+ REFNSIID GetIID() const {return GetClass()->GetIID();}
2645
+ nsXPCWrappedJS* GetRootWrapper() const {return mRoot;}
2646
+ nsXPCWrappedJS* GetNextWrapper() const {return mNext;}
2647
+
2648
+ nsXPCWrappedJS* Find(REFNSIID aIID);
2649
+ nsXPCWrappedJS* FindInherited(REFNSIID aIID);
2650
+
2651
+ JSBool IsValid() const {return mJSObj != nsnull;}
2652
+ void SystemIsBeingShutDown(JSRuntime* rt);
2653
+
2654
+ // This is used by XPCJSRuntime::GCCallback to find wrappers that no
2655
+ // longer root their JSObject and are only still alive because they
2656
+ // were being used via nsSupportsWeakReference at the time when their
2657
+ // last (outside) reference was released. Wrappers that fit into that
2658
+ // category are only deleted when we see that their corresponding JSObject
2659
+ // is to be finalized.
2660
+ JSBool IsSubjectToFinalization() const {return IsValid() && mRefCnt == 1;}
2661
+
2662
+ JSBool IsAggregatedToNative() const {return mRoot->mOuter != nsnull;}
2663
+ nsISupports* GetAggregatedNativeObject() const {return mRoot->mOuter;}
2664
+
2665
+ void TraceJS(JSTracer* trc);
2666
+ #ifdef DEBUG
2667
+ static void PrintTraceName(JSTracer* trc, char *buf, size_t bufsize);
2668
+ #endif
2669
+
2670
+ virtual ~nsXPCWrappedJS();
2671
+ protected:
2672
+ nsXPCWrappedJS(); // not implemented
2673
+ nsXPCWrappedJS(XPCCallContext& ccx,
2674
+ JSObject* aJSObj,
2675
+ nsXPCWrappedJSClass* aClass,
2676
+ nsXPCWrappedJS* root,
2677
+ nsISupports* aOuter);
2678
+
2679
+ void Unlink();
2680
+
2681
+ private:
2682
+ JSObject* mJSObj;
2683
+ nsXPCWrappedJSClass* mClass;
2684
+ nsXPCWrappedJS* mRoot;
2685
+ nsXPCWrappedJS* mNext;
2686
+ nsISupports* mOuter; // only set in root
2687
+ };
2688
+
2689
+ /***************************************************************************/
2690
+
2691
+ class XPCJSObjectHolder : public nsIXPConnectJSObjectHolder,
2692
+ public XPCRootSetElem
2693
+ {
2694
+ public:
2695
+ // all the interface method declarations...
2696
+ NS_DECL_ISUPPORTS
2697
+ NS_DECL_NSIXPCONNECTJSOBJECTHOLDER
2698
+
2699
+ // non-interface implementation
2700
+
2701
+ public:
2702
+ static XPCJSObjectHolder* newHolder(XPCCallContext& ccx, JSObject* obj);
2703
+
2704
+ virtual ~XPCJSObjectHolder();
2705
+
2706
+ void TraceJS(JSTracer *trc);
2707
+ #ifdef DEBUG
2708
+ static void PrintTraceName(JSTracer* trc, char *buf, size_t bufsize);
2709
+ #endif
2710
+
2711
+ private:
2712
+ XPCJSObjectHolder(XPCCallContext& ccx, JSObject* obj);
2713
+ XPCJSObjectHolder(); // not implemented
2714
+
2715
+ JSObject* mJSObj;
2716
+ };
2717
+
2718
+ /***************************************************************************
2719
+ ****************************************************************************
2720
+ *
2721
+ * All manner of utility classes follow...
2722
+ *
2723
+ ****************************************************************************
2724
+ ***************************************************************************/
2725
+
2726
+ class xpcProperty : public nsIProperty
2727
+ {
2728
+ public:
2729
+ NS_DECL_ISUPPORTS
2730
+ NS_DECL_NSIPROPERTY
2731
+
2732
+ xpcProperty(const PRUnichar* aName, PRUint32 aNameLen, nsIVariant* aValue);
2733
+ virtual ~xpcProperty() {}
2734
+
2735
+ private:
2736
+ nsString mName;
2737
+ nsCOMPtr<nsIVariant> mValue;
2738
+ };
2739
+
2740
+ class xpcPropertyBagEnumerator : public nsISimpleEnumerator
2741
+ {
2742
+ public:
2743
+ NS_DECL_ISUPPORTS
2744
+ NS_DECL_NSISIMPLEENUMERATOR
2745
+
2746
+ xpcPropertyBagEnumerator(PRUint32 count);
2747
+ virtual ~xpcPropertyBagEnumerator() {}
2748
+
2749
+ JSBool AppendElement(nsISupports* element);
2750
+
2751
+ private:
2752
+ nsSupportsArray mArray;
2753
+ PRUint32 mIndex;
2754
+ PRUint32 mCount;
2755
+ };
2756
+
2757
+ /***************************************************************************/
2758
+ // data conversion
2759
+
2760
+ // class here just for static methods
2761
+ class XPCConvert
2762
+ {
2763
+ public:
2764
+ static JSBool IsMethodReflectable(const XPTMethodDescriptor& info);
2765
+
2766
+ /**
2767
+ * Convert a native object into a jsval.
2768
+ *
2769
+ * @param ccx the context for the whole procedure
2770
+ * @param d [out] the resulting jsval
2771
+ * @param s the native object we're working with
2772
+ * @param type the type of object that s is
2773
+ * @param iid the interface of s that we want
2774
+ * @param scope the default scope to put on the new JSObject's __parent__
2775
+ * chain
2776
+ * @param pErr [out] relevant error code, if any.
2777
+ */
2778
+ static JSBool NativeData2JS(XPCCallContext& ccx, jsval* d, const void* s,
2779
+ const nsXPTType& type, const nsID* iid,
2780
+ JSObject* scope, nsresult* pErr);
2781
+
2782
+ static JSBool JSData2Native(XPCCallContext& ccx, void* d, jsval s,
2783
+ const nsXPTType& type,
2784
+ JSBool useAllocator, const nsID* iid,
2785
+ nsresult* pErr);
2786
+
2787
+ /**
2788
+ * Convert a native nsISupports into a JSObject.
2789
+ *
2790
+ * @param ccx the context for the whole procedure
2791
+ * @param dest [out] the resulting JSObject
2792
+ * @param src the native object we're working with
2793
+ * @param iid the interface of src that we want
2794
+ * @param scope the default scope to put on the new JSObject's __parent__
2795
+ * chain
2796
+ * @param allowNativeWrapper if true, this method may wrap the resulting
2797
+ * JSObject in an XPCNativeWrapper and return that, as needed.
2798
+ * @param pErr [out] relevant error code, if any.
2799
+ */
2800
+ static JSBool NativeInterface2JSObject(XPCCallContext& ccx,
2801
+ jsval* d,
2802
+ nsIXPConnectJSObjectHolder** dest,
2803
+ nsISupports* src,
2804
+ const nsID* iid,
2805
+ XPCNativeInterface* Interface,
2806
+ nsWrapperCache *cache,
2807
+ JSObject* scope,
2808
+ PRBool allowNativeWrapper,
2809
+ PRBool isGlobal,
2810
+ nsresult* pErr);
2811
+
2812
+ static JSBool GetNativeInterfaceFromJSObject(XPCCallContext& ccx,
2813
+ void** dest, JSObject* src,
2814
+ const nsID* iid,
2815
+ nsresult* pErr);
2816
+ static JSBool JSObject2NativeInterface(XPCCallContext& ccx,
2817
+ void** dest, JSObject* src,
2818
+ const nsID* iid,
2819
+ nsISupports* aOuter,
2820
+ nsresult* pErr);
2821
+ static JSBool GetISupportsFromJSObject(JSObject* obj, nsISupports** iface);
2822
+
2823
+ /**
2824
+ * Convert a native array into a jsval.
2825
+ *
2826
+ * @param ccx the context for the whole procedure
2827
+ * @param d [out] the resulting jsval
2828
+ * @param s the native array we're working with
2829
+ * @param type the type of objects in the array
2830
+ * @param iid the interface of each object in the array that we want
2831
+ * @param count the number of items in the array
2832
+ * @param scope the default scope to put on the new JSObjects' __parent__
2833
+ * chain
2834
+ * @param pErr [out] relevant error code, if any.
2835
+ */
2836
+ static JSBool NativeArray2JS(XPCCallContext& ccx,
2837
+ jsval* d, const void** s,
2838
+ const nsXPTType& type, const nsID* iid,
2839
+ JSUint32 count, JSObject* scope,
2840
+ nsresult* pErr);
2841
+
2842
+ static JSBool JSArray2Native(XPCCallContext& ccx, void** d, jsval s,
2843
+ JSUint32 count, JSUint32 capacity,
2844
+ const nsXPTType& type,
2845
+ JSBool useAllocator, const nsID* iid,
2846
+ uintN* pErr);
2847
+
2848
+ static JSBool NativeStringWithSize2JS(XPCCallContext& ccx,
2849
+ jsval* d, const void* s,
2850
+ const nsXPTType& type,
2851
+ JSUint32 count,
2852
+ nsresult* pErr);
2853
+
2854
+ static JSBool JSStringWithSize2Native(XPCCallContext& ccx, void* d, jsval s,
2855
+ JSUint32 count, JSUint32 capacity,
2856
+ const nsXPTType& type,
2857
+ JSBool useAllocator,
2858
+ uintN* pErr);
2859
+
2860
+ static nsresult JSValToXPCException(XPCCallContext& ccx,
2861
+ jsval s,
2862
+ const char* ifaceName,
2863
+ const char* methodName,
2864
+ nsIException** exception);
2865
+
2866
+ static nsresult JSErrorToXPCException(XPCCallContext& ccx,
2867
+ const char* message,
2868
+ const char* ifaceName,
2869
+ const char* methodName,
2870
+ const JSErrorReport* report,
2871
+ nsIException** exception);
2872
+
2873
+ static nsresult ConstructException(nsresult rv, const char* message,
2874
+ const char* ifaceName,
2875
+ const char* methodName,
2876
+ nsISupports* data,
2877
+ nsIException** exception,
2878
+ JSContext* cx,
2879
+ jsval *jsExceptionPtr);
2880
+
2881
+ static void RemoveXPCOMUCStringFinalizer();
2882
+
2883
+ private:
2884
+ XPCConvert(); // not implemented
2885
+
2886
+ };
2887
+
2888
+ /***************************************************************************/
2889
+
2890
+ // readable string conversions, static methods only
2891
+ class XPCStringConvert
2892
+ {
2893
+ public:
2894
+
2895
+ static JSString *ReadableToJSString(JSContext *cx,
2896
+ const nsAString &readable);
2897
+
2898
+ static XPCReadableJSStringWrapper *JSStringToReadable(XPCCallContext& ccx,
2899
+ JSString *str);
2900
+
2901
+ static void ShutdownDOMStringFinalizer();
2902
+
2903
+ private:
2904
+ XPCStringConvert(); // not implemented
2905
+ };
2906
+
2907
+ extern JSBool
2908
+ XPC_JSArgumentFormatter(JSContext *cx, const char *format,
2909
+ JSBool fromJS, jsval **vpp, va_list *app);
2910
+
2911
+
2912
+ /***************************************************************************/
2913
+ // code for throwing exceptions into JS
2914
+
2915
+ class XPCThrower
2916
+ {
2917
+ public:
2918
+ static void Throw(nsresult rv, JSContext* cx);
2919
+ static void Throw(nsresult rv, XPCCallContext& ccx);
2920
+ static void ThrowBadResult(nsresult rv, nsresult result, XPCCallContext& ccx);
2921
+ static void ThrowBadParam(nsresult rv, uintN paramNum, XPCCallContext& ccx);
2922
+ #ifdef XPC_IDISPATCH_SUPPORT
2923
+ static void ThrowCOMError(JSContext* cx, unsigned long COMErrorCode,
2924
+ nsresult rv = NS_ERROR_XPC_COM_ERROR,
2925
+ const EXCEPINFO * exception = nsnull);
2926
+ #endif
2927
+ static JSBool SetVerbosity(JSBool state)
2928
+ {JSBool old = sVerbose; sVerbose = state; return old;}
2929
+
2930
+ static void BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz);
2931
+ static JSBool CheckForPendingException(nsresult result, JSContext *cx);
2932
+
2933
+ private:
2934
+ static void Verbosify(XPCCallContext& ccx,
2935
+ char** psz, PRBool own);
2936
+
2937
+ static JSBool ThrowExceptionObject(JSContext* cx, nsIException* e);
2938
+
2939
+ private:
2940
+ static JSBool sVerbose;
2941
+ };
2942
+
2943
+
2944
+ /***************************************************************************/
2945
+
2946
+ class XPCJSStack
2947
+ {
2948
+ public:
2949
+ static nsresult
2950
+ CreateStack(JSContext* cx, nsIStackFrame** stack);
2951
+
2952
+ static nsresult
2953
+ CreateStackFrameLocation(PRUint32 aLanguage,
2954
+ const char* aFilename,
2955
+ const char* aFunctionName,
2956
+ PRInt32 aLineNumber,
2957
+ nsIStackFrame* aCaller,
2958
+ nsIStackFrame** stack);
2959
+ private:
2960
+ XPCJSStack(); // not implemented
2961
+ };
2962
+
2963
+ /***************************************************************************/
2964
+
2965
+ class nsXPCException :
2966
+ public nsIXPCException
2967
+ {
2968
+ public:
2969
+ NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCEXCEPTION_CID)
2970
+
2971
+ NS_DECL_ISUPPORTS
2972
+ NS_DECL_NSIEXCEPTION
2973
+ NS_DECL_NSIXPCEXCEPTION
2974
+
2975
+ static nsresult NewException(const char *aMessage,
2976
+ nsresult aResult,
2977
+ nsIStackFrame *aLocation,
2978
+ nsISupports *aData,
2979
+ nsIException** exception);
2980
+
2981
+ static JSBool NameAndFormatForNSResult(nsresult rv,
2982
+ const char** name,
2983
+ const char** format);
2984
+
2985
+ static void* IterateNSResults(nsresult* rv,
2986
+ const char** name,
2987
+ const char** format,
2988
+ void** iterp);
2989
+
2990
+ static PRUint32 GetNSResultCount();
2991
+
2992
+ nsXPCException();
2993
+ virtual ~nsXPCException();
2994
+
2995
+ static void InitStatics() { sEverMadeOneFromFactory = JS_FALSE; }
2996
+
2997
+ PRBool StealThrownJSVal(jsval* vp);
2998
+ void StowThrownJSVal(JSContext* cx, jsval v);
2999
+
3000
+ protected:
3001
+ void Reset();
3002
+ private:
3003
+ char* mMessage;
3004
+ nsresult mResult;
3005
+ char* mName;
3006
+ nsIStackFrame* mLocation;
3007
+ nsISupports* mData;
3008
+ char* mFilename;
3009
+ int mLineNumber;
3010
+ nsIException* mInner;
3011
+ PRBool mInitialized;
3012
+
3013
+ nsAutoJSValHolder mThrownJSVal;
3014
+
3015
+ static JSBool sEverMadeOneFromFactory;
3016
+ };
3017
+
3018
+ /***************************************************************************/
3019
+ /*
3020
+ * nsJSID implements nsIJSID. It is also used by nsJSIID and nsJSCID as a
3021
+ * member (as a hidden implementaion detail) to which they delegate many calls.
3022
+ */
3023
+
3024
+ extern JSBool xpc_InitJSxIDClassObjects();
3025
+ extern void xpc_DestroyJSxIDClassObjects();
3026
+
3027
+
3028
+ class nsJSID : public nsIJSID
3029
+ {
3030
+ public:
3031
+ NS_DEFINE_STATIC_CID_ACCESSOR(NS_JS_ID_CID)
3032
+
3033
+ NS_DECL_ISUPPORTS
3034
+ NS_DECL_NSIJSID
3035
+
3036
+ PRBool InitWithName(const nsID& id, const char *nameString);
3037
+ PRBool SetName(const char* name);
3038
+ void SetNameToNoString()
3039
+ {NS_ASSERTION(!mName, "name already set"); mName = gNoString;}
3040
+ PRBool NameIsSet() const {return nsnull != mName;}
3041
+ const nsID& ID() const {return mID;}
3042
+ PRBool IsValid() const {return !mID.Equals(GetInvalidIID());}
3043
+
3044
+ static nsJSID* NewID(const char* str);
3045
+ static nsJSID* NewID(const nsID& id);
3046
+
3047
+ nsJSID();
3048
+ virtual ~nsJSID();
3049
+ protected:
3050
+
3051
+ void Reset();
3052
+ const nsID& GetInvalidIID() const;
3053
+
3054
+ protected:
3055
+ static char gNoString[];
3056
+ nsID mID;
3057
+ char* mNumber;
3058
+ char* mName;
3059
+ };
3060
+
3061
+ // nsJSIID
3062
+
3063
+ class nsJSIID : public nsIJSIID, public nsIXPCScriptable
3064
+ #ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
3065
+ , public nsISecurityCheckedComponent
3066
+ #endif
3067
+ {
3068
+ public:
3069
+ NS_DECL_ISUPPORTS
3070
+
3071
+ // we manually delagate these to nsJSID
3072
+ NS_DECL_NSIJSID
3073
+
3074
+ // we implement the rest...
3075
+ NS_DECL_NSIJSIID
3076
+ NS_DECL_NSIXPCSCRIPTABLE
3077
+ #ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
3078
+ NS_DECL_NSISECURITYCHECKEDCOMPONENT
3079
+ #endif
3080
+
3081
+ static nsJSIID* NewID(nsIInterfaceInfo* aInfo);
3082
+
3083
+ nsJSIID(nsIInterfaceInfo* aInfo);
3084
+ nsJSIID(); // not implemented
3085
+ virtual ~nsJSIID();
3086
+
3087
+ private:
3088
+ nsCOMPtr<nsIInterfaceInfo> mInfo;
3089
+ };
3090
+
3091
+ // nsJSCID
3092
+
3093
+ class nsJSCID : public nsIJSCID, public nsIXPCScriptable
3094
+ {
3095
+ public:
3096
+ NS_DECL_ISUPPORTS
3097
+
3098
+ // we manually delagate these to nsJSID
3099
+ NS_DECL_NSIJSID
3100
+
3101
+ // we implement the rest...
3102
+ NS_DECL_NSIJSCID
3103
+ NS_DECL_NSIXPCSCRIPTABLE
3104
+
3105
+ static nsJSCID* NewID(const char* str);
3106
+
3107
+ nsJSCID();
3108
+ virtual ~nsJSCID();
3109
+
3110
+ private:
3111
+ void ResolveName();
3112
+
3113
+ private:
3114
+ nsJSID mDetails;
3115
+ };
3116
+
3117
+
3118
+ /***************************************************************************/
3119
+ // XPCJSContextStack is not actually an xpcom object, but xpcom calls are
3120
+ // delegated to it as an implementation detail.
3121
+ struct XPCJSContextInfo {
3122
+ XPCJSContextInfo(JSContext* aCx) :
3123
+ cx(aCx),
3124
+ frame(nsnull),
3125
+ requestDepth(0)
3126
+ {}
3127
+ JSContext* cx;
3128
+
3129
+ // Frame to be restored when this JSContext becomes the topmost
3130
+ // one.
3131
+ JSStackFrame* frame;
3132
+
3133
+ // Greater than 0 if a request was suspended
3134
+ jsrefcount requestDepth;
3135
+ };
3136
+
3137
+ class XPCJSContextStack
3138
+ {
3139
+ public:
3140
+ NS_DECL_NSIJSCONTEXTSTACK
3141
+ NS_DECL_NSITHREADJSCONTEXTSTACK
3142
+
3143
+ XPCJSContextStack();
3144
+ virtual ~XPCJSContextStack();
3145
+
3146
+ #ifdef DEBUG
3147
+ JSBool DEBUG_StackHasJSContext(JSContext* aJSContext);
3148
+ #endif
3149
+
3150
+ const nsTArray<XPCJSContextInfo>* GetStack()
3151
+ { return &mStack; }
3152
+
3153
+ private:
3154
+ nsAutoTArray<XPCJSContextInfo, 16> mStack;
3155
+ JSContext* mSafeJSContext;
3156
+
3157
+ // If non-null, we own it; same as mSafeJSContext if SetSafeJSContext
3158
+ // not called.
3159
+ JSContext* mOwnSafeJSContext;
3160
+ };
3161
+
3162
+ /***************************************************************************/
3163
+
3164
+ #define NS_XPC_JSCONTEXT_STACK_ITERATOR_CID \
3165
+ { 0x05bae29d, 0x8aef, 0x486d, \
3166
+ { 0x84, 0xaa, 0x53, 0xf4, 0x8f, 0x14, 0x68, 0x11 } }
3167
+
3168
+ class nsXPCJSContextStackIterator : public nsIJSContextStackIterator
3169
+ {
3170
+ public:
3171
+ NS_DECL_ISUPPORTS
3172
+ NS_DECL_NSIJSCONTEXTSTACKITERATOR
3173
+
3174
+ private:
3175
+ const nsTArray<XPCJSContextInfo> *mStack;
3176
+ PRUint32 mPosition;
3177
+ };
3178
+
3179
+ /**************************************************************/
3180
+ // All of our thread local storage.
3181
+
3182
+ #define BAD_TLS_INDEX ((PRUint32) -1)
3183
+
3184
+ class XPCPerThreadData
3185
+ {
3186
+ public:
3187
+ // Get the instance of this object for the current thread
3188
+ static inline XPCPerThreadData* GetData(JSContext *cx)
3189
+ {
3190
+ if(cx)
3191
+ {
3192
+ NS_ASSERTION(cx->thread, "Uh, JS context w/o a thread?");
3193
+
3194
+ if(cx->thread == sMainJSThread)
3195
+ return sMainThreadData;
3196
+ }
3197
+ else if(sMainThreadData && sMainThreadData->mThread == PR_GetCurrentThread())
3198
+ {
3199
+ return sMainThreadData;
3200
+ }
3201
+
3202
+ return GetDataImpl(cx);
3203
+ }
3204
+
3205
+ static void CleanupAllThreads();
3206
+
3207
+ ~XPCPerThreadData();
3208
+
3209
+ nsresult GetException(nsIException** aException)
3210
+ {
3211
+ if(EnsureExceptionManager())
3212
+ return mExceptionManager->GetCurrentException(aException);
3213
+
3214
+ NS_IF_ADDREF(mException);
3215
+ *aException = mException;
3216
+ return NS_OK;
3217
+ }
3218
+
3219
+ nsresult SetException(nsIException* aException)
3220
+ {
3221
+ if(EnsureExceptionManager())
3222
+ return mExceptionManager->SetCurrentException(aException);
3223
+
3224
+ NS_IF_ADDREF(aException);
3225
+ NS_IF_RELEASE(mException);
3226
+ mException = aException;
3227
+ return NS_OK;
3228
+ }
3229
+
3230
+ nsIExceptionManager* GetExceptionManager()
3231
+ {
3232
+ if(EnsureExceptionManager())
3233
+ return mExceptionManager;
3234
+ return nsnull;
3235
+ }
3236
+
3237
+ JSBool EnsureExceptionManager()
3238
+ {
3239
+ if(mExceptionManager)
3240
+ return JS_TRUE;
3241
+
3242
+ if(mExceptionManagerNotAvailable)
3243
+ return JS_FALSE;
3244
+
3245
+ nsCOMPtr<nsIExceptionService> xs =
3246
+ do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
3247
+ if(xs)
3248
+ xs->GetCurrentExceptionManager(&mExceptionManager);
3249
+ if(mExceptionManager)
3250
+ return JS_TRUE;
3251
+
3252
+ mExceptionManagerNotAvailable = JS_TRUE;
3253
+ return JS_FALSE;
3254
+ }
3255
+
3256
+ XPCJSContextStack* GetJSContextStack() {return mJSContextStack;}
3257
+
3258
+ XPCCallContext* GetCallContext() const {return mCallContext;}
3259
+ XPCCallContext* SetCallContext(XPCCallContext* ccx)
3260
+ {XPCCallContext* old = mCallContext; mCallContext = ccx; return old;}
3261
+
3262
+ jsval GetResolveName() const {return mResolveName;}
3263
+ jsval SetResolveName(jsval name)
3264
+ {jsval old = mResolveName; mResolveName = name; return old;}
3265
+
3266
+ XPCWrappedNative* GetResolvingWrapper() const {return mResolvingWrapper;}
3267
+ XPCWrappedNative* SetResolvingWrapper(XPCWrappedNative* w)
3268
+ {XPCWrappedNative* old = mResolvingWrapper;
3269
+ mResolvingWrapper = w; return old;}
3270
+
3271
+ void Cleanup();
3272
+ void ReleaseNatives();
3273
+
3274
+ PRBool IsValid() const {return mJSContextStack != nsnull;}
3275
+
3276
+ static PRLock* GetLock() {return gLock;}
3277
+ // Must be called with the threads locked.
3278
+ static XPCPerThreadData* IterateThreads(XPCPerThreadData** iteratorp);
3279
+
3280
+ AutoMarkingPtr** GetAutoRootsAdr() {return &mAutoRoots;}
3281
+
3282
+ void TraceJS(JSTracer* trc);
3283
+ void MarkAutoRootsAfterJSFinalize();
3284
+
3285
+ jsuword GetStackLimit() const { return mStackLimit; }
3286
+
3287
+ static void InitStatics()
3288
+ { gLock = nsnull; gThreads = nsnull; gTLSIndex = BAD_TLS_INDEX; }
3289
+
3290
+ #ifdef XPC_CHECK_WRAPPER_THREADSAFETY
3291
+ JSUint32 IncrementWrappedNativeThreadsafetyReportDepth()
3292
+ {return ++mWrappedNativeThreadsafetyReportDepth;}
3293
+ void ClearWrappedNativeThreadsafetyReportDepth()
3294
+ {mWrappedNativeThreadsafetyReportDepth = 0;}
3295
+ #endif
3296
+
3297
+ static void ShutDown()
3298
+ {sMainJSThread = nsnull; sMainThreadData = nsnull;}
3299
+
3300
+ static PRBool IsMainThread(JSContext *cx)
3301
+ { return cx->thread == sMainJSThread; }
3302
+
3303
+ private:
3304
+ XPCPerThreadData();
3305
+ static XPCPerThreadData* GetDataImpl(JSContext *cx);
3306
+
3307
+ private:
3308
+ XPCJSContextStack* mJSContextStack;
3309
+ XPCPerThreadData* mNextThread;
3310
+ XPCCallContext* mCallContext;
3311
+ jsval mResolveName;
3312
+ XPCWrappedNative* mResolvingWrapper;
3313
+
3314
+ nsIExceptionManager* mExceptionManager;
3315
+ nsIException* mException;
3316
+ JSBool mExceptionManagerNotAvailable;
3317
+ AutoMarkingPtr* mAutoRoots;
3318
+
3319
+ jsuword mStackLimit;
3320
+
3321
+ #ifdef XPC_CHECK_WRAPPER_THREADSAFETY
3322
+ JSUint32 mWrappedNativeThreadsafetyReportDepth;
3323
+ #endif
3324
+ PRThread* mThread;
3325
+
3326
+ static PRLock* gLock;
3327
+ static XPCPerThreadData* gThreads;
3328
+ static PRUintn gTLSIndex;
3329
+
3330
+ // Cached value of cx->thread on the main thread.
3331
+ static void *sMainJSThread;
3332
+
3333
+ // Cached per thread data for the main thread. Only safe to access
3334
+ // if cx->thread == sMainJSThread.
3335
+ static XPCPerThreadData *sMainThreadData;
3336
+ };
3337
+
3338
+ /***************************************************************************/
3339
+ #ifndef XPCONNECT_STANDALONE
3340
+ #include "nsIScriptSecurityManager.h"
3341
+
3342
+ class BackstagePass : public nsIScriptObjectPrincipal,
3343
+ public nsIXPCScriptable,
3344
+ public nsIClassInfo
3345
+ {
3346
+ public:
3347
+ NS_DECL_ISUPPORTS
3348
+ NS_DECL_NSIXPCSCRIPTABLE
3349
+ NS_DECL_NSICLASSINFO
3350
+
3351
+ virtual nsIPrincipal* GetPrincipal() {
3352
+ return mPrincipal;
3353
+ }
3354
+
3355
+ BackstagePass(nsIPrincipal *prin) :
3356
+ mPrincipal(prin)
3357
+ {
3358
+ }
3359
+
3360
+ virtual ~BackstagePass() { }
3361
+
3362
+ private:
3363
+ nsCOMPtr<nsIPrincipal> mPrincipal;
3364
+ };
3365
+
3366
+ #else
3367
+
3368
+ class BackstagePass : public nsIXPCScriptable, public nsIClassInfo
3369
+ {
3370
+ public:
3371
+ NS_DECL_ISUPPORTS
3372
+ NS_DECL_NSIXPCSCRIPTABLE
3373
+ NS_DECL_NSICLASSINFO
3374
+
3375
+ BackstagePass()
3376
+ {
3377
+ }
3378
+
3379
+ virtual ~BackstagePass() { }
3380
+ };
3381
+
3382
+ #endif
3383
+
3384
+ class nsJSRuntimeServiceImpl : public nsIJSRuntimeService,
3385
+ public nsSupportsWeakReference
3386
+ {
3387
+ public:
3388
+ NS_DECL_ISUPPORTS
3389
+ NS_DECL_NSIJSRUNTIMESERVICE
3390
+
3391
+ // This returns an AddRef'd pointer. It does not do this with an out param
3392
+ // only because this form is required by generic module macro:
3393
+ // NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR
3394
+ static nsJSRuntimeServiceImpl* GetSingleton();
3395
+
3396
+ static void FreeSingleton();
3397
+
3398
+ nsJSRuntimeServiceImpl();
3399
+ virtual ~nsJSRuntimeServiceImpl();
3400
+
3401
+ static void InitStatics() { gJSRuntimeService = nsnull; }
3402
+ protected:
3403
+ static nsJSRuntimeServiceImpl* gJSRuntimeService;
3404
+ nsCOMPtr<nsIXPCScriptable> mBackstagePass;
3405
+ };
3406
+
3407
+ /***************************************************************************/
3408
+ // 'Components' object
3409
+
3410
+ class nsXPCComponents : public nsIXPCComponents,
3411
+ public nsIXPCScriptable,
3412
+ public nsIClassInfo
3413
+ #ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
3414
+ , public nsISecurityCheckedComponent
3415
+ #endif
3416
+ {
3417
+ public:
3418
+ NS_DECL_ISUPPORTS
3419
+ NS_DECL_NSIXPCCOMPONENTS
3420
+ NS_DECL_NSIXPCSCRIPTABLE
3421
+ NS_DECL_NSICLASSINFO
3422
+
3423
+ #ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
3424
+ NS_DECL_NSISECURITYCHECKEDCOMPONENT
3425
+ #endif
3426
+
3427
+ public:
3428
+ static JSBool
3429
+ AttachNewComponentsObject(XPCCallContext& ccx,
3430
+ XPCWrappedNativeScope* aScope,
3431
+ JSObject* aGlobal);
3432
+
3433
+ void SystemIsBeingShutDown() {ClearMembers();}
3434
+
3435
+ virtual ~nsXPCComponents();
3436
+
3437
+ private:
3438
+ nsXPCComponents();
3439
+ void ClearMembers();
3440
+
3441
+ private:
3442
+ nsXPCComponents_Interfaces* mInterfaces;
3443
+ nsXPCComponents_InterfacesByID* mInterfacesByID;
3444
+ nsXPCComponents_Classes* mClasses;
3445
+ nsXPCComponents_ClassesByID* mClassesByID;
3446
+ nsXPCComponents_Results* mResults;
3447
+ nsXPCComponents_ID* mID;
3448
+ nsXPCComponents_Exception* mException;
3449
+ nsXPCComponents_Constructor* mConstructor;
3450
+ nsXPCComponents_Utils* mUtils;
3451
+ };
3452
+
3453
+ /***************************************************************************/
3454
+
3455
+ class nsXPCComponents_Interfaces :
3456
+ public nsIScriptableInterfaces,
3457
+ public nsIXPCScriptable,
3458
+ public nsIClassInfo
3459
+ #ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
3460
+ , public nsISecurityCheckedComponent
3461
+ #endif
3462
+ {
3463
+ public:
3464
+ // all the interface method declarations...
3465
+ NS_DECL_ISUPPORTS
3466
+ NS_DECL_NSISCRIPTABLEINTERFACES
3467
+ NS_DECL_NSIXPCSCRIPTABLE
3468
+ NS_DECL_NSICLASSINFO
3469
+ #ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
3470
+ NS_DECL_NSISECURITYCHECKEDCOMPONENT
3471
+ #endif
3472
+
3473
+ public:
3474
+ nsXPCComponents_Interfaces();
3475
+ virtual ~nsXPCComponents_Interfaces();
3476
+
3477
+ private:
3478
+ nsCOMPtr<nsIInterfaceInfoManager> mManager;
3479
+ };
3480
+
3481
+
3482
+ /***************************************************************************/
3483
+
3484
+ extern JSObject*
3485
+ xpc_NewIDObject(JSContext *cx, JSObject* jsobj, const nsID& aID);
3486
+
3487
+ extern const nsID*
3488
+ xpc_JSObjectToID(JSContext *cx, JSObject* obj);
3489
+
3490
+ extern JSBool
3491
+ xpc_JSObjectIsID(JSContext *cx, JSObject* obj);
3492
+
3493
+ /***************************************************************************/
3494
+ // in xpcdebug.cpp
3495
+
3496
+ extern JSBool
3497
+ xpc_DumpJSStack(JSContext* cx, JSBool showArgs, JSBool showLocals,
3498
+ JSBool showThisProps);
3499
+
3500
+ extern JSBool
3501
+ xpc_DumpEvalInJSStackFrame(JSContext* cx, JSUint32 frameno, const char* text);
3502
+
3503
+ extern JSBool
3504
+ xpc_DumpJSObject(JSObject* obj);
3505
+
3506
+ extern JSBool
3507
+ xpc_InstallJSDebuggerKeywordHandler(JSRuntime* rt);
3508
+
3509
+ /***************************************************************************/
3510
+
3511
+ // Definition of nsScriptError, defined here because we lack a place to put
3512
+ // XPCOM objects associated with the JavaScript engine.
3513
+ class nsScriptError : public nsIScriptError {
3514
+ public:
3515
+ nsScriptError();
3516
+
3517
+ virtual ~nsScriptError();
3518
+
3519
+ // TODO - do something reasonable on getting null from these babies.
3520
+
3521
+ NS_DECL_ISUPPORTS
3522
+ NS_DECL_NSICONSOLEMESSAGE
3523
+ NS_DECL_NSISCRIPTERROR
3524
+
3525
+ private:
3526
+ nsString mMessage;
3527
+ nsString mSourceName;
3528
+ PRUint32 mLineNumber;
3529
+ nsString mSourceLine;
3530
+ PRUint32 mColumnNumber;
3531
+ PRUint32 mFlags;
3532
+ nsCString mCategory;
3533
+ };
3534
+
3535
+ /***************************************************************************/
3536
+ // XXX allowing for future notifications to XPCCallContext
3537
+
3538
+ class AutoJSRequest
3539
+ {
3540
+ public:
3541
+ AutoJSRequest(XPCCallContext& aCCX)
3542
+ : mCCX(aCCX), mCX(aCCX.GetJSContext()) {BeginRequest();}
3543
+ ~AutoJSRequest() {EndRequest();}
3544
+
3545
+ void EndRequest() {
3546
+ if(mCX) {
3547
+ JS_EndRequest(mCX);
3548
+ mCX = nsnull;
3549
+ }
3550
+ }
3551
+ private:
3552
+ void BeginRequest() {
3553
+ if(JS_GetContextThread(mCX))
3554
+ JS_BeginRequest(mCX);
3555
+ else
3556
+ mCX = nsnull;
3557
+ }
3558
+ private:
3559
+ XPCCallContext& mCCX;
3560
+ JSContext* mCX;
3561
+ };
3562
+
3563
+ class AutoJSSuspendRequest
3564
+ {
3565
+ public:
3566
+ AutoJSSuspendRequest(XPCCallContext& aCCX)
3567
+ : mCX(aCCX.GetJSContext()) {SuspendRequest();}
3568
+ ~AutoJSSuspendRequest() {ResumeRequest();}
3569
+
3570
+ void ResumeRequest() {
3571
+ if(mCX) {
3572
+ JS_ResumeRequest(mCX, mDepth);
3573
+ mCX = nsnull;
3574
+ }
3575
+ }
3576
+ private:
3577
+ void SuspendRequest() {
3578
+ if(JS_GetContextThread(mCX))
3579
+ mDepth = JS_SuspendRequest(mCX);
3580
+ else
3581
+ mCX = nsnull;
3582
+ }
3583
+ private:
3584
+ JSContext* mCX;
3585
+ jsrefcount mDepth;
3586
+ };
3587
+
3588
+ class AutoJSSuspendRequestWithNoCallContext
3589
+ {
3590
+ public:
3591
+ AutoJSSuspendRequestWithNoCallContext(JSContext *aCX)
3592
+ : mCX(aCX) {SuspendRequest();}
3593
+ ~AutoJSSuspendRequestWithNoCallContext() {ResumeRequest();}
3594
+
3595
+ void ResumeRequest() {
3596
+ if(mCX) {
3597
+ JS_ResumeRequest(mCX, mDepth);
3598
+ mCX = nsnull;
3599
+ }
3600
+ }
3601
+ private:
3602
+ void SuspendRequest() {
3603
+ if(JS_GetContextThread(mCX))
3604
+ mDepth = JS_SuspendRequest(mCX);
3605
+ else
3606
+ mCX = nsnull;
3607
+ }
3608
+ private:
3609
+ JSContext* mCX;
3610
+ jsrefcount mDepth;
3611
+ };
3612
+
3613
+ class AutoJSSuspendNonMainThreadRequest
3614
+ {
3615
+ public:
3616
+ AutoJSSuspendNonMainThreadRequest(JSContext *aCX)
3617
+ : mCX(aCX) {SuspendRequest();}
3618
+ ~AutoJSSuspendNonMainThreadRequest() {ResumeRequest();}
3619
+
3620
+ void ResumeRequest() {
3621
+ if (mCX) {
3622
+ JS_ResumeRequest(mCX, mDepth);
3623
+ mCX = nsnull;
3624
+ }
3625
+ }
3626
+
3627
+ private:
3628
+ void SuspendRequest() {
3629
+ if (mCX && !XPCPerThreadData::IsMainThread(mCX))
3630
+ mDepth = JS_SuspendRequest(mCX);
3631
+ else
3632
+ mCX = nsnull;
3633
+ }
3634
+
3635
+ JSContext *mCX;
3636
+ jsrefcount mDepth;
3637
+ };
3638
+
3639
+
3640
+ /*****************************************/
3641
+
3642
+ class AutoJSRequestWithNoCallContext
3643
+ {
3644
+ public:
3645
+ AutoJSRequestWithNoCallContext(JSContext* aCX) : mCX(aCX) {BeginRequest();}
3646
+ ~AutoJSRequestWithNoCallContext() {EndRequest();}
3647
+
3648
+ void EndRequest() {
3649
+ if(mCX) {
3650
+ JS_EndRequest(mCX);
3651
+ mCX = nsnull;
3652
+ }
3653
+ }
3654
+ private:
3655
+ void BeginRequest() {
3656
+ if(JS_GetContextThread(mCX))
3657
+ JS_BeginRequest(mCX);
3658
+ else
3659
+ mCX = nsnull;
3660
+ }
3661
+ private:
3662
+ JSContext* mCX;
3663
+ };
3664
+
3665
+ /***************************************************************************/
3666
+ class AutoJSErrorAndExceptionEater
3667
+ {
3668
+ public:
3669
+ AutoJSErrorAndExceptionEater(JSContext* aCX)
3670
+ : mCX(aCX),
3671
+ mOldErrorReporter(JS_SetErrorReporter(mCX, nsnull)),
3672
+ mOldExceptionState(JS_SaveExceptionState(mCX)) {}
3673
+ ~AutoJSErrorAndExceptionEater()
3674
+ {
3675
+ JS_SetErrorReporter(mCX, mOldErrorReporter);
3676
+ JS_RestoreExceptionState(mCX, mOldExceptionState);
3677
+ }
3678
+ private:
3679
+ JSContext* mCX;
3680
+ JSErrorReporter mOldErrorReporter;
3681
+ JSExceptionState* mOldExceptionState;
3682
+ };
3683
+
3684
+ /******************************************************************************
3685
+ * Handles pre/post script processing and the setting/resetting the error
3686
+ * reporter
3687
+ */
3688
+ class AutoScriptEvaluate
3689
+ {
3690
+ public:
3691
+ /**
3692
+ * Saves the JSContext as well as initializing our state
3693
+ * @param cx The JSContext, this can be null, we don't do anything then
3694
+ */
3695
+ AutoScriptEvaluate(JSContext * cx)
3696
+ : mJSContext(cx), mState(0), mErrorReporterSet(PR_FALSE),
3697
+ mEvaluated(PR_FALSE), mContextHasThread(0) {}
3698
+
3699
+ /**
3700
+ * Does the pre script evaluation and sets the error reporter if given
3701
+ * This function should only be called once, and will assert if called
3702
+ * more than once
3703
+ * @param errorReporter the error reporter callback function to set
3704
+ */
3705
+
3706
+ void StartEvaluating(JSErrorReporter errorReporter = nsnull);
3707
+ /**
3708
+ * Does the post script evaluation and resets the error reporter
3709
+ */
3710
+ ~AutoScriptEvaluate();
3711
+ private:
3712
+ JSContext* mJSContext;
3713
+ JSExceptionState* mState;
3714
+ PRBool mErrorReporterSet;
3715
+ PRBool mEvaluated;
3716
+ jsword mContextHasThread;
3717
+
3718
+ // No copying or assignment allowed
3719
+ AutoScriptEvaluate(const AutoScriptEvaluate &);
3720
+ AutoScriptEvaluate & operator =(const AutoScriptEvaluate &);
3721
+ };
3722
+
3723
+ /***************************************************************************/
3724
+ class AutoResolveName
3725
+ {
3726
+ public:
3727
+ AutoResolveName(XPCCallContext& ccx, jsval name)
3728
+ : mTLS(ccx.GetThreadData()),
3729
+ mOld(mTLS->SetResolveName(name)),
3730
+ mCheck(name) {}
3731
+ ~AutoResolveName()
3732
+ {
3733
+ #ifdef DEBUG
3734
+ jsval old =
3735
+ #endif
3736
+ mTLS->SetResolveName(mOld);
3737
+ NS_ASSERTION(old == mCheck, "Bad Nesting!");
3738
+ }
3739
+
3740
+ private:
3741
+ XPCPerThreadData* mTLS;
3742
+ jsval mOld;
3743
+ jsval mCheck;
3744
+ };
3745
+
3746
+ /***************************************************************************/
3747
+ class XPCMarkableJSVal
3748
+ {
3749
+ public:
3750
+ XPCMarkableJSVal(jsval val) : mVal(val), mValPtr(&mVal) {}
3751
+ XPCMarkableJSVal(jsval *pval) : mVal(0), mValPtr(pval) {}
3752
+ ~XPCMarkableJSVal() {}
3753
+ void Mark() {}
3754
+ void TraceJS(JSTracer* trc)
3755
+ {
3756
+ JS_CALL_VALUE_TRACER(trc, *mValPtr, "XPCMarkableJSVal");
3757
+ }
3758
+ void AutoTrace(JSTracer* trc) {}
3759
+ private:
3760
+ XPCMarkableJSVal(); // not implemented
3761
+ jsval mVal;
3762
+ jsval* mValPtr;
3763
+ };
3764
+
3765
+ /***************************************************************************/
3766
+ // AutoMarkingPtr is the base class for the various AutoMarking pointer types
3767
+ // below. This system allows us to temporarily protect instances of our garbage
3768
+ // collected types after they are constructed but before they are safely
3769
+ // attached to other rooted objects.
3770
+ // This base class has pure virtual support for marking.
3771
+
3772
+ class AutoMarkingPtr
3773
+ {
3774
+ public:
3775
+ AutoMarkingPtr(XPCCallContext& ccx)
3776
+ : mNext(nsnull), mTLS(ccx.GetThreadData()) {Link();}
3777
+
3778
+ virtual ~AutoMarkingPtr() {Unlink();}
3779
+
3780
+ void Link()
3781
+ {if(!mTLS) return;
3782
+ AutoMarkingPtr** list = mTLS->GetAutoRootsAdr();
3783
+ mNext = *list; *list = this;}
3784
+
3785
+ void Unlink()
3786
+ {if(!mTLS) return;
3787
+ AutoMarkingPtr** cur = mTLS->GetAutoRootsAdr();
3788
+ while(*cur != this) {
3789
+ NS_ASSERTION(*cur, "This object not in list!");
3790
+ cur = &(*cur)->mNext;
3791
+ }
3792
+ *cur = mNext;
3793
+ mTLS = nsnull;
3794
+ }
3795
+
3796
+ AutoMarkingPtr* GetNext() {return mNext;}
3797
+
3798
+ virtual void TraceJS(JSTracer* trc) = 0;
3799
+ virtual void MarkAfterJSFinalize() = 0;
3800
+
3801
+ protected:
3802
+ AutoMarkingPtr* mNext;
3803
+ XPCPerThreadData* mTLS;
3804
+ };
3805
+
3806
+ // More joy of macros...
3807
+
3808
+ #define DEFINE_AUTO_MARKING_PTR_TYPE(class_, type_) \
3809
+ class class_ : public AutoMarkingPtr \
3810
+ { \
3811
+ public: \
3812
+ class_ (XPCCallContext& ccx, type_ * ptr = nsnull) \
3813
+ : AutoMarkingPtr(ccx), mPtr(ptr) {} \
3814
+ virtual ~ class_ () {} \
3815
+ \
3816
+ virtual void TraceJS(JSTracer* trc) \
3817
+ {if(mPtr) { \
3818
+ mPtr->TraceJS(trc); \
3819
+ mPtr->AutoTrace(trc); \
3820
+ } \
3821
+ if(mNext) mNext->TraceJS(trc);} \
3822
+ \
3823
+ virtual void MarkAfterJSFinalize() \
3824
+ {if(mPtr) mPtr->Mark(); \
3825
+ if(mNext) mNext->MarkAfterJSFinalize();} \
3826
+ \
3827
+ type_ * get() const {return mPtr;} \
3828
+ operator type_ *() const {return mPtr;} \
3829
+ type_ * operator->() const {return mPtr;} \
3830
+ \
3831
+ class_ & operator =(type_ * p) \
3832
+ {mPtr = p; return *this;} \
3833
+ \
3834
+ protected: \
3835
+ type_ * mPtr; \
3836
+ };
3837
+
3838
+ // Use the macro above to define our AutoMarking types...
3839
+
3840
+ DEFINE_AUTO_MARKING_PTR_TYPE(AutoMarkingNativeInterfacePtr, XPCNativeInterface)
3841
+ DEFINE_AUTO_MARKING_PTR_TYPE(AutoMarkingNativeSetPtr, XPCNativeSet)
3842
+ DEFINE_AUTO_MARKING_PTR_TYPE(AutoMarkingWrappedNativePtr, XPCWrappedNative)
3843
+ DEFINE_AUTO_MARKING_PTR_TYPE(AutoMarkingWrappedNativeTearOffPtr, XPCWrappedNativeTearOff)
3844
+ DEFINE_AUTO_MARKING_PTR_TYPE(AutoMarkingWrappedNativeProtoPtr, XPCWrappedNativeProto)
3845
+ DEFINE_AUTO_MARKING_PTR_TYPE(AutoMarkingJSVal, XPCMarkableJSVal)
3846
+
3847
+ #define DEFINE_AUTO_MARKING_ARRAY_PTR_TYPE(class_, type_) \
3848
+ class class_ : public AutoMarkingPtr \
3849
+ { \
3850
+ public: \
3851
+ class_ (XPCCallContext& ccx) \
3852
+ : AutoMarkingPtr(ccx), mPtr(nsnull), mCount(0) {} \
3853
+ class_ (XPCCallContext& ccx, type_** aPtr, PRUint32 aCount, \
3854
+ PRBool aClear = PR_FALSE) \
3855
+ : AutoMarkingPtr(ccx), mPtr(aPtr), mCount(aCount) \
3856
+ { \
3857
+ if(!mPtr) mCount = 0; \
3858
+ else if(aClear) memset(mPtr, 0, mCount*sizeof(type_*)); \
3859
+ } \
3860
+ virtual ~ class_ () {} \
3861
+ \
3862
+ virtual void TraceJS(JSTracer* trc) \
3863
+ { \
3864
+ for(PRUint32 i = 0; i < mCount; ++i) \
3865
+ { \
3866
+ type_* cur = mPtr[i]; \
3867
+ if(cur) \
3868
+ { \
3869
+ cur->TraceJS(trc); \
3870
+ cur->AutoTrace(trc); \
3871
+ } \
3872
+ } \
3873
+ if(mNext) mNext->TraceJS(trc); \
3874
+ } \
3875
+ \
3876
+ virtual void MarkAfterJSFinalize() \
3877
+ { \
3878
+ for(PRUint32 i = 0; i < mCount; ++i) \
3879
+ { \
3880
+ type_* cur = mPtr[i]; \
3881
+ if(cur) \
3882
+ cur->Mark(); \
3883
+ } \
3884
+ if(mNext) mNext->MarkAfterJSFinalize(); \
3885
+ } \
3886
+ \
3887
+ type_ ** get() const {return mPtr;} \
3888
+ operator type_ **() const {return mPtr;} \
3889
+ type_ ** operator->() const {return mPtr;} \
3890
+ \
3891
+ class_ & operator =(const class_ & inst) \
3892
+ {mPtr = inst.mPtr; mCount = inst.mCount; return *this;} \
3893
+ \
3894
+ protected: \
3895
+ type_ ** mPtr; \
3896
+ PRUint32 mCount; \
3897
+ };
3898
+
3899
+ DEFINE_AUTO_MARKING_ARRAY_PTR_TYPE(AutoMarkingNativeInterfacePtrArrayPtr,
3900
+ XPCNativeInterface)
3901
+
3902
+ // Note: It looked like I would need one of these AutoMarkingPtr types for
3903
+ // XPCNativeScriptableInfo in order to manage marking its
3904
+ // XPCNativeScriptableShared member during construction. But AFAICT we build
3905
+ // these and bind them to rooted things so immediately that this just is not
3906
+ // needed.
3907
+
3908
+ #define AUTO_MARK_JSVAL_HELPER2(tok, line) tok##line
3909
+ #define AUTO_MARK_JSVAL_HELPER(tok, line) AUTO_MARK_JSVAL_HELPER2(tok, line)
3910
+
3911
+ #define AUTO_MARK_JSVAL(ccx, val) \
3912
+ XPCMarkableJSVal AUTO_MARK_JSVAL_HELPER(_val_,__LINE__)(val); \
3913
+ AutoMarkingJSVal AUTO_MARK_JSVAL_HELPER(_automarker_,__LINE__) \
3914
+ (ccx, &AUTO_MARK_JSVAL_HELPER(_val_,__LINE__))
3915
+
3916
+ #ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
3917
+ /***************************************************************************/
3918
+ // Allocates a string that grants all access ("AllAccess")
3919
+
3920
+ extern char* xpc_CloneAllAccess();
3921
+ /***************************************************************************/
3922
+ // Returns access if wideName is in list
3923
+
3924
+ extern char * xpc_CheckAccessList(const PRUnichar* wideName, const char* list[]);
3925
+ #endif
3926
+
3927
+ /***************************************************************************/
3928
+ // in xpcvariant.cpp...
3929
+
3930
+ // {1809FD50-91E8-11d5-90F9-0010A4E73D9A}
3931
+ #define XPCVARIANT_IID \
3932
+ {0x1809fd50, 0x91e8, 0x11d5, \
3933
+ { 0x90, 0xf9, 0x0, 0x10, 0xa4, 0xe7, 0x3d, 0x9a } }
3934
+
3935
+ class XPCVariant : public nsIVariant
3936
+ {
3937
+ public:
3938
+ NS_DECL_CYCLE_COLLECTING_ISUPPORTS
3939
+ NS_DECL_NSIVARIANT
3940
+ NS_DECL_CYCLE_COLLECTION_CLASS(XPCVariant)
3941
+
3942
+ // If this class ever implements nsIWritableVariant, take special care with
3943
+ // the case when mJSVal is JSVAL_STRING, since we don't own the data in
3944
+ // that case.
3945
+
3946
+ // We #define and iid so that out module local code can use QI to detect
3947
+ // if a given nsIVariant is in fact an XPCVariant.
3948
+ NS_DECLARE_STATIC_IID_ACCESSOR(XPCVARIANT_IID)
3949
+
3950
+ static XPCVariant* newVariant(XPCCallContext& ccx, jsval aJSVal);
3951
+
3952
+ jsval GetJSVal() const {return mJSVal;}
3953
+
3954
+ XPCVariant(XPCCallContext& ccx, jsval aJSVal);
3955
+
3956
+ /**
3957
+ * Convert a variant into a jsval.
3958
+ *
3959
+ * @param ccx the context for the whole procedure
3960
+ * @param variant the variant to convert
3961
+ * @param scope the default scope to put on the new JSObject's __parent__
3962
+ * chain
3963
+ * @param pErr [out] relevant error code, if any.
3964
+ * @param pJSVal [out] the resulting jsval.
3965
+ */
3966
+ static JSBool VariantDataToJS(XPCCallContext& ccx,
3967
+ nsIVariant* variant,
3968
+ JSObject* scope, nsresult* pErr,
3969
+ jsval* pJSVal);
3970
+
3971
+ protected:
3972
+ virtual ~XPCVariant() { }
3973
+
3974
+ JSBool InitializeData(XPCCallContext& ccx);
3975
+
3976
+ protected:
3977
+ nsDiscriminatedUnion mData;
3978
+ jsval mJSVal;
3979
+ JSBool mReturnRawObject;
3980
+ };
3981
+
3982
+ NS_DEFINE_STATIC_IID_ACCESSOR(XPCVariant, XPCVARIANT_IID)
3983
+
3984
+ class XPCTraceableVariant: public XPCVariant,
3985
+ public XPCRootSetElem
3986
+ {
3987
+ public:
3988
+ XPCTraceableVariant(XPCCallContext& ccx, jsval aJSVal)
3989
+ : XPCVariant(ccx, aJSVal)
3990
+ {
3991
+ ccx.GetRuntime()->AddVariantRoot(this);
3992
+ }
3993
+
3994
+ virtual ~XPCTraceableVariant();
3995
+
3996
+ void TraceJS(JSTracer* trc);
3997
+ #ifdef DEBUG
3998
+ static void PrintTraceName(JSTracer* trc, char *buf, size_t bufsize);
3999
+ #endif
4000
+ };
4001
+
4002
+ /***************************************************************************/
4003
+ #ifndef XPCONNECT_STANDALONE
4004
+
4005
+ #define PRINCIPALHOLDER_IID \
4006
+ {0xbf109f49, 0xf94a, 0x43d8, {0x93, 0xdb, 0xe4, 0x66, 0x49, 0xc5, 0xd9, 0x7d}}
4007
+
4008
+ class PrincipalHolder : public nsIScriptObjectPrincipal
4009
+ {
4010
+ public:
4011
+ NS_DECLARE_STATIC_IID_ACCESSOR(PRINCIPALHOLDER_IID)
4012
+
4013
+ PrincipalHolder(nsIPrincipal *holdee)
4014
+ : mHoldee(holdee)
4015
+ {
4016
+ }
4017
+ virtual ~PrincipalHolder() { }
4018
+
4019
+ NS_DECL_ISUPPORTS
4020
+
4021
+ nsIPrincipal *GetPrincipal();
4022
+
4023
+ private:
4024
+ nsCOMPtr<nsIPrincipal> mHoldee;
4025
+ };
4026
+
4027
+ NS_DEFINE_STATIC_IID_ACCESSOR(PrincipalHolder, PRINCIPALHOLDER_IID)
4028
+
4029
+ #endif /* !XPCONNECT_STANDALONE */
4030
+
4031
+ /***************************************************************************/
4032
+ // Utilities
4033
+
4034
+ inline void *
4035
+ xpc_GetJSPrivate(JSObject *obj)
4036
+ {
4037
+ jsval v;
4038
+
4039
+ JS_ASSERT(STOBJ_GET_CLASS(obj)->flags & JSCLASS_HAS_PRIVATE);
4040
+ v = obj->fslots[JSSLOT_PRIVATE];
4041
+ if (!JSVAL_IS_INT(v))
4042
+ return NULL;
4043
+ return JSVAL_TO_PRIVATE(v);
4044
+ }
4045
+
4046
+ #ifndef XPCONNECT_STANDALONE
4047
+
4048
+ // Helper for creating a sandbox object to use for evaluating
4049
+ // untrusted code completely separated from all other code in the
4050
+ // system using xpc_EvalInSandbox(). Takes the JSContext on which to
4051
+ // do setup etc on, puts the sandbox object in *vp (which must be
4052
+ // rooted by the caller), and uses the principal that's either
4053
+ // directly passed in prinOrSop or indirectly as an
4054
+ // nsIScriptObjectPrincipal holding the principal. If no principal is
4055
+ // reachable through prinOrSop, a new null principal will be created
4056
+ // and used.
4057
+ nsresult
4058
+ xpc_CreateSandboxObject(JSContext * cx, jsval * vp, nsISupports *prinOrSop);
4059
+
4060
+ // Helper for evaluating scripts in a sandbox object created with
4061
+ // xpc_CreateSandboxObject(). The caller is responsible of ensuring
4062
+ // that *rval doesn't get collected during the call or usage after the
4063
+ // call. This helper will use filename and lineNo for error reporting,
4064
+ // and if no filename is provided it will use the codebase from the
4065
+ // principal and line number 1 as a fallback. if returnStringOnly is
4066
+ // true, then the result in *rval, or the exception in cx->exception
4067
+ // will be coerced into strings. If an exception is thrown converting
4068
+ // an exception to a string, evalInSandbox will return an NS_ERROR_*
4069
+ // result, and cx->exception will be empty.
4070
+ nsresult
4071
+ xpc_EvalInSandbox(JSContext *cx, JSObject *sandbox, const nsAString& source,
4072
+ const char *filename, PRInt32 lineNo,
4073
+ JSVersion jsVersion, PRBool returnStringOnly, jsval *rval);
4074
+ #endif /* !XPCONNECT_STANDALONE */
4075
+
4076
+ /***************************************************************************/
4077
+ // Inlined utilities.
4078
+
4079
+ inline JSBool
4080
+ xpc_ForcePropertyResolve(JSContext* cx, JSObject* obj, jsval idval);
4081
+
4082
+ inline jsval
4083
+ GetRTStringByIndex(JSContext *cx, uintN index);
4084
+
4085
+ // Wrapper for JS_NewObject to mark the new object as system when parent is
4086
+ // also a system object.
4087
+ inline JSObject*
4088
+ xpc_NewSystemInheritingJSObject(JSContext *cx, JSClass *clasp, JSObject *proto,
4089
+ JSObject *parent);
4090
+
4091
+ inline JSBool
4092
+ xpc_SameScope(XPCWrappedNativeScope *objectscope,
4093
+ XPCWrappedNativeScope *xpcscope,
4094
+ JSBool *sameOrigin);
4095
+
4096
+ nsISupports *
4097
+ XPC_GetIdentityObject(JSContext *cx, JSObject *obj);
4098
+
4099
+ PRBool
4100
+ IsXPCSafeJSObjectWrapperClass(JSClass *clazz);
4101
+
4102
+ JSObject *
4103
+ XPC_SJOW_GetUnsafeObject(JSObject *obj);
4104
+
4105
+ JSBool
4106
+ XPC_SJOW_Construct(JSContext *cx, JSObject *obj, uintN, jsval *argv,
4107
+ jsval *rval);
4108
+
4109
+ PRBool
4110
+ XPC_SJOW_AttachNewConstructorObject(XPCCallContext &ccx,
4111
+ JSObject *aGlobalObject);
4112
+
4113
+ JSBool
4114
+ XPC_XOW_WrapObject(JSContext *cx, JSObject *parent, jsval *vp,
4115
+ XPCWrappedNative *wn = nsnull);
4116
+
4117
+ JSBool
4118
+ XPC_SOW_WrapObject(JSContext *cx, JSObject *parent, jsval v,
4119
+ jsval *vp);
4120
+
4121
+ #ifdef XPC_IDISPATCH_SUPPORT
4122
+ // IDispatch specific classes
4123
+ #include "XPCDispPrivate.h"
4124
+ #endif
4125
+
4126
+ /***************************************************************************/
4127
+ // Inlines use the above - include last.
4128
+
4129
+ #include "xpcinlines.h"
4130
+
4131
+ /***************************************************************************/
4132
+ // Maps have inlines that use the above - include last.
4133
+
4134
+ #include "xpcmaps.h"
4135
+
4136
+ /***************************************************************************/
4137
+
4138
+ #endif /* xpcprivate_h___ */