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,2609 @@
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
+ * Pierre Phaneuf <pp@ludusdesign.com>
27
+ * Nate Nielsen <nielsen@memberwebs.com>
28
+ *
29
+ * Alternatively, the contents of this file may be used under the terms of
30
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
31
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32
+ * in which case the provisions of the GPL or the LGPL are applicable instead
33
+ * of those above. If you wish to allow use of your version of this file only
34
+ * under the terms of either the GPL or the LGPL, and not to allow others to
35
+ * use your version of this file under the terms of the MPL, indicate your
36
+ * decision by deleting the provisions above and replace them with the notice
37
+ * and other provisions required by the GPL or the LGPL. If you do not delete
38
+ * the provisions above, a recipient may use your version of this file under
39
+ * the terms of any one of the MPL, the GPL or the LGPL.
40
+ *
41
+ * ***** END LICENSE BLOCK ***** */
42
+
43
+ /* High level class and public functions implementation. */
44
+
45
+ #include "xpcprivate.h"
46
+ #include "XPCNativeWrapper.h"
47
+ #include "XPCWrapper.h"
48
+ #include "nsBaseHashtable.h"
49
+ #include "nsHashKeys.h"
50
+ #include "jsatom.h"
51
+ #include "jsfun.h"
52
+ #include "jsscript.h"
53
+ #include "nsThreadUtilsInternal.h"
54
+ #include "dom_quickstubs.h"
55
+
56
+ NS_IMPL_THREADSAFE_ISUPPORTS6(nsXPConnect,
57
+ nsIXPConnect,
58
+ nsISupportsWeakReference,
59
+ nsIThreadObserver,
60
+ nsIJSRuntimeService,
61
+ nsIJSContextStack,
62
+ nsIThreadJSContextStack)
63
+
64
+ nsXPConnect* nsXPConnect::gSelf = nsnull;
65
+ JSBool nsXPConnect::gOnceAliveNowDead = JS_FALSE;
66
+ PRUint32 nsXPConnect::gReportAllJSExceptions = 0;
67
+
68
+ // Global cache of the default script security manager (QI'd to
69
+ // nsIScriptSecurityManager)
70
+ nsIScriptSecurityManager *gScriptSecurityManager = nsnull;
71
+
72
+ const char XPC_CONTEXT_STACK_CONTRACTID[] = "@mozilla.org/js/xpc/ContextStack;1";
73
+ const char XPC_RUNTIME_CONTRACTID[] = "@mozilla.org/js/xpc/RuntimeService;1";
74
+ const char XPC_EXCEPTION_CONTRACTID[] = "@mozilla.org/js/xpc/Exception;1";
75
+ const char XPC_CONSOLE_CONTRACTID[] = "@mozilla.org/consoleservice;1";
76
+ const char XPC_SCRIPT_ERROR_CONTRACTID[] = "@mozilla.org/scripterror;1";
77
+ const char XPC_ID_CONTRACTID[] = "@mozilla.org/js/xpc/ID;1";
78
+ const char XPC_XPCONNECT_CONTRACTID[] = "@mozilla.org/js/xpc/XPConnect;1";
79
+
80
+ /***************************************************************************/
81
+
82
+ nsXPConnect::nsXPConnect()
83
+ : mRuntime(nsnull),
84
+ mInterfaceInfoManager(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID)),
85
+ mDefaultSecurityManager(nsnull),
86
+ mDefaultSecurityManagerFlags(0),
87
+ mShuttingDown(JS_FALSE),
88
+ mCycleCollectionContext(nsnull),
89
+ mCycleCollecting(PR_FALSE)
90
+ {
91
+ mRuntime = XPCJSRuntime::newXPCJSRuntime(this);
92
+
93
+ nsCycleCollector_registerRuntime(nsIProgrammingLanguage::JAVASCRIPT, this);
94
+ #ifdef DEBUG_CC
95
+ mJSRoots.ops = nsnull;
96
+ #endif
97
+
98
+ #ifdef XPC_TOOLS_SUPPORT
99
+ {
100
+ char* filename = PR_GetEnv("MOZILLA_JS_PROFILER_OUTPUT");
101
+ if(filename && *filename)
102
+ {
103
+ mProfilerOutputFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
104
+ if(mProfilerOutputFile &&
105
+ NS_SUCCEEDED(mProfilerOutputFile->InitWithNativePath(nsDependentCString(filename))))
106
+ {
107
+ mProfiler = do_GetService(XPCTOOLS_PROFILER_CONTRACTID);
108
+ if(mProfiler)
109
+ {
110
+ if(NS_SUCCEEDED(mProfiler->Start()))
111
+ {
112
+ #ifdef DEBUG
113
+ printf("***** profiling JavaScript. Output to: %s\n",
114
+ filename);
115
+ #endif
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ #endif
122
+ char* reportableEnv = PR_GetEnv("MOZ_REPORT_ALL_JS_EXCEPTIONS");
123
+ if(reportableEnv && *reportableEnv)
124
+ gReportAllJSExceptions = 1;
125
+ }
126
+
127
+ nsXPConnect::~nsXPConnect()
128
+ {
129
+ NS_ASSERTION(!mCycleCollectionContext,
130
+ "Didn't call FinishCycleCollection?");
131
+ nsCycleCollector_forgetRuntime(nsIProgrammingLanguage::JAVASCRIPT);
132
+
133
+ JSContext *cx = nsnull;
134
+ if (mRuntime) {
135
+ // Create our own JSContext rather than an XPCCallContext, since
136
+ // otherwise we will create a new safe JS context and attach a
137
+ // components object that won't get GCed.
138
+ // And do this before calling CleanupAllThreads, so that we
139
+ // don't create an extra xpcPerThreadData.
140
+ cx = JS_NewContext(mRuntime->GetJSRuntime(), 8192);
141
+ }
142
+
143
+ XPCPerThreadData::CleanupAllThreads();
144
+ mShuttingDown = JS_TRUE;
145
+ if (cx) {
146
+ JS_BeginRequest(cx);
147
+
148
+ // XXX Call even if |mRuntime| null?
149
+ XPCWrappedNativeScope::SystemIsBeingShutDown(cx);
150
+
151
+ mRuntime->SystemIsBeingShutDown(cx);
152
+
153
+ JS_EndRequest(cx);
154
+ JS_DestroyContext(cx);
155
+ }
156
+
157
+ NS_IF_RELEASE(mDefaultSecurityManager);
158
+
159
+ gScriptSecurityManager = nsnull;
160
+
161
+ // shutdown the logging system
162
+ XPC_LOG_FINISH();
163
+
164
+ delete mRuntime;
165
+
166
+ gSelf = nsnull;
167
+ gOnceAliveNowDead = JS_TRUE;
168
+ }
169
+
170
+ // static
171
+ nsXPConnect*
172
+ nsXPConnect::GetXPConnect()
173
+ {
174
+ if(!gSelf)
175
+ {
176
+ if(gOnceAliveNowDead)
177
+ return nsnull;
178
+ gSelf = new nsXPConnect();
179
+ if(!gSelf)
180
+ return nsnull;
181
+
182
+ if(!gSelf->mRuntime ||
183
+ !gSelf->mInterfaceInfoManager)
184
+ {
185
+ // ctor failed to create an acceptable instance
186
+ delete gSelf;
187
+ gSelf = nsnull;
188
+ }
189
+ else
190
+ {
191
+ // Initial extra ref to keep the singleton alive
192
+ // balanced by explicit call to ReleaseXPConnectSingleton()
193
+ NS_ADDREF(gSelf);
194
+ if (NS_FAILED(NS_SetGlobalThreadObserver(gSelf))) {
195
+ NS_RELEASE(gSelf);
196
+ // Fall through to returning null
197
+ }
198
+ }
199
+ }
200
+ return gSelf;
201
+ }
202
+
203
+ // static
204
+ nsXPConnect*
205
+ nsXPConnect::GetSingleton()
206
+ {
207
+ nsXPConnect* xpc = nsXPConnect::GetXPConnect();
208
+ NS_IF_ADDREF(xpc);
209
+ return xpc;
210
+ }
211
+
212
+ // static
213
+ void
214
+ nsXPConnect::ReleaseXPConnectSingleton()
215
+ {
216
+ nsXPConnect* xpc = gSelf;
217
+ if(xpc)
218
+ {
219
+ NS_SetGlobalThreadObserver(nsnull);
220
+
221
+ #ifdef XPC_TOOLS_SUPPORT
222
+ if(xpc->mProfiler)
223
+ {
224
+ xpc->mProfiler->Stop();
225
+ xpc->mProfiler->WriteResults(xpc->mProfilerOutputFile);
226
+ }
227
+ #endif
228
+
229
+ #ifdef DEBUG
230
+ // force a dump of the JavaScript gc heap if JS is still alive
231
+ // if requested through XPC_SHUTDOWN_HEAP_DUMP environment variable
232
+ {
233
+ // autoscope
234
+ XPCCallContext ccx(NATIVE_CALLER);
235
+ if(ccx.IsValid())
236
+ {
237
+ const char* dumpName = getenv("XPC_SHUTDOWN_HEAP_DUMP");
238
+ if(dumpName)
239
+ {
240
+ FILE* dumpFile = (*dumpName == '\0' ||
241
+ strcmp(dumpName, "stdout") == 0)
242
+ ? stdout
243
+ : fopen(dumpName, "w");
244
+ if(dumpFile)
245
+ {
246
+ JS_DumpHeap(ccx, dumpFile, nsnull, 0, nsnull,
247
+ static_cast<size_t>(-1), nsnull);
248
+ if(dumpFile != stdout)
249
+ fclose(dumpFile);
250
+ }
251
+ }
252
+ }
253
+ }
254
+ #endif
255
+ #ifdef XPC_DUMP_AT_SHUTDOWN
256
+ // NOTE: to see really interesting stuff turn on the prlog stuff.
257
+ // See the comment at the top of xpclog.h to see how to do that.
258
+ xpc->DebugDump(7);
259
+ #endif
260
+ nsrefcnt cnt;
261
+ NS_RELEASE2(xpc, cnt);
262
+ #ifdef XPC_DUMP_AT_SHUTDOWN
263
+ if(0 != cnt)
264
+ printf("*** dangling reference to nsXPConnect: refcnt=%d\n", cnt);
265
+ else
266
+ printf("+++ XPConnect had no dangling references.\n");
267
+ #endif
268
+ }
269
+ }
270
+
271
+ // static
272
+ nsresult
273
+ nsXPConnect::GetInterfaceInfoManager(nsIInterfaceInfoSuperManager** iim,
274
+ nsXPConnect* xpc /*= nsnull*/)
275
+ {
276
+ if(!xpc && !(xpc = GetXPConnect()))
277
+ return NS_ERROR_FAILURE;
278
+
279
+ *iim = xpc->mInterfaceInfoManager;
280
+ NS_IF_ADDREF(*iim);
281
+ return NS_OK;
282
+ }
283
+
284
+ // static
285
+ XPCJSRuntime*
286
+ nsXPConnect::GetRuntimeInstance()
287
+ {
288
+ nsXPConnect* xpc = GetXPConnect();
289
+ NS_ASSERTION(xpc, "Must not be called if XPC failed to initialize");
290
+ return xpc->GetRuntime();
291
+ }
292
+
293
+ // static
294
+ JSBool
295
+ nsXPConnect::IsISupportsDescendant(nsIInterfaceInfo* info)
296
+ {
297
+ PRBool found = PR_FALSE;
298
+ if(info)
299
+ info->HasAncestor(&NS_GET_IID(nsISupports), &found);
300
+ return found;
301
+ }
302
+
303
+ /***************************************************************************/
304
+
305
+ typedef PRBool (*InfoTester)(nsIInterfaceInfoManager* manager, const void* data,
306
+ nsIInterfaceInfo** info);
307
+
308
+ static PRBool IIDTester(nsIInterfaceInfoManager* manager, const void* data,
309
+ nsIInterfaceInfo** info)
310
+ {
311
+ return NS_SUCCEEDED(manager->GetInfoForIID((const nsIID *) data, info)) &&
312
+ *info;
313
+ }
314
+
315
+ static PRBool NameTester(nsIInterfaceInfoManager* manager, const void* data,
316
+ nsIInterfaceInfo** info)
317
+ {
318
+ return NS_SUCCEEDED(manager->GetInfoForName((const char *) data, info)) &&
319
+ *info;
320
+ }
321
+
322
+ static nsresult FindInfo(InfoTester tester, const void* data,
323
+ nsIInterfaceInfoSuperManager* iism,
324
+ nsIInterfaceInfo** info)
325
+ {
326
+ if(tester(iism, data, info))
327
+ return NS_OK;
328
+
329
+ // If not found, then let's ask additional managers.
330
+
331
+ PRBool yes;
332
+ nsCOMPtr<nsISimpleEnumerator> list;
333
+
334
+ if(NS_SUCCEEDED(iism->HasAdditionalManagers(&yes)) && yes &&
335
+ NS_SUCCEEDED(iism->EnumerateAdditionalManagers(getter_AddRefs(list))) &&
336
+ list)
337
+ {
338
+ PRBool more;
339
+ nsCOMPtr<nsIInterfaceInfoManager> current;
340
+
341
+ while(NS_SUCCEEDED(list->HasMoreElements(&more)) && more &&
342
+ NS_SUCCEEDED(list->GetNext(getter_AddRefs(current))) && current)
343
+ {
344
+ if(tester(current, data, info))
345
+ return NS_OK;
346
+ }
347
+ }
348
+
349
+ return NS_ERROR_NO_INTERFACE;
350
+ }
351
+
352
+ nsresult
353
+ nsXPConnect::GetInfoForIID(const nsIID * aIID, nsIInterfaceInfo** info)
354
+ {
355
+ return FindInfo(IIDTester, aIID, mInterfaceInfoManager, info);
356
+ }
357
+
358
+ nsresult
359
+ nsXPConnect::GetInfoForName(const char * name, nsIInterfaceInfo** info)
360
+ {
361
+ return FindInfo(NameTester, name, mInterfaceInfoManager, info);
362
+ }
363
+
364
+ static JSGCCallback gOldJSGCCallback;
365
+ // Whether cycle collection was run.
366
+ static PRBool gDidCollection;
367
+ // Whether starting cycle collection was successful.
368
+ static PRBool gInCollection;
369
+ // Whether cycle collection collected anything.
370
+ static PRBool gCollected;
371
+
372
+ static JSBool
373
+ XPCCycleCollectGCCallback(JSContext *cx, JSGCStatus status)
374
+ {
375
+ // Launch the cycle collector.
376
+ switch(status)
377
+ {
378
+ case JSGC_BEGIN:
379
+ nsXPConnect::GetRuntimeInstance()->UnrootContextGlobals();
380
+ break;
381
+
382
+ case JSGC_MARK_END:
383
+ // This is the hook between marking and sweeping in the JS GC. Do cycle
384
+ // collection.
385
+ if(!gDidCollection)
386
+ {
387
+ NS_ASSERTION(!gInCollection, "Recursing?");
388
+
389
+ gDidCollection = PR_TRUE;
390
+ gInCollection = nsCycleCollector_beginCollection();
391
+ }
392
+
393
+ // Mark JS objects that are held by XPCOM objects that are in cycles
394
+ // that will not be collected.
395
+ nsXPConnect::GetRuntimeInstance()->
396
+ TraceXPConnectRoots(cx->runtime->gcMarkingTracer, JS_TRUE);
397
+ break;
398
+
399
+ case JSGC_END:
400
+ if(gInCollection)
401
+ {
402
+ gInCollection = PR_FALSE;
403
+ gCollected = nsCycleCollector_finishCollection();
404
+ }
405
+ break;
406
+
407
+ default:
408
+ break;
409
+ }
410
+
411
+ return gOldJSGCCallback ? gOldJSGCCallback(cx, status) : JS_TRUE;
412
+ }
413
+
414
+ PRBool
415
+ nsXPConnect::Collect()
416
+ {
417
+ // We're dividing JS objects into 2 categories:
418
+ //
419
+ // 1. "real" roots, held by the JS engine itself or rooted through the root
420
+ // and lock JS APIs. Roots from this category are considered black in the
421
+ // cycle collector, any cycle they participate in is uncollectable.
422
+ //
423
+ // 2. roots held by C++ objects that participate in cycle collection,
424
+ // held by XPConnect (see XPCJSRuntime::TraceXPConnectRoots). Roots from
425
+ // this category are considered grey in the cycle collector, their final
426
+ // color depends on the objects that hold them. It is thus very important
427
+ // to always traverse the objects that hold these objects during cycle
428
+ // collection (see XPCJSRuntime::AddXPConnectRoots).
429
+ //
430
+ // Note that if a root is in both categories it is the fact that it is in
431
+ // category 1 that takes precedence, so it will be considered black.
432
+ //
433
+ //
434
+ // We split up garbage collection into 3 phases (1, 3 and 4) and do cycle
435
+ // collection between the first 2 phases of garbage collection:
436
+ //
437
+ // 1. marking of the roots in category 1 by having the JS GC do its marking
438
+ // 2. cycle collection
439
+ // 3. marking of the roots in category 2 by
440
+ // XPCJSRuntime::TraceXPConnectRoots
441
+ // 4. sweeping of unmarked JS objects
442
+ //
443
+ // During cycle collection, marked JS objects (and the objects they hold)
444
+ // will be colored black. White objects holding roots from category 2 will
445
+ // be forgotten by XPConnect (in the unlink callback of the white objects).
446
+ // During phase 3 we'll only mark black objects holding JS objects (white
447
+ // objects were forgotten) and white JS objects will be swept during
448
+ // phase 4.
449
+ // Because splitting up the JS GC itself is hard, we're going to use a GC
450
+ // callback to do phase 2 and 3 after phase 1 has ended (see
451
+ // XPCCycleCollectGCCallback).
452
+ //
453
+ // If DEBUG_CC is not defined the cycle collector will not traverse roots
454
+ // from category 1 or any JS objects held by them. Any JS objects they hold
455
+ // will already be marked by the JS GC and will thus be colored black
456
+ // themselves. Any C++ objects they hold will have a missing (untraversed)
457
+ // edge from the JS object to the C++ object and so it will be marked black
458
+ // too. This decreases the number of objects that the cycle collector has to
459
+ // deal with.
460
+ // To improve debugging, if DEBUG_CC is defined all JS objects are
461
+ // traversed.
462
+
463
+ XPCCallContext cycleCollectionContext(NATIVE_CALLER);
464
+ if(!cycleCollectionContext.IsValid())
465
+ {
466
+ return PR_FALSE;
467
+ }
468
+
469
+ mCycleCollecting = PR_TRUE;
470
+ mCycleCollectionContext = &cycleCollectionContext;
471
+ gDidCollection = PR_FALSE;
472
+ gInCollection = PR_FALSE;
473
+ gCollected = PR_FALSE;
474
+
475
+ JSContext *cx = mCycleCollectionContext->GetJSContext();
476
+ gOldJSGCCallback = JS_SetGCCallback(cx, XPCCycleCollectGCCallback);
477
+ JS_GC(cx);
478
+ JS_SetGCCallback(cx, gOldJSGCCallback);
479
+ gOldJSGCCallback = nsnull;
480
+
481
+ mCycleCollectionContext = nsnull;
482
+ mCycleCollecting = PR_FALSE;
483
+
484
+ return gCollected;
485
+ }
486
+
487
+ // JSTRACE_XML can recursively hold on to more JSTRACE_XML objects, adding it to
488
+ // the cycle collector avoids stack overflow.
489
+ #define ADD_TO_CC(_kind) ((_kind) == JSTRACE_OBJECT || (_kind) == JSTRACE_XML)
490
+
491
+ #ifdef DEBUG_CC
492
+ struct NoteJSRootTracer : public JSTracer
493
+ {
494
+ NoteJSRootTracer(PLDHashTable *aObjects,
495
+ nsCycleCollectionTraversalCallback& cb)
496
+ : mObjects(aObjects),
497
+ mCb(cb)
498
+ {
499
+ }
500
+ PLDHashTable* mObjects;
501
+ nsCycleCollectionTraversalCallback& mCb;
502
+ };
503
+
504
+ static void
505
+ NoteJSRoot(JSTracer *trc, void *thing, uint32 kind)
506
+ {
507
+ if(ADD_TO_CC(kind))
508
+ {
509
+ NoteJSRootTracer *tracer = static_cast<NoteJSRootTracer*>(trc);
510
+ PLDHashEntryHdr *entry = PL_DHashTableOperate(tracer->mObjects, thing,
511
+ PL_DHASH_ADD);
512
+ if(entry && !reinterpret_cast<PLDHashEntryStub*>(entry)->key)
513
+ {
514
+ reinterpret_cast<PLDHashEntryStub*>(entry)->key = thing;
515
+ tracer->mCb.NoteRoot(nsIProgrammingLanguage::JAVASCRIPT, thing,
516
+ nsXPConnect::GetXPConnect());
517
+ }
518
+ }
519
+ else if(kind != JSTRACE_DOUBLE && kind != JSTRACE_STRING)
520
+ {
521
+ JS_TraceChildren(trc, thing, kind);
522
+ }
523
+ }
524
+ #endif
525
+
526
+ nsresult
527
+ nsXPConnect::BeginCycleCollection(nsCycleCollectionTraversalCallback &cb)
528
+ {
529
+ #ifdef DEBUG_CC
530
+ NS_ASSERTION(!mJSRoots.ops, "Didn't call FinishCollection?");
531
+
532
+ if(!mCycleCollectionContext)
533
+ {
534
+ // Being called from nsCycleCollector::ExplainLiveExpectedGarbage.
535
+ mExplainCycleCollectionContext = new XPCCallContext(NATIVE_CALLER);
536
+ if(!mExplainCycleCollectionContext ||
537
+ !mExplainCycleCollectionContext->IsValid())
538
+ {
539
+ mExplainCycleCollectionContext = nsnull;
540
+ return PR_FALSE;
541
+ }
542
+
543
+ mCycleCollectionContext = mExplainCycleCollectionContext;
544
+
545
+ // Record all objects held by the JS runtime. This avoids doing a
546
+ // complete GC if we're just tracing to explain (from
547
+ // ExplainLiveExpectedGarbage), which makes the results of cycle
548
+ // collection identical for DEBUG_CC and non-DEBUG_CC builds.
549
+ if(!PL_DHashTableInit(&mJSRoots, PL_DHashGetStubOps(), nsnull,
550
+ sizeof(PLDHashEntryStub), PL_DHASH_MIN_SIZE)) {
551
+ mJSRoots.ops = nsnull;
552
+
553
+ return NS_ERROR_OUT_OF_MEMORY;
554
+ }
555
+
556
+ GetRuntime()->UnrootContextGlobals();
557
+
558
+ PRBool alreadyCollecting = mCycleCollecting;
559
+ mCycleCollecting = PR_TRUE;
560
+ NoteJSRootTracer trc(&mJSRoots, cb);
561
+ JS_TRACER_INIT(&trc, mCycleCollectionContext->GetJSContext(),
562
+ NoteJSRoot);
563
+ JS_TraceRuntime(&trc);
564
+ mCycleCollecting = alreadyCollecting;
565
+ }
566
+ #else
567
+ NS_ASSERTION(mCycleCollectionContext,
568
+ "Didn't call nsXPConnect::Collect()?");
569
+ #endif
570
+
571
+ GetRuntime()->AddXPConnectRoots(mCycleCollectionContext->GetJSContext(),
572
+ cb);
573
+
574
+ #ifndef XPCONNECT_STANDALONE
575
+ if(!mScopes.IsInitialized())
576
+ {
577
+ mScopes.Init();
578
+ }
579
+ NS_ASSERTION(mScopes.Count() == 0, "Didn't clear mScopes?");
580
+ XPCWrappedNativeScope::TraverseScopes(*mCycleCollectionContext);
581
+ #endif
582
+
583
+ return NS_OK;
584
+ }
585
+
586
+ #ifndef XPCONNECT_STANDALONE
587
+ void
588
+ nsXPConnect::RecordTraversal(void *p, nsISupports *s)
589
+ {
590
+ mScopes.Put(p, s);
591
+ }
592
+ #endif
593
+
594
+ nsresult
595
+ nsXPConnect::FinishCycleCollection()
596
+ {
597
+ #ifdef DEBUG_CC
598
+ if(mExplainCycleCollectionContext)
599
+ {
600
+ mCycleCollectionContext = nsnull;
601
+ mExplainCycleCollectionContext = nsnull;
602
+
603
+ GetRuntime()->RootContextGlobals();
604
+ }
605
+ #endif
606
+
607
+ #ifndef XPCONNECT_STANDALONE
608
+ mScopes.Clear();
609
+ #endif
610
+
611
+ #ifdef DEBUG_CC
612
+ if(mJSRoots.ops)
613
+ {
614
+ PL_DHashTableFinish(&mJSRoots);
615
+ mJSRoots.ops = nsnull;
616
+ }
617
+ #endif
618
+
619
+ return NS_OK;
620
+ }
621
+
622
+ nsCycleCollectionParticipant *
623
+ nsXPConnect::ToParticipant(void *p)
624
+ {
625
+ return this;
626
+ }
627
+
628
+ NS_IMETHODIMP
629
+ nsXPConnect::RootAndUnlinkJSObjects(void *p)
630
+ {
631
+ return NS_OK;
632
+ }
633
+
634
+ #ifdef DEBUG_CC
635
+ void
636
+ nsXPConnect::PrintAllReferencesTo(void *p)
637
+ {
638
+ #ifdef DEBUG
639
+ if(!mCycleCollectionContext) {
640
+ NS_NOTREACHED("no context");
641
+ return;
642
+ }
643
+ JS_DumpHeap(*mCycleCollectionContext, stdout, nsnull, 0, p,
644
+ 0x7fffffff, nsnull);
645
+ #endif
646
+ }
647
+ #endif
648
+
649
+ NS_IMETHODIMP
650
+ nsXPConnect::Unlink(void *p)
651
+ {
652
+ return NS_OK;
653
+ }
654
+
655
+ NS_IMETHODIMP
656
+ nsXPConnect::Unroot(void *p)
657
+ {
658
+ return NS_OK;
659
+ }
660
+
661
+ struct TraversalTracer : public JSTracer
662
+ {
663
+ TraversalTracer(nsCycleCollectionTraversalCallback &aCb) : cb(aCb)
664
+ {
665
+ }
666
+ nsCycleCollectionTraversalCallback &cb;
667
+ };
668
+
669
+ static void
670
+ NoteJSChild(JSTracer *trc, void *thing, uint32 kind)
671
+ {
672
+ if(ADD_TO_CC(kind))
673
+ {
674
+ TraversalTracer *tracer = static_cast<TraversalTracer*>(trc);
675
+ #if defined(DEBUG) && defined(DEBUG_CC)
676
+ // based on DumpNotify in jsapi.c
677
+ if (tracer->debugPrinter) {
678
+ char buffer[200];
679
+ tracer->debugPrinter(trc, buffer, sizeof(buffer));
680
+ tracer->cb.NoteNextEdgeName(buffer);
681
+ } else if (tracer->debugPrintIndex != (size_t)-1) {
682
+ char buffer[200];
683
+ JS_snprintf(buffer, sizeof(buffer), "%s[%lu]",
684
+ static_cast<const char *>(tracer->debugPrintArg),
685
+ tracer->debugPrintIndex);
686
+ tracer->cb.NoteNextEdgeName(buffer);
687
+ } else {
688
+ tracer->cb.NoteNextEdgeName(
689
+ static_cast<const char*>(tracer->debugPrintArg));
690
+ }
691
+ #endif
692
+ tracer->cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, thing);
693
+ }
694
+ else if(kind != JSTRACE_DOUBLE && kind != JSTRACE_STRING)
695
+ {
696
+ JS_TraceChildren(trc, thing, kind);
697
+ }
698
+ }
699
+
700
+ static JSBool
701
+ WrapperIsNotMainThreadOnly(XPCWrappedNative *wrapper)
702
+ {
703
+ XPCWrappedNativeProto *proto = wrapper->GetProto();
704
+ if(proto && proto->ClassIsMainThreadOnly())
705
+ return PR_FALSE;
706
+
707
+ // If the native participates in cycle collection then we know it can only
708
+ // be used on the main thread, in that case we assume the wrapped native
709
+ // can only be used on the main thread too.
710
+ nsXPCOMCycleCollectionParticipant* participant;
711
+ return NS_FAILED(CallQueryInterface(wrapper->Native(), &participant));
712
+ }
713
+
714
+ NS_IMETHODIMP
715
+ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
716
+ {
717
+ if(!mCycleCollectionContext)
718
+ return NS_ERROR_FAILURE;
719
+
720
+ JSContext *cx = mCycleCollectionContext->GetJSContext();
721
+
722
+ uint32 traceKind = js_GetGCThingTraceKind(p);
723
+ JSObject *obj;
724
+ JSClass *clazz;
725
+
726
+ // We do not want to add wrappers to the cycle collector if they're not
727
+ // explicitly marked as main thread only, because the cycle collector isn't
728
+ // able to deal with objects that might be used off of the main thread. We
729
+ // do want to explicitly mark them for cycle collection if the wrapper has
730
+ // an external reference, because the wrapper would mark the JS object if
731
+ // we did add the wrapper to the cycle collector.
732
+ JSBool dontTraverse = PR_FALSE;
733
+ JSBool markJSObject = PR_FALSE;
734
+ if(traceKind == JSTRACE_OBJECT)
735
+ {
736
+ obj = static_cast<JSObject*>(p);
737
+ clazz = OBJ_GET_CLASS(cx, obj);
738
+
739
+ if(clazz == &XPC_WN_Tearoff_JSClass)
740
+ {
741
+ XPCWrappedNative *wrapper =
742
+ (XPCWrappedNative*)xpc_GetJSPrivate(STOBJ_GET_PARENT(obj));
743
+ dontTraverse = WrapperIsNotMainThreadOnly(wrapper);
744
+ }
745
+ else if(IS_WRAPPER_CLASS(clazz))
746
+ {
747
+ XPCWrappedNative *wrapper = (XPCWrappedNative*)xpc_GetJSPrivate(obj);
748
+ dontTraverse = WrapperIsNotMainThreadOnly(wrapper);
749
+ markJSObject = dontTraverse && wrapper->HasExternalReference();
750
+ }
751
+ }
752
+
753
+ CCNodeType type;
754
+
755
+ #ifdef DEBUG_CC
756
+ {
757
+ // Note that the conditions under which we specify GCMarked vs.
758
+ // GCUnmarked are different between ExplainLiveExpectedGarbage and
759
+ // the normal case. In the normal case, we're saying that anything
760
+ // reachable from a JS runtime root is itself such a root. This
761
+ // doesn't actually break anything; it really just does some of the
762
+ // cycle collector's work for it. However, when debugging, we
763
+ // (1) actually need to know what the root is and (2) don't want to
764
+ // do an extra GC, so we use mJSRoots, built from JS_TraceRuntime,
765
+ // which produces a different result because we didn't call
766
+ // JS_TraceChildren to trace everything that was reachable.
767
+ if(mJSRoots.ops)
768
+ {
769
+ // ExplainLiveExpectedGarbage codepath
770
+ PLDHashEntryHdr* entry =
771
+ PL_DHashTableOperate(&mJSRoots, p, PL_DHASH_LOOKUP);
772
+ type = markJSObject || PL_DHASH_ENTRY_IS_BUSY(entry) ? GCMarked :
773
+ GCUnmarked;
774
+ }
775
+ else
776
+ {
777
+ // Normal codepath (matches non-DEBUG_CC codepath).
778
+ type = !markJSObject && JS_IsAboutToBeFinalized(cx, p) ? GCUnmarked :
779
+ GCMarked;
780
+ }
781
+
782
+ char name[72];
783
+ if(traceKind == JSTRACE_OBJECT)
784
+ {
785
+ JSObject *obj = static_cast<JSObject*>(p);
786
+ JSClass *clazz = OBJ_GET_CLASS(cx, obj);
787
+ if(XPCNativeWrapper::IsNativeWrapperClass(clazz))
788
+ {
789
+ XPCWrappedNative* wn = XPCNativeWrapper::GetWrappedNative(obj);
790
+ if(wn)
791
+ {
792
+ XPCNativeScriptableInfo* si = wn->GetScriptableInfo();
793
+ if(si)
794
+ {
795
+ JS_snprintf(name, sizeof(name), "XPCNativeWrapper (%s)",
796
+ si->GetJSClass()->name);
797
+ }
798
+ else
799
+ {
800
+ nsIClassInfo* ci = wn->GetClassInfo();
801
+ char* className = nsnull;
802
+ if(ci)
803
+ ci->GetClassDescription(&className);
804
+ if(className)
805
+ {
806
+ JS_snprintf(name, sizeof(name), "XPCNativeWrapper (%s)",
807
+ className);
808
+ PR_Free(className);
809
+ }
810
+ else
811
+ {
812
+ XPCNativeSet* set = wn->GetSet();
813
+ XPCNativeInterface** array = set->GetInterfaceArray();
814
+ PRUint16 count = set->GetInterfaceCount();
815
+
816
+ if(count > 0)
817
+ JS_snprintf(name, sizeof(name),
818
+ "XPCNativeWrapper (%s)",
819
+ array[0]->GetNameString());
820
+ else
821
+ JS_snprintf(name, sizeof(name), "XPCNativeWrapper");
822
+ }
823
+ }
824
+ }
825
+ else
826
+ {
827
+ JS_snprintf(name, sizeof(name), "XPCNativeWrapper");
828
+ }
829
+ }
830
+ else
831
+ {
832
+ XPCNativeScriptableInfo* si = nsnull;
833
+ if(IS_PROTO_CLASS(clazz))
834
+ {
835
+ XPCWrappedNativeProto* p =
836
+ (XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
837
+ si = p->GetScriptableInfo();
838
+ }
839
+ if(si)
840
+ {
841
+ JS_snprintf(name, sizeof(name), "JS Object (%s - %s)",
842
+ clazz->name, si->GetJSClass()->name);
843
+ }
844
+ else if(clazz == &js_ScriptClass)
845
+ {
846
+ JSScript* script = (JSScript*) xpc_GetJSPrivate(obj);
847
+ if(script->filename)
848
+ {
849
+ JS_snprintf(name, sizeof(name), "JS Object (Script - %s)",
850
+ script->filename);
851
+ }
852
+ else
853
+ {
854
+ JS_snprintf(name, sizeof(name), "JS Object (Script)");
855
+ }
856
+ }
857
+ else if(clazz == &js_FunctionClass)
858
+ {
859
+ JSFunction* fun = (JSFunction*) xpc_GetJSPrivate(obj);
860
+ JSString* str = JS_GetFunctionId(fun);
861
+ if(str)
862
+ {
863
+ NS_ConvertUTF16toUTF8
864
+ fname(JS_GetStringChars(str));
865
+ JS_snprintf(name, sizeof(name), "JS Object (Function - %s)",
866
+ fname.get());
867
+ }
868
+ else
869
+ {
870
+ JS_snprintf(name, sizeof(name), "JS Object (Function)");
871
+ }
872
+ }
873
+ else
874
+ {
875
+ JS_snprintf(name, sizeof(name), "JS Object (%s)", clazz->name);
876
+ }
877
+ }
878
+ }
879
+ else
880
+ {
881
+ static const char trace_types[JSTRACE_LIMIT][7] = {
882
+ "Object",
883
+ "Double",
884
+ "String",
885
+ "Xml"
886
+ };
887
+ JS_snprintf(name, sizeof(name), "JS %s", trace_types[traceKind]);
888
+ }
889
+
890
+ if(traceKind == JSTRACE_OBJECT) {
891
+ JSObject *global = static_cast<JSObject*>(p), *parent;
892
+ while((parent = JS_GetParent(cx, global)))
893
+ global = parent;
894
+ char fullname[100];
895
+ JS_snprintf(fullname, sizeof(fullname), "%s (global=%p)", name, global);
896
+ cb.DescribeNode(type, 0, sizeof(JSObject), fullname);
897
+ } else {
898
+ cb.DescribeNode(type, 0, sizeof(JSObject), name);
899
+ }
900
+
901
+ }
902
+ #else
903
+ type = !markJSObject && JS_IsAboutToBeFinalized(cx, p) ? GCUnmarked :
904
+ GCMarked;
905
+ cb.DescribeNode(type, 0);
906
+ #endif
907
+
908
+ if(!ADD_TO_CC(traceKind))
909
+ return NS_OK;
910
+
911
+ #ifndef DEBUG_CC
912
+ // There's no need to trace objects that have already been marked by the JS
913
+ // GC. Any JS objects hanging from them will already be marked. Only do this
914
+ // if DEBUG_CC is not defined, else we do want to know about all JS objects
915
+ // to get better graphs and explanations.
916
+ if(type == GCMarked)
917
+ return NS_OK;
918
+ #endif
919
+
920
+ TraversalTracer trc(cb);
921
+
922
+ JS_TRACER_INIT(&trc, cx, NoteJSChild);
923
+ JS_TraceChildren(&trc, p, traceKind);
924
+
925
+ if(traceKind != JSTRACE_OBJECT || dontTraverse)
926
+ return NS_OK;
927
+
928
+ if(clazz == &XPC_WN_Tearoff_JSClass)
929
+ {
930
+ // A tearoff holds a strong reference to its native object
931
+ // (see XPCWrappedNative::FlatJSObjectFinalized). Its XPCWrappedNative
932
+ // will be held alive through the parent of the JSObject of the tearoff.
933
+ XPCWrappedNativeTearOff *to =
934
+ (XPCWrappedNativeTearOff*) xpc_GetJSPrivate(obj);
935
+ NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "xpc_GetJSPrivate(obj)->mNative");
936
+ cb.NoteXPCOMChild(to->GetNative());
937
+ }
938
+ // XXX XPCNativeWrapper seems to be the only class that doesn't hold a
939
+ // strong reference to its nsISupports private. This test does seem
940
+ // fragile though, we should probably whitelist classes that do hold
941
+ // a strong reference, but that might not be possible.
942
+ else if(clazz->flags & JSCLASS_HAS_PRIVATE &&
943
+ clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS &&
944
+ !XPCNativeWrapper::IsNativeWrapperClass(clazz))
945
+ {
946
+ NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "xpc_GetJSPrivate(obj)");
947
+ cb.NoteXPCOMChild(static_cast<nsISupports*>(xpc_GetJSPrivate(obj)));
948
+ }
949
+
950
+ #ifndef XPCONNECT_STANDALONE
951
+ if(clazz->flags & JSCLASS_IS_GLOBAL)
952
+ {
953
+ nsISupports *principal = nsnull;
954
+ mScopes.Get(obj, &principal);
955
+ NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "scope principal");
956
+ cb.NoteXPCOMChild(principal);
957
+ }
958
+ #endif
959
+
960
+ return NS_OK;
961
+ }
962
+
963
+ PRInt32
964
+ nsXPConnect::GetRequestDepth(JSContext* cx)
965
+ {
966
+ PRInt32 requestDepth = cx->outstandingRequests;
967
+ XPCCallContext* context = GetCycleCollectionContext();
968
+ if(context && cx == context->GetJSContext())
969
+ // Ignore the request from the XPCCallContext we created for cycle
970
+ // collection.
971
+ --requestDepth;
972
+ return requestDepth;
973
+ }
974
+
975
+ class JSContextParticipant : public nsCycleCollectionParticipant
976
+ {
977
+ public:
978
+ NS_IMETHOD RootAndUnlinkJSObjects(void *n)
979
+ {
980
+ return NS_OK;
981
+ }
982
+ NS_IMETHOD Unlink(void *n)
983
+ {
984
+ // We must not unlink a JSContext because Root/Unroot don't ensure that
985
+ // the pointer is still valid.
986
+ return NS_OK;
987
+ }
988
+ NS_IMETHOD Unroot(void *n)
989
+ {
990
+ return NS_OK;
991
+ }
992
+ NS_IMETHODIMP Traverse(void *n, nsCycleCollectionTraversalCallback &cb)
993
+ {
994
+ JSContext *cx = static_cast<JSContext*>(n);
995
+
996
+ // Add cx->requestDepth to the refcount, if there are outstanding
997
+ // requests the context needs to be kept alive and adding unknown
998
+ // edges will ensure that any cycles this context is in won't be
999
+ // collected.
1000
+ PRInt32 refCount = nsXPConnect::GetXPConnect()->GetRequestDepth(cx) + 1;
1001
+
1002
+ #ifdef DEBUG_CC
1003
+ cb.DescribeNode(RefCounted, refCount, sizeof(JSContext),
1004
+ "JSContext");
1005
+ cb.NoteNextEdgeName("[global object]");
1006
+ #else
1007
+ cb.DescribeNode(RefCounted, refCount);
1008
+ #endif
1009
+ cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT,
1010
+ cx->globalObject);
1011
+
1012
+ return NS_OK;
1013
+ }
1014
+ };
1015
+
1016
+ static JSContextParticipant JSContext_cycleCollectorGlobal;
1017
+
1018
+ // static
1019
+ nsCycleCollectionParticipant*
1020
+ nsXPConnect::JSContextParticipant()
1021
+ {
1022
+ return &JSContext_cycleCollectorGlobal;
1023
+ }
1024
+
1025
+ NS_IMETHODIMP_(void)
1026
+ nsXPConnect::NoteJSContext(JSContext *aJSContext,
1027
+ nsCycleCollectionTraversalCallback &aCb)
1028
+ {
1029
+ aCb.NoteNativeChild(aJSContext, &JSContext_cycleCollectorGlobal);
1030
+ }
1031
+
1032
+
1033
+ /***************************************************************************/
1034
+ /***************************************************************************/
1035
+ // nsIXPConnect interface methods...
1036
+
1037
+ inline nsresult UnexpectedFailure(nsresult rv)
1038
+ {
1039
+ NS_ERROR("This is not supposed to fail!");
1040
+ return rv;
1041
+ }
1042
+
1043
+ class SaveFrame
1044
+ {
1045
+ public:
1046
+ SaveFrame(JSContext *cx)
1047
+ : mJSContext(cx) {
1048
+ mFrame = JS_SaveFrameChain(mJSContext);
1049
+ }
1050
+
1051
+ ~SaveFrame() {
1052
+ JS_RestoreFrameChain(mJSContext, mFrame);
1053
+ }
1054
+
1055
+ private:
1056
+ JSContext *mJSContext;
1057
+ JSStackFrame *mFrame;
1058
+ };
1059
+
1060
+ /* void initClasses (in JSContextPtr aJSContext, in JSObjectPtr aGlobalJSObj); */
1061
+ NS_IMETHODIMP
1062
+ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj)
1063
+ {
1064
+ NS_ASSERTION(aJSContext, "bad param");
1065
+ NS_ASSERTION(aGlobalJSObj, "bad param");
1066
+
1067
+ SaveFrame sf(aJSContext);
1068
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1069
+ if(!ccx.IsValid())
1070
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1071
+
1072
+ if(!xpc_InitJSxIDClassObjects())
1073
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1074
+
1075
+ if(!xpc_InitWrappedNativeJSOps())
1076
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1077
+
1078
+ XPCWrappedNativeScope* scope =
1079
+ XPCWrappedNativeScope::GetNewOrUsed(ccx, aGlobalJSObj);
1080
+
1081
+ if(!scope)
1082
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1083
+
1084
+ scope->RemoveWrappedNativeProtos();
1085
+
1086
+ if(!nsXPCComponents::AttachNewComponentsObject(ccx, scope, aGlobalJSObj))
1087
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1088
+
1089
+ #ifdef XPC_IDISPATCH_SUPPORT
1090
+ // Initialize any properties IDispatch needs on the global object
1091
+ XPCIDispatchExtension::Initialize(ccx, aGlobalJSObj);
1092
+ #endif
1093
+
1094
+ if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, aGlobalJSObj))
1095
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1096
+
1097
+ if (!XPC_SJOW_AttachNewConstructorObject(ccx, aGlobalJSObj))
1098
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1099
+
1100
+ return NS_OK;
1101
+ }
1102
+
1103
+ static JSBool
1104
+ TempGlobalResolve(JSContext *aJSContext, JSObject *obj, jsval id)
1105
+ {
1106
+ JSBool resolved;
1107
+ return JS_ResolveStandardClass(aJSContext, obj, id, &resolved);
1108
+ }
1109
+
1110
+ static JSClass xpcTempGlobalClass = {
1111
+ "xpcTempGlobalClass", JSCLASS_GLOBAL_FLAGS,
1112
+ JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
1113
+ JS_EnumerateStub, TempGlobalResolve, JS_ConvertStub, JS_FinalizeStub,
1114
+ JSCLASS_NO_OPTIONAL_MEMBERS
1115
+ };
1116
+
1117
+ /* nsIXPConnectJSObjectHolder initClassesWithNewWrappedGlobal (in JSContextPtr aJSContext, in nsISupports aCOMObj, in nsIIDRef aIID, in PRUint32 aFlags); */
1118
+ NS_IMETHODIMP
1119
+ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
1120
+ nsISupports *aCOMObj,
1121
+ const nsIID & aIID,
1122
+ PRUint32 aFlags,
1123
+ nsIXPConnectJSObjectHolder **_retval)
1124
+ {
1125
+ NS_ASSERTION(aJSContext, "bad param");
1126
+ NS_ASSERTION(aCOMObj, "bad param");
1127
+ NS_ASSERTION(_retval, "bad param");
1128
+
1129
+ // XXX This is not pretty. We make a temporary global object and
1130
+ // init it with all the Components object junk just so we have a
1131
+ // parent with an xpc scope to use when wrapping the object that will
1132
+ // become the 'real' global.
1133
+
1134
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1135
+
1136
+ PRBool system = (aFlags & nsIXPConnect::FLAG_SYSTEM_GLOBAL_OBJECT) != 0;
1137
+ JSObject* tempGlobal = JS_NewSystemObject(aJSContext, &xpcTempGlobalClass,
1138
+ nsnull, nsnull, system);
1139
+
1140
+ if(!tempGlobal ||
1141
+ !JS_SetParent(aJSContext, tempGlobal, nsnull) ||
1142
+ !JS_SetPrototype(aJSContext, tempGlobal, nsnull))
1143
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1144
+
1145
+ jsval v;
1146
+ nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
1147
+ {
1148
+ // Scope for our auto-marker; it just needs to keep tempGlobal alive
1149
+ // long enough for InitClasses and WrapNative to do their work
1150
+ AUTO_MARK_JSVAL(ccx, OBJECT_TO_JSVAL(tempGlobal));
1151
+
1152
+ if(NS_FAILED(InitClasses(aJSContext, tempGlobal)))
1153
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1154
+
1155
+ nsresult rv;
1156
+ if(!XPCConvert::NativeInterface2JSObject(ccx, &v,
1157
+ getter_AddRefs(holder),
1158
+ aCOMObj, &aIID, nsnull,
1159
+ nsnull, tempGlobal,
1160
+ PR_FALSE, OBJ_IS_GLOBAL, &rv))
1161
+ return UnexpectedFailure(rv);
1162
+
1163
+ NS_ASSERTION(NS_SUCCEEDED(rv) && holder, "Didn't wrap properly");
1164
+ }
1165
+
1166
+ JSObject* globalJSObj = JSVAL_TO_OBJECT(v);
1167
+ if(!globalJSObj)
1168
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1169
+
1170
+ if(aFlags & nsIXPConnect::FLAG_SYSTEM_GLOBAL_OBJECT)
1171
+ NS_ASSERTION(JS_IsSystemObject(aJSContext, globalJSObj), "huh?!");
1172
+
1173
+ // voodoo to fixup scoping and parenting...
1174
+
1175
+ JS_SetParent(aJSContext, globalJSObj, nsnull);
1176
+
1177
+ JSObject* oldGlobal = JS_GetGlobalObject(aJSContext);
1178
+ if(!oldGlobal || oldGlobal == tempGlobal)
1179
+ JS_SetGlobalObject(aJSContext, globalJSObj);
1180
+
1181
+ if((aFlags & nsIXPConnect::INIT_JS_STANDARD_CLASSES) &&
1182
+ !JS_InitStandardClasses(aJSContext, globalJSObj))
1183
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1184
+
1185
+ XPCWrappedNative* wrapper =
1186
+ reinterpret_cast<XPCWrappedNative*>(holder.get());
1187
+ XPCWrappedNativeScope* scope = wrapper->GetScope();
1188
+
1189
+ if(!scope)
1190
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1191
+
1192
+ NS_ASSERTION(scope->GetGlobalJSObject() == tempGlobal, "stealing scope!");
1193
+
1194
+ scope->SetGlobal(ccx, globalJSObj);
1195
+
1196
+ JSObject* protoJSObject = wrapper->HasProto() ?
1197
+ wrapper->GetProto()->GetJSProtoObject() :
1198
+ globalJSObj;
1199
+ if(protoJSObject)
1200
+ {
1201
+ if(protoJSObject != globalJSObj)
1202
+ JS_SetParent(aJSContext, protoJSObject, globalJSObj);
1203
+ JS_SetPrototype(aJSContext, protoJSObject, scope->GetPrototypeJSObject());
1204
+ }
1205
+
1206
+ if(!(aFlags & nsIXPConnect::OMIT_COMPONENTS_OBJECT)) {
1207
+ SaveFrame sf(ccx);
1208
+ if(!nsXPCComponents::AttachNewComponentsObject(ccx, scope, globalJSObj))
1209
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1210
+
1211
+ if(!XPCNativeWrapper::AttachNewConstructorObject(ccx, globalJSObj))
1212
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1213
+
1214
+ if(!XPC_SJOW_AttachNewConstructorObject(ccx, globalJSObj))
1215
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1216
+ }
1217
+
1218
+ NS_ADDREF(*_retval = holder);
1219
+
1220
+ return NS_OK;
1221
+ }
1222
+
1223
+ /* nsIXPConnectJSObjectHolder wrapNative (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDRef aIID); */
1224
+ NS_IMETHODIMP
1225
+ nsXPConnect::WrapNative(JSContext * aJSContext,
1226
+ JSObject * aScope,
1227
+ nsISupports *aCOMObj,
1228
+ const nsIID & aIID,
1229
+ nsIXPConnectJSObjectHolder **aHolder)
1230
+ {
1231
+ NS_ASSERTION(aHolder, "bad param");
1232
+
1233
+ jsval v;
1234
+ return WrapNativeToJSVal(aJSContext, aScope, aCOMObj, &aIID, &v, aHolder);
1235
+ }
1236
+
1237
+ /* void wrapNativeToJSVal (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDPtr aIID, out JSVal aVal, out nsIXPConnectJSObjectHolder aHolder); */
1238
+ NS_IMETHODIMP
1239
+ nsXPConnect::WrapNativeToJSVal(JSContext * aJSContext,
1240
+ JSObject * aScope,
1241
+ nsISupports *aCOMObj,
1242
+ const nsIID * aIID,
1243
+ jsval *aVal,
1244
+ nsIXPConnectJSObjectHolder **aHolder)
1245
+ {
1246
+ NS_ASSERTION(aJSContext, "bad param");
1247
+ NS_ASSERTION(aScope, "bad param");
1248
+ NS_ASSERTION(aCOMObj, "bad param");
1249
+
1250
+ if(aHolder)
1251
+ *aHolder = nsnull;
1252
+
1253
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1254
+ if(!ccx.IsValid())
1255
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1256
+
1257
+ nsresult rv;
1258
+ if(!XPCConvert::NativeInterface2JSObject(ccx, aVal, aHolder, aCOMObj, aIID,
1259
+ nsnull, nsnull, aScope, PR_FALSE,
1260
+ OBJ_IS_NOT_GLOBAL, &rv))
1261
+ return rv;
1262
+
1263
+ #ifdef DEBUG
1264
+ NS_ASSERTION(!XPCNativeWrapper::IsNativeWrapper(JSVAL_TO_OBJECT(*aVal)),
1265
+ "Shouldn't be returning a native wrapper here");
1266
+ #endif
1267
+
1268
+ return NS_OK;
1269
+ }
1270
+
1271
+ /* void wrapJS (in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */
1272
+ NS_IMETHODIMP
1273
+ nsXPConnect::WrapJS(JSContext * aJSContext,
1274
+ JSObject * aJSObj,
1275
+ const nsIID & aIID,
1276
+ void * *result)
1277
+ {
1278
+ NS_ASSERTION(aJSContext, "bad param");
1279
+ NS_ASSERTION(aJSObj, "bad param");
1280
+ NS_ASSERTION(result, "bad param");
1281
+
1282
+ *result = nsnull;
1283
+
1284
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1285
+ if(!ccx.IsValid())
1286
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1287
+
1288
+ nsresult rv;
1289
+ if(!XPCConvert::JSObject2NativeInterface(ccx, result, aJSObj,
1290
+ &aIID, nsnull, &rv))
1291
+ return rv;
1292
+ return NS_OK;
1293
+ }
1294
+
1295
+ /* void wrapJSAggregatedToNative (in nsISupports aOuter, in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */
1296
+ NS_IMETHODIMP
1297
+ nsXPConnect::WrapJSAggregatedToNative(nsISupports *aOuter,
1298
+ JSContext * aJSContext,
1299
+ JSObject * aJSObj,
1300
+ const nsIID & aIID,
1301
+ void * *result)
1302
+ {
1303
+ NS_ASSERTION(aOuter, "bad param");
1304
+ NS_ASSERTION(aJSContext, "bad param");
1305
+ NS_ASSERTION(aJSObj, "bad param");
1306
+ NS_ASSERTION(result, "bad param");
1307
+
1308
+ *result = nsnull;
1309
+
1310
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1311
+ if(!ccx.IsValid())
1312
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1313
+
1314
+ nsresult rv;
1315
+ if(!XPCConvert::JSObject2NativeInterface(ccx, result, aJSObj,
1316
+ &aIID, aOuter, &rv))
1317
+ return rv;
1318
+ return NS_OK;
1319
+ }
1320
+
1321
+ /* nsIXPConnectWrappedNative getWrappedNativeOfJSObject (in JSContextPtr aJSContext, in JSObjectPtr aJSObj); */
1322
+ NS_IMETHODIMP
1323
+ nsXPConnect::GetWrappedNativeOfJSObject(JSContext * aJSContext,
1324
+ JSObject * aJSObj,
1325
+ nsIXPConnectWrappedNative **_retval)
1326
+ {
1327
+ NS_ASSERTION(aJSContext, "bad param");
1328
+ NS_ASSERTION(aJSObj, "bad param");
1329
+ NS_ASSERTION(_retval, "bad param");
1330
+
1331
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1332
+ if(!ccx.IsValid())
1333
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1334
+
1335
+ nsIXPConnectWrappedNative* wrapper =
1336
+ XPCWrappedNative::GetWrappedNativeOfJSObject(aJSContext, aJSObj);
1337
+ if(wrapper)
1338
+ {
1339
+ NS_ADDREF(wrapper);
1340
+ *_retval = wrapper;
1341
+ return NS_OK;
1342
+ }
1343
+ // else...
1344
+ *_retval = nsnull;
1345
+ return NS_ERROR_FAILURE;
1346
+ }
1347
+
1348
+ /* nsIXPConnectWrappedNative getWrappedNativeOfNativeObject (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDRef aIID); */
1349
+ NS_IMETHODIMP
1350
+ nsXPConnect::GetWrappedNativeOfNativeObject(JSContext * aJSContext,
1351
+ JSObject * aScope,
1352
+ nsISupports *aCOMObj,
1353
+ const nsIID & aIID,
1354
+ nsIXPConnectWrappedNative **_retval)
1355
+ {
1356
+ NS_ASSERTION(aJSContext, "bad param");
1357
+ NS_ASSERTION(aScope, "bad param");
1358
+ NS_ASSERTION(aCOMObj, "bad param");
1359
+ NS_ASSERTION(_retval, "bad param");
1360
+
1361
+ *_retval = nsnull;
1362
+
1363
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1364
+ if(!ccx.IsValid())
1365
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1366
+
1367
+ XPCWrappedNativeScope* scope =
1368
+ XPCWrappedNativeScope::FindInJSObjectScope(ccx, aScope);
1369
+ if(!scope)
1370
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1371
+
1372
+ AutoMarkingNativeInterfacePtr iface(ccx);
1373
+ iface = XPCNativeInterface::GetNewOrUsed(ccx, &aIID);
1374
+ if(!iface)
1375
+ return NS_ERROR_FAILURE;
1376
+
1377
+ XPCWrappedNative* wrapper;
1378
+
1379
+ nsresult rv = XPCWrappedNative::GetUsedOnly(ccx, aCOMObj, scope, iface,
1380
+ &wrapper);
1381
+ if(NS_FAILED(rv))
1382
+ return NS_ERROR_FAILURE;
1383
+ *_retval = static_cast<nsIXPConnectWrappedNative*>(wrapper);
1384
+ return NS_OK;
1385
+ }
1386
+
1387
+ /* nsIXPConnectJSObjectHolder reparentWrappedNativeIfFound (in JSContextPtr aJSContext, in JSObjectPtr aScope, in JSObjectPtr aNewParent, in nsISupports aCOMObj); */
1388
+ NS_IMETHODIMP
1389
+ nsXPConnect::ReparentWrappedNativeIfFound(JSContext * aJSContext,
1390
+ JSObject * aScope,
1391
+ JSObject * aNewParent,
1392
+ nsISupports *aCOMObj,
1393
+ nsIXPConnectJSObjectHolder **_retval)
1394
+ {
1395
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1396
+ if(!ccx.IsValid())
1397
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1398
+
1399
+ XPCWrappedNativeScope* scope =
1400
+ XPCWrappedNativeScope::FindInJSObjectScope(ccx, aScope);
1401
+ if(!scope)
1402
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1403
+
1404
+ XPCWrappedNativeScope* scope2 =
1405
+ XPCWrappedNativeScope::FindInJSObjectScope(ccx, aNewParent);
1406
+ if(!scope2)
1407
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1408
+
1409
+ return XPCWrappedNative::
1410
+ ReparentWrapperIfFound(ccx, scope, scope2, aNewParent, aCOMObj,
1411
+ (XPCWrappedNative**) _retval);
1412
+ }
1413
+
1414
+ static JSDHashOperator
1415
+ MoveableWrapperFinder(JSDHashTable *table, JSDHashEntryHdr *hdr,
1416
+ uint32 number, void *arg)
1417
+ {
1418
+ // Every element counts.
1419
+ nsVoidArray *va = static_cast<nsVoidArray *>(arg);
1420
+ va->AppendElement(((Native2WrappedNativeMap::Entry*)hdr)->value);
1421
+ return JS_DHASH_NEXT;
1422
+ }
1423
+
1424
+ /* void reparentScopeAwareWrappers(in JSContextPtr aJSContext, in JSObjectPtr aOldScope, in JSObjectPtr aNewScope); */
1425
+ NS_IMETHODIMP
1426
+ nsXPConnect::ReparentScopeAwareWrappers(JSContext *aJSContext,
1427
+ JSObject *aOldScope,
1428
+ JSObject *aNewScope)
1429
+ {
1430
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1431
+ if(!ccx.IsValid())
1432
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1433
+
1434
+ XPCWrappedNativeScope *oldScope =
1435
+ XPCWrappedNativeScope::FindInJSObjectScope(ccx, aOldScope);
1436
+ if(!oldScope)
1437
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1438
+
1439
+ XPCWrappedNativeScope *newScope =
1440
+ XPCWrappedNativeScope::FindInJSObjectScope(ccx, aNewScope);
1441
+ if(!newScope)
1442
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1443
+
1444
+ // First, look through the old scope and find all of the wrappers that
1445
+ // we're going to move.
1446
+ nsVoidArray wrappersToMove;
1447
+
1448
+ { // scoped lock
1449
+ XPCAutoLock lock(GetRuntime()->GetMapLock());
1450
+ Native2WrappedNativeMap *map = oldScope->GetWrappedNativeMap();
1451
+ wrappersToMove.SizeTo(map->Count());
1452
+ map->Enumerate(MoveableWrapperFinder, &wrappersToMove);
1453
+ }
1454
+
1455
+ // Now that we have the wrappers, reparent them to the new scope.
1456
+ for(PRInt32 i = 0, stop = wrappersToMove.Count(); i < stop; ++i)
1457
+ {
1458
+ // First, check to see if this wrapper really needs to be
1459
+ // reparented.
1460
+
1461
+ XPCWrappedNative *wrapper =
1462
+ static_cast<XPCWrappedNative *>(wrappersToMove[i]);
1463
+ nsISupports *identity = wrapper->GetIdentityObject();
1464
+ nsCOMPtr<nsIClassInfo> info(do_QueryInterface(identity));
1465
+
1466
+ // ClassInfo is implemented as singleton objects. If the identity
1467
+ // object here is the same object as returned by the QI, then it
1468
+ // is the singleton classinfo, so we don't need to reparent it.
1469
+ if(SameCOMIdentity(identity, info))
1470
+ info = nsnull;
1471
+
1472
+ if(!info)
1473
+ continue;
1474
+
1475
+ XPCNativeScriptableCreateInfo sciProto;
1476
+ XPCNativeScriptableCreateInfo sciWrapper;
1477
+
1478
+ nsresult rv =
1479
+ XPCWrappedNative::GatherScriptableCreateInfo(identity,
1480
+ info.get(),
1481
+ &sciProto,
1482
+ &sciWrapper);
1483
+ if(NS_FAILED(rv))
1484
+ return NS_ERROR_FAILURE;
1485
+
1486
+ // If the wrapper doesn't want precreate, then we don't need to
1487
+ // worry about reparenting it.
1488
+ if(!sciWrapper.GetFlags().WantPreCreate())
1489
+ continue;
1490
+
1491
+ JSObject *newParent = aOldScope;
1492
+ rv = sciWrapper.GetCallback()->PreCreate(identity, ccx, aOldScope,
1493
+ &newParent);
1494
+ if(NS_FAILED(rv))
1495
+ return rv;
1496
+
1497
+ if(newParent != aOldScope)
1498
+ {
1499
+ // The wrapper returned a new parent. If the new parent is in
1500
+ // a different scope, then we need to reparent it, otherwise,
1501
+ // the old scope is fine.
1502
+
1503
+ XPCWrappedNativeScope *betterScope =
1504
+ XPCWrappedNativeScope::FindInJSObjectScope(ccx, newParent);
1505
+ if(betterScope == oldScope)
1506
+ continue;
1507
+
1508
+ NS_ASSERTION(betterScope == newScope, "Weird scope returned");
1509
+ }
1510
+ else
1511
+ {
1512
+ // The old scope still works for this wrapper.
1513
+ continue;
1514
+ }
1515
+
1516
+ // Now, reparent the wrapper, since we know that it wants to be
1517
+ // reparented.
1518
+
1519
+ nsRefPtr<XPCWrappedNative> junk;
1520
+ rv = XPCWrappedNative::ReparentWrapperIfFound(ccx, oldScope,
1521
+ newScope, newParent,
1522
+ wrapper->GetIdentityObject(),
1523
+ getter_AddRefs(junk));
1524
+ NS_ENSURE_SUCCESS(rv, rv);
1525
+ }
1526
+
1527
+ return NS_OK;
1528
+ }
1529
+
1530
+ /* void setSecurityManagerForJSContext (in JSContextPtr aJSContext, in nsIXPCSecurityManager aManager, in PRUint16 flags); */
1531
+ NS_IMETHODIMP
1532
+ nsXPConnect::SetSecurityManagerForJSContext(JSContext * aJSContext,
1533
+ nsIXPCSecurityManager *aManager,
1534
+ PRUint16 flags)
1535
+ {
1536
+ NS_ASSERTION(aJSContext, "bad param");
1537
+
1538
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1539
+ if(!ccx.IsValid())
1540
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1541
+
1542
+ XPCContext* xpcc = ccx.GetXPCContext();
1543
+
1544
+ NS_IF_ADDREF(aManager);
1545
+ nsIXPCSecurityManager* oldManager = xpcc->GetSecurityManager();
1546
+ NS_IF_RELEASE(oldManager);
1547
+
1548
+ xpcc->SetSecurityManager(aManager);
1549
+ xpcc->SetSecurityManagerFlags(flags);
1550
+ return NS_OK;
1551
+ }
1552
+
1553
+ /* void getSecurityManagerForJSContext (in JSContextPtr aJSContext, out nsIXPCSecurityManager aManager, out PRUint16 flags); */
1554
+ NS_IMETHODIMP
1555
+ nsXPConnect::GetSecurityManagerForJSContext(JSContext * aJSContext,
1556
+ nsIXPCSecurityManager **aManager,
1557
+ PRUint16 *flags)
1558
+ {
1559
+ NS_ASSERTION(aJSContext, "bad param");
1560
+ NS_ASSERTION(aManager, "bad param");
1561
+ NS_ASSERTION(flags, "bad param");
1562
+
1563
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1564
+ if(!ccx.IsValid())
1565
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1566
+
1567
+ XPCContext* xpcc = ccx.GetXPCContext();
1568
+
1569
+ nsIXPCSecurityManager* manager = xpcc->GetSecurityManager();
1570
+ NS_IF_ADDREF(manager);
1571
+ *aManager = manager;
1572
+ *flags = xpcc->GetSecurityManagerFlags();
1573
+ return NS_OK;
1574
+ }
1575
+
1576
+ /* void setDefaultSecurityManager (in nsIXPCSecurityManager aManager, in PRUint16 flags); */
1577
+ NS_IMETHODIMP
1578
+ nsXPConnect::SetDefaultSecurityManager(nsIXPCSecurityManager *aManager,
1579
+ PRUint16 flags)
1580
+ {
1581
+ NS_IF_ADDREF(aManager);
1582
+ NS_IF_RELEASE(mDefaultSecurityManager);
1583
+ mDefaultSecurityManager = aManager;
1584
+ mDefaultSecurityManagerFlags = flags;
1585
+
1586
+ nsCOMPtr<nsIScriptSecurityManager> ssm =
1587
+ do_QueryInterface(mDefaultSecurityManager);
1588
+
1589
+ // Remember the result of the above QI for fast access to the
1590
+ // script securityt manager.
1591
+ gScriptSecurityManager = ssm;
1592
+
1593
+ return NS_OK;
1594
+ }
1595
+
1596
+ /* void getDefaultSecurityManager (out nsIXPCSecurityManager aManager, out PRUint16 flags); */
1597
+ NS_IMETHODIMP
1598
+ nsXPConnect::GetDefaultSecurityManager(nsIXPCSecurityManager **aManager,
1599
+ PRUint16 *flags)
1600
+ {
1601
+ NS_ASSERTION(aManager, "bad param");
1602
+ NS_ASSERTION(flags, "bad param");
1603
+
1604
+ NS_IF_ADDREF(mDefaultSecurityManager);
1605
+ *aManager = mDefaultSecurityManager;
1606
+ *flags = mDefaultSecurityManagerFlags;
1607
+ return NS_OK;
1608
+ }
1609
+
1610
+ /* nsIStackFrame createStackFrameLocation (in PRUint32 aLanguage, in string aFilename, in string aFunctionName, in PRInt32 aLineNumber, in nsIStackFrame aCaller); */
1611
+ NS_IMETHODIMP
1612
+ nsXPConnect::CreateStackFrameLocation(PRUint32 aLanguage,
1613
+ const char *aFilename,
1614
+ const char *aFunctionName,
1615
+ PRInt32 aLineNumber,
1616
+ nsIStackFrame *aCaller,
1617
+ nsIStackFrame **_retval)
1618
+ {
1619
+ NS_ASSERTION(_retval, "bad param");
1620
+
1621
+ return XPCJSStack::CreateStackFrameLocation(aLanguage,
1622
+ aFilename,
1623
+ aFunctionName,
1624
+ aLineNumber,
1625
+ aCaller,
1626
+ _retval);
1627
+ }
1628
+
1629
+ /* readonly attribute nsIStackFrame CurrentJSStack; */
1630
+ NS_IMETHODIMP
1631
+ nsXPConnect::GetCurrentJSStack(nsIStackFrame * *aCurrentJSStack)
1632
+ {
1633
+ NS_ASSERTION(aCurrentJSStack, "bad param");
1634
+ *aCurrentJSStack = nsnull;
1635
+
1636
+ JSContext* cx;
1637
+ // is there a current context available?
1638
+ if(NS_SUCCEEDED(Peek(&cx)) && cx)
1639
+ {
1640
+ nsCOMPtr<nsIStackFrame> stack;
1641
+ XPCJSStack::CreateStack(cx, getter_AddRefs(stack));
1642
+ if(stack)
1643
+ {
1644
+ // peel off native frames...
1645
+ PRUint32 language;
1646
+ nsCOMPtr<nsIStackFrame> caller;
1647
+ while(stack &&
1648
+ NS_SUCCEEDED(stack->GetLanguage(&language)) &&
1649
+ language != nsIProgrammingLanguage::JAVASCRIPT &&
1650
+ NS_SUCCEEDED(stack->GetCaller(getter_AddRefs(caller))) &&
1651
+ caller)
1652
+ {
1653
+ stack = caller;
1654
+ }
1655
+ NS_IF_ADDREF(*aCurrentJSStack = stack);
1656
+ }
1657
+ }
1658
+ return NS_OK;
1659
+ }
1660
+
1661
+ /* readonly attribute nsIXPCNativeCallContext CurrentNativeCallContext; */
1662
+ NS_IMETHODIMP
1663
+ nsXPConnect::GetCurrentNativeCallContext(nsAXPCNativeCallContext * *aCurrentNativeCallContext)
1664
+ {
1665
+ NS_ASSERTION(aCurrentNativeCallContext, "bad param");
1666
+
1667
+ XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
1668
+ if(data)
1669
+ {
1670
+ *aCurrentNativeCallContext = data->GetCallContext();
1671
+ return NS_OK;
1672
+ }
1673
+ //else...
1674
+ *aCurrentNativeCallContext = nsnull;
1675
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1676
+ }
1677
+
1678
+ /* attribute nsIException PendingException; */
1679
+ NS_IMETHODIMP
1680
+ nsXPConnect::GetPendingException(nsIException * *aPendingException)
1681
+ {
1682
+ NS_ASSERTION(aPendingException, "bad param");
1683
+
1684
+ XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
1685
+ if(!data)
1686
+ {
1687
+ *aPendingException = nsnull;
1688
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1689
+ }
1690
+
1691
+ return data->GetException(aPendingException);
1692
+ }
1693
+
1694
+ NS_IMETHODIMP
1695
+ nsXPConnect::SetPendingException(nsIException * aPendingException)
1696
+ {
1697
+ XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
1698
+ if(!data)
1699
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1700
+
1701
+ data->SetException(aPendingException);
1702
+ return NS_OK;
1703
+ }
1704
+
1705
+ NS_IMETHODIMP
1706
+ nsXPConnect::SyncJSContexts(void)
1707
+ {
1708
+ // Do-nothing compatibility function
1709
+ return NS_OK;
1710
+ }
1711
+
1712
+ /* nsIXPCFunctionThisTranslator setFunctionThisTranslator (in nsIIDRef aIID, in nsIXPCFunctionThisTranslator aTranslator); */
1713
+ NS_IMETHODIMP
1714
+ nsXPConnect::SetFunctionThisTranslator(const nsIID & aIID,
1715
+ nsIXPCFunctionThisTranslator *aTranslator,
1716
+ nsIXPCFunctionThisTranslator **_retval)
1717
+ {
1718
+ XPCJSRuntime* rt = GetRuntime();
1719
+ nsIXPCFunctionThisTranslator* old;
1720
+ IID2ThisTranslatorMap* map = rt->GetThisTranslatorMap();
1721
+
1722
+ {
1723
+ XPCAutoLock lock(rt->GetMapLock()); // scoped lock
1724
+ if(_retval)
1725
+ {
1726
+ old = map->Find(aIID);
1727
+ NS_IF_ADDREF(old);
1728
+ *_retval = old;
1729
+ }
1730
+ map->Add(aIID, aTranslator);
1731
+ }
1732
+ return NS_OK;
1733
+ }
1734
+
1735
+ /* nsIXPCFunctionThisTranslator getFunctionThisTranslator (in nsIIDRef aIID); */
1736
+ NS_IMETHODIMP
1737
+ nsXPConnect::GetFunctionThisTranslator(const nsIID & aIID,
1738
+ nsIXPCFunctionThisTranslator **_retval)
1739
+ {
1740
+ XPCJSRuntime* rt = GetRuntime();
1741
+ nsIXPCFunctionThisTranslator* old;
1742
+ IID2ThisTranslatorMap* map = rt->GetThisTranslatorMap();
1743
+
1744
+ {
1745
+ XPCAutoLock lock(rt->GetMapLock()); // scoped lock
1746
+ old = map->Find(aIID);
1747
+ NS_IF_ADDREF(old);
1748
+ *_retval = old;
1749
+ }
1750
+ return NS_OK;
1751
+ }
1752
+
1753
+ /* void setSafeJSContextForCurrentThread (in JSContextPtr cx); */
1754
+ NS_IMETHODIMP
1755
+ nsXPConnect::SetSafeJSContextForCurrentThread(JSContext * cx)
1756
+ {
1757
+ XPCCallContext ccx(NATIVE_CALLER);
1758
+ if(!ccx.IsValid())
1759
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1760
+ return ccx.GetThreadData()->GetJSContextStack()->SetSafeJSContext(cx);
1761
+ }
1762
+
1763
+ /* void clearAllWrappedNativeSecurityPolicies (); */
1764
+ NS_IMETHODIMP
1765
+ nsXPConnect::ClearAllWrappedNativeSecurityPolicies()
1766
+ {
1767
+ XPCCallContext ccx(NATIVE_CALLER);
1768
+ if(!ccx.IsValid())
1769
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1770
+
1771
+ return XPCWrappedNativeScope::ClearAllWrappedNativeSecurityPolicies(ccx);
1772
+ }
1773
+
1774
+ /* void restoreWrappedNativePrototype (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsIClassInfo aClassInfo, in nsIXPConnectJSObjectHolder aPrototype); */
1775
+ NS_IMETHODIMP
1776
+ nsXPConnect::RestoreWrappedNativePrototype(JSContext * aJSContext,
1777
+ JSObject * aScope,
1778
+ nsIClassInfo * aClassInfo,
1779
+ nsIXPConnectJSObjectHolder * aPrototype)
1780
+ {
1781
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1782
+ if(!ccx.IsValid())
1783
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1784
+
1785
+ if(!aClassInfo || !aPrototype)
1786
+ return UnexpectedFailure(NS_ERROR_INVALID_ARG);
1787
+
1788
+ JSObject *protoJSObject;
1789
+ nsresult rv = aPrototype->GetJSObject(&protoJSObject);
1790
+ if(NS_FAILED(rv))
1791
+ return UnexpectedFailure(rv);
1792
+
1793
+ if(!IS_PROTO_CLASS(STOBJ_GET_CLASS(protoJSObject)))
1794
+ return UnexpectedFailure(NS_ERROR_INVALID_ARG);
1795
+
1796
+ XPCWrappedNativeScope* scope =
1797
+ XPCWrappedNativeScope::FindInJSObjectScope(ccx, aScope);
1798
+ if(!scope)
1799
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1800
+
1801
+ XPCWrappedNativeProto *proto =
1802
+ (XPCWrappedNativeProto*)xpc_GetJSPrivate(protoJSObject);
1803
+ if(!proto)
1804
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1805
+
1806
+ if(scope != proto->GetScope())
1807
+ {
1808
+ NS_ERROR("Attempt to reset prototype to a prototype from a"
1809
+ "different scope!");
1810
+
1811
+ return UnexpectedFailure(NS_ERROR_INVALID_ARG);
1812
+ }
1813
+
1814
+ XPCNativeScriptableInfo *si = proto->GetScriptableInfo();
1815
+
1816
+ if(si && si->GetFlags().DontSharePrototype())
1817
+ return UnexpectedFailure(NS_ERROR_INVALID_ARG);
1818
+
1819
+ ClassInfo2WrappedNativeProtoMap* map = scope->GetWrappedNativeProtoMap();
1820
+ XPCLock* lock = GetRuntime()->GetMapLock();
1821
+
1822
+ { // scoped lock
1823
+ XPCAutoLock al(lock);
1824
+
1825
+ XPCWrappedNativeProtoMap* detachedMap =
1826
+ GetRuntime()->GetDetachedWrappedNativeProtoMap();
1827
+
1828
+ // If we're replacing an old proto, make sure to put it on the
1829
+ // map of detached wrapped native protos so that the old proto
1830
+ // gets properly cleaned up, especially during shutdown.
1831
+ XPCWrappedNativeProto *oldProto = map->Find(aClassInfo);
1832
+ if(oldProto)
1833
+ {
1834
+ detachedMap->Add(oldProto);
1835
+
1836
+ // ClassInfo2WrappedNativeProtoMap doesn't ever replace
1837
+ // entries in the map, so now since we know there's an
1838
+ // entry for aClassInfo in the map we have to remove it to
1839
+ // be able to add the new one.
1840
+ map->Remove(aClassInfo);
1841
+
1842
+ // This code should do the right thing even if we're
1843
+ // restoring the current proto, but warn in that case
1844
+ // since doing that is pointless.
1845
+ NS_ASSERTION(proto != oldProto,
1846
+ "Restoring current prototype, fix caller!");
1847
+ }
1848
+
1849
+ map->Add(aClassInfo, proto);
1850
+
1851
+ // Remove the prototype from the map of detached wrapped
1852
+ // native prototypes now that the prototype is part of a scope
1853
+ // again.
1854
+ detachedMap->Remove(proto);
1855
+ }
1856
+
1857
+ // The global in this scope didn't change, but a prototype did
1858
+ // (most likely the global object's prototype), which means the
1859
+ // scope needs to get a chance to update its cached
1860
+ // Object.prototype pointers etc.
1861
+ scope->SetGlobal(ccx, aScope);
1862
+
1863
+ return NS_OK;
1864
+ }
1865
+
1866
+ NS_IMETHODIMP
1867
+ nsXPConnect::CreateSandbox(JSContext *cx, nsIPrincipal *principal,
1868
+ nsIXPConnectJSObjectHolder **_retval)
1869
+ {
1870
+ #ifdef XPCONNECT_STANDALONE
1871
+ return NS_ERROR_NOT_AVAILABLE;
1872
+ #else /* XPCONNECT_STANDALONE */
1873
+ XPCCallContext ccx(NATIVE_CALLER, cx);
1874
+ if(!ccx.IsValid())
1875
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1876
+
1877
+ *_retval = nsnull;
1878
+
1879
+ jsval rval = JSVAL_VOID;
1880
+ AUTO_MARK_JSVAL(ccx, &rval);
1881
+
1882
+ nsresult rv = xpc_CreateSandboxObject(cx, &rval, principal);
1883
+ NS_ASSERTION(NS_FAILED(rv) || !JSVAL_IS_PRIMITIVE(rval),
1884
+ "Bad return value from xpc_CreateSandboxObject()!");
1885
+
1886
+ if (NS_SUCCEEDED(rv) && !JSVAL_IS_PRIMITIVE(rval)) {
1887
+ *_retval = XPCJSObjectHolder::newHolder(ccx, JSVAL_TO_OBJECT(rval));
1888
+ NS_ENSURE_TRUE(*_retval, NS_ERROR_OUT_OF_MEMORY);
1889
+
1890
+ NS_ADDREF(*_retval);
1891
+ }
1892
+
1893
+ return rv;
1894
+ #endif /* XPCONNECT_STANDALONE */
1895
+ }
1896
+
1897
+ NS_IMETHODIMP
1898
+ nsXPConnect::EvalInSandboxObject(const nsAString& source, JSContext *cx,
1899
+ nsIXPConnectJSObjectHolder *sandbox,
1900
+ PRBool returnStringOnly, jsval *rval)
1901
+ {
1902
+ #ifdef XPCONNECT_STANDALONE
1903
+ return NS_ERROR_NOT_AVAILABLE;
1904
+ #else /* XPCONNECT_STANDALONE */
1905
+ if (!sandbox)
1906
+ return NS_ERROR_INVALID_ARG;
1907
+
1908
+ JSObject *obj;
1909
+ nsresult rv = sandbox->GetJSObject(&obj);
1910
+ NS_ENSURE_SUCCESS(rv, rv);
1911
+
1912
+ return xpc_EvalInSandbox(cx, obj, source,
1913
+ NS_ConvertUTF16toUTF8(source).get(), 1,
1914
+ JSVERSION_DEFAULT, returnStringOnly, rval);
1915
+ #endif /* XPCONNECT_STANDALONE */
1916
+ }
1917
+
1918
+ /* void GetXPCWrappedNativeJSClassInfo(out JSClassConstPtr clazz, out JSObjectOpsConstPtr ops1, out JSObjectOpsConstPtr ops2); */
1919
+ NS_IMETHODIMP
1920
+ nsXPConnect::GetXPCWrappedNativeJSClassInfo(const JSClass **clazz,
1921
+ JSGetObjectOps *ops1,
1922
+ JSGetObjectOps *ops2)
1923
+ {
1924
+ // Expose the JSClass and JSGetObjectOps pointers used by
1925
+ // IS_WRAPPER_CLASS(). If that macro ever changes, this function
1926
+ // needs to stay in sync.
1927
+
1928
+ *clazz = &XPC_WN_NoHelper_JSClass.base;
1929
+ *ops1 = XPC_WN_GetObjectOpsNoCall;
1930
+ *ops2 = XPC_WN_GetObjectOpsWithCall;
1931
+
1932
+ return NS_OK;
1933
+ }
1934
+
1935
+ /* nsIXPConnectJSObjectHolder getWrappedNativePrototype (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsIClassInfo aClassInfo); */
1936
+ NS_IMETHODIMP
1937
+ nsXPConnect::GetWrappedNativePrototype(JSContext * aJSContext,
1938
+ JSObject * aScope,
1939
+ nsIClassInfo *aClassInfo,
1940
+ nsIXPConnectJSObjectHolder **_retval)
1941
+ {
1942
+ XPCCallContext ccx(NATIVE_CALLER, aJSContext);
1943
+ if(!ccx.IsValid())
1944
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1945
+
1946
+ XPCWrappedNativeScope* scope =
1947
+ XPCWrappedNativeScope::FindInJSObjectScope(ccx, aScope);
1948
+ if(!scope)
1949
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1950
+
1951
+ XPCNativeScriptableCreateInfo sciProto;
1952
+ XPCWrappedNative::GatherProtoScriptableCreateInfo(aClassInfo, &sciProto);
1953
+
1954
+ AutoMarkingWrappedNativeProtoPtr proto(ccx);
1955
+ proto = XPCWrappedNativeProto::GetNewOrUsed(ccx, scope, aClassInfo,
1956
+ &sciProto, JS_FALSE,
1957
+ OBJ_IS_NOT_GLOBAL);
1958
+ if(!proto)
1959
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1960
+
1961
+ nsIXPConnectJSObjectHolder* holder;
1962
+ *_retval = holder = XPCJSObjectHolder::newHolder(ccx,
1963
+ proto->GetJSProtoObject());
1964
+ if(!holder)
1965
+ return UnexpectedFailure(NS_ERROR_FAILURE);
1966
+
1967
+ NS_ADDREF(holder);
1968
+ return NS_OK;
1969
+ }
1970
+
1971
+ /* [noscript] JSVal GetCrossOriginWrapperForValue(in JSContextPtr aJSContext, in JSVal aCurrentVal); */
1972
+ NS_IMETHODIMP
1973
+ nsXPConnect::GetXOWForObject(JSContext * aJSContext,
1974
+ JSObject * aParent,
1975
+ JSObject * aWrappedObj,
1976
+ jsval * rval)
1977
+ {
1978
+ *rval = OBJECT_TO_JSVAL(aWrappedObj);
1979
+ return XPC_XOW_WrapObject(aJSContext, aParent, rval)
1980
+ ? NS_OK : NS_ERROR_FAILURE;
1981
+ }
1982
+
1983
+ static inline PRBool
1984
+ PerformOp(JSContext *cx, PRUint32 aWay, JSObject *obj)
1985
+ {
1986
+ NS_ASSERTION(aWay == nsIXPConnect::XPC_XOW_CLEARSCOPE,
1987
+ "Nothing else is implemented yet");
1988
+
1989
+ JS_ClearScope(cx, obj);
1990
+ return PR_TRUE;
1991
+ }
1992
+
1993
+ /* [noscript] void updateXOWs (in JSContextPtr aJSContext,
1994
+ * in nsIXPConnectJSObjectHolder aObject,
1995
+ * in PRUint32 aWay); */
1996
+ NS_IMETHODIMP
1997
+ nsXPConnect::UpdateXOWs(JSContext* aJSContext,
1998
+ nsIXPConnectWrappedNative* aObject,
1999
+ PRUint32 aWay)
2000
+ {
2001
+ typedef WrappedNative2WrapperMap::Link Link;
2002
+ XPCWrappedNative* wn = static_cast<XPCWrappedNative *>(aObject);
2003
+ XPCWrappedNativeScope* scope = wn->GetScope();
2004
+ WrappedNative2WrapperMap* map = scope->GetWrapperMap();
2005
+ Link* list;
2006
+
2007
+ {
2008
+ XPCAutoLock al(GetRuntime()->GetMapLock());
2009
+
2010
+ list = map->FindLink(wn->GetFlatJSObject());
2011
+ }
2012
+
2013
+ if(!list)
2014
+ return NS_OK; // No wrappers to update.
2015
+
2016
+ AutoJSRequestWithNoCallContext req(aJSContext);
2017
+
2018
+ Link* cur = list;
2019
+ if(cur->obj && !PerformOp(aJSContext, aWay, cur->obj))
2020
+ return NS_ERROR_FAILURE;
2021
+
2022
+ for(cur = (Link *)PR_NEXT_LINK(list); cur != list;
2023
+ cur = (Link *)PR_NEXT_LINK(cur))
2024
+ {
2025
+ if(!PerformOp(aJSContext, aWay, cur->obj))
2026
+ return NS_ERROR_FAILURE;
2027
+ }
2028
+
2029
+ return NS_OK;
2030
+ }
2031
+
2032
+ /* void releaseJSContext (in JSContextPtr aJSContext, in PRBool noGC); */
2033
+ NS_IMETHODIMP
2034
+ nsXPConnect::ReleaseJSContext(JSContext * aJSContext, PRBool noGC)
2035
+ {
2036
+ NS_ASSERTION(aJSContext, "bad param");
2037
+ XPCPerThreadData* tls = XPCPerThreadData::GetData(aJSContext);
2038
+ if(tls)
2039
+ {
2040
+ XPCCallContext* ccx = nsnull;
2041
+ for(XPCCallContext* cur = tls->GetCallContext();
2042
+ cur;
2043
+ cur = cur->GetPrevCallContext())
2044
+ {
2045
+ if(cur->GetJSContext() == aJSContext)
2046
+ {
2047
+ ccx = cur;
2048
+ // Keep looping to find the deepest matching call context.
2049
+ }
2050
+ }
2051
+
2052
+ if(ccx)
2053
+ {
2054
+ #ifdef DEBUG_xpc_hacker
2055
+ printf("!xpc - deferring destruction of JSContext @ %p\n",
2056
+ (void *)aJSContext);
2057
+ #endif
2058
+ ccx->SetDestroyJSContextInDestructor(JS_TRUE);
2059
+ JS_ClearNewbornRoots(aJSContext);
2060
+ return NS_OK;
2061
+ }
2062
+ // else continue on and synchronously destroy the JSContext ...
2063
+
2064
+ NS_ASSERTION(!tls->GetJSContextStack() ||
2065
+ !tls->GetJSContextStack()->
2066
+ DEBUG_StackHasJSContext(aJSContext),
2067
+ "JSContext still in threadjscontextstack!");
2068
+ }
2069
+
2070
+ if(noGC)
2071
+ JS_DestroyContextNoGC(aJSContext);
2072
+ else
2073
+ JS_DestroyContext(aJSContext);
2074
+ return NS_OK;
2075
+ }
2076
+
2077
+ /* void debugDump (in short depth); */
2078
+ NS_IMETHODIMP
2079
+ nsXPConnect::DebugDump(PRInt16 depth)
2080
+ {
2081
+ #ifdef DEBUG
2082
+ depth-- ;
2083
+ XPC_LOG_ALWAYS(("nsXPConnect @ %x with mRefCnt = %d", this, mRefCnt.get()));
2084
+ XPC_LOG_INDENT();
2085
+ XPC_LOG_ALWAYS(("gSelf @ %x", gSelf));
2086
+ XPC_LOG_ALWAYS(("gOnceAliveNowDead is %d", (int)gOnceAliveNowDead));
2087
+ XPC_LOG_ALWAYS(("mDefaultSecurityManager @ %x", mDefaultSecurityManager));
2088
+ XPC_LOG_ALWAYS(("mDefaultSecurityManagerFlags of %x", mDefaultSecurityManagerFlags));
2089
+ XPC_LOG_ALWAYS(("mInterfaceInfoManager @ %x", mInterfaceInfoManager.get()));
2090
+ if(mRuntime)
2091
+ {
2092
+ if(depth)
2093
+ mRuntime->DebugDump(depth);
2094
+ else
2095
+ XPC_LOG_ALWAYS(("XPCJSRuntime @ %x", mRuntime));
2096
+ }
2097
+ else
2098
+ XPC_LOG_ALWAYS(("mRuntime is null"));
2099
+ XPCWrappedNativeScope::DebugDumpAllScopes(depth);
2100
+ XPC_LOG_OUTDENT();
2101
+ #endif
2102
+ return NS_OK;
2103
+ }
2104
+
2105
+ /* void debugDumpObject (in nsISupports aCOMObj, in short depth); */
2106
+ NS_IMETHODIMP
2107
+ nsXPConnect::DebugDumpObject(nsISupports *p, PRInt16 depth)
2108
+ {
2109
+ #ifdef DEBUG
2110
+ if(!depth)
2111
+ return NS_OK;
2112
+ if(!p)
2113
+ {
2114
+ XPC_LOG_ALWAYS(("*** Cound not dump object with NULL address"));
2115
+ return NS_OK;
2116
+ }
2117
+
2118
+ nsIXPConnect* xpc;
2119
+ nsIXPCWrappedJSClass* wjsc;
2120
+ nsIXPConnectWrappedNative* wn;
2121
+ nsIXPConnectWrappedJS* wjs;
2122
+
2123
+ if(NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnect),
2124
+ (void**)&xpc)))
2125
+ {
2126
+ XPC_LOG_ALWAYS(("Dumping a nsIXPConnect..."));
2127
+ xpc->DebugDump(depth);
2128
+ NS_RELEASE(xpc);
2129
+ }
2130
+ else if(NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPCWrappedJSClass),
2131
+ (void**)&wjsc)))
2132
+ {
2133
+ XPC_LOG_ALWAYS(("Dumping a nsIXPCWrappedJSClass..."));
2134
+ wjsc->DebugDump(depth);
2135
+ NS_RELEASE(wjsc);
2136
+ }
2137
+ else if(NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedNative),
2138
+ (void**)&wn)))
2139
+ {
2140
+ XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedNative..."));
2141
+ wn->DebugDump(depth);
2142
+ NS_RELEASE(wn);
2143
+ }
2144
+ else if(NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedJS),
2145
+ (void**)&wjs)))
2146
+ {
2147
+ XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedJS..."));
2148
+ wjs->DebugDump(depth);
2149
+ NS_RELEASE(wjs);
2150
+ }
2151
+ else
2152
+ XPC_LOG_ALWAYS(("*** Could not dump the nsISupports @ %x", p));
2153
+ #endif
2154
+ return NS_OK;
2155
+ }
2156
+
2157
+ /* void debugDumpJSStack (in PRBool showArgs, in PRBool showLocals, in PRBool showThisProps); */
2158
+ NS_IMETHODIMP
2159
+ nsXPConnect::DebugDumpJSStack(PRBool showArgs,
2160
+ PRBool showLocals,
2161
+ PRBool showThisProps)
2162
+ {
2163
+ JSContext* cx;
2164
+ if(NS_FAILED(Peek(&cx)))
2165
+ printf("failed to peek into nsIThreadJSContextStack service!\n");
2166
+ else if(!cx)
2167
+ printf("there is no JSContext on the nsIThreadJSContextStack!\n");
2168
+ else
2169
+ xpc_DumpJSStack(cx, showArgs, showLocals, showThisProps);
2170
+
2171
+ return NS_OK;
2172
+ }
2173
+
2174
+ /* void debugDumpEvalInJSStackFrame (in PRUint32 aFrameNumber, in string aSourceText); */
2175
+ NS_IMETHODIMP
2176
+ nsXPConnect::DebugDumpEvalInJSStackFrame(PRUint32 aFrameNumber, const char *aSourceText)
2177
+ {
2178
+ JSContext* cx;
2179
+ if(NS_FAILED(Peek(&cx)))
2180
+ printf("failed to peek into nsIThreadJSContextStack service!\n");
2181
+ else if(!cx)
2182
+ printf("there is no JSContext on the nsIThreadJSContextStack!\n");
2183
+ else
2184
+ xpc_DumpEvalInJSStackFrame(cx, aFrameNumber, aSourceText);
2185
+
2186
+ return NS_OK;
2187
+ }
2188
+
2189
+ /* JSVal variantToJS (in JSContextPtr ctx, in JSObjectPtr scope, in nsIVariant value); */
2190
+ NS_IMETHODIMP
2191
+ nsXPConnect::VariantToJS(JSContext* ctx, JSObject* scope, nsIVariant* value, jsval* _retval)
2192
+ {
2193
+ NS_PRECONDITION(ctx, "bad param");
2194
+ NS_PRECONDITION(scope, "bad param");
2195
+ NS_PRECONDITION(value, "bad param");
2196
+ NS_PRECONDITION(_retval, "bad param");
2197
+
2198
+ XPCCallContext ccx(NATIVE_CALLER, ctx);
2199
+ if(!ccx.IsValid())
2200
+ return NS_ERROR_FAILURE;
2201
+
2202
+ nsresult rv = NS_OK;
2203
+ if(!XPCVariant::VariantDataToJS(ccx, value, scope, &rv, _retval))
2204
+ {
2205
+ if(NS_FAILED(rv))
2206
+ return rv;
2207
+
2208
+ return NS_ERROR_FAILURE;
2209
+ }
2210
+
2211
+ return NS_OK;
2212
+ }
2213
+
2214
+ /* nsIVariant JSToVariant (in JSContextPtr ctx, in JSVal value); */
2215
+ NS_IMETHODIMP
2216
+ nsXPConnect::JSToVariant(JSContext* ctx, jsval value, nsIVariant** _retval)
2217
+ {
2218
+ NS_PRECONDITION(ctx, "bad param");
2219
+ NS_PRECONDITION(value, "bad param");
2220
+ NS_PRECONDITION(_retval, "bad param");
2221
+
2222
+ XPCCallContext ccx(NATIVE_CALLER, ctx);
2223
+ if(!ccx.IsValid())
2224
+ return NS_ERROR_FAILURE;
2225
+
2226
+ *_retval = XPCVariant::newVariant(ccx, value);
2227
+ if(!(*_retval))
2228
+ return NS_ERROR_FAILURE;
2229
+
2230
+ return NS_OK;
2231
+ }
2232
+
2233
+ /* void flagSystemFilenamePrefix (in string filenamePrefix,
2234
+ * in PRBool aWantNativeWrappers); */
2235
+ NS_IMETHODIMP
2236
+ nsXPConnect::FlagSystemFilenamePrefix(const char *aFilenamePrefix,
2237
+ PRBool aWantNativeWrappers)
2238
+ {
2239
+ NS_PRECONDITION(aFilenamePrefix, "bad param");
2240
+
2241
+ JSRuntime* rt = GetRuntime()->GetJSRuntime();;
2242
+ uint32 flags = JSFILENAME_SYSTEM;
2243
+ if(aWantNativeWrappers)
2244
+ flags |= JSFILENAME_PROTECTED;
2245
+ if(!JS_FlagScriptFilenamePrefix(rt, aFilenamePrefix, flags))
2246
+ return NS_ERROR_OUT_OF_MEMORY;
2247
+ return NS_OK;
2248
+ }
2249
+
2250
+ NS_IMETHODIMP
2251
+ nsXPConnect::OnProcessNextEvent(nsIThreadInternal *aThread, PRBool aMayWait,
2252
+ PRUint32 aRecursionDepth)
2253
+ {
2254
+ // Push a null JSContext so that we don't see any script during
2255
+ // event processing.
2256
+ return Push(nsnull);
2257
+ }
2258
+
2259
+ NS_IMETHODIMP
2260
+ nsXPConnect::AfterProcessNextEvent(nsIThreadInternal *aThread,
2261
+ PRUint32 aRecursionDepth)
2262
+ {
2263
+ return Pop(nsnull);
2264
+ }
2265
+
2266
+ NS_IMETHODIMP
2267
+ nsXPConnect::OnDispatchedEvent(nsIThreadInternal* aThread)
2268
+ {
2269
+ NS_NOTREACHED("Why tell us?");
2270
+ return NS_ERROR_UNEXPECTED;
2271
+ }
2272
+
2273
+ NS_IMETHODIMP
2274
+ nsXPConnect::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
2275
+ {
2276
+ return mRuntime->AddJSHolder(aHolder, aTracer);
2277
+ }
2278
+
2279
+ NS_IMETHODIMP
2280
+ nsXPConnect::RemoveJSHolder(void* aHolder)
2281
+ {
2282
+ return mRuntime->RemoveJSHolder(aHolder);
2283
+ }
2284
+
2285
+ NS_IMETHODIMP
2286
+ nsXPConnect::SetReportAllJSExceptions(PRBool newval)
2287
+ {
2288
+ // Ignore if the environment variable was set.
2289
+ if (gReportAllJSExceptions != 1)
2290
+ gReportAllJSExceptions = newval ? 2 : 0;
2291
+
2292
+ return NS_OK;
2293
+ }
2294
+
2295
+ /* [noscript, notxpcom] PRBool defineDOMQuickStubs (in JSContextPtr cx, in JSObjectPtr proto, in PRUint32 flags, in PRUint32 interfaceCount, [array, size_is (interfaceCount)] in nsIIDPtr interfaceArray); */
2296
+ NS_IMETHODIMP_(PRBool)
2297
+ nsXPConnect::DefineDOMQuickStubs(JSContext * cx,
2298
+ JSObject * proto,
2299
+ PRUint32 flags,
2300
+ PRUint32 interfaceCount,
2301
+ const nsIID * *interfaceArray)
2302
+ {
2303
+ return DOM_DefineQuickStubs(cx, proto, flags,
2304
+ interfaceCount, interfaceArray);
2305
+ }
2306
+
2307
+ NS_IMETHODIMP
2308
+ nsXPConnect::GetWrapperForObject(JSContext* aJSContext,
2309
+ JSObject* aObject,
2310
+ JSObject* aScope,
2311
+ nsIPrincipal* aPrincipal,
2312
+ PRUint32 aFilenameFlags,
2313
+ jsval* _retval)
2314
+ {
2315
+ NS_ASSERTION(aFilenameFlags != JSFILENAME_NULL, "Null filename!");
2316
+ NS_ASSERTION(XPCPerThreadData::IsMainThread(aJSContext),
2317
+ "Must only be called from the main thread as these wrappers "
2318
+ "are not threadsafe!");
2319
+
2320
+ JSAutoRequest ar(aJSContext);
2321
+
2322
+ XPCWrappedNative *wrapper =
2323
+ XPCWrappedNative::GetWrappedNativeOfJSObject(aJSContext, aObject);
2324
+ if(!wrapper)
2325
+ {
2326
+ // Couldn't get the wrapped native (maybe a prototype?) so just return
2327
+ // the original object.
2328
+ *_retval = OBJECT_TO_JSVAL(aObject);
2329
+ return NS_OK;
2330
+ }
2331
+
2332
+ XPCWrappedNativeScope *xpcscope =
2333
+ XPCWrappedNativeScope::FindInJSObjectScope(aJSContext, aScope);
2334
+ if(!xpcscope)
2335
+ return NS_ERROR_FAILURE;
2336
+
2337
+ #ifdef DEBUG_mrbkap
2338
+ {
2339
+ JSObject *scopeobj = xpcscope->GetGlobalJSObject();
2340
+ JSObject *toInnerize = scopeobj;
2341
+ OBJ_TO_INNER_OBJECT(aJSContext, toInnerize);
2342
+ NS_ASSERTION(toInnerize == scopeobj, "Scope chain ending in outer object?");
2343
+ }
2344
+ #endif
2345
+
2346
+ XPCWrappedNativeScope *objectscope = wrapper->GetScope();
2347
+ {
2348
+ JSObject *possibleOuter = objectscope->GetGlobalJSObject();
2349
+ OBJ_TO_INNER_OBJECT(aJSContext, possibleOuter);
2350
+ if(!possibleOuter)
2351
+ return NS_ERROR_FAILURE;
2352
+
2353
+ if(objectscope->GetGlobalJSObject() != possibleOuter)
2354
+ {
2355
+ objectscope =
2356
+ XPCWrappedNativeScope::FindInJSObjectScope(aJSContext,
2357
+ possibleOuter);
2358
+ NS_ASSERTION(objectscope, "Unable to find a scope from an object");
2359
+ }
2360
+ }
2361
+
2362
+ *_retval = OBJECT_TO_JSVAL(aObject);
2363
+
2364
+ JSBool sameOrigin;
2365
+ JSBool sameScope = xpc_SameScope(objectscope, xpcscope, &sameOrigin);
2366
+ JSBool forceXOW = XPC_XOW_ClassNeedsXOW(STOBJ_GET_CLASS(aObject)->name);
2367
+
2368
+ // We can do nothing if:
2369
+ // - We're wrapping a system object
2370
+ // or
2371
+ // - We're from the same *scope* AND
2372
+ // - We're not about to force a XOW (e.g. for "window") OR
2373
+ // - We're not actually going to create a XOW (we're wrapping for
2374
+ // chrome).
2375
+ if(STOBJ_IS_SYSTEM(aObject) ||
2376
+ (sameScope &&
2377
+ (!forceXOW || (aFilenameFlags & JSFILENAME_SYSTEM))))
2378
+ return NS_OK;
2379
+
2380
+ JSObject* wrappedObj = nsnull;
2381
+
2382
+ if(aFilenameFlags & JSFILENAME_PROTECTED)
2383
+ {
2384
+ wrappedObj = XPCNativeWrapper::GetNewOrUsed(aJSContext, wrapper,
2385
+ aPrincipal);
2386
+ }
2387
+ else if(aFilenameFlags & JSFILENAME_SYSTEM)
2388
+ {
2389
+ jsval val = OBJECT_TO_JSVAL(aObject);
2390
+ if(XPC_SJOW_Construct(aJSContext, nsnull, 1, &val, &val))
2391
+ wrappedObj = JSVAL_TO_OBJECT(val);
2392
+ }
2393
+ else
2394
+ {
2395
+ // We don't wrap anything same origin unless the class name requires
2396
+ // it.
2397
+ if(sameOrigin && !forceXOW)
2398
+ return NS_OK;
2399
+
2400
+ jsval val = OBJECT_TO_JSVAL(aObject);
2401
+ if(XPC_XOW_WrapObject(aJSContext, aScope, &val, wrapper))
2402
+ wrappedObj = JSVAL_TO_OBJECT(val);
2403
+ }
2404
+
2405
+ if(!wrappedObj)
2406
+ return NS_ERROR_FAILURE;
2407
+
2408
+ *_retval = OBJECT_TO_JSVAL(wrappedObj);
2409
+ if(wrapper->NeedsChromeWrapper() &&
2410
+ !XPC_SOW_WrapObject(aJSContext, aScope, *_retval, _retval))
2411
+ return NS_ERROR_FAILURE;
2412
+ return NS_OK;
2413
+ }
2414
+
2415
+ /* attribute JSRuntime runtime; */
2416
+ NS_IMETHODIMP
2417
+ nsXPConnect::GetRuntime(JSRuntime **runtime)
2418
+ {
2419
+ if(!runtime)
2420
+ return NS_ERROR_NULL_POINTER;
2421
+
2422
+ *runtime = GetRuntime()->GetJSRuntime();
2423
+ return NS_OK;
2424
+ }
2425
+
2426
+ /* attribute nsIXPCScriptable backstagePass; */
2427
+ NS_IMETHODIMP
2428
+ nsXPConnect::GetBackstagePass(nsIXPCScriptable **bsp)
2429
+ {
2430
+ if(!mBackstagePass) {
2431
+ #ifndef XPCONNECT_STANDALONE
2432
+ nsCOMPtr<nsIPrincipal> sysprin;
2433
+ nsCOMPtr<nsIScriptSecurityManager> secman =
2434
+ do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
2435
+ if(!secman)
2436
+ return NS_ERROR_NOT_AVAILABLE;
2437
+ if(NS_FAILED(secman->GetSystemPrincipal(getter_AddRefs(sysprin))))
2438
+ return NS_ERROR_NOT_AVAILABLE;
2439
+
2440
+ mBackstagePass = new BackstagePass(sysprin);
2441
+ #else
2442
+ mBackstagePass = new BackstagePass();
2443
+ #endif
2444
+ if(!mBackstagePass)
2445
+ return NS_ERROR_OUT_OF_MEMORY;
2446
+ }
2447
+ NS_ADDREF(*bsp = mBackstagePass);
2448
+ return NS_OK;
2449
+ }
2450
+
2451
+ // nsIJSContextStack and nsIThreadJSContextStack implementations
2452
+
2453
+ /* readonly attribute PRInt32 Count; */
2454
+ NS_IMETHODIMP
2455
+ nsXPConnect::GetCount(PRInt32 *aCount)
2456
+ {
2457
+ if(!aCount)
2458
+ return NS_ERROR_NULL_POINTER;
2459
+
2460
+ XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
2461
+
2462
+ if(!data)
2463
+ {
2464
+ *aCount = 0;
2465
+ return NS_ERROR_FAILURE;
2466
+ }
2467
+
2468
+ return data->GetJSContextStack()->GetCount(aCount);
2469
+ }
2470
+
2471
+ /* JSContext Peek (); */
2472
+ NS_IMETHODIMP
2473
+ nsXPConnect::Peek(JSContext * *_retval)
2474
+ {
2475
+ if(!_retval)
2476
+ return NS_ERROR_NULL_POINTER;
2477
+
2478
+ XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
2479
+
2480
+ if(!data)
2481
+ {
2482
+ *_retval = nsnull;
2483
+ return NS_ERROR_FAILURE;
2484
+ }
2485
+
2486
+ return data->GetJSContextStack()->Peek(_retval);
2487
+ }
2488
+
2489
+ /* JSContext Pop (); */
2490
+ NS_IMETHODIMP
2491
+ nsXPConnect::Pop(JSContext * *_retval)
2492
+ {
2493
+ XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
2494
+
2495
+ if(!data)
2496
+ {
2497
+ if(_retval)
2498
+ *_retval = nsnull;
2499
+ return NS_ERROR_FAILURE;
2500
+ }
2501
+
2502
+ return data->GetJSContextStack()->Pop(_retval);
2503
+ }
2504
+
2505
+ /* void Push (in JSContext cx); */
2506
+ NS_IMETHODIMP
2507
+ nsXPConnect::Push(JSContext * cx)
2508
+ {
2509
+ XPCPerThreadData* data = XPCPerThreadData::GetData(cx);
2510
+
2511
+ if(!data)
2512
+ return NS_ERROR_FAILURE;
2513
+
2514
+ return data->GetJSContextStack()->Push(cx);
2515
+ }
2516
+
2517
+ /* attribute JSContext SafeJSContext; */
2518
+ NS_IMETHODIMP
2519
+ nsXPConnect::GetSafeJSContext(JSContext * *aSafeJSContext)
2520
+ {
2521
+ NS_ASSERTION(aSafeJSContext, "loser!");
2522
+
2523
+ XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
2524
+
2525
+ if(!data)
2526
+ {
2527
+ *aSafeJSContext = nsnull;
2528
+ return NS_ERROR_FAILURE;
2529
+ }
2530
+
2531
+ return data->GetJSContextStack()->GetSafeJSContext(aSafeJSContext);
2532
+ }
2533
+
2534
+ /* attribute JSContext SafeJSContext; */
2535
+ NS_IMETHODIMP
2536
+ nsXPConnect::SetSafeJSContext(JSContext * aSafeJSContext)
2537
+ {
2538
+ XPCPerThreadData* data = XPCPerThreadData::GetData(aSafeJSContext);
2539
+
2540
+ if(!data)
2541
+ return NS_ERROR_FAILURE;
2542
+
2543
+ return data->GetJSContextStack()->SetSafeJSContext(aSafeJSContext);
2544
+ }
2545
+
2546
+ /* These are here to be callable from a debugger */
2547
+ JS_BEGIN_EXTERN_C
2548
+ JS_EXPORT_API(void) DumpJSStack()
2549
+ {
2550
+ nsresult rv;
2551
+ nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
2552
+ if(NS_SUCCEEDED(rv) && xpc)
2553
+ xpc->DebugDumpJSStack(PR_TRUE, PR_TRUE, PR_FALSE);
2554
+ else
2555
+ printf("failed to get XPConnect service!\n");
2556
+ }
2557
+
2558
+ JS_EXPORT_API(void) DumpJSEval(PRUint32 frameno, const char* text)
2559
+ {
2560
+ nsresult rv;
2561
+ nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
2562
+ if(NS_SUCCEEDED(rv) && xpc)
2563
+ xpc->DebugDumpEvalInJSStackFrame(frameno, text);
2564
+ else
2565
+ printf("failed to get XPConnect service!\n");
2566
+ }
2567
+
2568
+ JS_EXPORT_API(void) DumpJSObject(JSObject* obj)
2569
+ {
2570
+ xpc_DumpJSObject(obj);
2571
+ }
2572
+
2573
+ JS_EXPORT_API(void) DumpJSValue(jsval val)
2574
+ {
2575
+ printf("Dumping 0x%p. Value tag is %u.\n", (void *) val, (PRUint32) JSVAL_TAG(val));
2576
+ if(JSVAL_IS_NULL(val)) {
2577
+ printf("Value is null\n");
2578
+ }
2579
+ else if(JSVAL_IS_OBJECT(val)) {
2580
+ printf("Value is an object\n");
2581
+ JSObject* obj = JSVAL_TO_OBJECT(val);
2582
+ DumpJSObject(obj);
2583
+ }
2584
+ else if(JSVAL_IS_NUMBER(val)) {
2585
+ printf("Value is a number: ");
2586
+ if(JSVAL_IS_INT(val))
2587
+ printf("Integer %i\n", JSVAL_TO_INT(val));
2588
+ else if(JSVAL_IS_DOUBLE(val))
2589
+ printf("Floating-point value %f\n", *JSVAL_TO_DOUBLE(val));
2590
+ }
2591
+ else if(JSVAL_IS_STRING(val)) {
2592
+ printf("Value is a string: ");
2593
+ JSString* string = JSVAL_TO_STRING(val);
2594
+ char* bytes = JS_GetStringBytes(string);
2595
+ printf("<%s>\n", bytes);
2596
+ }
2597
+ else if(JSVAL_IS_BOOLEAN(val)) {
2598
+ printf("Value is boolean: ");
2599
+ printf(JSVAL_TO_BOOLEAN(val) ? "true" : "false");
2600
+ }
2601
+ else if(JSVAL_IS_VOID(val)) {
2602
+ printf("Value is undefined\n");
2603
+ }
2604
+ else {
2605
+ printf("No idea what this value is.\n");
2606
+ }
2607
+ }
2608
+ JS_END_EXTERN_C
2609
+