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,1717 @@
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) 1999
22
+ * the Initial Developer. All Rights Reserved.
23
+ *
24
+ * Contributors:
25
+ * Mike Shaver <shaver@zeroknowledge.com>
26
+ * John Bandhauer <jband@netscape.com>
27
+ * IBM Corp.
28
+ * Robert Ginda <rginda@netscape.com>
29
+ *
30
+ * Alternatively, the contents of this file may be used under the terms of
31
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
32
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
33
+ * in which case the provisions of the GPL or the LGPL are applicable instead
34
+ * of those above. If you wish to allow use of your version of this file only
35
+ * under the terms of either the GPL or the LGPL, and not to allow others to
36
+ * use your version of this file under the terms of the MPL, indicate your
37
+ * decision by deleting the provisions above and replace them with the notice
38
+ * and other provisions required by the GPL or the LGPL. If you do not delete
39
+ * the provisions above, a recipient may use your version of this file under
40
+ * the terms of any one of the MPL, the GPL or the LGPL.
41
+ *
42
+ * ***** END LICENSE BLOCK ***** */
43
+
44
+ #ifdef MOZ_LOGGING
45
+ #define FORCE_PR_LOG
46
+ #endif
47
+
48
+ #include <stdarg.h>
49
+
50
+ #include "prlog.h"
51
+
52
+ #include "nsCOMPtr.h"
53
+ #include "nsAutoPtr.h"
54
+ #include "nsICategoryManager.h"
55
+ #include "nsIComponentManager.h"
56
+ #include "nsIComponentManagerObsolete.h"
57
+ #include "nsIGenericFactory.h"
58
+ #include "nsILocalFile.h"
59
+ #include "nsIModule.h"
60
+ #include "nsIServiceManager.h"
61
+ #include "nsISupports.h"
62
+ #include "mozJSComponentLoader.h"
63
+ #include "nsIJSRuntimeService.h"
64
+ #include "nsIJSContextStack.h"
65
+ #include "nsIXPConnect.h"
66
+ #include "nsCRT.h"
67
+ #include "nsMemory.h"
68
+ #include "nsIObserverService.h"
69
+ #include "nsIXPCScriptable.h"
70
+ #include "nsString.h"
71
+ #ifndef XPCONNECT_STANDALONE
72
+ #include "nsIScriptSecurityManager.h"
73
+ #include "nsIURI.h"
74
+ #include "nsIFileURL.h"
75
+ #include "nsNetUtil.h"
76
+ #endif
77
+ #include "jsxdrapi.h"
78
+ #include "jsprf.h"
79
+ #include "nsIFastLoadFileControl.h"
80
+ // For reporting errors with the console service
81
+ #include "nsIScriptError.h"
82
+ #include "nsIConsoleService.h"
83
+ #include "prmem.h"
84
+ #include "plbase64.h"
85
+
86
+ #if defined(MOZ_SHARK) || defined(MOZ_CALLGRIND) || defined(MOZ_VTUNE)
87
+ #include "jsdbgapi.h"
88
+ #endif
89
+
90
+ static const char kJSRuntimeServiceContractID[] = "@mozilla.org/js/xpc/RuntimeService;1";
91
+ static const char kXPConnectServiceContractID[] = "@mozilla.org/js/xpc/XPConnect;1";
92
+ static const char kObserverServiceContractID[] = "@mozilla.org/observer-service;1";
93
+
94
+ /* Some platforms don't have an implementation of PR_MemMap(). */
95
+ #if !defined(XP_BEOS) && !defined(XP_OS2)
96
+ #define HAVE_PR_MEMMAP
97
+ #endif
98
+
99
+ /**
100
+ * Buffer sizes for serialization and deserialization of scripts.
101
+ * FIXME: bug #411579 (tune this macro!) Last updated: Jan 2008
102
+ */
103
+ #define XPC_SERIALIZATION_BUFFER_SIZE (64 * 1024)
104
+ #define XPC_DESERIALIZATION_BUFFER_SIZE (12 * 8192)
105
+
106
+ // Inactivity delay before closing our fastload file stream.
107
+ static const int kFastLoadWriteDelay = 10000; // 10 seconds
108
+
109
+ #ifdef PR_LOGGING
110
+ // NSPR_LOG_MODULES=JSComponentLoader:5
111
+ static PRLogModuleInfo *gJSCLLog;
112
+ #endif
113
+
114
+ #define LOG(args) PR_LOG(gJSCLLog, PR_LOG_DEBUG, args)
115
+
116
+ // Components.utils.import error messages
117
+ #define ERROR_SCOPE_OBJ "%s - Second argument must be an object."
118
+ #define ERROR_NOT_PRESENT "%s - EXPORTED_SYMBOLS is not present."
119
+ #define ERROR_NOT_AN_ARRAY "%s - EXPORTED_SYMBOLS is not an array."
120
+ #define ERROR_GETTING_ARRAY_LENGTH "%s - Error getting array length of EXPORTED_SYMBOLS."
121
+ #define ERROR_ARRAY_ELEMENT "%s - EXPORTED_SYMBOLS[%d] is not a string."
122
+ #define ERROR_GETTING_SYMBOL "%s - Could not get symbol '%s'."
123
+ #define ERROR_SETTING_SYMBOL "%s - Could not set symbol '%s' on target object."
124
+
125
+ void
126
+ mozJSLoaderErrorReporter(JSContext *cx, const char *message, JSErrorReport *rep)
127
+ {
128
+ nsresult rv;
129
+
130
+ /* Use the console service to register the error. */
131
+ nsCOMPtr<nsIConsoleService> consoleService =
132
+ do_GetService(NS_CONSOLESERVICE_CONTRACTID);
133
+
134
+ /*
135
+ * Make an nsIScriptError, populate it with information from this
136
+ * error, then log it with the console service. The UI can then
137
+ * poll the service to update the Error console.
138
+ */
139
+ nsCOMPtr<nsIScriptError> errorObject =
140
+ do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
141
+
142
+ if (consoleService && errorObject) {
143
+ /*
144
+ * Got an error object; prepare appropriate-width versions of
145
+ * various arguments to it.
146
+ */
147
+ nsAutoString fileUni;
148
+ fileUni.AssignWithConversion(rep->filename);
149
+
150
+ PRUint32 column = rep->uctokenptr - rep->uclinebuf;
151
+
152
+ rv = errorObject->Init(reinterpret_cast<const PRUnichar*>
153
+ (rep->ucmessage),
154
+ fileUni.get(),
155
+ reinterpret_cast<const PRUnichar*>
156
+ (rep->uclinebuf),
157
+ rep->lineno, column, rep->flags,
158
+ "component javascript");
159
+ if (NS_SUCCEEDED(rv)) {
160
+ rv = consoleService->LogMessage(errorObject);
161
+ if (NS_SUCCEEDED(rv)) {
162
+ // We're done! Skip return to fall thru to stderr
163
+ // printout, for the benefit of those invoking the
164
+ // browser with -console
165
+ // return;
166
+ }
167
+ }
168
+ }
169
+
170
+ /*
171
+ * If any of the above fails for some reason, fall back to
172
+ * printing to stderr.
173
+ */
174
+ #ifdef DEBUG
175
+ fprintf(stderr, "JS Component Loader: %s %s:%d\n"
176
+ " %s\n",
177
+ JSREPORT_IS_WARNING(rep->flags) ? "WARNING" : "ERROR",
178
+ rep->filename, rep->lineno,
179
+ message ? message : "<no message>");
180
+ #endif
181
+ }
182
+
183
+ static JSBool
184
+ Dump(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
185
+ {
186
+ JSString *str;
187
+ if (!argc)
188
+ return JS_TRUE;
189
+
190
+ str = JS_ValueToString(cx, argv[0]);
191
+ if (!str)
192
+ return JS_FALSE;
193
+
194
+ char *bytes = JS_GetStringBytes(str);
195
+ fputs(bytes, stderr);
196
+ return JS_TRUE;
197
+ }
198
+
199
+ static JSBool
200
+ Debug(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
201
+ {
202
+ #ifdef DEBUG
203
+ return Dump(cx, obj, argc, argv, rval);
204
+ #else
205
+ return JS_TRUE;
206
+ #endif
207
+ }
208
+
209
+ static JSBool
210
+ Atob(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
211
+ {
212
+ JSString *str;
213
+ if (!argc)
214
+ return JS_TRUE;
215
+
216
+ str = JS_ValueToString(cx, argv[0]);
217
+ if (!str)
218
+ return JS_FALSE;
219
+
220
+ size_t base64StrLength = JS_GetStringLength(str);
221
+ char *base64Str = JS_GetStringBytes(str);
222
+
223
+ PRUint32 bin_dataLength = (PRUint32)base64StrLength;
224
+ if (base64Str[base64StrLength - 1] == '=') {
225
+ if (base64Str[base64StrLength - 2] == '=')
226
+ bin_dataLength -= 2;
227
+ else
228
+ --bin_dataLength;
229
+ }
230
+ bin_dataLength = (PRUint32)((PRUint64)bin_dataLength * 3) / 4;
231
+
232
+ char *bin_data = PL_Base64Decode(base64Str, base64StrLength, nsnull);
233
+ if (!bin_data)
234
+ return JS_FALSE;
235
+
236
+ str = JS_NewStringCopyN(cx, bin_data, bin_dataLength);
237
+ PR_Free(bin_data);
238
+ if (!str)
239
+ return JS_FALSE;
240
+
241
+ *rval = STRING_TO_JSVAL(str);
242
+ return JS_TRUE;
243
+ }
244
+
245
+ static JSBool
246
+ Btoa(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
247
+ {
248
+ JSString *str;
249
+ if (!argc)
250
+ return JS_TRUE;
251
+
252
+ str = JS_ValueToString(cx, argv[0]);
253
+ if (!str)
254
+ return JS_FALSE;
255
+
256
+ char *bin_data = JS_GetStringBytes(str);
257
+ size_t bin_dataLength = JS_GetStringLength(str);
258
+
259
+ char *base64 = PL_Base64Encode(bin_data, bin_dataLength, nsnull);
260
+ if (!base64)
261
+ return JS_FALSE;
262
+
263
+ PRUint32 base64Length = ((bin_dataLength + 2) / 3) * 4;
264
+ str = JS_NewStringCopyN(cx, base64, base64Length);
265
+ PR_Free(base64);
266
+ if (!str)
267
+ return JS_FALSE;
268
+
269
+ *rval = STRING_TO_JSVAL(str);
270
+ return JS_TRUE;
271
+ }
272
+
273
+ static JSFunctionSpec gGlobalFun[] = {
274
+ {"dump", Dump, 1,0,0},
275
+ {"debug", Debug, 1,0,0},
276
+ {"atob", Atob, 1,0,0},
277
+ {"btoa", Btoa, 1,0,0},
278
+ #ifdef MOZ_SHARK
279
+ {"startShark", js_StartShark, 0,0,0},
280
+ {"stopShark", js_StopShark, 0,0,0},
281
+ {"connectShark", js_ConnectShark, 0,0,0},
282
+ {"disconnectShark", js_DisconnectShark,0,0,0},
283
+ #endif
284
+ #ifdef MOZ_CALLGRIND
285
+ {"startCallgrind", js_StartCallgrind, 0,0,0},
286
+ {"stopCallgrind", js_StopCallgrind, 0,0,0},
287
+ {"dumpCallgrind", js_DumpCallgrind, 1,0,0},
288
+ #endif
289
+ #ifdef MOZ_VTUNE
290
+ {"startVtune", js_StartVtune, 1,0,0},
291
+ {"stopVtune", js_StopVtune, 0,0,0},
292
+ {"pauseVtune", js_PauseVtune, 0,0,0},
293
+ {"resumeVtune", js_ResumeVtune, 0,0,0},
294
+ #endif
295
+ {nsnull,nsnull,0,0,0}
296
+ };
297
+
298
+ class JSCLContextHelper
299
+ {
300
+ public:
301
+ JSCLContextHelper(mozJSComponentLoader* loader);
302
+ ~JSCLContextHelper() { Pop(); }
303
+
304
+ JSContext* Pop();
305
+
306
+ operator JSContext*() const {return mContext;}
307
+
308
+ JSCLContextHelper(); // not implemnted
309
+ private:
310
+ JSContext* mContext;
311
+ intN mContextThread;
312
+ nsIThreadJSContextStack* mContextStack;
313
+ };
314
+
315
+
316
+ class JSCLAutoErrorReporterSetter
317
+ {
318
+ public:
319
+ JSCLAutoErrorReporterSetter(JSContext* cx, JSErrorReporter reporter)
320
+ {mContext = cx; mOldReporter = JS_SetErrorReporter(cx, reporter);}
321
+ ~JSCLAutoErrorReporterSetter()
322
+ {JS_SetErrorReporter(mContext, mOldReporter);}
323
+ JSCLAutoErrorReporterSetter(); // not implemented
324
+ private:
325
+ JSContext* mContext;
326
+ JSErrorReporter mOldReporter;
327
+ };
328
+
329
+ static nsresult
330
+ OutputError(JSContext *cx,
331
+ const char *format,
332
+ va_list ap)
333
+ {
334
+ char *buf = JS_vsmprintf(format, ap);
335
+ if (!buf) {
336
+ return NS_ERROR_OUT_OF_MEMORY;
337
+ }
338
+
339
+ JS_ReportError(cx, buf);
340
+ JS_smprintf_free(buf);
341
+
342
+ return NS_OK;
343
+ }
344
+
345
+ static nsresult
346
+ ReportOnCaller(nsAXPCNativeCallContext *cc,
347
+ const char *format, ...) {
348
+ if (!cc) {
349
+ return NS_ERROR_FAILURE;
350
+ }
351
+
352
+ va_list ap;
353
+ va_start(ap, format);
354
+
355
+ nsresult rv;
356
+ JSContext *callerContext;
357
+ rv = cc->GetJSContext(&callerContext);
358
+ NS_ENSURE_SUCCESS(rv, rv);
359
+
360
+ return OutputError(callerContext, format, ap);
361
+ }
362
+
363
+ static nsresult
364
+ ReportOnCaller(JSCLContextHelper &helper,
365
+ const char *format, ...)
366
+ {
367
+ va_list ap;
368
+ va_start(ap, format);
369
+
370
+ JSContext *cx = helper.Pop();
371
+ if (!cx) {
372
+ return NS_ERROR_FAILURE;
373
+ }
374
+
375
+ return OutputError(cx, format, ap);
376
+ }
377
+
378
+ NS_IMPL_ISUPPORTS1(nsXPCFastLoadIO, nsIFastLoadFileIO)
379
+
380
+ NS_IMETHODIMP
381
+ nsXPCFastLoadIO::GetInputStream(nsIInputStream **_retval)
382
+ {
383
+ if (! mInputStream) {
384
+ nsCOMPtr<nsIInputStream> fileInput;
385
+ nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInput),
386
+ mFile);
387
+ NS_ENSURE_SUCCESS(rv, rv);
388
+
389
+ rv = NS_NewBufferedInputStream(getter_AddRefs(mInputStream),
390
+ fileInput,
391
+ XPC_DESERIALIZATION_BUFFER_SIZE);
392
+ NS_ENSURE_SUCCESS(rv, rv);
393
+ }
394
+
395
+ NS_ADDREF(*_retval = mInputStream);
396
+ return NS_OK;
397
+ }
398
+
399
+ NS_IMETHODIMP
400
+ nsXPCFastLoadIO::GetOutputStream(nsIOutputStream **_retval)
401
+ {
402
+ if (! mOutputStream) {
403
+ PRInt32 ioFlags = PR_WRONLY;
404
+ if (! mInputStream) {
405
+ ioFlags |= PR_CREATE_FILE | PR_TRUNCATE;
406
+ }
407
+
408
+ nsCOMPtr<nsIOutputStream> fileOutput;
409
+ nsresult rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOutput),
410
+ mFile, ioFlags, 0644);
411
+ NS_ENSURE_SUCCESS(rv, rv);
412
+
413
+ rv = NS_NewBufferedOutputStream(getter_AddRefs(mOutputStream),
414
+ fileOutput,
415
+ XPC_SERIALIZATION_BUFFER_SIZE);
416
+ NS_ENSURE_SUCCESS(rv, rv);
417
+ }
418
+
419
+ NS_ADDREF(*_retval = mOutputStream);
420
+ return NS_OK;
421
+ }
422
+
423
+ static nsresult
424
+ ReadScriptFromStream(JSContext *cx, nsIObjectInputStream *stream,
425
+ JSScript **script)
426
+ {
427
+ *script = nsnull;
428
+
429
+ PRUint32 size;
430
+ nsresult rv = stream->Read32(&size);
431
+ NS_ENSURE_SUCCESS(rv, rv);
432
+
433
+ char *data;
434
+ rv = stream->ReadBytes(size, &data);
435
+ NS_ENSURE_SUCCESS(rv, rv);
436
+
437
+ JSXDRState *xdr = JS_XDRNewMem(cx, JSXDR_DECODE);
438
+ NS_ENSURE_TRUE(xdr, NS_ERROR_OUT_OF_MEMORY);
439
+
440
+ xdr->userdata = stream;
441
+ JS_XDRMemSetData(xdr, data, size);
442
+
443
+ if (!JS_XDRScript(xdr, script)) {
444
+ rv = NS_ERROR_FAILURE;
445
+ }
446
+
447
+ // Update data in case ::JS_XDRScript called back into C++ code to
448
+ // read an XPCOM object.
449
+ //
450
+ // In that case, the serialization process must have flushed a run
451
+ // of counted bytes containing JS data at the point where the XPCOM
452
+ // object starts, after which an encoding C++ callback from the JS
453
+ // XDR code must have written the XPCOM object directly into the
454
+ // nsIObjectOutputStream.
455
+ //
456
+ // The deserialization process will XDR-decode counted bytes up to
457
+ // but not including the XPCOM object, then call back into C++ to
458
+ // read the object, then read more counted bytes and hand them off
459
+ // to the JSXDRState, so more JS data can be decoded.
460
+ //
461
+ // This interleaving of JS XDR data and XPCOM object data may occur
462
+ // several times beneath the call to ::JS_XDRScript, above. At the
463
+ // end of the day, we need to free (via nsMemory) the data owned by
464
+ // the JSXDRState. So we steal it back, nulling xdr's buffer so it
465
+ // doesn't get passed to ::JS_free by ::JS_XDRDestroy.
466
+
467
+ uint32 length;
468
+ data = static_cast<char*>(JS_XDRMemGetData(xdr, &length));
469
+ if (data) {
470
+ JS_XDRMemSetData(xdr, nsnull, 0);
471
+ }
472
+ JS_XDRDestroy(xdr);
473
+
474
+ // If data is null now, it must have been freed while deserializing an
475
+ // XPCOM object (e.g., a principal) beneath ::JS_XDRScript.
476
+ if (data) {
477
+ nsMemory::Free(data);
478
+ }
479
+
480
+ return rv;
481
+ }
482
+
483
+ static nsresult
484
+ WriteScriptToStream(JSContext *cx, JSScript *script,
485
+ nsIObjectOutputStream *stream)
486
+ {
487
+ JSXDRState *xdr = JS_XDRNewMem(cx, JSXDR_ENCODE);
488
+ NS_ENSURE_TRUE(xdr, NS_ERROR_OUT_OF_MEMORY);
489
+
490
+ xdr->userdata = stream;
491
+ nsresult rv = NS_OK;
492
+
493
+ if (JS_XDRScript(xdr, &script)) {
494
+ // Get the encoded JSXDRState data and write it. The JSXDRState owns
495
+ // this buffer memory and will free it beneath ::JS_XDRDestroy.
496
+ //
497
+ // If an XPCOM object needs to be written in the midst of the JS XDR
498
+ // encoding process, the C++ code called back from the JS engine (e.g.,
499
+ // nsEncodeJSPrincipals in caps/src/nsJSPrincipals.cpp) will flush data
500
+ // from the JSXDRState to aStream, then write the object, then return
501
+ // to JS XDR code with xdr reset so new JS data is encoded at the front
502
+ // of the xdr's data buffer.
503
+ //
504
+ // However many XPCOM objects are interleaved with JS XDR data in the
505
+ // stream, when control returns here from ::JS_XDRScript, we'll have
506
+ // one last buffer of data to write to aStream.
507
+
508
+ uint32 size;
509
+ const char* data = reinterpret_cast<const char*>
510
+ (JS_XDRMemGetData(xdr, &size));
511
+ NS_ASSERTION(data, "no decoded JSXDRState data!");
512
+
513
+ rv = stream->Write32(size);
514
+ if (NS_SUCCEEDED(rv)) {
515
+ rv = stream->WriteBytes(data, size);
516
+ }
517
+ } else {
518
+ rv = NS_ERROR_FAILURE; // likely to be a principals serialization error
519
+ }
520
+
521
+ JS_XDRDestroy(xdr);
522
+ return rv;
523
+ }
524
+
525
+ mozJSComponentLoader::mozJSComponentLoader()
526
+ : mRuntime(nsnull),
527
+ mContext(nsnull),
528
+ mInitialized(PR_FALSE)
529
+ {
530
+ NS_ASSERTION(!sSelf, "mozJSComponentLoader should be a singleton");
531
+
532
+ #ifdef PR_LOGGING
533
+ if (!gJSCLLog) {
534
+ gJSCLLog = PR_NewLogModule("JSComponentLoader");
535
+ }
536
+ #endif
537
+
538
+ sSelf = this;
539
+ }
540
+
541
+ mozJSComponentLoader::~mozJSComponentLoader()
542
+ {
543
+ if (mInitialized) {
544
+ NS_ERROR("'xpcom-shutdown-loaders' was not fired before cleaning up mozJSComponentLoader");
545
+ UnloadModules();
546
+ }
547
+
548
+ NS_ASSERTION(!mFastLoadTimer,
549
+ "Fastload file should have been closed via xpcom-shutdown");
550
+
551
+ sSelf = nsnull;
552
+ }
553
+
554
+ mozJSComponentLoader*
555
+ mozJSComponentLoader::sSelf;
556
+
557
+ NS_IMPL_ISUPPORTS3(mozJSComponentLoader,
558
+ nsIModuleLoader,
559
+ xpcIJSModuleLoader,
560
+ nsIObserver)
561
+
562
+ nsresult
563
+ mozJSComponentLoader::ReallyInit()
564
+ {
565
+ nsresult rv;
566
+
567
+ /*
568
+ * Get the JSRuntime from the runtime svc, if possible.
569
+ * We keep a reference around, because it's a Bad Thing if the runtime
570
+ * service gets shut down before we're done. Bad!
571
+ */
572
+
573
+ mRuntimeService = do_GetService(kJSRuntimeServiceContractID, &rv);
574
+ if (NS_FAILED(rv) ||
575
+ NS_FAILED(rv = mRuntimeService->GetRuntime(&mRuntime)))
576
+ return rv;
577
+
578
+ mContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
579
+ if (NS_FAILED(rv))
580
+ return rv;
581
+
582
+ // Create our compilation context.
583
+ mContext = JS_NewContext(mRuntime, 256);
584
+ if (!mContext)
585
+ return NS_ERROR_OUT_OF_MEMORY;
586
+
587
+ uint32 options = JS_GetOptions(mContext);
588
+ JS_SetOptions(mContext, options | JSOPTION_XML);
589
+
590
+ // Always use the latest js version
591
+ JS_SetVersion(mContext, JSVERSION_LATEST);
592
+
593
+ // Limit C stack consumption to a reasonable 512K
594
+ int stackDummy;
595
+ const jsuword kStackSize = 0x80000;
596
+ jsuword stackLimit, currentStackAddr = (jsuword)&stackDummy;
597
+
598
+ #if JS_STACK_GROWTH_DIRECTION < 0
599
+ stackLimit = (currentStackAddr > kStackSize)
600
+ ? currentStackAddr - kStackSize
601
+ : 0;
602
+ #else
603
+ stackLimit = (currentStackAddr + kStackSize > currentStackAddr)
604
+ ? currentStackAddr + kStackSize
605
+ : (jsuword) -1;
606
+ #endif
607
+
608
+ JS_SetThreadStackLimit(mContext, stackLimit);
609
+
610
+ #ifndef XPCONNECT_STANDALONE
611
+ nsCOMPtr<nsIScriptSecurityManager> secman =
612
+ do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
613
+ if (!secman)
614
+ return NS_ERROR_FAILURE;
615
+
616
+ rv = secman->GetSystemPrincipal(getter_AddRefs(mSystemPrincipal));
617
+ if (NS_FAILED(rv) || !mSystemPrincipal)
618
+ return NS_ERROR_FAILURE;
619
+ #endif
620
+
621
+ if (!mModules.Init(32))
622
+ return NS_ERROR_OUT_OF_MEMORY;
623
+ if (!mImports.Init(32))
624
+ return NS_ERROR_OUT_OF_MEMORY;
625
+ if (!mInProgressImports.Init(32))
626
+ return NS_ERROR_OUT_OF_MEMORY;
627
+
628
+ // Set up our fastload file
629
+ nsCOMPtr<nsIFastLoadService> flSvc = do_GetFastLoadService(&rv);
630
+ if (NS_SUCCEEDED(rv))
631
+ rv = flSvc->NewFastLoadFile("XPC", getter_AddRefs(mFastLoadFile));
632
+ if (NS_FAILED(rv)) {
633
+ LOG(("Could not get fastload file location\n"));
634
+ }
635
+
636
+ // Listen for xpcom-shutdown so that we can close out our fastload file
637
+ // at that point (after that we can no longer create an input stream).
638
+ nsCOMPtr<nsIObserverService> obsSvc =
639
+ do_GetService(kObserverServiceContractID, &rv);
640
+ NS_ENSURE_SUCCESS(rv, rv);
641
+
642
+ rv = obsSvc->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
643
+ NS_ENSURE_SUCCESS(rv, rv);
644
+
645
+ rv = obsSvc->AddObserver(this, "xpcom-shutdown-loaders", PR_FALSE);
646
+ NS_ENSURE_SUCCESS(rv, rv);
647
+
648
+ #ifdef DEBUG_shaver_off
649
+ fprintf(stderr, "mJCL: ReallyInit success!\n");
650
+ #endif
651
+ mInitialized = PR_TRUE;
652
+
653
+ return NS_OK;
654
+ }
655
+
656
+ NS_IMETHODIMP
657
+ mozJSComponentLoader::LoadModule(nsILocalFile* aComponentFile,
658
+ nsIModule* *aResult)
659
+ {
660
+ nsresult rv;
661
+
662
+ nsCAutoString leafName;
663
+ aComponentFile->GetNativeLeafName(leafName);
664
+ if (!StringTail(leafName, 3).LowerCaseEqualsLiteral(".js"))
665
+ return NS_ERROR_INVALID_ARG;
666
+
667
+ if (!mInitialized) {
668
+ rv = ReallyInit();
669
+ if (NS_FAILED(rv))
670
+ return rv;
671
+ }
672
+
673
+ nsCOMPtr<nsIHashable> lfhash(do_QueryInterface(aComponentFile));
674
+ if (!lfhash) {
675
+ NS_ERROR("nsLocalFile not implementing nsIHashable");
676
+ return NS_NOINTERFACE;
677
+ }
678
+
679
+ ModuleEntry* mod;
680
+ if (mModules.Get(lfhash, &mod)) {
681
+ NS_ASSERTION(mod->module, "Bad hashtable data!");
682
+ NS_ADDREF(*aResult = mod->module);
683
+ return NS_OK;
684
+ }
685
+
686
+ nsAutoPtr<ModuleEntry> entry(new ModuleEntry);
687
+ if (!entry)
688
+ return NS_ERROR_OUT_OF_MEMORY;
689
+
690
+ rv = GlobalForLocation(aComponentFile, &entry->global, &entry->location,
691
+ nsnull);
692
+ if (NS_FAILED(rv)) {
693
+ #ifdef DEBUG_shaver
694
+ fprintf(stderr, "GlobalForLocation failed!\n");
695
+ #endif
696
+ return rv;
697
+ }
698
+
699
+ nsCOMPtr<nsIXPConnect> xpc = do_GetService(kXPConnectServiceContractID,
700
+ &rv);
701
+ if (NS_FAILED(rv))
702
+ return rv;
703
+
704
+ nsCOMPtr<nsIComponentManager> cm;
705
+ rv = NS_GetComponentManager(getter_AddRefs(cm));
706
+ if (NS_FAILED(rv))
707
+ return rv;
708
+
709
+ JSCLContextHelper cx(this);
710
+
711
+ JSObject* cm_jsobj;
712
+ nsCOMPtr<nsIXPConnectJSObjectHolder> cm_holder;
713
+ rv = xpc->WrapNative(cx, entry->global, cm,
714
+ NS_GET_IID(nsIComponentManager),
715
+ getter_AddRefs(cm_holder));
716
+
717
+ if (NS_FAILED(rv)) {
718
+ #ifdef DEBUG_shaver
719
+ fprintf(stderr, "WrapNative(%p,%p,nsIComponentManager) failed: %x\n",
720
+ (void *)(JSContext*)cx, (void *)mCompMgr, rv);
721
+ #endif
722
+ return rv;
723
+ }
724
+
725
+ rv = cm_holder->GetJSObject(&cm_jsobj);
726
+ if (NS_FAILED(rv)) {
727
+ #ifdef DEBUG_shaver
728
+ fprintf(stderr, "GetJSObject of ComponentManager failed\n");
729
+ #endif
730
+ return rv;
731
+ }
732
+
733
+ JSObject* file_jsobj;
734
+ nsCOMPtr<nsIXPConnectJSObjectHolder> file_holder;
735
+ rv = xpc->WrapNative(cx, entry->global, aComponentFile,
736
+ NS_GET_IID(nsIFile),
737
+ getter_AddRefs(file_holder));
738
+
739
+ if (NS_FAILED(rv)) {
740
+ return rv;
741
+ }
742
+
743
+ rv = file_holder->GetJSObject(&file_jsobj);
744
+ if (NS_FAILED(rv)) {
745
+ return rv;
746
+ }
747
+
748
+ JSCLAutoErrorReporterSetter aers(cx, mozJSLoaderErrorReporter);
749
+
750
+ jsval argv[2], retval, NSGetModule_val;
751
+
752
+ if (!JS_GetProperty(cx, entry->global, "NSGetModule", &NSGetModule_val) ||
753
+ JSVAL_IS_VOID(NSGetModule_val)) {
754
+ return NS_ERROR_FAILURE;
755
+ }
756
+
757
+ if (JS_TypeOfValue(cx, NSGetModule_val) != JSTYPE_FUNCTION) {
758
+ nsCAutoString path;
759
+ aComponentFile->GetNativePath(path);
760
+
761
+ JS_ReportError(cx, "%s has NSGetModule property that is not a function",
762
+ path.get());
763
+ return NS_ERROR_FAILURE;
764
+ }
765
+
766
+ argv[0] = OBJECT_TO_JSVAL(cm_jsobj);
767
+ argv[1] = OBJECT_TO_JSVAL(file_jsobj);
768
+ if (!JS_CallFunctionValue(cx, entry->global, NSGetModule_val,
769
+ 2, argv, &retval)) {
770
+ return NS_ERROR_FAILURE;
771
+ }
772
+
773
+ #ifdef DEBUG_shaver_off
774
+ JSString *s = JS_ValueToString(cx, retval);
775
+ fprintf(stderr, "mJCL: %s::NSGetModule returned %s\n",
776
+ registryLocation, JS_GetStringBytes(s));
777
+ #endif
778
+
779
+ JSObject *jsModuleObj;
780
+ if (!JS_ValueToObject(cx, retval, &jsModuleObj)) {
781
+ /* XXX report error properly */
782
+ return NS_ERROR_FAILURE;
783
+ }
784
+
785
+ rv = xpc->WrapJS(cx, jsModuleObj,
786
+ NS_GET_IID(nsIModule), getter_AddRefs(entry->module));
787
+ if (NS_FAILED(rv)) {
788
+ /* XXX report error properly */
789
+ #ifdef DEBUG
790
+ fprintf(stderr, "mJCL: couldn't get nsIModule from jsval\n");
791
+ #endif
792
+ return rv;
793
+ }
794
+
795
+ // Cache this module for later
796
+ if (!mModules.Put(lfhash, entry))
797
+ return NS_ERROR_OUT_OF_MEMORY;
798
+
799
+ NS_ADDREF(*aResult = entry->module);
800
+
801
+ // The hash owns the ModuleEntry now, forget about it
802
+ entry.forget();
803
+
804
+ return NS_OK;
805
+ }
806
+
807
+ // Some stack based classes for cleaning up on early return
808
+ #ifdef HAVE_PR_MEMMAP
809
+ class FileAutoCloser
810
+ {
811
+ public:
812
+ explicit FileAutoCloser(PRFileDesc *file) : mFile(file) {}
813
+ ~FileAutoCloser() { PR_Close(mFile); }
814
+ private:
815
+ PRFileDesc *mFile;
816
+ };
817
+
818
+ class FileMapAutoCloser
819
+ {
820
+ public:
821
+ explicit FileMapAutoCloser(PRFileMap *map) : mMap(map) {}
822
+ ~FileMapAutoCloser() { PR_CloseFileMap(mMap); }
823
+ private:
824
+ PRFileMap *mMap;
825
+ };
826
+ #endif
827
+
828
+ class JSPrincipalsHolder
829
+ {
830
+ public:
831
+ JSPrincipalsHolder(JSContext *cx, JSPrincipals *principals)
832
+ : mCx(cx), mPrincipals(principals) {}
833
+ ~JSPrincipalsHolder() { JSPRINCIPALS_DROP(mCx, mPrincipals); }
834
+ private:
835
+ JSContext *mCx;
836
+ JSPrincipals *mPrincipals;
837
+ };
838
+
839
+ class JSScriptHolder
840
+ {
841
+ public:
842
+ JSScriptHolder(JSContext *cx, JSScript *script)
843
+ : mCx(cx), mScript(script) {}
844
+ ~JSScriptHolder() { ::JS_DestroyScript(mCx, mScript); }
845
+ private:
846
+ JSContext *mCx;
847
+ JSScript *mScript;
848
+ };
849
+
850
+ class FastLoadStateHolder
851
+ {
852
+ public:
853
+ explicit FastLoadStateHolder(nsIFastLoadService *service);
854
+ ~FastLoadStateHolder() { pop(); }
855
+
856
+ void pop();
857
+
858
+ private:
859
+ nsCOMPtr<nsIFastLoadService> mService;
860
+ nsCOMPtr<nsIFastLoadFileIO> mIO;
861
+ nsCOMPtr<nsIObjectInputStream> mInputStream;
862
+ nsCOMPtr<nsIObjectOutputStream> mOutputStream;
863
+ };
864
+
865
+ FastLoadStateHolder::FastLoadStateHolder(nsIFastLoadService *service)
866
+ {
867
+ if (!service)
868
+ return;
869
+
870
+ mService = service;
871
+ service->GetFileIO(getter_AddRefs(mIO));
872
+ service->GetInputStream(getter_AddRefs(mInputStream));
873
+ service->GetOutputStream(getter_AddRefs(mOutputStream));
874
+ }
875
+
876
+ void
877
+ FastLoadStateHolder::pop()
878
+ {
879
+ if (!mService)
880
+ return;
881
+
882
+ mService->SetFileIO(mIO);
883
+ mService->SetInputStream(mInputStream);
884
+ mService->SetOutputStream(mOutputStream);
885
+
886
+ mService = nsnull;
887
+ }
888
+
889
+ /* static */
890
+ void
891
+ mozJSComponentLoader::CloseFastLoad(nsITimer *timer, void *closure)
892
+ {
893
+ static_cast<mozJSComponentLoader*>(closure)->CloseFastLoad();
894
+ }
895
+
896
+ void
897
+ mozJSComponentLoader::CloseFastLoad()
898
+ {
899
+ // Close our fastload streams
900
+ LOG(("Closing fastload file\n"));
901
+ if (mFastLoadOutput) {
902
+ nsresult rv = mFastLoadOutput->Close();
903
+ if (NS_SUCCEEDED(rv)) {
904
+ nsCOMPtr<nsIFastLoadService> flSvc = do_GetFastLoadService(&rv);
905
+ if (NS_SUCCEEDED(rv)) {
906
+ flSvc->CacheChecksum(mFastLoadFile, mFastLoadOutput);
907
+ }
908
+ }
909
+ mFastLoadOutput = nsnull;
910
+ }
911
+ if (mFastLoadInput) {
912
+ mFastLoadInput->Close();
913
+ mFastLoadInput = nsnull;
914
+ }
915
+
916
+ mFastLoadIO = nsnull;
917
+ mFastLoadTimer = nsnull;
918
+ }
919
+
920
+ nsresult
921
+ mozJSComponentLoader::StartFastLoad(nsIFastLoadService *flSvc)
922
+ {
923
+ if (!mFastLoadFile || !flSvc) {
924
+ return NS_ERROR_NOT_AVAILABLE;
925
+ }
926
+
927
+ // Now set our IO object as current, and create our streams.
928
+ if (!mFastLoadIO) {
929
+ mFastLoadIO = new nsXPCFastLoadIO(mFastLoadFile);
930
+ NS_ENSURE_TRUE(mFastLoadIO, NS_ERROR_OUT_OF_MEMORY);
931
+ }
932
+
933
+ nsresult rv = flSvc->SetFileIO(mFastLoadIO);
934
+ NS_ENSURE_SUCCESS(rv, rv);
935
+
936
+ if (!mFastLoadInput && !mFastLoadOutput) {
937
+ // First time accessing the fastload file
938
+ PRBool exists;
939
+ mFastLoadFile->Exists(&exists);
940
+ if (exists) {
941
+ LOG(("trying to use existing fastload file\n"));
942
+
943
+ nsCOMPtr<nsIInputStream> input;
944
+ rv = mFastLoadIO->GetInputStream(getter_AddRefs(input));
945
+ NS_ENSURE_SUCCESS(rv, rv);
946
+
947
+ rv = flSvc->NewInputStream(input, getter_AddRefs(mFastLoadInput));
948
+ if (NS_SUCCEEDED(rv)) {
949
+ LOG(("opened fastload file for reading\n"));
950
+
951
+ nsCOMPtr<nsIFastLoadReadControl>
952
+ readControl(do_QueryInterface(mFastLoadInput));
953
+ if (readControl) {
954
+ // Verify checksum, using the FastLoadService's
955
+ // checksum cache to avoid computing more than once
956
+ // per session.
957
+ PRUint32 checksum;
958
+ rv = readControl->GetChecksum(&checksum);
959
+ if (NS_SUCCEEDED(rv)) {
960
+ PRUint32 verified;
961
+ rv = flSvc->ComputeChecksum(mFastLoadFile,
962
+ readControl, &verified);
963
+ if (NS_SUCCEEDED(rv) && verified != checksum) {
964
+ LOG(("Incorrect checksum detected"));
965
+ rv = NS_ERROR_FAILURE;
966
+ }
967
+ }
968
+ }
969
+
970
+ if (NS_SUCCEEDED(rv)) {
971
+ /* Get the JS bytecode version number and validate it. */
972
+ PRUint32 version;
973
+ rv = mFastLoadInput->Read32(&version);
974
+ if (NS_SUCCEEDED(rv) && version != JSXDR_BYTECODE_VERSION) {
975
+ LOG(("Bad JS bytecode version\n"));
976
+ rv = NS_ERROR_UNEXPECTED;
977
+ }
978
+ }
979
+ }
980
+ if (NS_FAILED(rv)) {
981
+ LOG(("Invalid fastload file detected, removing it\n"));
982
+ if (mFastLoadInput) {
983
+ mFastLoadInput->Close();
984
+ mFastLoadInput = nsnull;
985
+ } else {
986
+ input->Close();
987
+ }
988
+ mFastLoadIO->SetInputStream(nsnull);
989
+ mFastLoadFile->Remove(PR_FALSE);
990
+ exists = PR_FALSE;
991
+ }
992
+ }
993
+
994
+ if (!exists) {
995
+ LOG(("Creating new fastload file\n"));
996
+
997
+ nsCOMPtr<nsIOutputStream> output;
998
+ rv = mFastLoadIO->GetOutputStream(getter_AddRefs(output));
999
+ NS_ENSURE_SUCCESS(rv, rv);
1000
+
1001
+ rv = flSvc->NewOutputStream(output,
1002
+ getter_AddRefs(mFastLoadOutput));
1003
+
1004
+ if (NS_SUCCEEDED(rv))
1005
+ rv = mFastLoadOutput->Write32(JSXDR_BYTECODE_VERSION);
1006
+
1007
+ if (NS_FAILED(rv)) {
1008
+ LOG(("Fatal error, could not create fastload file\n"));
1009
+
1010
+ if (mFastLoadOutput) {
1011
+ mFastLoadOutput->Close();
1012
+ mFastLoadOutput = nsnull;
1013
+ } else {
1014
+ output->Close();
1015
+ }
1016
+ mFastLoadIO->SetOutputStream(nsnull);
1017
+ mFastLoadFile->Remove(PR_FALSE);
1018
+ return rv;
1019
+ }
1020
+ }
1021
+ }
1022
+
1023
+ flSvc->SetInputStream(mFastLoadInput);
1024
+ flSvc->SetOutputStream(mFastLoadOutput);
1025
+
1026
+ // Start our update timer. This allows us to keep the stream open
1027
+ // when many components are loaded in succession, but close it once
1028
+ // there has been a period of inactivity.
1029
+
1030
+ if (!mFastLoadTimer) {
1031
+ mFastLoadTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
1032
+ NS_ENSURE_SUCCESS(rv, rv);
1033
+
1034
+ rv = mFastLoadTimer->InitWithFuncCallback(&mozJSComponentLoader::CloseFastLoad,
1035
+ this,
1036
+ kFastLoadWriteDelay,
1037
+ nsITimer::TYPE_ONE_SHOT);
1038
+ } else {
1039
+ rv = mFastLoadTimer->SetDelay(kFastLoadWriteDelay);
1040
+ }
1041
+
1042
+ return rv;
1043
+ }
1044
+
1045
+ nsresult
1046
+ mozJSComponentLoader::ReadScript(nsIFastLoadService *flSvc,
1047
+ const char *nativePath, nsIURI *uri,
1048
+ JSContext *cx, JSScript **script)
1049
+ {
1050
+ NS_ASSERTION(flSvc, "fastload not initialized");
1051
+
1052
+ nsresult rv = flSvc->StartMuxedDocument(uri, nativePath,
1053
+ nsIFastLoadService::NS_FASTLOAD_READ);
1054
+ if (NS_FAILED(rv)) {
1055
+ return rv; // don't warn since NOT_AVAILABLE is an ok error
1056
+ }
1057
+
1058
+ LOG(("Found %s in fastload file\n", nativePath));
1059
+
1060
+ nsCOMPtr<nsIURI> oldURI;
1061
+ rv = flSvc->SelectMuxedDocument(uri, getter_AddRefs(oldURI));
1062
+ NS_ENSURE_SUCCESS(rv, rv);
1063
+
1064
+ NS_ASSERTION(mFastLoadInput,
1065
+ "FASTLOAD_READ should only succeed with an input stream");
1066
+
1067
+ rv = ReadScriptFromStream(cx, mFastLoadInput, script);
1068
+ if (NS_SUCCEEDED(rv)) {
1069
+ rv = flSvc->EndMuxedDocument(uri);
1070
+ }
1071
+
1072
+ return rv;
1073
+ }
1074
+
1075
+ nsresult
1076
+ mozJSComponentLoader::WriteScript(nsIFastLoadService *flSvc, JSScript *script,
1077
+ nsIFile *component, const char *nativePath,
1078
+ nsIURI *uri, JSContext *cx)
1079
+ {
1080
+ NS_ASSERTION(flSvc, "fastload not initialized");
1081
+ nsresult rv;
1082
+
1083
+ if (!mFastLoadOutput) {
1084
+ // Trying to read a URI that was not in the fastload file will have
1085
+ // created an output stream for us. But, if we haven't tried to
1086
+ // load anything that was missing, it will still be null.
1087
+ rv = flSvc->GetOutputStream(getter_AddRefs(mFastLoadOutput));
1088
+ NS_ENSURE_SUCCESS(rv, rv);
1089
+ }
1090
+
1091
+ NS_ASSERTION(mFastLoadOutput, "must have an output stream here");
1092
+
1093
+ LOG(("Writing %s to fastload\n", nativePath));
1094
+ rv = flSvc->AddDependency(component);
1095
+ NS_ENSURE_SUCCESS(rv, rv);
1096
+
1097
+ rv = flSvc->StartMuxedDocument(uri, nativePath,
1098
+ nsIFastLoadService::NS_FASTLOAD_WRITE);
1099
+ NS_ENSURE_SUCCESS(rv, rv);
1100
+
1101
+ nsCOMPtr<nsIURI> oldURI;
1102
+ rv = flSvc->SelectMuxedDocument(uri, getter_AddRefs(oldURI));
1103
+ NS_ENSURE_SUCCESS(rv, rv);
1104
+
1105
+ rv = WriteScriptToStream(cx, script, mFastLoadOutput);
1106
+ NS_ENSURE_SUCCESS(rv, rv);
1107
+
1108
+ return flSvc->EndMuxedDocument(uri);
1109
+ }
1110
+
1111
+ nsresult
1112
+ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponent,
1113
+ JSObject **aGlobal,
1114
+ char **aLocation,
1115
+ jsval *exception)
1116
+ {
1117
+ nsresult rv;
1118
+
1119
+ JSPrincipals* jsPrincipals = nsnull;
1120
+ JSCLContextHelper cx(this);
1121
+
1122
+ #ifndef XPCONNECT_STANDALONE
1123
+ rv = mSystemPrincipal->GetJSPrincipals(cx, &jsPrincipals);
1124
+ NS_ENSURE_SUCCESS(rv, rv);
1125
+
1126
+ JSPrincipalsHolder princHolder(mContext, jsPrincipals);
1127
+ #endif
1128
+
1129
+ nsCOMPtr<nsIXPCScriptable> backstagePass;
1130
+ rv = mRuntimeService->GetBackstagePass(getter_AddRefs(backstagePass));
1131
+ NS_ENSURE_SUCCESS(rv, rv);
1132
+
1133
+ JSCLAutoErrorReporterSetter aers(cx, mozJSLoaderErrorReporter);
1134
+
1135
+ nsCOMPtr<nsIXPConnect> xpc =
1136
+ do_GetService(kXPConnectServiceContractID, &rv);
1137
+ NS_ENSURE_SUCCESS(rv, rv);
1138
+
1139
+ // Make sure InitClassesWithNewWrappedGlobal() installs the
1140
+ // backstage pass as the global in our compilation context.
1141
+ JS_SetGlobalObject(cx, nsnull);
1142
+
1143
+ nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
1144
+ rv = xpc->InitClassesWithNewWrappedGlobal(cx, backstagePass,
1145
+ NS_GET_IID(nsISupports),
1146
+ nsIXPConnect::
1147
+ FLAG_SYSTEM_GLOBAL_OBJECT,
1148
+ getter_AddRefs(holder));
1149
+ NS_ENSURE_SUCCESS(rv, rv);
1150
+
1151
+ JSObject *global;
1152
+ rv = holder->GetJSObject(&global);
1153
+ NS_ENSURE_SUCCESS(rv, rv);
1154
+
1155
+ if (!JS_DefineFunctions(cx, global, gGlobalFun)) {
1156
+ return NS_ERROR_FAILURE;
1157
+ }
1158
+
1159
+ nsCOMPtr<nsIXPConnectJSObjectHolder> locationHolder;
1160
+ rv = xpc->WrapNative(cx, global, aComponent,
1161
+ NS_GET_IID(nsILocalFile),
1162
+ getter_AddRefs(locationHolder));
1163
+ NS_ENSURE_SUCCESS(rv, rv);
1164
+
1165
+ JSObject *locationObj;
1166
+ rv = locationHolder->GetJSObject(&locationObj);
1167
+ NS_ENSURE_SUCCESS(rv, rv);
1168
+
1169
+ if (!JS_DefineProperty(cx, global, "__LOCATION__",
1170
+ OBJECT_TO_JSVAL(locationObj), nsnull, nsnull, 0)) {
1171
+ return NS_ERROR_FAILURE;
1172
+ }
1173
+
1174
+ nsCAutoString nativePath;
1175
+ // Quick hack to unbust XPCONNECT_STANDALONE.
1176
+ // This leaves the jsdebugger with a non-URL pathname in the
1177
+ // XPCONNECT_STANDALONE case - but at least it builds and runs otherwise.
1178
+ // See: http://bugzilla.mozilla.org/show_bug.cgi?id=121438
1179
+ #ifdef XPCONNECT_STANDALONE
1180
+ localFile->GetNativePath(nativePath);
1181
+ #else
1182
+ NS_GetURLSpecFromFile(aComponent, nativePath);
1183
+ #endif
1184
+
1185
+ // Before compiling the script, first check to see if we have it in
1186
+ // the fastload file. Note: as a rule, fastload errors are not fatal
1187
+ // to loading the script, since we can always slow-load.
1188
+ nsCOMPtr<nsIFastLoadService> flSvc = do_GetFastLoadService(&rv);
1189
+
1190
+ // Save the old state and restore it upon return
1191
+ FastLoadStateHolder flState(flSvc);
1192
+ PRBool fastLoading = PR_FALSE;
1193
+
1194
+ if (NS_SUCCEEDED(rv)) {
1195
+ rv = StartFastLoad(flSvc);
1196
+ if (NS_SUCCEEDED(rv)) {
1197
+ fastLoading = PR_TRUE;
1198
+ }
1199
+ }
1200
+
1201
+ nsCOMPtr<nsIURI> uri;
1202
+ rv = NS_NewURI(getter_AddRefs(uri), nativePath);
1203
+ NS_ENSURE_SUCCESS(rv, rv);
1204
+
1205
+ JSScript *script = nsnull;
1206
+
1207
+ if (fastLoading) {
1208
+ rv = ReadScript(flSvc, nativePath.get(), uri, cx, &script);
1209
+ if (NS_SUCCEEDED(rv)) {
1210
+ LOG(("Successfully loaded %s from fastload\n", nativePath.get()));
1211
+ fastLoading = PR_FALSE; // no need to write out the script
1212
+ } else if (rv == NS_ERROR_NOT_AVAILABLE) {
1213
+ // This is ok, it just means the script is not yet in the
1214
+ // fastload file.
1215
+ rv = NS_OK;
1216
+ } else {
1217
+ LOG(("Failed to deserialize %s\n", nativePath.get()));
1218
+
1219
+ // Remove the fastload file, it may be corrupted.
1220
+ LOG(("Invalid fastload file detected, removing it\n"));
1221
+ nsCOMPtr<nsIObjectOutputStream> objectOutput;
1222
+ flSvc->GetOutputStream(getter_AddRefs(objectOutput));
1223
+ if (objectOutput) {
1224
+ flSvc->SetOutputStream(nsnull);
1225
+ objectOutput->Close();
1226
+ }
1227
+ nsCOMPtr<nsIObjectInputStream> objectInput;
1228
+ flSvc->GetInputStream(getter_AddRefs(objectInput));
1229
+ if (objectInput) {
1230
+ flSvc->SetInputStream(nsnull);
1231
+ objectInput->Close();
1232
+ }
1233
+ if (mFastLoadFile) {
1234
+ mFastLoadFile->Remove(PR_FALSE);
1235
+ }
1236
+ fastLoading = PR_FALSE;
1237
+ }
1238
+ }
1239
+
1240
+
1241
+ if (!script || NS_FAILED(rv)) {
1242
+ // The script wasn't in the fastload cache, so compile it now.
1243
+ LOG(("Slow loading %s\n", nativePath.get()));
1244
+
1245
+ // If |exception| is non-null, then our caller wants us to propagate
1246
+ // any exceptions out to our caller. Ensure that the engine doesn't
1247
+ // eagerly report the exception.
1248
+ uint32 oldopts = 0;
1249
+ if (exception) {
1250
+ oldopts = JS_GetOptions(cx);
1251
+ JS_SetOptions(cx, oldopts | JSOPTION_DONT_REPORT_UNCAUGHT);
1252
+ }
1253
+
1254
+ #ifdef HAVE_PR_MEMMAP
1255
+ PRInt64 fileSize;
1256
+ rv = aComponent->GetFileSize(&fileSize);
1257
+ if (NS_FAILED(rv)) {
1258
+ JS_SetOptions(cx, oldopts);
1259
+ return rv;
1260
+ }
1261
+
1262
+ PRInt64 maxSize;
1263
+ LL_UI2L(maxSize, PR_UINT32_MAX);
1264
+ if (LL_CMP(fileSize, >, maxSize)) {
1265
+ NS_ERROR("file too large");
1266
+ JS_SetOptions(cx, oldopts);
1267
+ return NS_ERROR_FAILURE;
1268
+ }
1269
+
1270
+ PRFileDesc *fileHandle;
1271
+ rv = aComponent->OpenNSPRFileDesc(PR_RDONLY, 0, &fileHandle);
1272
+ if (NS_FAILED(rv)) {
1273
+ JS_SetOptions(cx, oldopts);
1274
+ return NS_ERROR_FILE_NOT_FOUND;
1275
+ }
1276
+
1277
+ // Make sure the file is closed, no matter how we return.
1278
+ FileAutoCloser fileCloser(fileHandle);
1279
+
1280
+ PRFileMap *map = PR_CreateFileMap(fileHandle, fileSize,
1281
+ PR_PROT_READONLY);
1282
+ if (!map) {
1283
+ NS_ERROR("Failed to create file map");
1284
+ JS_SetOptions(cx, oldopts);
1285
+ return NS_ERROR_FAILURE;
1286
+ }
1287
+
1288
+ // Make sure the file map is closed, no matter how we return.
1289
+ FileMapAutoCloser mapCloser(map);
1290
+
1291
+ PRUint32 fileSize32;
1292
+ LL_L2UI(fileSize32, fileSize);
1293
+
1294
+ char *buf = static_cast<char*>(PR_MemMap(map, 0, fileSize32));
1295
+ if (!buf) {
1296
+ NS_WARNING("Failed to map file");
1297
+ JS_SetOptions(cx, oldopts);
1298
+ return NS_ERROR_FAILURE;
1299
+ }
1300
+
1301
+ script = JS_CompileScriptForPrincipals(cx, global,
1302
+ jsPrincipals,
1303
+ buf, fileSize32,
1304
+ nativePath.get(), 1);
1305
+ PR_MemUnmap(buf, fileSize32);
1306
+
1307
+ #else /* HAVE_PR_MEMMAP */
1308
+
1309
+ /**
1310
+ * No memmap implementation, so fall back to using
1311
+ * JS_CompileFileHandleForPrincipals().
1312
+ */
1313
+
1314
+ FILE *fileHandle;
1315
+ rv = aComponent->OpenANSIFileDesc("r", &fileHandle);
1316
+ if (NS_FAILED(rv)) {
1317
+ JS_SetOptions(cx, oldopts);
1318
+ return NS_ERROR_FILE_NOT_FOUND;
1319
+ }
1320
+
1321
+ script = JS_CompileFileHandleForPrincipals(cx, global,
1322
+ nativePath.get(),
1323
+ fileHandle, jsPrincipals);
1324
+
1325
+ /* JS will close the filehandle after compilation is complete. */
1326
+ #endif /* HAVE_PR_MEMMAP */
1327
+
1328
+ // Propagate the exception, if one exists. Also, don't leave the stale
1329
+ // exception on this context.
1330
+ // NB: The caller must stick exception into a rooted slot (probably on
1331
+ // its context) as soon as possible to avoid GC hazards.
1332
+ if (exception) {
1333
+ JS_SetOptions(cx, oldopts);
1334
+ if (!script) {
1335
+ JS_GetPendingException(cx, exception);
1336
+ JS_ClearPendingException(cx);
1337
+ }
1338
+ }
1339
+ }
1340
+
1341
+ if (!script) {
1342
+ #ifdef DEBUG_shaver_off
1343
+ fprintf(stderr, "mJCL: script compilation of %s FAILED\n",
1344
+ nativePath.get());
1345
+ #endif
1346
+ return NS_ERROR_FAILURE;
1347
+ }
1348
+
1349
+ // Ensure that we clean up the script on return.
1350
+ JSScriptHolder scriptHolder(cx, script);
1351
+
1352
+ // Flag this script as a system script
1353
+ // FIXME: BUG 346139: We actually want to flag this exact filename, not
1354
+ // anything that starts with this filename... Maybe we need a way to do
1355
+ // that? On the other hand, the fact that this is in our components dir
1356
+ // means that if someone snuck a malicious file into this dir we're screwed
1357
+ // anyway... So maybe flagging as a prefix is fine.
1358
+ xpc->FlagSystemFilenamePrefix(nativePath.get(), PR_TRUE);
1359
+
1360
+ #ifdef DEBUG_shaver_off
1361
+ fprintf(stderr, "mJCL: compiled JS component %s\n",
1362
+ nativePath.get());
1363
+ #endif
1364
+
1365
+ if (fastLoading) {
1366
+ // We successfully compiled the script, so cache it in fastload.
1367
+ rv = WriteScript(flSvc, script, aComponent, nativePath.get(), uri, cx);
1368
+
1369
+ // Don't treat failure to write as fatal, since we might be working
1370
+ // with a read-only fastload file.
1371
+ if (NS_SUCCEEDED(rv)) {
1372
+ LOG(("Successfully wrote to fastload\n"));
1373
+ } else {
1374
+ LOG(("Failed to write to fastload\n"));
1375
+ }
1376
+ }
1377
+
1378
+ // Restore the old state of the fastload service.
1379
+ flState.pop();
1380
+
1381
+ // Assign aGlobal here so that it's available to recursive imports.
1382
+ // See bug 384168.
1383
+ *aGlobal = global;
1384
+
1385
+ jsval retval;
1386
+ if (!JS_ExecuteScript(cx, global, script, &retval)) {
1387
+ #ifdef DEBUG_shaver_off
1388
+ fprintf(stderr, "mJCL: failed to execute %s\n", nativePath.get());
1389
+ #endif
1390
+ *aGlobal = nsnull;
1391
+ return NS_ERROR_FAILURE;
1392
+ }
1393
+
1394
+ /* Freed when we remove from the table. */
1395
+ nsCAutoString path;
1396
+ aComponent->GetNativePath(path);
1397
+ *aLocation = ToNewCString(path);
1398
+ if (!*aLocation) {
1399
+ *aGlobal = nsnull;
1400
+ return NS_ERROR_OUT_OF_MEMORY;
1401
+ }
1402
+
1403
+ JS_AddNamedRoot(cx, aGlobal, *aLocation);
1404
+ return NS_OK;
1405
+ }
1406
+
1407
+ void
1408
+ mozJSComponentLoader::UnloadModules()
1409
+ {
1410
+ mInitialized = PR_FALSE;
1411
+
1412
+ mInProgressImports.Clear();
1413
+ mImports.Clear();
1414
+ mModules.Clear();
1415
+
1416
+ // Destroying our context will force a GC.
1417
+ JS_DestroyContext(mContext);
1418
+ mContext = nsnull;
1419
+
1420
+ mRuntimeService = nsnull;
1421
+ mContextStack = nsnull;
1422
+ #ifdef DEBUG_shaver_off
1423
+ fprintf(stderr, "mJCL: UnloadAll(%d)\n", aWhen);
1424
+ #endif
1425
+ }
1426
+
1427
+ /* [JSObject] import (in AUTF8String registryLocation,
1428
+ [optional] in JSObject targetObj ); */
1429
+ NS_IMETHODIMP
1430
+ mozJSComponentLoader::Import(const nsACString & registryLocation)
1431
+ {
1432
+ // This function should only be called from JS.
1433
+ nsresult rv;
1434
+
1435
+ nsCOMPtr<nsIXPConnect> xpc =
1436
+ do_GetService(kXPConnectServiceContractID, &rv);
1437
+ NS_ENSURE_SUCCESS(rv, rv);
1438
+
1439
+ nsAXPCNativeCallContext *cc = nsnull;
1440
+ rv = xpc->GetCurrentNativeCallContext(&cc);
1441
+ NS_ENSURE_SUCCESS(rv, rv);
1442
+
1443
+ #ifdef DEBUG
1444
+ {
1445
+ // ensure that we are being call from JS, from this method
1446
+ nsCOMPtr<nsIInterfaceInfo> info;
1447
+ rv = cc->GetCalleeInterface(getter_AddRefs(info));
1448
+ NS_ENSURE_SUCCESS(rv, rv);
1449
+ nsXPIDLCString name;
1450
+ info->GetName(getter_Copies(name));
1451
+ NS_ASSERTION(nsCRT::strcmp("nsIXPCComponents_Utils", name.get()) == 0,
1452
+ "Components.utils.import must only be called from JS.");
1453
+ PRUint16 methodIndex;
1454
+ const nsXPTMethodInfo *methodInfo;
1455
+ rv = info->GetMethodInfoForName("import", &methodIndex, &methodInfo);
1456
+ NS_ENSURE_SUCCESS(rv, rv);
1457
+ PRUint16 calleeIndex;
1458
+ rv = cc->GetCalleeMethodIndex(&calleeIndex);
1459
+ NS_ASSERTION(calleeIndex == methodIndex,
1460
+ "Components.utils.import called from another utils method.");
1461
+ }
1462
+ #endif
1463
+
1464
+ JSContext *cx = nsnull;
1465
+ rv = cc->GetJSContext(&cx);
1466
+ NS_ENSURE_SUCCESS(rv, rv);
1467
+
1468
+ JSAutoRequest ar(cx);
1469
+
1470
+ JSObject *targetObject = nsnull;
1471
+
1472
+ PRUint32 argc = 0;
1473
+ rv = cc->GetArgc(&argc);
1474
+ NS_ENSURE_SUCCESS(rv, rv);
1475
+
1476
+ if (argc > 1) {
1477
+ // The caller passed in the optional second argument. Get it.
1478
+ jsval *argv = nsnull;
1479
+ rv = cc->GetArgvPtr(&argv);
1480
+ NS_ENSURE_SUCCESS(rv, rv);
1481
+ if (!JSVAL_IS_OBJECT(argv[1])) {
1482
+ return ReportOnCaller(cc, ERROR_SCOPE_OBJ,
1483
+ PromiseFlatCString(registryLocation).get());
1484
+ }
1485
+ targetObject = JSVAL_TO_OBJECT(argv[1]);
1486
+ } else {
1487
+ // Our targetObject is the caller's global object. Find it by
1488
+ // walking the calling object's parent chain.
1489
+
1490
+ nsCOMPtr<nsIXPConnectWrappedNative> wn;
1491
+ rv = cc->GetCalleeWrapper(getter_AddRefs(wn));
1492
+ NS_ENSURE_SUCCESS(rv, rv);
1493
+
1494
+ wn->GetJSObject(&targetObject);
1495
+ if (!targetObject) {
1496
+ NS_ERROR("null calling object");
1497
+ return NS_ERROR_FAILURE;
1498
+ }
1499
+
1500
+ targetObject = JS_GetGlobalForObject(cx, targetObject);
1501
+ }
1502
+
1503
+ JSObject *globalObj = nsnull;
1504
+ rv = ImportInto(registryLocation, targetObject, cc, &globalObj);
1505
+
1506
+ jsval *retval = nsnull;
1507
+ cc->GetRetValPtr(&retval);
1508
+ if (*retval)
1509
+ *retval = OBJECT_TO_JSVAL(globalObj);
1510
+
1511
+ return rv;
1512
+ }
1513
+
1514
+ /* [noscript] JSObjectPtr importInto(in AUTF8String registryLocation,
1515
+ in JSObjectPtr targetObj); */
1516
+ NS_IMETHODIMP
1517
+ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
1518
+ JSObject * targetObj,
1519
+ nsAXPCNativeCallContext * cc,
1520
+ JSObject * *_retval)
1521
+ {
1522
+ nsresult rv;
1523
+ *_retval = nsnull;
1524
+
1525
+ if (!mInitialized) {
1526
+ rv = ReallyInit();
1527
+ NS_ENSURE_SUCCESS(rv, rv);
1528
+ }
1529
+
1530
+ nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
1531
+ NS_ENSURE_SUCCESS(rv, rv);
1532
+
1533
+ // Get the URI.
1534
+ nsCOMPtr<nsIURI> resURI;
1535
+ rv = ioService->NewURI(aLocation, nsnull, nsnull, getter_AddRefs(resURI));
1536
+ nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(resURI, &rv);
1537
+ // If we don't have a file URL, then the location passed in is invalid.
1538
+ NS_ENSURE_SUCCESS(rv, NS_ERROR_INVALID_ARG);
1539
+
1540
+ // Get the file belonging to it.
1541
+ nsCOMPtr<nsIFile> file;
1542
+ rv = fileURL->GetFile(getter_AddRefs(file));
1543
+ NS_ENSURE_SUCCESS(rv, rv);
1544
+ nsCOMPtr<nsILocalFile> componentFile = do_QueryInterface(file, &rv);
1545
+ NS_ENSURE_SUCCESS(rv, rv);
1546
+
1547
+ nsCOMPtr<nsIHashable> lfhash(do_QueryInterface(componentFile));
1548
+ if (!lfhash) {
1549
+ NS_ERROR("nsLocalFile not implementing nsIHashable");
1550
+ return NS_NOINTERFACE;
1551
+ }
1552
+
1553
+ ModuleEntry* mod;
1554
+ nsAutoPtr<ModuleEntry> newEntry;
1555
+ if (!mImports.Get(lfhash, &mod) && !mInProgressImports.Get(lfhash, &mod)) {
1556
+ newEntry = new ModuleEntry;
1557
+ if (!newEntry || !mInProgressImports.Put(lfhash, newEntry))
1558
+ return NS_ERROR_OUT_OF_MEMORY;
1559
+
1560
+ jsval exception = JSVAL_VOID;
1561
+ rv = GlobalForLocation(componentFile, &newEntry->global,
1562
+ &newEntry->location, &exception);
1563
+
1564
+ mInProgressImports.Remove(lfhash);
1565
+
1566
+ if (NS_FAILED(rv)) {
1567
+ *_retval = nsnull;
1568
+
1569
+ if (!JSVAL_IS_VOID(exception)) {
1570
+ // An exception was thrown during compilation. Propagate it
1571
+ // out to our caller so they can report it.
1572
+ JSContext *callercx;
1573
+ cc->GetJSContext(&callercx);
1574
+ JS_SetPendingException(callercx, exception);
1575
+ return NS_OK;
1576
+ }
1577
+
1578
+ // Something failed, but we don't know what it is, guess.
1579
+ return NS_ERROR_FILE_NOT_FOUND;
1580
+ }
1581
+
1582
+ mod = newEntry;
1583
+ }
1584
+
1585
+ NS_ASSERTION(mod->global, "Import table contains entry with no global");
1586
+ *_retval = mod->global;
1587
+
1588
+ jsval symbols;
1589
+ if (targetObj) {
1590
+ JSCLContextHelper cxhelper(this);
1591
+
1592
+ if (!JS_GetProperty(mContext, mod->global,
1593
+ "EXPORTED_SYMBOLS", &symbols)) {
1594
+ return ReportOnCaller(cxhelper, ERROR_NOT_PRESENT,
1595
+ PromiseFlatCString(aLocation).get());
1596
+ }
1597
+
1598
+ JSObject *symbolsObj = nsnull;
1599
+ if (!JSVAL_IS_OBJECT(symbols) ||
1600
+ !(symbolsObj = JSVAL_TO_OBJECT(symbols)) ||
1601
+ !JS_IsArrayObject(mContext, symbolsObj)) {
1602
+ return ReportOnCaller(cxhelper, ERROR_NOT_AN_ARRAY,
1603
+ PromiseFlatCString(aLocation).get());
1604
+ }
1605
+
1606
+ // Iterate over symbols array, installing symbols on targetObj:
1607
+
1608
+ jsuint symbolCount = 0;
1609
+ if (!JS_GetArrayLength(mContext, symbolsObj, &symbolCount)) {
1610
+ return ReportOnCaller(cxhelper, ERROR_GETTING_ARRAY_LENGTH,
1611
+ PromiseFlatCString(aLocation).get());
1612
+ }
1613
+
1614
+ #ifdef DEBUG
1615
+ nsCAutoString logBuffer;
1616
+ #endif
1617
+
1618
+ for (jsuint i = 0; i < symbolCount; ++i) {
1619
+ jsval val;
1620
+ JSString *symbolName;
1621
+
1622
+ if (!JS_GetElement(mContext, symbolsObj, i, &val) ||
1623
+ !JSVAL_IS_STRING(val)) {
1624
+ return ReportOnCaller(cxhelper, ERROR_ARRAY_ELEMENT,
1625
+ PromiseFlatCString(aLocation).get(), i);
1626
+ }
1627
+
1628
+ symbolName = JSVAL_TO_STRING(val);
1629
+ if (!JS_GetProperty(mContext, mod->global,
1630
+ JS_GetStringBytes(symbolName), &val)) {
1631
+ return ReportOnCaller(cxhelper, ERROR_GETTING_SYMBOL,
1632
+ PromiseFlatCString(aLocation).get(),
1633
+ JS_GetStringBytes(symbolName));
1634
+ }
1635
+
1636
+ if (!JS_SetProperty(mContext, targetObj,
1637
+ JS_GetStringBytes(symbolName), &val)) {
1638
+ return ReportOnCaller(cxhelper, ERROR_SETTING_SYMBOL,
1639
+ PromiseFlatCString(aLocation).get(),
1640
+ JS_GetStringBytes(symbolName));
1641
+ }
1642
+ #ifdef DEBUG
1643
+ if (i == 0) {
1644
+ logBuffer.AssignLiteral("Installing symbols [ ");
1645
+ }
1646
+ logBuffer.Append(JS_GetStringBytes(symbolName));
1647
+ logBuffer.AppendLiteral(" ");
1648
+ if (i == symbolCount - 1) {
1649
+ LOG(("%s] from %s\n", PromiseFlatCString(logBuffer).get(),
1650
+ PromiseFlatCString(aLocation).get()));
1651
+ }
1652
+ #endif
1653
+ }
1654
+ }
1655
+
1656
+ // Cache this module for later
1657
+ if (newEntry) {
1658
+ if (!mImports.Put(lfhash, newEntry))
1659
+ return NS_ERROR_OUT_OF_MEMORY;
1660
+ newEntry.forget();
1661
+ }
1662
+
1663
+ return NS_OK;
1664
+ }
1665
+
1666
+ NS_IMETHODIMP
1667
+ mozJSComponentLoader::Observe(nsISupports *subject, const char *topic,
1668
+ const PRUnichar *data)
1669
+ {
1670
+ if (!strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
1671
+ if (mFastLoadTimer) {
1672
+ mFastLoadTimer->Cancel();
1673
+ }
1674
+
1675
+ CloseFastLoad();
1676
+ }
1677
+ else if (!strcmp(topic, "xpcom-shutdown-loaders")) {
1678
+ UnloadModules();
1679
+ }
1680
+ else {
1681
+ NS_ERROR("Unexpected observer topic.");
1682
+ }
1683
+
1684
+ return NS_OK;
1685
+ }
1686
+
1687
+ //----------------------------------------------------------------------
1688
+
1689
+ JSCLContextHelper::JSCLContextHelper(mozJSComponentLoader *loader)
1690
+ : mContext(loader->mContext), mContextThread(0),
1691
+ mContextStack(loader->mContextStack)
1692
+ {
1693
+ mContextStack->Push(mContext);
1694
+ mContextThread = JS_GetContextThread(mContext);
1695
+ if (mContextThread) {
1696
+ JS_BeginRequest(mContext);
1697
+ }
1698
+ }
1699
+
1700
+ // Pops the context that was pushed and then returns the context that is now at
1701
+ // the top of the stack.
1702
+ JSContext*
1703
+ JSCLContextHelper::Pop()
1704
+ {
1705
+ JSContext* cx = nsnull;
1706
+ if (mContextStack) {
1707
+ JS_ClearNewbornRoots(mContext);
1708
+ if (mContextThread) {
1709
+ JS_EndRequest(mContext);
1710
+ }
1711
+
1712
+ mContextStack->Pop(nsnull);
1713
+ mContextStack->Peek(&cx);
1714
+ mContextStack = nsnull;
1715
+ }
1716
+ return cx;
1717
+ }