johnson 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (371) hide show
  1. data/.autotest +14 -0
  2. data/CHANGELOG.rdoc +11 -0
  3. data/Manifest.txt +370 -0
  4. data/README.rdoc +60 -0
  5. data/Rakefile +42 -0
  6. data/bin/johnson +108 -0
  7. data/docs/MINGW32.mk +124 -0
  8. data/docs/cross-compile.txt +38 -0
  9. data/ext/spidermonkey/context.c +115 -0
  10. data/ext/spidermonkey/context.h +19 -0
  11. data/ext/spidermonkey/conversions.c +320 -0
  12. data/ext/spidermonkey/conversions.h +18 -0
  13. data/ext/spidermonkey/debugger.c +226 -0
  14. data/ext/spidermonkey/debugger.h +9 -0
  15. data/ext/spidermonkey/extconf.rb +30 -0
  16. data/ext/spidermonkey/extensions.c +37 -0
  17. data/ext/spidermonkey/extensions.h +12 -0
  18. data/ext/spidermonkey/global.c +40 -0
  19. data/ext/spidermonkey/global.h +11 -0
  20. data/ext/spidermonkey/idhash.c +16 -0
  21. data/ext/spidermonkey/idhash.h +8 -0
  22. data/ext/spidermonkey/immutable_node.c +1153 -0
  23. data/ext/spidermonkey/immutable_node.c.erb +523 -0
  24. data/ext/spidermonkey/immutable_node.h +22 -0
  25. data/ext/spidermonkey/jroot.h +187 -0
  26. data/ext/spidermonkey/js_land_proxy.c +610 -0
  27. data/ext/spidermonkey/js_land_proxy.h +20 -0
  28. data/ext/spidermonkey/ruby_land_proxy.c +543 -0
  29. data/ext/spidermonkey/ruby_land_proxy.h +17 -0
  30. data/ext/spidermonkey/runtime.c +330 -0
  31. data/ext/spidermonkey/runtime.h +25 -0
  32. data/ext/spidermonkey/spidermonkey.c +20 -0
  33. data/ext/spidermonkey/spidermonkey.h +29 -0
  34. data/johnson.gemspec +44 -0
  35. data/js/johnson/cli.js +30 -0
  36. data/js/johnson/prelude.js +80 -0
  37. data/lib/johnson.rb +55 -0
  38. data/lib/johnson/cli.rb +7 -0
  39. data/lib/johnson/cli/options.rb +67 -0
  40. data/lib/johnson/error.rb +4 -0
  41. data/lib/johnson/nodes.rb +7 -0
  42. data/lib/johnson/nodes/binary_node.rb +65 -0
  43. data/lib/johnson/nodes/for.rb +14 -0
  44. data/lib/johnson/nodes/for_in.rb +12 -0
  45. data/lib/johnson/nodes/function.rb +13 -0
  46. data/lib/johnson/nodes/list.rb +28 -0
  47. data/lib/johnson/nodes/node.rb +68 -0
  48. data/lib/johnson/nodes/ternary_node.rb +20 -0
  49. data/lib/johnson/parser.rb +21 -0
  50. data/lib/johnson/parser/syntax_error.rb +13 -0
  51. data/lib/johnson/runtime.rb +63 -0
  52. data/lib/johnson/spidermonkey/context.rb +10 -0
  53. data/lib/johnson/spidermonkey/debugger.rb +67 -0
  54. data/lib/johnson/spidermonkey/immutable_node.rb +282 -0
  55. data/lib/johnson/spidermonkey/js_land_proxy.rb +62 -0
  56. data/lib/johnson/spidermonkey/mutable_tree_visitor.rb +242 -0
  57. data/lib/johnson/spidermonkey/ruby_land_proxy.rb +54 -0
  58. data/lib/johnson/spidermonkey/runtime.rb +103 -0
  59. data/lib/johnson/version.rb +3 -0
  60. data/lib/johnson/visitable.rb +16 -0
  61. data/lib/johnson/visitors.rb +5 -0
  62. data/lib/johnson/visitors/dot_visitor.rb +169 -0
  63. data/lib/johnson/visitors/ecma_visitor.rb +323 -0
  64. data/lib/johnson/visitors/enumerating_visitor.rb +15 -0
  65. data/lib/johnson/visitors/sexp_visitor.rb +174 -0
  66. data/lib/johnson/visitors/visitor.rb +91 -0
  67. data/lib/rails/init.rb +37 -0
  68. data/lib/tasks/gem.rake +9 -0
  69. data/lib/tasks/parsing.rake +37 -0
  70. data/lib/tasks/testing.rake +36 -0
  71. data/lib/tasks/vendor.rake +20 -0
  72. data/test/helper.rb +55 -0
  73. data/test/johnson/browser_test.rb +43 -0
  74. data/test/johnson/conversions/array_test.rb +32 -0
  75. data/test/johnson/conversions/boolean_test.rb +17 -0
  76. data/test/johnson/conversions/callable_test.rb +34 -0
  77. data/test/johnson/conversions/file_test.rb +15 -0
  78. data/test/johnson/conversions/nil_test.rb +20 -0
  79. data/test/johnson/conversions/number_test.rb +34 -0
  80. data/test/johnson/conversions/regexp_test.rb +24 -0
  81. data/test/johnson/conversions/string_test.rb +26 -0
  82. data/test/johnson/conversions/struct_test.rb +15 -0
  83. data/test/johnson/conversions/symbol_test.rb +19 -0
  84. data/test/johnson/conversions/thread_test.rb +24 -0
  85. data/test/johnson/error_test.rb +9 -0
  86. data/test/johnson/extensions_test.rb +56 -0
  87. data/test/johnson/nodes/array_literal_test.rb +57 -0
  88. data/test/johnson/nodes/array_node_test.rb +26 -0
  89. data/test/johnson/nodes/binary_node_test.rb +61 -0
  90. data/test/johnson/nodes/bracket_access_test.rb +16 -0
  91. data/test/johnson/nodes/delete_test.rb +11 -0
  92. data/test/johnson/nodes/do_while_test.rb +12 -0
  93. data/test/johnson/nodes/dot_accessor_test.rb +15 -0
  94. data/test/johnson/nodes/export_test.rb +9 -0
  95. data/test/johnson/nodes/for_test.rb +54 -0
  96. data/test/johnson/nodes/function_test.rb +71 -0
  97. data/test/johnson/nodes/if_test.rb +41 -0
  98. data/test/johnson/nodes/import_test.rb +13 -0
  99. data/test/johnson/nodes/label_test.rb +19 -0
  100. data/test/johnson/nodes/let_test.rb +31 -0
  101. data/test/johnson/nodes/object_literal_test.rb +110 -0
  102. data/test/johnson/nodes/return_test.rb +16 -0
  103. data/test/johnson/nodes/semi_test.rb +8 -0
  104. data/test/johnson/nodes/switch_test.rb +55 -0
  105. data/test/johnson/nodes/ternary_test.rb +25 -0
  106. data/test/johnson/nodes/throw_test.rb +9 -0
  107. data/test/johnson/nodes/try_node_test.rb +59 -0
  108. data/test/johnson/nodes/typeof_test.rb +11 -0
  109. data/test/johnson/nodes/unary_node_test.rb +23 -0
  110. data/test/johnson/nodes/void_test.rb +11 -0
  111. data/test/johnson/nodes/while_test.rb +26 -0
  112. data/test/johnson/nodes/with_test.rb +10 -0
  113. data/test/johnson/prelude_test.rb +56 -0
  114. data/test/johnson/runtime_test.rb +64 -0
  115. data/test/johnson/spidermonkey/context_test.rb +21 -0
  116. data/test/johnson/spidermonkey/immutable_node_test.rb +34 -0
  117. data/test/johnson/spidermonkey/js_land_proxy_test.rb +236 -0
  118. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +240 -0
  119. data/test/johnson/spidermonkey/runtime_test.rb +17 -0
  120. data/test/johnson/version_test.rb +13 -0
  121. data/test/johnson/visitors/dot_visitor_test.rb +39 -0
  122. data/test/johnson/visitors/enumerating_visitor_test.rb +12 -0
  123. data/test/johnson_test.rb +16 -0
  124. data/test/parser_test.rb +276 -0
  125. data/vendor/spidermonkey/.cvsignore +9 -0
  126. data/vendor/spidermonkey/Makefile.in +449 -0
  127. data/vendor/spidermonkey/Makefile.ref +365 -0
  128. data/vendor/spidermonkey/README.html +820 -0
  129. data/vendor/spidermonkey/SpiderMonkey.rsp +12 -0
  130. data/vendor/spidermonkey/Y.js +19 -0
  131. data/vendor/spidermonkey/build.mk +43 -0
  132. data/vendor/spidermonkey/config.mk +192 -0
  133. data/vendor/spidermonkey/config/AIX4.1.mk +65 -0
  134. data/vendor/spidermonkey/config/AIX4.2.mk +64 -0
  135. data/vendor/spidermonkey/config/AIX4.3.mk +65 -0
  136. data/vendor/spidermonkey/config/Darwin.mk +83 -0
  137. data/vendor/spidermonkey/config/Darwin1.3.mk +81 -0
  138. data/vendor/spidermonkey/config/Darwin1.4.mk +41 -0
  139. data/vendor/spidermonkey/config/Darwin5.2.mk +81 -0
  140. data/vendor/spidermonkey/config/Darwin5.3.mk +81 -0
  141. data/vendor/spidermonkey/config/HP-UXB.10.10.mk +77 -0
  142. data/vendor/spidermonkey/config/HP-UXB.10.20.mk +77 -0
  143. data/vendor/spidermonkey/config/HP-UXB.11.00.mk +80 -0
  144. data/vendor/spidermonkey/config/IRIX.mk +87 -0
  145. data/vendor/spidermonkey/config/IRIX5.3.mk +44 -0
  146. data/vendor/spidermonkey/config/IRIX6.1.mk +44 -0
  147. data/vendor/spidermonkey/config/IRIX6.2.mk +44 -0
  148. data/vendor/spidermonkey/config/IRIX6.3.mk +44 -0
  149. data/vendor/spidermonkey/config/IRIX6.5.mk +44 -0
  150. data/vendor/spidermonkey/config/Linux_All.mk +103 -0
  151. data/vendor/spidermonkey/config/Mac_OS10.0.mk +82 -0
  152. data/vendor/spidermonkey/config/OSF1V4.0.mk +72 -0
  153. data/vendor/spidermonkey/config/OSF1V5.0.mk +69 -0
  154. data/vendor/spidermonkey/config/SunOS4.1.4.mk +101 -0
  155. data/vendor/spidermonkey/config/SunOS5.10.mk +50 -0
  156. data/vendor/spidermonkey/config/SunOS5.3.mk +91 -0
  157. data/vendor/spidermonkey/config/SunOS5.4.mk +92 -0
  158. data/vendor/spidermonkey/config/SunOS5.5.1.mk +44 -0
  159. data/vendor/spidermonkey/config/SunOS5.5.mk +87 -0
  160. data/vendor/spidermonkey/config/SunOS5.6.mk +89 -0
  161. data/vendor/spidermonkey/config/SunOS5.7.mk +44 -0
  162. data/vendor/spidermonkey/config/SunOS5.8.mk +44 -0
  163. data/vendor/spidermonkey/config/SunOS5.9.mk +44 -0
  164. data/vendor/spidermonkey/config/WINNT4.0.mk +117 -0
  165. data/vendor/spidermonkey/config/WINNT5.0.mk +117 -0
  166. data/vendor/spidermonkey/config/WINNT5.1.mk +117 -0
  167. data/vendor/spidermonkey/config/WINNT5.2.mk +117 -0
  168. data/vendor/spidermonkey/config/WINNT6.0.mk +117 -0
  169. data/vendor/spidermonkey/config/dgux.mk +64 -0
  170. data/vendor/spidermonkey/editline/Makefile.ref +144 -0
  171. data/vendor/spidermonkey/editline/README +83 -0
  172. data/vendor/spidermonkey/editline/editline.3 +175 -0
  173. data/vendor/spidermonkey/editline/editline.c +1369 -0
  174. data/vendor/spidermonkey/editline/editline.h +135 -0
  175. data/vendor/spidermonkey/editline/sysunix.c +182 -0
  176. data/vendor/spidermonkey/editline/unix.h +82 -0
  177. data/vendor/spidermonkey/fdlibm/.cvsignore +7 -0
  178. data/vendor/spidermonkey/fdlibm/Makefile.in +127 -0
  179. data/vendor/spidermonkey/fdlibm/Makefile.ref +192 -0
  180. data/vendor/spidermonkey/fdlibm/e_acos.c +147 -0
  181. data/vendor/spidermonkey/fdlibm/e_acosh.c +105 -0
  182. data/vendor/spidermonkey/fdlibm/e_asin.c +156 -0
  183. data/vendor/spidermonkey/fdlibm/e_atan2.c +165 -0
  184. data/vendor/spidermonkey/fdlibm/e_atanh.c +110 -0
  185. data/vendor/spidermonkey/fdlibm/e_cosh.c +133 -0
  186. data/vendor/spidermonkey/fdlibm/e_exp.c +202 -0
  187. data/vendor/spidermonkey/fdlibm/e_fmod.c +184 -0
  188. data/vendor/spidermonkey/fdlibm/e_gamma.c +71 -0
  189. data/vendor/spidermonkey/fdlibm/e_gamma_r.c +70 -0
  190. data/vendor/spidermonkey/fdlibm/e_hypot.c +173 -0
  191. data/vendor/spidermonkey/fdlibm/e_j0.c +524 -0
  192. data/vendor/spidermonkey/fdlibm/e_j1.c +523 -0
  193. data/vendor/spidermonkey/fdlibm/e_jn.c +315 -0
  194. data/vendor/spidermonkey/fdlibm/e_lgamma.c +71 -0
  195. data/vendor/spidermonkey/fdlibm/e_lgamma_r.c +347 -0
  196. data/vendor/spidermonkey/fdlibm/e_log.c +184 -0
  197. data/vendor/spidermonkey/fdlibm/e_log10.c +134 -0
  198. data/vendor/spidermonkey/fdlibm/e_pow.c +386 -0
  199. data/vendor/spidermonkey/fdlibm/e_rem_pio2.c +222 -0
  200. data/vendor/spidermonkey/fdlibm/e_remainder.c +120 -0
  201. data/vendor/spidermonkey/fdlibm/e_scalb.c +89 -0
  202. data/vendor/spidermonkey/fdlibm/e_sinh.c +122 -0
  203. data/vendor/spidermonkey/fdlibm/e_sqrt.c +497 -0
  204. data/vendor/spidermonkey/fdlibm/fdlibm.h +273 -0
  205. data/vendor/spidermonkey/fdlibm/fdlibm.mak +1453 -0
  206. data/vendor/spidermonkey/fdlibm/fdlibm.mdp +0 -0
  207. data/vendor/spidermonkey/fdlibm/k_cos.c +135 -0
  208. data/vendor/spidermonkey/fdlibm/k_rem_pio2.c +354 -0
  209. data/vendor/spidermonkey/fdlibm/k_sin.c +114 -0
  210. data/vendor/spidermonkey/fdlibm/k_standard.c +785 -0
  211. data/vendor/spidermonkey/fdlibm/k_tan.c +170 -0
  212. data/vendor/spidermonkey/fdlibm/s_asinh.c +101 -0
  213. data/vendor/spidermonkey/fdlibm/s_atan.c +175 -0
  214. data/vendor/spidermonkey/fdlibm/s_cbrt.c +133 -0
  215. data/vendor/spidermonkey/fdlibm/s_ceil.c +120 -0
  216. data/vendor/spidermonkey/fdlibm/s_copysign.c +72 -0
  217. data/vendor/spidermonkey/fdlibm/s_cos.c +118 -0
  218. data/vendor/spidermonkey/fdlibm/s_erf.c +356 -0
  219. data/vendor/spidermonkey/fdlibm/s_expm1.c +267 -0
  220. data/vendor/spidermonkey/fdlibm/s_fabs.c +70 -0
  221. data/vendor/spidermonkey/fdlibm/s_finite.c +71 -0
  222. data/vendor/spidermonkey/fdlibm/s_floor.c +121 -0
  223. data/vendor/spidermonkey/fdlibm/s_frexp.c +99 -0
  224. data/vendor/spidermonkey/fdlibm/s_ilogb.c +85 -0
  225. data/vendor/spidermonkey/fdlibm/s_isnan.c +74 -0
  226. data/vendor/spidermonkey/fdlibm/s_ldexp.c +66 -0
  227. data/vendor/spidermonkey/fdlibm/s_lib_version.c +73 -0
  228. data/vendor/spidermonkey/fdlibm/s_log1p.c +211 -0
  229. data/vendor/spidermonkey/fdlibm/s_logb.c +79 -0
  230. data/vendor/spidermonkey/fdlibm/s_matherr.c +64 -0
  231. data/vendor/spidermonkey/fdlibm/s_modf.c +132 -0
  232. data/vendor/spidermonkey/fdlibm/s_nextafter.c +124 -0
  233. data/vendor/spidermonkey/fdlibm/s_rint.c +131 -0
  234. data/vendor/spidermonkey/fdlibm/s_scalbn.c +107 -0
  235. data/vendor/spidermonkey/fdlibm/s_signgam.c +40 -0
  236. data/vendor/spidermonkey/fdlibm/s_significand.c +68 -0
  237. data/vendor/spidermonkey/fdlibm/s_sin.c +118 -0
  238. data/vendor/spidermonkey/fdlibm/s_tan.c +112 -0
  239. data/vendor/spidermonkey/fdlibm/s_tanh.c +122 -0
  240. data/vendor/spidermonkey/fdlibm/w_acos.c +78 -0
  241. data/vendor/spidermonkey/fdlibm/w_acosh.c +78 -0
  242. data/vendor/spidermonkey/fdlibm/w_asin.c +80 -0
  243. data/vendor/spidermonkey/fdlibm/w_atan2.c +79 -0
  244. data/vendor/spidermonkey/fdlibm/w_atanh.c +81 -0
  245. data/vendor/spidermonkey/fdlibm/w_cosh.c +77 -0
  246. data/vendor/spidermonkey/fdlibm/w_exp.c +88 -0
  247. data/vendor/spidermonkey/fdlibm/w_fmod.c +78 -0
  248. data/vendor/spidermonkey/fdlibm/w_gamma.c +85 -0
  249. data/vendor/spidermonkey/fdlibm/w_gamma_r.c +81 -0
  250. data/vendor/spidermonkey/fdlibm/w_hypot.c +78 -0
  251. data/vendor/spidermonkey/fdlibm/w_j0.c +105 -0
  252. data/vendor/spidermonkey/fdlibm/w_j1.c +106 -0
  253. data/vendor/spidermonkey/fdlibm/w_jn.c +128 -0
  254. data/vendor/spidermonkey/fdlibm/w_lgamma.c +85 -0
  255. data/vendor/spidermonkey/fdlibm/w_lgamma_r.c +81 -0
  256. data/vendor/spidermonkey/fdlibm/w_log.c +78 -0
  257. data/vendor/spidermonkey/fdlibm/w_log10.c +81 -0
  258. data/vendor/spidermonkey/fdlibm/w_pow.c +99 -0
  259. data/vendor/spidermonkey/fdlibm/w_remainder.c +77 -0
  260. data/vendor/spidermonkey/fdlibm/w_scalb.c +95 -0
  261. data/vendor/spidermonkey/fdlibm/w_sinh.c +77 -0
  262. data/vendor/spidermonkey/fdlibm/w_sqrt.c +77 -0
  263. data/vendor/spidermonkey/javascript-trace.d +73 -0
  264. data/vendor/spidermonkey/js.c +3951 -0
  265. data/vendor/spidermonkey/js.mdp +0 -0
  266. data/vendor/spidermonkey/js.msg +308 -0
  267. data/vendor/spidermonkey/js3240.rc +79 -0
  268. data/vendor/spidermonkey/jsOS240.def +654 -0
  269. data/vendor/spidermonkey/jsapi.c +5836 -0
  270. data/vendor/spidermonkey/jsapi.h +2624 -0
  271. data/vendor/spidermonkey/jsarena.c +450 -0
  272. data/vendor/spidermonkey/jsarena.h +318 -0
  273. data/vendor/spidermonkey/jsarray.c +2996 -0
  274. data/vendor/spidermonkey/jsarray.h +127 -0
  275. data/vendor/spidermonkey/jsatom.c +1045 -0
  276. data/vendor/spidermonkey/jsatom.h +442 -0
  277. data/vendor/spidermonkey/jsbit.h +253 -0
  278. data/vendor/spidermonkey/jsbool.c +176 -0
  279. data/vendor/spidermonkey/jsbool.h +73 -0
  280. data/vendor/spidermonkey/jsclist.h +139 -0
  281. data/vendor/spidermonkey/jscntxt.c +1348 -0
  282. data/vendor/spidermonkey/jscntxt.h +1120 -0
  283. data/vendor/spidermonkey/jscompat.h +57 -0
  284. data/vendor/spidermonkey/jsconfig.h +248 -0
  285. data/vendor/spidermonkey/jsconfig.mk +181 -0
  286. data/vendor/spidermonkey/jscpucfg.c +396 -0
  287. data/vendor/spidermonkey/jscpucfg.h +212 -0
  288. data/vendor/spidermonkey/jsdate.c +2390 -0
  289. data/vendor/spidermonkey/jsdate.h +124 -0
  290. data/vendor/spidermonkey/jsdbgapi.c +1802 -0
  291. data/vendor/spidermonkey/jsdbgapi.h +464 -0
  292. data/vendor/spidermonkey/jsdhash.c +868 -0
  293. data/vendor/spidermonkey/jsdhash.h +592 -0
  294. data/vendor/spidermonkey/jsdtoa.c +3167 -0
  295. data/vendor/spidermonkey/jsdtoa.h +130 -0
  296. data/vendor/spidermonkey/jsdtracef.c +317 -0
  297. data/vendor/spidermonkey/jsdtracef.h +77 -0
  298. data/vendor/spidermonkey/jsemit.c +6909 -0
  299. data/vendor/spidermonkey/jsemit.h +741 -0
  300. data/vendor/spidermonkey/jsexn.c +1371 -0
  301. data/vendor/spidermonkey/jsexn.h +96 -0
  302. data/vendor/spidermonkey/jsfile.c +2736 -0
  303. data/vendor/spidermonkey/jsfile.h +56 -0
  304. data/vendor/spidermonkey/jsfile.msg +90 -0
  305. data/vendor/spidermonkey/jsfun.c +2634 -0
  306. data/vendor/spidermonkey/jsfun.h +254 -0
  307. data/vendor/spidermonkey/jsgc.c +3562 -0
  308. data/vendor/spidermonkey/jsgc.h +403 -0
  309. data/vendor/spidermonkey/jshash.c +476 -0
  310. data/vendor/spidermonkey/jshash.h +151 -0
  311. data/vendor/spidermonkey/jsify.pl +485 -0
  312. data/vendor/spidermonkey/jsinterp.c +7007 -0
  313. data/vendor/spidermonkey/jsinterp.h +525 -0
  314. data/vendor/spidermonkey/jsinvoke.c +43 -0
  315. data/vendor/spidermonkey/jsiter.c +1067 -0
  316. data/vendor/spidermonkey/jsiter.h +122 -0
  317. data/vendor/spidermonkey/jskeyword.tbl +124 -0
  318. data/vendor/spidermonkey/jskwgen.c +460 -0
  319. data/vendor/spidermonkey/jslibmath.h +266 -0
  320. data/vendor/spidermonkey/jslock.c +1309 -0
  321. data/vendor/spidermonkey/jslock.h +313 -0
  322. data/vendor/spidermonkey/jslocko.asm +60 -0
  323. data/vendor/spidermonkey/jslog2.c +94 -0
  324. data/vendor/spidermonkey/jslong.c +264 -0
  325. data/vendor/spidermonkey/jslong.h +412 -0
  326. data/vendor/spidermonkey/jsmath.c +567 -0
  327. data/vendor/spidermonkey/jsmath.h +57 -0
  328. data/vendor/spidermonkey/jsnum.c +1239 -0
  329. data/vendor/spidermonkey/jsnum.h +283 -0
  330. data/vendor/spidermonkey/jsobj.c +5282 -0
  331. data/vendor/spidermonkey/jsobj.h +709 -0
  332. data/vendor/spidermonkey/jsopcode.c +5245 -0
  333. data/vendor/spidermonkey/jsopcode.h +394 -0
  334. data/vendor/spidermonkey/jsopcode.tbl +523 -0
  335. data/vendor/spidermonkey/jsotypes.h +202 -0
  336. data/vendor/spidermonkey/jsparse.c +6704 -0
  337. data/vendor/spidermonkey/jsparse.h +511 -0
  338. data/vendor/spidermonkey/jsprf.c +1262 -0
  339. data/vendor/spidermonkey/jsprf.h +150 -0
  340. data/vendor/spidermonkey/jsproto.tbl +128 -0
  341. data/vendor/spidermonkey/jsprvtd.h +267 -0
  342. data/vendor/spidermonkey/jspubtd.h +744 -0
  343. data/vendor/spidermonkey/jsregexp.c +4364 -0
  344. data/vendor/spidermonkey/jsregexp.h +183 -0
  345. data/vendor/spidermonkey/jsreops.tbl +145 -0
  346. data/vendor/spidermonkey/jsscan.c +2012 -0
  347. data/vendor/spidermonkey/jsscan.h +387 -0
  348. data/vendor/spidermonkey/jsscope.c +1957 -0
  349. data/vendor/spidermonkey/jsscope.h +418 -0
  350. data/vendor/spidermonkey/jsscript.c +1832 -0
  351. data/vendor/spidermonkey/jsscript.h +287 -0
  352. data/vendor/spidermonkey/jsshell.msg +50 -0
  353. data/vendor/spidermonkey/jsstddef.h +83 -0
  354. data/vendor/spidermonkey/jsstr.c +5005 -0
  355. data/vendor/spidermonkey/jsstr.h +641 -0
  356. data/vendor/spidermonkey/jstypes.h +475 -0
  357. data/vendor/spidermonkey/jsutil.c +345 -0
  358. data/vendor/spidermonkey/jsutil.h +157 -0
  359. data/vendor/spidermonkey/jsxdrapi.c +800 -0
  360. data/vendor/spidermonkey/jsxdrapi.h +218 -0
  361. data/vendor/spidermonkey/jsxml.c +8476 -0
  362. data/vendor/spidermonkey/jsxml.h +349 -0
  363. data/vendor/spidermonkey/lock_SunOS.s +119 -0
  364. data/vendor/spidermonkey/perfect.js +39 -0
  365. data/vendor/spidermonkey/plify_jsdhash.sed +36 -0
  366. data/vendor/spidermonkey/prmjtime.c +846 -0
  367. data/vendor/spidermonkey/prmjtime.h +103 -0
  368. data/vendor/spidermonkey/resource.h +15 -0
  369. data/vendor/spidermonkey/rules.mk +197 -0
  370. data/vendor/spidermonkey/win32.order +384 -0
  371. metadata +513 -0
