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,63 @@
1
+ /* ***** BEGIN LICENSE BLOCK *****
2
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3
+ *
4
+ * The contents of this file are subject to the Mozilla Public License Version
5
+ * 1.1 (the "License"); you may not use this file except in compliance with
6
+ * the License. You may obtain a copy of the License at
7
+ * http://www.mozilla.org/MPL/
8
+ *
9
+ * Software distributed under the License is distributed on an "AS IS" basis,
10
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
+ * for the specific language governing rights and limitations under the
12
+ * License.
13
+ *
14
+ * The Original Code is Mozilla Communicator client code, released
15
+ * March 31, 1998.
16
+ *
17
+ * The Initial Developer of the Original Code is
18
+ * Netscape Communications Corporation.
19
+ * Portions created by the Initial Developer are Copyright (C) 1998-1999
20
+ * the Initial Developer. All Rights Reserved.
21
+ *
22
+ * Contributor(s):
23
+ *
24
+ * Alternatively, the contents of this file may be used under the terms of
25
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
26
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
+ * in which case the provisions of the GPL or the LGPL are applicable instead
28
+ * of those above. If you wish to allow use of your version of this file only
29
+ * under the terms of either the GPL or the LGPL, and not to allow others to
30
+ * use your version of this file under the terms of the MPL, indicate your
31
+ * decision by deleting the provisions above and replace them with the notice
32
+ * and other provisions required by the GPL or the LGPL. If you do not delete
33
+ * the provisions above, a recipient may use your version of this file under
34
+ * the terms of any one of the MPL, the GPL or the LGPL.
35
+ *
36
+ * ***** END LICENSE BLOCK ***** */
37
+
38
+ /* -*- Mode: C; tab-width: 8 -*-
39
+ * Copyright (C) 1998-1999 Netscape Communications Corporation, All Rights Reserved.
40
+ */
41
+
42
+ #ifndef jsmath_h___
43
+ #define jsmath_h___
44
+ /*
45
+ * JS math functions.
46
+ */
47
+
48
+ JS_BEGIN_EXTERN_C
49
+
50
+ extern JSClass js_MathClass;
51
+
52
+ extern JSObject *
53
+ js_InitMathClass(JSContext *cx, JSObject *obj);
54
+
55
+ extern void
56
+ js_random_init(JSRuntime *rt);
57
+
58
+ extern jsdouble
59
+ js_random_nextDouble(JSRuntime *rt);
60
+
61
+ JS_END_EXTERN_C
62
+
63
+ #endif /* jsmath_h___ */
@@ -0,0 +1,1374 @@
1
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ *
3
+ * ***** BEGIN LICENSE BLOCK *****
4
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
+ *
6
+ * The contents of this file are subject to the Mozilla Public License Version
7
+ * 1.1 (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ * http://www.mozilla.org/MPL/
10
+ *
11
+ * Software distributed under the License is distributed on an "AS IS" basis,
12
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
+ * for the specific language governing rights and limitations under the
14
+ * License.
15
+ *
16
+ * The Original Code is Mozilla Communicator client code, released
17
+ * March 31, 1998.
18
+ *
19
+ * The Initial Developer of the Original Code is
20
+ * Netscape Communications Corporation.
21
+ * Portions created by the Initial Developer are Copyright (C) 1998
22
+ * the Initial Developer. All Rights Reserved.
23
+ *
24
+ * Contributor(s):
25
+ * IBM Corp.
26
+ *
27
+ * Alternatively, the contents of this file may be used under the terms of
28
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
29
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30
+ * in which case the provisions of the GPL or the LGPL are applicable instead
31
+ * of those above. If you wish to allow use of your version of this file only
32
+ * under the terms of either the GPL or the LGPL, and not to allow others to
33
+ * use your version of this file under the terms of the MPL, indicate your
34
+ * decision by deleting the provisions above and replace them with the notice
35
+ * and other provisions required by the GPL or the LGPL. If you do not delete
36
+ * the provisions above, a recipient may use your version of this file under
37
+ * the terms of any one of the MPL, the GPL or the LGPL.
38
+ *
39
+ * ***** END LICENSE BLOCK ***** */
40
+
41
+ /*
42
+ * JS number type and wrapper class.
43
+ */
44
+ #include "jsstddef.h"
45
+ #if defined(XP_WIN) || defined(XP_OS2)
46
+ #include <float.h>
47
+ #endif
48
+ #ifdef XP_OS2
49
+ #define _PC_53 PC_53
50
+ #define _MCW_EM MCW_EM
51
+ #define _MCW_PC MCW_PC
52
+ #endif
53
+ #include <locale.h>
54
+ #include <limits.h>
55
+ #include <math.h>
56
+ #include <stdlib.h>
57
+ #include <string.h>
58
+ #include "jstypes.h"
59
+ #include "jsutil.h" /* Added by JSIFY */
60
+ #include "jsapi.h"
61
+ #include "jsatom.h"
62
+ #include "jsbuiltins.h"
63
+ #include "jscntxt.h"
64
+ #include "jsversion.h"
65
+ #include "jsdtoa.h"
66
+ #include "jsgc.h"
67
+ #include "jsinterp.h"
68
+ #include "jsnum.h"
69
+ #include "jsobj.h"
70
+ #include "jsopcode.h"
71
+ #include "jsprf.h"
72
+ #include "jsscope.h"
73
+ #include "jsstr.h"
74
+
75
+ static JSBool
76
+ num_isNaN(JSContext *cx, uintN argc, jsval *vp)
77
+ {
78
+ jsdouble x;
79
+
80
+ if (argc == 0) {
81
+ *vp = JSVAL_TRUE;
82
+ return JS_TRUE;
83
+ }
84
+ x = js_ValueToNumber(cx, &vp[2]);
85
+ if (JSVAL_IS_NULL(vp[2]))
86
+ return JS_FALSE;
87
+ *vp = BOOLEAN_TO_JSVAL(JSDOUBLE_IS_NaN(x));
88
+ return JS_TRUE;
89
+ }
90
+
91
+ static JSBool
92
+ num_isFinite(JSContext *cx, uintN argc, jsval *vp)
93
+ {
94
+ jsdouble x;
95
+
96
+ if (argc == 0) {
97
+ *vp = JSVAL_FALSE;
98
+ return JS_TRUE;
99
+ }
100
+ x = js_ValueToNumber(cx, &vp[2]);
101
+ if (JSVAL_IS_NULL(vp[2]))
102
+ return JS_FALSE;
103
+ *vp = BOOLEAN_TO_JSVAL(JSDOUBLE_IS_FINITE(x));
104
+ return JS_TRUE;
105
+ }
106
+
107
+ static JSBool
108
+ num_parseFloat(JSContext *cx, uintN argc, jsval *vp)
109
+ {
110
+ JSString *str;
111
+ jsdouble d;
112
+ const jschar *bp, *end, *ep;
113
+
114
+ if (argc == 0) {
115
+ *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
116
+ return JS_TRUE;
117
+ }
118
+ str = js_ValueToString(cx, vp[2]);
119
+ if (!str)
120
+ return JS_FALSE;
121
+ JSSTRING_CHARS_AND_END(str, bp, end);
122
+ if (!js_strtod(cx, bp, end, &ep, &d))
123
+ return JS_FALSE;
124
+ if (ep == bp) {
125
+ *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
126
+ return JS_TRUE;
127
+ }
128
+ return js_NewNumberInRootedValue(cx, d, vp);
129
+ }
130
+
131
+ #ifdef JS_TRACER
132
+ static jsdouble FASTCALL
133
+ ParseFloat(JSContext* cx, JSString* str)
134
+ {
135
+ const jschar* bp;
136
+ const jschar* end;
137
+ const jschar* ep;
138
+ jsdouble d;
139
+
140
+ JSSTRING_CHARS_AND_END(str, bp, end);
141
+ if (!js_strtod(cx, bp, end, &ep, &d) || ep == bp)
142
+ return js_NaN;
143
+ return d;
144
+ }
145
+ #endif
146
+
147
+ /* See ECMA 15.1.2.2. */
148
+ static JSBool
149
+ num_parseInt(JSContext *cx, uintN argc, jsval *vp)
150
+ {
151
+ jsint radix;
152
+ JSString *str;
153
+ jsdouble d;
154
+ const jschar *bp, *end, *ep;
155
+
156
+ if (argc == 0) {
157
+ *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
158
+ return JS_TRUE;
159
+ }
160
+ if (argc > 1) {
161
+ radix = js_ValueToECMAInt32(cx, &vp[3]);
162
+ if (JSVAL_IS_NULL(vp[3]))
163
+ return JS_FALSE;
164
+ } else {
165
+ radix = 0;
166
+ }
167
+ if (radix != 0 && (radix < 2 || radix > 36)) {
168
+ *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
169
+ return JS_TRUE;
170
+ }
171
+
172
+ if (JSVAL_IS_INT(vp[2]) && (radix == 0 || radix == 10)) {
173
+ *vp = vp[2];
174
+ return JS_TRUE;
175
+ }
176
+
177
+ str = js_ValueToString(cx, vp[2]);
178
+ if (!str)
179
+ return JS_FALSE;
180
+ JSSTRING_CHARS_AND_END(str, bp, end);
181
+ if (!js_strtointeger(cx, bp, end, &ep, radix, &d))
182
+ return JS_FALSE;
183
+ if (ep == bp) {
184
+ *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
185
+ return JS_TRUE;
186
+ }
187
+ return js_NewNumberInRootedValue(cx, d, vp);
188
+ }
189
+
190
+ #ifdef JS_TRACER
191
+ static jsdouble FASTCALL
192
+ ParseInt(JSContext* cx, JSString* str)
193
+ {
194
+ const jschar* bp;
195
+ const jschar* end;
196
+ const jschar* ep;
197
+ jsdouble d;
198
+
199
+ JSSTRING_CHARS_AND_END(str, bp, end);
200
+ if (!js_strtointeger(cx, bp, end, &ep, 0, &d) || ep == bp)
201
+ return js_NaN;
202
+ return d;
203
+ }
204
+
205
+ static jsdouble FASTCALL
206
+ ParseIntDouble(jsdouble d)
207
+ {
208
+ if (!JSDOUBLE_IS_FINITE(d))
209
+ return js_NaN;
210
+ if (d > 0)
211
+ return floor(d);
212
+ if (d < 0)
213
+ return -floor(-d);
214
+ return 0;
215
+ }
216
+ #endif
217
+
218
+ const char js_Infinity_str[] = "Infinity";
219
+ const char js_NaN_str[] = "NaN";
220
+ const char js_isNaN_str[] = "isNaN";
221
+ const char js_isFinite_str[] = "isFinite";
222
+ const char js_parseFloat_str[] = "parseFloat";
223
+ const char js_parseInt_str[] = "parseInt";
224
+
225
+ #ifdef JS_TRACER
226
+
227
+ JS_DEFINE_TRCINFO_2(num_parseInt,
228
+ (2, (static, DOUBLE, ParseInt, CONTEXT, STRING, 1, 1)),
229
+ (1, (static, DOUBLE, ParseIntDouble, DOUBLE, 1, 1)))
230
+
231
+ JS_DEFINE_TRCINFO_1(num_parseFloat,
232
+ (2, (static, DOUBLE, ParseFloat, CONTEXT, STRING, 1, 1)))
233
+
234
+ #endif /* JS_TRACER */
235
+
236
+ static JSFunctionSpec number_functions[] = {
237
+ JS_FN(js_isNaN_str, num_isNaN, 1,0),
238
+ JS_FN(js_isFinite_str, num_isFinite, 1,0),
239
+ JS_TN(js_parseFloat_str, num_parseFloat, 1,0, num_parseFloat_trcinfo),
240
+ JS_TN(js_parseInt_str, num_parseInt, 2,0, num_parseInt_trcinfo),
241
+ JS_FS_END
242
+ };
243
+
244
+ JSClass js_NumberClass = {
245
+ js_Number_str,
246
+ JSCLASS_HAS_PRIVATE | JSCLASS_HAS_CACHED_PROTO(JSProto_Number),
247
+ JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
248
+ JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
249
+ JSCLASS_NO_OPTIONAL_MEMBERS
250
+ };
251
+
252
+ static JSBool
253
+ Number(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
254
+ {
255
+ jsval v;
256
+ jsdouble d;
257
+
258
+ if (argc != 0) {
259
+ d = js_ValueToNumber(cx, &argv[0]);
260
+ v = argv[0];
261
+ if (JSVAL_IS_NULL(v))
262
+ return JS_FALSE;
263
+ if (v != JSVAL_TRUE) {
264
+ JS_ASSERT(JSVAL_IS_INT(v) || JSVAL_IS_DOUBLE(v));
265
+ } else {
266
+ if (!js_NewNumberInRootedValue(cx, d, &argv[0]))
267
+ return JS_FALSE;
268
+ v = argv[0];
269
+ }
270
+ } else {
271
+ v = JSVAL_ZERO;
272
+ }
273
+ if (!JS_IsConstructing(cx)) {
274
+ *rval = v;
275
+ return JS_TRUE;
276
+ }
277
+ STOBJ_SET_SLOT(obj, JSSLOT_PRIVATE, v);
278
+ return JS_TRUE;
279
+ }
280
+
281
+ #if JS_HAS_TOSOURCE
282
+ static JSBool
283
+ num_toSource(JSContext *cx, uintN argc, jsval *vp)
284
+ {
285
+ jsval v;
286
+ jsdouble d;
287
+ char numBuf[DTOSTR_STANDARD_BUFFER_SIZE], *numStr;
288
+ char buf[64];
289
+ JSString *str;
290
+
291
+ if (!js_GetPrimitiveThis(cx, vp, &js_NumberClass, &v))
292
+ return JS_FALSE;
293
+ JS_ASSERT(JSVAL_IS_NUMBER(v));
294
+ d = JSVAL_IS_INT(v) ? (jsdouble)JSVAL_TO_INT(v) : *JSVAL_TO_DOUBLE(v);
295
+ numStr = JS_dtostr(numBuf, sizeof numBuf, DTOSTR_STANDARD, 0, d);
296
+ if (!numStr) {
297
+ JS_ReportOutOfMemory(cx);
298
+ return JS_FALSE;
299
+ }
300
+ JS_snprintf(buf, sizeof buf, "(new %s(%s))", js_NumberClass.name, numStr);
301
+ str = JS_NewStringCopyZ(cx, buf);
302
+ if (!str)
303
+ return JS_FALSE;
304
+ *vp = STRING_TO_JSVAL(str);
305
+ return JS_TRUE;
306
+ }
307
+ #endif
308
+
309
+ /* The buf must be big enough for MIN_INT to fit including '-' and '\0'. */
310
+ static char *
311
+ IntToCString(jsint i, jsint base, char *buf, size_t bufSize)
312
+ {
313
+ char *cp;
314
+ jsuint u;
315
+
316
+ u = (i < 0) ? -i : i;
317
+
318
+ cp = buf + bufSize; /* one past last buffer cell */
319
+ *--cp = '\0'; /* null terminate the string to be */
320
+
321
+ /*
322
+ * Build the string from behind. We use multiply and subtraction
323
+ * instead of modulus because that's much faster.
324
+ */
325
+ switch (base) {
326
+ case 10:
327
+ do {
328
+ jsuint newu = u / 10;
329
+ *--cp = (char)(u - newu * 10) + '0';
330
+ u = newu;
331
+ } while (u != 0);
332
+ break;
333
+ case 16:
334
+ do {
335
+ jsuint newu = u / 16;
336
+ *--cp = "0123456789abcdef"[u - newu * 16];
337
+ u = newu;
338
+ } while (u != 0);
339
+ break;
340
+ default:
341
+ JS_ASSERT(base >= 2 && base <= 36);
342
+ do {
343
+ jsuint newu = u / base;
344
+ *--cp = "0123456789abcdefghijklmnopqrstuvwxyz"[u - newu * base];
345
+ u = newu;
346
+ } while (u != 0);
347
+ break;
348
+ }
349
+ if (i < 0)
350
+ *--cp = '-';
351
+
352
+ JS_ASSERT(cp >= buf);
353
+ return cp;
354
+ }
355
+
356
+ static JSBool
357
+ num_toString(JSContext *cx, uintN argc, jsval *vp)
358
+ {
359
+ jsval v;
360
+ jsdouble d;
361
+ jsint base;
362
+ JSString *str;
363
+
364
+ if (!js_GetPrimitiveThis(cx, vp, &js_NumberClass, &v))
365
+ return JS_FALSE;
366
+ JS_ASSERT(JSVAL_IS_NUMBER(v));
367
+ d = JSVAL_IS_INT(v) ? (jsdouble)JSVAL_TO_INT(v) : *JSVAL_TO_DOUBLE(v);
368
+ base = 10;
369
+ if (argc != 0 && !JSVAL_IS_VOID(vp[2])) {
370
+ base = js_ValueToECMAInt32(cx, &vp[2]);
371
+ if (JSVAL_IS_NULL(vp[2]))
372
+ return JS_FALSE;
373
+ if (base < 2 || base > 36) {
374
+ char numBuf[12];
375
+ char *numStr = IntToCString(base, 10, numBuf, sizeof numBuf);
376
+ JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_RADIX,
377
+ numStr);
378
+ return JS_FALSE;
379
+ }
380
+ }
381
+ if (base == 10) {
382
+ str = js_NumberToString(cx, d);
383
+ } else {
384
+ char *dStr = JS_dtobasestr(base, d);
385
+ if (!dStr) {
386
+ JS_ReportOutOfMemory(cx);
387
+ return JS_FALSE;
388
+ }
389
+ str = JS_NewStringCopyZ(cx, dStr);
390
+ free(dStr);
391
+ }
392
+ if (!str)
393
+ return JS_FALSE;
394
+ *vp = STRING_TO_JSVAL(str);
395
+ return JS_TRUE;
396
+ }
397
+
398
+ static JSBool
399
+ num_toLocaleString(JSContext *cx, uintN argc, jsval *vp)
400
+ {
401
+ char thousandsLength, decimalLength;
402
+ const char *numGrouping, *tmpGroup;
403
+ JSRuntime *rt;
404
+ JSString *numStr, *str;
405
+ const char *num, *end, *tmpSrc;
406
+ char *buf, *tmpDest;
407
+ const char *nint;
408
+ int digits, size, remainder, nrepeat;
409
+
410
+ /*
411
+ * Create the string, move back to bytes to make string twiddling
412
+ * a bit easier and so we can insert platform charset seperators.
413
+ */
414
+ if (!num_toString(cx, 0, vp))
415
+ return JS_FALSE;
416
+ JS_ASSERT(JSVAL_IS_STRING(*vp));
417
+ numStr = JSVAL_TO_STRING(*vp);
418
+ num = js_GetStringBytes(cx, numStr);
419
+ if (!num)
420
+ return JS_FALSE;
421
+
422
+ /*
423
+ * Find the first non-integer value, whether it be a letter as in
424
+ * 'Infinity', a decimal point, or an 'e' from exponential notation.
425
+ */
426
+ nint = num;
427
+ if (*nint == '-')
428
+ nint++;
429
+ while (*nint >= '0' && *nint <= '9')
430
+ nint++;
431
+ digits = nint - num;
432
+ end = num + digits;
433
+ if (!digits)
434
+ return JS_TRUE;
435
+
436
+ rt = cx->runtime;
437
+ thousandsLength = strlen(rt->thousandsSeparator);
438
+ decimalLength = strlen(rt->decimalSeparator);
439
+
440
+ /* Figure out how long resulting string will be. */
441
+ size = digits + (*nint ? strlen(nint + 1) + 1 : 0);
442
+ if (*nint == '.')
443
+ size += decimalLength;
444
+
445
+ numGrouping = tmpGroup = rt->numGrouping;
446
+ remainder = digits;
447
+ if (*num == '-')
448
+ remainder--;
449
+
450
+ while (*tmpGroup != CHAR_MAX && *tmpGroup != '\0') {
451
+ if (*tmpGroup >= remainder)
452
+ break;
453
+ size += thousandsLength;
454
+ remainder -= *tmpGroup;
455
+ tmpGroup++;
456
+ }
457
+ if (*tmpGroup == '\0' && *numGrouping != '\0') {
458
+ nrepeat = (remainder - 1) / tmpGroup[-1];
459
+ size += thousandsLength * nrepeat;
460
+ remainder -= nrepeat * tmpGroup[-1];
461
+ } else {
462
+ nrepeat = 0;
463
+ }
464
+ tmpGroup--;
465
+
466
+ buf = (char *)JS_malloc(cx, size + 1);
467
+ if (!buf)
468
+ return JS_FALSE;
469
+
470
+ tmpDest = buf;
471
+ tmpSrc = num;
472
+
473
+ while (*tmpSrc == '-' || remainder--)
474
+ *tmpDest++ = *tmpSrc++;
475
+ while (tmpSrc < end) {
476
+ strcpy(tmpDest, rt->thousandsSeparator);
477
+ tmpDest += thousandsLength;
478
+ memcpy(tmpDest, tmpSrc, *tmpGroup);
479
+ tmpDest += *tmpGroup;
480
+ tmpSrc += *tmpGroup;
481
+ if (--nrepeat < 0)
482
+ tmpGroup--;
483
+ }
484
+
485
+ if (*nint == '.') {
486
+ strcpy(tmpDest, rt->decimalSeparator);
487
+ tmpDest += decimalLength;
488
+ strcpy(tmpDest, nint + 1);
489
+ } else {
490
+ strcpy(tmpDest, nint);
491
+ }
492
+
493
+ if (cx->localeCallbacks && cx->localeCallbacks->localeToUnicode)
494
+ return cx->localeCallbacks->localeToUnicode(cx, buf, vp);
495
+
496
+ str = JS_NewString(cx, buf, size);
497
+ if (!str) {
498
+ JS_free(cx, buf);
499
+ return JS_FALSE;
500
+ }
501
+
502
+ *vp = STRING_TO_JSVAL(str);
503
+ return JS_TRUE;
504
+ }
505
+
506
+ static JSBool
507
+ num_valueOf(JSContext *cx, uintN argc, jsval *vp)
508
+ {
509
+ jsval v;
510
+ JSObject *obj;
511
+
512
+ v = vp[1];
513
+ if (JSVAL_IS_NUMBER(v)) {
514
+ *vp = v;
515
+ return JS_TRUE;
516
+ }
517
+ obj = JS_THIS_OBJECT(cx, vp);
518
+ if (!JS_InstanceOf(cx, obj, &js_NumberClass, vp + 2))
519
+ return JS_FALSE;
520
+ *vp = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
521
+ return JS_TRUE;
522
+ }
523
+
524
+
525
+ #define MAX_PRECISION 100
526
+
527
+ static JSBool
528
+ num_to(JSContext *cx, JSDToStrMode zeroArgMode, JSDToStrMode oneArgMode,
529
+ jsint precisionMin, jsint precisionMax, jsint precisionOffset,
530
+ uintN argc, jsval *vp)
531
+ {
532
+ jsval v;
533
+ jsdouble d, precision;
534
+ JSString *str;
535
+
536
+ /* Use MAX_PRECISION+1 because precisionOffset can be 1. */
537
+ char buf[DTOSTR_VARIABLE_BUFFER_SIZE(MAX_PRECISION+1)];
538
+ char *numStr;
539
+
540
+ if (!js_GetPrimitiveThis(cx, vp, &js_NumberClass, &v))
541
+ return JS_FALSE;
542
+ JS_ASSERT(JSVAL_IS_NUMBER(v));
543
+ d = JSVAL_IS_INT(v) ? (jsdouble)JSVAL_TO_INT(v) : *JSVAL_TO_DOUBLE(v);
544
+
545
+ if (argc == 0) {
546
+ precision = 0.0;
547
+ oneArgMode = zeroArgMode;
548
+ } else {
549
+ precision = js_ValueToNumber(cx, &vp[2]);
550
+ if (JSVAL_IS_NULL(vp[2]))
551
+ return JS_FALSE;
552
+ precision = js_DoubleToInteger(precision);
553
+ if (precision < precisionMin || precision > precisionMax) {
554
+ numStr = JS_dtostr(buf, sizeof buf, DTOSTR_STANDARD, 0, precision);
555
+ if (!numStr)
556
+ JS_ReportOutOfMemory(cx);
557
+ else
558
+ JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_PRECISION_RANGE, numStr);
559
+ return JS_FALSE;
560
+ }
561
+ }
562
+
563
+ numStr = JS_dtostr(buf, sizeof buf, oneArgMode, (jsint)precision + precisionOffset, d);
564
+ if (!numStr) {
565
+ JS_ReportOutOfMemory(cx);
566
+ return JS_FALSE;
567
+ }
568
+ str = JS_NewStringCopyZ(cx, numStr);
569
+ if (!str)
570
+ return JS_FALSE;
571
+ *vp = STRING_TO_JSVAL(str);
572
+ return JS_TRUE;
573
+ }
574
+
575
+ /*
576
+ * In the following three implementations, we allow a larger range of precision
577
+ * than ECMA requires; this is permitted by ECMA-262.
578
+ */
579
+ static JSBool
580
+ num_toFixed(JSContext *cx, uintN argc, jsval *vp)
581
+ {
582
+ return num_to(cx, DTOSTR_FIXED, DTOSTR_FIXED, -20, MAX_PRECISION, 0,
583
+ argc, vp);
584
+ }
585
+
586
+ static JSBool
587
+ num_toExponential(JSContext *cx, uintN argc, jsval *vp)
588
+ {
589
+ return num_to(cx, DTOSTR_STANDARD_EXPONENTIAL, DTOSTR_EXPONENTIAL, 0,
590
+ MAX_PRECISION, 1, argc, vp);
591
+ }
592
+
593
+ static JSBool
594
+ num_toPrecision(JSContext *cx, uintN argc, jsval *vp)
595
+ {
596
+ if (argc == 0 || JSVAL_IS_VOID(vp[2]))
597
+ return num_toString(cx, 0, vp);
598
+ return num_to(cx, DTOSTR_STANDARD, DTOSTR_PRECISION, 1, MAX_PRECISION, 0,
599
+ argc, vp);
600
+ }
601
+
602
+ #ifdef JS_TRACER
603
+
604
+ JS_DEFINE_TRCINFO_2(num_toString,
605
+ (3, (static, STRING, NumberToStringWithBase, CONTEXT, THIS_DOUBLE, INT32, 1, 1)),
606
+ (2, (extern, STRING, js_NumberToString, CONTEXT, THIS_DOUBLE, 1, 1)))
607
+
608
+ #endif /* JS_TRACER */
609
+
610
+ static JSFunctionSpec number_methods[] = {
611
+ #if JS_HAS_TOSOURCE
612
+ JS_FN(js_toSource_str, num_toSource, 0,JSFUN_THISP_NUMBER),
613
+ #endif
614
+ JS_TN(js_toString_str, num_toString, 1,JSFUN_THISP_NUMBER,
615
+ num_toString_trcinfo),
616
+ JS_FN(js_toLocaleString_str, num_toLocaleString, 0,JSFUN_THISP_NUMBER),
617
+ JS_FN(js_valueOf_str, num_valueOf, 0,JSFUN_THISP_NUMBER),
618
+ JS_FN(js_toJSON_str, num_valueOf, 0,JSFUN_THISP_NUMBER),
619
+ JS_FN("toFixed", num_toFixed, 1,JSFUN_THISP_NUMBER),
620
+ JS_FN("toExponential", num_toExponential, 1,JSFUN_THISP_NUMBER),
621
+ JS_FN("toPrecision", num_toPrecision, 1,JSFUN_THISP_NUMBER),
622
+ JS_FS_END
623
+ };
624
+
625
+ /* NB: Keep this in synch with number_constants[]. */
626
+ enum nc_slot {
627
+ NC_NaN,
628
+ NC_POSITIVE_INFINITY,
629
+ NC_NEGATIVE_INFINITY,
630
+ NC_MAX_VALUE,
631
+ NC_MIN_VALUE,
632
+ NC_LIMIT
633
+ };
634
+
635
+ /*
636
+ * Some to most C compilers forbid spelling these at compile time, or barf
637
+ * if you try, so all but MAX_VALUE are set up by js_InitRuntimeNumberState
638
+ * using union jsdpun.
639
+ */
640
+ static JSConstDoubleSpec number_constants[] = {
641
+ {0, js_NaN_str, 0,{0,0,0}},
642
+ {0, "POSITIVE_INFINITY", 0,{0,0,0}},
643
+ {0, "NEGATIVE_INFINITY", 0,{0,0,0}},
644
+ {1.7976931348623157E+308, "MAX_VALUE", 0,{0,0,0}},
645
+ {0, "MIN_VALUE", 0,{0,0,0}},
646
+ {0,0,0,{0,0,0}}
647
+ };
648
+
649
+ jsdouble js_NaN;
650
+
651
+ #if (defined XP_WIN || defined XP_OS2) && \
652
+ !defined WINCE && \
653
+ !defined __MWERKS__ && \
654
+ (defined _M_IX86 || \
655
+ (defined __GNUC__ && !defined __MINGW32__))
656
+
657
+ /*
658
+ * Set the exception mask to mask all exceptions and set the FPU precision
659
+ * to 53 bit mantissa.
660
+ * On Alpha platform this is handled via Compiler option.
661
+ */
662
+ #define FIX_FPU() _control87(MCW_EM | PC_53, MCW_EM | MCW_PC)
663
+
664
+ #else
665
+
666
+ #define FIX_FPU() ((void)0)
667
+
668
+ #endif
669
+
670
+ JSBool
671
+ js_InitRuntimeNumberState(JSContext *cx)
672
+ {
673
+ JSRuntime *rt;
674
+ jsdpun u;
675
+ struct lconv *locale;
676
+
677
+ rt = cx->runtime;
678
+ JS_ASSERT(!rt->jsNaN);
679
+
680
+ FIX_FPU();
681
+
682
+ u.s.hi = JSDOUBLE_HI32_EXPMASK | JSDOUBLE_HI32_MANTMASK;
683
+ u.s.lo = 0xffffffff;
684
+ number_constants[NC_NaN].dval = js_NaN = u.d;
685
+ rt->jsNaN = js_NewWeaklyRootedDouble(cx, js_NaN);
686
+ if (!rt->jsNaN)
687
+ return JS_FALSE;
688
+
689
+ u.s.hi = JSDOUBLE_HI32_EXPMASK;
690
+ u.s.lo = 0x00000000;
691
+ number_constants[NC_POSITIVE_INFINITY].dval = u.d;
692
+ rt->jsPositiveInfinity = js_NewWeaklyRootedDouble(cx, u.d);
693
+ if (!rt->jsPositiveInfinity)
694
+ return JS_FALSE;
695
+
696
+ u.s.hi = JSDOUBLE_HI32_SIGNBIT | JSDOUBLE_HI32_EXPMASK;
697
+ u.s.lo = 0x00000000;
698
+ number_constants[NC_NEGATIVE_INFINITY].dval = u.d;
699
+ rt->jsNegativeInfinity = js_NewWeaklyRootedDouble(cx, u.d);
700
+ if (!rt->jsNegativeInfinity)
701
+ return JS_FALSE;
702
+
703
+ u.s.hi = 0;
704
+ u.s.lo = 1;
705
+ number_constants[NC_MIN_VALUE].dval = u.d;
706
+
707
+ locale = localeconv();
708
+ rt->thousandsSeparator =
709
+ JS_strdup(cx, locale->thousands_sep ? locale->thousands_sep : "'");
710
+ rt->decimalSeparator =
711
+ JS_strdup(cx, locale->decimal_point ? locale->decimal_point : ".");
712
+ rt->numGrouping =
713
+ JS_strdup(cx, locale->grouping ? locale->grouping : "\3\0");
714
+
715
+ return rt->thousandsSeparator && rt->decimalSeparator && rt->numGrouping;
716
+ }
717
+
718
+ void
719
+ js_TraceRuntimeNumberState(JSTracer *trc)
720
+ {
721
+ JSRuntime *rt;
722
+
723
+ rt = trc->context->runtime;
724
+ if (rt->jsNaN)
725
+ JS_CALL_DOUBLE_TRACER(trc, rt->jsNaN, "NaN");
726
+ if (rt->jsPositiveInfinity)
727
+ JS_CALL_DOUBLE_TRACER(trc, rt->jsPositiveInfinity, "+Infinity");
728
+ if (rt->jsNegativeInfinity)
729
+ JS_CALL_DOUBLE_TRACER(trc, rt->jsNegativeInfinity, "-Infinity");
730
+ }
731
+
732
+ void
733
+ js_FinishRuntimeNumberState(JSContext *cx)
734
+ {
735
+ JSRuntime *rt = cx->runtime;
736
+
737
+ js_UnlockGCThingRT(rt, rt->jsNaN);
738
+ js_UnlockGCThingRT(rt, rt->jsNegativeInfinity);
739
+ js_UnlockGCThingRT(rt, rt->jsPositiveInfinity);
740
+
741
+ rt->jsNaN = NULL;
742
+ rt->jsNegativeInfinity = NULL;
743
+ rt->jsPositiveInfinity = NULL;
744
+
745
+ JS_free(cx, (void *)rt->thousandsSeparator);
746
+ JS_free(cx, (void *)rt->decimalSeparator);
747
+ JS_free(cx, (void *)rt->numGrouping);
748
+ rt->thousandsSeparator = rt->decimalSeparator = rt->numGrouping = NULL;
749
+ }
750
+
751
+ JSObject *
752
+ js_InitNumberClass(JSContext *cx, JSObject *obj)
753
+ {
754
+ JSObject *proto, *ctor;
755
+ JSRuntime *rt;
756
+
757
+ /* XXX must do at least once per new thread, so do it per JSContext... */
758
+ FIX_FPU();
759
+
760
+ if (!JS_DefineFunctions(cx, obj, number_functions))
761
+ return NULL;
762
+
763
+ proto = JS_InitClass(cx, obj, NULL, &js_NumberClass, Number, 1,
764
+ NULL, number_methods, NULL, NULL);
765
+ if (!proto || !(ctor = JS_GetConstructor(cx, proto)))
766
+ return NULL;
767
+ STOBJ_SET_SLOT(proto, JSSLOT_PRIVATE, JSVAL_ZERO);
768
+ if (!JS_DefineConstDoubles(cx, ctor, number_constants))
769
+ return NULL;
770
+
771
+ /* ECMA 15.1.1.1 */
772
+ rt = cx->runtime;
773
+ if (!JS_DefineProperty(cx, obj, js_NaN_str, DOUBLE_TO_JSVAL(rt->jsNaN),
774
+ NULL, NULL, JSPROP_PERMANENT)) {
775
+ return NULL;
776
+ }
777
+
778
+ /* ECMA 15.1.1.2 */
779
+ if (!JS_DefineProperty(cx, obj, js_Infinity_str,
780
+ DOUBLE_TO_JSVAL(rt->jsPositiveInfinity),
781
+ NULL, NULL, JSPROP_PERMANENT)) {
782
+ return NULL;
783
+ }
784
+ return proto;
785
+ }
786
+
787
+ JSBool
788
+ js_NewNumberInRootedValue(JSContext *cx, jsdouble d, jsval *vp)
789
+ {
790
+ jsint i;
791
+
792
+ if (JSDOUBLE_IS_INT(d, i) && INT_FITS_IN_JSVAL(i)) {
793
+ *vp = INT_TO_JSVAL(i);
794
+ return JS_TRUE;
795
+ }
796
+ return js_NewDoubleInRootedValue(cx, d, vp);
797
+ }
798
+
799
+ JSBool
800
+ js_NewWeaklyRootedNumber(JSContext *cx, jsdouble d, jsval *rval)
801
+ {
802
+ jsint i;
803
+ if (JSDOUBLE_IS_INT(d, i) && INT_FITS_IN_JSVAL(i)) {
804
+ *rval = INT_TO_JSVAL(i);
805
+ return JS_TRUE;
806
+ }
807
+ return JS_NewDoubleValue(cx, d, rval);
808
+ }
809
+
810
+ /*
811
+ * Convert a number to C string. The buf must be large enough to accommodate
812
+ * the result, including '-' and '\0', if base == 10 or d is an integer that
813
+ * fits in 32 bits. The caller must free the resulting pointer if it does not
814
+ * point into buf.
815
+ */
816
+ static char *
817
+ NumberToCString(JSContext *cx, jsdouble d, jsint base, char *buf, size_t bufSize)
818
+ {
819
+ jsint i;
820
+ char *numStr;
821
+
822
+ JS_ASSERT(bufSize >= DTOSTR_STANDARD_BUFFER_SIZE);
823
+ if (JSDOUBLE_IS_INT(d, i)) {
824
+ numStr = IntToCString(i, base, buf, bufSize);
825
+ } else {
826
+ if (base == 10)
827
+ numStr = JS_dtostr(buf, bufSize, DTOSTR_STANDARD, 0, d);
828
+ else
829
+ numStr = JS_dtobasestr(base, d);
830
+ if (!numStr) {
831
+ JS_ReportOutOfMemory(cx);
832
+ return NULL;
833
+ }
834
+ }
835
+ return numStr;
836
+ }
837
+
838
+ static JSString * JS_FASTCALL
839
+ NumberToStringWithBase(JSContext *cx, jsdouble d, jsint base)
840
+ {
841
+ /*
842
+ * The longest possible result here that would need to fit in buf is
843
+ * (-0x80000000).toString(2), which has length 33. (This can produce
844
+ * longer results, but in those cases buf is not used; see comment at
845
+ * NumberToCString.)
846
+ */
847
+ char buf[34];
848
+ char *numStr;
849
+ JSString *s;
850
+
851
+ if (base < 2 || base > 36)
852
+ return NULL;
853
+ numStr = NumberToCString(cx, d, base, buf, sizeof buf);
854
+ if (!numStr)
855
+ return NULL;
856
+ s = JS_NewStringCopyZ(cx, numStr);
857
+ if (!(numStr >= buf && numStr < buf + sizeof buf))
858
+ free(numStr);
859
+ return s;
860
+ }
861
+
862
+ JSString * JS_FASTCALL
863
+ js_NumberToString(JSContext *cx, jsdouble d)
864
+ {
865
+ return NumberToStringWithBase(cx, d, 10);
866
+ }
867
+
868
+ jsdouble
869
+ js_ValueToNumber(JSContext *cx, jsval *vp)
870
+ {
871
+ jsval v;
872
+ JSString *str;
873
+ const jschar *bp, *end, *ep;
874
+ jsdouble d, *dp;
875
+ JSObject *obj;
876
+ JSTempValueRooter tvr;
877
+
878
+ v = *vp;
879
+ for (;;) {
880
+ if (JSVAL_IS_INT(v))
881
+ return (jsdouble) JSVAL_TO_INT(v);
882
+ if (JSVAL_IS_DOUBLE(v))
883
+ return *JSVAL_TO_DOUBLE(v);
884
+ if (JSVAL_IS_STRING(v)) {
885
+ str = JSVAL_TO_STRING(v);
886
+
887
+ /*
888
+ * Note that ECMA doesn't treat a string beginning with a '0' as
889
+ * an octal number here. This works because all such numbers will
890
+ * be interpreted as decimal by js_strtod and will never get
891
+ * passed to js_strtointeger (which would interpret them as
892
+ * octal).
893
+ */
894
+ JSSTRING_CHARS_AND_END(str, bp, end);
895
+ if ((!js_strtod(cx, bp, end, &ep, &d) ||
896
+ js_SkipWhiteSpace(ep, end) != end) &&
897
+ (!js_strtointeger(cx, bp, end, &ep, 0, &d) ||
898
+ js_SkipWhiteSpace(ep, end) != end)) {
899
+ break;
900
+ }
901
+
902
+ /*
903
+ * JSVAL_TRUE indicates that double jsval was never constructed
904
+ * for the result.
905
+ */
906
+ *vp = JSVAL_TRUE;
907
+ return d;
908
+ }
909
+ if (JSVAL_IS_BOOLEAN(v)) {
910
+ if (JSVAL_TO_BOOLEAN(v)) {
911
+ *vp = JSVAL_ONE;
912
+ return 1.0;
913
+ } else {
914
+ *vp = JSVAL_ZERO;
915
+ return 0.0;
916
+ }
917
+ }
918
+ if (JSVAL_IS_NULL(v)) {
919
+ *vp = JSVAL_ZERO;
920
+ return 0.0;
921
+ }
922
+ if (JSVAL_IS_VOID(v))
923
+ break;
924
+
925
+ JS_ASSERT(!JSVAL_IS_PRIMITIVE(v));
926
+ obj = JSVAL_TO_OBJECT(v);
927
+
928
+ /*
929
+ * vp roots obj so we cannot use it as an extra root for
930
+ * OBJ_DEFAULT_VALUE result when calling the hook.
931
+ */
932
+ JS_PUSH_SINGLE_TEMP_ROOT(cx, v, &tvr);
933
+ if (!OBJ_DEFAULT_VALUE(cx, obj, JSTYPE_NUMBER, &tvr.u.value))
934
+ obj = NULL;
935
+ else
936
+ v = *vp = tvr.u.value;
937
+ JS_POP_TEMP_ROOT(cx, &tvr);
938
+ if (!obj) {
939
+ *vp = JSVAL_NULL;
940
+ return 0.0;
941
+ }
942
+ if (!JSVAL_IS_PRIMITIVE(v))
943
+ break;
944
+ }
945
+
946
+ dp = cx->runtime->jsNaN;
947
+ *vp = DOUBLE_TO_JSVAL(dp);
948
+ return *dp;
949
+ }
950
+
951
+ int32
952
+ js_ValueToECMAInt32(JSContext *cx, jsval *vp)
953
+ {
954
+ jsval v;
955
+ jsdouble d;
956
+
957
+ v = *vp;
958
+ if (JSVAL_IS_INT(v))
959
+ return JSVAL_TO_INT(v);
960
+ if (JSVAL_IS_DOUBLE(v)) {
961
+ d = *JSVAL_TO_DOUBLE(v);
962
+ *vp = JSVAL_TRUE;
963
+ } else {
964
+ d = js_ValueToNumber(cx, vp);
965
+ if (JSVAL_IS_NULL(*vp))
966
+ return 0;
967
+ *vp = JSVAL_TRUE;
968
+ }
969
+ return js_DoubleToECMAInt32(d);
970
+ }
971
+
972
+ int32
973
+ js_DoubleToECMAInt32(jsdouble d)
974
+ {
975
+ int32 i;
976
+ jsdouble two32, two31;
977
+
978
+ if (!JSDOUBLE_IS_FINITE(d))
979
+ return 0;
980
+
981
+ i = (int32) d;
982
+ if ((jsdouble) i == d)
983
+ return i;
984
+
985
+ two32 = 4294967296.0;
986
+ two31 = 2147483648.0;
987
+ d = fmod(d, two32);
988
+ d = (d >= 0) ? floor(d) : ceil(d) + two32;
989
+ return (int32) (d >= two31 ? d - two32 : d);
990
+ }
991
+
992
+ uint32
993
+ js_ValueToECMAUint32(JSContext *cx, jsval *vp)
994
+ {
995
+ jsval v;
996
+ jsint i;
997
+ jsdouble d;
998
+
999
+ v = *vp;
1000
+ if (JSVAL_IS_INT(v)) {
1001
+ i = JSVAL_TO_INT(v);
1002
+ if (i < 0)
1003
+ *vp = JSVAL_TRUE;
1004
+ return (uint32) i;
1005
+ }
1006
+ if (JSVAL_IS_DOUBLE(v)) {
1007
+ d = *JSVAL_TO_DOUBLE(v);
1008
+ *vp = JSVAL_TRUE;
1009
+ } else {
1010
+ d = js_ValueToNumber(cx, vp);
1011
+ if (JSVAL_IS_NULL(*vp))
1012
+ return 0;
1013
+ *vp = JSVAL_TRUE;
1014
+ }
1015
+ return js_DoubleToECMAUint32(d);
1016
+ }
1017
+
1018
+ uint32
1019
+ js_DoubleToECMAUint32(jsdouble d)
1020
+ {
1021
+ int32 i;
1022
+ JSBool neg;
1023
+ jsdouble two32;
1024
+
1025
+ if (!JSDOUBLE_IS_FINITE(d))
1026
+ return 0;
1027
+
1028
+ /*
1029
+ * We check whether d fits int32, not uint32, as all but the ">>>" bit
1030
+ * manipulation bytecode stores the result as int, not uint. When the
1031
+ * result does not fit int jsval, it will be stored as a negative double.
1032
+ */
1033
+ i = (int32) d;
1034
+ if ((jsdouble) i == d)
1035
+ return (int32)i;
1036
+
1037
+ neg = (d < 0);
1038
+ d = floor(neg ? -d : d);
1039
+ d = neg ? -d : d;
1040
+
1041
+ two32 = 4294967296.0;
1042
+ d = fmod(d, two32);
1043
+
1044
+ return (uint32) (d >= 0 ? d : d + two32);
1045
+ }
1046
+
1047
+ int32
1048
+ js_ValueToInt32(JSContext *cx, jsval *vp)
1049
+ {
1050
+ jsval v;
1051
+ jsdouble d;
1052
+
1053
+ v = *vp;
1054
+ if (JSVAL_IS_INT(v))
1055
+ return JSVAL_TO_INT(v);
1056
+ d = js_ValueToNumber(cx, vp);
1057
+ if (JSVAL_IS_NULL(*vp))
1058
+ return 0;
1059
+ if (JSVAL_IS_INT(*vp))
1060
+ return JSVAL_TO_INT(*vp);
1061
+
1062
+ *vp = JSVAL_TRUE;
1063
+ if (JSDOUBLE_IS_NaN(d) || d <= -2147483649.0 || 2147483648.0 <= d) {
1064
+ js_ReportValueError(cx, JSMSG_CANT_CONVERT,
1065
+ JSDVG_SEARCH_STACK, v, NULL);
1066
+ *vp = JSVAL_NULL;
1067
+ return 0;
1068
+ }
1069
+ return (int32) floor(d + 0.5); /* Round to nearest */
1070
+ }
1071
+
1072
+ uint16
1073
+ js_ValueToUint16(JSContext *cx, jsval *vp)
1074
+ {
1075
+ jsdouble d;
1076
+ uint16 u;
1077
+ jsuint m;
1078
+ JSBool neg;
1079
+
1080
+ d = js_ValueToNumber(cx, vp);
1081
+ if (JSVAL_IS_NULL(*vp))
1082
+ return 0;
1083
+
1084
+ if (JSVAL_IS_INT(*vp)) {
1085
+ u = (uint16) JSVAL_TO_INT(*vp);
1086
+ } else if (d == 0 || !JSDOUBLE_IS_FINITE(d)) {
1087
+ u = (uint16) 0;
1088
+ } else {
1089
+ u = (uint16) d;
1090
+ if ((jsdouble) u != d) {
1091
+ neg = (d < 0);
1092
+ d = floor(neg ? -d : d);
1093
+ d = neg ? -d : d;
1094
+ m = JS_BIT(16);
1095
+ d = fmod(d, (double) m);
1096
+ if (d < 0)
1097
+ d += m;
1098
+ u = (uint16) d;
1099
+ }
1100
+ }
1101
+ *vp = INT_TO_JSVAL(u);
1102
+ return u;
1103
+ }
1104
+
1105
+ jsdouble
1106
+ js_DoubleToInteger(jsdouble d)
1107
+ {
1108
+ JSBool neg;
1109
+
1110
+ if (d == 0)
1111
+ return d;
1112
+ if (!JSDOUBLE_IS_FINITE(d)) {
1113
+ if (JSDOUBLE_IS_NaN(d))
1114
+ return 0;
1115
+ return d;
1116
+ }
1117
+ neg = (d < 0);
1118
+ d = floor(neg ? -d : d);
1119
+ return neg ? -d : d;
1120
+ }
1121
+
1122
+ JSBool
1123
+ js_strtod(JSContext *cx, const jschar *s, const jschar *send,
1124
+ const jschar **ep, jsdouble *dp)
1125
+ {
1126
+ const jschar *s1;
1127
+ size_t length, i;
1128
+ char cbuf[32];
1129
+ char *cstr, *istr, *estr;
1130
+ JSBool negative;
1131
+ jsdouble d;
1132
+
1133
+ s1 = js_SkipWhiteSpace(s, send);
1134
+ length = send - s1;
1135
+
1136
+ /* Use cbuf to avoid malloc */
1137
+ if (length >= sizeof cbuf) {
1138
+ cstr = (char *) JS_malloc(cx, length + 1);
1139
+ if (!cstr)
1140
+ return JS_FALSE;
1141
+ } else {
1142
+ cstr = cbuf;
1143
+ }
1144
+
1145
+ for (i = 0; i != length; i++) {
1146
+ if (s1[i] >> 8)
1147
+ break;
1148
+ cstr[i] = (char)s1[i];
1149
+ }
1150
+ cstr[i] = 0;
1151
+
1152
+ istr = cstr;
1153
+ if ((negative = (*istr == '-')) != 0 || *istr == '+')
1154
+ istr++;
1155
+ if (!strncmp(istr, js_Infinity_str, sizeof js_Infinity_str - 1)) {
1156
+ d = *(negative ? cx->runtime->jsNegativeInfinity : cx->runtime->jsPositiveInfinity);
1157
+ estr = istr + 8;
1158
+ } else {
1159
+ int err;
1160
+ d = JS_strtod(cstr, &estr, &err);
1161
+ if (d == HUGE_VAL)
1162
+ d = *cx->runtime->jsPositiveInfinity;
1163
+ else if (d == -HUGE_VAL)
1164
+ d = *cx->runtime->jsNegativeInfinity;
1165
+ #ifdef HPUX
1166
+ if (d == 0.0 && negative) {
1167
+ /*
1168
+ * "-0", "-1e-2000" come out as positive zero
1169
+ * here on HPUX. Force a negative zero instead.
1170
+ */
1171
+ JSDOUBLE_HI32(d) = JSDOUBLE_HI32_SIGNBIT;
1172
+ JSDOUBLE_LO32(d) = 0;
1173
+ }
1174
+ #endif
1175
+ }
1176
+
1177
+ i = estr - cstr;
1178
+ if (cstr != cbuf)
1179
+ JS_free(cx, cstr);
1180
+ *ep = i ? s1 + i : s;
1181
+ *dp = d;
1182
+ return JS_TRUE;
1183
+ }
1184
+
1185
+ struct BinaryDigitReader
1186
+ {
1187
+ uintN base; /* Base of number; must be a power of 2 */
1188
+ uintN digit; /* Current digit value in radix given by base */
1189
+ uintN digitMask; /* Mask to extract the next bit from digit */
1190
+ const jschar *digits; /* Pointer to the remaining digits */
1191
+ const jschar *end; /* Pointer to first non-digit */
1192
+ };
1193
+
1194
+ /* Return the next binary digit from the number or -1 if done */
1195
+ static intN GetNextBinaryDigit(struct BinaryDigitReader *bdr)
1196
+ {
1197
+ intN bit;
1198
+
1199
+ if (bdr->digitMask == 0) {
1200
+ uintN c;
1201
+
1202
+ if (bdr->digits == bdr->end)
1203
+ return -1;
1204
+
1205
+ c = *bdr->digits++;
1206
+ if ('0' <= c && c <= '9')
1207
+ bdr->digit = c - '0';
1208
+ else if ('a' <= c && c <= 'z')
1209
+ bdr->digit = c - 'a' + 10;
1210
+ else bdr->digit = c - 'A' + 10;
1211
+ bdr->digitMask = bdr->base >> 1;
1212
+ }
1213
+ bit = (bdr->digit & bdr->digitMask) != 0;
1214
+ bdr->digitMask >>= 1;
1215
+ return bit;
1216
+ }
1217
+
1218
+ JSBool
1219
+ js_strtointeger(JSContext *cx, const jschar *s, const jschar *send,
1220
+ const jschar **ep, jsint base, jsdouble *dp)
1221
+ {
1222
+ const jschar *s1, *start;
1223
+ JSBool negative;
1224
+ jsdouble value;
1225
+
1226
+ s1 = js_SkipWhiteSpace(s, send);
1227
+ if (s1 == send)
1228
+ goto no_digits;
1229
+ if ((negative = (*s1 == '-')) != 0 || *s1 == '+') {
1230
+ s1++;
1231
+ if (s1 == send)
1232
+ goto no_digits;
1233
+ }
1234
+
1235
+ if (base == 0) {
1236
+ /* No base supplied, or some base that evaluated to 0. */
1237
+ if (*s1 == '0') {
1238
+ /* It's either hex or octal; only increment char if str isn't '0' */
1239
+ if (s1 + 1 != send && (s1[1] == 'X' || s1[1] == 'x')) {
1240
+ base = 16;
1241
+ s1 += 2;
1242
+ if (s1 == send)
1243
+ goto no_digits;
1244
+ } else {
1245
+ base = 8;
1246
+ }
1247
+ } else {
1248
+ base = 10; /* Default to decimal. */
1249
+ }
1250
+ } else if (base == 16) {
1251
+ /* If base is 16, ignore hex prefix. */
1252
+ if (*s1 == '0' && s1 + 1 != send && (s1[1] == 'X' || s1[1] == 'x')) {
1253
+ s1 += 2;
1254
+ if (s1 == send)
1255
+ goto no_digits;
1256
+ }
1257
+ }
1258
+
1259
+ /*
1260
+ * Done with the preliminaries; find some prefix of the string that's
1261
+ * a number in the given base.
1262
+ */
1263
+ JS_ASSERT(s1 < send);
1264
+ start = s1;
1265
+ value = 0.0;
1266
+ do {
1267
+ uintN digit;
1268
+ jschar c = *s1;
1269
+ if ('0' <= c && c <= '9')
1270
+ digit = c - '0';
1271
+ else if ('a' <= c && c <= 'z')
1272
+ digit = c - 'a' + 10;
1273
+ else if ('A' <= c && c <= 'Z')
1274
+ digit = c - 'A' + 10;
1275
+ else
1276
+ break;
1277
+ if (digit >= (uintN)base)
1278
+ break;
1279
+ value = value * base + digit;
1280
+ } while (++s1 != send);
1281
+
1282
+ if (value >= 9007199254740992.0) {
1283
+ if (base == 10) {
1284
+ /*
1285
+ * If we're accumulating a decimal number and the number is >=
1286
+ * 2^53, then the result from the repeated multiply-add above may
1287
+ * be inaccurate. Call JS_strtod to get the correct answer.
1288
+ */
1289
+ size_t i;
1290
+ size_t length = s1 - start;
1291
+ char *cstr = (char *) JS_malloc(cx, length + 1);
1292
+ char *estr;
1293
+ int err=0;
1294
+
1295
+ if (!cstr)
1296
+ return JS_FALSE;
1297
+ for (i = 0; i != length; i++)
1298
+ cstr[i] = (char)start[i];
1299
+ cstr[length] = 0;
1300
+
1301
+ value = JS_strtod(cstr, &estr, &err);
1302
+ if (err == JS_DTOA_ENOMEM) {
1303
+ JS_ReportOutOfMemory(cx);
1304
+ JS_free(cx, cstr);
1305
+ return JS_FALSE;
1306
+ }
1307
+ if (err == JS_DTOA_ERANGE && value == HUGE_VAL)
1308
+ value = *cx->runtime->jsPositiveInfinity;
1309
+ JS_free(cx, cstr);
1310
+ } else if ((base & (base - 1)) == 0) {
1311
+ /*
1312
+ * The number may also be inaccurate for power-of-two bases. This
1313
+ * happens if the addition in value * base + digit causes a round-
1314
+ * down to an even least significant mantissa bit when the first
1315
+ * dropped bit is a one. If any of the following digits in the
1316
+ * number (which haven't been added in yet) are nonzero, then the
1317
+ * correct action would have been to round up instead of down. An
1318
+ * example occurs when reading the number 0x1000000000000081, which
1319
+ * rounds to 0x1000000000000000 instead of 0x1000000000000100.
1320
+ */
1321
+ struct BinaryDigitReader bdr;
1322
+ intN bit, bit2;
1323
+ intN j;
1324
+
1325
+ bdr.base = base;
1326
+ bdr.digitMask = 0;
1327
+ bdr.digits = start;
1328
+ bdr.end = s1;
1329
+ value = 0.0;
1330
+
1331
+ /* Skip leading zeros. */
1332
+ do {
1333
+ bit = GetNextBinaryDigit(&bdr);
1334
+ } while (bit == 0);
1335
+
1336
+ if (bit == 1) {
1337
+ /* Gather the 53 significant bits (including the leading 1) */
1338
+ value = 1.0;
1339
+ for (j = 52; j; j--) {
1340
+ bit = GetNextBinaryDigit(&bdr);
1341
+ if (bit < 0)
1342
+ goto done;
1343
+ value = value*2 + bit;
1344
+ }
1345
+ /* bit2 is the 54th bit (the first dropped from the mantissa) */
1346
+ bit2 = GetNextBinaryDigit(&bdr);
1347
+ if (bit2 >= 0) {
1348
+ jsdouble factor = 2.0;
1349
+ intN sticky = 0; /* sticky is 1 if any bit beyond the 54th is 1 */
1350
+ intN bit3;
1351
+
1352
+ while ((bit3 = GetNextBinaryDigit(&bdr)) >= 0) {
1353
+ sticky |= bit3;
1354
+ factor *= 2;
1355
+ }
1356
+ value += bit2 & (bit | sticky);
1357
+ value *= factor;
1358
+ }
1359
+ done:;
1360
+ }
1361
+ }
1362
+ }
1363
+ /* We don't worry about inaccurate numbers for any other base. */
1364
+
1365
+ if (s1 == start) {
1366
+ no_digits:
1367
+ *dp = 0.0;
1368
+ *ep = s;
1369
+ } else {
1370
+ *dp = negative ? -value : value;
1371
+ *ep = s1;
1372
+ }
1373
+ return JS_TRUE;
1374
+ }