johnson 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (371) hide show
  1. data/.autotest +14 -0
  2. data/CHANGELOG.rdoc +11 -0
  3. data/Manifest.txt +370 -0
  4. data/README.rdoc +60 -0
  5. data/Rakefile +42 -0
  6. data/bin/johnson +108 -0
  7. data/docs/MINGW32.mk +124 -0
  8. data/docs/cross-compile.txt +38 -0
  9. data/ext/spidermonkey/context.c +115 -0
  10. data/ext/spidermonkey/context.h +19 -0
  11. data/ext/spidermonkey/conversions.c +320 -0
  12. data/ext/spidermonkey/conversions.h +18 -0
  13. data/ext/spidermonkey/debugger.c +226 -0
  14. data/ext/spidermonkey/debugger.h +9 -0
  15. data/ext/spidermonkey/extconf.rb +30 -0
  16. data/ext/spidermonkey/extensions.c +37 -0
  17. data/ext/spidermonkey/extensions.h +12 -0
  18. data/ext/spidermonkey/global.c +40 -0
  19. data/ext/spidermonkey/global.h +11 -0
  20. data/ext/spidermonkey/idhash.c +16 -0
  21. data/ext/spidermonkey/idhash.h +8 -0
  22. data/ext/spidermonkey/immutable_node.c +1153 -0
  23. data/ext/spidermonkey/immutable_node.c.erb +523 -0
  24. data/ext/spidermonkey/immutable_node.h +22 -0
  25. data/ext/spidermonkey/jroot.h +187 -0
  26. data/ext/spidermonkey/js_land_proxy.c +610 -0
  27. data/ext/spidermonkey/js_land_proxy.h +20 -0
  28. data/ext/spidermonkey/ruby_land_proxy.c +543 -0
  29. data/ext/spidermonkey/ruby_land_proxy.h +17 -0
  30. data/ext/spidermonkey/runtime.c +330 -0
  31. data/ext/spidermonkey/runtime.h +25 -0
  32. data/ext/spidermonkey/spidermonkey.c +20 -0
  33. data/ext/spidermonkey/spidermonkey.h +29 -0
  34. data/johnson.gemspec +44 -0
  35. data/js/johnson/cli.js +30 -0
  36. data/js/johnson/prelude.js +80 -0
  37. data/lib/johnson.rb +55 -0
  38. data/lib/johnson/cli.rb +7 -0
  39. data/lib/johnson/cli/options.rb +67 -0
  40. data/lib/johnson/error.rb +4 -0
  41. data/lib/johnson/nodes.rb +7 -0
  42. data/lib/johnson/nodes/binary_node.rb +65 -0
  43. data/lib/johnson/nodes/for.rb +14 -0
  44. data/lib/johnson/nodes/for_in.rb +12 -0
  45. data/lib/johnson/nodes/function.rb +13 -0
  46. data/lib/johnson/nodes/list.rb +28 -0
  47. data/lib/johnson/nodes/node.rb +68 -0
  48. data/lib/johnson/nodes/ternary_node.rb +20 -0
  49. data/lib/johnson/parser.rb +21 -0
  50. data/lib/johnson/parser/syntax_error.rb +13 -0
  51. data/lib/johnson/runtime.rb +63 -0
  52. data/lib/johnson/spidermonkey/context.rb +10 -0
  53. data/lib/johnson/spidermonkey/debugger.rb +67 -0
  54. data/lib/johnson/spidermonkey/immutable_node.rb +282 -0
  55. data/lib/johnson/spidermonkey/js_land_proxy.rb +62 -0
  56. data/lib/johnson/spidermonkey/mutable_tree_visitor.rb +242 -0
  57. data/lib/johnson/spidermonkey/ruby_land_proxy.rb +54 -0
  58. data/lib/johnson/spidermonkey/runtime.rb +103 -0
  59. data/lib/johnson/version.rb +3 -0
  60. data/lib/johnson/visitable.rb +16 -0
  61. data/lib/johnson/visitors.rb +5 -0
  62. data/lib/johnson/visitors/dot_visitor.rb +169 -0
  63. data/lib/johnson/visitors/ecma_visitor.rb +323 -0
  64. data/lib/johnson/visitors/enumerating_visitor.rb +15 -0
  65. data/lib/johnson/visitors/sexp_visitor.rb +174 -0
  66. data/lib/johnson/visitors/visitor.rb +91 -0
  67. data/lib/rails/init.rb +37 -0
  68. data/lib/tasks/gem.rake +9 -0
  69. data/lib/tasks/parsing.rake +37 -0
  70. data/lib/tasks/testing.rake +36 -0
  71. data/lib/tasks/vendor.rake +20 -0
  72. data/test/helper.rb +55 -0
  73. data/test/johnson/browser_test.rb +43 -0
  74. data/test/johnson/conversions/array_test.rb +32 -0
  75. data/test/johnson/conversions/boolean_test.rb +17 -0
  76. data/test/johnson/conversions/callable_test.rb +34 -0
  77. data/test/johnson/conversions/file_test.rb +15 -0
  78. data/test/johnson/conversions/nil_test.rb +20 -0
  79. data/test/johnson/conversions/number_test.rb +34 -0
  80. data/test/johnson/conversions/regexp_test.rb +24 -0
  81. data/test/johnson/conversions/string_test.rb +26 -0
  82. data/test/johnson/conversions/struct_test.rb +15 -0
  83. data/test/johnson/conversions/symbol_test.rb +19 -0
  84. data/test/johnson/conversions/thread_test.rb +24 -0
  85. data/test/johnson/error_test.rb +9 -0
  86. data/test/johnson/extensions_test.rb +56 -0
  87. data/test/johnson/nodes/array_literal_test.rb +57 -0
  88. data/test/johnson/nodes/array_node_test.rb +26 -0
  89. data/test/johnson/nodes/binary_node_test.rb +61 -0
  90. data/test/johnson/nodes/bracket_access_test.rb +16 -0
  91. data/test/johnson/nodes/delete_test.rb +11 -0
  92. data/test/johnson/nodes/do_while_test.rb +12 -0
  93. data/test/johnson/nodes/dot_accessor_test.rb +15 -0
  94. data/test/johnson/nodes/export_test.rb +9 -0
  95. data/test/johnson/nodes/for_test.rb +54 -0
  96. data/test/johnson/nodes/function_test.rb +71 -0
  97. data/test/johnson/nodes/if_test.rb +41 -0
  98. data/test/johnson/nodes/import_test.rb +13 -0
  99. data/test/johnson/nodes/label_test.rb +19 -0
  100. data/test/johnson/nodes/let_test.rb +31 -0
  101. data/test/johnson/nodes/object_literal_test.rb +110 -0
  102. data/test/johnson/nodes/return_test.rb +16 -0
  103. data/test/johnson/nodes/semi_test.rb +8 -0
  104. data/test/johnson/nodes/switch_test.rb +55 -0
  105. data/test/johnson/nodes/ternary_test.rb +25 -0
  106. data/test/johnson/nodes/throw_test.rb +9 -0
  107. data/test/johnson/nodes/try_node_test.rb +59 -0
  108. data/test/johnson/nodes/typeof_test.rb +11 -0
  109. data/test/johnson/nodes/unary_node_test.rb +23 -0
  110. data/test/johnson/nodes/void_test.rb +11 -0
  111. data/test/johnson/nodes/while_test.rb +26 -0
  112. data/test/johnson/nodes/with_test.rb +10 -0
  113. data/test/johnson/prelude_test.rb +56 -0
  114. data/test/johnson/runtime_test.rb +64 -0
  115. data/test/johnson/spidermonkey/context_test.rb +21 -0
  116. data/test/johnson/spidermonkey/immutable_node_test.rb +34 -0
  117. data/test/johnson/spidermonkey/js_land_proxy_test.rb +236 -0
  118. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +240 -0
  119. data/test/johnson/spidermonkey/runtime_test.rb +17 -0
  120. data/test/johnson/version_test.rb +13 -0
  121. data/test/johnson/visitors/dot_visitor_test.rb +39 -0
  122. data/test/johnson/visitors/enumerating_visitor_test.rb +12 -0
  123. data/test/johnson_test.rb +16 -0
  124. data/test/parser_test.rb +276 -0
  125. data/vendor/spidermonkey/.cvsignore +9 -0
  126. data/vendor/spidermonkey/Makefile.in +449 -0
  127. data/vendor/spidermonkey/Makefile.ref +365 -0
  128. data/vendor/spidermonkey/README.html +820 -0
  129. data/vendor/spidermonkey/SpiderMonkey.rsp +12 -0
  130. data/vendor/spidermonkey/Y.js +19 -0
  131. data/vendor/spidermonkey/build.mk +43 -0
  132. data/vendor/spidermonkey/config.mk +192 -0
  133. data/vendor/spidermonkey/config/AIX4.1.mk +65 -0
  134. data/vendor/spidermonkey/config/AIX4.2.mk +64 -0
  135. data/vendor/spidermonkey/config/AIX4.3.mk +65 -0
  136. data/vendor/spidermonkey/config/Darwin.mk +83 -0
  137. data/vendor/spidermonkey/config/Darwin1.3.mk +81 -0
  138. data/vendor/spidermonkey/config/Darwin1.4.mk +41 -0
  139. data/vendor/spidermonkey/config/Darwin5.2.mk +81 -0
  140. data/vendor/spidermonkey/config/Darwin5.3.mk +81 -0
  141. data/vendor/spidermonkey/config/HP-UXB.10.10.mk +77 -0
  142. data/vendor/spidermonkey/config/HP-UXB.10.20.mk +77 -0
  143. data/vendor/spidermonkey/config/HP-UXB.11.00.mk +80 -0
  144. data/vendor/spidermonkey/config/IRIX.mk +87 -0
  145. data/vendor/spidermonkey/config/IRIX5.3.mk +44 -0
  146. data/vendor/spidermonkey/config/IRIX6.1.mk +44 -0
  147. data/vendor/spidermonkey/config/IRIX6.2.mk +44 -0
  148. data/vendor/spidermonkey/config/IRIX6.3.mk +44 -0
  149. data/vendor/spidermonkey/config/IRIX6.5.mk +44 -0
  150. data/vendor/spidermonkey/config/Linux_All.mk +103 -0
  151. data/vendor/spidermonkey/config/Mac_OS10.0.mk +82 -0
  152. data/vendor/spidermonkey/config/OSF1V4.0.mk +72 -0
  153. data/vendor/spidermonkey/config/OSF1V5.0.mk +69 -0
  154. data/vendor/spidermonkey/config/SunOS4.1.4.mk +101 -0
  155. data/vendor/spidermonkey/config/SunOS5.10.mk +50 -0
  156. data/vendor/spidermonkey/config/SunOS5.3.mk +91 -0
  157. data/vendor/spidermonkey/config/SunOS5.4.mk +92 -0
  158. data/vendor/spidermonkey/config/SunOS5.5.1.mk +44 -0
  159. data/vendor/spidermonkey/config/SunOS5.5.mk +87 -0
  160. data/vendor/spidermonkey/config/SunOS5.6.mk +89 -0
  161. data/vendor/spidermonkey/config/SunOS5.7.mk +44 -0
  162. data/vendor/spidermonkey/config/SunOS5.8.mk +44 -0
  163. data/vendor/spidermonkey/config/SunOS5.9.mk +44 -0
  164. data/vendor/spidermonkey/config/WINNT4.0.mk +117 -0
  165. data/vendor/spidermonkey/config/WINNT5.0.mk +117 -0
  166. data/vendor/spidermonkey/config/WINNT5.1.mk +117 -0
  167. data/vendor/spidermonkey/config/WINNT5.2.mk +117 -0
  168. data/vendor/spidermonkey/config/WINNT6.0.mk +117 -0
  169. data/vendor/spidermonkey/config/dgux.mk +64 -0
  170. data/vendor/spidermonkey/editline/Makefile.ref +144 -0
  171. data/vendor/spidermonkey/editline/README +83 -0
  172. data/vendor/spidermonkey/editline/editline.3 +175 -0
  173. data/vendor/spidermonkey/editline/editline.c +1369 -0
  174. data/vendor/spidermonkey/editline/editline.h +135 -0
  175. data/vendor/spidermonkey/editline/sysunix.c +182 -0
  176. data/vendor/spidermonkey/editline/unix.h +82 -0
  177. data/vendor/spidermonkey/fdlibm/.cvsignore +7 -0
  178. data/vendor/spidermonkey/fdlibm/Makefile.in +127 -0
  179. data/vendor/spidermonkey/fdlibm/Makefile.ref +192 -0
  180. data/vendor/spidermonkey/fdlibm/e_acos.c +147 -0
  181. data/vendor/spidermonkey/fdlibm/e_acosh.c +105 -0
  182. data/vendor/spidermonkey/fdlibm/e_asin.c +156 -0
  183. data/vendor/spidermonkey/fdlibm/e_atan2.c +165 -0
  184. data/vendor/spidermonkey/fdlibm/e_atanh.c +110 -0
  185. data/vendor/spidermonkey/fdlibm/e_cosh.c +133 -0
  186. data/vendor/spidermonkey/fdlibm/e_exp.c +202 -0
  187. data/vendor/spidermonkey/fdlibm/e_fmod.c +184 -0
  188. data/vendor/spidermonkey/fdlibm/e_gamma.c +71 -0
  189. data/vendor/spidermonkey/fdlibm/e_gamma_r.c +70 -0
  190. data/vendor/spidermonkey/fdlibm/e_hypot.c +173 -0
  191. data/vendor/spidermonkey/fdlibm/e_j0.c +524 -0
  192. data/vendor/spidermonkey/fdlibm/e_j1.c +523 -0
  193. data/vendor/spidermonkey/fdlibm/e_jn.c +315 -0
  194. data/vendor/spidermonkey/fdlibm/e_lgamma.c +71 -0
  195. data/vendor/spidermonkey/fdlibm/e_lgamma_r.c +347 -0
  196. data/vendor/spidermonkey/fdlibm/e_log.c +184 -0
  197. data/vendor/spidermonkey/fdlibm/e_log10.c +134 -0
  198. data/vendor/spidermonkey/fdlibm/e_pow.c +386 -0
  199. data/vendor/spidermonkey/fdlibm/e_rem_pio2.c +222 -0
  200. data/vendor/spidermonkey/fdlibm/e_remainder.c +120 -0
  201. data/vendor/spidermonkey/fdlibm/e_scalb.c +89 -0
  202. data/vendor/spidermonkey/fdlibm/e_sinh.c +122 -0
  203. data/vendor/spidermonkey/fdlibm/e_sqrt.c +497 -0
  204. data/vendor/spidermonkey/fdlibm/fdlibm.h +273 -0
  205. data/vendor/spidermonkey/fdlibm/fdlibm.mak +1453 -0
  206. data/vendor/spidermonkey/fdlibm/fdlibm.mdp +0 -0
  207. data/vendor/spidermonkey/fdlibm/k_cos.c +135 -0
  208. data/vendor/spidermonkey/fdlibm/k_rem_pio2.c +354 -0
  209. data/vendor/spidermonkey/fdlibm/k_sin.c +114 -0
  210. data/vendor/spidermonkey/fdlibm/k_standard.c +785 -0
  211. data/vendor/spidermonkey/fdlibm/k_tan.c +170 -0
  212. data/vendor/spidermonkey/fdlibm/s_asinh.c +101 -0
  213. data/vendor/spidermonkey/fdlibm/s_atan.c +175 -0
  214. data/vendor/spidermonkey/fdlibm/s_cbrt.c +133 -0
  215. data/vendor/spidermonkey/fdlibm/s_ceil.c +120 -0
  216. data/vendor/spidermonkey/fdlibm/s_copysign.c +72 -0
  217. data/vendor/spidermonkey/fdlibm/s_cos.c +118 -0
  218. data/vendor/spidermonkey/fdlibm/s_erf.c +356 -0
  219. data/vendor/spidermonkey/fdlibm/s_expm1.c +267 -0
  220. data/vendor/spidermonkey/fdlibm/s_fabs.c +70 -0
  221. data/vendor/spidermonkey/fdlibm/s_finite.c +71 -0
  222. data/vendor/spidermonkey/fdlibm/s_floor.c +121 -0
  223. data/vendor/spidermonkey/fdlibm/s_frexp.c +99 -0
  224. data/vendor/spidermonkey/fdlibm/s_ilogb.c +85 -0
  225. data/vendor/spidermonkey/fdlibm/s_isnan.c +74 -0
  226. data/vendor/spidermonkey/fdlibm/s_ldexp.c +66 -0
  227. data/vendor/spidermonkey/fdlibm/s_lib_version.c +73 -0
  228. data/vendor/spidermonkey/fdlibm/s_log1p.c +211 -0
  229. data/vendor/spidermonkey/fdlibm/s_logb.c +79 -0
  230. data/vendor/spidermonkey/fdlibm/s_matherr.c +64 -0
  231. data/vendor/spidermonkey/fdlibm/s_modf.c +132 -0
  232. data/vendor/spidermonkey/fdlibm/s_nextafter.c +124 -0
  233. data/vendor/spidermonkey/fdlibm/s_rint.c +131 -0
  234. data/vendor/spidermonkey/fdlibm/s_scalbn.c +107 -0
  235. data/vendor/spidermonkey/fdlibm/s_signgam.c +40 -0
  236. data/vendor/spidermonkey/fdlibm/s_significand.c +68 -0
  237. data/vendor/spidermonkey/fdlibm/s_sin.c +118 -0
  238. data/vendor/spidermonkey/fdlibm/s_tan.c +112 -0
  239. data/vendor/spidermonkey/fdlibm/s_tanh.c +122 -0
  240. data/vendor/spidermonkey/fdlibm/w_acos.c +78 -0
  241. data/vendor/spidermonkey/fdlibm/w_acosh.c +78 -0
  242. data/vendor/spidermonkey/fdlibm/w_asin.c +80 -0
  243. data/vendor/spidermonkey/fdlibm/w_atan2.c +79 -0
  244. data/vendor/spidermonkey/fdlibm/w_atanh.c +81 -0
  245. data/vendor/spidermonkey/fdlibm/w_cosh.c +77 -0
  246. data/vendor/spidermonkey/fdlibm/w_exp.c +88 -0
  247. data/vendor/spidermonkey/fdlibm/w_fmod.c +78 -0
  248. data/vendor/spidermonkey/fdlibm/w_gamma.c +85 -0
  249. data/vendor/spidermonkey/fdlibm/w_gamma_r.c +81 -0
  250. data/vendor/spidermonkey/fdlibm/w_hypot.c +78 -0
  251. data/vendor/spidermonkey/fdlibm/w_j0.c +105 -0
  252. data/vendor/spidermonkey/fdlibm/w_j1.c +106 -0
  253. data/vendor/spidermonkey/fdlibm/w_jn.c +128 -0
  254. data/vendor/spidermonkey/fdlibm/w_lgamma.c +85 -0
  255. data/vendor/spidermonkey/fdlibm/w_lgamma_r.c +81 -0
  256. data/vendor/spidermonkey/fdlibm/w_log.c +78 -0
  257. data/vendor/spidermonkey/fdlibm/w_log10.c +81 -0
  258. data/vendor/spidermonkey/fdlibm/w_pow.c +99 -0
  259. data/vendor/spidermonkey/fdlibm/w_remainder.c +77 -0
  260. data/vendor/spidermonkey/fdlibm/w_scalb.c +95 -0
  261. data/vendor/spidermonkey/fdlibm/w_sinh.c +77 -0
  262. data/vendor/spidermonkey/fdlibm/w_sqrt.c +77 -0
  263. data/vendor/spidermonkey/javascript-trace.d +73 -0
  264. data/vendor/spidermonkey/js.c +3951 -0
  265. data/vendor/spidermonkey/js.mdp +0 -0
  266. data/vendor/spidermonkey/js.msg +308 -0
  267. data/vendor/spidermonkey/js3240.rc +79 -0
  268. data/vendor/spidermonkey/jsOS240.def +654 -0
  269. data/vendor/spidermonkey/jsapi.c +5836 -0
  270. data/vendor/spidermonkey/jsapi.h +2624 -0
  271. data/vendor/spidermonkey/jsarena.c +450 -0
  272. data/vendor/spidermonkey/jsarena.h +318 -0
  273. data/vendor/spidermonkey/jsarray.c +2996 -0
  274. data/vendor/spidermonkey/jsarray.h +127 -0
  275. data/vendor/spidermonkey/jsatom.c +1045 -0
  276. data/vendor/spidermonkey/jsatom.h +442 -0
  277. data/vendor/spidermonkey/jsbit.h +253 -0
  278. data/vendor/spidermonkey/jsbool.c +176 -0
  279. data/vendor/spidermonkey/jsbool.h +73 -0
  280. data/vendor/spidermonkey/jsclist.h +139 -0
  281. data/vendor/spidermonkey/jscntxt.c +1348 -0
  282. data/vendor/spidermonkey/jscntxt.h +1120 -0
  283. data/vendor/spidermonkey/jscompat.h +57 -0
  284. data/vendor/spidermonkey/jsconfig.h +248 -0
  285. data/vendor/spidermonkey/jsconfig.mk +181 -0
  286. data/vendor/spidermonkey/jscpucfg.c +396 -0
  287. data/vendor/spidermonkey/jscpucfg.h +212 -0
  288. data/vendor/spidermonkey/jsdate.c +2390 -0
  289. data/vendor/spidermonkey/jsdate.h +124 -0
  290. data/vendor/spidermonkey/jsdbgapi.c +1802 -0
  291. data/vendor/spidermonkey/jsdbgapi.h +464 -0
  292. data/vendor/spidermonkey/jsdhash.c +868 -0
  293. data/vendor/spidermonkey/jsdhash.h +592 -0
  294. data/vendor/spidermonkey/jsdtoa.c +3167 -0
  295. data/vendor/spidermonkey/jsdtoa.h +130 -0
  296. data/vendor/spidermonkey/jsdtracef.c +317 -0
  297. data/vendor/spidermonkey/jsdtracef.h +77 -0
  298. data/vendor/spidermonkey/jsemit.c +6909 -0
  299. data/vendor/spidermonkey/jsemit.h +741 -0
  300. data/vendor/spidermonkey/jsexn.c +1371 -0
  301. data/vendor/spidermonkey/jsexn.h +96 -0
  302. data/vendor/spidermonkey/jsfile.c +2736 -0
  303. data/vendor/spidermonkey/jsfile.h +56 -0
  304. data/vendor/spidermonkey/jsfile.msg +90 -0
  305. data/vendor/spidermonkey/jsfun.c +2634 -0
  306. data/vendor/spidermonkey/jsfun.h +254 -0
  307. data/vendor/spidermonkey/jsgc.c +3562 -0
  308. data/vendor/spidermonkey/jsgc.h +403 -0
  309. data/vendor/spidermonkey/jshash.c +476 -0
  310. data/vendor/spidermonkey/jshash.h +151 -0
  311. data/vendor/spidermonkey/jsify.pl +485 -0
  312. data/vendor/spidermonkey/jsinterp.c +7007 -0
  313. data/vendor/spidermonkey/jsinterp.h +525 -0
  314. data/vendor/spidermonkey/jsinvoke.c +43 -0
  315. data/vendor/spidermonkey/jsiter.c +1067 -0
  316. data/vendor/spidermonkey/jsiter.h +122 -0
  317. data/vendor/spidermonkey/jskeyword.tbl +124 -0
  318. data/vendor/spidermonkey/jskwgen.c +460 -0
  319. data/vendor/spidermonkey/jslibmath.h +266 -0
  320. data/vendor/spidermonkey/jslock.c +1309 -0
  321. data/vendor/spidermonkey/jslock.h +313 -0
  322. data/vendor/spidermonkey/jslocko.asm +60 -0
  323. data/vendor/spidermonkey/jslog2.c +94 -0
  324. data/vendor/spidermonkey/jslong.c +264 -0
  325. data/vendor/spidermonkey/jslong.h +412 -0
  326. data/vendor/spidermonkey/jsmath.c +567 -0
  327. data/vendor/spidermonkey/jsmath.h +57 -0
  328. data/vendor/spidermonkey/jsnum.c +1239 -0
  329. data/vendor/spidermonkey/jsnum.h +283 -0
  330. data/vendor/spidermonkey/jsobj.c +5282 -0
  331. data/vendor/spidermonkey/jsobj.h +709 -0
  332. data/vendor/spidermonkey/jsopcode.c +5245 -0
  333. data/vendor/spidermonkey/jsopcode.h +394 -0
  334. data/vendor/spidermonkey/jsopcode.tbl +523 -0
  335. data/vendor/spidermonkey/jsotypes.h +202 -0
  336. data/vendor/spidermonkey/jsparse.c +6704 -0
  337. data/vendor/spidermonkey/jsparse.h +511 -0
  338. data/vendor/spidermonkey/jsprf.c +1262 -0
  339. data/vendor/spidermonkey/jsprf.h +150 -0
  340. data/vendor/spidermonkey/jsproto.tbl +128 -0
  341. data/vendor/spidermonkey/jsprvtd.h +267 -0
  342. data/vendor/spidermonkey/jspubtd.h +744 -0
  343. data/vendor/spidermonkey/jsregexp.c +4364 -0
  344. data/vendor/spidermonkey/jsregexp.h +183 -0
  345. data/vendor/spidermonkey/jsreops.tbl +145 -0
  346. data/vendor/spidermonkey/jsscan.c +2012 -0
  347. data/vendor/spidermonkey/jsscan.h +387 -0
  348. data/vendor/spidermonkey/jsscope.c +1957 -0
  349. data/vendor/spidermonkey/jsscope.h +418 -0
  350. data/vendor/spidermonkey/jsscript.c +1832 -0
  351. data/vendor/spidermonkey/jsscript.h +287 -0
  352. data/vendor/spidermonkey/jsshell.msg +50 -0
  353. data/vendor/spidermonkey/jsstddef.h +83 -0
  354. data/vendor/spidermonkey/jsstr.c +5005 -0
  355. data/vendor/spidermonkey/jsstr.h +641 -0
  356. data/vendor/spidermonkey/jstypes.h +475 -0
  357. data/vendor/spidermonkey/jsutil.c +345 -0
  358. data/vendor/spidermonkey/jsutil.h +157 -0
  359. data/vendor/spidermonkey/jsxdrapi.c +800 -0
  360. data/vendor/spidermonkey/jsxdrapi.h +218 -0
  361. data/vendor/spidermonkey/jsxml.c +8476 -0
  362. data/vendor/spidermonkey/jsxml.h +349 -0
  363. data/vendor/spidermonkey/lock_SunOS.s +119 -0
  364. data/vendor/spidermonkey/perfect.js +39 -0
  365. data/vendor/spidermonkey/plify_jsdhash.sed +36 -0
  366. data/vendor/spidermonkey/prmjtime.c +846 -0
  367. data/vendor/spidermonkey/prmjtime.h +103 -0
  368. data/vendor/spidermonkey/resource.h +15 -0
  369. data/vendor/spidermonkey/rules.mk +197 -0
  370. data/vendor/spidermonkey/win32.order +384 -0
  371. metadata +513 -0