@@ -0,0 +1,2624 @@
1
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ * vim: set ts=8 sw=4 et tw=78:
3
+ *
4
+ * ***** BEGIN LICENSE BLOCK *****
5
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6
+ *
7
+ * The contents of this file are subject to the Mozilla Public License Version
8
+ * 1.1 (the "License"); you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ * http://www.mozilla.org/MPL/
11
+ *
12
+ * Software distributed under the License is distributed on an "AS IS" basis,
13
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14
+ * for the specific language governing rights and limitations under the
15
+ * License.
16
+ *
17
+ * The Original Code is Mozilla Communicator client code, released
18
+ * March 31, 1998.
19
+ *
20
+ * The Initial Developer of the Original Code is
21
+ * Netscape Communications Corporation.
22
+ * Portions created by the Initial Developer are Copyright (C) 1998
23
+ * the Initial Developer. All Rights Reserved.
24
+ *
25
+ * Contributor(s):
26
+ *
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
+ #ifndef jsapi_h___
42
+ #define jsapi_h___
43
+ /*
44
+ * JavaScript API.
45
+ */
46
+ #include <stddef.h>
47
+ #include <stdio.h>
48
+ #include "jspubtd.h"
49
+ #include "jsutil.h"
50
+
51
+ JS_BEGIN_EXTERN_C
52
+
53
+ /*
54
+ * Type tags stored in the low bits of a jsval.
55
+ */
56
+ #define JSVAL_OBJECT 0x0 /* untagged reference to object */
57
+ #define JSVAL_INT 0x1 /* tagged 31-bit integer value */
58
+ #define JSVAL_DOUBLE 0x2 /* tagged reference to double */
59
+ #define JSVAL_STRING 0x4 /* tagged reference to string */
60
+ #define JSVAL_BOOLEAN 0x6 /* tagged boolean value */
61
+
62
+ /* Type tag bitfield length and derived macros. */
63
+ #define JSVAL_TAGBITS 3
64
+ #define JSVAL_TAGMASK JS_BITMASK(JSVAL_TAGBITS)
65
+ #define JSVAL_TAG(v) ((v) & JSVAL_TAGMASK)
66
+ #define JSVAL_SETTAG(v,t) ((v) | (t))
67
+ #define JSVAL_CLRTAG(v) ((v) & ~(jsval)JSVAL_TAGMASK)
68
+ #define JSVAL_ALIGN JS_BIT(JSVAL_TAGBITS)
69
+
70
+ /* Predicates for type testing. */
71
+ #define JSVAL_IS_OBJECT(v) (JSVAL_TAG(v) == JSVAL_OBJECT)
72
+ #define JSVAL_IS_NUMBER(v) (JSVAL_IS_INT(v) || JSVAL_IS_DOUBLE(v))
73
+ #define JSVAL_IS_INT(v) (((v) & JSVAL_INT) && (v) != JSVAL_VOID)
74
+ #define JSVAL_IS_DOUBLE(v) (JSVAL_TAG(v) == JSVAL_DOUBLE)
75
+ #define JSVAL_IS_STRING(v) (JSVAL_TAG(v) == JSVAL_STRING)
76
+ #define JSVAL_IS_BOOLEAN(v) (JSVAL_TAG(v) == JSVAL_BOOLEAN)
77
+ #define JSVAL_IS_NULL(v) ((v) == JSVAL_NULL)
78
+ #define JSVAL_IS_VOID(v) ((v) == JSVAL_VOID)
79
+ #define JSVAL_IS_PRIMITIVE(v) (!JSVAL_IS_OBJECT(v) || JSVAL_IS_NULL(v))
80
+
81
+ /* Objects, strings, and doubles are GC'ed. */
82
+ #define JSVAL_IS_GCTHING(v) (!((v) & JSVAL_INT) && !JSVAL_IS_BOOLEAN(v))
83
+ #define JSVAL_TO_GCTHING(v) ((void *)JSVAL_CLRTAG(v))
84
+ #define JSVAL_TO_OBJECT(v) ((JSObject *)JSVAL_TO_GCTHING(v))
85
+ #define JSVAL_TO_DOUBLE(v) ((jsdouble *)JSVAL_TO_GCTHING(v))
86
+ #define JSVAL_TO_STRING(v) ((JSString *)JSVAL_TO_GCTHING(v))
87
+ #define OBJECT_TO_JSVAL(obj) ((jsval)(obj))
88
+ #define DOUBLE_TO_JSVAL(dp) JSVAL_SETTAG((jsval)(dp), JSVAL_DOUBLE)
89
+ #define STRING_TO_JSVAL(str) JSVAL_SETTAG((jsval)(str), JSVAL_STRING)
90
+
91
+ /* Lock and unlock the GC thing held by a jsval. */
92
+ #define JSVAL_LOCK(cx,v) (JSVAL_IS_GCTHING(v) \
93
+ ? JS_LockGCThing(cx, JSVAL_TO_GCTHING(v)) \
94
+ : JS_TRUE)
95
+ #define JSVAL_UNLOCK(cx,v) (JSVAL_IS_GCTHING(v) \
96
+ ? JS_UnlockGCThing(cx, JSVAL_TO_GCTHING(v)) \
97
+ : JS_TRUE)
98
+
99
+ /* Domain limits for the jsval int type. */
100
+ #define JSVAL_INT_BITS 31
101
+ #define JSVAL_INT_POW2(n) ((jsval)1 << (n))
102
+ #define JSVAL_INT_MIN ((jsval)1 - JSVAL_INT_POW2(30))
103
+ #define JSVAL_INT_MAX (JSVAL_INT_POW2(30) - 1)
104
+ #define INT_FITS_IN_JSVAL(i) ((jsuint)((i)+JSVAL_INT_MAX) <= 2*JSVAL_INT_MAX)
105
+ #define JSVAL_TO_INT(v) ((jsint)(v) >> 1)
106
+ #define INT_TO_JSVAL(i) (((jsval)(i) << 1) | JSVAL_INT)
107
+
108
+ /* Convert between boolean and jsval. */
109
+ #define JSVAL_TO_BOOLEAN(v) ((JSBool)((v) >> JSVAL_TAGBITS))
110
+ #define BOOLEAN_TO_JSVAL(b) JSVAL_SETTAG((jsval)(b) << JSVAL_TAGBITS, \
111
+ JSVAL_BOOLEAN)
112
+
113
+ /* A private data pointer (2-byte-aligned) can be stored as an int jsval. */
114
+ #define JSVAL_TO_PRIVATE(v) ((void *)((v) & ~JSVAL_INT))
115
+ #define PRIVATE_TO_JSVAL(p) ((jsval)(p) | JSVAL_INT)
116
+
117
+ /* Property attributes, set in JSPropertySpec and passed to API functions. */
118
+ #define JSPROP_ENUMERATE 0x01 /* property is visible to for/in loop */
119
+ #define JSPROP_READONLY 0x02 /* not settable: assignment is no-op */
120
+ #define JSPROP_PERMANENT 0x04 /* property cannot be deleted */
121
+ #define JSPROP_EXPORTED 0x08 /* property is exported from object */
122
+ #define JSPROP_GETTER 0x10 /* property holds getter function */
123
+ #define JSPROP_SETTER 0x20 /* property holds setter function */
124
+ #define JSPROP_SHARED 0x40 /* don't allocate a value slot for this
125
+ property; don't copy the property on
126
+ set of the same-named property in an
127
+ object that delegates to a prototype
128
+ containing this property */
129
+ #define JSPROP_INDEX 0x80 /* name is actually (jsint) index */
130
+
131
+ /* Function flags, set in JSFunctionSpec and passed to JS_NewFunction etc. */
132
+ #define JSFUN_LAMBDA 0x08 /* expressed, not declared, function */
133
+ #define JSFUN_GETTER JSPROP_GETTER
134
+ #define JSFUN_SETTER JSPROP_SETTER
135
+ #define JSFUN_BOUND_METHOD 0x40 /* bind this to fun->object's parent */
136
+ #define JSFUN_HEAVYWEIGHT 0x80 /* activation requires a Call object */
137
+
138
+ #define JSFUN_DISJOINT_FLAGS(f) ((f) & 0x0f)
139
+ #define JSFUN_GSFLAGS(f) ((f) & (JSFUN_GETTER | JSFUN_SETTER))
140
+
141
+ #ifdef MOZILLA_1_8_BRANCH
142
+
143
+ /*
144
+ * Squeeze three more bits into existing 8-bit flags by taking advantage of
145
+ * the invalid combination (JSFUN_GETTER | JSFUN_SETTER).
146
+ */
147
+ #define JSFUN_GETTER_TEST(f) (JSFUN_GSFLAGS(f) == JSFUN_GETTER)
148
+ #define JSFUN_SETTER_TEST(f) (JSFUN_GSFLAGS(f) == JSFUN_SETTER)
149
+ #define JSFUN_FLAGS_TEST(f,t) (JSFUN_GSFLAGS(~(f)) ? (f) & (t) : 0)
150
+ #define JSFUN_BOUND_METHOD_TEST(f) JSFUN_FLAGS_TEST(f, JSFUN_BOUND_METHOD)
151
+ #define JSFUN_HEAVYWEIGHT_TEST(f) JSFUN_FLAGS_TEST(f, JSFUN_HEAVYWEIGHT)
152
+
153
+ #define JSFUN_GSFLAG2ATTR(f) (JSFUN_GETTER_TEST(f) ? JSPROP_GETTER : \
154
+ JSFUN_SETTER_TEST(f) ? JSPROP_SETTER : 0)
155
+
156
+ #define JSFUN_THISP_FLAGS(f) (JSFUN_GSFLAGS(~(f)) ? 0 : \
157
+ (f) & JSFUN_THISP_PRIMITIVE)
158
+ #define JSFUN_THISP_TEST(f,t) ((f) == (t) || (f) == JSFUN_THISP_PRIMITIVE)
159
+
160
+ #define JSFUN_THISP_STRING 0x30 /* |this| may be a primitive string */
161
+ #define JSFUN_THISP_NUMBER 0x70 /* |this| may be a primitive number */
162
+ #define JSFUN_THISP_BOOLEAN 0xb0 /* |this| may be a primitive boolean */
163
+ #define JSFUN_THISP_PRIMITIVE 0xf0 /* |this| may be any primitive value */
164
+
165
+ #define JSFUN_FLAGS_MASK 0xf8 /* overlay JSFUN_* attributes */
166
+
167
+ #else
168
+
169
+ #define JSFUN_GETTER_TEST(f) ((f) & JSFUN_GETTER)
170
+ #define JSFUN_SETTER_TEST(f) ((f) & JSFUN_SETTER)
171
+ #define JSFUN_BOUND_METHOD_TEST(f) ((f) & JSFUN_BOUND_METHOD)
172
+ #define JSFUN_HEAVYWEIGHT_TEST(f) ((f) & JSFUN_HEAVYWEIGHT)
173
+
174
+ #define JSFUN_GSFLAG2ATTR(f) JSFUN_GSFLAGS(f)
175
+
176
+ #define JSFUN_THISP_FLAGS(f) (f)
177
+ #define JSFUN_THISP_TEST(f,t) ((f) & t)
178
+
179
+ #define JSFUN_THISP_STRING 0x0100 /* |this| may be a primitive string */
180
+ #define JSFUN_THISP_NUMBER 0x0200 /* |this| may be a primitive number */
181
+ #define JSFUN_THISP_BOOLEAN 0x0400 /* |this| may be a primitive boolean */
182
+ #define JSFUN_THISP_PRIMITIVE 0x0700 /* |this| may be any primitive value */
183
+
184
+ #define JSFUN_FAST_NATIVE 0x0800 /* JSFastNative needs no JSStackFrame */
185
+
186
+ #define JSFUN_FLAGS_MASK 0x0ff8 /* overlay JSFUN_* attributes --
187
+ note that bit #15 is used internally
188
+ to flag interpreted functions */
189
+
190
+ #define JSFUN_STUB_GSOPS 0x1000 /* use JS_PropertyStub getter/setter
191
+ instead of defaulting to class gsops
192
+ for property holding function */
193
+
194
+ #endif
195
+
196
+ /*
197
+ * Re-use JSFUN_LAMBDA, which applies only to scripted functions, for use in
198
+ * JSFunctionSpec arrays that specify generic native prototype methods, i.e.,
199
+ * methods of a class prototype that are exposed as static methods taking an
200
+ * extra leading argument: the generic |this| parameter.
201
+ *
202
+ * If you set this flag in a JSFunctionSpec struct's flags initializer, then
203
+ * that struct must live at least as long as the native static method object
204
+ * created due to this flag by JS_DefineFunctions or JS_InitClass. Typically
205
+ * JSFunctionSpec structs are allocated in static arrays.
206
+ */
207
+ #define JSFUN_GENERIC_NATIVE JSFUN_LAMBDA
208
+
209
+ /*
210
+ * Well-known JS values. The extern'd variables are initialized when the
211
+ * first JSContext is created by JS_NewContext (see below).
212
+ */
213
+ #define JSVAL_VOID INT_TO_JSVAL(0 - JSVAL_INT_POW2(30))
214
+ #define JSVAL_NULL OBJECT_TO_JSVAL(0)
215
+ #define JSVAL_ZERO INT_TO_JSVAL(0)
216
+ #define JSVAL_ONE INT_TO_JSVAL(1)
217
+ #define JSVAL_FALSE BOOLEAN_TO_JSVAL(JS_FALSE)
218
+ #define JSVAL_TRUE BOOLEAN_TO_JSVAL(JS_TRUE)
219
+
220
+ /*
221
+ * Microseconds since the epoch, midnight, January 1, 1970 UTC. See the
222
+ * comment in jstypes.h regarding safe int64 usage.
223
+ */
224
+ extern JS_PUBLIC_API(int64)
225
+ JS_Now(void);
226
+
227
+ /* Don't want to export data, so provide accessors for non-inline jsvals. */
228
+ extern JS_PUBLIC_API(jsval)
229
+ JS_GetNaNValue(JSContext *cx);
230
+
231
+ extern JS_PUBLIC_API(jsval)
232
+ JS_GetNegativeInfinityValue(JSContext *cx);
233
+
234
+ extern JS_PUBLIC_API(jsval)
235
+ JS_GetPositiveInfinityValue(JSContext *cx);
236
+
237
+ extern JS_PUBLIC_API(jsval)
238
+ JS_GetEmptyStringValue(JSContext *cx);
239
+
240
+ /*
241
+ * Format is a string of the following characters (spaces are insignificant),
242
+ * specifying the tabulated type conversions:
243
+ *
244
+ * b JSBool Boolean
245
+ * c uint16/jschar ECMA uint16, Unicode char
246
+ * i int32 ECMA int32
247
+ * u uint32 ECMA uint32
248
+ * j int32 Rounded int32 (coordinate)
249
+ * d jsdouble IEEE double
250
+ * I jsdouble Integral IEEE double
251
+ * s char * C string
252
+ * S JSString * Unicode string, accessed by a JSString pointer
253
+ * W jschar * Unicode character vector, 0-terminated (W for wide)
254
+ * o JSObject * Object reference
255
+ * f JSFunction * Function private
256
+ * v jsval Argument value (no conversion)
257
+ * * N/A Skip this argument (no vararg)
258
+ * / N/A End of required arguments
259
+ *
260
+ * The variable argument list after format must consist of &b, &c, &s, e.g.,
261
+ * where those variables have the types given above. For the pointer types
262
+ * char *, JSString *, and JSObject *, the pointed-at memory returned belongs
263
+ * to the JS runtime, not to the calling native code. The runtime promises
264
+ * to keep this memory valid so long as argv refers to allocated stack space
265
+ * (so long as the native function is active).
266
+ *
267
+ * Fewer arguments than format specifies may be passed only if there is a /
268
+ * in format after the last required argument specifier and argc is at least
269
+ * the number of required arguments. More arguments than format specifies
270
+ * may be passed without error; it is up to the caller to deal with trailing
271
+ * unconverted arguments.
272
+ */
273
+ extern JS_PUBLIC_API(JSBool)
274
+ JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format,
275
+ ...);
276
+
277
+ #ifdef va_start
278
+ extern JS_PUBLIC_API(JSBool)
279
+ JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv,
280
+ const char *format, va_list ap);
281
+ #endif
282
+
283
+ /*
284
+ * Inverse of JS_ConvertArguments: scan format and convert trailing arguments
285
+ * into jsvals, GC-rooted if necessary by the JS stack. Return null on error,
286
+ * and a pointer to the new argument vector on success. Also return a stack
287
+ * mark on success via *markp, in which case the caller must eventually clean
288
+ * up by calling JS_PopArguments.
289
+ *
290
+ * Note that the number of actual arguments supplied is specified exclusively
291
+ * by format, so there is no argc parameter.
292
+ */
293
+ extern JS_PUBLIC_API(jsval *)
294
+ JS_PushArguments(JSContext *cx, void **markp, const char *format, ...);
295
+
296
+ #ifdef va_start
297
+ extern JS_PUBLIC_API(jsval *)
298
+ JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap);
299
+ #endif
300
+
301
+ extern JS_PUBLIC_API(void)
302
+ JS_PopArguments(JSContext *cx, void *mark);
303
+
304
+ #ifdef JS_ARGUMENT_FORMATTER_DEFINED
305
+
306
+ /*
307
+ * Add and remove a format string handler for JS_{Convert,Push}Arguments{,VA}.
308
+ * The handler function has this signature (see jspubtd.h):
309
+ *
310
+ * JSBool MyArgumentFormatter(JSContext *cx, const char *format,
311
+ * JSBool fromJS, jsval **vpp, va_list *app);
312
+ *
313
+ * It should return true on success, and return false after reporting an error
314
+ * or detecting an already-reported error.
315
+ *
316
+ * For a given format string, for example "AA", the formatter is called from
317
+ * JS_ConvertArgumentsVA like so:
318
+ *
319
+ * formatter(cx, "AA...", JS_TRUE, &sp, &ap);
320
+ *
321
+ * sp points into the arguments array on the JS stack, while ap points into
322
+ * the stdarg.h va_list on the C stack. The JS_TRUE passed for fromJS tells
323
+ * the formatter to convert zero or more jsvals at sp to zero or more C values
324
+ * accessed via pointers-to-values at ap, updating both sp (via *vpp) and ap
325
+ * (via *app) to point past the converted arguments and their result pointers
326
+ * on the C stack.
327
+ *
328
+ * When called from JS_PushArgumentsVA, the formatter is invoked thus:
329
+ *
330
+ * formatter(cx, "AA...", JS_FALSE, &sp, &ap);
331
+ *
332
+ * where JS_FALSE for fromJS means to wrap the C values at ap according to the
333
+ * format specifier and store them at sp, updating ap and sp appropriately.
334
+ *
335
+ * The "..." after "AA" is the rest of the format string that was passed into
336
+ * JS_{Convert,Push}Arguments{,VA}. The actual format trailing substring used
337
+ * in each Convert or PushArguments call is passed to the formatter, so that
338
+ * one such function may implement several formats, in order to share code.
339
+ *
340
+ * Remove just forgets about any handler associated with format. Add does not
341
+ * copy format, it points at the string storage allocated by the caller, which
342
+ * is typically a string constant. If format is in dynamic storage, it is up
343
+ * to the caller to keep the string alive until Remove is called.
344
+ */
345
+ extern JS_PUBLIC_API(JSBool)
346
+ JS_AddArgumentFormatter(JSContext *cx, const char *format,
347
+ JSArgumentFormatter formatter);
348
+
349
+ extern JS_PUBLIC_API(void)
350
+ JS_RemoveArgumentFormatter(JSContext *cx, const char *format);
351
+
352
+ #endif /* JS_ARGUMENT_FORMATTER_DEFINED */
353
+
354
+ extern JS_PUBLIC_API(JSBool)
355
+ JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
356
+
357
+ extern JS_PUBLIC_API(JSBool)
358
+ JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
359
+
360
+ extern JS_PUBLIC_API(JSFunction *)
361
+ JS_ValueToFunction(JSContext *cx, jsval v);
362
+
363
+ extern JS_PUBLIC_API(JSFunction *)
364
+ JS_ValueToConstructor(JSContext *cx, jsval v);
365
+
366
+ extern JS_PUBLIC_API(JSString *)
367
+ JS_ValueToString(JSContext *cx, jsval v);
368
+
369
+ extern JS_PUBLIC_API(JSBool)
370
+ JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
371
+
372
+ /*
373
+ * Convert a value to a number, then to an int32, according to the ECMA rules
374
+ * for ToInt32.
375
+ */
376
+ extern JS_PUBLIC_API(JSBool)
377
+ JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip);
378
+
379
+ /*
380
+ * Convert a value to a number, then to a uint32, according to the ECMA rules
381
+ * for ToUint32.
382
+ */
383
+ extern JS_PUBLIC_API(JSBool)
384
+ JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip);
385
+
386
+ /*
387
+ * Convert a value to a number, then to an int32 if it fits by rounding to
388
+ * nearest; but failing with an error report if the double is out of range
389
+ * or unordered.
390
+ */
391
+ extern JS_PUBLIC_API(JSBool)
392
+ JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip);
393
+
394
+ /*
395
+ * ECMA ToUint16, for mapping a jsval to a Unicode point.
396
+ */
397
+ extern JS_PUBLIC_API(JSBool)
398
+ JS_ValueToUint16(JSContext *cx, jsval v, uint16 *ip);
399
+
400
+ extern JS_PUBLIC_API(JSBool)
401
+ JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
402
+
403
+ extern JS_PUBLIC_API(JSType)
404
+ JS_TypeOfValue(JSContext *cx, jsval v);
405
+
406
+ extern JS_PUBLIC_API(const char *)
407
+ JS_GetTypeName(JSContext *cx, JSType type);
408
+
409
+ /************************************************************************/
410
+
411
+ /*
412
+ * Initialization, locking, contexts, and memory allocation.
413
+ *
414
+ * It is important that the first runtime and first context be created in a
415
+ * single-threaded fashion, otherwise the behavior of the library is undefined.
416
+ * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference
417
+ */
418
+ #define JS_NewRuntime JS_Init
419
+ #define JS_DestroyRuntime JS_Finish
420
+ #define JS_LockRuntime JS_Lock
421
+ #define JS_UnlockRuntime JS_Unlock
422
+
423
+ extern JS_PUBLIC_API(JSRuntime *)
424
+ JS_NewRuntime(uint32 maxbytes);
425
+
426
+ extern JS_PUBLIC_API(void)
427
+ JS_DestroyRuntime(JSRuntime *rt);
428
+
429
+ extern JS_PUBLIC_API(void)
430
+ JS_ShutDown(void);
431
+
432
+ JS_PUBLIC_API(void *)
433
+ JS_GetRuntimePrivate(JSRuntime *rt);
434
+
435
+ JS_PUBLIC_API(void)
436
+ JS_SetRuntimePrivate(JSRuntime *rt, void *data);
437
+
438
+ extern JS_PUBLIC_API(void)
439
+ JS_BeginRequest(JSContext *cx);
440
+
441
+ extern JS_PUBLIC_API(void)
442
+ JS_EndRequest(JSContext *cx);
443
+
444
+ /* Yield to pending GC operations, regardless of request depth */
445
+ extern JS_PUBLIC_API(void)
446
+ JS_YieldRequest(JSContext *cx);
447
+
448
+ extern JS_PUBLIC_API(jsrefcount)
449
+ JS_SuspendRequest(JSContext *cx);
450
+
451
+ extern JS_PUBLIC_API(void)
452
+ JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth);
453
+
454
+ #ifdef __cplusplus
455
+ JS_END_EXTERN_C
456
+
457
+ class JSAutoRequest {
458
+ public:
459
+ JSAutoRequest(JSContext *cx) : mContext(cx), mSaveDepth(0) {
460
+ JS_BeginRequest(mContext);
461
+ }
462
+ ~JSAutoRequest() {
463
+ JS_EndRequest(mContext);
464
+ }
465
+
466
+ void suspend() {
467
+ mSaveDepth = JS_SuspendRequest(mContext);
468
+ }
469
+ void resume() {
470
+ JS_ResumeRequest(mContext, mSaveDepth);
471
+ }
472
+
473
+ protected:
474
+ JSContext *mContext;
475
+ jsrefcount mSaveDepth;
476
+
477
+ #if 0
478
+ private:
479
+ static void *operator new(size_t) CPP_THROW_NEW { return 0; };
480
+ static void operator delete(void *, size_t) { };
481
+ #endif
482
+ };
483
+
484
+ JS_BEGIN_EXTERN_C
485
+ #endif
486
+
487
+ extern JS_PUBLIC_API(void)
488
+ JS_Lock(JSRuntime *rt);
489
+
490
+ extern JS_PUBLIC_API(void)
491
+ JS_Unlock(JSRuntime *rt);
492
+
493
+ extern JS_PUBLIC_API(JSContextCallback)
494
+ JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback);
495
+
496
+ extern JS_PUBLIC_API(JSContext *)
497
+ JS_NewContext(JSRuntime *rt, size_t stackChunkSize);
498
+
499
+ extern JS_PUBLIC_API(void)
500
+ JS_DestroyContext(JSContext *cx);
501
+
502
+ extern JS_PUBLIC_API(void)
503
+ JS_DestroyContextNoGC(JSContext *cx);
504
+
505
+ extern JS_PUBLIC_API(void)
506
+ JS_DestroyContextMaybeGC(JSContext *cx);
507
+
508
+ extern JS_PUBLIC_API(void *)
509
+ JS_GetContextPrivate(JSContext *cx);
510
+
511
+ extern JS_PUBLIC_API(void)
512
+ JS_SetContextPrivate(JSContext *cx, void *data);
513
+
514
+ extern JS_PUBLIC_API(JSRuntime *)
515
+ JS_GetRuntime(JSContext *cx);
516
+
517
+ extern JS_PUBLIC_API(JSContext *)
518
+ JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
519
+
520
+ extern JS_PUBLIC_API(JSVersion)
521
+ JS_GetVersion(JSContext *cx);
522
+
523
+ extern JS_PUBLIC_API(JSVersion)
524
+ JS_SetVersion(JSContext *cx, JSVersion version);
525
+
526
+ extern JS_PUBLIC_API(const char *)
527
+ JS_VersionToString(JSVersion version);
528
+
529
+ extern JS_PUBLIC_API(JSVersion)
530
+ JS_StringToVersion(const char *string);
531
+
532
+ /*
533
+ * JS options are orthogonal to version, and may be freely composed with one
534
+ * another as well as with version.
535
+ *
536
+ * JSOPTION_VAROBJFIX is recommended -- see the comments associated with the
537
+ * prototypes for JS_ExecuteScript, JS_EvaluateScript, etc.
538
+ */
539
+ #define JSOPTION_STRICT JS_BIT(0) /* warn on dubious practice */
540
+ #define JSOPTION_WERROR JS_BIT(1) /* convert warning to error */
541
+ #define JSOPTION_VAROBJFIX JS_BIT(2) /* make JS_EvaluateScript use
542
+ the last object on its 'obj'
543
+ param's scope chain as the
544
+ ECMA 'variables object' */
545
+ #define JSOPTION_PRIVATE_IS_NSISUPPORTS \
546
+ JS_BIT(3) /* context private data points
547
+ to an nsISupports subclass */
548
+ #define JSOPTION_COMPILE_N_GO JS_BIT(4) /* caller of JS_Compile*Script
549
+ promises to execute compiled
550
+ script once only; enables
551
+ compile-time scope chain
552
+ resolution of consts. */
553
+ #define JSOPTION_ATLINE JS_BIT(5) /* //@line number ["filename"]
554
+ option supported for the
555
+ XUL preprocessor and kindred
556
+ beasts. */
557
+ #define JSOPTION_XML JS_BIT(6) /* EMCAScript for XML support:
558
+ parse <!-- --> as a token,
559
+ not backward compatible with
560
+ the comment-hiding hack used
561
+ in HTML script tags. */
562
+ #define JSOPTION_NATIVE_BRANCH_CALLBACK \
563
+ JS_BIT(7) /* the branch callback set by
564
+ JS_SetBranchCallback may be
565
+ called with a null script
566
+ parameter, by native code
567
+ that loops intensively.
568
+ Deprecated, use
569
+ JS_SetOperationCallback
570
+ instead */
571
+ #define JSOPTION_DONT_REPORT_UNCAUGHT \
572
+ JS_BIT(8) /* When returning from the
573
+ outermost API call, prevent
574
+ uncaught exceptions from
575
+ being converted to error
576
+ reports */
577
+
578
+ #define JSOPTION_RELIMIT JS_BIT(9) /* Throw exception on any
579
+ regular expression which
580
+ backtracks more than n^3
581
+ times, where n is length
582
+ of the input string */
583
+ #define JSOPTION_ANONFUNFIX JS_BIT(10) /* Disallow function () {} in
584
+ statement context per
585
+ ECMA-262 Edition 3. */
586
+
587
+ extern JS_PUBLIC_API(uint32)
588
+ JS_GetOptions(JSContext *cx);
589
+
590
+ extern JS_PUBLIC_API(uint32)
591
+ JS_SetOptions(JSContext *cx, uint32 options);
592
+
593
+ extern JS_PUBLIC_API(uint32)
594
+ JS_ToggleOptions(JSContext *cx, uint32 options);
595
+
596
+ extern JS_PUBLIC_API(const char *)
597
+ JS_GetImplementationVersion(void);
598
+
599
+ extern JS_PUBLIC_API(JSObject *)
600
+ JS_GetGlobalObject(JSContext *cx);
601
+
602
+ extern JS_PUBLIC_API(void)
603
+ JS_SetGlobalObject(JSContext *cx, JSObject *obj);
604
+
605
+ /*
606
+ * Initialize standard JS class constructors, prototypes, and any top-level
607
+ * functions and constants associated with the standard classes (e.g. isNaN
608
+ * for Number).
609
+ *
610
+ * NB: This sets cx's global object to obj if it was null.
611
+ */
612
+ extern JS_PUBLIC_API(JSBool)
613
+ JS_InitStandardClasses(JSContext *cx, JSObject *obj);
614
+
615
+ /*
616
+ * Resolve id, which must contain either a string or an int, to a standard
617
+ * class name in obj if possible, defining the class's constructor and/or
618
+ * prototype and storing true in *resolved. If id does not name a standard
619
+ * class or a top-level property induced by initializing a standard class,
620
+ * store false in *resolved and just return true. Return false on error,
621
+ * as usual for JSBool result-typed API entry points.
622
+ *
623
+ * This API can be called directly from a global object class's resolve op,
624
+ * to define standard classes lazily. The class's enumerate op should call
625
+ * JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in
626
+ * loops any classes not yet resolved lazily.
627
+ */
628
+ extern JS_PUBLIC_API(JSBool)
629
+ JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsval id,
630
+ JSBool *resolved);
631
+
632
+ extern JS_PUBLIC_API(JSBool)
633
+ JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj);
634
+
635
+ /*
636
+ * Enumerate any already-resolved standard class ids into ida, or into a new
637
+ * JSIdArray if ida is null. Return the augmented array on success, null on
638
+ * failure with ida (if it was non-null on entry) destroyed.
639
+ */
640
+ extern JS_PUBLIC_API(JSIdArray *)
641
+ JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj,
642
+ JSIdArray *ida);
643
+
644
+ extern JS_PUBLIC_API(JSBool)
645
+ JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
646
+ JSObject **objp);
647
+
648
+ extern JS_PUBLIC_API(JSObject *)
649
+ JS_GetScopeChain(JSContext *cx);
650
+
651
+ extern JS_PUBLIC_API(JSObject *)
652
+ JS_GetGlobalForObject(JSContext *cx, JSObject *obj);
653
+
654
+ /*
655
+ * Macros to hide interpreter stack layout details from a JSFastNative using
656
+ * its jsval *vp parameter. The stack layout underlying invocation can't change
657
+ * without breaking source and binary compatibility (argv[-2] is well-known to
658
+ * be the callee jsval, and argv[-1] is as well known to be |this|).
659
+ *
660
+ * Note well: However, argv[-1] may be JSVAL_NULL where with slow natives it
661
+ * is the global object, so embeddings implementing fast natives *must* call
662
+ * JS_THIS or JS_THIS_OBJECT and test for failure indicated by a null return,
663
+ * which should propagate as a false return from native functions and hooks.
664
+ *
665
+ * To reduce boilerplace checks, JS_InstanceOf and JS_GetInstancePrivate now
666
+ * handle a null obj parameter by returning false (throwing a TypeError if
667
+ * given non-null argv), so most native functions that type-check their |this|
668
+ * parameter need not add null checking.
669
+ *
670
+ * NB: there is an anti-dependency between JS_CALLEE and JS_SET_RVAL: native
671
+ * methods that may inspect their callee must defer setting their return value
672
+ * until after any such possible inspection. Otherwise the return value will be
673
+ * inspected instead of the callee function object.
674
+ *
675
+ * WARNING: These are not (yet) mandatory macros, but new code outside of the
676
+ * engine should use them. In the Mozilla 2.0 milestone their definitions may
677
+ * change incompatibly.
678
+ */
679
+ #define JS_CALLEE(cx,vp) ((vp)[0])
680
+ #define JS_ARGV_CALLEE(argv) ((argv)[-2])
681
+ #define JS_THIS(cx,vp) JS_ComputeThis(cx, vp)
682
+ #define JS_THIS_OBJECT(cx,vp) ((JSObject *) JS_THIS(cx,vp))
683
+ #define JS_ARGV(cx,vp) ((vp) + 2)
684
+ #define JS_RVAL(cx,vp) (*(vp))
685
+ #define JS_SET_RVAL(cx,vp,v) (*(vp) = (v))
686
+
687
+ extern JS_PUBLIC_API(jsval)
688
+ JS_ComputeThis(JSContext *cx, jsval *vp);
689
+
690
+ extern JS_PUBLIC_API(void *)
691
+ JS_malloc(JSContext *cx, size_t nbytes);
692
+
693
+ extern JS_PUBLIC_API(void *)
694
+ JS_realloc(JSContext *cx, void *p, size_t nbytes);
695
+
696
+ extern JS_PUBLIC_API(void)
697
+ JS_free(JSContext *cx, void *p);
698
+
699
+ extern JS_PUBLIC_API(char *)
700
+ JS_strdup(JSContext *cx, const char *s);
701
+
702
+ extern JS_PUBLIC_API(jsdouble *)
703
+ JS_NewDouble(JSContext *cx, jsdouble d);
704
+
705
+ extern JS_PUBLIC_API(JSBool)
706
+ JS_NewDoubleValue(JSContext *cx, jsdouble d, jsval *rval);
707
+
708
+ extern JS_PUBLIC_API(JSBool)
709
+ JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
710
+
711
+ /*
712
+ * A JS GC root is a pointer to a JSObject *, JSString *, or jsdouble * that
713
+ * itself points into the GC heap (more recently, we support this extension:
714
+ * a root may be a pointer to a jsval v for which JSVAL_IS_GCTHING(v) is true).
715
+ *
716
+ * Therefore, you never pass JSObject *obj to JS_AddRoot(cx, obj). You always
717
+ * call JS_AddRoot(cx, &obj), passing obj by reference. And later, before obj
718
+ * or the structure it is embedded within goes out of scope or is freed, you
719
+ * must call JS_RemoveRoot(cx, &obj).
720
+ *
721
+ * Also, use JS_AddNamedRoot(cx, &structPtr->memberObj, "structPtr->memberObj")
722
+ * in preference to JS_AddRoot(cx, &structPtr->memberObj), in order to identify
723
+ * roots by their source callsites. This way, you can find the callsite while
724
+ * debugging if you should fail to do JS_RemoveRoot(cx, &structPtr->memberObj)
725
+ * before freeing structPtr's memory.
726
+ */
727
+ extern JS_PUBLIC_API(JSBool)
728
+ JS_AddRoot(JSContext *cx, void *rp);
729
+
730
+ #ifdef NAME_ALL_GC_ROOTS
731
+ #define JS_DEFINE_TO_TOKEN(def) #def
732
+ #define JS_DEFINE_TO_STRING(def) JS_DEFINE_TO_TOKEN(def)
733
+ #define JS_AddRoot(cx,rp) JS_AddNamedRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
734
+ #endif
735
+
736
+ extern JS_PUBLIC_API(JSBool)
737
+ JS_AddNamedRoot(JSContext *cx, void *rp, const char *name);
738
+
739
+ extern JS_PUBLIC_API(JSBool)
740
+ JS_AddNamedRootRT(JSRuntime *rt, void *rp, const char *name);
741
+
742
+ extern JS_PUBLIC_API(JSBool)
743
+ JS_RemoveRoot(JSContext *cx, void *rp);
744
+
745
+ extern JS_PUBLIC_API(JSBool)
746
+ JS_RemoveRootRT(JSRuntime *rt, void *rp);
747
+
748
+ /*
749
+ * The last GC thing of each type (object, string, double, external string
750
+ * types) created on a given context is kept alive until another thing of the
751
+ * same type is created, using a newborn root in the context. These newborn
752
+ * roots help native code protect newly-created GC-things from GC invocations
753
+ * activated before those things can be rooted using local or global roots.
754
+ *
755
+ * However, the newborn roots can also entrain great gobs of garbage, so the
756
+ * JS_GC entry point clears them for the context on which GC is being forced.
757
+ * Embeddings may need to do likewise for all contexts.
758
+ *
759
+ * See the scoped local root API immediately below for a better way to manage
760
+ * newborns in cases where native hooks (functions, getters, setters, etc.)
761
+ * create many GC-things, potentially without connecting them to predefined
762
+ * local roots such as *rval or argv[i] in an active native function. Using
763
+ * JS_EnterLocalRootScope disables updating of the context's per-gc-thing-type
764
+ * newborn roots, until control flow unwinds and leaves the outermost nesting
765
+ * local root scope.
766
+ */
767
+ extern JS_PUBLIC_API(void)
768
+ JS_ClearNewbornRoots(JSContext *cx);
769
+
770
+ /*
771
+ * Scoped local root management allows native functions, getter/setters, etc.
772
+ * to avoid worrying about the newborn root pigeon-holes, overloading local
773
+ * roots allocated in argv and *rval, or ending up having to call JS_Add*Root
774
+ * and JS_RemoveRoot to manage global roots temporarily.
775
+ *
776
+ * Instead, calling JS_EnterLocalRootScope and JS_LeaveLocalRootScope around
777
+ * the body of the native hook causes the engine to allocate a local root for
778
+ * each newborn created in between the two API calls, using a local root stack
779
+ * associated with cx. For example:
780
+ *
781
+ * JSBool
782
+ * my_GetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
783
+ * {
784
+ * JSBool ok;
785
+ *
786
+ * if (!JS_EnterLocalRootScope(cx))
787
+ * return JS_FALSE;
788
+ * ok = my_GetPropertyBody(cx, obj, id, vp);
789
+ * JS_LeaveLocalRootScope(cx);
790
+ * return ok;
791
+ * }
792
+ *
793
+ * NB: JS_LeaveLocalRootScope must be called once for every prior successful
794
+ * call to JS_EnterLocalRootScope. If JS_EnterLocalRootScope fails, you must
795
+ * not make the matching JS_LeaveLocalRootScope call.
796
+ *
797
+ * JS_LeaveLocalRootScopeWithResult(cx, rval) is an alternative way to leave
798
+ * a local root scope that protects a result or return value, by effectively
799
+ * pushing it in the caller's local root scope.
800
+ *
801
+ * In case a native hook allocates many objects or other GC-things, but the
802
+ * native protects some of those GC-things by storing them as property values
803
+ * in an object that is itself protected, the hook can call JS_ForgetLocalRoot
804
+ * to free the local root automatically pushed for the now-protected GC-thing.
805
+ *
806
+ * JS_ForgetLocalRoot works on any GC-thing allocated in the current local
807
+ * root scope, but it's more time-efficient when called on references to more
808
+ * recently created GC-things. Calling it successively on other than the most
809
+ * recently allocated GC-thing will tend to average the time inefficiency, and
810
+ * may risk O(n^2) growth rate, but in any event, you shouldn't allocate too
811
+ * many local roots if you can root as you go (build a tree of objects from
812
+ * the top down, forgetting each latest-allocated GC-thing immediately upon
813
+ * linking it to its parent).
814
+ */
815
+ extern JS_PUBLIC_API(JSBool)
816
+ JS_EnterLocalRootScope(JSContext *cx);
817
+
818
+ extern JS_PUBLIC_API(void)
819
+ JS_LeaveLocalRootScope(JSContext *cx);
820
+
821
+ extern JS_PUBLIC_API(void)
822
+ JS_LeaveLocalRootScopeWithResult(JSContext *cx, jsval rval);
823
+
824
+ extern JS_PUBLIC_API(void)
825
+ JS_ForgetLocalRoot(JSContext *cx, void *thing);
826
+
827
+ #ifdef __cplusplus
828
+ JS_END_EXTERN_C
829
+
830
+ class JSAutoLocalRootScope {
831
+ public:
832
+ JSAutoLocalRootScope(JSContext *cx) : mContext(cx) {
833
+ JS_EnterLocalRootScope(mContext);
834
+ }
835
+ ~JSAutoLocalRootScope() {
836
+ JS_LeaveLocalRootScope(mContext);
837
+ }
838
+
839
+ void forget(void *thing) {
840
+ JS_ForgetLocalRoot(mContext, thing);
841
+ }
842
+
843
+ protected:
844
+ JSContext *mContext;
845
+
846
+ #if 0
847
+ private:
848
+ static void *operator new(size_t) CPP_THROW_NEW { return 0; };
849
+ static void operator delete(void *, size_t) { };
850
+ #endif
851
+ };
852
+
853
+ JS_BEGIN_EXTERN_C
854
+ #endif
855
+
856
+ #ifdef DEBUG
857
+ extern JS_PUBLIC_API(void)
858
+ JS_DumpNamedRoots(JSRuntime *rt,
859
+ void (*dump)(const char *name, void *rp, void *data),
860
+ void *data);
861
+ #endif
862
+
863
+ /*
864
+ * Call JS_MapGCRoots to map the GC's roots table using map(rp, name, data).
865
+ * The root is pointed at by rp; if the root is unnamed, name is null; data is
866
+ * supplied from the third parameter to JS_MapGCRoots.
867
+ *
868
+ * The map function should return JS_MAP_GCROOT_REMOVE to cause the currently
869
+ * enumerated root to be removed. To stop enumeration, set JS_MAP_GCROOT_STOP
870
+ * in the return value. To keep on mapping, return JS_MAP_GCROOT_NEXT. These
871
+ * constants are flags; you can OR them together.
872
+ *
873
+ * This function acquires and releases rt's GC lock around the mapping of the
874
+ * roots table, so the map function should run to completion in as few cycles
875
+ * as possible. Of course, map cannot call JS_GC, JS_MaybeGC, JS_BeginRequest,
876
+ * or any JS API entry point that acquires locks, without double-tripping or
877
+ * deadlocking on the GC lock.
878
+ *
879
+ * JS_MapGCRoots returns the count of roots that were successfully mapped.
880
+ */
881
+ #define JS_MAP_GCROOT_NEXT 0 /* continue mapping entries */
882
+ #define JS_MAP_GCROOT_STOP 1 /* stop mapping entries */
883
+ #define JS_MAP_GCROOT_REMOVE 2 /* remove and free the current entry */
884
+
885
+ typedef intN
886
+ (* JS_DLL_CALLBACK JSGCRootMapFun)(void *rp, const char *name, void *data);
887
+
888
+ extern JS_PUBLIC_API(uint32)
889
+ JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data);
890
+
891
+ extern JS_PUBLIC_API(JSBool)
892
+ JS_LockGCThing(JSContext *cx, void *thing);
893
+
894
+ extern JS_PUBLIC_API(JSBool)
895
+ JS_LockGCThingRT(JSRuntime *rt, void *thing);
896
+
897
+ extern JS_PUBLIC_API(JSBool)
898
+ JS_UnlockGCThing(JSContext *cx, void *thing);
899
+
900
+ extern JS_PUBLIC_API(JSBool)
901
+ JS_UnlockGCThingRT(JSRuntime *rt, void *thing);
902
+
903
+ /*
904
+ * Register externally maintained GC roots.
905
+ *
906
+ * traceOp: the trace operation. For each root the implementation should call
907
+ * JS_CallTracer whenever the root contains a traceable thing.
908
+ * data: the data argument to pass to each invocation of traceOp.
909
+ */
910
+ extern JS_PUBLIC_API(void)
911
+ JS_SetExtraGCRoots(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
912
+
913
+ /*
914
+ * For implementors of JSMarkOp. All new code should implement JSTraceOp
915
+ * instead.
916
+ */
917
+ extern JS_PUBLIC_API(void)
918
+ JS_MarkGCThing(JSContext *cx, void *thing, const char *name, void *arg);
919
+
920
+ /*
921
+ * JS_CallTracer API and related macros for implementors of JSTraceOp, to
922
+ * enumerate all references to traceable things reachable via a property or
923
+ * other strong ref identified for debugging purposes by name or index or
924
+ * a naming callback.
925
+ *
926
+ * By definition references to traceable things include non-null pointers
927
+ * to JSObject, JSString and jsdouble and corresponding jsvals.
928
+ *
929
+ * See the JSTraceOp typedef in jspubtd.h.
930
+ */
931
+
932
+ /* Trace kinds to pass to JS_Tracing. */
933
+ #define JSTRACE_OBJECT 0
934
+ #define JSTRACE_DOUBLE 1
935
+ #define JSTRACE_STRING 2
936
+
937
+ /*
938
+ * Use the following macros to check if a particular jsval is a traceable
939
+ * thing and to extract the thing and its kind to pass to JS_CallTracer.
940
+ */
941
+ #define JSVAL_IS_TRACEABLE(v) (JSVAL_IS_GCTHING(v) && !JSVAL_IS_NULL(v))
942
+ #define JSVAL_TO_TRACEABLE(v) (JSVAL_TO_GCTHING(v))
943
+ #define JSVAL_TRACE_KIND(v) (JSVAL_TAG(v) >> 1)
944
+
945
+ JS_STATIC_ASSERT(JSVAL_TRACE_KIND(JSVAL_OBJECT) == JSTRACE_OBJECT);
946
+ JS_STATIC_ASSERT(JSVAL_TRACE_KIND(JSVAL_DOUBLE) == JSTRACE_DOUBLE);
947
+ JS_STATIC_ASSERT(JSVAL_TRACE_KIND(JSVAL_STRING) == JSTRACE_STRING);
948
+
949
+ struct JSTracer {
950
+ JSContext *context;
951
+ JSTraceCallback callback;
952
+ #ifdef DEBUG
953
+ JSTraceNamePrinter debugPrinter;
954
+ const void *debugPrintArg;
955
+ size_t debugPrintIndex;
956
+ #endif
957
+ };
958
+
959
+ /*
960
+ * The method to call on each reference to a traceable thing stored in a
961
+ * particular JSObject or other runtime structure. With DEBUG defined the
962
+ * caller before calling JS_CallTracer must initialize JSTracer fields
963
+ * describing the reference using the macros below.
964
+ */
965
+ extern JS_PUBLIC_API(void)
966
+ JS_CallTracer(JSTracer *trc, void *thing, uint32 kind);
967
+
968
+ /*
969
+ * Set debugging information about a reference to a traceable thing to prepare
970
+ * for the following call to JS_CallTracer.
971
+ *
972
+ * When printer is null, arg must be const char * or char * C string naming
973
+ * the reference and index must be either (size_t)-1 indicating that the name
974
+ * alone describes the reference or it must be an index into some array vector
975
+ * that stores the reference.
976
+ *
977
+ * When printer callback is not null, the arg and index arguments are
978
+ * available to the callback as debugPrinterArg and debugPrintIndex fields
979
+ * of JSTracer.
980
+ *
981
+ * The storage for name or callback's arguments needs to live only until
982
+ * the following call to JS_CallTracer returns.
983
+ */
984
+ #ifdef DEBUG
985
+ # define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \
986
+ JS_BEGIN_MACRO \
987
+ (trc)->debugPrinter = (printer); \
988
+ (trc)->debugPrintArg = (arg); \
989
+ (trc)->debugPrintIndex = (index); \
990
+ JS_END_MACRO
991
+ #else
992
+ # define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \
993
+ JS_BEGIN_MACRO \
994
+ JS_END_MACRO
995
+ #endif
996
+
997
+ /*
998
+ * Convenience macro to describe the argument of JS_CallTracer using C string
999
+ * and index.
1000
+ */
1001
+ # define JS_SET_TRACING_INDEX(trc, name, index) \
1002
+ JS_SET_TRACING_DETAILS(trc, NULL, name, index)
1003
+
1004
+ /*
1005
+ * Convenience macro to describe the argument of JS_CallTracer using C string.
1006
+ */
1007
+ # define JS_SET_TRACING_NAME(trc, name) \
1008
+ JS_SET_TRACING_DETAILS(trc, NULL, name, (size_t)-1)
1009
+
1010
+ /*
1011
+ * Convenience macro to invoke JS_CallTracer using C string as the name for
1012
+ * the reference to a traceable thing.
1013
+ */
1014
+ # define JS_CALL_TRACER(trc, thing, kind, name) \
1015
+ JS_BEGIN_MACRO \
1016
+ JS_SET_TRACING_NAME(trc, name); \
1017
+ JS_CallTracer((trc), (thing), (kind)); \
1018
+ JS_END_MACRO
1019
+
1020
+ /*
1021
+ * Convenience macros to invoke JS_CallTracer when jsval represents a
1022
+ * reference to a traceable thing.
1023
+ */
1024
+ #define JS_CALL_VALUE_TRACER(trc, val, name) \
1025
+ JS_BEGIN_MACRO \
1026
+ if (JSVAL_IS_TRACEABLE(val)) { \
1027
+ JS_CALL_TRACER((trc), JSVAL_TO_GCTHING(val), \
1028
+ JSVAL_TRACE_KIND(val), name); \
1029
+ } \
1030
+ JS_END_MACRO
1031
+
1032
+ #define JS_CALL_OBJECT_TRACER(trc, object, name) \
1033
+ JS_BEGIN_MACRO \
1034
+ JSObject *obj_ = (object); \
1035
+ JS_ASSERT(obj_); \
1036
+ JS_CALL_TRACER((trc), obj_, JSTRACE_OBJECT, name); \
1037
+ JS_END_MACRO
1038
+
1039
+ #define JS_CALL_STRING_TRACER(trc, string, name) \
1040
+ JS_BEGIN_MACRO \
1041
+ JSString *str_ = (string); \
1042
+ JS_ASSERT(str_); \
1043
+ JS_CALL_TRACER((trc), str_, JSTRACE_STRING, name); \
1044
+ JS_END_MACRO
1045
+
1046
+ #define JS_CALL_DOUBLE_TRACER(trc, number, name) \
1047
+ JS_BEGIN_MACRO \
1048
+ jsdouble *num_ = (number); \
1049
+ JS_ASSERT(num_); \
1050
+ JS_CALL_TRACER((trc), num_, JSTRACE_DOUBLE, name); \
1051
+ JS_END_MACRO
1052
+
1053
+ /*
1054
+ * API for JSTraceCallback implementations.
1055
+ */
1056
+ # define JS_TRACER_INIT(trc, cx_, callback_) \
1057
+ JS_BEGIN_MACRO \
1058
+ (trc)->context = (cx_); \
1059
+ (trc)->callback = (callback_); \
1060
+ JS_SET_TRACING_DETAILS(trc, NULL, NULL, (size_t)-1); \
1061
+ JS_END_MACRO
1062
+
1063
+ extern JS_PUBLIC_API(void)
1064
+ JS_TraceChildren(JSTracer *trc, void *thing, uint32 kind);
1065
+
1066
+ extern JS_PUBLIC_API(void)
1067
+ JS_TraceRuntime(JSTracer *trc);
1068
+
1069
+ #ifdef DEBUG
1070
+
1071
+ extern JS_PUBLIC_API(void)
1072
+ JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
1073
+ void *thing, uint32 kind, JSBool includeDetails);
1074
+
1075
+ /*
1076
+ * DEBUG-only method to dump the object graph of heap-allocated things.
1077
+ *
1078
+ * fp: file for the dump output.
1079
+ * start: when non-null, dump only things reachable from start
1080
+ * thing. Otherwise dump all things reachable from the
1081
+ * runtime roots.
1082
+ * startKind: trace kind of start if start is not null. Must be 0 when
1083
+ * start is null.
1084
+ * thingToFind: dump only paths in the object graph leading to thingToFind
1085
+ * when non-null.
1086
+ * maxDepth: the upper bound on the number of edges to descend from the
1087
+ * graph roots.
1088
+ * thingToIgnore: thing to ignore during the graph traversal when non-null.
1089
+ */
1090
+ extern JS_PUBLIC_API(JSBool)
1091
+ JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
1092
+ void *thingToFind, size_t maxDepth, void *thingToIgnore);
1093
+
1094
+ #endif
1095
+
1096
+ /*
1097
+ * Garbage collector API.
1098
+ */
1099
+ extern JS_PUBLIC_API(void)
1100
+ JS_GC(JSContext *cx);
1101
+
1102
+ extern JS_PUBLIC_API(void)
1103
+ JS_MaybeGC(JSContext *cx);
1104
+
1105
+ extern JS_PUBLIC_API(JSGCCallback)
1106
+ JS_SetGCCallback(JSContext *cx, JSGCCallback cb);
1107
+
1108
+ extern JS_PUBLIC_API(JSGCCallback)
1109
+ JS_SetGCCallbackRT(JSRuntime *rt, JSGCCallback cb);
1110
+
1111
+ extern JS_PUBLIC_API(JSBool)
1112
+ JS_IsGCMarkingTracer(JSTracer *trc);
1113
+
1114
+ extern JS_PUBLIC_API(JSBool)
1115
+ JS_IsAboutToBeFinalized(JSContext *cx, void *thing);
1116
+
1117
+ typedef enum JSGCParamKey {
1118
+ /* Maximum nominal heap before last ditch GC. */
1119
+ JSGC_MAX_BYTES = 0,
1120
+
1121
+ /* Number of JS_malloc bytes before last ditch GC. */
1122
+ JSGC_MAX_MALLOC_BYTES = 1,
1123
+
1124
+ /* Hoard stackPools for this long, in ms, default is 30 seconds. */
1125
+ JSGC_STACKPOOL_LIFESPAN = 2
1126
+ } JSGCParamKey;
1127
+
1128
+ extern JS_PUBLIC_API(void)
1129
+ JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32 value);
1130
+
1131
+ /*
1132
+ * Add a finalizer for external strings created by JS_NewExternalString (see
1133
+ * below) using a type-code returned from this function, and that understands
1134
+ * how to free or release the memory pointed at by JS_GetStringChars(str).
1135
+ *
1136
+ * Return a nonnegative type index if there is room for finalizer in the
1137
+ * global GC finalizers table, else return -1. If the engine is compiled
1138
+ * JS_THREADSAFE and used in a multi-threaded environment, this function must
1139
+ * be invoked on the primordial thread only, at startup -- or else the entire
1140
+ * program must single-thread itself while loading a module that calls this
1141
+ * function.
1142
+ */
1143
+ extern JS_PUBLIC_API(intN)
1144
+ JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer);
1145
+
1146
+ /*
1147
+ * Remove finalizer from the global GC finalizers table, returning its type
1148
+ * code if found, -1 if not found.
1149
+ *
1150
+ * As with JS_AddExternalStringFinalizer, there is a threading restriction
1151
+ * if you compile the engine JS_THREADSAFE: this function may be called for a
1152
+ * given finalizer pointer on only one thread; different threads may call to
1153
+ * remove distinct finalizers safely.
1154
+ *
1155
+ * You must ensure that all strings with finalizer's type have been collected
1156
+ * before calling this function. Otherwise, string data will be leaked by the
1157
+ * GC, for want of a finalizer to call.
1158
+ */
1159
+ extern JS_PUBLIC_API(intN)
1160
+ JS_RemoveExternalStringFinalizer(JSStringFinalizeOp finalizer);
1161
+
1162
+ /*
1163
+ * Create a new JSString whose chars member refers to external memory, i.e.,
1164
+ * memory requiring special, type-specific finalization. The type code must
1165
+ * be a nonnegative return value from JS_AddExternalStringFinalizer.
1166
+ */
1167
+ extern JS_PUBLIC_API(JSString *)
1168
+ JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type);
1169
+
1170
+ /*
1171
+ * Returns the external-string finalizer index for this string, or -1 if it is
1172
+ * an "internal" (native to JS engine) string.
1173
+ */
1174
+ extern JS_PUBLIC_API(intN)
1175
+ JS_GetExternalStringGCType(JSRuntime *rt, JSString *str);
1176
+
1177
+ /*
1178
+ * Sets maximum (if stack grows upward) or minimum (downward) legal stack byte
1179
+ * address in limitAddr for the thread or process stack used by cx. To disable
1180
+ * stack size checking, pass 0 for limitAddr.
1181
+ */
1182
+ extern JS_PUBLIC_API(void)
1183
+ JS_SetThreadStackLimit(JSContext *cx, jsuword limitAddr);
1184
+
1185
+ /*
1186
+ * Set the quota on the number of bytes that stack-like data structures can
1187
+ * use when the runtime compiles and executes scripts. These structures
1188
+ * consume heap space, so JS_SetThreadStackLimit does not bound their size.
1189
+ * The default quota is 32MB which is quite generous.
1190
+ *
1191
+ * The function must be called before any script compilation or execution API
1192
+ * calls, i.e. either immediately after JS_NewContext or from JSCONTEXT_NEW
1193
+ * context callback.
1194
+ */
1195
+ extern JS_PUBLIC_API(void)
1196
+ JS_SetScriptStackQuota(JSContext *cx, size_t quota);
1197
+
1198
+ #define JS_DEFAULT_SCRIPT_STACK_QUOTA ((size_t) 0x2000000)
1199
+
1200
+ /************************************************************************/
1201
+
1202
+ /*
1203
+ * Classes, objects, and properties.
1204
+ */
1205
+
1206
+ /* For detailed comments on the function pointer types, see jspubtd.h. */
1207
+ struct JSClass {
1208
+ const char *name;
1209
+ uint32 flags;
1210
+
1211
+ /* Mandatory non-null function pointer members. */
1212
+ JSPropertyOp addProperty;
1213
+ JSPropertyOp delProperty;
1214
+ JSPropertyOp getProperty;
1215
+ JSPropertyOp setProperty;
1216
+ JSEnumerateOp enumerate;
1217
+ JSResolveOp resolve;
1218
+ JSConvertOp convert;
1219
+ JSFinalizeOp finalize;
1220
+
1221
+ /* Optionally non-null members start here. */
1222
+ JSGetObjectOps getObjectOps;
1223
+ JSCheckAccessOp checkAccess;
1224
+ JSNative call;
1225
+ JSNative construct;
1226
+ JSXDRObjectOp xdrObject;
1227
+ JSHasInstanceOp hasInstance;
1228
+ JSMarkOp mark;
1229
+ JSReserveSlotsOp reserveSlots;
1230
+ };
1231
+
1232
+ struct JSExtendedClass {
1233
+ JSClass base;
1234
+ JSEqualityOp equality;
1235
+ JSObjectOp outerObject;
1236
+ JSObjectOp innerObject;
1237
+ JSIteratorOp iteratorObject;
1238
+ JSObjectOp wrappedObject; /* NB: infallible, null
1239
+ returns are treated as
1240
+ the original object */
1241
+ void (*reserved0)(void);
1242
+ void (*reserved1)(void);
1243
+ void (*reserved2)(void);
1244
+ };
1245
+
1246
+ #define JSCLASS_HAS_PRIVATE (1<<0) /* objects have private slot */
1247
+ #define JSCLASS_NEW_ENUMERATE (1<<1) /* has JSNewEnumerateOp hook */
1248
+ #define JSCLASS_NEW_RESOLVE (1<<2) /* has JSNewResolveOp hook */
1249
+ #define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) /* private is (nsISupports *) */
1250
+ #define JSCLASS_SHARE_ALL_PROPERTIES (1<<4) /* all properties are SHARED */
1251
+ #define JSCLASS_NEW_RESOLVE_GETS_START (1<<5) /* JSNewResolveOp gets starting
1252
+ object in prototype chain
1253
+ passed in via *objp in/out
1254
+ parameter */
1255
+ #define JSCLASS_CONSTRUCT_PROTOTYPE (1<<6) /* call constructor on class
1256
+ prototype */
1257
+ #define JSCLASS_DOCUMENT_OBSERVER (1<<7) /* DOM document observer */
1258
+
1259
+ /*
1260
+ * To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or
1261
+ * JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where
1262
+ * n is a constant in [1, 255]. Reserved slots are indexed from 0 to n-1.
1263
+ */
1264
+ #define JSCLASS_RESERVED_SLOTS_SHIFT 8 /* room for 8 flags below */
1265
+ #define JSCLASS_RESERVED_SLOTS_WIDTH 8 /* and 16 above this field */
1266
+ #define JSCLASS_RESERVED_SLOTS_MASK JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH)
1267
+ #define JSCLASS_HAS_RESERVED_SLOTS(n) (((n) & JSCLASS_RESERVED_SLOTS_MASK) \
1268
+ << JSCLASS_RESERVED_SLOTS_SHIFT)
1269
+ #define JSCLASS_RESERVED_SLOTS(clasp) (((clasp)->flags \
1270
+ >> JSCLASS_RESERVED_SLOTS_SHIFT) \
1271
+ & JSCLASS_RESERVED_SLOTS_MASK)
1272
+
1273
+ #define JSCLASS_HIGH_FLAGS_SHIFT (JSCLASS_RESERVED_SLOTS_SHIFT + \
1274
+ JSCLASS_RESERVED_SLOTS_WIDTH)
1275
+
1276
+ /* True if JSClass is really a JSExtendedClass. */
1277
+ #define JSCLASS_IS_EXTENDED (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0))
1278
+ #define JSCLASS_IS_ANONYMOUS (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1))
1279
+ #define JSCLASS_IS_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2))
1280
+
1281
+ /* Indicates that JSClass.mark is a tracer with JSTraceOp type. */
1282
+ #define JSCLASS_MARK_IS_TRACE (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3))
1283
+
1284
+ /*
1285
+ * ECMA-262 requires that most constructors used internally create objects
1286
+ * with "the original Foo.prototype value" as their [[Prototype]] (__proto__)
1287
+ * member initial value. The "original ... value" verbiage is there because
1288
+ * in ECMA-262, global properties naming class objects are read/write and
1289
+ * deleteable, for the most part.
1290
+ *
1291
+ * Implementing this efficiently requires that global objects have classes
1292
+ * with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS won't break
1293
+ * anything except the ECMA-262 "original prototype value" behavior, which was
1294
+ * broken for years in SpiderMonkey. In other words, without these flags you
1295
+ * get backward compatibility.
1296
+ */
1297
+ #define JSCLASS_GLOBAL_FLAGS \
1298
+ (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSProto_LIMIT))
1299
+
1300
+ /* Fast access to the original value of each standard class's prototype. */
1301
+ #define JSCLASS_CACHED_PROTO_SHIFT (JSCLASS_HIGH_FLAGS_SHIFT + 8)
1302
+ #define JSCLASS_CACHED_PROTO_WIDTH 8
1303
+ #define JSCLASS_CACHED_PROTO_MASK JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH)
1304
+ #define JSCLASS_HAS_CACHED_PROTO(key) ((key) << JSCLASS_CACHED_PROTO_SHIFT)
1305
+ #define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey) \
1306
+ (((clasp)->flags \
1307
+ >> JSCLASS_CACHED_PROTO_SHIFT) \
1308
+ & JSCLASS_CACHED_PROTO_MASK))
1309
+
1310
+ /* Initializer for unused members of statically initialized JSClass structs. */
1311
+ #define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,0,0,0
1312
+ #define JSCLASS_NO_RESERVED_MEMBERS 0,0,0
1313
+
1314
+ /* For detailed comments on these function pointer types, see jspubtd.h. */
1315
+ struct JSObjectOps {
1316
+ /* Mandatory non-null function pointer members. */
1317
+ JSNewObjectMapOp newObjectMap;
1318
+ JSObjectMapOp destroyObjectMap;
1319
+ JSLookupPropOp lookupProperty;
1320
+ JSDefinePropOp defineProperty;
1321
+ JSPropertyIdOp getProperty;
1322
+ JSPropertyIdOp setProperty;
1323
+ JSAttributesOp getAttributes;
1324
+ JSAttributesOp setAttributes;
1325
+ JSPropertyIdOp deleteProperty;
1326
+ JSConvertOp defaultValue;
1327
+ JSNewEnumerateOp enumerate;
1328
+ JSCheckAccessIdOp checkAccess;
1329
+
1330
+ /* Optionally non-null members start here. */
1331
+ JSObjectOp thisObject;
1332
+ JSPropertyRefOp dropProperty;
1333
+ JSNative call;
1334
+ JSNative construct;
1335
+ JSXDRObjectOp xdrObject;
1336
+ JSHasInstanceOp hasInstance;
1337
+ JSSetObjectSlotOp setProto;
1338
+ JSSetObjectSlotOp setParent;
1339
+ JSTraceOp trace;
1340
+ JSFinalizeOp clear;
1341
+ JSGetRequiredSlotOp getRequiredSlot;
1342
+ JSSetRequiredSlotOp setRequiredSlot;
1343
+ };
1344
+
1345
+ struct JSXMLObjectOps {
1346
+ JSObjectOps base;
1347
+ JSGetMethodOp getMethod;
1348
+ JSSetMethodOp setMethod;
1349
+ JSEnumerateValuesOp enumerateValues;
1350
+ JSEqualityOp equality;
1351
+ JSConcatenateOp concatenate;
1352
+ };
1353
+
1354
+ /*
1355
+ * Classes that expose JSObjectOps via a non-null getObjectOps class hook may
1356
+ * derive a property structure from this struct, return a pointer to it from
1357
+ * lookupProperty and defineProperty, and use the pointer to avoid rehashing
1358
+ * in getAttributes and setAttributes.
1359
+ *
1360
+ * The jsid type contains either an int jsval (see JSVAL_IS_INT above), or an
1361
+ * internal pointer that is opaque to users of this API, but which users may
1362
+ * convert from and to a jsval using JS_ValueToId and JS_IdToValue.
1363
+ */
1364
+ struct JSProperty {
1365
+ jsid id;
1366
+ };
1367
+
1368
+ struct JSIdArray {
1369
+ jsint length;
1370
+ jsid vector[1]; /* actually, length jsid words */
1371
+ };
1372
+
1373
+ extern JS_PUBLIC_API(void)
1374
+ JS_DestroyIdArray(JSContext *cx, JSIdArray *ida);
1375
+
1376
+ extern JS_PUBLIC_API(JSBool)
1377
+ JS_ValueToId(JSContext *cx, jsval v, jsid *idp);
1378
+
1379
+ extern JS_PUBLIC_API(JSBool)
1380
+ JS_IdToValue(JSContext *cx, jsid id, jsval *vp);
1381
+
1382
+ /*
1383
+ * The magic XML namespace id is int-tagged, but not a valid integer jsval.
1384
+ * Global object classes in embeddings that enable JS_HAS_XML_SUPPORT (E4X)
1385
+ * should handle this id specially before converting id via JSVAL_TO_INT.
1386
+ */
1387
+ #define JS_DEFAULT_XML_NAMESPACE_ID ((jsid) JSVAL_VOID)
1388
+
1389
+ /*
1390
+ * JSNewResolveOp flag bits.
1391
+ */
1392
+ #define JSRESOLVE_QUALIFIED 0x01 /* resolve a qualified property id */
1393
+ #define JSRESOLVE_ASSIGNING 0x02 /* resolve on the left of assignment */
1394
+ #define JSRESOLVE_DETECTING 0x04 /* 'if (o.p)...' or '(o.p) ?...:...' */
1395
+ #define JSRESOLVE_DECLARING 0x08 /* var, const, or function prolog op */
1396
+ #define JSRESOLVE_CLASSNAME 0x10 /* class name used when constructing */
1397
+
1398
+ extern JS_PUBLIC_API(JSBool)
1399
+ JS_PropertyStub(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
1400
+
1401
+ extern JS_PUBLIC_API(JSBool)
1402
+ JS_EnumerateStub(JSContext *cx, JSObject *obj);
1403
+
1404
+ extern JS_PUBLIC_API(JSBool)
1405
+ JS_ResolveStub(JSContext *cx, JSObject *obj, jsval id);
1406
+
1407
+ extern JS_PUBLIC_API(JSBool)
1408
+ JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
1409
+
1410
+ extern JS_PUBLIC_API(void)
1411
+ JS_FinalizeStub(JSContext *cx, JSObject *obj);
1412
+
1413
+ struct JSConstDoubleSpec {
1414
+ jsdouble dval;
1415
+ const char *name;
1416
+ uint8 flags;
1417
+ uint8 spare[3];
1418
+ };
1419
+
1420
+ /*
1421
+ * To define an array element rather than a named property member, cast the
1422
+ * element's index to (const char *) and initialize name with it, and set the
1423
+ * JSPROP_INDEX bit in flags.
1424
+ */
1425
+ struct JSPropertySpec {
1426
+ const char *name;
1427
+ int8 tinyid;
1428
+ uint8 flags;
1429
+ JSPropertyOp getter;
1430
+ JSPropertyOp setter;
1431
+ };
1432
+
1433
+ struct JSFunctionSpec {
1434
+ const char *name;
1435
+ JSNative call;
1436
+ #ifdef MOZILLA_1_8_BRANCH
1437
+ uint8 nargs;
1438
+ uint8 flags;
1439
+ uint16 extra;
1440
+ #else
1441
+ uint16 nargs;
1442
+ uint16 flags;
1443
+
1444
+ /*
1445
+ * extra & 0xFFFF: Number of extra argument slots for local GC roots.
1446
+ * If fast native, must be zero.
1447
+ * extra >> 16: If slow native, reserved for future use (must be 0).
1448
+ * If fast native, minimum required argc.
1449
+ */
1450
+ uint32 extra;
1451
+ #endif
1452
+ };
1453
+
1454
+ /*
1455
+ * Terminating sentinel initializer to put at the end of a JSFunctionSpec array
1456
+ * that's passed to JS_DefineFunctions or JS_InitClass.
1457
+ */
1458
+ #define JS_FS_END JS_FS(NULL,NULL,0,0,0)
1459
+
1460
+ /*
1461
+ * Initializer macro for a JSFunctionSpec array element. This is the original
1462
+ * kind of native function specifier initializer. Use JS_FN ("fast native", see
1463
+ * JSFastNative in jspubtd.h) for all functions that do not need a stack frame
1464
+ * when activated.
1465
+ */
1466
+ #define JS_FS(name,call,nargs,flags,extra) \
1467
+ {name, call, nargs, flags, extra}
1468
+
1469
+ /*
1470
+ * "Fast native" initializer macro for a JSFunctionSpec array element. Use this
1471
+ * in preference to JS_FS if the native in question does not need its own stack
1472
+ * frame when activated.
1473
+ */
1474
+ #define JS_FN(name,fastcall,minargs,nargs,flags) \
1475
+ {name, (JSNative)(fastcall), nargs, \
1476
+ (flags) | JSFUN_FAST_NATIVE | JSFUN_STUB_GSOPS, \
1477
+ (minargs) << 16}
1478
+
1479
+ extern JS_PUBLIC_API(JSObject *)
1480
+ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
1481
+ JSClass *clasp, JSNative constructor, uintN nargs,
1482
+ JSPropertySpec *ps, JSFunctionSpec *fs,
1483
+ JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
1484
+
1485
+ #ifdef JS_THREADSAFE
1486
+ extern JS_PUBLIC_API(JSClass *)
1487
+ JS_GetClass(JSContext *cx, JSObject *obj);
1488
+
1489
+ #define JS_GET_CLASS(cx,obj) JS_GetClass(cx, obj)
1490
+ #else
1491
+ extern JS_PUBLIC_API(JSClass *)
1492
+ JS_GetClass(JSObject *obj);
1493
+
1494
+ #define JS_GET_CLASS(cx,obj) JS_GetClass(obj)
1495
+ #endif
1496
+
1497
+ extern JS_PUBLIC_API(JSBool)
1498
+ JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
1499
+
1500
+ extern JS_PUBLIC_API(JSBool)
1501
+ JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
1502
+
1503
+ extern JS_PUBLIC_API(void *)
1504
+ JS_GetPrivate(JSContext *cx, JSObject *obj);
1505
+
1506
+ extern JS_PUBLIC_API(JSBool)
1507
+ JS_SetPrivate(JSContext *cx, JSObject *obj, void *data);
1508
+
1509
+ extern JS_PUBLIC_API(void *)
1510
+ JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
1511
+ jsval *argv);
1512
+
1513
+ extern JS_PUBLIC_API(JSObject *)
1514
+ JS_GetPrototype(JSContext *cx, JSObject *obj);
1515
+
1516
+ extern JS_PUBLIC_API(JSBool)
1517
+ JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
1518
+
1519
+ extern JS_PUBLIC_API(JSObject *)
1520
+ JS_GetParent(JSContext *cx, JSObject *obj);
1521
+
1522
+ extern JS_PUBLIC_API(JSBool)
1523
+ JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent);
1524
+
1525
+ extern JS_PUBLIC_API(JSObject *)
1526
+ JS_GetConstructor(JSContext *cx, JSObject *proto);
1527
+
1528
+ /*
1529
+ * Get a unique identifier for obj, good for the lifetime of obj (even if it
1530
+ * is moved by a copying GC). Return false on failure (likely out of memory),
1531
+ * and true with *idp containing the unique id on success.
1532
+ */
1533
+ extern JS_PUBLIC_API(JSBool)
1534
+ JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp);
1535
+
1536
+ extern JS_PUBLIC_API(JSObject *)
1537
+ JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
1538
+
1539
+ /*
1540
+ * Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
1541
+ * proto if proto's actual parameter value is null.
1542
+ */
1543
+ extern JS_PUBLIC_API(JSObject *)
1544
+ JS_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
1545
+ JSObject *parent);
1546
+
1547
+ extern JS_PUBLIC_API(JSBool)
1548
+ JS_SealObject(JSContext *cx, JSObject *obj, JSBool deep);
1549
+
1550
+ extern JS_PUBLIC_API(JSObject *)
1551
+ JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
1552
+ JSObject *parent);
1553
+
1554
+ extern JS_PUBLIC_API(JSObject *)
1555
+ JS_ConstructObjectWithArguments(JSContext *cx, JSClass *clasp, JSObject *proto,
1556
+ JSObject *parent, uintN argc, jsval *argv);
1557
+
1558
+ extern JS_PUBLIC_API(JSObject *)
1559
+ JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
1560
+ JSObject *proto, uintN attrs);
1561
+
1562
+ extern JS_PUBLIC_API(JSBool)
1563
+ JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds);
1564
+
1565
+ extern JS_PUBLIC_API(JSBool)
1566
+ JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
1567
+
1568
+ extern JS_PUBLIC_API(JSBool)
1569
+ JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
1570
+ JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
1571
+
1572
+ /*
1573
+ * Determine the attributes (JSPROP_* flags) of a property on a given object.
1574
+ *
1575
+ * If the object does not have a property by that name, *foundp will be
1576
+ * JS_FALSE and the value of *attrsp is undefined.
1577
+ */
1578
+ extern JS_PUBLIC_API(JSBool)
1579
+ JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
1580
+ uintN *attrsp, JSBool *foundp);
1581
+
1582
+ /*
1583
+ * The same, but if the property is native, return its getter and setter via
1584
+ * *getterp and *setterp, respectively (and only if the out parameter pointer
1585
+ * is not null).
1586
+ */
1587
+ extern JS_PUBLIC_API(JSBool)
1588
+ JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
1589
+ const char *name,
1590
+ uintN *attrsp, JSBool *foundp,
1591
+ JSPropertyOp *getterp,
1592
+ JSPropertyOp *setterp);
1593
+
1594
+ /*
1595
+ * Set the attributes of a property on a given object.
1596
+ *
1597
+ * If the object does not have a property by that name, *foundp will be
1598
+ * JS_FALSE and nothing will be altered.
1599
+ */
1600
+ extern JS_PUBLIC_API(JSBool)
1601
+ JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
1602
+ uintN attrs, JSBool *foundp);
1603
+
1604
+ extern JS_PUBLIC_API(JSBool)
1605
+ JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
1606
+ int8 tinyid, jsval value,
1607
+ JSPropertyOp getter, JSPropertyOp setter,
1608
+ uintN attrs);
1609
+
1610
+ extern JS_PUBLIC_API(JSBool)
1611
+ JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name,
1612
+ const char *alias);
1613
+
1614
+ extern JS_PUBLIC_API(JSBool)
1615
+ JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name,
1616
+ JSBool *foundp);
1617
+
1618
+ extern JS_PUBLIC_API(JSBool)
1619
+ JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp);
1620
+
1621
+ extern JS_PUBLIC_API(JSBool)
1622
+ JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
1623
+
1624
+ extern JS_PUBLIC_API(JSBool)
1625
+ JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name,
1626
+ uintN flags, jsval *vp);
1627
+
1628
+ extern JS_PUBLIC_API(JSBool)
1629
+ JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
1630
+
1631
+ extern JS_PUBLIC_API(JSBool)
1632
+ JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
1633
+ jsval *vp);
1634
+
1635
+ extern JS_PUBLIC_API(JSBool)
1636
+ JS_GetMethod(JSContext *cx, JSObject *obj, const char *name, JSObject **objp,
1637
+ jsval *vp);
1638
+
1639
+ extern JS_PUBLIC_API(JSBool)
1640
+ JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
1641
+
1642
+ extern JS_PUBLIC_API(JSBool)
1643
+ JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
1644
+
1645
+ extern JS_PUBLIC_API(JSBool)
1646
+ JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name,
1647
+ jsval *rval);
1648
+
1649
+ extern JS_PUBLIC_API(JSBool)
1650
+ JS_DefineUCProperty(JSContext *cx, JSObject *obj,
1651
+ const jschar *name, size_t namelen, jsval value,
1652
+ JSPropertyOp getter, JSPropertyOp setter,
1653
+ uintN attrs);
1654
+
1655
+ /*
1656
+ * Determine the attributes (JSPROP_* flags) of a property on a given object.
1657
+ *
1658
+ * If the object does not have a property by that name, *foundp will be
1659
+ * JS_FALSE and the value of *attrsp is undefined.
1660
+ */
1661
+ extern JS_PUBLIC_API(JSBool)
1662
+ JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
1663
+ const jschar *name, size_t namelen,
1664
+ uintN *attrsp, JSBool *foundp);
1665
+
1666
+ /*
1667
+ * The same, but if the property is native, return its getter and setter via
1668
+ * *getterp and *setterp, respectively (and only if the out parameter pointer
1669
+ * is not null).
1670
+ */
1671
+ extern JS_PUBLIC_API(JSBool)
1672
+ JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
1673
+ const jschar *name, size_t namelen,
1674
+ uintN *attrsp, JSBool *foundp,
1675
+ JSPropertyOp *getterp,
1676
+ JSPropertyOp *setterp);
1677
+
1678
+ /*
1679
+ * Set the attributes of a property on a given object.
1680
+ *
1681
+ * If the object does not have a property by that name, *foundp will be
1682
+ * JS_FALSE and nothing will be altered.
1683
+ */
1684
+ extern JS_PUBLIC_API(JSBool)
1685
+ JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
1686
+ const jschar *name, size_t namelen,
1687
+ uintN attrs, JSBool *foundp);
1688
+
1689
+
1690
+ extern JS_PUBLIC_API(JSBool)
1691
+ JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
1692
+ const jschar *name, size_t namelen,
1693
+ int8 tinyid, jsval value,
1694
+ JSPropertyOp getter, JSPropertyOp setter,
1695
+ uintN attrs);
1696
+
1697
+ extern JS_PUBLIC_API(JSBool)
1698
+ JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name,
1699
+ size_t namelen, JSBool *foundp);
1700
+
1701
+ extern JS_PUBLIC_API(JSBool)
1702
+ JS_HasUCProperty(JSContext *cx, JSObject *obj,
1703
+ const jschar *name, size_t namelen,
1704
+ JSBool *vp);
1705
+
1706
+ extern JS_PUBLIC_API(JSBool)
1707
+ JS_LookupUCProperty(JSContext *cx, JSObject *obj,
1708
+ const jschar *name, size_t namelen,
1709
+ jsval *vp);
1710
+
1711
+ extern JS_PUBLIC_API(JSBool)
1712
+ JS_GetUCProperty(JSContext *cx, JSObject *obj,
1713
+ const jschar *name, size_t namelen,
1714
+ jsval *vp);
1715
+
1716
+ extern JS_PUBLIC_API(JSBool)
1717
+ JS_SetUCProperty(JSContext *cx, JSObject *obj,
1718
+ const jschar *name, size_t namelen,
1719
+ jsval *vp);
1720
+
1721
+ extern JS_PUBLIC_API(JSBool)
1722
+ JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
1723
+ const jschar *name, size_t namelen,
1724
+ jsval *rval);
1725
+
1726
+ extern JS_PUBLIC_API(JSObject *)
1727
+ JS_NewArrayObject(JSContext *cx, jsint length, jsval *vector);
1728
+
1729
+ extern JS_PUBLIC_API(JSBool)
1730
+ JS_IsArrayObject(JSContext *cx, JSObject *obj);
1731
+
1732
+ extern JS_PUBLIC_API(JSBool)
1733
+ JS_GetArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
1734
+
1735
+ extern JS_PUBLIC_API(JSBool)
1736
+ JS_SetArrayLength(JSContext *cx, JSObject *obj, jsuint length);
1737
+
1738
+ extern JS_PUBLIC_API(JSBool)
1739
+ JS_HasArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
1740
+
1741
+ extern JS_PUBLIC_API(JSBool)
1742
+ JS_DefineElement(JSContext *cx, JSObject *obj, jsint index, jsval value,
1743
+ JSPropertyOp getter, JSPropertyOp setter, uintN attrs);
1744
+
1745
+ extern JS_PUBLIC_API(JSBool)
1746
+ JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias);
1747
+
1748
+ extern JS_PUBLIC_API(JSBool)
1749
+ JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, jsint index,
1750
+ JSBool *foundp);
1751
+
1752
+ extern JS_PUBLIC_API(JSBool)
1753
+ JS_HasElement(JSContext *cx, JSObject *obj, jsint index, JSBool *foundp);
1754
+
1755
+ extern JS_PUBLIC_API(JSBool)
1756
+ JS_LookupElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
1757
+
1758
+ extern JS_PUBLIC_API(JSBool)
1759
+ JS_GetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
1760
+
1761
+ extern JS_PUBLIC_API(JSBool)
1762
+ JS_SetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
1763
+
1764
+ extern JS_PUBLIC_API(JSBool)
1765
+ JS_DeleteElement(JSContext *cx, JSObject *obj, jsint index);
1766
+
1767
+ extern JS_PUBLIC_API(JSBool)
1768
+ JS_DeleteElement2(JSContext *cx, JSObject *obj, jsint index, jsval *rval);
1769
+
1770
+ extern JS_PUBLIC_API(void)
1771
+ JS_ClearScope(JSContext *cx, JSObject *obj);
1772
+
1773
+ extern JS_PUBLIC_API(JSIdArray *)
1774
+ JS_Enumerate(JSContext *cx, JSObject *obj);
1775
+
1776
+ /*
1777
+ * Create an object to iterate over enumerable properties of obj, in arbitrary
1778
+ * property definition order. NB: This differs from longstanding for..in loop
1779
+ * order, which uses order of property definition in obj.
1780
+ */
1781
+ extern JS_PUBLIC_API(JSObject *)
1782
+ JS_NewPropertyIterator(JSContext *cx, JSObject *obj);
1783
+
1784
+ /*
1785
+ * Return true on success with *idp containing the id of the next enumerable
1786
+ * property to visit using iterobj, or JSVAL_VOID if there is no such property
1787
+ * left to visit. Return false on error.
1788
+ */
1789
+ extern JS_PUBLIC_API(JSBool)
1790
+ JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp);
1791
+
1792
+ extern JS_PUBLIC_API(JSBool)
1793
+ JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
1794
+ jsval *vp, uintN *attrsp);
1795
+
1796
+ extern JS_PUBLIC_API(JSCheckAccessOp)
1797
+ JS_SetCheckObjectAccessCallback(JSRuntime *rt, JSCheckAccessOp acb);
1798
+
1799
+ extern JS_PUBLIC_API(JSBool)
1800
+ JS_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval *vp);
1801
+
1802
+ extern JS_PUBLIC_API(JSBool)
1803
+ JS_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval v);
1804
+
1805
+ /************************************************************************/
1806
+
1807
+ /*
1808
+ * Security protocol.
1809
+ */
1810
+ struct JSPrincipals {
1811
+ char *codebase;
1812
+
1813
+ /* XXX unspecified and unused by Mozilla code -- can we remove these? */
1814
+ void * (* JS_DLL_CALLBACK getPrincipalArray)(JSContext *cx, JSPrincipals *);
1815
+ JSBool (* JS_DLL_CALLBACK globalPrivilegesEnabled)(JSContext *cx, JSPrincipals *);
1816
+
1817
+ /* Don't call "destroy"; use reference counting macros below. */
1818
+ jsrefcount refcount;
1819
+
1820
+ void (* JS_DLL_CALLBACK destroy)(JSContext *cx, JSPrincipals *);
1821
+ JSBool (* JS_DLL_CALLBACK subsume)(JSPrincipals *, JSPrincipals *);
1822
+ };
1823
+
1824
+ #ifdef JS_THREADSAFE
1825
+ #define JSPRINCIPALS_HOLD(cx, principals) JS_HoldPrincipals(cx,principals)
1826
+ #define JSPRINCIPALS_DROP(cx, principals) JS_DropPrincipals(cx,principals)
1827
+
1828
+ extern JS_PUBLIC_API(jsrefcount)
1829
+ JS_HoldPrincipals(JSContext *cx, JSPrincipals *principals);
1830
+
1831
+ extern JS_PUBLIC_API(jsrefcount)
1832
+ JS_DropPrincipals(JSContext *cx, JSPrincipals *principals);
1833
+
1834
+ #else
1835
+ #define JSPRINCIPALS_HOLD(cx, principals) (++(principals)->refcount)
1836
+ #define JSPRINCIPALS_DROP(cx, principals) \
1837
+ ((--(principals)->refcount == 0) \
1838
+ ? ((*(principals)->destroy)((cx), (principals)), 0) \
1839
+ : (principals)->refcount)
1840
+ #endif
1841
+
1842
+ extern JS_PUBLIC_API(JSPrincipalsTranscoder)
1843
+ JS_SetPrincipalsTranscoder(JSRuntime *rt, JSPrincipalsTranscoder px);
1844
+
1845
+ extern JS_PUBLIC_API(JSObjectPrincipalsFinder)
1846
+ JS_SetObjectPrincipalsFinder(JSRuntime *rt, JSObjectPrincipalsFinder fop);
1847
+
1848
+ /************************************************************************/
1849
+
1850
+ /*
1851
+ * Functions and scripts.
1852
+ */
1853
+ extern JS_PUBLIC_API(JSFunction *)
1854
+ JS_NewFunction(JSContext *cx, JSNative call, uintN nargs, uintN flags,
1855
+ JSObject *parent, const char *name);
1856
+
1857
+ extern JS_PUBLIC_API(JSObject *)
1858
+ JS_GetFunctionObject(JSFunction *fun);
1859
+
1860
+ /*
1861
+ * Deprecated, useful only for diagnostics. Use JS_GetFunctionId instead for
1862
+ * anonymous vs. "anonymous" disambiguation and Unicode fidelity.
1863
+ */
1864
+ extern JS_PUBLIC_API(const char *)
1865
+ JS_GetFunctionName(JSFunction *fun);
1866
+
1867
+ /*
1868
+ * Return the function's identifier as a JSString, or null if fun is unnamed.
1869
+ * The returned string lives as long as fun, so you don't need to root a saved
1870
+ * reference to it if fun is well-connected or rooted, and provided you bound
1871
+ * the use of the saved reference by fun's lifetime.
1872
+ *
1873
+ * Prefer JS_GetFunctionId over JS_GetFunctionName because it returns null for
1874
+ * truly anonymous functions, and because it doesn't chop to ISO-Latin-1 chars
1875
+ * from UTF-16-ish jschars.
1876
+ */
1877
+ extern JS_PUBLIC_API(JSString *)
1878
+ JS_GetFunctionId(JSFunction *fun);
1879
+
1880
+ /*
1881
+ * Return JSFUN_* flags for fun.
1882
+ */
1883
+ extern JS_PUBLIC_API(uintN)
1884
+ JS_GetFunctionFlags(JSFunction *fun);
1885
+
1886
+ /*
1887
+ * Return the arity (length) of fun.
1888
+ */
1889
+ extern JS_PUBLIC_API(uint16)
1890
+ JS_GetFunctionArity(JSFunction *fun);
1891
+
1892
+ /*
1893
+ * Infallible predicate to test whether obj is a function object (faster than
1894
+ * comparing obj's class name to "Function", but equivalent unless someone has
1895
+ * overwritten the "Function" identifier with a different constructor and then
1896
+ * created instances using that constructor that might be passed in as obj).
1897
+ */
1898
+ extern JS_PUBLIC_API(JSBool)
1899
+ JS_ObjectIsFunction(JSContext *cx, JSObject *obj);
1900
+
1901
+ extern JS_PUBLIC_API(JSBool)
1902
+ JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs);
1903
+
1904
+ extern JS_PUBLIC_API(JSFunction *)
1905
+ JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call,
1906
+ uintN nargs, uintN attrs);
1907
+
1908
+ extern JS_PUBLIC_API(JSFunction *)
1909
+ JS_DefineUCFunction(JSContext *cx, JSObject *obj,
1910
+ const jschar *name, size_t namelen, JSNative call,
1911
+ uintN nargs, uintN attrs);
1912
+
1913
+ extern JS_PUBLIC_API(JSObject *)
1914
+ JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent);
1915
+
1916
+ /*
1917
+ * Given a buffer, return JS_FALSE if the buffer might become a valid
1918
+ * javascript statement with the addition of more lines. Otherwise return
1919
+ * JS_TRUE. The intent is to support interactive compilation - accumulate
1920
+ * lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to
1921
+ * the compiler.
1922
+ */
1923
+ extern JS_PUBLIC_API(JSBool)
1924
+ JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj,
1925
+ const char *bytes, size_t length);
1926
+
1927
+ /*
1928
+ * The JSScript objects returned by the following functions refer to string and
1929
+ * other kinds of literals, including doubles and RegExp objects. These
1930
+ * literals are vulnerable to garbage collection; to root script objects and
1931
+ * prevent literals from being collected, create a rootable object using
1932
+ * JS_NewScriptObject, and root the resulting object using JS_Add[Named]Root.
1933
+ */
1934
+ extern JS_PUBLIC_API(JSScript *)
1935
+ JS_CompileScript(JSContext *cx, JSObject *obj,
1936
+ const char *bytes, size_t length,
1937
+ const char *filename, uintN lineno);
1938
+
1939
+ extern JS_PUBLIC_API(JSScript *)
1940
+ JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
1941
+ JSPrincipals *principals,
1942
+ const char *bytes, size_t length,
1943
+ const char *filename, uintN lineno);
1944
+
1945
+ extern JS_PUBLIC_API(JSScript *)
1946
+ JS_CompileUCScript(JSContext *cx, JSObject *obj,
1947
+ const jschar *chars, size_t length,
1948
+ const char *filename, uintN lineno);
1949
+
1950
+ extern JS_PUBLIC_API(JSScript *)
1951
+ JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
1952
+ JSPrincipals *principals,
1953
+ const jschar *chars, size_t length,
1954
+ const char *filename, uintN lineno);
1955
+
1956
+ extern JS_PUBLIC_API(JSScript *)
1957
+ JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename);
1958
+
1959
+ extern JS_PUBLIC_API(JSScript *)
1960
+ JS_CompileFileHandle(JSContext *cx, JSObject *obj, const char *filename,
1961
+ FILE *fh);
1962
+
1963
+ extern JS_PUBLIC_API(JSScript *)
1964
+ JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj,
1965
+ const char *filename, FILE *fh,
1966
+ JSPrincipals *principals);
1967
+
1968
+ /*
1969
+ * NB: you must use JS_NewScriptObject and root a pointer to its return value
1970
+ * in order to keep a JSScript and its atoms safe from garbage collection after
1971
+ * creating the script via JS_Compile* and before a JS_ExecuteScript* call.
1972
+ * E.g., and without error checks:
1973
+ *
1974
+ * JSScript *script = JS_CompileFile(cx, global, filename);
1975
+ * JSObject *scrobj = JS_NewScriptObject(cx, script);
1976
+ * JS_AddNamedRoot(cx, &scrobj, "scrobj");
1977
+ * do {
1978
+ * jsval result;
1979
+ * JS_ExecuteScript(cx, global, script, &result);
1980
+ * JS_GC();
1981
+ * } while (!JSVAL_IS_BOOLEAN(result) || JSVAL_TO_BOOLEAN(result));
1982
+ * JS_RemoveRoot(cx, &scrobj);
1983
+ */
1984
+ extern JS_PUBLIC_API(JSObject *)
1985
+ JS_NewScriptObject(JSContext *cx, JSScript *script);
1986
+
1987
+ /*
1988
+ * Infallible getter for a script's object. If JS_NewScriptObject has not been
1989
+ * called on script yet, the return value will be null.
1990
+ */
1991
+ extern JS_PUBLIC_API(JSObject *)
1992
+ JS_GetScriptObject(JSScript *script);
1993
+
1994
+ extern JS_PUBLIC_API(void)
1995
+ JS_DestroyScript(JSContext *cx, JSScript *script);
1996
+
1997
+ extern JS_PUBLIC_API(JSFunction *)
1998
+ JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
1999
+ uintN nargs, const char **argnames,
2000
+ const char *bytes, size_t length,
2001
+ const char *filename, uintN lineno);
2002
+
2003
+ extern JS_PUBLIC_API(JSFunction *)
2004
+ JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
2005
+ JSPrincipals *principals, const char *name,
2006
+ uintN nargs, const char **argnames,
2007
+ const char *bytes, size_t length,
2008
+ const char *filename, uintN lineno);
2009
+
2010
+ extern JS_PUBLIC_API(JSFunction *)
2011
+ JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
2012
+ uintN nargs, const char **argnames,
2013
+ const jschar *chars, size_t length,
2014
+ const char *filename, uintN lineno);
2015
+
2016
+ extern JS_PUBLIC_API(JSFunction *)
2017
+ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
2018
+ JSPrincipals *principals, const char *name,
2019
+ uintN nargs, const char **argnames,
2020
+ const jschar *chars, size_t length,
2021
+ const char *filename, uintN lineno);
2022
+
2023
+ extern JS_PUBLIC_API(JSString *)
2024
+ JS_DecompileScript(JSContext *cx, JSScript *script, const char *name,
2025
+ uintN indent);
2026
+
2027
+ /*
2028
+ * API extension: OR this into indent to avoid pretty-printing the decompiled
2029
+ * source resulting from JS_DecompileFunction{,Body}.
2030
+ */
2031
+ #define JS_DONT_PRETTY_PRINT ((uintN)0x8000)
2032
+
2033
+ extern JS_PUBLIC_API(JSString *)
2034
+ JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent);
2035
+
2036
+ extern JS_PUBLIC_API(JSString *)
2037
+ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent);
2038
+
2039
+ /*
2040
+ * NB: JS_ExecuteScript, JS_ExecuteScriptPart, and the JS_Evaluate*Script*
2041
+ * quadruplets all use the obj parameter as the initial scope chain header,
2042
+ * the 'this' keyword value, and the variables object (ECMA parlance for where
2043
+ * 'var' and 'function' bind names) of the execution context for script.
2044
+ *
2045
+ * Using obj as the variables object is problematic if obj's parent (which is
2046
+ * the scope chain link; see JS_SetParent and JS_NewObject) is not null: in
2047
+ * this case, variables created by 'var x = 0', e.g., go in obj, but variables
2048
+ * created by assignment to an unbound id, 'x = 0', go in the last object on
2049
+ * the scope chain linked by parent.
2050
+ *
2051
+ * ECMA calls that last scoping object the "global object", but note that many
2052
+ * embeddings have several such objects. ECMA requires that "global code" be
2053
+ * executed with the variables object equal to this global object. But these
2054
+ * JS API entry points provide freedom to execute code against a "sub-global",
2055
+ * i.e., a parented or scoped object, in which case the variables object will
2056
+ * differ from the last object on the scope chain, resulting in confusing and
2057
+ * non-ECMA explicit vs. implicit variable creation.
2058
+ *
2059
+ * Caveat embedders: unless you already depend on this buggy variables object
2060
+ * binding behavior, you should call JS_SetOptions(cx, JSOPTION_VAROBJFIX) or
2061
+ * JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_VAROBJFIX) -- the latter if
2062
+ * someone may have set other options on cx already -- for each context in the
2063
+ * application, if you pass parented objects as the obj parameter, or may ever
2064
+ * pass such objects in the future.
2065
+ *
2066
+ * Why a runtime option? The alternative is to add six or so new API entry
2067
+ * points with signatures matching the following six, and that doesn't seem
2068
+ * worth the code bloat cost. Such new entry points would probably have less
2069
+ * obvious names, too, so would not tend to be used. The JS_SetOption call,
2070
+ * OTOH, can be more easily hacked into existing code that does not depend on
2071
+ * the bug; such code can continue to use the familiar JS_EvaluateScript,
2072
+ * etc., entry points.
2073
+ */
2074
+ extern JS_PUBLIC_API(JSBool)
2075
+ JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
2076
+
2077
+ /*
2078
+ * Execute either the function-defining prolog of a script, or the script's
2079
+ * main body, but not both.
2080
+ */
2081
+ typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart;
2082
+
2083
+ extern JS_PUBLIC_API(JSBool)
2084
+ JS_ExecuteScriptPart(JSContext *cx, JSObject *obj, JSScript *script,
2085
+ JSExecPart part, jsval *rval);
2086
+
2087
+ extern JS_PUBLIC_API(JSBool)
2088
+ JS_EvaluateScript(JSContext *cx, JSObject *obj,
2089
+ const char *bytes, uintN length,
2090
+ const char *filename, uintN lineno,
2091
+ jsval *rval);
2092
+
2093
+ extern JS_PUBLIC_API(JSBool)
2094
+ JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
2095
+ JSPrincipals *principals,
2096
+ const char *bytes, uintN length,
2097
+ const char *filename, uintN lineno,
2098
+ jsval *rval);
2099
+
2100
+ extern JS_PUBLIC_API(JSBool)
2101
+ JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
2102
+ const jschar *chars, uintN length,
2103
+ const char *filename, uintN lineno,
2104
+ jsval *rval);
2105
+
2106
+ extern JS_PUBLIC_API(JSBool)
2107
+ JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
2108
+ JSPrincipals *principals,
2109
+ const jschar *chars, uintN length,
2110
+ const char *filename, uintN lineno,
2111
+ jsval *rval);
2112
+
2113
+ extern JS_PUBLIC_API(JSBool)
2114
+ JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, uintN argc,
2115
+ jsval *argv, jsval *rval);
2116
+
2117
+ extern JS_PUBLIC_API(JSBool)
2118
+ JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc,
2119
+ jsval *argv, jsval *rval);
2120
+
2121
+ extern JS_PUBLIC_API(JSBool)
2122
+ JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc,
2123
+ jsval *argv, jsval *rval);
2124
+
2125
+ /*
2126
+ * The maximum value of the operation limit to pass to JS_SetOperationCallback
2127
+ * and JS_SetOperationLimit.
2128
+ */
2129
+ #define JS_MAX_OPERATION_LIMIT ((uint32) 0x7FFFFFFF)
2130
+
2131
+ #define JS_OPERATION_WEIGHT_BASE 4096
2132
+
2133
+ /*
2134
+ * Set the operation callback that the engine calls periodically after
2135
+ * the internal operation count reaches the specified limit.
2136
+ *
2137
+ * When operationLimit is JS_OPERATION_WEIGHT_BASE, the callback will be
2138
+ * called at least after each backward jump in the interpreter. To minimize
2139
+ * the overhead of the callback invocation we suggest at least
2140
+ *
2141
+ * 100 * JS_OPERATION_WEIGHT_BASE
2142
+ *
2143
+ * as a value for operationLimit.
2144
+ */
2145
+ extern JS_PUBLIC_API(void)
2146
+ JS_SetOperationCallback(JSContext *cx, JSOperationCallback callback,
2147
+ uint32 operationLimit);
2148
+
2149
+ extern JS_PUBLIC_API(void)
2150
+ JS_ClearOperationCallback(JSContext *cx);
2151
+
2152
+ extern JS_PUBLIC_API(JSOperationCallback)
2153
+ JS_GetOperationCallback(JSContext *cx);
2154
+
2155
+ /*
2156
+ * Get the operation limit associated with the operation callback. This API
2157
+ * function may be called only when the result of JS_GetOperationCallback(cx)
2158
+ * is not null.
2159
+ */
2160
+ extern JS_PUBLIC_API(uint32)
2161
+ JS_GetOperationLimit(JSContext *cx);
2162
+
2163
+ /*
2164
+ * Change the operation limit associated with the operation callback. This API
2165
+ * function may be called only when the result of JS_GetOperationCallback(cx)
2166
+ * is not null.
2167
+ */
2168
+ extern JS_PUBLIC_API(void)
2169
+ JS_SetOperationLimit(JSContext *cx, uint32 operationLimit);
2170
+
2171
+ /*
2172
+ * Note well: JS_SetBranchCallback is deprecated. It is similar to
2173
+ *
2174
+ * JS_SetOperationCallback(cx, callback, 4096, NULL);
2175
+ *
2176
+ * except that the callback will not be called from a long-running native
2177
+ * function when JSOPTION_NATIVE_BRANCH_CALLBACK is not set and the top-most
2178
+ * frame is native.
2179
+ */
2180
+ extern JS_PUBLIC_API(JSBranchCallback)
2181
+ JS_SetBranchCallback(JSContext *cx, JSBranchCallback cb);
2182
+
2183
+ extern JS_PUBLIC_API(JSBool)
2184
+ JS_IsRunning(JSContext *cx);
2185
+
2186
+ extern JS_PUBLIC_API(JSBool)
2187
+ JS_IsConstructing(JSContext *cx);
2188
+
2189
+ /*
2190
+ * Returns true if a script is executing and its current bytecode is a set
2191
+ * (assignment) operation, even if there are native (no script) stack frames
2192
+ * between the script and the caller to JS_IsAssigning.
2193
+ */
2194
+ extern JS_FRIEND_API(JSBool)
2195
+ JS_IsAssigning(JSContext *cx);
2196
+
2197
+ /*
2198
+ * Set the second return value, which should be a string or int jsval that
2199
+ * identifies a property in the returned object, to form an ECMA reference
2200
+ * type value (obj, id). Only native methods can return reference types,
2201
+ * and if the returned value is used on the left-hand side of an assignment
2202
+ * op, the identified property will be set. If the return value is in an
2203
+ * r-value, the interpreter just gets obj[id]'s value.
2204
+ */
2205
+ extern JS_PUBLIC_API(void)
2206
+ JS_SetCallReturnValue2(JSContext *cx, jsval v);
2207
+
2208
+ /*
2209
+ * Saving and restoring frame chains.
2210
+ *
2211
+ * These two functions are used to set aside cx's call stack while that stack
2212
+ * is inactive. After a call to JS_SaveFrameChain, it looks as if there is no
2213
+ * code running on cx. Before calling JS_RestoreFrameChain, cx's call stack
2214
+ * must be balanced and all nested calls to JS_SaveFrameChain must have had
2215
+ * matching JS_RestoreFrameChain calls.
2216
+ *
2217
+ * JS_SaveFrameChain deals with cx not having any code running on it. A null
2218
+ * return does not signify an error, and JS_RestoreFrameChain handles a null
2219
+ * frame pointer argument safely.
2220
+ */
2221
+ extern JS_PUBLIC_API(JSStackFrame *)
2222
+ JS_SaveFrameChain(JSContext *cx);
2223
+
2224
+ extern JS_PUBLIC_API(void)
2225
+ JS_RestoreFrameChain(JSContext *cx, JSStackFrame *fp);
2226
+
2227
+ /************************************************************************/
2228
+
2229
+ /*
2230
+ * Strings.
2231
+ *
2232
+ * NB: JS_NewString takes ownership of bytes on success, avoiding a copy; but
2233
+ * on error (signified by null return), it leaves bytes owned by the caller.
2234
+ * So the caller must free bytes in the error case, if it has no use for them.
2235
+ * In contrast, all the JS_New*StringCopy* functions do not take ownership of
2236
+ * the character memory passed to them -- they copy it.
2237
+ */
2238
+ extern JS_PUBLIC_API(JSString *)
2239
+ JS_NewString(JSContext *cx, char *bytes, size_t length);
2240
+
2241
+ extern JS_PUBLIC_API(JSString *)
2242
+ JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);
2243
+
2244
+ extern JS_PUBLIC_API(JSString *)
2245
+ JS_NewStringCopyZ(JSContext *cx, const char *s);
2246
+
2247
+ extern JS_PUBLIC_API(JSString *)
2248
+ JS_InternString(JSContext *cx, const char *s);
2249
+
2250
+ extern JS_PUBLIC_API(JSString *)
2251
+ JS_NewUCString(JSContext *cx, jschar *chars, size_t length);
2252
+
2253
+ extern JS_PUBLIC_API(JSString *)
2254
+ JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n);
2255
+
2256
+ extern JS_PUBLIC_API(JSString *)
2257
+ JS_NewUCStringCopyZ(JSContext *cx, const jschar *s);
2258
+
2259
+ extern JS_PUBLIC_API(JSString *)
2260
+ JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length);
2261
+
2262
+ extern JS_PUBLIC_API(JSString *)
2263
+ JS_InternUCString(JSContext *cx, const jschar *s);
2264
+
2265
+ extern JS_PUBLIC_API(char *)
2266
+ JS_GetStringBytes(JSString *str);
2267
+
2268
+ extern JS_PUBLIC_API(jschar *)
2269
+ JS_GetStringChars(JSString *str);
2270
+
2271
+ extern JS_PUBLIC_API(size_t)
2272
+ JS_GetStringLength(JSString *str);
2273
+
2274
+ extern JS_PUBLIC_API(intN)
2275
+ JS_CompareStrings(JSString *str1, JSString *str2);
2276
+
2277
+ /*
2278
+ * Mutable string support. A string's characters are never mutable in this JS
2279
+ * implementation, but a growable string has a buffer that can be reallocated,
2280
+ * and a dependent string is a substring of another (growable, dependent, or
2281
+ * immutable) string. The direct data members of the (opaque to API clients)
2282
+ * JSString struct may be changed in a single-threaded way for growable and
2283
+ * dependent strings.
2284
+ *
2285
+ * Therefore mutable strings cannot be used by more than one thread at a time.
2286
+ * You may call JS_MakeStringImmutable to convert the string from a mutable
2287
+ * (growable or dependent) string to an immutable (and therefore thread-safe)
2288
+ * string. The engine takes care of converting growable and dependent strings
2289
+ * to immutable for you if you store strings in multi-threaded objects using
2290
+ * JS_SetProperty or kindred API entry points.
2291
+ *
2292
+ * If you store a JSString pointer in a native data structure that is (safely)
2293
+ * accessible to multiple threads, you must call JS_MakeStringImmutable before
2294
+ * retiring the store.
2295
+ */
2296
+ extern JS_PUBLIC_API(JSString *)
2297
+ JS_NewGrowableString(JSContext *cx, jschar *chars, size_t length);
2298
+
2299
+ /*
2300
+ * Create a dependent string, i.e., a string that owns no character storage,
2301
+ * but that refers to a slice of another string's chars. Dependent strings
2302
+ * are mutable by definition, so the thread safety comments above apply.
2303
+ */
2304
+ extern JS_PUBLIC_API(JSString *)
2305
+ JS_NewDependentString(JSContext *cx, JSString *str, size_t start,
2306
+ size_t length);
2307
+
2308
+ /*
2309
+ * Concatenate two strings, resulting in a new growable string. If you create
2310
+ * the left string and pass it to JS_ConcatStrings on a single thread, try to
2311
+ * use JS_NewGrowableString to create the left string -- doing so helps Concat
2312
+ * avoid allocating a new buffer for the result and copying left's chars into
2313
+ * the new buffer. See above for thread safety comments.
2314
+ */
2315
+ extern JS_PUBLIC_API(JSString *)
2316
+ JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
2317
+
2318
+ /*
2319
+ * Convert a dependent string into an independent one. This function does not
2320
+ * change the string's mutability, so the thread safety comments above apply.
2321
+ */
2322
+ extern JS_PUBLIC_API(const jschar *)
2323
+ JS_UndependString(JSContext *cx, JSString *str);
2324
+
2325
+ /*
2326
+ * Convert a mutable string (either growable or dependent) into an immutable,
2327
+ * thread-safe one.
2328
+ */
2329
+ extern JS_PUBLIC_API(JSBool)
2330
+ JS_MakeStringImmutable(JSContext *cx, JSString *str);
2331
+
2332
+ /*
2333
+ * Return JS_TRUE if C (char []) strings passed via the API and internally
2334
+ * are UTF-8.
2335
+ */
2336
+ JS_PUBLIC_API(JSBool)
2337
+ JS_CStringsAreUTF8(void);
2338
+
2339
+ /*
2340
+ * Update the value to be returned by JS_CStringsAreUTF8(). Once set, it
2341
+ * can never be changed. This API must be called before the first call to
2342
+ * JS_NewRuntime.
2343
+ */
2344
+ JS_PUBLIC_API(void)
2345
+ JS_SetCStringsAreUTF8(void);
2346
+
2347
+ /*
2348
+ * Character encoding support.
2349
+ *
2350
+ * For both JS_EncodeCharacters and JS_DecodeBytes, set *dstlenp to the size
2351
+ * of the destination buffer before the call; on return, *dstlenp contains the
2352
+ * number of bytes (JS_EncodeCharacters) or jschars (JS_DecodeBytes) actually
2353
+ * stored. To determine the necessary destination buffer size, make a sizing
2354
+ * call that passes NULL for dst.
2355
+ *
2356
+ * On errors, the functions report the error. In that case, *dstlenp contains
2357
+ * the number of characters or bytes transferred so far. If cx is NULL, no
2358
+ * error is reported on failure, and the functions simply return JS_FALSE.
2359
+ *
2360
+ * NB: Neither function stores an additional zero byte or jschar after the
2361
+ * transcoded string.
2362
+ *
2363
+ * If JS_CStringsAreUTF8() is true then JS_EncodeCharacters encodes to
2364
+ * UTF-8, and JS_DecodeBytes decodes from UTF-8, which may create additional
2365
+ * errors if the character sequence is malformed. If UTF-8 support is
2366
+ * disabled, the functions deflate and inflate, respectively.
2367
+ */
2368
+ JS_PUBLIC_API(JSBool)
2369
+ JS_EncodeCharacters(JSContext *cx, const jschar *src, size_t srclen, char *dst,
2370
+ size_t *dstlenp);
2371
+
2372
+ JS_PUBLIC_API(JSBool)
2373
+ JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst,
2374
+ size_t *dstlenp);
2375
+
2376
+ /*
2377
+ * A variation on JS_EncodeCharacters where a null terminated string is
2378
+ * returned that you are expected to call JS_free on when done.
2379
+ */
2380
+ JS_PUBLIC_API(char *)
2381
+ JS_EncodeString(JSContext *cx, JSString *str);
2382
+
2383
+ /************************************************************************/
2384
+
2385
+ /*
2386
+ * Locale specific string conversion and error message callbacks.
2387
+ */
2388
+ struct JSLocaleCallbacks {
2389
+ JSLocaleToUpperCase localeToUpperCase;
2390
+ JSLocaleToLowerCase localeToLowerCase;
2391
+ JSLocaleCompare localeCompare;
2392
+ JSLocaleToUnicode localeToUnicode;
2393
+ JSErrorCallback localeGetErrorMessage;
2394
+ };
2395
+
2396
+ /*
2397
+ * Establish locale callbacks. The pointer must persist as long as the
2398
+ * JSContext. Passing NULL restores the default behaviour.
2399
+ */
2400
+ extern JS_PUBLIC_API(void)
2401
+ JS_SetLocaleCallbacks(JSContext *cx, JSLocaleCallbacks *callbacks);
2402
+
2403
+ /*
2404
+ * Return the address of the current locale callbacks struct, which may
2405
+ * be NULL.
2406
+ */
2407
+ extern JS_PUBLIC_API(JSLocaleCallbacks *)
2408
+ JS_GetLocaleCallbacks(JSContext *cx);
2409
+
2410
+ /************************************************************************/
2411
+
2412
+ /*
2413
+ * Error reporting.
2414
+ */
2415
+
2416
+ /*
2417
+ * Report an exception represented by the sprintf-like conversion of format
2418
+ * and its arguments. This exception message string is passed to a pre-set
2419
+ * JSErrorReporter function (set by JS_SetErrorReporter; see jspubtd.h for
2420
+ * the JSErrorReporter typedef).
2421
+ */
2422
+ extern JS_PUBLIC_API(void)
2423
+ JS_ReportError(JSContext *cx, const char *format, ...);
2424
+
2425
+ /*
2426
+ * Use an errorNumber to retrieve the format string, args are char *
2427
+ */
2428
+ extern JS_PUBLIC_API(void)
2429
+ JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
2430
+ void *userRef, const uintN errorNumber, ...);
2431
+
2432
+ /*
2433
+ * Use an errorNumber to retrieve the format string, args are jschar *
2434
+ */
2435
+ extern JS_PUBLIC_API(void)
2436
+ JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
2437
+ void *userRef, const uintN errorNumber, ...);
2438
+
2439
+ /*
2440
+ * As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)).
2441
+ * Return true if there was no error trying to issue the warning, and if the
2442
+ * warning was not converted into an error due to the JSOPTION_WERROR option
2443
+ * being set, false otherwise.
2444
+ */
2445
+ extern JS_PUBLIC_API(JSBool)
2446
+ JS_ReportWarning(JSContext *cx, const char *format, ...);
2447
+
2448
+ extern JS_PUBLIC_API(JSBool)
2449
+ JS_ReportErrorFlagsAndNumber(JSContext *cx, uintN flags,
2450
+ JSErrorCallback errorCallback, void *userRef,
2451
+ const uintN errorNumber, ...);
2452
+
2453
+ extern JS_PUBLIC_API(JSBool)
2454
+ JS_ReportErrorFlagsAndNumberUC(JSContext *cx, uintN flags,
2455
+ JSErrorCallback errorCallback, void *userRef,
2456
+ const uintN errorNumber, ...);
2457
+
2458
+ /*
2459
+ * Complain when out of memory.
2460
+ */
2461
+ extern JS_PUBLIC_API(void)
2462
+ JS_ReportOutOfMemory(JSContext *cx);
2463
+
2464
+ /*
2465
+ * Complain when an allocation size overflows the maximum supported limit.
2466
+ */
2467
+ extern JS_PUBLIC_API(void)
2468
+ JS_ReportAllocationOverflow(JSContext *cx);
2469
+
2470
+ struct JSErrorReport {
2471
+ const char *filename; /* source file name, URL, etc., or null */
2472
+ uintN lineno; /* source line number */
2473
+ const char *linebuf; /* offending source line without final \n */
2474
+ const char *tokenptr; /* pointer to error token in linebuf */
2475
+ const jschar *uclinebuf; /* unicode (original) line buffer */
2476
+ const jschar *uctokenptr; /* unicode (original) token pointer */
2477
+ uintN flags; /* error/warning, etc. */
2478
+ uintN errorNumber; /* the error number, e.g. see js.msg */
2479
+ const jschar *ucmessage; /* the (default) error message */
2480
+ const jschar **messageArgs; /* arguments for the error message */
2481
+ };
2482
+
2483
+ /*
2484
+ * JSErrorReport flag values. These may be freely composed.
2485
+ */
2486
+ #define JSREPORT_ERROR 0x0 /* pseudo-flag for default case */
2487
+ #define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */
2488
+ #define JSREPORT_EXCEPTION 0x2 /* exception was thrown */
2489
+ #define JSREPORT_STRICT 0x4 /* error or warning due to strict option */
2490
+
2491
+ /*
2492
+ * If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception
2493
+ * has been thrown for this runtime error, and the host should ignore it.
2494
+ * Exception-aware hosts should also check for JS_IsExceptionPending if
2495
+ * JS_ExecuteScript returns failure, and signal or propagate the exception, as
2496
+ * appropriate.
2497
+ */
2498
+ #define JSREPORT_IS_WARNING(flags) (((flags) & JSREPORT_WARNING) != 0)
2499
+ #define JSREPORT_IS_EXCEPTION(flags) (((flags) & JSREPORT_EXCEPTION) != 0)
2500
+ #define JSREPORT_IS_STRICT(flags) (((flags) & JSREPORT_STRICT) != 0)
2501
+
2502
+ extern JS_PUBLIC_API(JSErrorReporter)
2503
+ JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
2504
+
2505
+ /************************************************************************/
2506
+
2507
+ /*
2508
+ * Regular Expressions.
2509
+ */
2510
+ #define JSREG_FOLD 0x01 /* fold uppercase to lowercase */
2511
+ #define JSREG_GLOB 0x02 /* global exec, creates array of matches */
2512
+ #define JSREG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */
2513
+ #define JSREG_STICKY 0x08 /* only match starting at lastIndex */
2514
+
2515
+ extern JS_PUBLIC_API(JSObject *)
2516
+ JS_NewRegExpObject(JSContext *cx, char *bytes, size_t length, uintN flags);
2517
+
2518
+ extern JS_PUBLIC_API(JSObject *)
2519
+ JS_NewUCRegExpObject(JSContext *cx, jschar *chars, size_t length, uintN flags);
2520
+
2521
+ extern JS_PUBLIC_API(void)
2522
+ JS_SetRegExpInput(JSContext *cx, JSString *input, JSBool multiline);
2523
+
2524
+ extern JS_PUBLIC_API(void)
2525
+ JS_ClearRegExpStatics(JSContext *cx);
2526
+
2527
+ extern JS_PUBLIC_API(void)
2528
+ JS_ClearRegExpRoots(JSContext *cx);
2529
+
2530
+ /* TODO: compile, exec, get/set other statics... */
2531
+
2532
+ /************************************************************************/
2533
+
2534
+ extern JS_PUBLIC_API(JSBool)
2535
+ JS_IsExceptionPending(JSContext *cx);
2536
+
2537
+ extern JS_PUBLIC_API(JSBool)
2538
+ JS_GetPendingException(JSContext *cx, jsval *vp);
2539
+
2540
+ extern JS_PUBLIC_API(void)
2541
+ JS_SetPendingException(JSContext *cx, jsval v);
2542
+
2543
+ extern JS_PUBLIC_API(void)
2544
+ JS_ClearPendingException(JSContext *cx);
2545
+
2546
+ extern JS_PUBLIC_API(JSBool)
2547
+ JS_ReportPendingException(JSContext *cx);
2548
+
2549
+ /*
2550
+ * Save the current exception state. This takes a snapshot of cx's current
2551
+ * exception state without making any change to that state.
2552
+ *
2553
+ * The returned state pointer MUST be passed later to JS_RestoreExceptionState
2554
+ * (to restore that saved state, overriding any more recent state) or else to
2555
+ * JS_DropExceptionState (to free the state struct in case it is not correct
2556
+ * or desirable to restore it). Both Restore and Drop free the state struct,
2557
+ * so callers must stop using the pointer returned from Save after calling the
2558
+ * Release or Drop API.
2559
+ */
2560
+ extern JS_PUBLIC_API(JSExceptionState *)
2561
+ JS_SaveExceptionState(JSContext *cx);
2562
+
2563
+ extern JS_PUBLIC_API(void)
2564
+ JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state);
2565
+
2566
+ extern JS_PUBLIC_API(void)
2567
+ JS_DropExceptionState(JSContext *cx, JSExceptionState *state);
2568
+
2569
+ /*
2570
+ * If the given value is an exception object that originated from an error,
2571
+ * the exception will contain an error report struct, and this API will return
2572
+ * the address of that struct. Otherwise, it returns NULL. The lifetime of
2573
+ * the error report struct that might be returned is the same as the lifetime
2574
+ * of the exception object.
2575
+ */
2576
+ extern JS_PUBLIC_API(JSErrorReport *)
2577
+ JS_ErrorFromException(JSContext *cx, jsval v);
2578
+
2579
+ /*
2580
+ * Given a reported error's message and JSErrorReport struct pointer, throw
2581
+ * the corresponding exception on cx.
2582
+ */
2583
+ extern JS_PUBLIC_API(JSBool)
2584
+ JS_ThrowReportedError(JSContext *cx, const char *message,
2585
+ JSErrorReport *reportp);
2586
+
2587
+ /*
2588
+ * Throws a StopIteration exception on cx.
2589
+ */
2590
+ extern JS_PUBLIC_API(JSBool)
2591
+ JS_ThrowStopIteration(JSContext *cx);
2592
+
2593
+ /*
2594
+ * Associate the current thread with the given context. This is done
2595
+ * implicitly by JS_NewContext.
2596
+ *
2597
+ * Returns the old thread id for this context, which should be treated as
2598
+ * an opaque value. This value is provided for comparison to 0, which
2599
+ * indicates that ClearContextThread has been called on this context
2600
+ * since the last SetContextThread, or non-0, which indicates the opposite.
2601
+ */
2602
+ extern JS_PUBLIC_API(jsword)
2603
+ JS_GetContextThread(JSContext *cx);
2604
+
2605
+ extern JS_PUBLIC_API(jsword)
2606
+ JS_SetContextThread(JSContext *cx);
2607
+
2608
+ extern JS_PUBLIC_API(jsword)
2609
+ JS_ClearContextThread(JSContext *cx);
2610
+
2611
+ /************************************************************************/
2612
+
2613
+ #ifdef DEBUG
2614
+ #define JS_GC_ZEAL 1
2615
+ #endif
2616
+
2617
+ #ifdef JS_GC_ZEAL
2618
+ extern JS_PUBLIC_API(void)
2619
+ JS_SetGCZeal(JSContext *cx, uint8 zeal);
2620
+ #endif
2621
+
2622
+ JS_END_EXTERN_C
2623
+
2624
+ #endif /* jsapi_h___ */