jbarnette-johnson 1.0.0.200806240111 → 1.0.0.200807291507

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. data/MANIFEST +1 -0
  2. data/Rakefile +3 -10
  3. data/bin/johnson +2 -1
  4. data/ext/spidermonkey/context.c +3 -4
  5. data/ext/spidermonkey/context.h +1 -1
  6. data/ext/spidermonkey/conversions.c +39 -33
  7. data/ext/spidermonkey/debugger.c +5 -5
  8. data/ext/spidermonkey/immutable_node.c.erb +11 -11
  9. data/ext/spidermonkey/jroot.h +4 -4
  10. data/ext/spidermonkey/js_land_proxy.c +9 -8
  11. data/ext/spidermonkey/ruby_land_proxy.c +5 -4
  12. data/ext/spidermonkey/runtime.c +1 -1
  13. data/johnson.gemspec +36 -0
  14. data/lib/hoe.rb +0 -7
  15. data/lib/johnson/cli/options.rb +10 -4
  16. data/lib/johnson/spidermonkey/runtime.rb +2 -2
  17. data/lib/johnson/version.rb +4 -2
  18. data/lib/johnson.rb +1 -0
  19. data/test/johnson/runtime_test.rb +11 -0
  20. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +6 -0
  21. data/vendor/spidermonkey/.cvsignore +9 -0
  22. data/vendor/spidermonkey/Makefile.in +462 -0
  23. data/vendor/spidermonkey/Makefile.ref +364 -0
  24. data/vendor/spidermonkey/README.html +820 -0
  25. data/vendor/spidermonkey/SpiderMonkey.rsp +12 -0
  26. data/vendor/spidermonkey/Y.js +19 -0
  27. data/vendor/spidermonkey/build.mk +43 -0
  28. data/vendor/spidermonkey/config/AIX4.1.mk +65 -0
  29. data/vendor/spidermonkey/config/AIX4.2.mk +64 -0
  30. data/vendor/spidermonkey/config/AIX4.3.mk +65 -0
  31. data/vendor/spidermonkey/config/Darwin.mk +83 -0
  32. data/vendor/spidermonkey/config/Darwin1.3.mk +81 -0
  33. data/vendor/spidermonkey/config/Darwin1.4.mk +41 -0
  34. data/vendor/spidermonkey/config/Darwin5.2.mk +81 -0
  35. data/vendor/spidermonkey/config/Darwin5.3.mk +81 -0
  36. data/vendor/spidermonkey/config/HP-UXB.10.10.mk +77 -0
  37. data/vendor/spidermonkey/config/HP-UXB.10.20.mk +77 -0
  38. data/vendor/spidermonkey/config/HP-UXB.11.00.mk +80 -0
  39. data/vendor/spidermonkey/config/IRIX.mk +87 -0
  40. data/vendor/spidermonkey/config/IRIX5.3.mk +44 -0
  41. data/vendor/spidermonkey/config/IRIX6.1.mk +44 -0
  42. data/vendor/spidermonkey/config/IRIX6.2.mk +44 -0
  43. data/vendor/spidermonkey/config/IRIX6.3.mk +44 -0
  44. data/vendor/spidermonkey/config/IRIX6.5.mk +44 -0
  45. data/vendor/spidermonkey/config/Linux_All.mk +103 -0
  46. data/vendor/spidermonkey/config/Mac_OS10.0.mk +82 -0
  47. data/vendor/spidermonkey/config/OSF1V4.0.mk +72 -0
  48. data/vendor/spidermonkey/config/OSF1V5.0.mk +69 -0
  49. data/vendor/spidermonkey/config/SunOS4.1.4.mk +101 -0
  50. data/vendor/spidermonkey/config/SunOS5.10.mk +50 -0
  51. data/vendor/spidermonkey/config/SunOS5.3.mk +91 -0
  52. data/vendor/spidermonkey/config/SunOS5.4.mk +92 -0
  53. data/vendor/spidermonkey/config/SunOS5.5.1.mk +44 -0
  54. data/vendor/spidermonkey/config/SunOS5.5.mk +87 -0
  55. data/vendor/spidermonkey/config/SunOS5.6.mk +89 -0
  56. data/vendor/spidermonkey/config/SunOS5.7.mk +44 -0
  57. data/vendor/spidermonkey/config/SunOS5.8.mk +44 -0
  58. data/vendor/spidermonkey/config/SunOS5.9.mk +44 -0
  59. data/vendor/spidermonkey/config/WINNT4.0.mk +117 -0
  60. data/vendor/spidermonkey/config/WINNT5.0.mk +117 -0
  61. data/vendor/spidermonkey/config/WINNT5.1.mk +117 -0
  62. data/vendor/spidermonkey/config/WINNT5.2.mk +117 -0
  63. data/vendor/spidermonkey/config/WINNT6.0.mk +117 -0
  64. data/vendor/spidermonkey/config/dgux.mk +64 -0
  65. data/vendor/spidermonkey/config.mk +192 -0
  66. data/vendor/spidermonkey/editline/Makefile.ref +144 -0
  67. data/vendor/spidermonkey/editline/README +83 -0
  68. data/vendor/spidermonkey/editline/editline.3 +175 -0
  69. data/vendor/spidermonkey/editline/editline.c +1369 -0
  70. data/vendor/spidermonkey/editline/editline.h +135 -0
  71. data/vendor/spidermonkey/editline/sysunix.c +182 -0
  72. data/vendor/spidermonkey/editline/unix.h +82 -0
  73. data/vendor/spidermonkey/fdlibm/.cvsignore +7 -0
  74. data/vendor/spidermonkey/fdlibm/Makefile.in +127 -0
  75. data/vendor/spidermonkey/fdlibm/Makefile.ref +192 -0
  76. data/vendor/spidermonkey/fdlibm/e_acos.c +147 -0
  77. data/vendor/spidermonkey/fdlibm/e_acosh.c +105 -0
  78. data/vendor/spidermonkey/fdlibm/e_asin.c +156 -0
  79. data/vendor/spidermonkey/fdlibm/e_atan2.c +165 -0
  80. data/vendor/spidermonkey/fdlibm/e_atanh.c +110 -0
  81. data/vendor/spidermonkey/fdlibm/e_cosh.c +133 -0
  82. data/vendor/spidermonkey/fdlibm/e_exp.c +202 -0
  83. data/vendor/spidermonkey/fdlibm/e_fmod.c +184 -0
  84. data/vendor/spidermonkey/fdlibm/e_gamma.c +71 -0
  85. data/vendor/spidermonkey/fdlibm/e_gamma_r.c +70 -0
  86. data/vendor/spidermonkey/fdlibm/e_hypot.c +173 -0
  87. data/vendor/spidermonkey/fdlibm/e_j0.c +524 -0
  88. data/vendor/spidermonkey/fdlibm/e_j1.c +523 -0
  89. data/vendor/spidermonkey/fdlibm/e_jn.c +315 -0
  90. data/vendor/spidermonkey/fdlibm/e_lgamma.c +71 -0
  91. data/vendor/spidermonkey/fdlibm/e_lgamma_r.c +347 -0
  92. data/vendor/spidermonkey/fdlibm/e_log.c +184 -0
  93. data/vendor/spidermonkey/fdlibm/e_log10.c +134 -0
  94. data/vendor/spidermonkey/fdlibm/e_pow.c +386 -0
  95. data/vendor/spidermonkey/fdlibm/e_rem_pio2.c +222 -0
  96. data/vendor/spidermonkey/fdlibm/e_remainder.c +120 -0
  97. data/vendor/spidermonkey/fdlibm/e_scalb.c +89 -0
  98. data/vendor/spidermonkey/fdlibm/e_sinh.c +122 -0
  99. data/vendor/spidermonkey/fdlibm/e_sqrt.c +497 -0
  100. data/vendor/spidermonkey/fdlibm/fdlibm.h +273 -0
  101. data/vendor/spidermonkey/fdlibm/fdlibm.mak +1453 -0
  102. data/vendor/spidermonkey/fdlibm/fdlibm.mdp +0 -0
  103. data/vendor/spidermonkey/fdlibm/k_cos.c +135 -0
  104. data/vendor/spidermonkey/fdlibm/k_rem_pio2.c +354 -0
  105. data/vendor/spidermonkey/fdlibm/k_sin.c +114 -0
  106. data/vendor/spidermonkey/fdlibm/k_standard.c +785 -0
  107. data/vendor/spidermonkey/fdlibm/k_tan.c +170 -0
  108. data/vendor/spidermonkey/fdlibm/s_asinh.c +101 -0
  109. data/vendor/spidermonkey/fdlibm/s_atan.c +175 -0
  110. data/vendor/spidermonkey/fdlibm/s_cbrt.c +133 -0
  111. data/vendor/spidermonkey/fdlibm/s_ceil.c +120 -0
  112. data/vendor/spidermonkey/fdlibm/s_copysign.c +72 -0
  113. data/vendor/spidermonkey/fdlibm/s_cos.c +118 -0
  114. data/vendor/spidermonkey/fdlibm/s_erf.c +356 -0
  115. data/vendor/spidermonkey/fdlibm/s_expm1.c +267 -0
  116. data/vendor/spidermonkey/fdlibm/s_fabs.c +70 -0
  117. data/vendor/spidermonkey/fdlibm/s_finite.c +71 -0
  118. data/vendor/spidermonkey/fdlibm/s_floor.c +121 -0
  119. data/vendor/spidermonkey/fdlibm/s_frexp.c +99 -0
  120. data/vendor/spidermonkey/fdlibm/s_ilogb.c +85 -0
  121. data/vendor/spidermonkey/fdlibm/s_isnan.c +74 -0
  122. data/vendor/spidermonkey/fdlibm/s_ldexp.c +66 -0
  123. data/vendor/spidermonkey/fdlibm/s_lib_version.c +73 -0
  124. data/vendor/spidermonkey/fdlibm/s_log1p.c +211 -0
  125. data/vendor/spidermonkey/fdlibm/s_logb.c +79 -0
  126. data/vendor/spidermonkey/fdlibm/s_matherr.c +64 -0
  127. data/vendor/spidermonkey/fdlibm/s_modf.c +132 -0
  128. data/vendor/spidermonkey/fdlibm/s_nextafter.c +124 -0
  129. data/vendor/spidermonkey/fdlibm/s_rint.c +131 -0
  130. data/vendor/spidermonkey/fdlibm/s_scalbn.c +107 -0
  131. data/vendor/spidermonkey/fdlibm/s_signgam.c +40 -0
  132. data/vendor/spidermonkey/fdlibm/s_significand.c +68 -0
  133. data/vendor/spidermonkey/fdlibm/s_sin.c +118 -0
  134. data/vendor/spidermonkey/fdlibm/s_tan.c +112 -0
  135. data/vendor/spidermonkey/fdlibm/s_tanh.c +122 -0
  136. data/vendor/spidermonkey/fdlibm/w_acos.c +78 -0
  137. data/vendor/spidermonkey/fdlibm/w_acosh.c +78 -0
  138. data/vendor/spidermonkey/fdlibm/w_asin.c +80 -0
  139. data/vendor/spidermonkey/fdlibm/w_atan2.c +79 -0
  140. data/vendor/spidermonkey/fdlibm/w_atanh.c +81 -0
  141. data/vendor/spidermonkey/fdlibm/w_cosh.c +77 -0
  142. data/vendor/spidermonkey/fdlibm/w_exp.c +88 -0
  143. data/vendor/spidermonkey/fdlibm/w_fmod.c +78 -0
  144. data/vendor/spidermonkey/fdlibm/w_gamma.c +85 -0
  145. data/vendor/spidermonkey/fdlibm/w_gamma_r.c +81 -0
  146. data/vendor/spidermonkey/fdlibm/w_hypot.c +78 -0
  147. data/vendor/spidermonkey/fdlibm/w_j0.c +105 -0
  148. data/vendor/spidermonkey/fdlibm/w_j1.c +106 -0
  149. data/vendor/spidermonkey/fdlibm/w_jn.c +128 -0
  150. data/vendor/spidermonkey/fdlibm/w_lgamma.c +85 -0
  151. data/vendor/spidermonkey/fdlibm/w_lgamma_r.c +81 -0
  152. data/vendor/spidermonkey/fdlibm/w_log.c +78 -0
  153. data/vendor/spidermonkey/fdlibm/w_log10.c +81 -0
  154. data/vendor/spidermonkey/fdlibm/w_pow.c +99 -0
  155. data/vendor/spidermonkey/fdlibm/w_remainder.c +77 -0
  156. data/vendor/spidermonkey/fdlibm/w_scalb.c +95 -0
  157. data/vendor/spidermonkey/fdlibm/w_sinh.c +77 -0
  158. data/vendor/spidermonkey/fdlibm/w_sqrt.c +77 -0
  159. data/vendor/spidermonkey/javascript-trace.d +73 -0
  160. data/vendor/spidermonkey/js.c +3951 -0
  161. data/vendor/spidermonkey/js.mak +4438 -0
  162. data/vendor/spidermonkey/js.mdp +0 -0
  163. data/vendor/spidermonkey/js.msg +307 -0
  164. data/vendor/spidermonkey/js.pkg +2 -0
  165. data/vendor/spidermonkey/js3240.rc +79 -0
  166. data/vendor/spidermonkey/jsOS240.def +654 -0
  167. data/vendor/spidermonkey/jsapi.c +5836 -0
  168. data/vendor/spidermonkey/jsapi.h +2624 -0
  169. data/vendor/spidermonkey/jsarena.c +450 -0
  170. data/vendor/spidermonkey/jsarena.h +318 -0
  171. data/vendor/spidermonkey/jsarray.c +2988 -0
  172. data/vendor/spidermonkey/jsarray.h +124 -0
  173. data/vendor/spidermonkey/jsatom.c +1045 -0
  174. data/vendor/spidermonkey/jsatom.h +442 -0
  175. data/vendor/spidermonkey/jsbit.h +253 -0
  176. data/vendor/spidermonkey/jsbool.c +176 -0
  177. data/vendor/spidermonkey/jsbool.h +73 -0
  178. data/vendor/spidermonkey/jsclist.h +139 -0
  179. data/vendor/spidermonkey/jscntxt.c +1348 -0
  180. data/vendor/spidermonkey/jscntxt.h +1120 -0
  181. data/vendor/spidermonkey/jscompat.h +57 -0
  182. data/vendor/spidermonkey/jsconfig.h +248 -0
  183. data/vendor/spidermonkey/jsconfig.mk +181 -0
  184. data/vendor/spidermonkey/jscpucfg.c +383 -0
  185. data/vendor/spidermonkey/jscpucfg.h +212 -0
  186. data/vendor/spidermonkey/jsdate.c +2398 -0
  187. data/vendor/spidermonkey/jsdate.h +124 -0
  188. data/vendor/spidermonkey/jsdbgapi.c +1799 -0
  189. data/vendor/spidermonkey/jsdbgapi.h +464 -0
  190. data/vendor/spidermonkey/jsdhash.c +868 -0
  191. data/vendor/spidermonkey/jsdhash.h +592 -0
  192. data/vendor/spidermonkey/jsdtoa.c +3167 -0
  193. data/vendor/spidermonkey/jsdtoa.h +130 -0
  194. data/vendor/spidermonkey/jsdtracef.c +317 -0
  195. data/vendor/spidermonkey/jsdtracef.h +77 -0
  196. data/vendor/spidermonkey/jsemit.c +6909 -0
  197. data/vendor/spidermonkey/jsemit.h +741 -0
  198. data/vendor/spidermonkey/jsexn.c +1371 -0
  199. data/vendor/spidermonkey/jsexn.h +96 -0
  200. data/vendor/spidermonkey/jsfile.c +2736 -0
  201. data/vendor/spidermonkey/jsfile.h +56 -0
  202. data/vendor/spidermonkey/jsfile.msg +90 -0
  203. data/vendor/spidermonkey/jsfun.c +2634 -0
  204. data/vendor/spidermonkey/jsfun.h +254 -0
  205. data/vendor/spidermonkey/jsgc.c +3554 -0
  206. data/vendor/spidermonkey/jsgc.h +403 -0
  207. data/vendor/spidermonkey/jshash.c +476 -0
  208. data/vendor/spidermonkey/jshash.h +151 -0
  209. data/vendor/spidermonkey/jsify.pl +485 -0
  210. data/vendor/spidermonkey/jsinterp.c +6981 -0
  211. data/vendor/spidermonkey/jsinterp.h +521 -0
  212. data/vendor/spidermonkey/jsinvoke.c +43 -0
  213. data/vendor/spidermonkey/jsiter.c +1067 -0
  214. data/vendor/spidermonkey/jsiter.h +122 -0
  215. data/vendor/spidermonkey/jskeyword.tbl +124 -0
  216. data/vendor/spidermonkey/jskwgen.c +460 -0
  217. data/vendor/spidermonkey/jslibmath.h +266 -0
  218. data/vendor/spidermonkey/jslock.c +1309 -0
  219. data/vendor/spidermonkey/jslock.h +313 -0
  220. data/vendor/spidermonkey/jslocko.asm +60 -0
  221. data/vendor/spidermonkey/jslog2.c +94 -0
  222. data/vendor/spidermonkey/jslong.c +264 -0
  223. data/vendor/spidermonkey/jslong.h +412 -0
  224. data/vendor/spidermonkey/jsmath.c +568 -0
  225. data/vendor/spidermonkey/jsmath.h +57 -0
  226. data/vendor/spidermonkey/jsnum.c +1228 -0
  227. data/vendor/spidermonkey/jsnum.h +283 -0
  228. data/vendor/spidermonkey/jsobj.c +5266 -0
  229. data/vendor/spidermonkey/jsobj.h +709 -0
  230. data/vendor/spidermonkey/jsopcode.c +5245 -0
  231. data/vendor/spidermonkey/jsopcode.h +394 -0
  232. data/vendor/spidermonkey/jsopcode.tbl +523 -0
  233. data/vendor/spidermonkey/jsotypes.h +202 -0
  234. data/vendor/spidermonkey/jsparse.c +6680 -0
  235. data/vendor/spidermonkey/jsparse.h +511 -0
  236. data/vendor/spidermonkey/jsprf.c +1262 -0
  237. data/vendor/spidermonkey/jsprf.h +150 -0
  238. data/vendor/spidermonkey/jsproto.tbl +128 -0
  239. data/vendor/spidermonkey/jsprvtd.h +267 -0
  240. data/vendor/spidermonkey/jspubtd.h +744 -0
  241. data/vendor/spidermonkey/jsregexp.c +4352 -0
  242. data/vendor/spidermonkey/jsregexp.h +183 -0
  243. data/vendor/spidermonkey/jsreops.tbl +145 -0
  244. data/vendor/spidermonkey/jsscan.c +2003 -0
  245. data/vendor/spidermonkey/jsscan.h +387 -0
  246. data/vendor/spidermonkey/jsscope.c +1948 -0
  247. data/vendor/spidermonkey/jsscope.h +418 -0
  248. data/vendor/spidermonkey/jsscript.c +1832 -0
  249. data/vendor/spidermonkey/jsscript.h +287 -0
  250. data/vendor/spidermonkey/jsshell.msg +50 -0
  251. data/vendor/spidermonkey/jsstddef.h +83 -0
  252. data/vendor/spidermonkey/jsstr.c +5004 -0
  253. data/vendor/spidermonkey/jsstr.h +641 -0
  254. data/vendor/spidermonkey/jstypes.h +475 -0
  255. data/vendor/spidermonkey/jsutil.c +345 -0
  256. data/vendor/spidermonkey/jsutil.h +157 -0
  257. data/vendor/spidermonkey/jsxdrapi.c +800 -0
  258. data/vendor/spidermonkey/jsxdrapi.h +218 -0
  259. data/vendor/spidermonkey/jsxml.c +8471 -0
  260. data/vendor/spidermonkey/jsxml.h +349 -0
  261. data/vendor/spidermonkey/lock_SunOS.s +119 -0
  262. data/vendor/spidermonkey/perfect.js +39 -0
  263. data/vendor/spidermonkey/plify_jsdhash.sed +36 -0
  264. data/vendor/spidermonkey/prmjtime.c +846 -0
  265. data/vendor/spidermonkey/prmjtime.h +103 -0
  266. data/vendor/spidermonkey/resource.h +15 -0
  267. data/vendor/spidermonkey/rules.mk +197 -0
  268. data/vendor/spidermonkey/win32.order +384 -0
  269. metadata +4 -3