@@ -0,0 +1,592 @@
1
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
+ /* ***** BEGIN LICENSE BLOCK *****
3
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
+ *
5
+ * The contents of this file are subject to the Mozilla Public License Version
6
+ * 1.1 (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ * http://www.mozilla.org/MPL/
9
+ *
10
+ * Software distributed under the License is distributed on an "AS IS" basis,
11
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
+ * for the specific language governing rights and limitations under the
13
+ * License.
14
+ *
15
+ * The Original Code is Mozilla JavaScript code.
16
+ *
17
+ * The Initial Developer of the Original Code is
18
+ * Netscape Communications Corporation.
19
+ * Portions created by the Initial Developer are Copyright (C) 1999-2001
20
+ * the Initial Developer. All Rights Reserved.
21
+ *
22
+ * Contributor(s):
23
+ * Brendan Eich <brendan@mozilla.org> (Original Author)
24
+ *
25
+ * Alternatively, the contents of this file may be used under the terms of
26
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
27
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
+ * in which case the provisions of the GPL or the LGPL are applicable instead
29
+ * of those above. If you wish to allow use of your version of this file only
30
+ * under the terms of either the GPL or the LGPL, and not to allow others to
31
+ * use your version of this file under the terms of the MPL, indicate your
32
+ * decision by deleting the provisions above and replace them with the notice
33
+ * and other provisions required by the GPL or the LGPL. If you do not delete
34
+ * the provisions above, a recipient may use your version of this file under
35
+ * the terms of any one of the MPL, the GPL or the LGPL.
36
+ *
37
+ * ***** END LICENSE BLOCK ***** */
38
+
39
+ #ifndef jsdhash_h___
40
+ #define jsdhash_h___
41
+ /*
42
+ * Double hashing, a la Knuth 6.
43
+ */
44
+ #include "jstypes.h"
45
+
46
+ JS_BEGIN_EXTERN_C
47
+
48
+ #if defined(__GNUC__) && defined(__i386__) && (__GNUC__ >= 3) && !defined(XP_OS2)
49
+ #define JS_DHASH_FASTCALL __attribute__ ((regparm (3),stdcall))
50
+ #elif defined(XP_WIN)
51
+ #define JS_DHASH_FASTCALL __fastcall
52
+ #else
53
+ #define JS_DHASH_FASTCALL
54
+ #endif
55
+
56
+ #ifdef DEBUG_XXXbrendan
57
+ #define JS_DHASHMETER 1
58
+ #endif
59
+
60
+ /* Table size limit, do not equal or exceed (see min&maxAlphaFrac, below). */
61
+ #undef JS_DHASH_SIZE_LIMIT
62
+ #define JS_DHASH_SIZE_LIMIT JS_BIT(24)
63
+
64
+ /* Minimum table size, or gross entry count (net is at most .75 loaded). */
65
+ #ifndef JS_DHASH_MIN_SIZE
66
+ #define JS_DHASH_MIN_SIZE 16
67
+ #elif (JS_DHASH_MIN_SIZE & (JS_DHASH_MIN_SIZE - 1)) != 0
68
+ #error "JS_DHASH_MIN_SIZE must be a power of two!"
69
+ #endif
70
+
71
+ /*
72
+ * Multiplicative hash uses an unsigned 32 bit integer and the golden ratio,
73
+ * expressed as a fixed-point 32-bit fraction.
74
+ */
75
+ #define JS_DHASH_BITS 32
76
+ #define JS_DHASH_GOLDEN_RATIO 0x9E3779B9U
77
+
78
+ /* Primitive and forward-struct typedefs. */
79
+ typedef uint32 JSDHashNumber;
80
+ typedef struct JSDHashEntryHdr JSDHashEntryHdr;
81
+ typedef struct JSDHashEntryStub JSDHashEntryStub;
82
+ typedef struct JSDHashTable JSDHashTable;
83
+ typedef struct JSDHashTableOps JSDHashTableOps;
84
+
85
+ /*
86
+ * Table entry header structure.
87
+ *
88
+ * In order to allow in-line allocation of key and value, we do not declare
89
+ * either here. Instead, the API uses const void *key as a formal parameter.
90
+ * The key need not be stored in the entry; it may be part of the value, but
91
+ * need not be stored at all.
92
+ *
93
+ * Callback types are defined below and grouped into the JSDHashTableOps
94
+ * structure, for single static initialization per hash table sub-type.
95
+ *
96
+ * Each hash table sub-type should nest the JSDHashEntryHdr structure at the
97
+ * front of its particular entry type. The keyHash member contains the result
98
+ * of multiplying the hash code returned from the hashKey callback (see below)
99
+ * by JS_DHASH_GOLDEN_RATIO, then constraining the result to avoid the magic 0
100
+ * and 1 values. The stored keyHash value is table size invariant, and it is
101
+ * maintained automatically by JS_DHashTableOperate -- users should never set
102
+ * it, and its only uses should be via the entry macros below.
103
+ *
104
+ * The JS_DHASH_ENTRY_IS_LIVE macro tests whether entry is neither free nor
105
+ * removed. An entry may be either busy or free; if busy, it may be live or
106
+ * removed. Consumers of this API should not access members of entries that
107
+ * are not live.
108
+ *
109
+ * However, use JS_DHASH_ENTRY_IS_BUSY for faster liveness testing of entries
110
+ * returned by JS_DHashTableOperate, as JS_DHashTableOperate never returns a
111
+ * non-live, busy (i.e., removed) entry pointer to its caller. See below for
112
+ * more details on JS_DHashTableOperate's calling rules.
113
+ */
114
+ struct JSDHashEntryHdr {
115
+ JSDHashNumber keyHash; /* every entry must begin like this */
116
+ };
117
+
118
+ #define JS_DHASH_ENTRY_IS_FREE(entry) ((entry)->keyHash == 0)
119
+ #define JS_DHASH_ENTRY_IS_BUSY(entry) (!JS_DHASH_ENTRY_IS_FREE(entry))
120
+ #define JS_DHASH_ENTRY_IS_LIVE(entry) ((entry)->keyHash >= 2)
121
+
122
+ /*
123
+ * A JSDHashTable is currently 8 words (without the JS_DHASHMETER overhead)
124
+ * on most architectures, and may be allocated on the stack or within another
125
+ * structure or class (see below for the Init and Finish functions to use).
126
+ *
127
+ * To decide whether to use double hashing vs. chaining, we need to develop a
128
+ * trade-off relation, as follows:
129
+ *
130
+ * Let alpha be the load factor, esize the entry size in words, count the
131
+ * entry count, and pow2 the power-of-two table size in entries.
132
+ *
133
+ * (JSDHashTable overhead) > (JSHashTable overhead)
134
+ * (unused table entry space) > (malloc and .next overhead per entry) +
135
+ * (buckets overhead)
136
+ * (1 - alpha) * esize * pow2 > 2 * count + pow2
137
+ *
138
+ * Notice that alpha is by definition (count / pow2):
139
+ *
140
+ * (1 - alpha) * esize * pow2 > 2 * alpha * pow2 + pow2
141
+ * (1 - alpha) * esize > 2 * alpha + 1
142
+ *
143
+ * esize > (1 + 2 * alpha) / (1 - alpha)
144
+ *
145
+ * This assumes both tables must keep keyHash, key, and value for each entry,
146
+ * where key and value point to separately allocated strings or structures.
147
+ * If key and value can be combined into one pointer, then the trade-off is:
148
+ *
149
+ * esize > (1 + 3 * alpha) / (1 - alpha)
150
+ *
151
+ * If the entry value can be a subtype of JSDHashEntryHdr, rather than a type
152
+ * that must be allocated separately and referenced by an entry.value pointer
153
+ * member, and provided key's allocation can be fused with its entry's, then
154
+ * k (the words wasted per entry with chaining) is 4.
155
+ *
156
+ * To see these curves, feed gnuplot input like so:
157
+ *
158
+ * gnuplot> f(x,k) = (1 + k * x) / (1 - x)
159
+ * gnuplot> plot [0:.75] f(x,2), f(x,3), f(x,4)
160
+ *
161
+ * For k of 2 and a well-loaded table (alpha > .5), esize must be more than 4
162
+ * words for chaining to be more space-efficient than double hashing.
163
+ *
164
+ * Solving for alpha helps us decide when to shrink an underloaded table:
165
+ *
166
+ * esize > (1 + k * alpha) / (1 - alpha)
167
+ * esize - alpha * esize > 1 + k * alpha
168
+ * esize - 1 > (k + esize) * alpha
169
+ * (esize - 1) / (k + esize) > alpha
170
+ *
171
+ * alpha < (esize - 1) / (esize + k)
172
+ *
173
+ * Therefore double hashing should keep alpha >= (esize - 1) / (esize + k),
174
+ * assuming esize is not too large (in which case, chaining should probably be
175
+ * used for any alpha). For esize=2 and k=3, we want alpha >= .2; for esize=3
176
+ * and k=2, we want alpha >= .4. For k=4, esize could be 6, and alpha >= .5
177
+ * would still obtain. See the JS_DHASH_MIN_ALPHA macro further below.
178
+ *
179
+ * The current implementation uses a configurable lower bound on alpha, which
180
+ * defaults to .25, when deciding to shrink the table (while still respecting
181
+ * JS_DHASH_MIN_SIZE).
182
+ *
183
+ * Note a qualitative difference between chaining and double hashing: under
184
+ * chaining, entry addresses are stable across table shrinks and grows. With
185
+ * double hashing, you can't safely hold an entry pointer and use it after an
186
+ * ADD or REMOVE operation, unless you sample table->generation before adding
187
+ * or removing, and compare the sample after, dereferencing the entry pointer
188
+ * only if table->generation has not changed.
189
+ *
190
+ * The moral of this story: there is no one-size-fits-all hash table scheme,
191
+ * but for small table entry size, and assuming entry address stability is not
192
+ * required, double hashing wins.
193
+ */
194
+ struct JSDHashTable {
195
+ const JSDHashTableOps *ops; /* virtual operations, see below */
196
+ void *data; /* ops- and instance-specific data */
197
+ int16 hashShift; /* multiplicative hash shift */
198
+ uint8 maxAlphaFrac; /* 8-bit fixed point max alpha */
199
+ uint8 minAlphaFrac; /* 8-bit fixed point min alpha */
200
+ uint32 entrySize; /* number of bytes in an entry */
201
+ uint32 entryCount; /* number of entries in table */
202
+ uint32 removedCount; /* removed entry sentinels in table */
203
+ uint32 generation; /* entry storage generation number */
204
+ char *entryStore; /* entry storage */
205
+ #ifdef JS_DHASHMETER
206
+ struct JSDHashStats {
207
+ uint32 searches; /* total number of table searches */
208
+ uint32 steps; /* hash chain links traversed */
209
+ uint32 hits; /* searches that found key */
210
+ uint32 misses; /* searches that didn't find key */
211
+ uint32 lookups; /* number of JS_DHASH_LOOKUPs */
212
+ uint32 addMisses; /* adds that miss, and do work */
213
+ uint32 addOverRemoved; /* adds that recycled a removed entry */
214
+ uint32 addHits; /* adds that hit an existing entry */
215
+ uint32 addFailures; /* out-of-memory during add growth */
216
+ uint32 removeHits; /* removes that hit, and do work */
217
+ uint32 removeMisses; /* useless removes that miss */
218
+ uint32 removeFrees; /* removes that freed entry directly */
219
+ uint32 removeEnums; /* removes done by Enumerate */
220
+ uint32 grows; /* table expansions */
221
+ uint32 shrinks; /* table contractions */
222
+ uint32 compresses; /* table compressions */
223
+ uint32 enumShrinks; /* contractions after Enumerate */
224
+ } stats;
225
+ #endif
226
+ };
227
+
228
+ /*
229
+ * Size in entries (gross, not net of free and removed sentinels) for table.
230
+ * We store hashShift rather than sizeLog2 to optimize the collision-free case
231
+ * in SearchTable.
232
+ */
233
+ #define JS_DHASH_TABLE_SIZE(table) JS_BIT(JS_DHASH_BITS - (table)->hashShift)
234
+
235
+ /*
236
+ * Table space at entryStore is allocated and freed using these callbacks.
237
+ * The allocator should return null on error only (not if called with nbytes
238
+ * equal to 0; but note that jsdhash.c code will never call with 0 nbytes).
239
+ */
240
+ typedef void *
241
+ (* JS_DLL_CALLBACK JSDHashAllocTable)(JSDHashTable *table, uint32 nbytes);
242
+
243
+ typedef void
244
+ (* JS_DLL_CALLBACK JSDHashFreeTable) (JSDHashTable *table, void *ptr);
245
+
246
+ /*
247
+ * Compute the hash code for a given key to be looked up, added, or removed
248
+ * from table. A hash code may have any JSDHashNumber value.
249
+ */
250
+ typedef JSDHashNumber
251
+ (* JS_DLL_CALLBACK JSDHashHashKey) (JSDHashTable *table, const void *key);
252
+
253
+ /*
254
+ * Compare the key identifying entry in table with the provided key parameter.
255
+ * Return JS_TRUE if keys match, JS_FALSE otherwise.
256
+ */
257
+ typedef JSBool
258
+ (* JS_DLL_CALLBACK JSDHashMatchEntry)(JSDHashTable *table,
259
+ const JSDHashEntryHdr *entry,
260
+ const void *key);
261
+
262
+ /*
263
+ * Copy the data starting at from to the new entry storage at to. Do not add
264
+ * reference counts for any strong references in the entry, however, as this
265
+ * is a "move" operation: the old entry storage at from will be freed without
266
+ * any reference-decrementing callback shortly.
267
+ */
268
+ typedef void
269
+ (* JS_DLL_CALLBACK JSDHashMoveEntry)(JSDHashTable *table,
270
+ const JSDHashEntryHdr *from,
271
+ JSDHashEntryHdr *to);
272
+
273
+ /*
274
+ * Clear the entry and drop any strong references it holds. This callback is
275
+ * invoked during a JS_DHASH_REMOVE operation (see below for operation codes),
276
+ * but only if the given key is found in the table.
277
+ */
278
+ typedef void
279
+ (* JS_DLL_CALLBACK JSDHashClearEntry)(JSDHashTable *table,
280
+ JSDHashEntryHdr *entry);
281
+
282
+ /*
283
+ * Called when a table (whether allocated dynamically by itself, or nested in
284
+ * a larger structure, or allocated on the stack) is finished. This callback
285
+ * allows table->ops-specific code to finalize table->data.
286
+ */
287
+ typedef void
288
+ (* JS_DLL_CALLBACK JSDHashFinalize) (JSDHashTable *table);
289
+
290
+ /*
291
+ * Initialize a new entry, apart from keyHash. This function is called when
292
+ * JS_DHashTableOperate's JS_DHASH_ADD case finds no existing entry for the
293
+ * given key, and must add a new one. At that point, entry->keyHash is not
294
+ * set yet, to avoid claiming the last free entry in a severely overloaded
295
+ * table.
296
+ */
297
+ typedef JSBool
298
+ (* JS_DLL_CALLBACK JSDHashInitEntry)(JSDHashTable *table,
299
+ JSDHashEntryHdr *entry,
300
+ const void *key);
301
+
302
+ /*
303
+ * Finally, the "vtable" structure for JSDHashTable. The first eight hooks
304
+ * must be provided by implementations; they're called unconditionally by the
305
+ * generic jsdhash.c code. Hooks after these may be null.
306
+ *
307
+ * Summary of allocation-related hook usage with C++ placement new emphasis:
308
+ * allocTable Allocate raw bytes with malloc, no ctors run.
309
+ * freeTable Free raw bytes with free, no dtors run.
310
+ * initEntry Call placement new using default key-based ctor.
311
+ * Return JS_TRUE on success, JS_FALSE on error.
312
+ * moveEntry Call placement new using copy ctor, run dtor on old
313
+ * entry storage.
314
+ * clearEntry Run dtor on entry.
315
+ * finalize Stub unless table->data was initialized and needs to
316
+ * be finalized.
317
+ *
318
+ * Note the reason why initEntry is optional: the default hooks (stubs) clear
319
+ * entry storage: On successful JS_DHashTableOperate(tbl, key, JS_DHASH_ADD),
320
+ * the returned entry pointer addresses an entry struct whose keyHash member
321
+ * has been set non-zero, but all other entry members are still clear (null).
322
+ * JS_DHASH_ADD callers can test such members to see whether the entry was
323
+ * newly created by the JS_DHASH_ADD call that just succeeded. If placement
324
+ * new or similar initialization is required, define an initEntry hook. Of
325
+ * course, the clearEntry hook must zero or null appropriately.
326
+ *
327
+ * XXX assumes 0 is null for pointer types.
328
+ */
329
+ struct JSDHashTableOps {
330
+ /* Mandatory hooks. All implementations must provide these. */
331
+ JSDHashAllocTable allocTable;
332
+ JSDHashFreeTable freeTable;
333
+ JSDHashHashKey hashKey;
334
+ JSDHashMatchEntry matchEntry;
335
+ JSDHashMoveEntry moveEntry;
336
+ JSDHashClearEntry clearEntry;
337
+ JSDHashFinalize finalize;
338
+
339
+ /* Optional hooks start here. If null, these are not called. */
340
+ JSDHashInitEntry initEntry;
341
+ };
342
+
343
+ /*
344
+ * Default implementations for the above ops.
345
+ */
346
+ extern JS_PUBLIC_API(void *)
347
+ JS_DHashAllocTable(JSDHashTable *table, uint32 nbytes);
348
+
349
+ extern JS_PUBLIC_API(void)
350
+ JS_DHashFreeTable(JSDHashTable *table, void *ptr);
351
+
352
+ extern JS_PUBLIC_API(JSDHashNumber)
353
+ JS_DHashStringKey(JSDHashTable *table, const void *key);
354
+
355
+ /* A minimal entry contains a keyHash header and a void key pointer. */
356
+ struct JSDHashEntryStub {
357
+ JSDHashEntryHdr hdr;
358
+ const void *key;
359
+ };
360
+
361
+ extern JS_PUBLIC_API(JSDHashNumber)
362
+ JS_DHashVoidPtrKeyStub(JSDHashTable *table, const void *key);
363
+
364
+ extern JS_PUBLIC_API(JSBool)
365
+ JS_DHashMatchEntryStub(JSDHashTable *table,
366
+ const JSDHashEntryHdr *entry,
367
+ const void *key);
368
+
369
+ extern JS_PUBLIC_API(JSBool)
370
+ JS_DHashMatchStringKey(JSDHashTable *table,
371
+ const JSDHashEntryHdr *entry,
372
+ const void *key);
373
+
374
+ extern JS_PUBLIC_API(void)
375
+ JS_DHashMoveEntryStub(JSDHashTable *table,
376
+ const JSDHashEntryHdr *from,
377
+ JSDHashEntryHdr *to);
378
+
379
+ extern JS_PUBLIC_API(void)
380
+ JS_DHashClearEntryStub(JSDHashTable *table, JSDHashEntryHdr *entry);
381
+
382
+ extern JS_PUBLIC_API(void)
383
+ JS_DHashFreeStringKey(JSDHashTable *table, JSDHashEntryHdr *entry);
384
+
385
+ extern JS_PUBLIC_API(void)
386
+ JS_DHashFinalizeStub(JSDHashTable *table);
387
+
388
+ /*
389
+ * If you use JSDHashEntryStub or a subclass of it as your entry struct, and
390
+ * if your entries move via memcpy and clear via memset(0), you can use these
391
+ * stub operations.
392
+ */
393
+ extern JS_PUBLIC_API(const JSDHashTableOps *)
394
+ JS_DHashGetStubOps(void);
395
+
396
+ /*
397
+ * Dynamically allocate a new JSDHashTable using malloc, initialize it using
398
+ * JS_DHashTableInit, and return its address. Return null on malloc failure.
399
+ * Note that the entry storage at table->entryStore will be allocated using
400
+ * the ops->allocTable callback.
401
+ */
402
+ extern JS_PUBLIC_API(JSDHashTable *)
403
+ JS_NewDHashTable(const JSDHashTableOps *ops, void *data, uint32 entrySize,
404
+ uint32 capacity);
405
+
406
+ /*
407
+ * Finalize table's data, free its entry storage (via table->ops->freeTable),
408
+ * and return the memory starting at table to the malloc heap.
409
+ */
410
+ extern JS_PUBLIC_API(void)
411
+ JS_DHashTableDestroy(JSDHashTable *table);
412
+
413
+ /*
414
+ * Initialize table with ops, data, entrySize, and capacity. Capacity is a
415
+ * guess for the smallest table size at which the table will usually be less
416
+ * than 75% loaded (the table will grow or shrink as needed; capacity serves
417
+ * only to avoid inevitable early growth from JS_DHASH_MIN_SIZE).
418
+ */
419
+ extern JS_PUBLIC_API(JSBool)
420
+ JS_DHashTableInit(JSDHashTable *table, const JSDHashTableOps *ops, void *data,
421
+ uint32 entrySize, uint32 capacity);
422
+
423
+ /*
424
+ * Set maximum and minimum alpha for table. The defaults are 0.75 and .25.
425
+ * maxAlpha must be in [0.5, 0.9375] for the default JS_DHASH_MIN_SIZE; or if
426
+ * MinSize=JS_DHASH_MIN_SIZE <= 256, in [0.5, (float)(MinSize-1)/MinSize]; or
427
+ * else in [0.5, 255.0/256]. minAlpha must be in [0, maxAlpha / 2), so that
428
+ * we don't shrink on the very next remove after growing a table upon adding
429
+ * an entry that brings entryCount past maxAlpha * tableSize.
430
+ */
431
+ extern JS_PUBLIC_API(void)
432
+ JS_DHashTableSetAlphaBounds(JSDHashTable *table,
433
+ float maxAlpha,
434
+ float minAlpha);
435
+
436
+ /*
437
+ * Call this macro with k, the number of pointer-sized words wasted per entry
438
+ * under chaining, to compute the minimum alpha at which double hashing still
439
+ * beats chaining.
440
+ */
441
+ #define JS_DHASH_MIN_ALPHA(table, k) \
442
+ ((float)((table)->entrySize / sizeof(void *) - 1) \
443
+ / ((table)->entrySize / sizeof(void *) + (k)))
444
+
445
+ /*
446
+ * Default max/min alpha, and macros to compute the value for the |capacity|
447
+ * parameter to JS_NewDHashTable and JS_DHashTableInit, given default or any
448
+ * max alpha, such that adding entryCount entries right after initializing the
449
+ * table will not require a reallocation (so JS_DHASH_ADD can't fail for those
450
+ * JS_DHashTableOperate calls).
451
+ *
452
+ * NB: JS_DHASH_CAP is a helper macro meant for use only in JS_DHASH_CAPACITY.
453
+ * Don't use it directly!
454
+ */
455
+ #define JS_DHASH_DEFAULT_MAX_ALPHA 0.75
456
+ #define JS_DHASH_DEFAULT_MIN_ALPHA 0.25
457
+
458
+ #define JS_DHASH_CAP(entryCount, maxAlpha) \
459
+ ((uint32)((double)(entryCount) / (maxAlpha)))
460
+
461
+ #define JS_DHASH_CAPACITY(entryCount, maxAlpha) \
462
+ (JS_DHASH_CAP(entryCount, maxAlpha) + \
463
+ (((JS_DHASH_CAP(entryCount, maxAlpha) * (uint8)(0x100 * (maxAlpha))) \
464
+ >> 8) < (entryCount)))
465
+
466
+ #define JS_DHASH_DEFAULT_CAPACITY(entryCount) \
467
+ JS_DHASH_CAPACITY(entryCount, JS_DHASH_DEFAULT_MAX_ALPHA)
468
+
469
+ /*
470
+ * Finalize table's data, free its entry storage using table->ops->freeTable,
471
+ * and leave its members unchanged from their last live values (which leaves
472
+ * pointers dangling). If you want to burn cycles clearing table, it's up to
473
+ * your code to call memset.
474
+ */
475
+ extern JS_PUBLIC_API(void)
476
+ JS_DHashTableFinish(JSDHashTable *table);
477
+
478
+ /*
479
+ * To consolidate keyHash computation and table grow/shrink code, we use a
480
+ * single entry point for lookup, add, and remove operations. The operation
481
+ * codes are declared here, along with codes returned by JSDHashEnumerator
482
+ * functions, which control JS_DHashTableEnumerate's behavior.
483
+ */
484
+ typedef enum JSDHashOperator {
485
+ JS_DHASH_LOOKUP = 0, /* lookup entry */
486
+ JS_DHASH_ADD = 1, /* add entry */
487
+ JS_DHASH_REMOVE = 2, /* remove entry, or enumerator says remove */
488
+ JS_DHASH_NEXT = 0, /* enumerator says continue */
489
+ JS_DHASH_STOP = 1 /* enumerator says stop */
490
+ } JSDHashOperator;
491
+
492
+ /*
493
+ * To lookup a key in table, call:
494
+ *
495
+ * entry = JS_DHashTableOperate(table, key, JS_DHASH_LOOKUP);
496
+ *
497
+ * If JS_DHASH_ENTRY_IS_BUSY(entry) is true, key was found and it identifies
498
+ * entry. If JS_DHASH_ENTRY_IS_FREE(entry) is true, key was not found.
499
+ *
500
+ * To add an entry identified by key to table, call:
501
+ *
502
+ * entry = JS_DHashTableOperate(table, key, JS_DHASH_ADD);
503
+ *
504
+ * If entry is null upon return, then either the table is severely overloaded,
505
+ * and memory can't be allocated for entry storage via table->ops->allocTable;
506
+ * Or if table->ops->initEntry is non-null, the table->ops->initEntry op may
507
+ * have returned false.
508
+ *
509
+ * Otherwise, entry->keyHash has been set so that JS_DHASH_ENTRY_IS_BUSY(entry)
510
+ * is true, and it is up to the caller to initialize the key and value parts
511
+ * of the entry sub-type, if they have not been set already (i.e. if entry was
512
+ * not already in the table, and if the optional initEntry hook was not used).
513
+ *
514
+ * To remove an entry identified by key from table, call:
515
+ *
516
+ * (void) JS_DHashTableOperate(table, key, JS_DHASH_REMOVE);
517
+ *
518
+ * If key's entry is found, it is cleared (via table->ops->clearEntry) and
519
+ * the entry is marked so that JS_DHASH_ENTRY_IS_FREE(entry). This operation
520
+ * returns null unconditionally; you should ignore its return value.
521
+ */
522
+ extern JS_PUBLIC_API(JSDHashEntryHdr *) JS_DHASH_FASTCALL
523
+ JS_DHashTableOperate(JSDHashTable *table, const void *key, JSDHashOperator op);
524
+
525
+ /*
526
+ * Remove an entry already accessed via LOOKUP or ADD.
527
+ *
528
+ * NB: this is a "raw" or low-level routine, intended to be used only where
529
+ * the inefficiency of a full JS_DHashTableOperate (which rehashes in order
530
+ * to find the entry given its key) is not tolerable. This function does not
531
+ * shrink the table if it is underloaded. It does not update stats #ifdef
532
+ * JS_DHASHMETER, either.
533
+ */
534
+ extern JS_PUBLIC_API(void)
535
+ JS_DHashTableRawRemove(JSDHashTable *table, JSDHashEntryHdr *entry);
536
+
537
+ /*
538
+ * Enumerate entries in table using etor:
539
+ *
540
+ * count = JS_DHashTableEnumerate(table, etor, arg);
541
+ *
542
+ * JS_DHashTableEnumerate calls etor like so:
543
+ *
544
+ * op = etor(table, entry, number, arg);
545
+ *
546
+ * where number is a zero-based ordinal assigned to live entries according to
547
+ * their order in table->entryStore.
548
+ *
549
+ * The return value, op, is treated as a set of flags. If op is JS_DHASH_NEXT,
550
+ * then continue enumerating. If op contains JS_DHASH_REMOVE, then clear (via
551
+ * table->ops->clearEntry) and free entry. Then we check whether op contains
552
+ * JS_DHASH_STOP; if so, stop enumerating and return the number of live entries
553
+ * that were enumerated so far. Return the total number of live entries when
554
+ * enumeration completes normally.
555
+ *
556
+ * If etor calls JS_DHashTableOperate on table with op != JS_DHASH_LOOKUP, it
557
+ * must return JS_DHASH_STOP; otherwise undefined behavior results.
558
+ *
559
+ * If any enumerator returns JS_DHASH_REMOVE, table->entryStore may be shrunk
560
+ * or compressed after enumeration, but before JS_DHashTableEnumerate returns.
561
+ * Such an enumerator therefore can't safely set aside entry pointers, but an
562
+ * enumerator that never returns JS_DHASH_REMOVE can set pointers to entries
563
+ * aside, e.g., to avoid copying live entries into an array of the entry type.
564
+ * Copying entry pointers is cheaper, and safe so long as the caller of such a
565
+ * "stable" Enumerate doesn't use the set-aside pointers after any call either
566
+ * to PL_DHashTableOperate, or to an "unstable" form of Enumerate, which might
567
+ * grow or shrink entryStore.
568
+ *
569
+ * If your enumerator wants to remove certain entries, but set aside pointers
570
+ * to other entries that it retains, it can use JS_DHashTableRawRemove on the
571
+ * entries to be removed, returning JS_DHASH_NEXT to skip them. Likewise, if
572
+ * you want to remove entries, but for some reason you do not want entryStore
573
+ * to be shrunk or compressed, you can call JS_DHashTableRawRemove safely on
574
+ * the entry being enumerated, rather than returning JS_DHASH_REMOVE.
575
+ */
576
+ typedef JSDHashOperator
577
+ (* JS_DLL_CALLBACK JSDHashEnumerator)(JSDHashTable *table, JSDHashEntryHdr *hdr,
578
+ uint32 number, void *arg);
579
+
580
+ extern JS_PUBLIC_API(uint32)
581
+ JS_DHashTableEnumerate(JSDHashTable *table, JSDHashEnumerator etor, void *arg);
582
+
583
+ #ifdef JS_DHASHMETER
584
+ #include <stdio.h>
585
+
586
+ extern JS_PUBLIC_API(void)
587
+ JS_DHashTableDumpMeter(JSDHashTable *table, JSDHashEnumerator dump, FILE *fp);
588
+ #endif
589
+
590
+ JS_END_EXTERN_C
591
+
592
+ #endif /* jsdhash_h___ */