@@ -0,0 +1,641 @@
1
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
+ *
3
+ * ***** BEGIN LICENSE BLOCK *****
4
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
+ *
6
+ * The contents of this file are subject to the Mozilla Public License Version
7
+ * 1.1 (the "License"); you may not use this file except in compliance with
8
+ * the License. You may obtain a copy of the License at
9
+ * http://www.mozilla.org/MPL/
10
+ *
11
+ * Software distributed under the License is distributed on an "AS IS" basis,
12
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
+ * for the specific language governing rights and limitations under the
14
+ * License.
15
+ *
16
+ * The Original Code is Mozilla Communicator client code, released
17
+ * March 31, 1998.
18
+ *
19
+ * The Initial Developer of the Original Code is
20
+ * Netscape Communications Corporation.
21
+ * Portions created by the Initial Developer are Copyright (C) 1998
22
+ * the Initial Developer. All Rights Reserved.
23
+ *
24
+ * Contributor(s):
25
+ *
26
+ * Alternatively, the contents of this file may be used under the terms of
27
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
28
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
+ * in which case the provisions of the GPL or the LGPL are applicable instead
30
+ * of those above. If you wish to allow use of your version of this file only
31
+ * under the terms of either the GPL or the LGPL, and not to allow others to
32
+ * use your version of this file under the terms of the MPL, indicate your
33
+ * decision by deleting the provisions above and replace them with the notice
34
+ * and other provisions required by the GPL or the LGPL. If you do not delete
35
+ * the provisions above, a recipient may use your version of this file under
36
+ * the terms of any one of the MPL, the GPL or the LGPL.
37
+ *
38
+ * ***** END LICENSE BLOCK ***** */
39
+
40
+ #ifndef jsstr_h___
41
+ #define jsstr_h___
42
+ /*
43
+ * JS string type implementation.
44
+ *
45
+ * A JS string is a counted array of unicode characters. To support handoff
46
+ * of API client memory, the chars are allocated separately from the length,
47
+ * necessitating a pointer after the count, to form a separately allocated
48
+ * string descriptor. String descriptors are GC'ed, while their chars are
49
+ * allocated from the malloc heap.
50
+ */
51
+ #include <ctype.h>
52
+ #include "jspubtd.h"
53
+ #include "jsprvtd.h"
54
+
55
+ JS_BEGIN_EXTERN_C
56
+
57
+ /*
58
+ * The GC-thing "string" type.
59
+ *
60
+ * When the JSSTRFLAG_DEPENDENT bit of the length field is unset, the u.chars
61
+ * field points to a flat character array owned by its GC-thing descriptor.
62
+ * The array is terminated at index length by a zero character and the size of
63
+ * the array in bytes is (length + 1) * sizeof(jschar). The terminator is
64
+ * purely a backstop, in case the chars pointer flows out to native code that
65
+ * requires \u0000 termination.
66
+ *
67
+ * A flat string with JSSTRFLAG_MUTABLE set means that the string is accessible
68
+ * only from one thread and it is possible to turn it into a dependent string
69
+ * of the same length to optimize js_ConcatStrings. It is also possible to grow
70
+ * such a string, but extreme care must be taken to ensure that no other code
71
+ * relies on the original length of the string.
72
+ *
73
+ * A flat string with JSSTRFLAG_ATOMIZED set means that the string is hashed as
74
+ * an atom. This flag is used to avoid re-hashing the already-atomized string.
75
+ *
76
+ * When JSSTRFLAG_DEPENDENT is set, the string depends on characters of another
77
+ * string strongly referenced by the u.base field. The base member may point to
78
+ * another dependent string if JSSTRING_CHARS has not been called yet.
79
+ *
80
+ * JSSTRFLAG_PREFIX determines the kind of the dependent string. When the flag
81
+ * is unset, the length field encodes both starting position relative to the
82
+ * base string and the number of characters in the dependent string, see
83
+ * JSSTRDEP_START_MASK and JSSTRDEP_LENGTH_MASK macros below for details.
84
+ *
85
+ * When JSSTRFLAG_PREFIX is set, the dependent string is a prefix of the base
86
+ * string. The number of characters in the prefix is encoded using all non-flag
87
+ * bits of the length field and spans the same 0 .. SIZE_T_MAX/4 range as the
88
+ * length of the flat string.
89
+ *
90
+ * NB: Always use the JSSTRING_LENGTH and JSSTRING_CHARS accessor macros.
91
+ */
92
+ struct JSString {
93
+ size_t length;
94
+ union {
95
+ jschar *chars;
96
+ JSString *base;
97
+ } u;
98
+ };
99
+
100
+ /*
101
+ * Definitions for flags stored in the high order bits of JSString.length.
102
+ * JSSTRFLAG_PREFIX and JSSTRFLAG_MUTABLE are two aliases for the same value.
103
+ * JSSTRFLAG_PREFIX should be used only if JSSTRFLAG_DEPENDENT is set and
104
+ * JSSTRFLAG_MUTABLE should be used only if the string is flat.
105
+ * JSSTRFLAG_ATOMIZED is used only with the flat immutable strings.
106
+ */
107
+ #define JSSTRFLAG_DEPENDENT JSSTRING_BIT(JS_BITS_PER_WORD - 1)
108
+ #define JSSTRFLAG_PREFIX JSSTRING_BIT(JS_BITS_PER_WORD - 2)
109
+ #define JSSTRFLAG_MUTABLE JSSTRFLAG_PREFIX
110
+ #define JSSTRFLAG_ATOMIZED JSSTRING_BIT(JS_BITS_PER_WORD - 3)
111
+
112
+ #define JSSTRING_LENGTH_BITS (JS_BITS_PER_WORD - 3)
113
+ #define JSSTRING_LENGTH_MASK JSSTRING_BITMASK(JSSTRING_LENGTH_BITS)
114
+
115
+ /* Universal JSString type inquiry and accessor macros. */
116
+ #define JSSTRING_BIT(n) ((size_t)1 << (n))
117
+ #define JSSTRING_BITMASK(n) (JSSTRING_BIT(n) - 1)
118
+ #define JSSTRING_HAS_FLAG(str,flg) ((str)->length & (flg))
119
+ #define JSSTRING_IS_DEPENDENT(str) JSSTRING_HAS_FLAG(str, JSSTRFLAG_DEPENDENT)
120
+ #define JSSTRING_IS_FLAT(str) (!JSSTRING_IS_DEPENDENT(str))
121
+ #define JSSTRING_IS_MUTABLE(str) (((str)->length & (JSSTRFLAG_DEPENDENT | \
122
+ JSSTRFLAG_MUTABLE)) == \
123
+ JSSTRFLAG_MUTABLE)
124
+ #define JSSTRING_IS_ATOMIZED(str) (((str)->length & (JSSTRFLAG_DEPENDENT | \
125
+ JSSTRFLAG_ATOMIZED)) ==\
126
+ JSSTRFLAG_ATOMIZED)
127
+
128
+ #define JSSTRING_CHARS(str) (JSSTRING_IS_DEPENDENT(str) \
129
+ ? JSSTRDEP_CHARS(str) \
130
+ : JSFLATSTR_CHARS(str))
131
+ #define JSSTRING_LENGTH(str) (JSSTRING_IS_DEPENDENT(str) \
132
+ ? JSSTRDEP_LENGTH(str) \
133
+ : JSFLATSTR_LENGTH(str))
134
+
135
+ #define JSSTRING_CHARS_AND_LENGTH(str, chars_, length_) \
136
+ ((void)(JSSTRING_IS_DEPENDENT(str) \
137
+ ? ((length_) = JSSTRDEP_LENGTH(str), \
138
+ (chars_) = JSSTRDEP_CHARS(str)) \
139
+ : ((length_) = JSFLATSTR_LENGTH(str), \
140
+ (chars_) = JSFLATSTR_CHARS(str))))
141
+
142
+ #define JSSTRING_CHARS_AND_END(str, chars_, end) \
143
+ ((void)((end) = JSSTRING_IS_DEPENDENT(str) \
144
+ ? JSSTRDEP_LENGTH(str) + ((chars_) = JSSTRDEP_CHARS(str)) \
145
+ : JSFLATSTR_LENGTH(str) + ((chars_) = JSFLATSTR_CHARS(str))))
146
+
147
+ /* Specific flat string initializer and accessor macros. */
148
+ #define JSFLATSTR_INIT(str, chars_, length_) \
149
+ ((void)(JS_ASSERT(((length_) & ~JSSTRING_LENGTH_MASK) == 0), \
150
+ (str)->length = (length_), (str)->u.chars = (chars_)))
151
+
152
+ #define JSFLATSTR_LENGTH(str) \
153
+ (JS_ASSERT(JSSTRING_IS_FLAT(str)), (str)->length & JSSTRING_LENGTH_MASK)
154
+
155
+ #define JSFLATSTR_CHARS(str) \
156
+ (JS_ASSERT(JSSTRING_IS_FLAT(str)), (str)->u.chars)
157
+
158
+ /*
159
+ * Macros to manipulate atomized and mutable flags of flat strings. It is safe
160
+ * to use these without extra locking due to the following properties:
161
+ *
162
+ * * We do not have a macro like JSFLATSTR_CLEAR_ATOMIZED as a string
163
+ * remains atomized until the GC collects it.
164
+ *
165
+ * * A thread may call JSFLATSTR_SET_MUTABLE only when it is the only thread
166
+ * accessing the string until a later call to JSFLATSTR_CLEAR_MUTABLE.
167
+ *
168
+ * * Multiple threads can call JSFLATSTR_CLEAR_MUTABLE but the macro
169
+ * actually clears the mutable flag only when the flag is set -- in which
170
+ * case only one thread can access the string (see previous property).
171
+ *
172
+ * Thus, when multiple threads access the string, JSFLATSTR_SET_ATOMIZED is
173
+ * the only macro that can update the length field of the string by changing
174
+ * the mutable bit from 0 to 1. We call the macro only after the string has
175
+ * been hashed. When some threads in js_ValueToStringId see that the flag is
176
+ * set, it knows that the string was atomized.
177
+ *
178
+ * On the other hand, if the thread sees that the flag is unset, it could be
179
+ * seeing a stale value when another thread has just atomized the string and
180
+ * set the flag. But this can lead only to an extra call to js_AtomizeString.
181
+ * This function would find that the string was already hashed and return it
182
+ * with the atomized bit set.
183
+ */
184
+ #define JSFLATSTR_SET_ATOMIZED(str) \
185
+ ((void)(JS_ASSERT(JSSTRING_IS_FLAT(str) && !JSSTRING_IS_MUTABLE(str)), \
186
+ (str)->length |= JSSTRFLAG_ATOMIZED))
187
+
188
+ #define JSFLATSTR_SET_MUTABLE(str) \
189
+ ((void)(JS_ASSERT(JSSTRING_IS_FLAT(str) && !JSSTRING_IS_ATOMIZED(str)), \
190
+ (str)->length |= JSSTRFLAG_MUTABLE))
191
+
192
+ #define JSFLATSTR_CLEAR_MUTABLE(str) \
193
+ ((void)(JS_ASSERT(JSSTRING_IS_FLAT(str)), \
194
+ JSSTRING_HAS_FLAG(str, JSSTRFLAG_MUTABLE) && \
195
+ ((str)->length &= ~JSSTRFLAG_MUTABLE)))
196
+
197
+ /* Specific dependent string shift/mask accessor and mutator macros. */
198
+ #define JSSTRDEP_START_BITS (JSSTRING_LENGTH_BITS-JSSTRDEP_LENGTH_BITS)
199
+ #define JSSTRDEP_START_SHIFT JSSTRDEP_LENGTH_BITS
200
+ #define JSSTRDEP_START_MASK JSSTRING_BITMASK(JSSTRDEP_START_BITS)
201
+ #define JSSTRDEP_LENGTH_BITS (JSSTRING_LENGTH_BITS / 2)
202
+ #define JSSTRDEP_LENGTH_MASK JSSTRING_BITMASK(JSSTRDEP_LENGTH_BITS)
203
+
204
+ #define JSSTRDEP_IS_PREFIX(str) JSSTRING_HAS_FLAG(str, JSSTRFLAG_PREFIX)
205
+
206
+ #define JSSTRDEP_START(str) (JSSTRDEP_IS_PREFIX(str) ? 0 \
207
+ : (((str)->length \
208
+ >> JSSTRDEP_START_SHIFT) \
209
+ & JSSTRDEP_START_MASK))
210
+ #define JSSTRDEP_LENGTH(str) ((str)->length \
211
+ & (JSSTRDEP_IS_PREFIX(str) \
212
+ ? JSSTRING_LENGTH_MASK \
213
+ : JSSTRDEP_LENGTH_MASK))
214
+
215
+ #define JSSTRDEP_INIT(str,bstr,off,len) \
216
+ ((str)->length = JSSTRFLAG_DEPENDENT \
217
+ | ((off) << JSSTRDEP_START_SHIFT) \
218
+ | (len), \
219
+ (str)->u.base = (bstr))
220
+
221
+ #define JSPREFIX_INIT(str,bstr,len) \
222
+ ((str)->length = JSSTRFLAG_DEPENDENT | JSSTRFLAG_PREFIX | (len), \
223
+ (str)->u.base = (bstr))
224
+
225
+ #define JSSTRDEP_BASE(str) ((str)->u.base)
226
+ #define JSPREFIX_BASE(str) JSSTRDEP_BASE(str)
227
+ #define JSPREFIX_SET_BASE(str,bstr) ((str)->u.base = (bstr))
228
+
229
+ #define JSSTRDEP_CHARS(str) \
230
+ (JSSTRING_IS_DEPENDENT(JSSTRDEP_BASE(str)) \
231
+ ? js_GetDependentStringChars(str) \
232
+ : JSFLATSTR_CHARS(JSSTRDEP_BASE(str)) + JSSTRDEP_START(str))
233
+
234
+ extern size_t
235
+ js_MinimizeDependentStrings(JSString *str, int level, JSString **basep);
236
+
237
+ extern jschar *
238
+ js_GetDependentStringChars(JSString *str);
239
+
240
+ extern const jschar *
241
+ js_GetStringChars(JSContext *cx, JSString *str);
242
+
243
+ extern JSString *
244
+ js_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
245
+
246
+ extern const jschar *
247
+ js_UndependString(JSContext *cx, JSString *str);
248
+
249
+ extern JSBool
250
+ js_MakeStringImmutable(JSContext *cx, JSString *str);
251
+
252
+ typedef struct JSCharBuffer {
253
+ size_t length;
254
+ jschar *chars;
255
+ } JSCharBuffer;
256
+
257
+ struct JSSubString {
258
+ size_t length;
259
+ const jschar *chars;
260
+ };
261
+
262
+ extern jschar js_empty_ucstr[];
263
+ extern JSSubString js_EmptySubString;
264
+
265
+ /* Unicode character attribute lookup tables. */
266
+ extern const uint8 js_X[];
267
+ extern const uint8 js_Y[];
268
+ extern const uint32 js_A[];
269
+
270
+ /* Enumerated Unicode general category types. */
271
+ typedef enum JSCharType {
272
+ JSCT_UNASSIGNED = 0,
273
+ JSCT_UPPERCASE_LETTER = 1,
274
+ JSCT_LOWERCASE_LETTER = 2,
275
+ JSCT_TITLECASE_LETTER = 3,
276
+ JSCT_MODIFIER_LETTER = 4,
277
+ JSCT_OTHER_LETTER = 5,
278
+ JSCT_NON_SPACING_MARK = 6,
279
+ JSCT_ENCLOSING_MARK = 7,
280
+ JSCT_COMBINING_SPACING_MARK = 8,
281
+ JSCT_DECIMAL_DIGIT_NUMBER = 9,
282
+ JSCT_LETTER_NUMBER = 10,
283
+ JSCT_OTHER_NUMBER = 11,
284
+ JSCT_SPACE_SEPARATOR = 12,
285
+ JSCT_LINE_SEPARATOR = 13,
286
+ JSCT_PARAGRAPH_SEPARATOR = 14,
287
+ JSCT_CONTROL = 15,
288
+ JSCT_FORMAT = 16,
289
+ JSCT_PRIVATE_USE = 18,
290
+ JSCT_SURROGATE = 19,
291
+ JSCT_DASH_PUNCTUATION = 20,
292
+ JSCT_START_PUNCTUATION = 21,
293
+ JSCT_END_PUNCTUATION = 22,
294
+ JSCT_CONNECTOR_PUNCTUATION = 23,
295
+ JSCT_OTHER_PUNCTUATION = 24,
296
+ JSCT_MATH_SYMBOL = 25,
297
+ JSCT_CURRENCY_SYMBOL = 26,
298
+ JSCT_MODIFIER_SYMBOL = 27,
299
+ JSCT_OTHER_SYMBOL = 28
300
+ } JSCharType;
301
+
302
+ /* Character classifying and mapping macros, based on java.lang.Character. */
303
+ #define JS_CCODE(c) (js_A[js_Y[(js_X[(uint16)(c)>>6]<<6)|((c)&0x3F)]])
304
+ #define JS_CTYPE(c) (JS_CCODE(c) & 0x1F)
305
+
306
+ #define JS_ISALPHA(c) ((((1 << JSCT_UPPERCASE_LETTER) | \
307
+ (1 << JSCT_LOWERCASE_LETTER) | \
308
+ (1 << JSCT_TITLECASE_LETTER) | \
309
+ (1 << JSCT_MODIFIER_LETTER) | \
310
+ (1 << JSCT_OTHER_LETTER)) \
311
+ >> JS_CTYPE(c)) & 1)
312
+
313
+ #define JS_ISALNUM(c) ((((1 << JSCT_UPPERCASE_LETTER) | \
314
+ (1 << JSCT_LOWERCASE_LETTER) | \
315
+ (1 << JSCT_TITLECASE_LETTER) | \
316
+ (1 << JSCT_MODIFIER_LETTER) | \
317
+ (1 << JSCT_OTHER_LETTER) | \
318
+ (1 << JSCT_DECIMAL_DIGIT_NUMBER)) \
319
+ >> JS_CTYPE(c)) & 1)
320
+
321
+ /* A unicode letter, suitable for use in an identifier. */
322
+ #define JS_ISLETTER(c) ((((1 << JSCT_UPPERCASE_LETTER) | \
323
+ (1 << JSCT_LOWERCASE_LETTER) | \
324
+ (1 << JSCT_TITLECASE_LETTER) | \
325
+ (1 << JSCT_MODIFIER_LETTER) | \
326
+ (1 << JSCT_OTHER_LETTER) | \
327
+ (1 << JSCT_LETTER_NUMBER)) \
328
+ >> JS_CTYPE(c)) & 1)
329
+
330
+ /*
331
+ * 'IdentifierPart' from ECMA grammar, is Unicode letter or combining mark or
332
+ * digit or connector punctuation.
333
+ */
334
+ #define JS_ISIDPART(c) ((((1 << JSCT_UPPERCASE_LETTER) | \
335
+ (1 << JSCT_LOWERCASE_LETTER) | \
336
+ (1 << JSCT_TITLECASE_LETTER) | \
337
+ (1 << JSCT_MODIFIER_LETTER) | \
338
+ (1 << JSCT_OTHER_LETTER) | \
339
+ (1 << JSCT_LETTER_NUMBER) | \
340
+ (1 << JSCT_NON_SPACING_MARK) | \
341
+ (1 << JSCT_COMBINING_SPACING_MARK) | \
342
+ (1 << JSCT_DECIMAL_DIGIT_NUMBER) | \
343
+ (1 << JSCT_CONNECTOR_PUNCTUATION)) \
344
+ >> JS_CTYPE(c)) & 1)
345
+
346
+ /* Unicode control-format characters, ignored in input */
347
+ #define JS_ISFORMAT(c) (((1 << JSCT_FORMAT) >> JS_CTYPE(c)) & 1)
348
+
349
+ /*
350
+ * Per ECMA-262 15.10.2.6, these characters are the only ones that make up a
351
+ * "word", as far as a RegExp is concerned. If we want a Unicode-friendlier
352
+ * definition of "word", we should rename this macro to something regexp-y.
353
+ */
354
+ #define JS_ISWORD(c) ((c) < 128 && (isalnum(c) || (c) == '_'))
355
+
356
+ #define JS_ISIDSTART(c) (JS_ISLETTER(c) || (c) == '_' || (c) == '$')
357
+ #define JS_ISIDENT(c) (JS_ISIDPART(c) || (c) == '_' || (c) == '$')
358
+
359
+ #define JS_ISXMLSPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || \
360
+ (c) == '\n')
361
+ #define JS_ISXMLNSSTART(c) ((JS_CCODE(c) & 0x00000100) || (c) == '_')
362
+ #define JS_ISXMLNS(c) ((JS_CCODE(c) & 0x00000080) || (c) == '.' || \
363
+ (c) == '-' || (c) == '_')
364
+ #define JS_ISXMLNAMESTART(c) (JS_ISXMLNSSTART(c) || (c) == ':')
365
+ #define JS_ISXMLNAME(c) (JS_ISXMLNS(c) || (c) == ':')
366
+
367
+ #define JS_ISDIGIT(c) (JS_CTYPE(c) == JSCT_DECIMAL_DIGIT_NUMBER)
368
+
369
+ /* XXXbe unify on A/X/Y tbls, avoid ctype.h? */
370
+ /* XXXbe fs, etc. ? */
371
+ #define JS_ISSPACE(c) ((JS_CCODE(c) & 0x00070000) == 0x00040000)
372
+ #define JS_ISPRINT(c) ((c) < 128 && isprint(c))
373
+
374
+ #define JS_ISUPPER(c) (JS_CTYPE(c) == JSCT_UPPERCASE_LETTER)
375
+ #define JS_ISLOWER(c) (JS_CTYPE(c) == JSCT_LOWERCASE_LETTER)
376
+
377
+ #define JS_TOUPPER(c) ((jschar) ((JS_CCODE(c) & 0x00100000) \
378
+ ? (c) - ((int32)JS_CCODE(c) >> 22) \
379
+ : (c)))
380
+ #define JS_TOLOWER(c) ((jschar) ((JS_CCODE(c) & 0x00200000) \
381
+ ? (c) + ((int32)JS_CCODE(c) >> 22) \
382
+ : (c)))
383
+
384
+ /*
385
+ * Shorthands for ASCII (7-bit) decimal and hex conversion.
386
+ * Manually inline isdigit for performance; MSVC doesn't do this for us.
387
+ */
388
+ #define JS7_ISDEC(c) ((((unsigned)(c)) - '0') <= 9)
389
+ #define JS7_UNDEC(c) ((c) - '0')
390
+ #define JS7_ISHEX(c) ((c) < 128 && isxdigit(c))
391
+ #define JS7_UNHEX(c) (uintN)(JS7_ISDEC(c) ? (c) - '0' : 10 + tolower(c) - 'a')
392
+ #define JS7_ISLET(c) ((c) < 128 && isalpha(c))
393
+
394
+ /* Initialize per-runtime string state for the first context in the runtime. */
395
+ extern JSBool
396
+ js_InitRuntimeStringState(JSContext *cx);
397
+
398
+ extern JSBool
399
+ js_InitDeflatedStringCache(JSRuntime *rt);
400
+
401
+ /*
402
+ * Maximum character code for which we will create a pinned unit string on
403
+ * demand -- see JSRuntime.unitStrings in jscntxt.h.
404
+ */
405
+ #define UNIT_STRING_LIMIT 256U
406
+
407
+ /*
408
+ * Get the independent string containing only character code at index in str
409
+ * (backstopped with a zero character as usual for independent strings).
410
+ */
411
+ extern JSString *
412
+ js_GetUnitString(JSContext *cx, JSString *str, size_t index);
413
+
414
+ extern void
415
+ js_FinishUnitStrings(JSRuntime *rt);
416
+
417
+ extern void
418
+ js_FinishRuntimeStringState(JSContext *cx);
419
+
420
+ extern void
421
+ js_FinishDeflatedStringCache(JSRuntime *rt);
422
+
423
+ /* Initialize the String class, returning its prototype object. */
424
+ extern JSClass js_StringClass;
425
+
426
+ extern JSObject *
427
+ js_InitStringClass(JSContext *cx, JSObject *obj);
428
+
429
+ extern const char js_escape_str[];
430
+ extern const char js_unescape_str[];
431
+ extern const char js_uneval_str[];
432
+ extern const char js_decodeURI_str[];
433
+ extern const char js_encodeURI_str[];
434
+ extern const char js_decodeURIComponent_str[];
435
+ extern const char js_encodeURIComponent_str[];
436
+
437
+ /* GC-allocate a string descriptor for the given malloc-allocated chars. */
438
+ extern JSString *
439
+ js_NewString(JSContext *cx, jschar *chars, size_t length);
440
+
441
+ extern JSString *
442
+ js_NewDependentString(JSContext *cx, JSString *base, size_t start,
443
+ size_t length);
444
+
445
+ /* Copy a counted string and GC-allocate a descriptor for it. */
446
+ extern JSString *
447
+ js_NewStringCopyN(JSContext *cx, const jschar *s, size_t n);
448
+
449
+ /* Copy a C string and GC-allocate a descriptor for it. */
450
+ extern JSString *
451
+ js_NewStringCopyZ(JSContext *cx, const jschar *s);
452
+
453
+ /*
454
+ * Free the chars held by str when it is finalized by the GC. When type is
455
+ * less then zero, it denotes an internal string. Otherwise it denotes the
456
+ * type of the external string allocated with JS_NewExternalString.
457
+ *
458
+ * This function always needs rt but can live with null cx.
459
+ */
460
+ extern void
461
+ js_FinalizeStringRT(JSRuntime *rt, JSString *str, intN type, JSContext *cx);
462
+
463
+ /*
464
+ * Convert a value to a printable C string.
465
+ */
466
+ typedef JSString *(*JSValueToStringFun)(JSContext *cx, jsval v);
467
+
468
+ extern JS_FRIEND_API(const char *)
469
+ js_ValueToPrintable(JSContext *cx, jsval v, JSValueToStringFun v2sfun);
470
+
471
+ #define js_ValueToPrintableString(cx,v) \
472
+ js_ValueToPrintable(cx, v, js_ValueToString)
473
+
474
+ #define js_ValueToPrintableSource(cx,v) \
475
+ js_ValueToPrintable(cx, v, js_ValueToSource)
476
+
477
+ /*
478
+ * Convert a value to a string, returning null after reporting an error,
479
+ * otherwise returning a new string reference.
480
+ */
481
+ extern JS_FRIEND_API(JSString *)
482
+ js_ValueToString(JSContext *cx, jsval v);
483
+
484
+ /*
485
+ * Convert a value to its source expression, returning null after reporting
486
+ * an error, otherwise returning a new string reference.
487
+ */
488
+ extern JS_FRIEND_API(JSString *)
489
+ js_ValueToSource(JSContext *cx, jsval v);
490
+
491
+ /*
492
+ * Compute a hash function from str. The caller can call this function even if
493
+ * str is not a GC-allocated thing.
494
+ */
495
+ extern uint32
496
+ js_HashString(JSString *str);
497
+
498
+ /*
499
+ * Test if strings are equal. The caller can call the function even if str1
500
+ * or str2 are not GC-allocated things.
501
+ */
502
+ extern JSBool
503
+ js_EqualStrings(JSString *str1, JSString *str2);
504
+
505
+ /*
506
+ * Return less than, equal to, or greater than zero depending on whether
507
+ * str1 is less than, equal to, or greater than str2.
508
+ */
509
+ extern intN
510
+ js_CompareStrings(JSString *str1, JSString *str2);
511
+
512
+ /*
513
+ * Boyer-Moore-Horspool superlinear search for pat:patlen in text:textlen.
514
+ * The patlen argument must be positive and no greater than BMH_PATLEN_MAX.
515
+ * The start argument tells where in text to begin the search.
516
+ *
517
+ * Return the index of pat in text, or -1 if not found.
518
+ */
519
+ #define BMH_CHARSET_SIZE 256 /* ISO-Latin-1 */
520
+ #define BMH_PATLEN_MAX 255 /* skip table element is uint8 */
521
+
522
+ #define BMH_BAD_PATTERN (-2) /* return value if pat is not ISO-Latin-1 */
523
+
524
+ extern jsint
525
+ js_BoyerMooreHorspool(const jschar *text, jsint textlen,
526
+ const jschar *pat, jsint patlen,
527
+ jsint start);
528
+
529
+ extern size_t
530
+ js_strlen(const jschar *s);
531
+
532
+ extern jschar *
533
+ js_strchr(const jschar *s, jschar c);
534
+
535
+ extern jschar *
536
+ js_strchr_limit(const jschar *s, jschar c, const jschar *limit);
537
+
538
+ #define js_strncpy(t, s, n) memcpy((t), (s), (n) * sizeof(jschar))
539
+
540
+ /*
541
+ * Return s advanced past any Unicode white space characters.
542
+ */
543
+ extern const jschar *
544
+ js_SkipWhiteSpace(const jschar *s, const jschar *end);
545
+
546
+ /*
547
+ * Inflate bytes to JS chars and vice versa. Report out of memory via cx
548
+ * and return null on error, otherwise return the jschar or byte vector that
549
+ * was JS_malloc'ed. length is updated with the length of the new string in jschars.
550
+ */
551
+ extern jschar *
552
+ js_InflateString(JSContext *cx, const char *bytes, size_t *length);
553
+
554
+ extern char *
555
+ js_DeflateString(JSContext *cx, const jschar *chars, size_t length);
556
+
557
+ /*
558
+ * Inflate bytes to JS chars into a buffer. 'chars' must be large enough for
559
+ * 'length' jschars. The buffer is NOT null-terminated. The destination length
560
+ * must be be initialized with the buffer size and will contain on return the
561
+ * number of copied chars.
562
+ */
563
+ extern JSBool
564
+ js_InflateStringToBuffer(JSContext* cx, const char *bytes, size_t length,
565
+ jschar *chars, size_t* charsLength);
566
+
567
+ /*
568
+ * Get number of bytes in the deflated sequence of characters.
569
+ */
570
+ extern size_t
571
+ js_GetDeflatedStringLength(JSContext *cx, const jschar *chars,
572
+ size_t charsLength);
573
+
574
+ /*
575
+ * Deflate JS chars to bytes into a buffer. 'bytes' must be large enough for
576
+ * 'length chars. The buffer is NOT null-terminated. The destination length
577
+ * must to be initialized with the buffer size and will contain on return the
578
+ * number of copied bytes.
579
+ */
580
+ extern JSBool
581
+ js_DeflateStringToBuffer(JSContext* cx, const jschar *chars,
582
+ size_t charsLength, char *bytes, size_t* length);
583
+
584
+ /*
585
+ * Associate bytes with str in the deflated string cache, returning true on
586
+ * successful association, false on out of memory.
587
+ */
588
+ extern JSBool
589
+ js_SetStringBytes(JSContext *cx, JSString *str, char *bytes, size_t length);
590
+
591
+ /*
592
+ * Find or create a deflated string cache entry for str that contains its
593
+ * characters chopped from Unicode code points into bytes.
594
+ */
595
+ extern const char *
596
+ js_GetStringBytes(JSContext *cx, JSString *str);
597
+
598
+ /* Remove a deflated string cache entry associated with str if any. */
599
+ extern void
600
+ js_PurgeDeflatedStringCache(JSRuntime *rt, JSString *str);
601
+
602
+ JSBool
603
+ js_str_escape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
604
+ jsval *rval);
605
+
606
+ /*
607
+ * Convert one UCS-4 char and write it into a UTF-8 buffer, which must be at
608
+ * least 6 bytes long. Return the number of UTF-8 bytes of data written.
609
+ */
610
+ extern int
611
+ js_OneUcs4ToUtf8Char(uint8 *utf8Buffer, uint32 ucs4Char);
612
+
613
+ /*
614
+ * Write str into buffer escaping any non-printable or non-ASCII character.
615
+ * Guarantees that a NUL is at the end of the buffer. Returns the length of
616
+ * the written output, NOT including the NUL. If buffer is null, just returns
617
+ * the length of the output. If quote is not 0, it must be a single or double
618
+ * quote character that will quote the output.
619
+ *
620
+ * The function is only defined for debug builds.
621
+ */
622
+ #define js_PutEscapedString(buffer, bufferSize, str, quote) \
623
+ js_PutEscapedStringImpl(buffer, bufferSize, NULL, str, quote)
624
+
625
+ /*
626
+ * Write str into file escaping any non-printable or non-ASCII character.
627
+ * Returns the number of bytes written to file. If quote is not 0, it must
628
+ * be a single or double quote character that will quote the output.
629
+ *
630
+ * The function is only defined for debug builds.
631
+ */
632
+ #define js_FileEscapedString(file, str, quote) \
633
+ (JS_ASSERT(file), js_PutEscapedStringImpl(NULL, 0, file, str, quote))
634
+
635
+ extern JS_FRIEND_API(size_t)
636
+ js_PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp,
637
+ JSString *str, uint32 quote);
638
+
639
+ JS_END_EXTERN_C
640
+
641
+ #endif /* jsstr_h___ */