3 typedef double double_t;
4 extern double acos (double __x) throw (); extern double __acos (double __x) throw ();
5 extern double asin (double __x) throw (); extern double __asin (double __x) throw ();
6 extern double atan (double __x) throw (); extern double __atan (double __x) throw ();
7 extern double atan2 (double __y, double __x) throw (); extern double __atan2 (double __y, double __x) throw ();
8 extern double cos (double __x) throw (); extern double __cos (double __x) throw ();
9 extern double sin (double __x) throw (); extern double __sin (double __x) throw ();
10 extern double tan (double __x) throw (); extern double __tan (double __x) throw ();
11 extern double cosh (double __x) throw (); extern double __cosh (double __x) throw ();
12 extern double sinh (double __x) throw (); extern double __sinh (double __x) throw ();
13 extern double tanh (double __x) throw (); extern double __tanh (double __x) throw ();
14 extern void sincos (double __x, double *__sinx, double *__cosx) throw (); extern void __sincos (double __x, double *__sinx, double *__cosx) throw ()
16 extern double acosh (double __x) throw (); extern double __acosh (double __x) throw ();
17 extern double asinh (double __x) throw (); extern double __asinh (double __x) throw ();
18 extern double atanh (double __x) throw (); extern double __atanh (double __x) throw ();
19 extern double exp (double __x) throw (); extern double __exp (double __x) throw ();
20 extern double frexp (double __x, int *__exponent) throw (); extern double __frexp (double __x, int *__exponent) throw ();
21 extern double ldexp (double __x, int __exponent) throw (); extern double __ldexp (double __x, int __exponent) throw ();
22 extern double log (double __x) throw (); extern double __log (double __x) throw ();
23 extern double log10 (double __x) throw (); extern double __log10 (double __x) throw ();
24 extern double modf (double __x, double *__iptr) throw (); extern double __modf (double __x, double *__iptr) throw () __attribute__ ((__nonnull__ (2)));
25 extern double exp10 (double __x) throw (); extern double __exp10 (double __x) throw ();
26 extern double pow10 (double __x) throw (); extern double __pow10 (double __x) throw ();
27 extern double expm1 (double __x) throw (); extern double __expm1 (double __x) throw ();
28 extern double log1p (double __x) throw (); extern double __log1p (double __x) throw ();
29 extern double logb (double __x) throw (); extern double __logb (double __x) throw ();
30 extern double exp2 (double __x) throw (); extern double __exp2 (double __x) throw ();
31 extern double log2 (double __x) throw (); extern double __log2 (double __x) throw ();
32 extern double pow (double __x, double __y) throw (); extern double __pow (double __x, double __y) throw ();
33 extern double sqrt (double __x) throw (); extern double __sqrt (double __x) throw ();
34 extern double hypot (double __x, double __y) throw (); extern double __hypot (double __x, double __y) throw ();
35 extern double cbrt (double __x) throw (); extern double __cbrt (double __x) throw ();
36 extern double ceil (double __x) throw () __attribute__ ((__const__)); extern double __ceil (double __x) throw () __attribute__ ((__const__));
37 extern double fabs (double __x) throw () __attribute__ ((__const__)); extern double __fabs (double __x) throw () __attribute__ ((__const__));
38 extern double floor (double __x) throw () __attribute__ ((__const__)); extern double __floor (double __x) throw () __attribute__ ((__const__));
39 extern double fmod (double __x, double __y) throw (); extern double __fmod (double __x, double __y) throw ();
40 extern int __isinf (double __value) throw () __attribute__ ((__const__));
41 extern int __finite (double __value) throw () __attribute__ ((__const__));
42 extern int isinf (double __value) throw () __attribute__ ((__const__));
43 extern int finite (double __value) throw () __attribute__ ((__const__));
44 extern double drem (double __x, double __y) throw (); extern double __drem (double __x, double __y) throw ();
45 extern double significand (double __x) throw (); extern double __significand (double __x) throw ();
46 extern double copysign (double __x, double __y) throw () __attribute__ ((__const__)); extern double __copysign (double __x, double __y) throw () __attribute__ ((__const__));
47 extern double nan (const char *__tagb) throw () __attribute__ ((__const__)); extern double __nan (const char *__tagb) throw () __attribute__ ((__const__));
48 extern int __isnan (double __value) throw () __attribute__ ((__const__));
49 extern int isnan (double __value) throw () __attribute__ ((__const__));
50 extern double j0 (double) throw (); extern double __j0 (double) throw ();
51 extern double j1 (double) throw (); extern double __j1 (double) throw ();
52 extern double jn (int, double) throw (); extern double __jn (int, double) throw ();
53 extern double y0 (double) throw (); extern double __y0 (double) throw ();
54 extern double y1 (double) throw (); extern double __y1 (double) throw ();
55 extern double yn (int, double) throw (); extern double __yn (int, double) throw ();
56 extern double erf (double) throw (); extern double __erf (double) throw ();
57 extern double erfc (double) throw (); extern double __erfc (double) throw ();
58 extern double lgamma (double) throw (); extern double __lgamma (double) throw ();
59 extern double tgamma (double) throw (); extern double __tgamma (double) throw ();
60 extern double gamma (double) throw (); extern double __gamma (double) throw ();
61 extern double lgamma_r (double, int *__signgamp) throw (); extern double __lgamma_r (double, int *__signgamp) throw ();
62 extern double rint (double __x) throw (); extern double __rint (double __x) throw ();
63 extern double nextafter (double __x, double __y) throw () __attribute__ ((__const__)); extern double __nextafter (double __x, double __y) throw () __attribute__ ((__const__));
64 extern double nexttoward (double __x, long double __y) throw () __attribute__ ((__const__)); extern double __nexttoward (double __x, long double __y) throw () __attribute__ ((__const__));
65 extern double remainder (double __x, double __y) throw (); extern double __remainder (double __x, double __y) throw ();
66 extern double scalbn (double __x, int __n) throw (); extern double __scalbn (double __x, int __n) throw ();
67 extern int ilogb (double __x) throw (); extern int __ilogb (double __x) throw ();
68 extern double scalbln (double __x, long int __n) throw (); extern double __scalbln (double __x, long int __n) throw ();
69 extern double nearbyint (double __x) throw (); extern double __nearbyint (double __x) throw ();
70 extern double round (double __x) throw () __attribute__ ((__const__)); extern double __round (double __x) throw () __attribute__ ((__const__));
71 extern double trunc (double __x) throw () __attribute__ ((__const__)); extern double __trunc (double __x) throw () __attribute__ ((__const__));
72 extern double remquo (double __x, double __y, int *__quo) throw (); extern double __remquo (double __x, double __y, int *__quo) throw ();
73 extern long int lrint (double __x) throw (); extern long int __lrint (double __x) throw ();
75 extern long long int llrint (double __x) throw (); extern long long int __llrint (double __x) throw ();
76 extern long int lround (double __x) throw (); extern long int __lround (double __x) throw ();
78 extern long long int llround (double __x) throw (); extern long long int __llround (double __x) throw ();
79 extern double fdim (double __x, double __y) throw (); extern double __fdim (double __x, double __y) throw ();
80 extern double fmax (double __x, double __y) throw () __attribute__ ((__const__)); extern double __fmax (double __x, double __y) throw () __attribute__ ((__const__));
81 extern double fmin (double __x, double __y) throw () __attribute__ ((__const__)); extern double __fmin (double __x, double __y) throw () __attribute__ ((__const__));
82 extern int __fpclassify (double __value) throw ()
83 __attribute__ ((__const__));
84 extern int __signbit (double __value) throw ()
85 __attribute__ ((__const__));
86 extern double fma (double __x, double __y, double __z) throw (); extern double __fma (double __x, double __y, double __z) throw ();
87 extern int __issignaling (double __value) throw ()
88 __attribute__ ((__const__));
89 extern double scalb (double __x, double __n) throw (); extern double __scalb (double __x, double __n) throw ();
90 extern float acosf (float __x) throw (); extern float __acosf (float __x) throw ();
91 extern float asinf (float __x) throw (); extern float __asinf (float __x) throw ();
92 extern float atanf (float __x) throw (); extern float __atanf (float __x) throw ();
93 extern float atan2f (float __y, float __x) throw (); extern float __atan2f (float __y, float __x) throw ();
94 extern float cosf (float __x) throw (); extern float __cosf (float __x) throw ();
95 extern float sinf (float __x) throw (); extern float __sinf (float __x) throw ();
96 extern float tanf (float __x) throw (); extern float __tanf (float __x) throw ();
97 extern float coshf (float __x) throw (); extern float __coshf (float __x) throw ();
98 extern float sinhf (float __x) throw (); extern float __sinhf (float __x) throw ();
99 extern float tanhf (float __x) throw (); extern float __tanhf (float __x) throw ();
100 extern void sincosf (float __x, float *__sinx, float *__cosx) throw (); extern void __sincosf (float __x, float *__sinx, float *__cosx) throw ()
102 extern float acoshf (float __x) throw (); extern float __acoshf (float __x) throw ();
103 extern float asinhf (float __x) throw (); extern float __asinhf (float __x) throw ();
104 extern float atanhf (float __x) throw (); extern float __atanhf (float __x) throw ();
105 extern float expf (float __x) throw (); extern float __expf (float __x) throw ();
106 extern float frexpf (float __x, int *__exponent) throw (); extern float __frexpf (float __x, int *__exponent) throw ();
107 extern float ldexpf (float __x, int __exponent) throw (); extern float __ldexpf (float __x, int __exponent) throw ();
108 extern float logf (float __x) throw (); extern float __logf (float __x) throw ();
109 extern float log10f (float __x) throw (); extern float __log10f (float __x) throw ();
110 extern float modff (float __x, float *__iptr) throw (); extern float __modff (float __x, float *__iptr) throw () __attribute__ ((__nonnull__ (2)));
111 extern float exp10f (float __x) throw (); extern float __exp10f (float __x) throw ();
112 extern float pow10f (float __x) throw (); extern float __pow10f (float __x) throw ();
113 extern float expm1f (float __x) throw (); extern float __expm1f (float __x) throw ();
114 extern float log1pf (float __x) throw (); extern float __log1pf (float __x) throw ();
115 extern float logbf (float __x) throw (); extern float __logbf (float __x) throw ();
116 extern float exp2f (float __x) throw (); extern float __exp2f (float __x) throw ();
117 extern float log2f (float __x) throw (); extern float __log2f (float __x) throw ();
118 extern float powf (float __x, float __y) throw (); extern float __powf (float __x, float __y) throw ();
119 extern float sqrtf (float __x) throw (); extern float __sqrtf (float __x) throw ();
120 extern float hypotf (float __x, float __y) throw (); extern float __hypotf (float __x, float __y) throw ();
121 extern float cbrtf (float __x) throw (); extern float __cbrtf (float __x) throw ();
122 extern float ceilf (float __x) throw () __attribute__ ((__const__)); extern float __ceilf (float __x) throw () __attribute__ ((__const__));
123 extern float fabsf (float __x) throw () __attribute__ ((__const__)); extern float __fabsf (float __x) throw () __attribute__ ((__const__));
124 extern float floorf (float __x) throw () __attribute__ ((__const__)); extern float __floorf (float __x) throw () __attribute__ ((__const__));
125 extern float fmodf (float __x, float __y) throw (); extern float __fmodf (float __x, float __y) throw ();
126 extern int __isinff (float __value) throw () __attribute__ ((__const__));
127 extern int __finitef (float __value) throw () __attribute__ ((__const__));
128 extern int isinff (float __value) throw () __attribute__ ((__const__));
129 extern int finitef (float __value) throw () __attribute__ ((__const__));
130 extern float dremf (float __x, float __y) throw (); extern float __dremf (float __x, float __y) throw ();
131 extern float significandf (float __x) throw (); extern float __significandf (float __x) throw ();
132 extern float copysignf (float __x, float __y) throw () __attribute__ ((__const__)); extern float __copysignf (float __x, float __y) throw () __attribute__ ((__const__));
133 extern float nanf (const char *__tagb) throw () __attribute__ ((__const__)); extern float __nanf (const char *__tagb) throw () __attribute__ ((__const__));
134 extern int __isnanf (float __value) throw () __attribute__ ((__const__));
135 extern int isnanf (float __value) throw () __attribute__ ((__const__));
136 extern float j0f (float) throw (); extern float __j0f (float) throw ();
137 extern float j1f (float) throw (); extern float __j1f (float) throw ();
138 extern float jnf (int, float) throw (); extern float __jnf (int, float) throw ();
139 extern float y0f (float) throw (); extern float __y0f (float) throw ();
140 extern float y1f (float) throw (); extern float __y1f (float) throw ();
141 extern float ynf (int, float) throw (); extern float __ynf (int, float) throw ();
142 extern float erff (float) throw (); extern float __erff (float) throw ();
143 extern float erfcf (float) throw (); extern float __erfcf (float) throw ();
144 extern float lgammaf (float) throw (); extern float __lgammaf (float) throw ();
145 extern float tgammaf (float) throw (); extern float __tgammaf (float) throw ();
146 extern float gammaf (float) throw (); extern float __gammaf (float) throw ();
147 extern float lgammaf_r (float, int *__signgamp) throw (); extern float __lgammaf_r (float, int *__signgamp) throw ();
148 extern float rintf (float __x) throw (); extern float __rintf (float __x) throw ();
149 extern float nextafterf (float __x, float __y) throw () __attribute__ ((__const__)); extern float __nextafterf (float __x, float __y) throw () __attribute__ ((__const__));
150 extern float nexttowardf (float __x, long double __y) throw () __attribute__ ((__const__)); extern float __nexttowardf (float __x, long double __y) throw () __attribute__ ((__const__));
151 extern float remainderf (float __x, float __y) throw (); extern float __remainderf (float __x, float __y) throw ();
152 extern float scalbnf (float __x, int __n) throw (); extern float __scalbnf (float __x, int __n) throw ();
153 extern int ilogbf (float __x) throw (); extern int __ilogbf (float __x) throw ();
154 extern float scalblnf (float __x, long int __n) throw (); extern float __scalblnf (float __x, long int __n) throw ();
155 extern float nearbyintf (float __x) throw (); extern float __nearbyintf (float __x) throw ();
156 extern float roundf (float __x) throw () __attribute__ ((__const__)); extern float __roundf (float __x) throw () __attribute__ ((__const__));
157 extern float truncf (float __x) throw () __attribute__ ((__const__)); extern float __truncf (float __x) throw () __attribute__ ((__const__));
158 extern float remquof (float __x, float __y, int *__quo) throw (); extern float __remquof (float __x, float __y, int *__quo) throw ();
159 extern long int lrintf (float __x) throw (); extern long int __lrintf (float __x) throw ();
161 extern long long int llrintf (float __x) throw (); extern long long int __llrintf (float __x) throw ();
162 extern long int lroundf (float __x) throw (); extern long int __lroundf (float __x) throw ();
164 extern long long int llroundf (float __x) throw (); extern long long int __llroundf (float __x) throw ();
165 extern float fdimf (float __x, float __y) throw (); extern float __fdimf (float __x, float __y) throw ();
166 extern float fmaxf (float __x, float __y) throw () __attribute__ ((__const__)); extern float __fmaxf (float __x, float __y) throw () __attribute__ ((__const__));
167 extern float fminf (float __x, float __y) throw () __attribute__ ((__const__)); extern float __fminf (float __x, float __y) throw () __attribute__ ((__const__));
168 extern int __fpclassifyf (float __value) throw ()
169 __attribute__ ((__const__));
170 extern int __signbitf (float __value) throw ()
171 __attribute__ ((__const__));
172 extern float fmaf (float __x, float __y, float __z) throw (); extern float __fmaf (float __x, float __y, float __z) throw ();
173 extern int __issignalingf (float __value) throw ()
174 __attribute__ ((__const__));
175 extern float scalbf (float __x, float __n) throw (); extern float __scalbf (float __x, float __n) throw ();
176 extern long double acosl (long double __x) throw (); extern long double __acosl (long double __x) throw ();
177 extern long double asinl (long double __x) throw (); extern long double __asinl (long double __x) throw ();
178 extern long double atanl (long double __x) throw (); extern long double __atanl (long double __x) throw ();
179 extern long double atan2l (long double __y, long double __x) throw (); extern long double __atan2l (long double __y, long double __x) throw ();
180 extern long double cosl (long double __x) throw (); extern long double __cosl (long double __x) throw ();
181 extern long double sinl (long double __x) throw (); extern long double __sinl (long double __x) throw ();
182 extern long double tanl (long double __x) throw (); extern long double __tanl (long double __x) throw ();
183 extern long double coshl (long double __x) throw (); extern long double __coshl (long double __x) throw ();
184 extern long double sinhl (long double __x) throw (); extern long double __sinhl (long double __x) throw ();
185 extern long double tanhl (long double __x) throw (); extern long double __tanhl (long double __x) throw ();
186 extern void sincosl (long double __x, long double *__sinx, long double *__cosx) throw (); extern void __sincosl (long double __x, long double *__sinx, long double *__cosx) throw ()
188 extern long double acoshl (long double __x) throw (); extern long double __acoshl (long double __x) throw ();
189 extern long double asinhl (long double __x) throw (); extern long double __asinhl (long double __x) throw ();
190 extern long double atanhl (long double __x) throw (); extern long double __atanhl (long double __x) throw ();
191 extern long double expl (long double __x) throw (); extern long double __expl (long double __x) throw ();
192 extern long double frexpl (long double __x, int *__exponent) throw (); extern long double __frexpl (long double __x, int *__exponent) throw ();
193 extern long double ldexpl (long double __x, int __exponent) throw (); extern long double __ldexpl (long double __x, int __exponent) throw ();
194 extern long double logl (long double __x) throw (); extern long double __logl (long double __x) throw ();
195 extern long double log10l (long double __x) throw (); extern long double __log10l (long double __x) throw ();
196 extern long double modfl (long double __x, long double *__iptr) throw (); extern long double __modfl (long double __x, long double *__iptr) throw () __attribute__ ((__nonnull__ (2)));
197 extern long double exp10l (long double __x) throw (); extern long double __exp10l (long double __x) throw ();
198 extern long double pow10l (long double __x) throw (); extern long double __pow10l (long double __x) throw ();
199 extern long double expm1l (long double __x) throw (); extern long double __expm1l (long double __x) throw ();
200 extern long double log1pl (long double __x) throw (); extern long double __log1pl (long double __x) throw ();
201 extern long double logbl (long double __x) throw (); extern long double __logbl (long double __x) throw ();
202 extern long double exp2l (long double __x) throw (); extern long double __exp2l (long double __x) throw ();
203 extern long double log2l (long double __x) throw (); extern long double __log2l (long double __x) throw ();
204 extern long double powl (long double __x, long double __y) throw (); extern long double __powl (long double __x, long double __y) throw ();
205 extern long double sqrtl (long double __x) throw (); extern long double __sqrtl (long double __x) throw ();
206 extern long double hypotl (long double __x, long double __y) throw (); extern long double __hypotl (long double __x, long double __y) throw ();
207 extern long double cbrtl (long double __x) throw (); extern long double __cbrtl (long double __x) throw ();
208 extern long double ceill (long double __x) throw () __attribute__ ((__const__)); extern long double __ceill (long double __x) throw () __attribute__ ((__const__));
209 extern long double fabsl (long double __x) throw () __attribute__ ((__const__)); extern long double __fabsl (long double __x) throw () __attribute__ ((__const__));
210 extern long double floorl (long double __x) throw () __attribute__ ((__const__)); extern long double __floorl (long double __x) throw () __attribute__ ((__const__));
211 extern long double fmodl (long double __x, long double __y) throw (); extern long double __fmodl (long double __x, long double __y) throw ();
212 extern int __isinfl (long double __value) throw () __attribute__ ((__const__));
213 extern int __finitel (long double __value) throw () __attribute__ ((__const__));
214 extern int isinfl (long double __value) throw () __attribute__ ((__const__));
215 extern int finitel (long double __value) throw () __attribute__ ((__const__));
216 extern long double dreml (long double __x, long double __y) throw (); extern long double __dreml (long double __x, long double __y) throw ();
217 extern long double significandl (long double __x) throw (); extern long double __significandl (long double __x) throw ();
218 extern long double copysignl (long double __x, long double __y) throw () __attribute__ ((__const__)); extern long double __copysignl (long double __x, long double __y) throw () __attribute__ ((__const__));
219 extern long double nanl (const char *__tagb) throw () __attribute__ ((__const__)); extern long double __nanl (const char *__tagb) throw () __attribute__ ((__const__));
220 extern int __isnanl (long double __value) throw () __attribute__ ((__const__));
221 extern int isnanl (long double __value) throw () __attribute__ ((__const__));
222 extern long double j0l (long double) throw (); extern long double __j0l (long double) throw ();
223 extern long double j1l (long double) throw (); extern long double __j1l (long double) throw ();
224 extern long double jnl (int, long double) throw (); extern long double __jnl (int, long double) throw ();
225 extern long double y0l (long double) throw (); extern long double __y0l (long double) throw ();
226 extern long double y1l (long double) throw (); extern long double __y1l (long double) throw ();
227 extern long double ynl (int, long double) throw (); extern long double __ynl (int, long double) throw ();
228 extern long double erfl (long double) throw (); extern long double __erfl (long double) throw ();
229 extern long double erfcl (long double) throw (); extern long double __erfcl (long double) throw ();
230 extern long double lgammal (long double) throw (); extern long double __lgammal (long double) throw ();
231 extern long double tgammal (long double) throw (); extern long double __tgammal (long double) throw ();
232 extern long double gammal (long double) throw (); extern long double __gammal (long double) throw ();
233 extern long double lgammal_r (long double, int *__signgamp) throw (); extern long double __lgammal_r (long double, int *__signgamp) throw ();
234 extern long double rintl (long double __x) throw (); extern long double __rintl (long double __x) throw ();
235 extern long double nextafterl (long double __x, long double __y) throw () __attribute__ ((__const__)); extern long double __nextafterl (long double __x, long double __y) throw () __attribute__ ((__const__));
236 extern long double nexttowardl (long double __x, long double __y) throw () __attribute__ ((__const__)); extern long double __nexttowardl (long double __x, long double __y) throw () __attribute__ ((__const__));
237 extern long double remainderl (long double __x, long double __y) throw (); extern long double __remainderl (long double __x, long double __y) throw ();
238 extern long double scalbnl (long double __x, int __n) throw (); extern long double __scalbnl (long double __x, int __n) throw ();
239 extern int ilogbl (long double __x) throw (); extern int __ilogbl (long double __x) throw ();
240 extern long double scalblnl (long double __x, long int __n) throw (); extern long double __scalblnl (long double __x, long int __n) throw ();
241 extern long double nearbyintl (long double __x) throw (); extern long double __nearbyintl (long double __x) throw ();
242 extern long double roundl (long double __x) throw () __attribute__ ((__const__)); extern long double __roundl (long double __x) throw () __attribute__ ((__const__));
243 extern long double truncl (long double __x) throw () __attribute__ ((__const__)); extern long double __truncl (long double __x) throw () __attribute__ ((__const__));
244 extern long double remquol (long double __x, long double __y, int *__quo) throw (); extern long double __remquol (long double __x, long double __y, int *__quo) throw ();
245 extern long int lrintl (long double __x) throw (); extern long int __lrintl (long double __x) throw ();
247 extern long long int llrintl (long double __x) throw (); extern long long int __llrintl (long double __x) throw ();
248 extern long int lroundl (long double __x) throw (); extern long int __lroundl (long double __x) throw ();
250 extern long long int llroundl (long double __x) throw (); extern long long int __llroundl (long double __x) throw ();
251 extern long double fdiml (long double __x, long double __y) throw (); extern long double __fdiml (long double __x, long double __y) throw ();
252 extern long double fmaxl (long double __x, long double __y) throw () __attribute__ ((__const__)); extern long double __fmaxl (long double __x, long double __y) throw () __attribute__ ((__const__));
253 extern long double fminl (long double __x, long double __y) throw () __attribute__ ((__const__)); extern long double __fminl (long double __x, long double __y) throw () __attribute__ ((__const__));
254 extern int __fpclassifyl (long double __value) throw ()
255 __attribute__ ((__const__));
256 extern int __signbitl (long double __value) throw ()
257 __attribute__ ((__const__));
258 extern long double fmal (long double __x, long double __y, long double __z) throw (); extern long double __fmal (long double __x, long double __y, long double __z) throw ();
259 extern int __issignalingl (long double __value) throw ()
260 __attribute__ ((__const__));
261 extern long double scalbl (long double __x, long double __n) throw (); extern long double __scalbl (long double __x, long double __n) throw ();
284 extern _LIB_VERSION_TYPE _LIB_VERSION;
293 extern int matherr (struct __exception *__exc) throw ();
294 extern __inline __attribute__ ((__gnu_inline__)) int
295 __attribute__ ((__leaf__)) __signbitf (float __x) throw ()
297 return __builtin_signbitf (__x);
299 extern __inline __attribute__ ((__gnu_inline__)) int
300 __attribute__ ((__leaf__)) __signbit (double __x) throw ()
302 return __builtin_signbit (__x);
304 extern __inline __attribute__ ((__gnu_inline__)) int
305 __attribute__ ((__leaf__)) __signbitl (long double __x) throw ()
307 return __signbit ((double) __x);
309 extern __inline __attribute__ ((__gnu_inline__)) double fdim (double __x, double __y) throw ();
310 extern __inline __attribute__ ((__gnu_inline__)) double
311 __attribute__ ((__leaf__)) fdim (double __x, double __y) throw ()
313 return __x <= __y ? 0 : __x - __y;
315 extern __inline __attribute__ ((__gnu_inline__)) float fdimf (float __x, float __y) throw ();
316 extern __inline __attribute__ ((__gnu_inline__)) float
317 __attribute__ ((__leaf__)) fdimf (float __x, float __y) throw ()
319 return __x <= __y ? 0 : __x - __y;
322 typedef long unsigned int size_t;
324 typedef unsigned char __u_char;
325 typedef unsigned short int __u_short;
326 typedef unsigned int __u_int;
327 typedef unsigned long int __u_long;
328 typedef signed char __int8_t;
329 typedef unsigned char __uint8_t;
330 typedef signed short int __int16_t;
331 typedef unsigned short int __uint16_t;
332 typedef signed int __int32_t;
333 typedef unsigned int __uint32_t;
334 typedef signed long int __int64_t;
335 typedef unsigned long int __uint64_t;
336 typedef long int __quad_t;
337 typedef unsigned long int __u_quad_t;
338 typedef unsigned long int __dev_t;
339 typedef unsigned int __uid_t;
340 typedef unsigned int __gid_t;
341 typedef unsigned long int __ino_t;
342 typedef unsigned long int __ino64_t;
343 typedef unsigned int __mode_t;
344 typedef unsigned long int __nlink_t;
345 typedef long int __off_t;
346 typedef long int __off64_t;
348 typedef struct { int __val[2]; } __fsid_t;
349 typedef long int __clock_t;
350 typedef unsigned long int __rlim_t;
351 typedef unsigned long int __rlim64_t;
352 typedef unsigned int __id_t;
353 typedef long int __time_t;
354 typedef unsigned int __useconds_t;
355 typedef long int __suseconds_t;
356 typedef int __daddr_t;
358 typedef int __clockid_t;
359 typedef void * __timer_t;
360 typedef long int __blksize_t;
361 typedef long int __blkcnt_t;
362 typedef long int __blkcnt64_t;
363 typedef unsigned long int __fsblkcnt_t;
364 typedef unsigned long int __fsblkcnt64_t;
365 typedef unsigned long int __fsfilcnt_t;
366 typedef unsigned long int __fsfilcnt64_t;
367 typedef long int __fsword_t;
368 typedef long int __ssize_t;
369 typedef long int __syscall_slong_t;
370 typedef unsigned long int __syscall_ulong_t;
371 typedef __off64_t __loff_t;
372 typedef __quad_t *__qaddr_t;
373 typedef char *__caddr_t;
374 typedef long int __intptr_t;
375 typedef unsigned int __socklen_t;
376 static __inline unsigned int
377 __bswap_32 (unsigned int __bsx)
379 return __builtin_bswap32 (__bsx);
381 static __inline __uint64_t
382 __bswap_64 (__uint64_t __bsx)
384 return __builtin_bswap64 (__bsx);
392 unsigned int __w_retcode:8;
393 unsigned int __w_coredump:1;
394 unsigned int __w_termsig:7;
399 unsigned int __w_stopsig:8;
400 unsigned int __w_stopval:8;
413 __extension__ typedef struct
418 extern size_t __ctype_get_mb_cur_max (void) throw () __attribute__ ((__warn_unused_result__));
419 extern double atof (const char *__nptr)
420 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
421 extern int atoi (const char *__nptr)
422 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
423 extern long int atol (const char *__nptr)
424 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
425 __extension__ extern long long int atoll (const char *__nptr)
426 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
427 extern double strtod (const char *__restrict __nptr,
428 char **__restrict __endptr)
429 throw () __attribute__ ((__nonnull__ (1)));
430 extern float strtof (const char *__restrict __nptr,
431 char **__restrict __endptr) throw () __attribute__ ((__nonnull__ (1)));
432 extern long double strtold (const char *__restrict __nptr,
433 char **__restrict __endptr)
434 throw () __attribute__ ((__nonnull__ (1)));
435 extern long int strtol (const char *__restrict __nptr,
436 char **__restrict __endptr, int __base)
437 throw () __attribute__ ((__nonnull__ (1)));
438 extern unsigned long int strtoul (const char *__restrict __nptr,
439 char **__restrict __endptr, int __base)
440 throw () __attribute__ ((__nonnull__ (1)));
442 extern long long int strtoq (const char *__restrict __nptr,
443 char **__restrict __endptr, int __base)
444 throw () __attribute__ ((__nonnull__ (1)));
446 extern unsigned long long int strtouq (const char *__restrict __nptr,
447 char **__restrict __endptr, int __base)
448 throw () __attribute__ ((__nonnull__ (1)));
450 extern long long int strtoll (const char *__restrict __nptr,
451 char **__restrict __endptr, int __base)
452 throw () __attribute__ ((__nonnull__ (1)));
454 extern unsigned long long int strtoull (const char *__restrict __nptr,
455 char **__restrict __endptr, int __base)
456 throw () __attribute__ ((__nonnull__ (1)));
457 typedef struct __locale_struct
459 struct __locale_data *__locales[13];
460 const unsigned short int *__ctype_b;
461 const int *__ctype_tolower;
462 const int *__ctype_toupper;
463 const char *__names[13];
465 typedef __locale_t locale_t;
466 extern long int strtol_l (const char *__restrict __nptr,
467 char **__restrict __endptr, int __base,
468 __locale_t __loc) throw () __attribute__ ((__nonnull__ (1, 4)));
469 extern unsigned long int strtoul_l (const char *__restrict __nptr,
470 char **__restrict __endptr,
471 int __base, __locale_t __loc)
472 throw () __attribute__ ((__nonnull__ (1, 4)));
474 extern long long int strtoll_l (const char *__restrict __nptr,
475 char **__restrict __endptr, int __base,
477 throw () __attribute__ ((__nonnull__ (1, 4)));
479 extern unsigned long long int strtoull_l (const char *__restrict __nptr,
480 char **__restrict __endptr,
481 int __base, __locale_t __loc)
482 throw () __attribute__ ((__nonnull__ (1, 4)));
483 extern double strtod_l (const char *__restrict __nptr,
484 char **__restrict __endptr, __locale_t __loc)
485 throw () __attribute__ ((__nonnull__ (1, 3)));
486 extern float strtof_l (const char *__restrict __nptr,
487 char **__restrict __endptr, __locale_t __loc)
488 throw () __attribute__ ((__nonnull__ (1, 3)));
489 extern long double strtold_l (const char *__restrict __nptr,
490 char **__restrict __endptr,
492 throw () __attribute__ ((__nonnull__ (1, 3)));
493 extern __inline __attribute__ ((__gnu_inline__)) int
494 __attribute__ ((__leaf__)) atoi (const char *__nptr) throw ()
496 return (int) strtol (__nptr, (char **) __null, 10);
498 extern __inline __attribute__ ((__gnu_inline__)) long int
499 __attribute__ ((__leaf__)) atol (const char *__nptr) throw ()
501 return strtol (__nptr, (char **) __null, 10);
503 __extension__ extern __inline __attribute__ ((__gnu_inline__)) long long int
504 __attribute__ ((__leaf__)) atoll (const char *__nptr) throw ()
506 return strtoll (__nptr, (char **) __null, 10);
508 extern char *l64a (long int __n) throw () __attribute__ ((__warn_unused_result__));
509 extern long int a64l (const char *__s)
510 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
512 typedef __u_char u_char;
513 typedef __u_short u_short;
514 typedef __u_int u_int;
515 typedef __u_long u_long;
516 typedef __quad_t quad_t;
517 typedef __u_quad_t u_quad_t;
518 typedef __fsid_t fsid_t;
519 typedef __loff_t loff_t;
520 typedef __ino_t ino_t;
521 typedef __ino64_t ino64_t;
522 typedef __dev_t dev_t;
523 typedef __gid_t gid_t;
524 typedef __mode_t mode_t;
525 typedef __nlink_t nlink_t;
526 typedef __uid_t uid_t;
527 typedef __off_t off_t;
528 typedef __off64_t off64_t;
529 typedef __pid_t pid_t;
531 typedef __ssize_t ssize_t;
532 typedef __daddr_t daddr_t;
533 typedef __caddr_t caddr_t;
534 typedef __key_t key_t;
535 typedef __clock_t clock_t;
536 typedef __time_t time_t;
537 typedef __clockid_t clockid_t;
538 typedef __timer_t timer_t;
539 typedef __useconds_t useconds_t;
540 typedef __suseconds_t suseconds_t;
541 typedef unsigned long int ulong;
542 typedef unsigned short int ushort;
543 typedef unsigned int uint;
544 typedef int int8_t __attribute__ ((__mode__ (__QI__)));
545 typedef int int16_t __attribute__ ((__mode__ (__HI__)));
546 typedef int int32_t __attribute__ ((__mode__ (__SI__)));
547 typedef int int64_t __attribute__ ((__mode__ (__DI__)));
548 typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__)));
549 typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__)));
550 typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__)));
551 typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__)));
552 typedef int register_t __attribute__ ((__mode__ (__word__)));
553 typedef int __sig_atomic_t;
556 unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
558 typedef __sigset_t sigset_t;
562 __syscall_slong_t tv_nsec;
567 __suseconds_t tv_usec;
569 typedef long int __fd_mask;
572 __fd_mask fds_bits[1024 / (8 * (int) sizeof (__fd_mask))];
574 typedef __fd_mask fd_mask;
576 extern int select (int __nfds, fd_set *__restrict __readfds,
577 fd_set *__restrict __writefds,
578 fd_set *__restrict __exceptfds,
579 struct timeval *__restrict __timeout);
580 extern int pselect (int __nfds, fd_set *__restrict __readfds,
581 fd_set *__restrict __writefds,
582 fd_set *__restrict __exceptfds,
583 const struct timespec *__restrict __timeout,
584 const __sigset_t *__restrict __sigmask);
585 extern long int __fdelt_chk (long int __d);
586 extern long int __fdelt_warn (long int __d)
587 __attribute__((__warning__ ("bit outside of fd_set selected")));
591 extern unsigned int gnu_dev_major (unsigned long long int __dev)
592 throw () __attribute__ ((__const__));
594 extern unsigned int gnu_dev_minor (unsigned long long int __dev)
595 throw () __attribute__ ((__const__));
597 extern unsigned long long int gnu_dev_makedev (unsigned int __major,
598 unsigned int __minor)
599 throw () __attribute__ ((__const__));
600 __extension__ extern __inline __attribute__ ((__gnu_inline__)) __attribute__ ((__const__)) unsigned int
601 __attribute__ ((__leaf__)) gnu_dev_major (unsigned long long int __dev) throw ()
603 return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
605 __extension__ extern __inline __attribute__ ((__gnu_inline__)) __attribute__ ((__const__)) unsigned int
606 __attribute__ ((__leaf__)) gnu_dev_minor (unsigned long long int __dev) throw ()
608 return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
610 __extension__ extern __inline __attribute__ ((__gnu_inline__)) __attribute__ ((__const__)) unsigned long long int
611 __attribute__ ((__leaf__)) gnu_dev_makedev (unsigned int __major, unsigned int __minor) throw ()
613 return ((__minor & 0xff) | ((__major & 0xfff) << 8)
614 | (((unsigned long long int) (__minor & ~0xff)) << 12)
615 | (((unsigned long long int) (__major & ~0xfff)) << 32));
618 typedef __blksize_t blksize_t;
619 typedef __blkcnt_t blkcnt_t;
620 typedef __fsblkcnt_t fsblkcnt_t;
621 typedef __fsfilcnt_t fsfilcnt_t;
622 typedef __blkcnt64_t blkcnt64_t;
623 typedef __fsblkcnt64_t fsblkcnt64_t;
624 typedef __fsfilcnt64_t fsfilcnt64_t;
625 typedef unsigned long int pthread_t;
631 typedef union pthread_attr_t pthread_attr_t;
632 typedef struct __pthread_internal_list
634 struct __pthread_internal_list *__prev;
635 struct __pthread_internal_list *__next;
639 struct __pthread_mutex_s
642 unsigned int __count;
644 unsigned int __nusers;
648 __pthread_list_t __list;
657 } pthread_mutexattr_t;
663 unsigned int __futex;
664 __extension__ unsigned long long int __total_seq;
665 __extension__ unsigned long long int __wakeup_seq;
666 __extension__ unsigned long long int __woken_seq;
668 unsigned int __nwaiters;
669 unsigned int __broadcast_seq;
672 __extension__ long long int __align;
678 } pthread_condattr_t;
679 typedef unsigned int pthread_key_t;
680 typedef int pthread_once_t;
686 unsigned int __nr_readers;
687 unsigned int __readers_wakeup;
688 unsigned int __writer_wakeup;
689 unsigned int __nr_readers_queued;
690 unsigned int __nr_writers_queued;
693 unsigned char __rwelision;
694 unsigned char __pad1[7];
695 unsigned long int __pad2;
696 unsigned int __flags;
705 } pthread_rwlockattr_t;
706 typedef volatile int pthread_spinlock_t;
716 } pthread_barrierattr_t;
718 extern long int random (void) throw ();
719 extern void srandom (unsigned int __seed) throw ();
720 extern char *initstate (unsigned int __seed, char *__statebuf,
721 size_t __statelen) throw () __attribute__ ((__nonnull__ (2)));
722 extern char *setstate (char *__statebuf) throw () __attribute__ ((__nonnull__ (1)));
733 extern int random_r (struct random_data *__restrict __buf,
734 int32_t *__restrict __result) throw () __attribute__ ((__nonnull__ (1, 2)));
735 extern int srandom_r (unsigned int __seed, struct random_data *__buf)
736 throw () __attribute__ ((__nonnull__ (2)));
737 extern int initstate_r (unsigned int __seed, char *__restrict __statebuf,
739 struct random_data *__restrict __buf)
740 throw () __attribute__ ((__nonnull__ (2, 4)));
741 extern int setstate_r (char *__restrict __statebuf,
742 struct random_data *__restrict __buf)
743 throw () __attribute__ ((__nonnull__ (1, 2)));
744 extern int rand (void) throw ();
745 extern void srand (unsigned int __seed) throw ();
746 extern int rand_r (unsigned int *__seed) throw ();
747 extern double drand48 (void) throw ();
748 extern double erand48 (unsigned short int __xsubi[3]) throw () __attribute__ ((__nonnull__ (1)));
749 extern long int lrand48 (void) throw ();
750 extern long int nrand48 (unsigned short int __xsubi[3])
751 throw () __attribute__ ((__nonnull__ (1)));
752 extern long int mrand48 (void) throw ();
753 extern long int jrand48 (unsigned short int __xsubi[3])
754 throw () __attribute__ ((__nonnull__ (1)));
755 extern void srand48 (long int __seedval) throw ();
756 extern unsigned short int *seed48 (unsigned short int __seed16v[3])
757 throw () __attribute__ ((__nonnull__ (1)));
758 extern void lcong48 (unsigned short int __param[7]) throw () __attribute__ ((__nonnull__ (1)));
761 unsigned short int __x[3];
762 unsigned short int __old_x[3];
763 unsigned short int __c;
764 unsigned short int __init;
765 __extension__ unsigned long long int __a;
767 extern int drand48_r (struct drand48_data *__restrict __buffer,
768 double *__restrict __result) throw () __attribute__ ((__nonnull__ (1, 2)));
769 extern int erand48_r (unsigned short int __xsubi[3],
770 struct drand48_data *__restrict __buffer,
771 double *__restrict __result) throw () __attribute__ ((__nonnull__ (1, 2)));
772 extern int lrand48_r (struct drand48_data *__restrict __buffer,
773 long int *__restrict __result)
774 throw () __attribute__ ((__nonnull__ (1, 2)));
775 extern int nrand48_r (unsigned short int __xsubi[3],
776 struct drand48_data *__restrict __buffer,
777 long int *__restrict __result)
778 throw () __attribute__ ((__nonnull__ (1, 2)));
779 extern int mrand48_r (struct drand48_data *__restrict __buffer,
780 long int *__restrict __result)
781 throw () __attribute__ ((__nonnull__ (1, 2)));
782 extern int jrand48_r (unsigned short int __xsubi[3],
783 struct drand48_data *__restrict __buffer,
784 long int *__restrict __result)
785 throw () __attribute__ ((__nonnull__ (1, 2)));
786 extern int srand48_r (long int __seedval, struct drand48_data *__buffer)
787 throw () __attribute__ ((__nonnull__ (2)));
788 extern int seed48_r (unsigned short int __seed16v[3],
789 struct drand48_data *__buffer) throw () __attribute__ ((__nonnull__ (1, 2)));
790 extern int lcong48_r (unsigned short int __param[7],
791 struct drand48_data *__buffer)
792 throw () __attribute__ ((__nonnull__ (1, 2)));
793 extern void *malloc (size_t __size) throw () __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__));
794 extern void *calloc (size_t __nmemb, size_t __size)
795 throw () __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__));
796 extern void *realloc (void *__ptr, size_t __size)
797 throw () __attribute__ ((__warn_unused_result__));
798 extern void free (void *__ptr) throw ();
799 extern void cfree (void *__ptr) throw ();
801 extern void *alloca (size_t __size) throw ();
803 extern void *valloc (size_t __size) throw () __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__));
804 extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
805 throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
806 extern void *aligned_alloc (size_t __alignment, size_t __size)
807 throw () __attribute__ ((__malloc__)) __attribute__ ((__alloc_size__ (2))) __attribute__ ((__warn_unused_result__));
808 extern void abort (void) throw () __attribute__ ((__noreturn__));
809 extern int atexit (void (*__func) (void)) throw () __attribute__ ((__nonnull__ (1)));
810 extern "C++" int at_quick_exit (void (*__func) (void))
811 throw () __asm ("at_quick_exit") __attribute__ ((__nonnull__ (1)));
812 extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg)
813 throw () __attribute__ ((__nonnull__ (1)));
814 extern void exit (int __status) throw () __attribute__ ((__noreturn__));
815 extern void quick_exit (int __status) throw () __attribute__ ((__noreturn__));
816 extern void _Exit (int __status) throw () __attribute__ ((__noreturn__));
817 extern char *getenv (const char *__name) throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
818 extern char *secure_getenv (const char *__name)
819 throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
820 extern int putenv (char *__string) throw () __attribute__ ((__nonnull__ (1)));
821 extern int setenv (const char *__name, const char *__value, int __replace)
822 throw () __attribute__ ((__nonnull__ (2)));
823 extern int unsetenv (const char *__name) throw () __attribute__ ((__nonnull__ (1)));
824 extern int clearenv (void) throw ();
825 extern char *mktemp (char *__template) throw () __attribute__ ((__nonnull__ (1)));
826 extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
827 extern int mkstemp64 (char *__template) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
828 extern int mkstemps (char *__template, int __suffixlen) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
829 extern int mkstemps64 (char *__template, int __suffixlen)
830 __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
831 extern char *mkdtemp (char *__template) throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
832 extern int mkostemp (char *__template, int __flags) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
833 extern int mkostemp64 (char *__template, int __flags) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
834 extern int mkostemps (char *__template, int __suffixlen, int __flags)
835 __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
836 extern int mkostemps64 (char *__template, int __suffixlen, int __flags)
837 __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
838 extern int system (const char *__command) __attribute__ ((__warn_unused_result__));
839 extern char *canonicalize_file_name (const char *__name)
840 throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
841 extern char *realpath (const char *__restrict __name,
842 char *__restrict __resolved) throw () __attribute__ ((__warn_unused_result__));
843 typedef int (*__compar_fn_t) (const void *, const void *);
844 typedef __compar_fn_t comparison_fn_t;
845 typedef int (*__compar_d_fn_t) (const void *, const void *, void *);
846 extern void *bsearch (const void *__key, const void *__base,
847 size_t __nmemb, size_t __size, __compar_fn_t __compar)
848 __attribute__ ((__nonnull__ (1, 2, 5))) __attribute__ ((__warn_unused_result__));
849 extern __inline __attribute__ ((__gnu_inline__)) void *
850 bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
851 __compar_fn_t __compar)
853 size_t __l, __u, __idx;
860 __idx = (__l + __u) / 2;
861 __p = (void *) (((const char *) __base) + (__idx * __size));
862 __comparison = (*__compar) (__key, __p);
863 if (__comparison < 0)
865 else if (__comparison > 0)
872 extern void qsort (void *__base, size_t __nmemb, size_t __size,
873 __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
874 extern void qsort_r (void *__base, size_t __nmemb, size_t __size,
875 __compar_d_fn_t __compar, void *__arg)
876 __attribute__ ((__nonnull__ (1, 4)));
877 extern int abs (int __x) throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__));
878 extern long int labs (long int __x) throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__));
879 __extension__ extern long long int llabs (long long int __x)
880 throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__));
881 extern div_t div (int __numer, int __denom)
882 throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__));
883 extern ldiv_t ldiv (long int __numer, long int __denom)
884 throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__));
885 __extension__ extern lldiv_t lldiv (long long int __numer,
886 long long int __denom)
887 throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__));
888 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt,
889 int *__restrict __sign) throw () __attribute__ ((__nonnull__ (3, 4))) __attribute__ ((__warn_unused_result__));
890 extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt,
891 int *__restrict __sign) throw () __attribute__ ((__nonnull__ (3, 4))) __attribute__ ((__warn_unused_result__));
892 extern char *gcvt (double __value, int __ndigit, char *__buf)
893 throw () __attribute__ ((__nonnull__ (3))) __attribute__ ((__warn_unused_result__));
894 extern char *qecvt (long double __value, int __ndigit,
895 int *__restrict __decpt, int *__restrict __sign)
896 throw () __attribute__ ((__nonnull__ (3, 4))) __attribute__ ((__warn_unused_result__));
897 extern char *qfcvt (long double __value, int __ndigit,
898 int *__restrict __decpt, int *__restrict __sign)
899 throw () __attribute__ ((__nonnull__ (3, 4))) __attribute__ ((__warn_unused_result__));
900 extern char *qgcvt (long double __value, int __ndigit, char *__buf)
901 throw () __attribute__ ((__nonnull__ (3))) __attribute__ ((__warn_unused_result__));
902 extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
903 int *__restrict __sign, char *__restrict __buf,
904 size_t __len) throw () __attribute__ ((__nonnull__ (3, 4, 5)));
905 extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
906 int *__restrict __sign, char *__restrict __buf,
907 size_t __len) throw () __attribute__ ((__nonnull__ (3, 4, 5)));
908 extern int qecvt_r (long double __value, int __ndigit,
909 int *__restrict __decpt, int *__restrict __sign,
910 char *__restrict __buf, size_t __len)
911 throw () __attribute__ ((__nonnull__ (3, 4, 5)));
912 extern int qfcvt_r (long double __value, int __ndigit,
913 int *__restrict __decpt, int *__restrict __sign,
914 char *__restrict __buf, size_t __len)
915 throw () __attribute__ ((__nonnull__ (3, 4, 5)));
916 extern int mblen (const char *__s, size_t __n) throw ();
917 extern int mbtowc (wchar_t *__restrict __pwc,
918 const char *__restrict __s, size_t __n) throw ();
919 extern int wctomb (char *__s, wchar_t __wchar) throw ();
920 extern size_t mbstowcs (wchar_t *__restrict __pwcs,
921 const char *__restrict __s, size_t __n) throw ();
922 extern size_t wcstombs (char *__restrict __s,
923 const wchar_t *__restrict __pwcs, size_t __n)
925 extern int rpmatch (const char *__response) throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__));
926 extern int getsubopt (char **__restrict __optionp,
927 char *const *__restrict __tokens,
928 char **__restrict __valuep)
929 throw () __attribute__ ((__nonnull__ (1, 2, 3))) __attribute__ ((__warn_unused_result__));
930 extern void setkey (const char *__key) throw () __attribute__ ((__nonnull__ (1)));
931 extern int posix_openpt (int __oflag) __attribute__ ((__warn_unused_result__));
932 extern int grantpt (int __fd) throw ();
933 extern int unlockpt (int __fd) throw ();
934 extern char *ptsname (int __fd) throw () __attribute__ ((__warn_unused_result__));
935 extern int ptsname_r (int __fd, char *__buf, size_t __buflen)
936 throw () __attribute__ ((__nonnull__ (2)));
937 extern int getpt (void);
938 extern int getloadavg (double __loadavg[], int __nelem)
939 throw () __attribute__ ((__nonnull__ (1)));
940 extern __inline __attribute__ ((__gnu_inline__)) double
941 __attribute__ ((__leaf__)) atof (const char *__nptr) throw ()
943 return strtod (__nptr, (char **) __null);
945 extern char *__realpath_chk (const char *__restrict __name,
946 char *__restrict __resolved,
947 size_t __resolvedlen) throw () __attribute__ ((__warn_unused_result__));
948 extern char *__realpath_alias (const char *__restrict __name, char *__restrict __resolved) throw () __asm__ ("" "realpath")
949 __attribute__ ((__warn_unused_result__));
950 extern char *__realpath_chk_warn (const char *__restrict __name, char *__restrict __resolved, size_t __resolvedlen) throw () __asm__ ("" "__realpath_chk")
951 __attribute__ ((__warn_unused_result__))
952 __attribute__((__warning__ ("second argument of realpath must be either NULL or at " "least PATH_MAX bytes long buffer")))
954 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) char *
955 __attribute__ ((__leaf__)) realpath (const char *__restrict __name, char *__restrict __resolved) throw ()
957 if (__builtin_object_size (__resolved, 2 > 1) != (size_t) -1)
959 return __realpath_chk (__name, __resolved, __builtin_object_size (__resolved, 2 > 1));
961 return __realpath_alias (__name, __resolved);
963 extern int __ptsname_r_chk (int __fd, char *__buf, size_t __buflen,
964 size_t __nreal) throw () __attribute__ ((__nonnull__ (2)));
965 extern int __ptsname_r_alias (int __fd, char *__buf, size_t __buflen) throw () __asm__ ("" "ptsname_r")
966 __attribute__ ((__nonnull__ (2)));
967 extern int __ptsname_r_chk_warn (int __fd, char *__buf, size_t __buflen, size_t __nreal) throw () __asm__ ("" "__ptsname_r_chk")
968 __attribute__ ((__nonnull__ (2))) __attribute__((__warning__ ("ptsname_r called with buflen bigger than " "size of buf")))
970 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
971 __attribute__ ((__leaf__)) ptsname_r (int __fd, char *__buf, size_t __buflen) throw ()
973 if (__builtin_object_size (__buf, 2 > 1) != (size_t) -1)
975 if (!__builtin_constant_p (__buflen))
976 return __ptsname_r_chk (__fd, __buf, __buflen, __builtin_object_size (__buf, 2 > 1));
977 if (__buflen > __builtin_object_size (__buf, 2 > 1))
978 return __ptsname_r_chk_warn (__fd, __buf, __buflen, __builtin_object_size (__buf, 2 > 1));
980 return __ptsname_r_alias (__fd, __buf, __buflen);
982 extern int __wctomb_chk (char *__s, wchar_t __wchar, size_t __buflen)
983 throw () __attribute__ ((__warn_unused_result__));
984 extern int __wctomb_alias (char *__s, wchar_t __wchar) throw () __asm__ ("" "wctomb")
985 __attribute__ ((__warn_unused_result__));
986 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) int
987 __attribute__ ((__leaf__)) wctomb (char *__s, wchar_t __wchar) throw ()
989 if (__builtin_object_size (__s, 2 > 1) != (size_t) -1 && 16 > __builtin_object_size (__s, 2 > 1))
990 return __wctomb_chk (__s, __wchar, __builtin_object_size (__s, 2 > 1));
991 return __wctomb_alias (__s, __wchar);
993 extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,
994 const char *__restrict __src,
995 size_t __len, size_t __dstlen) throw ();
996 extern size_t __mbstowcs_alias (wchar_t *__restrict __dst, const char *__restrict __src, size_t __len) throw () __asm__ ("" "mbstowcs")
998 extern size_t __mbstowcs_chk_warn (wchar_t *__restrict __dst, const char *__restrict __src, size_t __len, size_t __dstlen) throw () __asm__ ("" "__mbstowcs_chk")
999 __attribute__((__warning__ ("mbstowcs called with dst buffer smaller than len " "* sizeof (wchar_t)")))
1001 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) size_t
1002 __attribute__ ((__leaf__)) mbstowcs (wchar_t *__restrict __dst, const char *__restrict __src, size_t __len) throw ()
1004 if (__builtin_object_size (__dst, 2 > 1) != (size_t) -1)
1006 if (!__builtin_constant_p (__len))
1007 return __mbstowcs_chk (__dst, __src, __len,
1008 __builtin_object_size (__dst, 2 > 1) / sizeof (wchar_t));
1009 if (__len > __builtin_object_size (__dst, 2 > 1) / sizeof (wchar_t))
1010 return __mbstowcs_chk_warn (__dst, __src, __len,
1011 __builtin_object_size (__dst, 2 > 1) / sizeof (wchar_t));
1013 return __mbstowcs_alias (__dst, __src, __len);
1015 extern size_t __wcstombs_chk (char *__restrict __dst,
1016 const wchar_t *__restrict __src,
1017 size_t __len, size_t __dstlen) throw ();
1018 extern size_t __wcstombs_alias (char *__restrict __dst, const wchar_t *__restrict __src, size_t __len) throw () __asm__ ("" "wcstombs")
1020 extern size_t __wcstombs_chk_warn (char *__restrict __dst, const wchar_t *__restrict __src, size_t __len, size_t __dstlen) throw () __asm__ ("" "__wcstombs_chk")
1021 __attribute__((__warning__ ("wcstombs called with dst buffer smaller than len")));
1022 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) size_t
1023 __attribute__ ((__leaf__)) wcstombs (char *__restrict __dst, const wchar_t *__restrict __src, size_t __len) throw ()
1025 if (__builtin_object_size (__dst, 2 > 1) != (size_t) -1)
1027 if (!__builtin_constant_p (__len))
1028 return __wcstombs_chk (__dst, __src, __len, __builtin_object_size (__dst, 2 > 1));
1029 if (__len > __builtin_object_size (__dst, 2 > 1))
1030 return __wcstombs_chk_warn (__dst, __src, __len, __builtin_object_size (__dst, 2 > 1));
1032 return __wcstombs_alias (__dst, __src, __len);
1036 extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
1037 size_t __n) throw () __attribute__ ((__nonnull__ (1, 2)));
1038 extern void *memmove (void *__dest, const void *__src, size_t __n)
1039 throw () __attribute__ ((__nonnull__ (1, 2)));
1040 extern void *memccpy (void *__restrict __dest, const void *__restrict __src,
1041 int __c, size_t __n)
1042 throw () __attribute__ ((__nonnull__ (1, 2)));
1043 extern void *memset (void *__s, int __c, size_t __n) throw () __attribute__ ((__nonnull__ (1)));
1044 extern int memcmp (const void *__s1, const void *__s2, size_t __n)
1045 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1048 extern void *memchr (void *__s, int __c, size_t __n)
1049 throw () __asm ("memchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1050 extern const void *memchr (const void *__s, int __c, size_t __n)
1051 throw () __asm ("memchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1052 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) void *
1053 memchr (void *__s, int __c, size_t __n) throw ()
1055 return __builtin_memchr (__s, __c, __n);
1057 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const void *
1058 memchr (const void *__s, int __c, size_t __n) throw ()
1060 return __builtin_memchr (__s, __c, __n);
1063 extern "C++" void *rawmemchr (void *__s, int __c)
1064 throw () __asm ("rawmemchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1065 extern "C++" const void *rawmemchr (const void *__s, int __c)
1066 throw () __asm ("rawmemchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1067 extern "C++" void *memrchr (void *__s, int __c, size_t __n)
1068 throw () __asm ("memrchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1069 extern "C++" const void *memrchr (const void *__s, int __c, size_t __n)
1070 throw () __asm ("memrchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1071 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
1072 throw () __attribute__ ((__nonnull__ (1, 2)));
1073 extern char *strncpy (char *__restrict __dest,
1074 const char *__restrict __src, size_t __n)
1075 throw () __attribute__ ((__nonnull__ (1, 2)));
1076 extern char *strcat (char *__restrict __dest, const char *__restrict __src)
1077 throw () __attribute__ ((__nonnull__ (1, 2)));
1078 extern char *strncat (char *__restrict __dest, const char *__restrict __src,
1079 size_t __n) throw () __attribute__ ((__nonnull__ (1, 2)));
1080 extern int strcmp (const char *__s1, const char *__s2)
1081 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1082 extern int strncmp (const char *__s1, const char *__s2, size_t __n)
1083 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1084 extern int strcoll (const char *__s1, const char *__s2)
1085 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1086 extern size_t strxfrm (char *__restrict __dest,
1087 const char *__restrict __src, size_t __n)
1088 throw () __attribute__ ((__nonnull__ (2)));
1089 extern int strcoll_l (const char *__s1, const char *__s2, __locale_t __l)
1090 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3)));
1091 extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n,
1092 __locale_t __l) throw () __attribute__ ((__nonnull__ (2, 4)));
1093 extern char *strdup (const char *__s)
1094 throw () __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1)));
1095 extern char *strndup (const char *__string, size_t __n)
1096 throw () __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1)));
1099 extern char *strchr (char *__s, int __c)
1100 throw () __asm ("strchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1101 extern const char *strchr (const char *__s, int __c)
1102 throw () __asm ("strchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1103 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char *
1104 strchr (char *__s, int __c) throw ()
1106 return __builtin_strchr (__s, __c);
1108 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char *
1109 strchr (const char *__s, int __c) throw ()
1111 return __builtin_strchr (__s, __c);
1116 extern char *strrchr (char *__s, int __c)
1117 throw () __asm ("strrchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1118 extern const char *strrchr (const char *__s, int __c)
1119 throw () __asm ("strrchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1120 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char *
1121 strrchr (char *__s, int __c) throw ()
1123 return __builtin_strrchr (__s, __c);
1125 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char *
1126 strrchr (const char *__s, int __c) throw ()
1128 return __builtin_strrchr (__s, __c);
1131 extern "C++" char *strchrnul (char *__s, int __c)
1132 throw () __asm ("strchrnul") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1133 extern "C++" const char *strchrnul (const char *__s, int __c)
1134 throw () __asm ("strchrnul") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1135 extern size_t strcspn (const char *__s, const char *__reject)
1136 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1137 extern size_t strspn (const char *__s, const char *__accept)
1138 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1141 extern char *strpbrk (char *__s, const char *__accept)
1142 throw () __asm ("strpbrk") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1143 extern const char *strpbrk (const char *__s, const char *__accept)
1144 throw () __asm ("strpbrk") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1145 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char *
1146 strpbrk (char *__s, const char *__accept) throw ()
1148 return __builtin_strpbrk (__s, __accept);
1150 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char *
1151 strpbrk (const char *__s, const char *__accept) throw ()
1153 return __builtin_strpbrk (__s, __accept);
1158 extern char *strstr (char *__haystack, const char *__needle)
1159 throw () __asm ("strstr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1160 extern const char *strstr (const char *__haystack, const char *__needle)
1161 throw () __asm ("strstr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1162 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char *
1163 strstr (char *__haystack, const char *__needle) throw ()
1165 return __builtin_strstr (__haystack, __needle);
1167 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char *
1168 strstr (const char *__haystack, const char *__needle) throw ()
1170 return __builtin_strstr (__haystack, __needle);
1173 extern char *strtok (char *__restrict __s, const char *__restrict __delim)
1174 throw () __attribute__ ((__nonnull__ (2)));
1175 extern char *__strtok_r (char *__restrict __s,
1176 const char *__restrict __delim,
1177 char **__restrict __save_ptr)
1178 throw () __attribute__ ((__nonnull__ (2, 3)));
1179 extern char *strtok_r (char *__restrict __s, const char *__restrict __delim,
1180 char **__restrict __save_ptr)
1181 throw () __attribute__ ((__nonnull__ (2, 3)));
1182 extern "C++" char *strcasestr (char *__haystack, const char *__needle)
1183 throw () __asm ("strcasestr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1184 extern "C++" const char *strcasestr (const char *__haystack,
1185 const char *__needle)
1186 throw () __asm ("strcasestr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1187 extern void *memmem (const void *__haystack, size_t __haystacklen,
1188 const void *__needle, size_t __needlelen)
1189 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 3)));
1190 extern void *__mempcpy (void *__restrict __dest,
1191 const void *__restrict __src, size_t __n)
1192 throw () __attribute__ ((__nonnull__ (1, 2)));
1193 extern void *mempcpy (void *__restrict __dest,
1194 const void *__restrict __src, size_t __n)
1195 throw () __attribute__ ((__nonnull__ (1, 2)));
1196 extern size_t strlen (const char *__s)
1197 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1198 extern size_t strnlen (const char *__string, size_t __maxlen)
1199 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1200 extern char *strerror (int __errnum) throw ();
1201 extern char *strerror_r (int __errnum, char *__buf, size_t __buflen)
1202 throw () __attribute__ ((__nonnull__ (2))) __attribute__ ((__warn_unused_result__));
1203 extern char *strerror_l (int __errnum, __locale_t __l) throw ();
1204 extern void __bzero (void *__s, size_t __n) throw () __attribute__ ((__nonnull__ (1)));
1205 extern void bcopy (const void *__src, void *__dest, size_t __n)
1206 throw () __attribute__ ((__nonnull__ (1, 2)));
1207 extern void bzero (void *__s, size_t __n) throw () __attribute__ ((__nonnull__ (1)));
1208 extern int bcmp (const void *__s1, const void *__s2, size_t __n)
1209 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1212 extern char *index (char *__s, int __c)
1213 throw () __asm ("index") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1214 extern const char *index (const char *__s, int __c)
1215 throw () __asm ("index") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1216 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char *
1217 index (char *__s, int __c) throw ()
1219 return __builtin_index (__s, __c);
1221 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char *
1222 index (const char *__s, int __c) throw ()
1224 return __builtin_index (__s, __c);
1229 extern char *rindex (char *__s, int __c)
1230 throw () __asm ("rindex") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1231 extern const char *rindex (const char *__s, int __c)
1232 throw () __asm ("rindex") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
1233 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char *
1234 rindex (char *__s, int __c) throw ()
1236 return __builtin_rindex (__s, __c);
1238 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char *
1239 rindex (const char *__s, int __c) throw ()
1241 return __builtin_rindex (__s, __c);
1244 extern int ffs (int __i) throw () __attribute__ ((__const__));
1245 extern int ffsl (long int __l) throw () __attribute__ ((__const__));
1246 __extension__ extern int ffsll (long long int __ll)
1247 throw () __attribute__ ((__const__));
1248 extern int strcasecmp (const char *__s1, const char *__s2)
1249 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1250 extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
1251 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1252 extern int strcasecmp_l (const char *__s1, const char *__s2,
1254 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3)));
1255 extern int strncasecmp_l (const char *__s1, const char *__s2,
1256 size_t __n, __locale_t __loc)
1257 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 4)));
1258 extern char *strsep (char **__restrict __stringp,
1259 const char *__restrict __delim)
1260 throw () __attribute__ ((__nonnull__ (1, 2)));
1261 extern char *strsignal (int __sig) throw ();
1262 extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src)
1263 throw () __attribute__ ((__nonnull__ (1, 2)));
1264 extern char *stpcpy (char *__restrict __dest, const char *__restrict __src)
1265 throw () __attribute__ ((__nonnull__ (1, 2)));
1266 extern char *__stpncpy (char *__restrict __dest,
1267 const char *__restrict __src, size_t __n)
1268 throw () __attribute__ ((__nonnull__ (1, 2)));
1269 extern char *stpncpy (char *__restrict __dest,
1270 const char *__restrict __src, size_t __n)
1271 throw () __attribute__ ((__nonnull__ (1, 2)));
1272 extern int strverscmp (const char *__s1, const char *__s2)
1273 throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
1274 extern char *strfry (char *__string) throw () __attribute__ ((__nonnull__ (1)));
1275 extern void *memfrob (void *__s, size_t __n) throw () __attribute__ ((__nonnull__ (1)));
1276 extern "C++" char *basename (char *__filename)
1277 throw () __asm ("basename") __attribute__ ((__nonnull__ (1)));
1278 extern "C++" const char *basename (const char *__filename)
1279 throw () __asm ("basename") __attribute__ ((__nonnull__ (1)));
1280 extern void __warn_memset_zero_len (void) __attribute__((__warning__ ("memset used with constant zero length parameter; this could be due to transposed parameters")))
1282 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void *
1283 __attribute__ ((__leaf__)) memcpy (void *__restrict __dest, const void *__restrict __src, size_t __len) throw ()
1285 return __builtin___memcpy_chk (__dest, __src, __len, __builtin_object_size (__dest, 0));
1287 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void *
1288 __attribute__ ((__leaf__)) memmove (void *__dest, const void *__src, size_t __len) throw ()
1290 return __builtin___memmove_chk (__dest, __src, __len, __builtin_object_size (__dest, 0));
1292 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void *
1293 __attribute__ ((__leaf__)) mempcpy (void *__restrict __dest, const void *__restrict __src, size_t __len) throw ()
1295 return __builtin___mempcpy_chk (__dest, __src, __len, __builtin_object_size (__dest, 0));
1297 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void *
1298 __attribute__ ((__leaf__)) memset (void *__dest, int __ch, size_t __len) throw ()
1300 if (__builtin_constant_p (__len) && __len == 0
1301 && (!__builtin_constant_p (__ch) || __ch != 0))
1303 __warn_memset_zero_len ();
1306 return __builtin___memset_chk (__dest, __ch, __len, __builtin_object_size (__dest, 0));
1308 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void
1309 __attribute__ ((__leaf__)) bcopy (const void *__src, void *__dest, size_t __len) throw ()
1311 (void) __builtin___memmove_chk (__dest, __src, __len, __builtin_object_size (__dest, 0));
1313 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void
1314 __attribute__ ((__leaf__)) bzero (void *__dest, size_t __len) throw ()
1316 (void) __builtin___memset_chk (__dest, '\0', __len, __builtin_object_size (__dest, 0));
1318 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char *
1319 __attribute__ ((__leaf__)) strcpy (char *__restrict __dest, const char *__restrict __src) throw ()
1321 return __builtin___strcpy_chk (__dest, __src, __builtin_object_size (__dest, 2 > 1));
1323 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char *
1324 __attribute__ ((__leaf__)) stpcpy (char *__restrict __dest, const char *__restrict __src) throw ()
1326 return __builtin___stpcpy_chk (__dest, __src, __builtin_object_size (__dest, 2 > 1));
1328 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char *
1329 __attribute__ ((__leaf__)) strncpy (char *__restrict __dest, const char *__restrict __src, size_t __len) throw ()
1331 return __builtin___strncpy_chk (__dest, __src, __len, __builtin_object_size (__dest, 2 > 1));
1333 extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
1334 size_t __destlen) throw ();
1335 extern char *__stpncpy_alias (char *__dest, const char *__src, size_t __n) throw () __asm__ ("" "stpncpy")
1337 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char *
1338 __attribute__ ((__leaf__)) stpncpy (char *__dest, const char *__src, size_t __n) throw ()
1340 if (__builtin_object_size (__dest, 2 > 1) != (size_t) -1
1341 && (!__builtin_constant_p (__n) || __n <= __builtin_object_size (__dest, 2 > 1)))
1342 return __stpncpy_chk (__dest, __src, __n, __builtin_object_size (__dest, 2 > 1));
1343 return __stpncpy_alias (__dest, __src, __n);
1345 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char *
1346 __attribute__ ((__leaf__)) strcat (char *__restrict __dest, const char *__restrict __src) throw ()
1348 return __builtin___strcat_chk (__dest, __src, __builtin_object_size (__dest, 2 > 1));
1350 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char *
1351 __attribute__ ((__leaf__)) strncat (char *__restrict __dest, const char *__restrict __src, size_t __len) throw ()
1353 return __builtin___strncat_chk (__dest, __src, __len, __builtin_object_size (__dest, 2 > 1));
1356 typedef long int ptrdiff_t;
1357 typedef unsigned char uint8_t;
1358 typedef unsigned short int uint16_t;
1359 typedef unsigned int uint32_t;
1360 typedef unsigned long int uint64_t;
1361 typedef signed char int_least8_t;
1362 typedef short int int_least16_t;
1363 typedef int int_least32_t;
1364 typedef long int int_least64_t;
1365 typedef unsigned char uint_least8_t;
1366 typedef unsigned short int uint_least16_t;
1367 typedef unsigned int uint_least32_t;
1368 typedef unsigned long int uint_least64_t;
1369 typedef signed char int_fast8_t;
1370 typedef long int int_fast16_t;
1371 typedef long int int_fast32_t;
1372 typedef long int int_fast64_t;
1373 typedef unsigned char uint_fast8_t;
1374 typedef unsigned long int uint_fast16_t;
1375 typedef unsigned long int uint_fast32_t;
1376 typedef unsigned long int uint_fast64_t;
1377 typedef long int intptr_t;
1378 typedef unsigned long int uintptr_t;
1379 typedef long int intmax_t;
1380 typedef unsigned long int uintmax_t;
1381 typedef int8_t JSInt8;
1382 typedef int16_t JSInt16;
1383 typedef int32_t JSInt32;
1384 typedef int64_t JSInt64;
1385 typedef intptr_t JSIntPtr;
1386 typedef uint8_t JSUint8;
1387 typedef uint16_t JSUint16;
1388 typedef uint32_t JSUint32;
1389 typedef uint64_t JSUint64;
1390 typedef uintptr_t JSUintPtr;
1393 typedef unsigned int JSUintn;
1394 typedef double JSFloat64;
1395 typedef size_t JSSize;
1396 typedef ptrdiff_t JSPtrdiff;
1397 typedef JSUintPtr JSUptrdiff;
1398 typedef JSIntn JSBool;
1399 typedef JSUint8 JSPackedBool;
1400 typedef JSIntPtr JSWord;
1401 typedef JSUintPtr JSUword;
1402 typedef JSUintn uintn;
1403 typedef JSUint64 uint64;
1404 typedef JSUint32 uint32;
1405 typedef JSUint16 uint16;
1406 typedef JSUint8 uint8;
1407 typedef JSIntn intn;
1408 typedef JSInt64 int64;
1409 typedef JSInt32 int32;
1410 typedef JSInt16 int16;
1411 typedef JSInt8 int8;
1412 typedef JSFloat64 float64;
1416 typedef JSIntn intN;
1417 typedef JSUintn uintN;
1418 typedef JSUword jsuword;
1419 typedef JSWord jsword;
1420 typedef float float32;
1422 extern __attribute__((visibility ("default"))) void
1423 JS_Assert(const char *s, const char *file, JSIntn ln);
1424 extern __attribute__((visibility ("default"))) void JS_Abort(void);
1425 static inline void* js_malloc(size_t bytes) {
1426 return malloc(bytes);
1428 static inline void* js_calloc(size_t bytes) {
1429 return calloc(bytes, 1);
1431 static inline void* js_realloc(void* p, size_t bytes) {
1432 return realloc(p, bytes);
1434 static inline void js_free(void* p) {
1439 __attribute__((always_inline)) inline T *js_new() {
1440 void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T () : __null;
1442 template <class T, class P1>
1443 __attribute__((always_inline)) inline T *js_new(const P1 &p1) {
1444 void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T (p1) : __null;
1446 template <class T, class P1, class P2>
1447 __attribute__((always_inline)) inline T *js_new(const P1 &p1, const P2 &p2) {
1448 void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T (p1, p2) : __null;
1450 template <class T, class P1, class P2, class P3>
1451 __attribute__((always_inline)) inline T *js_new(const P1 &p1, const P2 &p2, const P3 &p3) {
1452 void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T (p1, p2, p3) : __null;
1454 template <class T, class P1, class P2, class P3, class P4>
1455 __attribute__((always_inline)) inline T *js_new(const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4) {
1456 void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T (p1, p2, p3, p4) : __null;
1459 __attribute__((always_inline)) inline void js_delete(T *p) {
1465 static const int JSMinAlignment = 8;
1467 __attribute__((always_inline)) inline T *js_array_new(size_t n) {
1468 uint64 numBytes64 = uint64(JSMinAlignment) + uint64(sizeof(T)) * uint64(n);
1469 size_t numBytes = size_t(numBytes64);
1470 if (numBytes64 != numBytes) {
1474 void *memory = js_malloc(numBytes);
1477 *(size_t *)memory = n;
1478 memory = (void*)(uintptr_t(memory) + JSMinAlignment);
1479 return new(memory) T[n];
1482 __attribute__((always_inline)) inline void js_array_delete(T *p) {
1484 void* p0 = (void *)(uintptr_t(p) - JSMinAlignment);
1485 size_t n = *(size_t *)p0;
1486 for (size_t i = 0; i < n; i++)
1493 __attribute__((always_inline)) inline static void
1496 memset(t, 0, sizeof(T));
1499 __attribute__((always_inline)) inline static void
1500 PodZero(T *t, size_t nelem)
1502 memset(t, 0, nelem * sizeof(T));
1504 template <class T, size_t N> static void PodZero(T (&)[N]);
1505 template <class T, size_t N> static void PodZero(T (&)[N], size_t);
1506 template <class T, size_t N>
1507 __attribute__((always_inline)) inline static void
1508 PodArrayZero(T (&t)[N])
1510 memset(t, 0, N * sizeof(T));
1513 __attribute__((always_inline)) inline static void
1514 PodCopy(T *dst, const T *src, size_t nelem)
1519 for (const T *srcend = src + nelem; src != srcend; ++src, ++dst)
1522 memcpy(dst, src, nelem * sizeof(T));
1527 typedef jsuword jsbitmap_t;
1528 typedef jsbitmap_t jsbitmap;
1529 extern __attribute__((visibility ("default"))) JSIntn JS_CeilingLog2(JSUint32 i);
1530 extern __attribute__((visibility ("default"))) JSIntn JS_FloorLog2(JSUint32 i);
1533 CountTrailingZeros(size_t n)
1536 return __builtin_ctzll(n);
1542 typedef struct _IO_FILE FILE;
1543 typedef struct _IO_FILE __FILE;
1556 __mbstate_t __state;
1561 __mbstate_t __state;
1563 typedef __builtin_va_list __gnuc_va_list;
1564 struct _IO_jump_t; struct _IO_FILE;
1565 typedef void _IO_lock_t;
1567 struct _IO_marker *_next;
1568 struct _IO_FILE *_sbuf;
1571 enum __codecvt_result
1582 char* _IO_read_base;
1583 char* _IO_write_base;
1584 char* _IO_write_ptr;
1585 char* _IO_write_end;
1588 char *_IO_save_base;
1589 char *_IO_backup_base;
1591 struct _IO_marker *_markers;
1592 struct _IO_FILE *_chain;
1595 __off_t _old_offset;
1596 unsigned short _cur_column;
1597 signed char _vtable_offset;
1607 char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
1609 struct _IO_FILE_plus;
1610 extern struct _IO_FILE_plus _IO_2_1_stdin_;
1611 extern struct _IO_FILE_plus _IO_2_1_stdout_;
1612 extern struct _IO_FILE_plus _IO_2_1_stderr_;
1613 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
1614 typedef __ssize_t __io_write_fn (void *__cookie, const char *__buf,
1616 typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w);
1617 typedef int __io_close_fn (void *__cookie);
1618 typedef __io_read_fn cookie_read_function_t;
1619 typedef __io_write_fn cookie_write_function_t;
1620 typedef __io_seek_fn cookie_seek_function_t;
1621 typedef __io_close_fn cookie_close_function_t;
1625 __io_write_fn *write;
1627 __io_close_fn *close;
1628 } _IO_cookie_io_functions_t;
1629 typedef _IO_cookie_io_functions_t cookie_io_functions_t;
1630 struct _IO_cookie_file;
1631 extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write,
1632 void *__cookie, _IO_cookie_io_functions_t __fns);
1634 extern int __underflow (_IO_FILE *);
1635 extern int __uflow (_IO_FILE *);
1636 extern int __overflow (_IO_FILE *, int);
1637 extern int _IO_getc (_IO_FILE *__fp);
1638 extern int _IO_putc (int __c, _IO_FILE *__fp);
1639 extern int _IO_feof (_IO_FILE *__fp) throw ();
1640 extern int _IO_ferror (_IO_FILE *__fp) throw ();
1641 extern int _IO_peekc_locked (_IO_FILE *__fp);
1642 extern void _IO_flockfile (_IO_FILE *) throw ();
1643 extern void _IO_funlockfile (_IO_FILE *) throw ();
1644 extern int _IO_ftrylockfile (_IO_FILE *) throw ();
1645 extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
1646 __gnuc_va_list, int *__restrict);
1647 extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
1649 extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t);
1650 extern size_t _IO_sgetn (_IO_FILE *, void *, size_t);
1651 extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int);
1652 extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int);
1653 extern void _IO_free_backup_area (_IO_FILE *) throw ();
1655 typedef __gnuc_va_list va_list;
1656 typedef _G_fpos_t fpos_t;
1657 typedef _G_fpos64_t fpos64_t;
1658 extern struct _IO_FILE *stdin;
1659 extern struct _IO_FILE *stdout;
1660 extern struct _IO_FILE *stderr;
1661 extern int remove (const char *__filename) throw ();
1662 extern int rename (const char *__old, const char *__new) throw ();
1663 extern int renameat (int __oldfd, const char *__old, int __newfd,
1664 const char *__new) throw ();
1665 extern FILE *tmpfile (void) __attribute__ ((__warn_unused_result__));
1666 extern FILE *tmpfile64 (void) __attribute__ ((__warn_unused_result__));
1667 extern char *tmpnam (char *__s) throw () __attribute__ ((__warn_unused_result__));
1668 extern char *tmpnam_r (char *__s) throw () __attribute__ ((__warn_unused_result__));
1669 extern char *tempnam (const char *__dir, const char *__pfx)
1670 throw () __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__));
1671 extern int fclose (FILE *__stream);
1672 extern int fflush (FILE *__stream);
1673 extern int fflush_unlocked (FILE *__stream);
1674 extern int fcloseall (void);
1675 extern FILE *fopen (const char *__restrict __filename,
1676 const char *__restrict __modes) __attribute__ ((__warn_unused_result__));
1677 extern FILE *freopen (const char *__restrict __filename,
1678 const char *__restrict __modes,
1679 FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
1680 extern FILE *fopen64 (const char *__restrict __filename,
1681 const char *__restrict __modes) __attribute__ ((__warn_unused_result__));
1682 extern FILE *freopen64 (const char *__restrict __filename,
1683 const char *__restrict __modes,
1684 FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
1685 extern FILE *fdopen (int __fd, const char *__modes) throw () __attribute__ ((__warn_unused_result__));
1686 extern FILE *fopencookie (void *__restrict __magic_cookie,
1687 const char *__restrict __modes,
1688 _IO_cookie_io_functions_t __io_funcs) throw () __attribute__ ((__warn_unused_result__));
1689 extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
1690 throw () __attribute__ ((__warn_unused_result__));
1691 extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) throw () __attribute__ ((__warn_unused_result__));
1692 extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) throw ();
1693 extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
1694 int __modes, size_t __n) throw ();
1695 extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
1696 size_t __size) throw ();
1697 extern void setlinebuf (FILE *__stream) throw ();
1698 extern int fprintf (FILE *__restrict __stream,
1699 const char *__restrict __format, ...);
1700 extern int printf (const char *__restrict __format, ...);
1701 extern int sprintf (char *__restrict __s,
1702 const char *__restrict __format, ...) throw ();
1703 extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
1704 __gnuc_va_list __arg);
1705 extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
1706 extern int vsprintf (char *__restrict __s, const char *__restrict __format,
1707 __gnuc_va_list __arg) throw ();
1708 extern int snprintf (char *__restrict __s, size_t __maxlen,
1709 const char *__restrict __format, ...)
1710 throw () __attribute__ ((__format__ (__printf__, 3, 4)));
1711 extern int vsnprintf (char *__restrict __s, size_t __maxlen,
1712 const char *__restrict __format, __gnuc_va_list __arg)
1713 throw () __attribute__ ((__format__ (__printf__, 3, 0)));
1714 extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
1715 __gnuc_va_list __arg)
1716 throw () __attribute__ ((__format__ (__printf__, 2, 0))) __attribute__ ((__warn_unused_result__));
1717 extern int __asprintf (char **__restrict __ptr,
1718 const char *__restrict __fmt, ...)
1719 throw () __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__ ((__warn_unused_result__));
1720 extern int asprintf (char **__restrict __ptr,
1721 const char *__restrict __fmt, ...)
1722 throw () __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__ ((__warn_unused_result__));
1723 extern int vdprintf (int __fd, const char *__restrict __fmt,
1724 __gnuc_va_list __arg)
1725 __attribute__ ((__format__ (__printf__, 2, 0)));
1726 extern int dprintf (int __fd, const char *__restrict __fmt, ...)
1727 __attribute__ ((__format__ (__printf__, 2, 3)));
1728 extern int fscanf (FILE *__restrict __stream,
1729 const char *__restrict __format, ...) __attribute__ ((__warn_unused_result__));
1730 extern int scanf (const char *__restrict __format, ...) __attribute__ ((__warn_unused_result__));
1731 extern int sscanf (const char *__restrict __s,
1732 const char *__restrict __format, ...) throw ();
1733 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
1734 __gnuc_va_list __arg)
1735 __attribute__ ((__format__ (__scanf__, 2, 0))) __attribute__ ((__warn_unused_result__));
1736 extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
1737 __attribute__ ((__format__ (__scanf__, 1, 0))) __attribute__ ((__warn_unused_result__));
1738 extern int vsscanf (const char *__restrict __s,
1739 const char *__restrict __format, __gnuc_va_list __arg)
1740 throw () __attribute__ ((__format__ (__scanf__, 2, 0)));
1741 extern int fgetc (FILE *__stream);
1742 extern int getc (FILE *__stream);
1743 extern int getchar (void);
1744 extern int getc_unlocked (FILE *__stream);
1745 extern int getchar_unlocked (void);
1746 extern int fgetc_unlocked (FILE *__stream);
1747 extern int fputc (int __c, FILE *__stream);
1748 extern int putc (int __c, FILE *__stream);
1749 extern int putchar (int __c);
1750 extern int fputc_unlocked (int __c, FILE *__stream);
1751 extern int putc_unlocked (int __c, FILE *__stream);
1752 extern int putchar_unlocked (int __c);
1753 extern int getw (FILE *__stream);
1754 extern int putw (int __w, FILE *__stream);
1755 extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
1756 __attribute__ ((__warn_unused_result__));
1757 extern char *gets (char *__s) __attribute__ ((__warn_unused_result__)) __attribute__ ((__deprecated__));
1758 extern char *fgets_unlocked (char *__restrict __s, int __n,
1759 FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
1760 extern __ssize_t __getdelim (char **__restrict __lineptr,
1761 size_t *__restrict __n, int __delimiter,
1762 FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
1763 extern __ssize_t getdelim (char **__restrict __lineptr,
1764 size_t *__restrict __n, int __delimiter,
1765 FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
1766 extern __ssize_t getline (char **__restrict __lineptr,
1767 size_t *__restrict __n,
1768 FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
1769 extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
1770 extern int puts (const char *__s);
1771 extern int ungetc (int __c, FILE *__stream);
1772 extern size_t fread (void *__restrict __ptr, size_t __size,
1773 size_t __n, FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
1774 extern size_t fwrite (const void *__restrict __ptr, size_t __size,
1775 size_t __n, FILE *__restrict __s);
1776 extern int fputs_unlocked (const char *__restrict __s,
1777 FILE *__restrict __stream);
1778 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
1779 size_t __n, FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
1780 extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
1781 size_t __n, FILE *__restrict __stream);
1782 extern int fseek (FILE *__stream, long int __off, int __whence);
1783 extern long int ftell (FILE *__stream) __attribute__ ((__warn_unused_result__));
1784 extern void rewind (FILE *__stream);
1785 extern int fseeko (FILE *__stream, __off_t __off, int __whence);
1786 extern __off_t ftello (FILE *__stream) __attribute__ ((__warn_unused_result__));
1787 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
1788 extern int fsetpos (FILE *__stream, const fpos_t *__pos);
1789 extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);
1790 extern __off64_t ftello64 (FILE *__stream) __attribute__ ((__warn_unused_result__));
1791 extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos);
1792 extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos);
1793 extern void clearerr (FILE *__stream) throw ();
1794 extern int feof (FILE *__stream) throw () __attribute__ ((__warn_unused_result__));
1795 extern int ferror (FILE *__stream) throw () __attribute__ ((__warn_unused_result__));
1796 extern void clearerr_unlocked (FILE *__stream) throw ();
1797 extern int feof_unlocked (FILE *__stream) throw () __attribute__ ((__warn_unused_result__));
1798 extern int ferror_unlocked (FILE *__stream) throw () __attribute__ ((__warn_unused_result__));
1799 extern void perror (const char *__s);
1800 extern int sys_nerr;
1801 extern const char *const sys_errlist[];
1802 extern int _sys_nerr;
1803 extern const char *const _sys_errlist[];
1804 extern int fileno (FILE *__stream) throw () __attribute__ ((__warn_unused_result__));
1805 extern int fileno_unlocked (FILE *__stream) throw () __attribute__ ((__warn_unused_result__));
1806 extern FILE *popen (const char *__command, const char *__modes) __attribute__ ((__warn_unused_result__));
1807 extern int pclose (FILE *__stream);
1808 extern char *ctermid (char *__s) throw ();
1809 extern char *cuserid (char *__s);
1811 extern int obstack_printf (struct obstack *__restrict __obstack,
1812 const char *__restrict __format, ...)
1813 throw () __attribute__ ((__format__ (__printf__, 2, 3)));
1814 extern int obstack_vprintf (struct obstack *__restrict __obstack,
1815 const char *__restrict __format,
1816 __gnuc_va_list __args)
1817 throw () __attribute__ ((__format__ (__printf__, 2, 0)));
1818 extern void flockfile (FILE *__stream) throw ();
1819 extern int ftrylockfile (FILE *__stream) throw () __attribute__ ((__warn_unused_result__));
1820 extern void funlockfile (FILE *__stream) throw ();
1821 extern __inline __attribute__ ((__gnu_inline__)) int
1824 return _IO_getc (stdin);
1826 extern __inline __attribute__ ((__gnu_inline__)) int
1827 fgetc_unlocked (FILE *__fp)
1829 return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++);
1831 extern __inline __attribute__ ((__gnu_inline__)) int
1832 getc_unlocked (FILE *__fp)
1834 return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++);
1836 extern __inline __attribute__ ((__gnu_inline__)) int
1837 getchar_unlocked (void)
1839 return (__builtin_expect (((stdin)->_IO_read_ptr >= (stdin)->_IO_read_end), 0) ? __uflow (stdin) : *(unsigned char *) (stdin)->_IO_read_ptr++);
1841 extern __inline __attribute__ ((__gnu_inline__)) int
1844 return _IO_putc (__c, stdout);
1846 extern __inline __attribute__ ((__gnu_inline__)) int
1847 fputc_unlocked (int __c, FILE *__stream)
1849 return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c)));
1851 extern __inline __attribute__ ((__gnu_inline__)) int
1852 putc_unlocked (int __c, FILE *__stream)
1854 return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c)));
1856 extern __inline __attribute__ ((__gnu_inline__)) int
1857 putchar_unlocked (int __c)
1859 return (__builtin_expect (((stdout)->_IO_write_ptr >= (stdout)->_IO_write_end), 0) ? __overflow (stdout, (unsigned char) (__c)) : (unsigned char) (*(stdout)->_IO_write_ptr++ = (__c)));
1861 extern __inline __attribute__ ((__gnu_inline__)) __ssize_t
1862 getline (char **__lineptr, size_t *__n, FILE *__stream)
1864 return __getdelim (__lineptr, __n, '\n', __stream);
1866 extern __inline __attribute__ ((__gnu_inline__)) int
1867 __attribute__ ((__leaf__)) feof_unlocked (FILE *__stream) throw ()
1869 return (((__stream)->_flags & 0x10) != 0);
1871 extern __inline __attribute__ ((__gnu_inline__)) int
1872 __attribute__ ((__leaf__)) ferror_unlocked (FILE *__stream) throw ()
1874 return (((__stream)->_flags & 0x20) != 0);
1876 extern int __sprintf_chk (char *__restrict __s, int __flag, size_t __slen,
1877 const char *__restrict __format, ...) throw ();
1878 extern int __vsprintf_chk (char *__restrict __s, int __flag, size_t __slen,
1879 const char *__restrict __format,
1880 __gnuc_va_list __ap) throw ();
1881 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1882 __attribute__ ((__leaf__)) sprintf (char *__restrict __s, const char *__restrict __fmt, ...) throw ()
1884 return __builtin___sprintf_chk (__s, 2 - 1,
1885 __builtin_object_size (__s, 2 > 1), __fmt, __builtin_va_arg_pack ());
1887 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1888 __attribute__ ((__leaf__)) vsprintf (char *__restrict __s, const char *__restrict __fmt, __gnuc_va_list __ap) throw ()
1890 return __builtin___vsprintf_chk (__s, 2 - 1,
1891 __builtin_object_size (__s, 2 > 1), __fmt, __ap);
1893 extern int __snprintf_chk (char *__restrict __s, size_t __n, int __flag,
1894 size_t __slen, const char *__restrict __format,
1896 extern int __vsnprintf_chk (char *__restrict __s, size_t __n, int __flag,
1897 size_t __slen, const char *__restrict __format,
1898 __gnuc_va_list __ap) throw ();
1899 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1900 __attribute__ ((__leaf__)) snprintf (char *__restrict __s, size_t __n, const char *__restrict __fmt, ...) throw ()
1902 return __builtin___snprintf_chk (__s, __n, 2 - 1,
1903 __builtin_object_size (__s, 2 > 1), __fmt, __builtin_va_arg_pack ());
1905 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1906 __attribute__ ((__leaf__)) vsnprintf (char *__restrict __s, size_t __n, const char *__restrict __fmt, __gnuc_va_list __ap) throw ()
1908 return __builtin___vsnprintf_chk (__s, __n, 2 - 1,
1909 __builtin_object_size (__s, 2 > 1), __fmt, __ap);
1911 extern int __fprintf_chk (FILE *__restrict __stream, int __flag,
1912 const char *__restrict __format, ...);
1913 extern int __printf_chk (int __flag, const char *__restrict __format, ...);
1914 extern int __vfprintf_chk (FILE *__restrict __stream, int __flag,
1915 const char *__restrict __format, __gnuc_va_list __ap);
1916 extern int __vprintf_chk (int __flag, const char *__restrict __format,
1917 __gnuc_va_list __ap);
1918 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1919 fprintf (FILE *__restrict __stream, const char *__restrict __fmt, ...)
1921 return __fprintf_chk (__stream, 2 - 1, __fmt,
1922 __builtin_va_arg_pack ());
1924 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1925 printf (const char *__restrict __fmt, ...)
1927 return __printf_chk (2 - 1, __fmt, __builtin_va_arg_pack ());
1929 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1930 vprintf (const char *__restrict __fmt, __gnuc_va_list __ap)
1932 return __vfprintf_chk (stdout, 2 - 1, __fmt, __ap);
1934 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1935 vfprintf (FILE *__restrict __stream,
1936 const char *__restrict __fmt, __gnuc_va_list __ap)
1938 return __vfprintf_chk (__stream, 2 - 1, __fmt, __ap);
1940 extern int __dprintf_chk (int __fd, int __flag, const char *__restrict __fmt,
1941 ...) __attribute__ ((__format__ (__printf__, 3, 4)));
1942 extern int __vdprintf_chk (int __fd, int __flag,
1943 const char *__restrict __fmt, __gnuc_va_list __arg)
1944 __attribute__ ((__format__ (__printf__, 3, 0)));
1945 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1946 dprintf (int __fd, const char *__restrict __fmt, ...)
1948 return __dprintf_chk (__fd, 2 - 1, __fmt,
1949 __builtin_va_arg_pack ());
1951 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1952 vdprintf (int __fd, const char *__restrict __fmt, __gnuc_va_list __ap)
1954 return __vdprintf_chk (__fd, 2 - 1, __fmt, __ap);
1956 extern int __asprintf_chk (char **__restrict __ptr, int __flag,
1957 const char *__restrict __fmt, ...)
1958 throw () __attribute__ ((__format__ (__printf__, 3, 4))) __attribute__ ((__warn_unused_result__));
1959 extern int __vasprintf_chk (char **__restrict __ptr, int __flag,
1960 const char *__restrict __fmt, __gnuc_va_list __arg)
1961 throw () __attribute__ ((__format__ (__printf__, 3, 0))) __attribute__ ((__warn_unused_result__));
1962 extern int __obstack_printf_chk (struct obstack *__restrict __obstack,
1963 int __flag, const char *__restrict __format,
1965 throw () __attribute__ ((__format__ (__printf__, 3, 4)));
1966 extern int __obstack_vprintf_chk (struct obstack *__restrict __obstack,
1968 const char *__restrict __format,
1969 __gnuc_va_list __args)
1970 throw () __attribute__ ((__format__ (__printf__, 3, 0)));
1971 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1972 __attribute__ ((__leaf__)) asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...) throw ()
1974 return __asprintf_chk (__ptr, 2 - 1, __fmt,
1975 __builtin_va_arg_pack ());
1977 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1978 __attribute__ ((__leaf__)) __asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...) throw ()
1980 return __asprintf_chk (__ptr, 2 - 1, __fmt,
1981 __builtin_va_arg_pack ());
1983 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1984 __attribute__ ((__leaf__)) obstack_printf (struct obstack *__restrict __obstack, const char *__restrict __fmt, ...) throw ()
1986 return __obstack_printf_chk (__obstack, 2 - 1, __fmt,
1987 __builtin_va_arg_pack ());
1989 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1990 __attribute__ ((__leaf__)) vasprintf (char **__restrict __ptr, const char *__restrict __fmt, __gnuc_va_list __ap) throw ()
1992 return __vasprintf_chk (__ptr, 2 - 1, __fmt, __ap);
1994 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
1995 __attribute__ ((__leaf__)) obstack_vprintf (struct obstack *__restrict __obstack, const char *__restrict __fmt, __gnuc_va_list __ap) throw ()
1997 return __obstack_vprintf_chk (__obstack, 2 - 1, __fmt,
2000 extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n,
2001 FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
2002 extern char *__fgets_alias (char *__restrict __s, int __n, FILE *__restrict __stream) __asm__ ("" "fgets")
2003 __attribute__ ((__warn_unused_result__));
2004 extern char *__fgets_chk_warn (char *__restrict __s, size_t __size, int __n, FILE *__restrict __stream) __asm__ ("" "__fgets_chk")
2005 __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fgets called with bigger size than length " "of destination buffer")))
2007 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) char *
2008 fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
2010 if (__builtin_object_size (__s, 2 > 1) != (size_t) -1)
2012 if (!__builtin_constant_p (__n) || __n <= 0)
2013 return __fgets_chk (__s, __builtin_object_size (__s, 2 > 1), __n, __stream);
2014 if ((size_t) __n > __builtin_object_size (__s, 2 > 1))
2015 return __fgets_chk_warn (__s, __builtin_object_size (__s, 2 > 1), __n, __stream);
2017 return __fgets_alias (__s, __n, __stream);
2019 extern size_t __fread_chk (void *__restrict __ptr, size_t __ptrlen,
2020 size_t __size, size_t __n,
2021 FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
2022 extern size_t __fread_alias (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "fread")
2023 __attribute__ ((__warn_unused_result__));
2024 extern size_t __fread_chk_warn (void *__restrict __ptr, size_t __ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "__fread_chk")
2025 __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fread called with bigger size * nmemb than length " "of destination buffer")))
2027 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) size_t
2028 fread (void *__restrict __ptr, size_t __size, size_t __n,
2029 FILE *__restrict __stream)
2031 if (__builtin_object_size (__ptr, 0) != (size_t) -1)
2033 if (!__builtin_constant_p (__size)
2034 || !__builtin_constant_p (__n)
2035 || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2)))
2036 return __fread_chk (__ptr, __builtin_object_size (__ptr, 0), __size, __n, __stream);
2037 if (__size * __n > __builtin_object_size (__ptr, 0))
2038 return __fread_chk_warn (__ptr, __builtin_object_size (__ptr, 0), __size, __n, __stream);
2040 return __fread_alias (__ptr, __size, __n, __stream);
2042 extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size,
2043 int __n, FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
2044 extern char *__fgets_unlocked_alias (char *__restrict __s, int __n, FILE *__restrict __stream) __asm__ ("" "fgets_unlocked")
2045 __attribute__ ((__warn_unused_result__));
2046 extern char *__fgets_unlocked_chk_warn (char *__restrict __s, size_t __size, int __n, FILE *__restrict __stream) __asm__ ("" "__fgets_unlocked_chk")
2047 __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fgets_unlocked called with bigger size than length " "of destination buffer")))
2049 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) char *
2050 fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream)
2052 if (__builtin_object_size (__s, 2 > 1) != (size_t) -1)
2054 if (!__builtin_constant_p (__n) || __n <= 0)
2055 return __fgets_unlocked_chk (__s, __builtin_object_size (__s, 2 > 1), __n, __stream);
2056 if ((size_t) __n > __builtin_object_size (__s, 2 > 1))
2057 return __fgets_unlocked_chk_warn (__s, __builtin_object_size (__s, 2 > 1), __n, __stream);
2059 return __fgets_unlocked_alias (__s, __n, __stream);
2061 extern size_t __fread_unlocked_chk (void *__restrict __ptr, size_t __ptrlen,
2062 size_t __size, size_t __n,
2063 FILE *__restrict __stream) __attribute__ ((__warn_unused_result__));
2064 extern size_t __fread_unlocked_alias (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "fread_unlocked")
2065 __attribute__ ((__warn_unused_result__));
2066 extern size_t __fread_unlocked_chk_warn (void *__restrict __ptr, size_t __ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "__fread_unlocked_chk")
2067 __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fread_unlocked called with bigger size * nmemb than " "length of destination buffer")))
2069 extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) size_t
2070 fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n,
2071 FILE *__restrict __stream)
2073 if (__builtin_object_size (__ptr, 0) != (size_t) -1)
2075 if (!__builtin_constant_p (__size)
2076 || !__builtin_constant_p (__n)
2077 || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2)))
2078 return __fread_unlocked_chk (__ptr, __builtin_object_size (__ptr, 0), __size, __n,
2080 if (__size * __n > __builtin_object_size (__ptr, 0))
2081 return __fread_unlocked_chk_warn (__ptr, __builtin_object_size (__ptr, 0), __size, __n,
2084 if (__builtin_constant_p (__size)
2085 && __builtin_constant_p (__n)
2086 && (__size | __n) < (((size_t) 1) << (8 * sizeof (size_t) / 2))
2087 && __size * __n <= 8)
2089 size_t __cnt = __size * __n;
2090 char *__cptr = (char *) __ptr;
2093 for (; __cnt > 0; --__cnt)
2095 int __c = (__builtin_expect (((__stream)->_IO_read_ptr >= (__stream)->_IO_read_end), 0) ? __uflow (__stream) : *(unsigned char *) (__stream)->_IO_read_ptr++);
2100 return (__cptr - (char *) __ptr) / __size;
2102 return __fread_unlocked_alias (__ptr, __size, __n, __stream);
2106 extern __attribute__((visibility ("default"))) JSUint32 JS_snprintf(char *out, JSUint32 outlen, const char *fmt, ...);
2107 extern __attribute__((visibility ("default"))) char* JS_smprintf(const char *fmt, ...);
2108 extern __attribute__((visibility ("default"))) void JS_smprintf_free(char *mem);
2109 extern __attribute__((visibility ("default"))) char* JS_sprintf_append(char *last, const char *fmt, ...);
2110 typedef JSIntn (*JSStuffFunc)(void *arg, const char *s, JSUint32 slen);
2111 extern __attribute__((visibility ("default"))) JSUint32 JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...);
2112 extern __attribute__((visibility ("default"))) JSUint32 JS_vsnprintf(char *out, JSUint32 outlen, const char *fmt, va_list ap);
2113 extern __attribute__((visibility ("default"))) char* JS_vsmprintf(const char *fmt, va_list ap);
2114 extern __attribute__((visibility ("default"))) char* JS_vsprintf_append(char *last, const char *fmt, va_list ap);
2115 extern __attribute__((visibility ("default"))) JSUint32 JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap);
2116 extern __attribute__((visibility ("default"))) JSInt32 JS_sscanf(const char *buf, const char *fmt, ...);
2121 JSVAL_TYPE_DOUBLE = 0x00,
2122 JSVAL_TYPE_INT32 = 0x01,
2123 JSVAL_TYPE_UNDEFINED = 0x02,
2124 JSVAL_TYPE_BOOLEAN = 0x03,
2125 JSVAL_TYPE_MAGIC = 0x04,
2126 JSVAL_TYPE_STRING = 0x05,
2127 JSVAL_TYPE_NULL = 0x06,
2128 JSVAL_TYPE_OBJECT = 0x07,
2129 JSVAL_TYPE_NONFUNOBJ = 0x57,
2130 JSVAL_TYPE_FUNOBJ = 0x67,
2131 JSVAL_TYPE_STRORNULL = 0x97,
2132 JSVAL_TYPE_OBJORNULL = 0x98,
2133 JSVAL_TYPE_BOXED = 0x99
2134 } __attribute__((packed));
2135 typedef int js_static_assert0[(sizeof(JSValueType) == 1) ? 1 : -1];
2138 JSVAL_TAG_MAX_DOUBLE = 0x1FFF0,
2139 JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32,
2140 JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED,
2141 JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING,
2142 JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN,
2143 JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC,
2144 JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL,
2145 JSVAL_TAG_OBJECT = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT
2146 } __attribute__((packed));
2147 typedef int js_static_assert1[(sizeof(JSValueTag) == sizeof(uint32)) ? 1 : -1];
2148 enum JSValueShiftedTag
2150 JSVAL_SHIFTED_TAG_MAX_DOUBLE = ((((uint64)JSVAL_TAG_MAX_DOUBLE) << 47) | 0xFFFFFFFF),
2151 JSVAL_SHIFTED_TAG_INT32 = (((uint64)JSVAL_TAG_INT32) << 47),
2152 JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64)JSVAL_TAG_UNDEFINED) << 47),
2153 JSVAL_SHIFTED_TAG_STRING = (((uint64)JSVAL_TAG_STRING) << 47),
2154 JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64)JSVAL_TAG_BOOLEAN) << 47),
2155 JSVAL_SHIFTED_TAG_MAGIC = (((uint64)JSVAL_TAG_MAGIC) << 47),
2156 JSVAL_SHIFTED_TAG_NULL = (((uint64)JSVAL_TAG_NULL) << 47),
2157 JSVAL_SHIFTED_TAG_OBJECT = (((uint64)JSVAL_TAG_OBJECT) << 47)
2158 } __attribute__((packed));
2159 typedef int js_static_assert2[(sizeof(JSValueShiftedTag) == sizeof(uint64)) ? 1 : -1];
2160 typedef enum JSWhyMagic
2164 JS_NATIVE_ENUMERATE,
2166 JS_GENERATOR_CLOSING,
2170 JS_SERIALIZE_NO_NODE,
2173 typedef struct JSString JSString;
2174 typedef struct JSFlatString JSFlatString;
2175 typedef struct JSObject JSObject;
2176 typedef union jsval_layout
2180 uint64 payload47 : 47;
2181 JSValueTag tag : 17;
2194 static __attribute__((always_inline)) inline JSBool
2195 JSVAL_IS_DOUBLE_IMPL(jsval_layout l)
2197 return l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE;
2199 static __attribute__((always_inline)) inline jsval_layout
2200 DOUBLE_TO_JSVAL_IMPL(double d)
2207 static __attribute__((always_inline)) inline JSBool
2208 JSVAL_IS_INT32_IMPL(jsval_layout l)
2210 return (uint32)(l.asBits >> 47) == JSVAL_TAG_INT32;
2212 static __attribute__((always_inline)) inline int32
2213 JSVAL_TO_INT32_IMPL(jsval_layout l)
2215 return (int32)l.asBits;
2217 static __attribute__((always_inline)) inline jsval_layout
2218 INT32_TO_JSVAL_IMPL(int32 i32)
2221 l.asBits = ((uint64)(uint32)i32) | JSVAL_SHIFTED_TAG_INT32;
2224 static __attribute__((always_inline)) inline JSBool
2225 JSVAL_IS_NUMBER_IMPL(jsval_layout l)
2227 return l.asBits < JSVAL_SHIFTED_TAG_UNDEFINED;
2229 static __attribute__((always_inline)) inline JSBool
2230 JSVAL_IS_UNDEFINED_IMPL(jsval_layout l)
2232 return l.asBits == JSVAL_SHIFTED_TAG_UNDEFINED;
2234 static __attribute__((always_inline)) inline JSBool
2235 JSVAL_IS_STRING_IMPL(jsval_layout l)
2237 return (uint32)(l.asBits >> 47) == JSVAL_TAG_STRING;
2239 static __attribute__((always_inline)) inline jsval_layout
2240 STRING_TO_JSVAL_IMPL(JSString *str)
2243 uint64 strBits = (uint64)str;
2246 l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING;
2249 static __attribute__((always_inline)) inline JSString *
2250 JSVAL_TO_STRING_IMPL(jsval_layout l)
2252 return (JSString *)(l.asBits & 0x00007FFFFFFFFFFFLL);
2254 static __attribute__((always_inline)) inline JSBool
2255 JSVAL_IS_BOOLEAN_IMPL(jsval_layout l)
2257 return (uint32)(l.asBits >> 47) == JSVAL_TAG_BOOLEAN;
2259 static __attribute__((always_inline)) inline JSBool
2260 JSVAL_TO_BOOLEAN_IMPL(jsval_layout l)
2262 return (JSBool)l.asBits;
2264 static __attribute__((always_inline)) inline jsval_layout
2265 BOOLEAN_TO_JSVAL_IMPL(JSBool b)
2268 l.asBits = ((uint64)(uint32)b) | JSVAL_SHIFTED_TAG_BOOLEAN;
2271 static __attribute__((always_inline)) inline JSBool
2272 JSVAL_IS_MAGIC_IMPL(jsval_layout l)
2274 return (l.asBits >> 47) == JSVAL_TAG_MAGIC;
2276 static __attribute__((always_inline)) inline JSObject *
2277 MAGIC_JSVAL_TO_OBJECT_OR_NULL_IMPL(jsval_layout l)
2279 uint64 ptrBits = l.asBits & 0x00007FFFFFFFFFFFLL;
2282 return (JSObject *)ptrBits;
2284 static __attribute__((always_inline)) inline JSBool
2285 JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l)
2287 return l.asBits < JSVAL_SHIFTED_TAG_OBJECT;
2289 static __attribute__((always_inline)) inline JSBool
2290 JSVAL_IS_OBJECT_IMPL(jsval_layout l)
2293 return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT;
2295 static __attribute__((always_inline)) inline JSBool
2296 JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l)
2299 return l.asBits >= JSVAL_SHIFTED_TAG_NULL;
2301 static __attribute__((always_inline)) inline JSObject *
2302 JSVAL_TO_OBJECT_IMPL(jsval_layout l)
2304 uint64 ptrBits = l.asBits & 0x00007FFFFFFFFFFFLL;
2306 return (JSObject *)ptrBits;
2308 static __attribute__((always_inline)) inline jsval_layout
2309 OBJECT_TO_JSVAL_IMPL(JSObject *obj)
2312 uint64 objBits = (uint64)obj;
2315 l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT;
2318 static __attribute__((always_inline)) inline JSBool
2319 JSVAL_IS_NULL_IMPL(jsval_layout l)
2321 return l.asBits == JSVAL_SHIFTED_TAG_NULL;
2323 static __attribute__((always_inline)) inline JSBool
2324 JSVAL_IS_GCTHING_IMPL(jsval_layout l)
2326 return l.asBits >= JSVAL_SHIFTED_TAG_STRING;
2328 static __attribute__((always_inline)) inline void *
2329 JSVAL_TO_GCTHING_IMPL(jsval_layout l)
2331 uint64 ptrBits = l.asBits & 0x00007FFFFFFFFFFFLL;
2333 return (void *)ptrBits;
2335 static __attribute__((always_inline)) inline JSBool
2336 JSVAL_IS_TRACEABLE_IMPL(jsval_layout l)
2338 return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l);
2340 static __attribute__((always_inline)) inline uint32
2341 JSVAL_TRACE_KIND_IMPL(jsval_layout l)
2343 return (uint32)(JSBool)!(JSVAL_IS_OBJECT_IMPL(l));
2345 static __attribute__((always_inline)) inline jsval_layout
2346 PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr)
2349 uint64 ptrBits = (uint64)ptr;
2351 l.asBits = ptrBits >> 1;
2355 static __attribute__((always_inline)) inline void *
2356 JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l)
2359 return (void *)(l.asBits << 1);
2361 static __attribute__((always_inline)) inline double
2362 JS_CANONICALIZE_NAN(double d)
2364 if ((__builtin_expect((d != d), 0))) {
2366 l.asBits = 0x7FF8000000000000LL;
2371 typedef __attribute__((aligned (8))) uint64 jsval;
2372 typedef ptrdiff_t jsid;
2375 typedef JSInt32 jsint;
2376 typedef JSUint32 jsuint;
2377 typedef float64 jsdouble;
2378 typedef JSInt32 jsrefcount;
2379 typedef JSUint16 jschar;
2380 typedef enum JSVersion {
2381 JSVERSION_1_0 = 100,
2382 JSVERSION_1_1 = 110,
2383 JSVERSION_1_2 = 120,
2384 JSVERSION_1_3 = 130,
2385 JSVERSION_1_4 = 140,
2386 JSVERSION_ECMA_3 = 148,
2387 JSVERSION_1_5 = 150,
2388 JSVERSION_1_6 = 160,
2389 JSVERSION_1_7 = 170,
2390 JSVERSION_1_8 = 180,
2391 JSVERSION_ECMA_5 = 185,
2392 JSVERSION_DEFAULT = 0,
2393 JSVERSION_UNKNOWN = -1,
2394 JSVERSION_LATEST = JSVERSION_ECMA_5
2396 typedef enum JSType {
2407 typedef enum JSProtoKey {
2410 JSProto_Function = 2,
2412 JSProto_Boolean = 4,
2418 JSProto_RegExp = 10,
2420 JSProto_Namespace = 12,
2422 JSProto_Reflect = 14,
2423 JSProto_ASTNode = 15,
2425 JSProto_InternalError = 17,
2426 JSProto_EvalError = 18,
2427 JSProto_RangeError = 19,
2428 JSProto_ReferenceError = 20,
2429 JSProto_SyntaxError = 21,
2430 JSProto_TypeError = 22,
2431 JSProto_URIError = 23,
2432 JSProto_Generator = 24,
2433 JSProto_Iterator = 25,
2434 JSProto_StopIteration = 26,
2435 JSProto_ArrayBuffer = 27,
2436 JSProto_Int8Array = 28,
2437 JSProto_Uint8Array = 29,
2438 JSProto_Int16Array = 30,
2439 JSProto_Uint16Array = 31,
2440 JSProto_Int32Array = 32,
2441 JSProto_Uint32Array = 33,
2442 JSProto_Float32Array = 34,
2443 JSProto_Float64Array = 35,
2444 JSProto_Uint8ClampedArray = 36,
2446 JSProto_AnyName = 38,
2449 typedef enum JSAccessMode {
2457 typedef enum JSIterateOp {
2459 JSENUMERATE_INIT_ALL,
2463 typedef struct JSClass JSClass;
2464 typedef struct JSConstDoubleSpec JSConstDoubleSpec;
2465 typedef struct JSContext JSContext;
2466 typedef struct JSErrorReport JSErrorReport;
2467 typedef struct JSFunction JSFunction;
2468 typedef struct JSFunctionSpec JSFunctionSpec;
2469 typedef struct JSTracer JSTracer;
2470 typedef struct JSIdArray JSIdArray;
2471 typedef struct JSPropertyDescriptor JSPropertyDescriptor;
2472 typedef struct JSPropertySpec JSPropertySpec;
2473 typedef struct JSObjectMap JSObjectMap;
2474 typedef struct JSRuntime JSRuntime;
2475 typedef struct JSStackFrame JSStackFrame;
2476 typedef struct JSXDRState JSXDRState;
2477 typedef struct JSExceptionState JSExceptionState;
2478 typedef struct JSLocaleCallbacks JSLocaleCallbacks;
2479 typedef struct JSSecurityCallbacks JSSecurityCallbacks;
2480 typedef struct JSONParser JSONParser;
2481 typedef struct JSCompartment JSCompartment;
2482 typedef struct JSCrossCompartmentCall JSCrossCompartmentCall;
2483 typedef struct JSStructuredCloneWriter JSStructuredCloneWriter;
2484 typedef struct JSStructuredCloneReader JSStructuredCloneReader;
2485 typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks;
2486 typedef class JSWrapper JSWrapper;
2487 typedef class JSCrossCompartmentWrapper JSCrossCompartmentWrapper;
2489 (* JSPropertyOp)(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
2491 (* JSStrictPropertyOp)(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
2493 (* JSNewEnumerateOp)(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
2494 jsval *statep, jsid *idp);
2496 (* JSEnumerateOp)(JSContext *cx, JSObject *obj);
2498 (* JSResolveOp)(JSContext *cx, JSObject *obj, jsid id);
2500 (* JSNewResolveOp)(JSContext *cx, JSObject *obj, jsid id, uintN flags,
2503 (* JSConvertOp)(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
2505 (* JSTypeOfOp)(JSContext *cx, JSObject *obj);
2507 (* JSFinalizeOp)(JSContext *cx, JSObject *obj);
2509 (* JSStringFinalizeOp)(JSContext *cx, JSString *str);
2511 (* JSCheckAccessOp)(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
2514 (* JSXDRObjectOp)(JSXDRState *xdr, JSObject **objp);
2516 (* JSHasInstanceOp)(JSContext *cx, JSObject *obj, const jsval *v, JSBool *bp);
2518 (* JSMarkOp)(JSContext *cx, JSObject *obj, void *arg);
2520 (* JSTraceOp)(JSTracer *trc, JSObject *obj);
2522 (* JSTraceCallback)(JSTracer *trc, void *thing, uint32 kind);
2524 (* JSTraceNamePrinter)(JSTracer *trc, char *buf, size_t bufsize);
2526 (* JSEqualityOp)(JSContext *cx, JSObject *obj, const jsval *v, JSBool *bp);
2528 (* JSNative)(JSContext *cx, uintN argc, jsval *vp);
2529 typedef enum JSContextOp {
2534 (* JSContextCallback)(JSContext *cx, uintN contextOp);
2535 typedef enum JSGCStatus {
2542 (* JSGCCallback)(JSContext *cx, JSGCStatus status);
2544 (* JSTraceDataOp)(JSTracer *trc, void *data);
2546 (* JSOperationCallback)(JSContext *cx);
2548 (* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report);
2549 typedef enum JSExnType {
2561 typedef struct JSErrorFormatString {
2565 } JSErrorFormatString;
2566 typedef const JSErrorFormatString *
2567 (* JSErrorCallback)(void *userRef, const char *locale,
2568 const uintN errorNumber);
2570 (* JSArgumentFormatter)(JSContext *cx, const char *format, JSBool fromJS,
2571 jsval **vpp, va_list *app);
2573 (* JSLocaleToUpperCase)(JSContext *cx, JSString *src, jsval *rval);
2575 (* JSLocaleToLowerCase)(JSContext *cx, JSString *src, jsval *rval);
2577 (* JSLocaleCompare)(JSContext *cx, JSString *src1, JSString *src2,
2580 (* JSLocaleToUnicode)(JSContext *cx, const char *src, jsval *rval);
2581 typedef struct JSPrincipals JSPrincipals;
2583 (* JSPrincipalsTranscoder)(JSXDRState *xdr, JSPrincipals **principalsp);
2584 typedef JSPrincipals *
2585 (* JSObjectPrincipalsFinder)(JSContext *cx, JSObject *obj);
2587 (* JSCSPEvalChecker)(JSContext *cx);
2589 (* JSWrapObjectCallback)(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent,
2592 (* JSPreWrapCallback)(JSContext *cx, JSObject *scope, JSObject *obj, uintN flags);
2595 JSCOMPARTMENT_DESTROY
2598 (* JSCompartmentCallback)(JSContext *cx, JSCompartment *compartment, uintN compartmentOp);
2599 typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r,
2600 uint32 tag, uint32 data, void *closure);
2601 typedef JSBool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w,
2602 JSObject *obj, void *closure);
2603 typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32 errorid);
2606 static __attribute__((always_inline)) inline JSBool
2607 JSVAL_IS_NULL(jsval v)
2611 return JSVAL_IS_NULL_IMPL(l);
2613 static __attribute__((always_inline)) inline JSBool
2614 JSVAL_IS_VOID(jsval v)
2618 return JSVAL_IS_UNDEFINED_IMPL(l);
2620 static __attribute__((always_inline)) inline JSBool
2621 JSVAL_IS_INT(jsval v)
2625 return JSVAL_IS_INT32_IMPL(l);
2627 static __attribute__((always_inline)) inline jsint
2628 JSVAL_TO_INT(jsval v)
2633 return JSVAL_TO_INT32_IMPL(l);
2635 static __attribute__((always_inline)) inline jsval
2636 INT_TO_JSVAL(int32 i)
2638 return ((INT32_TO_JSVAL_IMPL(i)).asBits);
2640 static __attribute__((always_inline)) inline JSBool
2641 JSVAL_IS_DOUBLE(jsval v)
2645 return JSVAL_IS_DOUBLE_IMPL(l);
2647 static __attribute__((always_inline)) inline jsdouble
2648 JSVAL_TO_DOUBLE(jsval v)
2655 static __attribute__((always_inline)) inline jsval
2656 DOUBLE_TO_JSVAL(jsdouble d)
2658 d = JS_CANONICALIZE_NAN(d);
2659 return ((DOUBLE_TO_JSVAL_IMPL(d)).asBits);
2661 static __attribute__((always_inline)) inline jsval
2662 UINT_TO_JSVAL(uint32 i)
2664 if (i <= ((jsint)0x7fffffff))
2665 return INT_TO_JSVAL((int32)i);
2666 return DOUBLE_TO_JSVAL((jsdouble)i);
2668 static __attribute__((always_inline)) inline JSBool
2669 JSVAL_IS_NUMBER(jsval v)
2673 return JSVAL_IS_NUMBER_IMPL(l);
2675 static __attribute__((always_inline)) inline JSBool
2676 JSVAL_IS_STRING(jsval v)
2680 return JSVAL_IS_STRING_IMPL(l);
2682 static __attribute__((always_inline)) inline JSString *
2683 JSVAL_TO_STRING(jsval v)
2688 return JSVAL_TO_STRING_IMPL(l);
2690 static __attribute__((always_inline)) inline jsval
2691 STRING_TO_JSVAL(JSString *str)
2693 return ((STRING_TO_JSVAL_IMPL(str)).asBits);
2695 static __attribute__((always_inline)) inline JSBool
2696 JSVAL_IS_OBJECT(jsval v)
2700 return JSVAL_IS_OBJECT_OR_NULL_IMPL(l);
2702 static __attribute__((always_inline)) inline JSObject *
2703 JSVAL_TO_OBJECT(jsval v)
2708 return JSVAL_TO_OBJECT_IMPL(l);
2710 static __attribute__((always_inline)) inline jsval
2711 OBJECT_TO_JSVAL(JSObject *obj)
2714 return ((OBJECT_TO_JSVAL_IMPL(obj)).asBits);
2715 return ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
2717 static __attribute__((always_inline)) inline JSBool
2718 JSVAL_IS_BOOLEAN(jsval v)
2722 return JSVAL_IS_BOOLEAN_IMPL(l);
2724 static __attribute__((always_inline)) inline JSBool
2725 JSVAL_TO_BOOLEAN(jsval v)
2730 return JSVAL_TO_BOOLEAN_IMPL(l);
2732 static __attribute__((always_inline)) inline jsval
2733 BOOLEAN_TO_JSVAL(JSBool b)
2735 return ((BOOLEAN_TO_JSVAL_IMPL(b)).asBits);
2737 static __attribute__((always_inline)) inline JSBool
2738 JSVAL_IS_PRIMITIVE(jsval v)
2742 return JSVAL_IS_PRIMITIVE_IMPL(l);
2744 static __attribute__((always_inline)) inline JSBool
2745 JSVAL_IS_GCTHING(jsval v)
2749 return JSVAL_IS_GCTHING_IMPL(l);
2751 static __attribute__((always_inline)) inline void *
2752 JSVAL_TO_GCTHING(jsval v)
2757 return JSVAL_TO_GCTHING_IMPL(l);
2759 static __attribute__((always_inline)) inline jsval
2760 PRIVATE_TO_JSVAL(void *ptr)
2762 return ((PRIVATE_PTR_TO_JSVAL_IMPL(ptr)).asBits);
2764 static __attribute__((always_inline)) inline void *
2765 JSVAL_TO_PRIVATE(jsval v)
2770 return JSVAL_TO_PRIVATE_PTR_IMPL(l);
2772 static __attribute__((always_inline)) inline JSBool
2773 JSID_IS_STRING(jsid iden)
2775 return ((iden) & 0x7) == 0;
2777 static __attribute__((always_inline)) inline JSString *
2778 JSID_TO_STRING(jsid iden)
2781 return (JSString *)((iden));
2783 static __attribute__((always_inline)) inline JSBool
2784 JSID_IS_ZERO(jsid iden)
2788 __attribute__((visibility ("default"))) JSBool
2789 JS_StringHasBeenInterned(JSString *str);
2790 static __attribute__((always_inline)) inline jsid
2791 INTERNED_STRING_TO_JSID(JSString *str)
2797 (iden) = (size_t)str;
2800 static __attribute__((always_inline)) inline JSBool
2801 JSID_IS_INT(jsid iden)
2803 return !!((iden) & 0x1);
2805 static __attribute__((always_inline)) inline int32
2806 JSID_TO_INT(jsid iden)
2809 return ((int32)(iden)) >> 1;
2811 static __attribute__((always_inline)) inline JSBool
2812 INT_FITS_IN_JSID(int32 i)
2814 return ((jsuint)(i) - (jsuint)(-(1 << 30)) <=
2815 (jsuint)(((1 << 30) - 1) - (-(1 << 30))));
2817 static __attribute__((always_inline)) inline jsid
2818 INT_TO_JSID(int32 i)
2822 (iden) = ((i << 1) | 0x1);
2825 static __attribute__((always_inline)) inline JSBool
2826 JSID_IS_OBJECT(jsid iden)
2828 return ((iden) & 0x7) == 0x4 &&
2829 (size_t)(iden) != 0x4;
2831 static __attribute__((always_inline)) inline JSObject *
2832 JSID_TO_OBJECT(jsid iden)
2835 return (JSObject *)((iden) & ~(size_t)0x7);
2837 static __attribute__((always_inline)) inline jsid
2838 OBJECT_TO_JSID(JSObject *obj)
2843 (iden) = ((size_t)obj | 0x4);
2846 static __attribute__((always_inline)) inline JSBool
2847 JSID_IS_GCTHING(jsid iden)
2849 return JSID_IS_STRING(iden) || JSID_IS_OBJECT(iden);
2851 static __attribute__((always_inline)) inline void *
2852 JSID_TO_GCTHING(jsid iden)
2854 return (void *)((iden) & ~(size_t)0x7);
2856 static __attribute__((always_inline)) inline JSBool
2857 JSID_IS_DEFAULT_XML_NAMESPACE(jsid iden)
2861 return ((size_t)(iden) == 0x6);
2863 static __attribute__((always_inline)) inline JSBool
2864 JSID_IS_VOID(jsid iden)
2868 return ((size_t)(iden) == 0x2);
2870 static __attribute__((always_inline)) inline JSBool
2871 JSID_IS_EMPTY(jsid iden)
2873 return ((size_t)(iden) == 0x4);
2875 extern __attribute__((visibility ("default"))) int64
2877 extern __attribute__((visibility ("default"))) jsval
2878 JS_GetNaNValue(JSContext *cx);
2879 extern __attribute__((visibility ("default"))) jsval
2880 JS_GetNegativeInfinityValue(JSContext *cx);
2881 extern __attribute__((visibility ("default"))) jsval
2882 JS_GetPositiveInfinityValue(JSContext *cx);
2883 extern __attribute__((visibility ("default"))) jsval
2884 JS_GetEmptyStringValue(JSContext *cx);
2885 extern __attribute__((visibility ("default"))) JSString *
2886 JS_GetEmptyString(JSRuntime *rt);
2887 extern __attribute__((visibility ("default"))) JSBool
2888 JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format,
2890 extern __attribute__((visibility ("default"))) JSBool
2891 JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv,
2892 const char *format, va_list ap);
2893 extern __attribute__((visibility ("default"))) JSBool
2894 JS_AddArgumentFormatter(JSContext *cx, const char *format,
2895 JSArgumentFormatter formatter);
2896 extern __attribute__((visibility ("default"))) void
2897 JS_RemoveArgumentFormatter(JSContext *cx, const char *format);
2898 extern __attribute__((visibility ("default"))) JSBool
2899 JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
2900 extern __attribute__((visibility ("default"))) JSBool
2901 JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
2902 extern __attribute__((visibility ("default"))) JSFunction *
2903 JS_ValueToFunction(JSContext *cx, jsval v);
2904 extern __attribute__((visibility ("default"))) JSFunction *
2905 JS_ValueToConstructor(JSContext *cx, jsval v);
2906 extern __attribute__((visibility ("default"))) JSString *
2907 JS_ValueToString(JSContext *cx, jsval v);
2908 extern __attribute__((visibility ("default"))) JSString *
2909 JS_ValueToSource(JSContext *cx, jsval v);
2910 extern __attribute__((visibility ("default"))) JSBool
2911 JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
2912 extern __attribute__((visibility ("default"))) JSBool
2913 JS_DoubleIsInt32(jsdouble d, jsint *ip);
2914 extern __attribute__((visibility ("default"))) JSBool
2915 JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip);
2916 extern __attribute__((visibility ("default"))) JSBool
2917 JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip);
2918 extern __attribute__((visibility ("default"))) JSBool
2919 JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip);
2920 extern __attribute__((visibility ("default"))) JSBool
2921 JS_ValueToUint16(JSContext *cx, jsval v, uint16 *ip);
2922 extern __attribute__((visibility ("default"))) JSBool
2923 JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
2924 extern __attribute__((visibility ("default"))) JSType
2925 JS_TypeOfValue(JSContext *cx, jsval v);
2926 extern __attribute__((visibility ("default"))) const char *
2927 JS_GetTypeName(JSContext *cx, JSType type);
2928 extern __attribute__((visibility ("default"))) JSBool
2929 JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, JSBool *equal);
2930 extern __attribute__((visibility ("default"))) JSBool
2931 JS_SameValue(JSContext *cx, jsval v1, jsval v2, JSBool *same);
2932 extern __attribute__((visibility ("default"))) JSRuntime *
2933 JS_Init(uint32 maxbytes);
2934 extern __attribute__((visibility ("default"))) void
2935 JS_Finish(JSRuntime *rt);
2936 extern __attribute__((visibility ("default"))) void
2938 __attribute__((visibility ("default"))) void *
2939 JS_GetRuntimePrivate(JSRuntime *rt);
2940 __attribute__((visibility ("default"))) void
2941 JS_SetRuntimePrivate(JSRuntime *rt, void *data);
2942 extern __attribute__((visibility ("default"))) void
2943 JS_BeginRequest(JSContext *cx);
2944 extern __attribute__((visibility ("default"))) void
2945 JS_EndRequest(JSContext *cx);
2946 extern __attribute__((visibility ("default"))) void
2947 JS_YieldRequest(JSContext *cx);
2948 extern __attribute__((visibility ("default"))) jsrefcount
2949 JS_SuspendRequest(JSContext *cx);
2950 extern __attribute__((visibility ("default"))) void
2951 JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth);
2952 extern __attribute__((visibility ("default"))) JSBool
2953 JS_IsInRequest(JSContext *cx);
2955 class JSAutoRequest {
2957 JSAutoRequest(JSContext *cx )
2958 : mContext(cx), mSaveDepth(0) {
2960 JS_BeginRequest(mContext);
2963 JS_EndRequest(mContext);
2966 mSaveDepth = JS_SuspendRequest(mContext);
2969 JS_ResumeRequest(mContext, mSaveDepth);
2972 JSContext *mContext;
2973 jsrefcount mSaveDepth;
2976 class JSAutoSuspendRequest {
2978 JSAutoSuspendRequest(JSContext *cx )
2979 : mContext(cx), mSaveDepth(0) {
2982 mSaveDepth = JS_SuspendRequest(mContext);
2985 ~JSAutoSuspendRequest() {
2990 JS_ResumeRequest(mContext, mSaveDepth);
2995 JSContext *mContext;
2996 jsrefcount mSaveDepth;
2999 class JSAutoCheckRequest {
3001 JSAutoCheckRequest(JSContext *cx ) {
3004 ~JSAutoCheckRequest() {
3010 extern __attribute__((visibility ("default"))) void
3011 JS_Lock(JSRuntime *rt);
3012 extern __attribute__((visibility ("default"))) void
3013 JS_Unlock(JSRuntime *rt);
3014 extern __attribute__((visibility ("default"))) JSContextCallback
3015 JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback);
3016 extern __attribute__((visibility ("default"))) JSContext *
3017 JS_NewContext(JSRuntime *rt, size_t stackChunkSize);
3018 extern __attribute__((visibility ("default"))) void
3019 JS_DestroyContext(JSContext *cx);
3020 extern __attribute__((visibility ("default"))) void
3021 JS_DestroyContextNoGC(JSContext *cx);
3022 extern __attribute__((visibility ("default"))) void
3023 JS_DestroyContextMaybeGC(JSContext *cx);
3024 extern __attribute__((visibility ("default"))) void *
3025 JS_GetContextPrivate(JSContext *cx);
3026 extern __attribute__((visibility ("default"))) void
3027 JS_SetContextPrivate(JSContext *cx, void *data);
3028 extern __attribute__((visibility ("default"))) JSRuntime *
3029 JS_GetRuntime(JSContext *cx);
3030 extern __attribute__((visibility ("default"))) JSContext *
3031 JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
3032 extern __attribute__((visibility ("default"))) JSVersion
3033 JS_GetVersion(JSContext *cx);
3034 extern __attribute__((visibility ("default"))) JSVersion
3035 JS_SetVersion(JSContext *cx, JSVersion version);
3036 extern __attribute__((visibility ("default"))) const char *
3037 JS_VersionToString(JSVersion version);
3038 extern __attribute__((visibility ("default"))) JSVersion
3039 JS_StringToVersion(const char *string);
3040 extern __attribute__((visibility ("default"))) uint32
3041 JS_GetOptions(JSContext *cx);
3042 extern __attribute__((visibility ("default"))) uint32
3043 JS_SetOptions(JSContext *cx, uint32 options);
3044 extern __attribute__((visibility ("default"))) uint32
3045 JS_ToggleOptions(JSContext *cx, uint32 options);
3046 extern __attribute__((visibility ("default"))) const char *
3047 JS_GetImplementationVersion(void);
3048 extern __attribute__((visibility ("default"))) JSCompartmentCallback
3049 JS_SetCompartmentCallback(JSRuntime *rt, JSCompartmentCallback callback);
3050 extern __attribute__((visibility ("default"))) JSWrapObjectCallback
3051 JS_SetWrapObjectCallbacks(JSRuntime *rt,
3052 JSWrapObjectCallback callback,
3053 JSPreWrapCallback precallback);
3054 extern __attribute__((visibility ("default"))) JSCrossCompartmentCall *
3055 JS_EnterCrossCompartmentCall(JSContext *cx, JSObject *target);
3056 extern __attribute__((visibility ("default"))) void
3057 JS_LeaveCrossCompartmentCall(JSCrossCompartmentCall *call);
3058 extern __attribute__((visibility ("default"))) void *
3059 JS_SetCompartmentPrivate(JSContext *cx, JSCompartment *compartment, void *data);
3060 extern __attribute__((visibility ("default"))) void *
3061 JS_GetCompartmentPrivate(JSContext *cx, JSCompartment *compartment);
3062 extern __attribute__((visibility ("default"))) JSBool
3063 JS_WrapObject(JSContext *cx, JSObject **objp);
3064 extern __attribute__((visibility ("default"))) JSBool
3065 JS_WrapValue(JSContext *cx, jsval *vp);
3066 extern __attribute__((visibility ("default"))) JSObject *
3067 JS_TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target);
3068 extern __attribute__((visibility ("default"))) JSObject *
3069 js_TransplantObjectWithWrapper(JSContext *cx,
3071 JSObject *origwrapper,
3072 JSObject *targetobj,
3073 JSObject *targetwrapper);
3074 extern __attribute__((visibility ("default"))) JSObject *
3075 js_TransplantObjectWithWrapper(JSContext *cx,
3077 JSObject *origwrapper,
3078 JSObject *targetobj,
3079 JSObject *targetwrapper);
3081 class __attribute__((visibility ("default"))) JSAutoEnterCompartment
3083 JSCrossCompartmentCall *call;
3085 JSAutoEnterCompartment() : call(__null) {}
3086 bool enter(JSContext *cx, JSObject *target);
3087 void enterAndIgnoreErrors(JSContext *cx, JSObject *target);
3088 bool entered() const { return call != __null; }
3089 ~JSAutoEnterCompartment() {
3090 if (call && call != reinterpret_cast<JSCrossCompartmentCall*>(1))
3091 JS_LeaveCrossCompartmentCall(call);
3093 void swap(JSAutoEnterCompartment &other) {
3094 JSCrossCompartmentCall *tmp = call;
3100 extern __attribute__((visibility ("default"))) JSObject *
3101 JS_GetGlobalObject(JSContext *cx);
3102 extern __attribute__((visibility ("default"))) void
3103 JS_SetGlobalObject(JSContext *cx, JSObject *obj);
3104 extern __attribute__((visibility ("default"))) JSBool
3105 JS_InitStandardClasses(JSContext *cx, JSObject *obj);
3106 extern __attribute__((visibility ("default"))) JSBool
3107 JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsid id,
3109 extern __attribute__((visibility ("default"))) JSBool
3110 JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj);
3111 extern __attribute__((visibility ("default"))) JSIdArray *
3112 JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj,
3114 extern __attribute__((visibility ("default"))) JSBool
3115 JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
3117 extern __attribute__((visibility ("default"))) JSObject *
3118 JS_GetScopeChain(JSContext *cx);
3119 extern __attribute__((visibility ("default"))) JSObject *
3120 JS_GetGlobalForObject(JSContext *cx, JSObject *obj);
3121 extern __attribute__((visibility ("default"))) JSObject *
3122 JS_GetGlobalForScopeChain(JSContext *cx);
3123 extern __attribute__((visibility ("default"))) jsval
3124 JS_ComputeThis(JSContext *cx, jsval *vp);
3126 JS_THIS(JSContext *cx, jsval *vp)
3128 return JSVAL_IS_PRIMITIVE(vp[1]) ? JS_ComputeThis(cx, vp) : vp[1];
3130 extern __attribute__((visibility ("default"))) void *
3131 JS_malloc(JSContext *cx, size_t nbytes);
3132 extern __attribute__((visibility ("default"))) void *
3133 JS_realloc(JSContext *cx, void *p, size_t nbytes);
3134 extern __attribute__((visibility ("default"))) void
3135 JS_free(JSContext *cx, void *p);
3136 extern __attribute__((visibility ("default"))) void
3137 JS_updateMallocCounter(JSContext *cx, size_t nbytes);
3138 extern __attribute__((visibility ("default"))) char *
3139 JS_strdup(JSContext *cx, const char *s);
3140 extern __attribute__((visibility ("default"))) JSBool
3141 JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
3142 extern __attribute__((visibility ("default"))) JSBool
3143 JS_AddValueRoot(JSContext *cx, jsval *vp);
3144 extern __attribute__((visibility ("default"))) JSBool
3145 JS_AddStringRoot(JSContext *cx, JSString **rp);
3146 extern __attribute__((visibility ("default"))) JSBool
3147 JS_AddObjectRoot(JSContext *cx, JSObject **rp);
3148 extern __attribute__((visibility ("default"))) JSBool
3149 JS_AddGCThingRoot(JSContext *cx, void **rp);
3150 extern __attribute__((visibility ("default"))) JSBool
3151 JS_AddNamedValueRoot(JSContext *cx, jsval *vp, const char *name);
3152 extern __attribute__((visibility ("default"))) JSBool
3153 JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name);
3154 extern __attribute__((visibility ("default"))) JSBool
3155 JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name);
3156 extern __attribute__((visibility ("default"))) JSBool
3157 JS_AddNamedGCThingRoot(JSContext *cx, void **rp, const char *name);
3158 extern __attribute__((visibility ("default"))) JSBool
3159 JS_RemoveValueRoot(JSContext *cx, jsval *vp);
3160 extern __attribute__((visibility ("default"))) JSBool
3161 JS_RemoveStringRoot(JSContext *cx, JSString **rp);
3162 extern __attribute__((visibility ("default"))) JSBool
3163 JS_RemoveObjectRoot(JSContext *cx, JSObject **rp);
3164 extern __attribute__((visibility ("default"))) JSBool
3165 JS_RemoveGCThingRoot(JSContext *cx, void **rp);
3166 extern __attribute__((visibility ("default"))) JSBool
3167 js_AddRootRT(JSRuntime *rt, jsval *vp, const char *name);
3168 extern __attribute__((visibility ("default"))) JSBool
3169 js_AddGCThingRootRT(JSRuntime *rt, void **rp, const char *name);
3170 extern __attribute__((visibility ("default"))) JSBool
3171 js_RemoveRoot(JSRuntime *rt, void *rp);
3174 template<typename T> class AnchorPermitted;
3175 template<> class AnchorPermitted<JSObject *> { };
3176 template<> class AnchorPermitted<const JSObject *> { };
3177 template<> class AnchorPermitted<JSFunction *> { };
3178 template<> class AnchorPermitted<const JSFunction *> { };
3179 template<> class AnchorPermitted<JSString *> { };
3180 template<> class AnchorPermitted<const JSString *> { };
3181 template<> class AnchorPermitted<jsval> { };
3182 template<typename T>
3183 class Anchor: AnchorPermitted<T> {
3186 explicit Anchor(T t) { hold = t; }
3188 T &get() { return hold; }
3189 void set(const T &t) { hold = t; }
3190 void clear() { hold = 0; }
3193 Anchor(const Anchor &);
3194 const Anchor &operator=(const Anchor &);
3196 template<typename T>
3197 inline Anchor<T>::~Anchor() {
3198 asm volatile("":: "g" (hold) : "memory");
3202 extern __attribute__((noinline)) __attribute__((visibility ("default"))) void
3203 JS_AnchorPtr(void *p);
3204 typedef enum JSGCRootType {
3205 JS_GC_ROOT_VALUE_PTR,
3206 JS_GC_ROOT_GCTHING_PTR
3209 (* JSGCRootMapFun)(void *rp, JSGCRootType type, const char *name, void *data);
3210 extern __attribute__((visibility ("default"))) uint32
3211 JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data);
3212 extern __attribute__((visibility ("default"))) JSBool
3213 JS_LockGCThing(JSContext *cx, void *thing);
3214 extern __attribute__((visibility ("default"))) JSBool
3215 JS_LockGCThingRT(JSRuntime *rt, void *thing);
3216 extern __attribute__((visibility ("default"))) JSBool
3217 JS_UnlockGCThing(JSContext *cx, void *thing);
3218 extern __attribute__((visibility ("default"))) JSBool
3219 JS_UnlockGCThingRT(JSRuntime *rt, void *thing);
3220 extern __attribute__((visibility ("default"))) void
3221 JS_SetExtraGCRoots(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
3222 extern __attribute__((visibility ("default"))) void
3223 JS_MarkGCThing(JSContext *cx, jsval v, const char *name, void *arg);
3224 static __attribute__((always_inline)) inline JSBool
3225 JSVAL_IS_TRACEABLE(jsval v)
3229 return JSVAL_IS_TRACEABLE_IMPL(l);
3231 static __attribute__((always_inline)) inline void *
3232 JSVAL_TO_TRACEABLE(jsval v)
3234 return JSVAL_TO_GCTHING(v);
3236 static __attribute__((always_inline)) inline uint32
3237 JSVAL_TRACE_KIND(jsval v)
3242 return JSVAL_TRACE_KIND_IMPL(l);
3246 JSTraceCallback callback;
3247 JSTraceNamePrinter debugPrinter;
3248 const void *debugPrintArg;
3249 size_t debugPrintIndex;
3251 extern __attribute__((visibility ("default"))) void
3252 JS_CallTracer(JSTracer *trc, void *thing, uint32 kind);
3253 extern __attribute__((visibility ("default"))) void
3254 JS_TraceChildren(JSTracer *trc, void *thing, uint32 kind);
3255 extern __attribute__((visibility ("default"))) void
3256 JS_TraceRuntime(JSTracer *trc);
3257 extern __attribute__((visibility ("default"))) void
3258 JS_GC(JSContext *cx);
3259 extern __attribute__((visibility ("default"))) void
3260 JS_MaybeGC(JSContext *cx);
3261 extern __attribute__((visibility ("default"))) JSGCCallback
3262 JS_SetGCCallback(JSContext *cx, JSGCCallback cb);
3263 extern __attribute__((visibility ("default"))) JSGCCallback
3264 JS_SetGCCallbackRT(JSRuntime *rt, JSGCCallback cb);
3265 extern __attribute__((visibility ("default"))) JSBool
3266 JS_IsGCMarkingTracer(JSTracer *trc);
3267 extern __attribute__((visibility ("default"))) JSBool
3268 JS_IsAboutToBeFinalized(JSContext *cx, void *thing);
3269 typedef enum JSGCParamKey {
3271 JSGC_MAX_MALLOC_BYTES = 1,
3272 JSGC_STACKPOOL_LIFESPAN = 2,
3273 JSGC_TRIGGER_FACTOR = 3,
3276 JSGC_MAX_CODE_CACHE_BYTES = 6,
3278 JSGC_UNUSED_CHUNKS = 8
3280 typedef enum JSGCMode {
3281 JSGC_MODE_GLOBAL = 0,
3282 JSGC_MODE_COMPARTMENT = 1
3284 extern __attribute__((visibility ("default"))) void
3285 JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32 value);
3286 extern __attribute__((visibility ("default"))) uint32
3287 JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key);
3288 extern __attribute__((visibility ("default"))) void
3289 JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32 value);
3290 extern __attribute__((visibility ("default"))) uint32
3291 JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key);
3292 extern __attribute__((visibility ("default"))) void
3293 JS_FlushCaches(JSContext *cx);
3294 extern __attribute__((visibility ("default"))) intN
3295 JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer);
3296 extern __attribute__((visibility ("default"))) intN
3297 JS_RemoveExternalStringFinalizer(JSStringFinalizeOp finalizer);
3298 extern __attribute__((visibility ("default"))) JSString *
3299 JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type);
3300 extern __attribute__((visibility ("default"))) intN
3301 JS_GetExternalStringGCType(JSRuntime *rt, JSString *str);
3302 extern __attribute__((visibility ("default"))) void
3303 JS_SetThreadStackLimit(JSContext *cx, jsuword limitAddr);
3304 extern __attribute__((visibility ("default"))) void
3305 JS_SetNativeStackQuota(JSContext *cx, size_t stackSize);
3306 extern __attribute__((visibility ("default"))) void
3307 JS_SetScriptStackQuota(JSContext *cx, size_t quota);
3308 typedef void (*JSClassInternal)();
3312 JSPropertyOp addProperty;
3313 JSPropertyOp delProperty;
3314 JSPropertyOp getProperty;
3315 JSStrictPropertyOp setProperty;
3316 JSEnumerateOp enumerate;
3317 JSResolveOp resolve;
3318 JSConvertOp convert;
3319 JSFinalizeOp finalize;
3320 JSClassInternal reserved0;
3321 JSCheckAccessOp checkAccess;
3324 JSXDRObjectOp xdrObject;
3325 JSHasInstanceOp hasInstance;
3327 JSClassInternal reserved1;
3334 extern __attribute__((visibility ("default"))) void
3335 JS_DestroyIdArray(JSContext *cx, JSIdArray *ida);
3336 extern __attribute__((visibility ("default"))) JSBool
3337 JS_ValueToId(JSContext *cx, jsval v, jsid *idp);
3338 extern __attribute__((visibility ("default"))) JSBool
3339 JS_IdToValue(JSContext *cx, jsid id, jsval *vp);
3340 extern __attribute__((visibility ("default"))) JSBool
3341 JS_PropertyStub(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
3342 extern __attribute__((visibility ("default"))) JSBool
3343 JS_StrictPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
3344 extern __attribute__((visibility ("default"))) JSBool
3345 JS_EnumerateStub(JSContext *cx, JSObject *obj);
3346 extern __attribute__((visibility ("default"))) JSBool
3347 JS_ResolveStub(JSContext *cx, JSObject *obj, jsid id);
3348 extern __attribute__((visibility ("default"))) JSBool
3349 JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
3350 extern __attribute__((visibility ("default"))) void
3351 JS_FinalizeStub(JSContext *cx, JSObject *obj);
3352 struct JSConstDoubleSpec {
3358 struct JSPropertySpec {
3362 JSPropertyOp getter;
3363 JSStrictPropertyOp setter;
3365 struct JSFunctionSpec {
3371 extern __attribute__((visibility ("default"))) JSObject *
3372 JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
3373 JSClass *clasp, JSNative constructor, uintN nargs,
3374 JSPropertySpec *ps, JSFunctionSpec *fs,
3375 JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
3376 extern __attribute__((visibility ("default"))) JSClass *
3377 JS_GetClass(JSContext *cx, JSObject *obj);
3378 extern __attribute__((visibility ("default"))) JSBool
3379 JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
3380 extern __attribute__((visibility ("default"))) JSBool
3381 JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
3382 extern __attribute__((visibility ("default"))) void *
3383 JS_GetPrivate(JSContext *cx, JSObject *obj);
3384 extern __attribute__((visibility ("default"))) JSBool
3385 JS_SetPrivate(JSContext *cx, JSObject *obj, void *data);
3386 extern __attribute__((visibility ("default"))) void *
3387 JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
3389 extern __attribute__((visibility ("default"))) JSObject *
3390 JS_GetPrototype(JSContext *cx, JSObject *obj);
3391 extern __attribute__((visibility ("default"))) JSBool
3392 JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
3393 extern __attribute__((visibility ("default"))) JSObject *
3394 JS_GetParent(JSContext *cx, JSObject *obj);
3395 extern __attribute__((visibility ("default"))) JSBool
3396 JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent);
3397 extern __attribute__((visibility ("default"))) JSObject *
3398 JS_GetConstructor(JSContext *cx, JSObject *proto);
3399 extern __attribute__((visibility ("default"))) JSBool
3400 JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp);
3401 extern __attribute__((visibility ("default"))) JSObject *
3402 JS_NewGlobalObject(JSContext *cx, JSClass *clasp);
3403 extern __attribute__((visibility ("default"))) JSObject *
3404 JS_NewCompartmentAndGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals);
3405 extern __attribute__((visibility ("default"))) JSObject *
3406 JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
3407 extern __attribute__((visibility ("default"))) JSBool
3408 JS_IsExtensible(JSObject *obj);
3409 extern __attribute__((visibility ("default"))) JSObject *
3410 JS_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
3412 extern __attribute__((visibility ("default"))) JSBool
3413 JS_DeepFreezeObject(JSContext *cx, JSObject *obj);
3414 extern __attribute__((visibility ("default"))) JSBool
3415 JS_FreezeObject(JSContext *cx, JSObject *obj);
3416 extern __attribute__((visibility ("default"))) JSObject *
3417 JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
3419 extern __attribute__((visibility ("default"))) JSObject *
3420 JS_ConstructObjectWithArguments(JSContext *cx, JSClass *clasp, JSObject *proto,
3421 JSObject *parent, uintN argc, jsval *argv);
3422 extern __attribute__((visibility ("default"))) JSObject *
3423 JS_New(JSContext *cx, JSObject *ctor, uintN argc, jsval *argv);
3424 extern __attribute__((visibility ("default"))) JSObject *
3425 JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
3426 JSObject *proto, uintN attrs);
3427 extern __attribute__((visibility ("default"))) JSBool
3428 JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds);
3429 extern __attribute__((visibility ("default"))) JSBool
3430 JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
3431 extern __attribute__((visibility ("default"))) JSBool
3432 JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
3433 JSPropertyOp getter, JSStrictPropertyOp setter, uintN attrs);
3434 extern __attribute__((visibility ("default"))) JSBool
3435 JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value,
3436 JSPropertyOp getter, JSStrictPropertyOp setter, uintN attrs);
3437 extern __attribute__((visibility ("default"))) JSBool
3438 JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, JSBool *bp);
3439 extern __attribute__((visibility ("default"))) JSBool
3440 JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
3441 uintN *attrsp, JSBool *foundp);
3442 extern __attribute__((visibility ("default"))) JSBool
3443 JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
3445 uintN *attrsp, JSBool *foundp,
3446 JSPropertyOp *getterp,
3447 JSStrictPropertyOp *setterp);
3448 extern __attribute__((visibility ("default"))) JSBool
3449 JS_GetPropertyAttrsGetterAndSetterById(JSContext *cx, JSObject *obj,
3451 uintN *attrsp, JSBool *foundp,
3452 JSPropertyOp *getterp,
3453 JSStrictPropertyOp *setterp);
3454 extern __attribute__((visibility ("default"))) JSBool
3455 JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
3456 uintN attrs, JSBool *foundp);
3457 extern __attribute__((visibility ("default"))) JSBool
3458 JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
3459 int8 tinyid, jsval value,
3460 JSPropertyOp getter, JSStrictPropertyOp setter,
3462 extern __attribute__((visibility ("default"))) JSBool
3463 JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name,
3465 extern __attribute__((visibility ("default"))) JSBool
3466 JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name,
3468 extern __attribute__((visibility ("default"))) JSBool
3469 JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id,
3471 extern __attribute__((visibility ("default"))) JSBool
3472 JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp);
3473 extern __attribute__((visibility ("default"))) JSBool
3474 JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, JSBool *foundp);
3475 extern __attribute__((visibility ("default"))) JSBool
3476 JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
3477 extern __attribute__((visibility ("default"))) JSBool
3478 JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
3479 extern __attribute__((visibility ("default"))) JSBool
3480 JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name,
3481 uintN flags, jsval *vp);
3482 extern __attribute__((visibility ("default"))) JSBool
3483 JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id,
3484 uintN flags, JSObject **objp, jsval *vp);
3485 struct JSPropertyDescriptor {
3488 JSPropertyOp getter;
3489 JSStrictPropertyOp setter;
3493 extern __attribute__((visibility ("default"))) JSBool
3494 JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, uintN flags,
3495 JSPropertyDescriptor *desc);
3496 extern __attribute__((visibility ("default"))) JSBool
3497 JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
3498 extern __attribute__((visibility ("default"))) JSBool
3499 JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
3500 extern __attribute__((visibility ("default"))) JSBool
3501 JS_GetPropertyDefault(JSContext *cx, JSObject *obj, const char *name, jsval def, jsval *vp);
3502 extern __attribute__((visibility ("default"))) JSBool
3503 JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
3504 extern __attribute__((visibility ("default"))) JSBool
3505 JS_GetPropertyByIdDefault(JSContext *cx, JSObject *obj, jsid id, jsval def, jsval *vp);
3506 extern __attribute__((visibility ("default"))) JSBool
3507 JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
3509 extern __attribute__((visibility ("default"))) JSBool
3510 JS_GetMethod(JSContext *cx, JSObject *obj, const char *name, JSObject **objp,
3512 extern __attribute__((visibility ("default"))) JSBool
3513 JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
3514 extern __attribute__((visibility ("default"))) JSBool
3515 JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
3516 extern __attribute__((visibility ("default"))) JSBool
3517 JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
3518 extern __attribute__((visibility ("default"))) JSBool
3519 JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name,
3521 extern __attribute__((visibility ("default"))) JSBool
3522 JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id);
3523 extern __attribute__((visibility ("default"))) JSBool
3524 JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, jsval *rval);
3525 extern __attribute__((visibility ("default"))) JSBool
3526 JS_DefineUCProperty(JSContext *cx, JSObject *obj,
3527 const jschar *name, size_t namelen, jsval value,
3528 JSPropertyOp getter, JSStrictPropertyOp setter,
3530 extern __attribute__((visibility ("default"))) JSBool
3531 JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
3532 const jschar *name, size_t namelen,
3533 uintN *attrsp, JSBool *foundp);
3534 extern __attribute__((visibility ("default"))) JSBool
3535 JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
3536 const jschar *name, size_t namelen,
3537 uintN *attrsp, JSBool *foundp,
3538 JSPropertyOp *getterp,
3539 JSStrictPropertyOp *setterp);
3540 extern __attribute__((visibility ("default"))) JSBool
3541 JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
3542 const jschar *name, size_t namelen,
3543 uintN attrs, JSBool *foundp);
3544 extern __attribute__((visibility ("default"))) JSBool
3545 JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
3546 const jschar *name, size_t namelen,
3547 int8 tinyid, jsval value,
3548 JSPropertyOp getter, JSStrictPropertyOp setter,
3550 extern __attribute__((visibility ("default"))) JSBool
3551 JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name,
3552 size_t namelen, JSBool *foundp);
3553 extern __attribute__((visibility ("default"))) JSBool
3554 JS_HasUCProperty(JSContext *cx, JSObject *obj,
3555 const jschar *name, size_t namelen,
3557 extern __attribute__((visibility ("default"))) JSBool
3558 JS_LookupUCProperty(JSContext *cx, JSObject *obj,
3559 const jschar *name, size_t namelen,
3561 extern __attribute__((visibility ("default"))) JSBool
3562 JS_GetUCProperty(JSContext *cx, JSObject *obj,
3563 const jschar *name, size_t namelen,
3565 extern __attribute__((visibility ("default"))) JSBool
3566 JS_SetUCProperty(JSContext *cx, JSObject *obj,
3567 const jschar *name, size_t namelen,
3569 extern __attribute__((visibility ("default"))) JSBool
3570 JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
3571 const jschar *name, size_t namelen,
3573 extern __attribute__((visibility ("default"))) JSObject *
3574 JS_NewArrayObject(JSContext *cx, jsint length, jsval *vector);
3575 extern __attribute__((visibility ("default"))) JSBool
3576 JS_IsArrayObject(JSContext *cx, JSObject *obj);
3577 extern __attribute__((visibility ("default"))) JSBool
3578 JS_GetArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
3579 extern __attribute__((visibility ("default"))) JSBool
3580 JS_SetArrayLength(JSContext *cx, JSObject *obj, jsuint length);
3581 extern __attribute__((visibility ("default"))) JSBool
3582 JS_HasArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp);
3583 extern __attribute__((visibility ("default"))) JSBool
3584 JS_DefineElement(JSContext *cx, JSObject *obj, jsint index, jsval value,
3585 JSPropertyOp getter, JSStrictPropertyOp setter, uintN attrs);
3586 extern __attribute__((visibility ("default"))) JSBool
3587 JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias);
3588 extern __attribute__((visibility ("default"))) JSBool
3589 JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, jsint index,
3591 extern __attribute__((visibility ("default"))) JSBool
3592 JS_HasElement(JSContext *cx, JSObject *obj, jsint index, JSBool *foundp);
3593 extern __attribute__((visibility ("default"))) JSBool
3594 JS_LookupElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
3595 extern __attribute__((visibility ("default"))) JSBool
3596 JS_GetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
3597 extern __attribute__((visibility ("default"))) JSBool
3598 JS_SetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
3599 extern __attribute__((visibility ("default"))) JSBool
3600 JS_DeleteElement(JSContext *cx, JSObject *obj, jsint index);
3601 extern __attribute__((visibility ("default"))) JSBool
3602 JS_DeleteElement2(JSContext *cx, JSObject *obj, jsint index, jsval *rval);
3603 extern __attribute__((visibility ("default"))) void
3604 JS_ClearScope(JSContext *cx, JSObject *obj);
3605 extern __attribute__((visibility ("default"))) JSIdArray *
3606 JS_Enumerate(JSContext *cx, JSObject *obj);
3607 extern __attribute__((visibility ("default"))) JSObject *
3608 JS_NewPropertyIterator(JSContext *cx, JSObject *obj);
3609 extern __attribute__((visibility ("default"))) JSBool
3610 JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp);
3611 extern __attribute__((visibility ("default"))) JSBool
3612 JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
3613 jsval *vp, uintN *attrsp);
3614 extern __attribute__((visibility ("default"))) JSBool
3615 JS_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval *vp);
3616 extern __attribute__((visibility ("default"))) JSBool
3617 JS_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval v);
3618 struct JSPrincipals {
3620 void * (* getPrincipalArray)(JSContext *cx, JSPrincipals *);
3621 JSBool (* globalPrivilegesEnabled)(JSContext *cx, JSPrincipals *);
3622 jsrefcount refcount;
3623 void (* destroy)(JSContext *cx, JSPrincipals *);
3624 JSBool (* subsume)(JSPrincipals *, JSPrincipals *);
3626 extern __attribute__((visibility ("default"))) jsrefcount
3627 JS_HoldPrincipals(JSContext *cx, JSPrincipals *principals);
3628 extern __attribute__((visibility ("default"))) jsrefcount
3629 JS_DropPrincipals(JSContext *cx, JSPrincipals *principals);
3630 struct JSSecurityCallbacks {
3631 JSCheckAccessOp checkObjectAccess;
3632 JSPrincipalsTranscoder principalsTranscoder;
3633 JSObjectPrincipalsFinder findObjectPrincipals;
3634 JSCSPEvalChecker contentSecurityPolicyAllows;
3636 extern __attribute__((visibility ("default"))) JSSecurityCallbacks *
3637 JS_SetRuntimeSecurityCallbacks(JSRuntime *rt, JSSecurityCallbacks *callbacks);
3638 extern __attribute__((visibility ("default"))) JSSecurityCallbacks *
3639 JS_GetRuntimeSecurityCallbacks(JSRuntime *rt);
3640 extern __attribute__((visibility ("default"))) JSSecurityCallbacks *
3641 JS_SetContextSecurityCallbacks(JSContext *cx, JSSecurityCallbacks *callbacks);
3642 extern __attribute__((visibility ("default"))) JSSecurityCallbacks *
3643 JS_GetSecurityCallbacks(JSContext *cx);
3644 extern __attribute__((visibility ("default"))) JSFunction *
3645 JS_NewFunction(JSContext *cx, JSNative call, uintN nargs, uintN flags,
3646 JSObject *parent, const char *name);
3647 extern __attribute__((visibility ("default"))) JSFunction *
3648 JS_NewFunctionById(JSContext *cx, JSNative call, uintN nargs, uintN flags,
3649 JSObject *parent, jsid id);
3650 extern __attribute__((visibility ("default"))) JSObject *
3651 JS_GetFunctionObject(JSFunction *fun);
3652 extern __attribute__((visibility ("default"))) JSString *
3653 JS_GetFunctionId(JSFunction *fun);
3654 extern __attribute__((visibility ("default"))) uintN
3655 JS_GetFunctionFlags(JSFunction *fun);
3656 extern __attribute__((visibility ("default"))) uint16
3657 JS_GetFunctionArity(JSFunction *fun);
3658 extern __attribute__((visibility ("default"))) JSBool
3659 JS_ObjectIsFunction(JSContext *cx, JSObject *obj);
3660 extern __attribute__((visibility ("default"))) JSBool
3661 JS_ObjectIsCallable(JSContext *cx, JSObject *obj);
3662 extern __attribute__((visibility ("default"))) JSBool
3663 JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs);
3664 extern __attribute__((visibility ("default"))) JSFunction *
3665 JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call,
3666 uintN nargs, uintN attrs);
3667 extern __attribute__((visibility ("default"))) JSFunction *
3668 JS_DefineUCFunction(JSContext *cx, JSObject *obj,
3669 const jschar *name, size_t namelen, JSNative call,
3670 uintN nargs, uintN attrs);
3671 extern __attribute__((visibility ("default"))) JSFunction *
3672 JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call,
3673 uintN nargs, uintN attrs);
3674 extern __attribute__((visibility ("default"))) JSObject *
3675 JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent);
3676 extern __attribute__((visibility ("default"))) JSBool
3677 JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj,
3678 const char *bytes, size_t length);
3679 extern __attribute__((visibility ("default"))) JSObject *
3680 JS_CompileScript(JSContext *cx, JSObject *obj,
3681 const char *bytes, size_t length,
3682 const char *filename, uintN lineno);
3683 extern __attribute__((visibility ("default"))) JSObject *
3684 JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
3685 JSPrincipals *principals,
3686 const char *bytes, size_t length,
3687 const char *filename, uintN lineno);
3688 extern __attribute__((visibility ("default"))) JSObject *
3689 JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
3690 JSPrincipals *principals,
3691 const char *bytes, size_t length,
3692 const char *filename, uintN lineno,
3694 extern __attribute__((visibility ("default"))) JSObject *
3695 JS_CompileUCScript(JSContext *cx, JSObject *obj,
3696 const jschar *chars, size_t length,
3697 const char *filename, uintN lineno);
3698 extern __attribute__((visibility ("default"))) JSObject *
3699 JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
3700 JSPrincipals *principals,
3701 const jschar *chars, size_t length,
3702 const char *filename, uintN lineno);
3703 extern __attribute__((visibility ("default"))) JSObject *
3704 JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
3705 JSPrincipals *principals,
3706 const jschar *chars, size_t length,
3707 const char *filename, uintN lineno,
3709 extern __attribute__((visibility ("default"))) JSObject *
3710 JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename);
3711 extern __attribute__((visibility ("default"))) JSObject *
3712 JS_CompileFileHandle(JSContext *cx, JSObject *obj, const char *filename,
3714 extern __attribute__((visibility ("default"))) JSObject *
3715 JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj,
3716 const char *filename, FILE *fh,
3717 JSPrincipals *principals);
3718 extern __attribute__((visibility ("default"))) JSObject *
3719 JS_CompileFileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj,
3720 const char *filename, FILE *fh,
3721 JSPrincipals *principals,
3723 extern __attribute__((visibility ("default"))) JSFunction *
3724 JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
3725 uintN nargs, const char **argnames,
3726 const char *bytes, size_t length,
3727 const char *filename, uintN lineno);
3728 extern __attribute__((visibility ("default"))) JSFunction *
3729 JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
3730 JSPrincipals *principals, const char *name,
3731 uintN nargs, const char **argnames,
3732 const char *bytes, size_t length,
3733 const char *filename, uintN lineno);
3734 extern __attribute__((visibility ("default"))) JSFunction *
3735 JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
3736 uintN nargs, const char **argnames,
3737 const jschar *chars, size_t length,
3738 const char *filename, uintN lineno);
3739 extern __attribute__((visibility ("default"))) JSFunction *
3740 JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
3741 JSPrincipals *principals, const char *name,
3742 uintN nargs, const char **argnames,
3743 const jschar *chars, size_t length,
3744 const char *filename, uintN lineno);
3745 extern __attribute__((visibility ("default"))) JSFunction *
3746 JS_CompileUCFunctionForPrincipalsVersion(JSContext *cx, JSObject *obj,
3747 JSPrincipals *principals, const char *name,
3748 uintN nargs, const char **argnames,
3749 const jschar *chars, size_t length,
3750 const char *filename, uintN lineno,
3752 extern __attribute__((visibility ("default"))) JSString *
3753 JS_DecompileScriptObject(JSContext *cx, JSObject *scriptObj, const char *name, uintN indent);
3754 extern __attribute__((visibility ("default"))) JSString *
3755 JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent);
3756 extern __attribute__((visibility ("default"))) JSString *
3757 JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent);
3758 extern __attribute__((visibility ("default"))) JSBool
3759 JS_ExecuteScript(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval);
3760 extern __attribute__((visibility ("default"))) JSBool
3761 JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval,
3763 typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart;
3764 extern __attribute__((visibility ("default"))) JSBool
3765 JS_EvaluateScript(JSContext *cx, JSObject *obj,
3766 const char *bytes, uintN length,
3767 const char *filename, uintN lineno,
3769 extern __attribute__((visibility ("default"))) JSBool
3770 JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
3771 JSPrincipals *principals,
3772 const char *bytes, uintN length,
3773 const char *filename, uintN lineno,
3775 extern __attribute__((visibility ("default"))) JSBool
3776 JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
3777 JSPrincipals *principals,
3778 const char *bytes, uintN length,
3779 const char *filename, uintN lineno,
3780 jsval *rval, JSVersion version);
3781 extern __attribute__((visibility ("default"))) JSBool
3782 JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
3783 const jschar *chars, uintN length,
3784 const char *filename, uintN lineno,
3786 extern __attribute__((visibility ("default"))) JSBool
3787 JS_EvaluateUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
3788 JSPrincipals *principals,
3789 const jschar *chars, uintN length,
3790 const char *filename, uintN lineno,
3791 jsval *rval, JSVersion version);
3792 extern __attribute__((visibility ("default"))) JSBool
3793 JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
3794 JSPrincipals *principals,
3795 const jschar *chars, uintN length,
3796 const char *filename, uintN lineno,
3798 extern __attribute__((visibility ("default"))) JSBool
3799 JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, uintN argc,
3800 jsval *argv, jsval *rval);
3801 extern __attribute__((visibility ("default"))) JSBool
3802 JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc,
3803 jsval *argv, jsval *rval);
3804 extern __attribute__((visibility ("default"))) JSBool
3805 JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc,
3806 jsval *argv, jsval *rval);
3811 Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, uintN argc, jsval *argv, jsval *rval) {
3812 return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval);
3816 Call(JSContext *cx, JSObject *thisObj, const char *name, uintN argc, jsval *argv, jsval *rval) {
3817 return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval);
3821 Call(JSContext *cx, JSObject *thisObj, jsval fun, uintN argc, jsval *argv, jsval *rval) {
3822 return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval);
3824 extern __attribute__((visibility ("default"))) bool
3825 Call(JSContext *cx, jsval thisv, jsval fun, uintN argc, jsval *argv, jsval *rval);
3828 Call(JSContext *cx, jsval thisv, JSObject *funObj, uintN argc, jsval *argv, jsval *rval) {
3829 return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval);
3833 extern __attribute__((visibility ("default"))) JSOperationCallback
3834 JS_SetOperationCallback(JSContext *cx, JSOperationCallback callback);
3835 extern __attribute__((visibility ("default"))) JSOperationCallback
3836 JS_GetOperationCallback(JSContext *cx);
3837 extern __attribute__((visibility ("default"))) void
3838 JS_TriggerOperationCallback(JSContext *cx);
3839 extern __attribute__((visibility ("default"))) void
3840 JS_TriggerAllOperationCallbacks(JSRuntime *rt);
3841 extern __attribute__((visibility ("default"))) JSBool
3842 JS_IsRunning(JSContext *cx);
3843 extern __attribute__((visibility ("default"))) JSStackFrame *
3844 JS_SaveFrameChain(JSContext *cx);
3845 extern __attribute__((visibility ("default"))) void
3846 JS_RestoreFrameChain(JSContext *cx, JSStackFrame *fp);
3847 extern __attribute__((visibility ("default"))) JSString *
3848 JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);
3849 extern __attribute__((visibility ("default"))) JSString *
3850 JS_NewStringCopyZ(JSContext *cx, const char *s);
3851 extern __attribute__((visibility ("default"))) JSString *
3852 JS_InternJSString(JSContext *cx, JSString *str);
3853 extern __attribute__((visibility ("default"))) JSString *
3854 JS_InternString(JSContext *cx, const char *s);
3855 extern __attribute__((visibility ("default"))) JSString *
3856 JS_NewUCString(JSContext *cx, jschar *chars, size_t length);
3857 extern __attribute__((visibility ("default"))) JSString *
3858 JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n);
3859 extern __attribute__((visibility ("default"))) JSString *
3860 JS_NewUCStringCopyZ(JSContext *cx, const jschar *s);
3861 extern __attribute__((visibility ("default"))) JSString *
3862 JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length);
3863 extern __attribute__((visibility ("default"))) JSString *
3864 JS_InternUCString(JSContext *cx, const jschar *s);
3865 extern __attribute__((visibility ("default"))) JSBool
3866 JS_CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32 *result);
3867 extern __attribute__((visibility ("default"))) JSBool
3868 JS_StringEqualsAscii(JSContext *cx, JSString *str, const char *asciiBytes, JSBool *match);
3869 extern __attribute__((visibility ("default"))) size_t
3870 JS_PutEscapedString(JSContext *cx, char *buffer, size_t size, JSString *str, char quote);
3871 extern __attribute__((visibility ("default"))) JSBool
3872 JS_FileEscapedString(FILE *fp, JSString *str, char quote);
3873 extern __attribute__((visibility ("default"))) size_t
3874 JS_GetStringLength(JSString *str);
3875 extern __attribute__((visibility ("default"))) const jschar *
3876 JS_GetStringCharsAndLength(JSContext *cx, JSString *str, size_t *length);
3877 extern __attribute__((visibility ("default"))) const jschar *
3878 JS_GetInternedStringChars(JSString *str);
3879 extern __attribute__((visibility ("default"))) const jschar *
3880 JS_GetInternedStringCharsAndLength(JSString *str, size_t *length);
3881 extern __attribute__((visibility ("default"))) const jschar *
3882 JS_GetStringCharsZ(JSContext *cx, JSString *str);
3883 extern __attribute__((visibility ("default"))) const jschar *
3884 JS_GetStringCharsZAndLength(JSContext *cx, JSString *str, size_t *length);
3885 extern __attribute__((visibility ("default"))) JSFlatString *
3886 JS_FlattenString(JSContext *cx, JSString *str);
3887 extern __attribute__((visibility ("default"))) const jschar *
3888 JS_GetFlatStringChars(JSFlatString *str);
3889 static __attribute__((always_inline)) inline JSFlatString *
3890 JSID_TO_FLAT_STRING(jsid id)
3893 return (JSFlatString *)((id));
3895 static __attribute__((always_inline)) inline JSFlatString *
3896 JS_ASSERT_STRING_IS_FLAT(JSString *str)
3899 return (JSFlatString *)str;
3901 static __attribute__((always_inline)) inline JSString *
3902 JS_FORGET_STRING_FLATNESS(JSFlatString *fstr)
3904 return (JSString *)fstr;
3906 extern __attribute__((visibility ("default"))) JSBool
3907 JS_FlatStringEqualsAscii(JSFlatString *str, const char *asciiBytes);
3908 extern __attribute__((visibility ("default"))) size_t
3909 JS_PutEscapedFlatString(char *buffer, size_t size, JSFlatString *str, char quote);
3910 extern __attribute__((visibility ("default"))) JSString *
3911 JS_NewGrowableString(JSContext *cx, jschar *chars, size_t length);
3912 extern __attribute__((visibility ("default"))) JSString *
3913 JS_NewDependentString(JSContext *cx, JSString *str, size_t start,
3915 extern __attribute__((visibility ("default"))) JSString *
3916 JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
3917 extern __attribute__((visibility ("default"))) const jschar *
3918 JS_UndependString(JSContext *cx, JSString *str);
3919 extern __attribute__((visibility ("default"))) JSBool
3920 JS_MakeStringImmutable(JSContext *cx, JSString *str);
3921 __attribute__((visibility ("default"))) JSBool
3922 JS_CStringsAreUTF8(void);
3923 __attribute__((visibility ("default"))) void
3924 JS_SetCStringsAreUTF8(void);
3925 __attribute__((visibility ("default"))) JSBool
3926 JS_EncodeCharacters(JSContext *cx, const jschar *src, size_t srclen, char *dst,
3928 __attribute__((visibility ("default"))) JSBool
3929 JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst,
3931 __attribute__((visibility ("default"))) char *
3932 JS_EncodeString(JSContext *cx, JSString *str);
3933 __attribute__((visibility ("default"))) size_t
3934 JS_GetStringEncodingLength(JSContext *cx, JSString *str);
3935 __attribute__((visibility ("default"))) size_t
3936 JS_EncodeStringToBuffer(JSString *str, char *buffer, size_t length);
3937 class JSAutoByteString {
3939 JSAutoByteString(JSContext *cx, JSString *str )
3940 : mBytes(JS_EncodeString(cx, str)) {
3948 ~JSAutoByteString() {
3951 void initBytes(char *bytes) {
3955 char *encode(JSContext *cx, JSString *str) {
3958 mBytes = JS_EncodeString(cx, str);
3968 bool operator!() const {
3974 JSAutoByteString(const JSAutoByteString &another);
3975 JSAutoByteString &operator=(const JSAutoByteString &another);
3977 typedef JSBool (* JSONWriteCallback)(const jschar *buf, uint32 len, void *data);
3978 __attribute__((visibility ("default"))) JSBool
3979 JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space,
3980 JSONWriteCallback callback, void *data);
3981 __attribute__((visibility ("default"))) JSBool
3982 JS_TryJSON(JSContext *cx, jsval *vp);
3983 __attribute__((visibility ("default"))) JSONParser *
3984 JS_BeginJSONParse(JSContext *cx, jsval *vp);
3985 __attribute__((visibility ("default"))) JSBool
3986 JS_ConsumeJSONText(JSContext *cx, JSONParser *jp, const jschar *data, uint32 len);
3987 __attribute__((visibility ("default"))) JSBool
3988 JS_FinishJSONParse(JSContext *cx, JSONParser *jp, jsval reviver);
3989 struct JSStructuredCloneCallbacks {
3990 ReadStructuredCloneOp read;
3991 WriteStructuredCloneOp write;
3992 StructuredCloneErrorOp reportError;
3994 __attribute__((visibility ("default"))) JSBool
3995 JS_ReadStructuredClone(JSContext *cx, const uint64 *data, size_t nbytes,
3996 uint32 version, jsval *vp,
3997 const JSStructuredCloneCallbacks *optionalCallbacks,
3999 __attribute__((visibility ("default"))) JSBool
4000 JS_WriteStructuredClone(JSContext *cx, jsval v, uint64 **datap, size_t *nbytesp,
4001 const JSStructuredCloneCallbacks *optionalCallbacks,
4003 __attribute__((visibility ("default"))) JSBool
4004 JS_StructuredClone(JSContext *cx, jsval v, jsval *vp,
4005 const JSStructuredCloneCallbacks *optionalCallbacks,
4007 class JSAutoStructuredCloneBuffer {
4013 JSAutoStructuredCloneBuffer()
4014 : cx_(__null), data_(__null), nbytes_(0), version_(1) {}
4015 ~JSAutoStructuredCloneBuffer() { clear(); }
4016 JSContext *cx() const { return cx_; }
4017 uint64 *data() const { return data_; }
4018 size_t nbytes() const { return nbytes_; }
4019 void clear(JSContext *cx=__null) {
4031 void adopt(JSContext *cx, uint64 *data, size_t nbytes,
4039 void steal(uint64 **datap, size_t *nbytesp, JSContext **cxp=__null,
4040 uint32 *versionp=__null) {
4046 *versionp = version_;
4052 bool read(jsval *vp, JSContext *cx=__null,
4053 const JSStructuredCloneCallbacks *optionalCallbacks=__null,
4054 void *closure=__null) const {
4059 return !!JS_ReadStructuredClone(cx, data_, nbytes_, version_, vp,
4060 optionalCallbacks, closure);
4062 bool write(JSContext *cx, jsval v,
4063 const JSStructuredCloneCallbacks *optionalCallbacks=__null,
4064 void *closure=__null) {
4067 bool ok = !!JS_WriteStructuredClone(cx, v, &data_, &nbytes_,
4068 optionalCallbacks, closure);
4076 void swap(JSAutoStructuredCloneBuffer &other) {
4077 JSContext *cx = other.cx_;
4078 uint64 *data = other.data_;
4079 size_t nbytes = other.nbytes_;
4080 uint32 version = other.version_;
4081 other.cx_ = this->cx_;
4082 other.data_ = this->data_;
4083 other.nbytes_ = this->nbytes_;
4084 other.version_ = this->version_;
4087 this->nbytes_ = nbytes;
4088 this->version_ = version;
4091 JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other);
4092 JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other);
4094 __attribute__((visibility ("default"))) void
4095 JS_SetStructuredCloneCallbacks(JSRuntime *rt, const JSStructuredCloneCallbacks *callbacks);
4096 __attribute__((visibility ("default"))) JSBool
4097 JS_ReadUint32Pair(JSStructuredCloneReader *r, uint32 *p1, uint32 *p2);
4098 __attribute__((visibility ("default"))) JSBool
4099 JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len);
4100 __attribute__((visibility ("default"))) JSBool
4101 JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32 tag, uint32 data);
4102 __attribute__((visibility ("default"))) JSBool
4103 JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len);
4104 struct JSLocaleCallbacks {
4105 JSLocaleToUpperCase localeToUpperCase;
4106 JSLocaleToLowerCase localeToLowerCase;
4107 JSLocaleCompare localeCompare;
4108 JSLocaleToUnicode localeToUnicode;
4109 JSErrorCallback localeGetErrorMessage;
4111 extern __attribute__((visibility ("default"))) void
4112 JS_SetLocaleCallbacks(JSContext *cx, JSLocaleCallbacks *callbacks);
4113 extern __attribute__((visibility ("default"))) JSLocaleCallbacks *
4114 JS_GetLocaleCallbacks(JSContext *cx);
4115 extern __attribute__((visibility ("default"))) void
4116 JS_ReportError(JSContext *cx, const char *format, ...);
4117 extern __attribute__((visibility ("default"))) void
4118 JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
4119 void *userRef, const uintN errorNumber, ...);
4120 extern __attribute__((visibility ("default"))) void
4121 JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
4122 void *userRef, const uintN errorNumber, ...);
4123 extern __attribute__((visibility ("default"))) JSBool
4124 JS_ReportWarning(JSContext *cx, const char *format, ...);
4125 extern __attribute__((visibility ("default"))) JSBool
4126 JS_ReportErrorFlagsAndNumber(JSContext *cx, uintN flags,
4127 JSErrorCallback errorCallback, void *userRef,
4128 const uintN errorNumber, ...);
4129 extern __attribute__((visibility ("default"))) JSBool
4130 JS_ReportErrorFlagsAndNumberUC(JSContext *cx, uintN flags,
4131 JSErrorCallback errorCallback, void *userRef,
4132 const uintN errorNumber, ...);
4133 extern __attribute__((visibility ("default"))) void
4134 JS_ReportOutOfMemory(JSContext *cx);
4135 extern __attribute__((visibility ("default"))) void
4136 JS_ReportAllocationOverflow(JSContext *cx);
4137 struct JSErrorReport {
4138 const char *filename;
4140 const char *linebuf;
4141 const char *tokenptr;
4142 const jschar *uclinebuf;
4143 const jschar *uctokenptr;
4146 const jschar *ucmessage;
4147 const jschar **messageArgs;
4149 extern __attribute__((visibility ("default"))) JSErrorReporter
4150 JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
4151 extern __attribute__((visibility ("default"))) JSObject *
4152 JS_NewDateObject(JSContext *cx, int year, int mon, int mday, int hour, int min, int sec);
4153 extern __attribute__((visibility ("default"))) JSObject *
4154 JS_NewDateObjectMsec(JSContext *cx, jsdouble msec);
4155 extern __attribute__((visibility ("default"))) JSBool
4156 JS_ObjectIsDate(JSContext *cx, JSObject *obj);
4157 extern __attribute__((visibility ("default"))) JSObject *
4158 JS_NewRegExpObject(JSContext *cx, JSObject *obj, char *bytes, size_t length, uintN flags);
4159 extern __attribute__((visibility ("default"))) JSObject *
4160 JS_NewUCRegExpObject(JSContext *cx, JSObject *obj, jschar *chars, size_t length, uintN flags);
4161 extern __attribute__((visibility ("default"))) void
4162 JS_SetRegExpInput(JSContext *cx, JSObject *obj, JSString *input, JSBool multiline);
4163 extern __attribute__((visibility ("default"))) void
4164 JS_ClearRegExpStatics(JSContext *cx, JSObject *obj);
4165 extern __attribute__((visibility ("default"))) JSBool
4166 JS_ExecuteRegExp(JSContext *cx, JSObject *obj, JSObject *reobj, jschar *chars, size_t length,
4167 size_t *indexp, JSBool test, jsval *rval);
4168 extern __attribute__((visibility ("default"))) JSObject *
4169 JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, uintN flags);
4170 extern __attribute__((visibility ("default"))) JSObject *
4171 JS_NewUCRegExpObjectNoStatics(JSContext *cx, jschar *chars, size_t length, uintN flags);
4172 extern __attribute__((visibility ("default"))) JSBool
4173 JS_ExecuteRegExpNoStatics(JSContext *cx, JSObject *reobj, jschar *chars, size_t length,
4174 size_t *indexp, JSBool test, jsval *rval);
4175 extern __attribute__((visibility ("default"))) JSBool
4176 JS_IsExceptionPending(JSContext *cx);
4177 extern __attribute__((visibility ("default"))) JSBool
4178 JS_GetPendingException(JSContext *cx, jsval *vp);
4179 extern __attribute__((visibility ("default"))) void
4180 JS_SetPendingException(JSContext *cx, jsval v);
4181 extern __attribute__((visibility ("default"))) void
4182 JS_ClearPendingException(JSContext *cx);
4183 extern __attribute__((visibility ("default"))) JSBool
4184 JS_ReportPendingException(JSContext *cx);
4185 extern __attribute__((visibility ("default"))) JSExceptionState *
4186 JS_SaveExceptionState(JSContext *cx);
4187 extern __attribute__((visibility ("default"))) void
4188 JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state);
4189 extern __attribute__((visibility ("default"))) void
4190 JS_DropExceptionState(JSContext *cx, JSExceptionState *state);
4191 extern __attribute__((visibility ("default"))) JSErrorReport *
4192 JS_ErrorFromException(JSContext *cx, jsval v);
4193 extern __attribute__((visibility ("default"))) JSBool
4194 JS_ThrowReportedError(JSContext *cx, const char *message,
4195 JSErrorReport *reportp);
4196 extern __attribute__((visibility ("default"))) JSBool
4197 JS_ThrowStopIteration(JSContext *cx);
4198 extern __attribute__((visibility ("default"))) jsword
4199 JS_GetContextThread(JSContext *cx);
4200 extern __attribute__((visibility ("default"))) jsword
4201 JS_SetContextThread(JSContext *cx);
4202 extern __attribute__((visibility ("default"))) jsword
4203 JS_ClearContextThread(JSContext *cx);
4204 static __attribute__((always_inline)) inline JSBool
4205 JS_IsConstructing(JSContext *cx, const jsval *vp)
4209 return JSVAL_IS_MAGIC_IMPL(l);
4211 static __attribute__((always_inline)) inline JSBool
4212 JS_IsConstructing_PossiblyWithGivenThisObject(JSContext *cx, const jsval *vp,
4213 JSObject **maybeThis)
4218 isCtor = JSVAL_IS_MAGIC_IMPL(l);
4220 *maybeThis = MAGIC_JSVAL_TO_OBJECT_OR_NULL_IMPL(l);
4223 extern __attribute__((visibility ("default"))) JSObject *
4224 JS_NewObjectForConstructor(JSContext *cx, const jsval *vp);
4227 static const uintN JS_GCTHING_ALIGN = 8;
4228 static const uintN JS_GCTHING_ZEROBITS = 3;
4229 typedef uint8 jsbytecode;
4230 typedef uint8 jssrcnote;
4231 typedef uint32 jsatomid;
4232 typedef struct JSArgumentFormatMap JSArgumentFormatMap;
4233 typedef struct JSCodeGenerator JSCodeGenerator;
4234 typedef struct JSGCThing JSGCThing;
4235 typedef struct JSGenerator JSGenerator;
4236 typedef struct JSNativeEnumerator JSNativeEnumerator;
4237 typedef struct JSFunctionBox JSFunctionBox;
4238 typedef struct JSObjectBox JSObjectBox;
4239 typedef struct JSParseNode JSParseNode;
4240 typedef struct JSProperty JSProperty;
4241 typedef struct JSScript JSScript;
4242 typedef struct JSSharpObjectMap JSSharpObjectMap;
4243 typedef struct JSThread JSThread;
4244 typedef struct JSThreadData JSThreadData;
4245 typedef struct JSTreeContext JSTreeContext;
4246 typedef struct JSTryNote JSTryNote;
4247 typedef struct JSLinearString JSLinearString;
4248 typedef struct JSAtom JSAtom;
4249 typedef struct JSAtomList JSAtomList;
4250 typedef struct JSAtomListElement JSAtomListElement;
4251 typedef struct JSAtomMap JSAtomMap;
4252 typedef struct JSAtomState JSAtomState;
4253 typedef struct JSCodeSpec JSCodeSpec;
4254 typedef struct JSPrinter JSPrinter;
4255 typedef struct JSRegExpStatics JSRegExpStatics;
4256 typedef struct JSStackHeader JSStackHeader;
4257 typedef struct JSSubString JSSubString;
4258 typedef struct JSNativeTraceInfo JSNativeTraceInfo;
4259 typedef struct JSSpecializedNative JSSpecializedNative;
4260 typedef struct JSXML JSXML;
4261 typedef struct JSXMLArray JSXMLArray;
4262 typedef struct JSXMLArrayCursor JSXMLArrayCursor;
4265 struct ArgumentsData;
4267 class RegExpStatics;
4268 class AutoStringRooter;
4269 class ExecuteArgsGuard;
4270 class InvokeFrameGuard;
4271 class InvokeArgsGuard;
4272 class InvokeSessionGuard;
4273 class TraceRecorder;
4274 struct TraceMonitor;
4277 class FrameRegsIter;
4285 class ContextAllocPolicy;
4286 class SystemAllocPolicy;
4288 size_t MinInlineCapacity = 0,
4289 class AllocPolicy = ContextAllocPolicy>
4292 struct DefaultHasher;
4293 template <class Key,
4295 class HashPolicy = DefaultHasher<Key>,
4296 class AllocPolicy = ContextAllocPolicy>
4299 class HashPolicy = DefaultHasher<T>,
4300 class AllocPolicy = ContextAllocPolicy>
4302 class PropertyCache;
4303 struct PropertyCacheEntry;
4308 typedef enum JSTrapStatus {
4315 typedef JSTrapStatus
4316 (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
4318 typedef JSTrapStatus
4319 (* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
4321 typedef JSTrapStatus
4322 (* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
4324 typedef JSTrapStatus
4325 (* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
4328 (* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, jsval old,
4329 jsval *newp, void *closure);
4331 (* JSNewScriptHook)(JSContext *cx,
4332 const char *filename,
4338 (* JSDestroyScriptHook)(JSContext *cx,
4342 (* JSSourceHandler)(const char *filename, uintN lineno, jschar *str,
4343 size_t length, void **listenerTSData, void *closure);
4345 (* JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before,
4346 JSBool *ok, void *closure);
4348 (* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report,
4350 typedef struct JSDebugHooks {
4351 JSInterruptHook interruptHook;
4352 void *interruptHookData;
4353 JSNewScriptHook newScriptHook;
4354 void *newScriptHookData;
4355 JSDestroyScriptHook destroyScriptHook;
4356 void *destroyScriptHookData;
4357 JSDebuggerHandler debuggerHandler;
4358 void *debuggerHandlerData;
4359 JSSourceHandler sourceHandler;
4360 void *sourceHandlerData;
4361 JSInterpreterHook executeHook;
4362 void *executeHookData;
4363 JSInterpreterHook callHook;
4365 JSThrowHook throwHook;
4366 void *throwHookData;
4367 JSDebugErrorHook debugErrorHook;
4368 void *debugErrorHookData;
4371 (* JSLookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
4372 JSProperty **propp);
4374 (* JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
4376 (* JSObjectOp)(JSContext *cx, JSObject *obj);
4378 (* JSIteratorOp)(JSContext *cx, JSObject *obj, JSBool keysonly);
4379 extern JSBool js_CStringsAreUTF8;
4380 extern __attribute__((visibility ("default"))) JSObject *
4381 js_ObjectToOuterObject(JSContext *cx, JSObject *obj);
4384 typedef uint32 JSHashNumber;
4385 typedef struct JSHashEntry JSHashEntry;
4386 typedef struct JSHashTable JSHashTable;
4387 typedef JSHashNumber (* JSHashFunction)(const void *key);
4388 typedef intN (* JSHashComparator)(const void *v1, const void *v2);
4389 typedef intN (* JSHashEnumerator)(JSHashEntry *he, intN i, void *arg);
4390 typedef struct JSHashAllocOps {
4391 void * (*allocTable)(void *pool, size_t size);
4392 void (*freeTable)(void *pool, void *item, size_t size);
4393 JSHashEntry * (*allocEntry)(void *pool, const void *key);
4394 void (*freeEntry)(void *pool, JSHashEntry *he, uintN flag);
4396 struct JSHashEntry {
4398 JSHashNumber keyHash;
4402 struct JSHashTable {
4403 JSHashEntry **buckets;
4406 JSHashFunction keyHash;
4407 JSHashComparator keyCompare;
4408 JSHashComparator valueCompare;
4409 JSHashAllocOps *allocOps;
4412 extern __attribute__((visibility ("default"))) JSHashTable *
4413 JS_NewHashTable(uint32 n, JSHashFunction keyHash,
4414 JSHashComparator keyCompare, JSHashComparator valueCompare,
4415 JSHashAllocOps *allocOps, void *allocPriv);
4416 extern __attribute__((visibility ("default"))) void
4417 JS_HashTableDestroy(JSHashTable *ht);
4418 extern __attribute__((visibility ("default"))) JSHashEntry **
4419 JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key);
4420 extern __attribute__((visibility ("default"))) JSHashEntry *
4421 JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **&hep, JSHashNumber keyHash,
4422 const void *key, void *value);
4423 extern __attribute__((visibility ("default"))) void
4424 JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he);
4425 extern __attribute__((visibility ("default"))) JSHashEntry *
4426 JS_HashTableAdd(JSHashTable *ht, const void *key, void *value);
4427 extern __attribute__((visibility ("default"))) JSBool
4428 JS_HashTableRemove(JSHashTable *ht, const void *key);
4429 extern __attribute__((visibility ("default"))) intN
4430 JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg);
4431 extern __attribute__((visibility ("default"))) void *
4432 JS_HashTableLookup(JSHashTable *ht, const void *key);
4433 extern __attribute__((visibility ("default"))) intN
4434 JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp);
4435 extern __attribute__((visibility ("default"))) JSHashNumber
4436 JS_HashString(const void *key);
4437 extern __attribute__((visibility ("default"))) intN
4438 JS_CompareValues(const void *v1, const void *v2);
4443 typedef long unsigned int size_t;
4444 typedef long int ptrdiff_t;
4448 inline namespace __gnu_cxx_ldbl128 { }
4458 exception() throw() { }
4459 virtual ~exception() throw();
4460 virtual const char* what() const throw();
4462 class bad_exception : public exception
4465 bad_exception() throw() { }
4466 virtual ~bad_exception() throw();
4467 virtual const char* what() const throw();
4469 typedef void (*terminate_handler) ();
4470 typedef void (*unexpected_handler) ();
4471 terminate_handler set_terminate(terminate_handler) throw();
4472 void terminate() throw() __attribute__ ((__noreturn__));
4473 unexpected_handler set_unexpected(unexpected_handler) throw();
4474 void unexpected() __attribute__ ((__noreturn__));
4475 bool uncaught_exception() throw() __attribute__ ((__pure__));
4479 void __verbose_terminate_handler();
4485 class bad_alloc : public exception
4488 bad_alloc() throw() { }
4489 virtual ~bad_alloc() throw();
4490 virtual const char* what() const throw();
4492 class bad_array_length : public bad_alloc
4495 bad_array_length() throw() { };
4496 virtual ~bad_array_length() throw();
4497 virtual const char* what() const throw();
4499 struct nothrow_t { };
4500 extern const nothrow_t nothrow;
4501 typedef void (*new_handler)();
4502 new_handler set_new_handler(new_handler) throw();
4504 void* operator new(std::size_t) throw(std::bad_alloc)
4505 __attribute__((__externally_visible__));
4506 void* operator new[](std::size_t) throw(std::bad_alloc)
4507 __attribute__((__externally_visible__));
4508 void operator delete(void*) throw()
4509 __attribute__((__externally_visible__));
4510 void operator delete[](void*) throw()
4511 __attribute__((__externally_visible__));
4512 void* operator new(std::size_t, const std::nothrow_t&) throw()
4513 __attribute__((__externally_visible__));
4514 void* operator new[](std::size_t, const std::nothrow_t&) throw()
4515 __attribute__((__externally_visible__));
4516 void operator delete(void*, const std::nothrow_t&) throw()
4517 __attribute__((__externally_visible__));
4518 void operator delete[](void*, const std::nothrow_t&) throw()
4519 __attribute__((__externally_visible__));
4520 inline void* operator new(std::size_t, void* __p) throw()
4522 inline void* operator new[](std::size_t, void* __p) throw()
4524 inline void operator delete (void*, void*) throw() { }
4525 inline void operator delete[](void*, void*) throw() { }
4529 template <size_t i, size_t j> struct Min {
4530 static const size_t result = i < j ? i : j;
4532 template <size_t i, size_t j> struct Max {
4533 static const size_t result = i > j ? i : j;
4535 template <size_t i, size_t min, size_t max> struct Clamp {
4536 static const size_t result = i < min ? min : (i > max ? max : i);
4538 template <size_t x, size_t y> struct Pow {
4539 static const size_t result = x * Pow<x, y - 1>::result;
4541 template <size_t x> struct Pow<x,0> {
4542 static const size_t result = 1;
4544 template <size_t i> struct FloorLog2 {
4545 static const size_t result = 1 + FloorLog2<i / 2>::result;
4547 template <> struct FloorLog2<0> { };
4548 template <> struct FloorLog2<1> { static const size_t result = 0; };
4549 template <size_t i> struct CeilingLog2 {
4550 static const size_t result = FloorLog2<2 * i - 1>::result;
4552 template <size_t i> struct RoundUpPow2 {
4553 static const size_t result = 1u << CeilingLog2<i>::result;
4555 template <> struct RoundUpPow2<0> {
4556 static const size_t result = 1;
4558 template <class T> struct BitSize {
4559 static const size_t result = sizeof(T) * 8;
4561 template <bool> struct StaticAssert {};
4562 template <> struct StaticAssert<true> { typedef int result; };
4563 template <class T, class U> struct IsSameType {
4564 static const bool result = false;
4566 template <class T> struct IsSameType<T,T> {
4567 static const bool result = true;
4569 template <size_t N> struct NBitMask {
4570 typedef typename StaticAssert<N < BitSize<size_t>::result>::result _;
4571 static const size_t result = (size_t(1) << N) - 1;
4573 template <> struct NBitMask<BitSize<size_t>::result> {
4574 static const size_t result = size_t(-1);
4576 template <size_t N> struct MulOverflowMask {
4577 static const size_t result =
4578 ~NBitMask<BitSize<size_t>::result - CeilingLog2<N>::result>::result;
4580 template <> struct MulOverflowMask<0> { };
4581 template <> struct MulOverflowMask<1> { static const size_t result = 0; };
4582 template <class T> struct UnsafeRangeSizeMask {
4583 static const size_t result = MulOverflowMask<2 * sizeof(T)>::result;
4585 template <class T> struct StripConst { typedef T result; };
4586 template <class T> struct StripConst<const T> { typedef T result; };
4587 template <class T> struct IsPodType { static const bool result = false; };
4588 template <> struct IsPodType<char> { static const bool result = true; };
4589 template <> struct IsPodType<signed char> { static const bool result = true; };
4590 template <> struct IsPodType<unsigned char> { static const bool result = true; };
4591 template <> struct IsPodType<short> { static const bool result = true; };
4592 template <> struct IsPodType<unsigned short> { static const bool result = true; };
4593 template <> struct IsPodType<int> { static const bool result = true; };
4594 template <> struct IsPodType<unsigned int> { static const bool result = true; };
4595 template <> struct IsPodType<long> { static const bool result = true; };
4596 template <> struct IsPodType<unsigned long> { static const bool result = true; };
4597 template <> struct IsPodType<float> { static const bool result = true; };
4598 template <> struct IsPodType<double> { static const bool result = true; };
4599 template <class T, size_t N> inline T *ArraySize(T (&)[N]) { return N; }
4600 template <class T, size_t N> inline T *ArrayEnd(T (&arr)[N]) { return arr + N; }
4602 class ReentrancyGuard
4604 ReentrancyGuard(const ReentrancyGuard &);
4605 void operator=(const ReentrancyGuard &);
4608 ReentrancyGuard(T & )
4615 __attribute__((always_inline)) inline size_t
4616 RoundUpPow2(size_t x)
4618 size_t log2 = ((x) <= 1 ? 0 : 1 + (((void) 0), ((size_t)((8 * 8) - 1 - __builtin_clzll((x) - 1)))));
4620 size_t result = size_t(1) << log2;
4624 __attribute__((always_inline)) inline size_t
4625 PointerRangeSize(T *begin, T *end)
4627 return (size_t(end) - size_t(begin)) / sizeof(T);
4629 class SystemAllocPolicy
4632 void *malloc(size_t bytes) { return js_malloc(bytes); }
4633 void *realloc(void *p, size_t bytes) { return js_realloc(p, bytes); }
4634 void free(void *p) { js_free(p); }
4635 void reportAllocOverflow() const {}
4637 template <size_t nbytes>
4638 struct AlignedStorage
4644 const void *addr() const { return u.bytes; }
4645 void *addr() { return u.bytes; }
4648 struct AlignedStorage2
4651 char bytes[sizeof(T)];
4654 const T *addr() const { return (const T *)u.bytes; }
4655 T *addr() { return (T *)u.bytes; }
4658 class LazilyConstructed
4660 AlignedStorage2<T> storage;
4662 T &asT() { return *storage.addr(); }
4664 LazilyConstructed() { constructed = false; }
4665 ~LazilyConstructed() { if (constructed) asT().~T(); }
4666 bool empty() const { return !constructed; }
4669 new(storage.addr()) T();
4673 void construct(const T1 &t1) {
4675 new(storage.addr()) T(t1);
4678 template <class T1, class T2>
4679 void construct(const T1 &t1, const T2 &t2) {
4681 new(storage.addr()) T(t1, t2);
4684 template <class T1, class T2, class T3>
4685 void construct(const T1 &t1, const T2 &t2, const T3 &t3) {
4687 new(storage.addr()) T(t1, t2, t3);
4690 template <class T1, class T2, class T3, class T4>
4691 void construct(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) {
4693 new(storage.addr()) T(t1, t2, t3, t4);
4706 constructed = false;
4710 class Conditionally {
4711 LazilyConstructed<T> t;
4713 Conditionally(bool b) { if (b) t.construct(); }
4715 Conditionally(bool b, const T1 &t1) { if (b) t.construct(t1); }
4716 template <class T1, class T2>
4717 Conditionally(bool b, const T1 &t1, const T2 &t2) { if (b) t.construct(t1, t2); }
4720 class AlignedPtrAndFlag
4724 AlignedPtrAndFlag(T *t, bool flag) {
4726 bits = uintptr_t(t) | uintptr_t(flag);
4729 return (T *)(bits & ~uintptr_t(1));
4732 return (bits & 1) != 0;
4736 bits = uintptr_t(t) | uintptr_t(flag());
4742 bits &= ~uintptr_t(1);
4744 void set(T *t, bool flag) {
4746 bits = uintptr_t(t) | flag;
4751 Reverse(T *beg, T *end)
4753 while (beg != end) {
4764 Find(T *beg, T *end, const T &v)
4766 for (T *p = beg; p != end; ++p) {
4772 template <class Container>
4773 static inline typename Container::ElementType *
4774 Find(Container &c, const typename Container::ElementType &v)
4776 return Find(c.begin(), c.end(), v);
4778 template <typename InputIterT, typename CallableT>
4780 ForEach(InputIterT begin, InputIterT end, CallableT f)
4782 for (; begin != end; ++begin)
4789 return t1 < t2 ? t1 : t2;
4795 return t1 > t2 ? t1 : t2;
4799 InitConst(const T &t)
4801 return const_cast<T &>(t);
4805 typedef uint32 HashNumber;
4807 template <class T, class HashPolicy, class AllocPolicy>
4808 class HashTable : AllocPolicy
4810 typedef typename tl::StripConst<T>::result NonConstT;
4811 typedef typename HashPolicy::KeyType Key;
4812 typedef typename HashPolicy::Lookup Lookup;
4813 static void assignT(NonConstT &dst, const T &src) { dst = src; }
4818 Entry() : keyHash(0), t() {}
4819 void operator=(const Entry &rhs) { keyHash = rhs.keyHash; assignT(t, rhs.t); }
4821 bool isFree() const { return keyHash == sFreeKey; }
4822 void setFree() { keyHash = sFreeKey; assignT(t, T()); }
4823 bool isRemoved() const { return keyHash == sRemovedKey; }
4824 void setRemoved() { keyHash = sRemovedKey; assignT(t, T()); }
4825 bool isLive() const { return isLiveHash(keyHash); }
4826 void setLive(HashNumber hn) { ((void) 0); keyHash = hn; }
4827 void setCollision() { ((void) 0); keyHash |= sCollisionBit; }
4828 void setCollision(HashNumber collisionBit) {
4829 ((void) 0); keyHash |= collisionBit;
4831 void unsetCollision() { ((void) 0); keyHash &= ~sCollisionBit; }
4832 bool hasCollision() const { ((void) 0); return keyHash & sCollisionBit; }
4833 bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; }
4834 HashNumber getKeyHash() const { ((void) 0); return keyHash; }
4838 friend class HashTable;
4839 typedef void (Ptr::* ConvertibleToBool)();
4843 Ptr(Entry &entry) : entry(&entry) {}
4845 bool found() const { return entry->isLive(); }
4846 operator ConvertibleToBool() const { return found() ? &Ptr::nonNull : 0; }
4847 bool operator==(const Ptr &rhs) const { ((void) 0); return entry == rhs.entry; }
4848 bool operator!=(const Ptr &rhs) const { return !(*this == rhs); }
4849 T &operator*() const { return entry->t; }
4850 T *operator->() const { return &entry->t; }
4852 class AddPtr : public Ptr
4854 friend class HashTable;
4856 AddPtr(Entry &entry, HashNumber hn) : Ptr(entry), keyHash(hn) {}
4861 friend class HashTable;
4862 Range(Entry *c, Entry *e) : cur(c), end(e) {
4863 while (cur != end && !cur->isLive())
4868 bool empty() const {
4877 while (++cur != end && !cur->isLive());
4880 class Enum : public Range
4882 friend class HashTable;
4886 void operator=(const Enum &);
4888 template<class Map> explicit
4889 Enum(Map &map) : Range(map.all()), table(map.impl), removed(false) {}
4890 void removeFront() {
4891 table.remove(*this->cur);
4896 table.checkUnderloaded();
4898 void endEnumeration() {
4900 table.checkUnderloaded();
4907 uint32 tableCapacity;
4910 uint32 removedCount;
4912 void setTableSizeLog2(unsigned sizeLog2) {
4913 hashShift = sHashBits - sizeLog2;
4914 tableCapacity = ((JSUint32)1 << (sizeLog2));
4916 static const unsigned sMinSizeLog2 = 4;
4917 static const unsigned sMinSize = 1 << sMinSizeLog2;
4918 static const unsigned sSizeLimit = ((JSUint32)1 << (24));
4919 static const unsigned sHashBits = tl::BitSize<HashNumber>::result;
4920 static const uint8 sMinAlphaFrac = 64;
4921 static const uint8 sMaxAlphaFrac = 192;
4922 static const uint8 sInvMaxAlpha = 171;
4923 static const HashNumber sGoldenRatio = 0x9E3779B9U;
4924 static const HashNumber sCollisionBit = 1;
4925 static const HashNumber sFreeKey = 0;
4926 static const HashNumber sRemovedKey = 1;
4927 static bool isLiveHash(HashNumber hash)
4929 return hash > sRemovedKey;
4931 static HashNumber prepareHash(const Lookup& l)
4933 HashNumber keyHash = HashPolicy::hash(l);
4934 keyHash *= sGoldenRatio;
4935 if (!isLiveHash(keyHash))
4936 keyHash -= (sRemovedKey + 1);
4937 return keyHash & ~sCollisionBit;
4939 static Entry *createTable(AllocPolicy &alloc, uint32 capacity)
4941 Entry *newTable = (Entry *)alloc.malloc(capacity * sizeof(Entry));
4944 for (Entry *e = newTable, *end = e + capacity; e != end; ++e)
4948 static void destroyTable(AllocPolicy &alloc, Entry *oldTable, uint32 capacity)
4950 for (Entry *e = oldTable, *end = e + capacity; e != end; ++e)
4952 alloc.free(oldTable);
4955 HashTable(AllocPolicy ap)
4962 bool init(uint32 length)
4966 uint32 capacity = (length * sInvMaxAlpha) >> 7;
4967 if (capacity < sMinSize)
4968 capacity = sMinSize;
4969 uint32 roundUp = sMinSize, roundUpLog2 = sMinSizeLog2;
4970 while (roundUp < capacity) {
4975 if (capacity >= sSizeLimit) {
4976 this->reportAllocOverflow();
4979 table = createTable(*this, capacity);
4982 setTableSizeLog2(roundUpLog2);
4986 bool initialized() const
4993 destroyTable(*this, table, tableCapacity);
4996 static HashNumber hash1(HashNumber hash0, uint32 shift) {
4997 return hash0 >> shift;
4999 static HashNumber hash2(HashNumber hash0, uint32 log2, uint32 shift) {
5000 return ((hash0 << log2) >> shift) | 1;
5003 return entryCount + removedCount >= ((sMaxAlphaFrac * tableCapacity) >> 8);
5005 bool underloaded() {
5006 return tableCapacity > sMinSize &&
5007 entryCount <= ((sMinAlphaFrac * tableCapacity) >> 8);
5009 static bool match(Entry &e, const Lookup &l) {
5010 return HashPolicy::match(HashPolicy::getKey(e.t), l);
5012 Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const
5019 HashNumber h1 = hash1(keyHash, hashShift);
5020 Entry *entry = &table[h1];
5021 if (entry->isFree()) {
5025 if (entry->matchHash(keyHash) && match(*entry, l)) {
5029 unsigned sizeLog2 = sHashBits - hashShift;
5030 HashNumber h2 = hash2(keyHash, sizeLog2, hashShift);
5031 HashNumber sizeMask = (HashNumber(1) << sizeLog2) - 1;
5032 Entry *firstRemoved = __null;
5034 if ((__builtin_expect((entry->isRemoved()), 0))) {
5036 firstRemoved = entry;
5038 entry->setCollision(collisionBit);
5044 if (entry->isFree()) {
5046 return firstRemoved ? *firstRemoved : *entry;
5048 if (entry->matchHash(keyHash) && match(*entry, l)) {
5054 Entry &findFreeEntry(HashNumber keyHash)
5058 HashNumber h1 = hash1(keyHash, hashShift);
5059 Entry *entry = &table[h1];
5060 if (entry->isFree()) {
5064 unsigned sizeLog2 = sHashBits - hashShift;
5065 HashNumber h2 = hash2(keyHash, sizeLog2, hashShift);
5066 HashNumber sizeMask = (HashNumber(1) << sizeLog2) - 1;
5069 entry->setCollision();
5074 if (entry->isFree()) {
5080 bool changeTableSize(int deltaLog2)
5082 Entry *oldTable = table;
5083 uint32 oldCap = tableCapacity;
5084 uint32 newLog2 = sHashBits - hashShift + deltaLog2;
5085 uint32 newCapacity = ((JSUint32)1 << (newLog2));
5086 if (newCapacity >= sSizeLimit) {
5087 this->reportAllocOverflow();
5090 Entry *newTable = createTable(*this, newCapacity);
5093 setTableSizeLog2(newLog2);
5097 for (Entry *src = oldTable, *end = src + oldCap; src != end; ++src) {
5098 if (src->isLive()) {
5099 src->unsetCollision();
5100 findFreeEntry(src->getKeyHash()) = *src;
5103 destroyTable(*this, oldTable, oldCap);
5106 void remove(Entry &e)
5109 if (e.hasCollision()) {
5118 void checkUnderloaded()
5120 if (underloaded()) {
5122 (void) changeTableSize(-1);
5128 for (Entry *e = table, *end = table + tableCapacity; e != end; ++e)
5134 return Range(table, table + tableCapacity);
5136 bool empty() const {
5139 uint32 count() const{
5142 uint32 generation() const {
5145 Ptr lookup(const Lookup &l) const {
5146 ReentrancyGuard g(*this);
5147 HashNumber keyHash = prepareHash(l);
5148 return Ptr(lookup(l, keyHash, 0));
5150 AddPtr lookupForAdd(const Lookup &l) const {
5151 ReentrancyGuard g(*this);
5152 HashNumber keyHash = prepareHash(l);
5153 Entry &entry = lookup(l, keyHash, sCollisionBit);
5154 return AddPtr(entry, keyHash);
5158 ReentrancyGuard g(*this);
5163 if (p.entry->isRemoved()) {
5166 p.keyHash |= sCollisionBit;
5170 if (removedCount >= (tableCapacity >> 2)) {
5177 if (!changeTableSize(deltaLog2))
5179 p.entry = &findFreeEntry(p.keyHash);
5182 p.entry->setLive(p.keyHash);
5186 bool add(AddPtr &p, T** pentry)
5190 *pentry = &p.entry->t;
5193 bool add(AddPtr &p, const T &t)
5200 bool relookupOrAdd(AddPtr& p, const Lookup &l, const T& t)
5203 ReentrancyGuard g(*this);
5204 p.entry = &lookup(l, p.keyHash, sCollisionBit);
5206 return p.found() || add(p, t);
5210 ReentrancyGuard g(*this);
5217 template <class Key>
5218 struct DefaultHasher
5221 static HashNumber hash(const Lookup &l) {
5224 static bool match(const Key &k, const Lookup &l) {
5229 struct DefaultHasher<T *>
5232 static HashNumber hash(T *l) {
5233 return HashNumber(reinterpret_cast<size_t>(l) >>
5234 tl::FloorLog2<sizeof(void *)>::result);
5236 static bool match(T *k, T *l) {
5240 template <class Key, class Value, class HashPolicy, class AllocPolicy>
5244 typedef typename HashPolicy::Lookup Lookup;
5247 template <class, class, class> friend class detail::HashTable;
5248 void operator=(const Entry &rhs) {
5249 const_cast<Key &>(key) = rhs.key;
5253 Entry() : key(), value() {}
5254 Entry(const Key &k, const Value &v) : key(k), value(v) {}
5259 struct MapHashPolicy : HashPolicy
5261 typedef Key KeyType;
5262 static const Key &getKey(Entry &e) { return e.key; }
5264 typedef detail::HashTable<Entry, MapHashPolicy, AllocPolicy> Impl;
5265 friend class Impl::Enum;
5266 HashMap(const HashMap &);
5267 HashMap &operator=(const HashMap &);
5270 HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {}
5271 bool init(uint32 len = 0) { return impl.init(len); }
5272 bool initialized() const { return impl.initialized(); }
5273 typedef typename Impl::Ptr Ptr;
5274 Ptr lookup(const Lookup &l) const { return impl.lookup(l); }
5275 void remove(Ptr p) { impl.remove(p); }
5276 typedef typename Impl::AddPtr AddPtr;
5277 AddPtr lookupForAdd(const Lookup &l) const {
5278 return impl.lookupForAdd(l);
5280 bool add(AddPtr &p, const Key &k, const Value &v) {
5282 if (!impl.add(p, &pentry))
5284 const_cast<Key &>(pentry->key) = k;
5288 bool add(AddPtr &p, const Key &k) {
5290 if (!impl.add(p, &pentry))
5292 const_cast<Key &>(pentry->key) = k;
5295 bool relookupOrAdd(AddPtr &p, const Key &k, const Value &v) {
5296 return impl.relookupOrAdd(p, k, Entry(k, v));
5298 typedef typename Impl::Range Range;
5299 Range all() const { return impl.all(); }
5300 size_t count() const { return impl.count(); }
5301 typedef typename Impl::Enum Enum;
5302 void clear() { impl.clear(); }
5303 bool empty() const { return impl.empty(); }
5304 unsigned generation() const { return impl.generation(); }
5305 bool has(const Lookup &l) const {
5306 return impl.lookup(l) != __null;
5308 Entry *put(const Key &k, const Value &v) {
5309 AddPtr p = lookupForAdd(k);
5314 return add(p, k, v) ? &*p : __null;
5316 void remove(const Lookup &l) {
5317 if (Ptr p = lookup(l))
5321 template <class T, class HashPolicy, class AllocPolicy>
5324 typedef typename HashPolicy::Lookup Lookup;
5325 struct SetOps : HashPolicy {
5327 static const KeyType &getKey(const T &t) { return t; }
5329 typedef detail::HashTable<const T, SetOps, AllocPolicy> Impl;
5330 friend class Impl::Enum;
5331 HashSet(const HashSet &);
5332 HashSet &operator=(const HashSet &);
5335 HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {}
5336 bool init(uint32 len = 0) { return impl.init(len); }
5337 bool initialized() const { return impl.initialized(); }
5338 typedef typename Impl::Ptr Ptr;
5339 Ptr lookup(const Lookup &l) const { return impl.lookup(l); }
5340 void remove(Ptr p) { impl.remove(p); }
5341 typedef typename Impl::AddPtr AddPtr;
5342 AddPtr lookupForAdd(const Lookup &l) const {
5343 return impl.lookupForAdd(l);
5345 bool add(AddPtr &p, const T &t) {
5346 return impl.add(p, t);
5348 bool relookupOrAdd(AddPtr &p, const Lookup &l, const T &t) {
5349 return impl.relookupOrAdd(p, l, t);
5351 typedef typename Impl::Range Range;
5352 Range all() const { return impl.all(); }
5353 size_t count() const { return impl.count(); }
5354 typedef typename Impl::Enum Enum;
5355 void clear() { impl.clear(); }
5356 bool empty() const { return impl.empty(); }
5357 unsigned generation() const { return impl.generation(); }
5358 bool has(const Lookup &l) const {
5359 return impl.lookup(l) != __null;
5361 const T *put(const T &t) {
5362 AddPtr p = lookupForAdd(t);
5363 return p ? &*p : (add(p, t) ? &*p : __null);
5365 void remove(const Lookup &l) {
5366 if (Ptr p = lookup(l))
5374 _ISupper = (1 << (0)),
5375 _ISlower = (1 << (1)),
5376 _ISalpha = (1 << (2)),
5377 _ISdigit = (1 << (3)),
5378 _ISxdigit = (1 << (4)),
5379 _ISspace = (1 << (5)),
5380 _ISprint = (1 << (6)),
5381 _ISgraph = (1 << (7)),
5382 _ISblank = (1 << (8)),
5383 _IScntrl = (1 << (9)),
5384 _ISpunct = (1 << (10)),
5385 _ISalnum = (1 << (11))
5387 extern const unsigned short int **__ctype_b_loc (void)
5388 throw () __attribute__ ((__const__));
5389 extern const __int32_t **__ctype_tolower_loc (void)
5390 throw () __attribute__ ((__const__));
5391 extern const __int32_t **__ctype_toupper_loc (void)
5392 throw () __attribute__ ((__const__));
5393 extern int isalnum (int) throw ();
5394 extern int isalpha (int) throw ();
5395 extern int iscntrl (int) throw ();
5396 extern int isdigit (int) throw ();
5397 extern int islower (int) throw ();
5398 extern int isgraph (int) throw ();
5399 extern int isprint (int) throw ();
5400 extern int ispunct (int) throw ();
5401 extern int isspace (int) throw ();
5402 extern int isupper (int) throw ();
5403 extern int isxdigit (int) throw ();
5404 extern int tolower (int __c) throw ();
5405 extern int toupper (int __c) throw ();
5406 extern int isblank (int) throw ();
5407 extern int isctype (int __c, int __mask) throw ();
5408 extern int isascii (int __c) throw ();
5409 extern int toascii (int __c) throw ();
5410 extern int _toupper (int) throw ();
5411 extern int _tolower (int) throw ();
5412 extern int isalnum_l (int, __locale_t) throw ();
5413 extern int isalpha_l (int, __locale_t) throw ();
5414 extern int iscntrl_l (int, __locale_t) throw ();
5415 extern int isdigit_l (int, __locale_t) throw ();
5416 extern int islower_l (int, __locale_t) throw ();
5417 extern int isgraph_l (int, __locale_t) throw ();
5418 extern int isprint_l (int, __locale_t) throw ();
5419 extern int ispunct_l (int, __locale_t) throw ();
5420 extern int isspace_l (int, __locale_t) throw ();
5421 extern int isupper_l (int, __locale_t) throw ();
5422 extern int isxdigit_l (int, __locale_t) throw ();
5423 extern int isblank_l (int, __locale_t) throw ();
5424 extern int __tolower_l (int __c, __locale_t __l) throw ();
5425 extern int tolower_l (int __c, __locale_t __l) throw ();
5426 extern int __toupper_l (int __c, __locale_t __l) throw ();
5427 extern int toupper_l (int __c, __locale_t __l) throw ();
5430 typedef unsigned char PRUint8;
5431 typedef signed char PRInt8;
5432 typedef unsigned short PRUint16;
5433 typedef short PRInt16;
5434 typedef unsigned int PRUint32;
5435 typedef int PRInt32;
5436 typedef long PRInt64;
5437 typedef unsigned long PRUint64;
5439 typedef unsigned int PRUintn;
5440 typedef double PRFloat64;
5441 typedef size_t PRSize;
5442 typedef PRInt32 PROffset32;
5443 typedef PRInt64 PROffset64;
5444 typedef ptrdiff_t PRPtrdiff;
5445 typedef unsigned long PRUptrdiff;
5446 typedef PRIntn PRBool;
5447 typedef PRUint8 PRPackedBool;
5448 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
5449 typedef PRUint16 PRUnichar;
5450 typedef long PRWord;
5451 typedef unsigned long PRUword;
5454 typedef struct PRLock PRLock;
5455 extern __attribute__((visibility("default"))) PRLock* PR_NewLock(void);
5456 extern __attribute__((visibility("default"))) void PR_DestroyLock(PRLock *lock);
5457 extern __attribute__((visibility("default"))) void PR_Lock(PRLock *lock);
5458 extern __attribute__((visibility("default"))) PRStatus PR_Unlock(PRLock *lock);
5459 extern __attribute__((visibility("default"))) void PR_AssertCurrentThreadOwnsLock(PRLock *lock);
5462 extern __attribute__((visibility("default"))) PRInt32 PR_AtomicIncrement(PRInt32 *val);
5463 extern __attribute__((visibility("default"))) PRInt32 PR_AtomicDecrement(PRInt32 *val);
5464 extern __attribute__((visibility("default"))) PRInt32 PR_AtomicSet(PRInt32 *val, PRInt32 newval);
5465 extern __attribute__((visibility("default"))) PRInt32 PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
5466 typedef struct PRStackElemStr PRStackElem;
5467 struct PRStackElemStr {
5468 PRStackElem *prstk_elem_next;
5470 typedef struct PRStackStr PRStack;
5471 extern __attribute__((visibility("default"))) PRStack * PR_CreateStack(const char *stack_name);
5472 extern __attribute__((visibility("default"))) void PR_StackPush(PRStack *stack, PRStackElem *stack_elem);
5473 extern __attribute__((visibility("default"))) PRStackElem * PR_StackPop(PRStack *stack);
5474 extern __attribute__((visibility("default"))) PRStatus PR_DestroyStack(PRStack *stack);
5477 typedef PRUint32 PRIntervalTime;
5478 extern __attribute__((visibility("default"))) PRIntervalTime PR_IntervalNow(void);
5479 extern __attribute__((visibility("default"))) PRUint32 PR_TicksPerSecond(void);
5480 extern __attribute__((visibility("default"))) PRIntervalTime PR_SecondsToInterval(PRUint32 seconds);
5481 extern __attribute__((visibility("default"))) PRIntervalTime PR_MillisecondsToInterval(PRUint32 milli);
5482 extern __attribute__((visibility("default"))) PRIntervalTime PR_MicrosecondsToInterval(PRUint32 micro);
5483 extern __attribute__((visibility("default"))) PRUint32 PR_IntervalToSeconds(PRIntervalTime ticks);
5484 extern __attribute__((visibility("default"))) PRUint32 PR_IntervalToMilliseconds(PRIntervalTime ticks);
5485 extern __attribute__((visibility("default"))) PRUint32 PR_IntervalToMicroseconds(PRIntervalTime ticks);
5488 typedef struct PRCondVar PRCondVar;
5489 extern __attribute__((visibility("default"))) PRCondVar* PR_NewCondVar(PRLock *lock);
5490 extern __attribute__((visibility("default"))) void PR_DestroyCondVar(PRCondVar *cvar);
5491 extern __attribute__((visibility("default"))) PRStatus PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout);
5492 extern __attribute__((visibility("default"))) PRStatus PR_NotifyCondVar(PRCondVar *cvar);
5493 extern __attribute__((visibility("default"))) PRStatus PR_NotifyAllCondVar(PRCondVar *cvar);
5496 typedef struct PRThread PRThread;
5497 typedef struct PRThreadStack PRThreadStack;
5498 typedef enum PRThreadType {
5502 typedef enum PRThreadScope {
5505 PR_GLOBAL_BOUND_THREAD
5507 typedef enum PRThreadState {
5509 PR_UNJOINABLE_THREAD
5511 typedef enum PRThreadPriority
5513 PR_PRIORITY_FIRST = 0,
5514 PR_PRIORITY_LOW = 0,
5515 PR_PRIORITY_NORMAL = 1,
5516 PR_PRIORITY_HIGH = 2,
5517 PR_PRIORITY_URGENT = 3,
5518 PR_PRIORITY_LAST = 3
5520 extern __attribute__((visibility("default"))) PRThread* PR_CreateThread(PRThreadType type,
5521 void ( *start)(void *arg),
5523 PRThreadPriority priority,
5524 PRThreadScope scope,
5525 PRThreadState state,
5526 PRUint32 stackSize);
5527 extern __attribute__((visibility("default"))) PRStatus PR_JoinThread(PRThread *thread);
5528 extern __attribute__((visibility("default"))) PRThread* PR_GetCurrentThread(void);
5529 extern __attribute__((visibility("default"))) PRThreadPriority PR_GetThreadPriority(const PRThread *thread);
5530 extern __attribute__((visibility("default"))) void PR_SetThreadPriority(PRThread *thread, PRThreadPriority priority);
5531 extern __attribute__((visibility("default"))) PRStatus PR_SetCurrentThreadName(const char *name);
5532 extern __attribute__((visibility("default"))) const char * PR_GetThreadName(const PRThread *thread);
5533 typedef void ( *PRThreadPrivateDTOR)(void *priv);
5534 extern __attribute__((visibility("default"))) PRStatus PR_NewThreadPrivateIndex(
5535 PRUintn *newIndex, PRThreadPrivateDTOR destructor);
5536 extern __attribute__((visibility("default"))) PRStatus PR_SetThreadPrivate(PRUintn tpdIndex, void *priv);
5537 extern __attribute__((visibility("default"))) void* PR_GetThreadPrivate(PRUintn tpdIndex);
5538 extern __attribute__((visibility("default"))) PRStatus PR_Interrupt(PRThread *thread);
5539 extern __attribute__((visibility("default"))) void PR_ClearInterrupt(void);
5540 extern __attribute__((visibility("default"))) void PR_BlockInterrupt(void);
5541 extern __attribute__((visibility("default"))) void PR_UnblockInterrupt(void);
5542 extern __attribute__((visibility("default"))) PRStatus PR_Sleep(PRIntervalTime ticks);
5543 extern __attribute__((visibility("default"))) PRThreadScope PR_GetThreadScope(const PRThread *thread);
5544 extern __attribute__((visibility("default"))) PRThreadType PR_GetThreadType(const PRThread *thread);
5545 extern __attribute__((visibility("default"))) PRThreadState PR_GetThreadState(const PRThread *thread);
5548 typedef struct JSFatLock JSFatLock;
5549 typedef struct JSThinLock {
5553 typedef PRLock JSLock;
5554 extern void js_Lock(JSContext *cx, JSThinLock *tl);
5555 extern void js_Unlock(JSContext *cx, JSThinLock *tl);
5556 extern void js_LockRuntime(JSRuntime *rt);
5557 extern void js_UnlockRuntime(JSRuntime *rt);
5558 extern int js_SetupLocks(int,int);
5559 extern void js_CleanupLocks();
5560 extern void js_InitLock(JSThinLock *);
5561 extern void js_FinishLock(JSThinLock *);
5563 js_CompareAndSwap(volatile jsword *w, jsword ov, jsword nv);
5565 js_AtomicSetMask(volatile jsword *w, jsword mask);
5567 js_AtomicClearMask(volatile jsword *w, jsword mask);
5574 AutoLock(JSLock *lock) : lock(lock) { PR_Lock(lock); }
5575 ~AutoLock() { PR_Unlock(lock); }
5579 JSDOUBLE_IS_NEGZERO(jsdouble d)
5581 return (d == 0 && (sizeof (d) == sizeof (float) ? __signbitf (d) : sizeof (d) == sizeof (double) ? __signbit (d) : __signbitl (d)));
5585 JSDOUBLE_IS_INT32(jsdouble d, int32_t* pi)
5587 if (JSDOUBLE_IS_NEGZERO(d))
5589 return d == (*pi = int32_t(d));
5591 static __attribute__((always_inline)) inline JSBool
5592 JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32 i32)
5594 return l.asBits == (((uint64)(uint32)i32) | JSVAL_SHIFTED_TAG_INT32);
5596 static __attribute__((always_inline)) inline JSBool
5597 JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, JSBool b)
5599 return l.asBits == (((uint64)(uint32)b) | JSVAL_SHIFTED_TAG_BOOLEAN);
5601 static __attribute__((always_inline)) inline jsval_layout
5602 MAGIC_TO_JSVAL_IMPL(JSWhyMagic why)
5605 l.asBits = ((uint64)(uint32)why) | JSVAL_SHIFTED_TAG_MAGIC;
5608 static __attribute__((always_inline)) inline jsval_layout
5609 MAGIC_TO_JSVAL_IMPL(JSObject *obj)
5612 l.asBits = ((uint64)obj) | JSVAL_SHIFTED_TAG_MAGIC;
5615 static __attribute__((always_inline)) inline JSBool
5616 JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs)
5618 uint64 lbits = lhs.asBits, rbits = rhs.asBits;
5619 return (lbits <= JSVAL_TAG_MAX_DOUBLE && rbits <= JSVAL_TAG_MAX_DOUBLE) ||
5620 (((lbits ^ rbits) & 0xFFFF800000000000LL) == 0);
5622 static __attribute__((always_inline)) inline jsval_layout
5623 PRIVATE_UINT32_TO_JSVAL_IMPL(uint32 ui)
5626 l.asBits = (uint64)ui;
5630 static __attribute__((always_inline)) inline uint32
5631 JSVAL_TO_PRIVATE_UINT32_IMPL(jsval_layout l)
5634 return (uint32)l.asBits;
5636 static __attribute__((always_inline)) inline JSValueType
5637 JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l)
5639 uint64 type = (l.asBits >> 47) & 0xF;
5641 return (JSValueType)type;
5643 static __attribute__((always_inline)) inline JSValueTag
5644 JSVAL_EXTRACT_NON_DOUBLE_TAG_IMPL(jsval_layout l)
5646 uint64 tag = l.asBits >> 47;
5648 return (JSValueTag)tag;
5650 typedef int js_static_assert3[(__builtin_offsetof (jsval_layout, s.payload) == 0) ? 1 : -1];
5651 typedef int js_static_assert4[((JSVAL_TYPE_NONFUNOBJ & 0xF) == JSVAL_TYPE_OBJECT) ? 1 : -1];
5652 typedef int js_static_assert5[((JSVAL_TYPE_FUNOBJ & 0xF) == JSVAL_TYPE_OBJECT) ? 1 : -1];
5653 static __attribute__((always_inline)) inline jsval_layout
5654 BOX_NON_DOUBLE_JSVAL(JSValueType type, uint64 *slot)
5658 uint32 isI32 = (uint32)(type < JSVAL_TYPE_MAGIC);
5659 uint32 shift = isI32 * 32;
5660 uint64 mask = ((uint64)-1) >> shift;
5661 uint64 payload = *slot & mask;
5664 l.asBits = payload | (((uint64)((JSValueTag)(JSVAL_TAG_MAX_DOUBLE | (type & 0xF)))) << 47);
5667 static __attribute__((always_inline)) inline void
5668 UNBOX_NON_DOUBLE_JSVAL(jsval_layout l, uint64 *out)
5671 *out = (l.asBits & 0x00007FFFFFFFFFFFLL);
5677 __attribute__((always_inline)) inline
5679 data.asBits = (((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)));
5681 __attribute__((always_inline)) inline
5682 void setUndefined() {
5683 data.asBits = (((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)));
5685 __attribute__((always_inline)) inline
5686 void setInt32(int32 i) {
5687 data = INT32_TO_JSVAL_IMPL(i);
5689 __attribute__((always_inline)) inline
5690 int32 &getInt32Ref() {
5692 return data.s.payload.i32;
5694 __attribute__((always_inline)) inline
5695 void setDouble(double d) {
5696 data = DOUBLE_TO_JSVAL_IMPL(d);
5698 __attribute__((always_inline)) inline
5699 double &getDoubleRef() {
5701 return data.asDouble;
5703 __attribute__((always_inline)) inline
5704 void setString(JSString *str) {
5705 data = STRING_TO_JSVAL_IMPL(str);
5707 __attribute__((always_inline)) inline
5708 void setObject(JSObject &obj) {
5709 data = OBJECT_TO_JSVAL_IMPL(&obj);
5711 __attribute__((always_inline)) inline
5712 void setBoolean(bool b) {
5713 data = BOOLEAN_TO_JSVAL_IMPL(b);
5715 __attribute__((always_inline)) inline
5716 void setMagic(JSWhyMagic why) {
5717 data = MAGIC_TO_JSVAL_IMPL(why);
5719 __attribute__((always_inline)) inline
5720 void setMagicWithObjectOrNullPayload(JSObject *obj) {
5721 data = MAGIC_TO_JSVAL_IMPL(obj);
5723 __attribute__((always_inline)) inline
5724 JSObject *getMagicObjectOrNullPayload() const {
5725 return MAGIC_JSVAL_TO_OBJECT_OR_NULL_IMPL(data);
5727 __attribute__((always_inline)) inline
5728 void setNumber(uint32 ui) {
5729 if (ui > ((jsint)0x7fffffff))
5730 setDouble((double)ui);
5732 setInt32((int32)ui);
5734 __attribute__((always_inline)) inline
5735 void setNumber(double d) {
5737 if (JSDOUBLE_IS_INT32(d, &i))
5742 __attribute__((always_inline)) inline
5743 void setObjectOrNull(JSObject *arg) {
5749 __attribute__((always_inline)) inline
5750 void setObjectOrUndefined(JSObject *arg) {
5756 __attribute__((always_inline)) inline
5757 void swap(Value &rhs) {
5758 uint64 tmp = rhs.data.asBits;
5759 rhs.data.asBits = data.asBits;
5762 __attribute__((always_inline)) inline
5763 bool isUndefined() const {
5764 return JSVAL_IS_UNDEFINED_IMPL(data);
5766 __attribute__((always_inline)) inline
5767 bool isNull() const {
5768 return JSVAL_IS_NULL_IMPL(data);
5770 __attribute__((always_inline)) inline
5771 bool isNullOrUndefined() const {
5772 return isNull() || isUndefined();
5774 __attribute__((always_inline)) inline
5775 bool isInt32() const {
5776 return JSVAL_IS_INT32_IMPL(data);
5778 __attribute__((always_inline)) inline
5779 bool isInt32(int32 i32) const {
5780 return JSVAL_IS_SPECIFIC_INT32_IMPL(data, i32);
5782 __attribute__((always_inline)) inline
5783 bool isDouble() const {
5784 return JSVAL_IS_DOUBLE_IMPL(data);
5786 __attribute__((always_inline)) inline
5787 bool isNumber() const {
5788 return JSVAL_IS_NUMBER_IMPL(data);
5790 __attribute__((always_inline)) inline
5791 bool isString() const {
5792 return JSVAL_IS_STRING_IMPL(data);
5794 __attribute__((always_inline)) inline
5795 bool isObject() const {
5796 return JSVAL_IS_OBJECT_IMPL(data);
5798 __attribute__((always_inline)) inline
5799 bool isPrimitive() const {
5800 return JSVAL_IS_PRIMITIVE_IMPL(data);
5802 __attribute__((always_inline)) inline
5803 bool isObjectOrNull() const {
5804 return JSVAL_IS_OBJECT_OR_NULL_IMPL(data);
5806 __attribute__((always_inline)) inline
5807 bool isGCThing() const {
5808 return JSVAL_IS_GCTHING_IMPL(data);
5810 __attribute__((always_inline)) inline
5811 bool isBoolean() const {
5812 return JSVAL_IS_BOOLEAN_IMPL(data);
5814 __attribute__((always_inline)) inline
5815 bool isTrue() const {
5816 return JSVAL_IS_SPECIFIC_BOOLEAN(data, true);
5818 __attribute__((always_inline)) inline
5819 bool isFalse() const {
5820 return JSVAL_IS_SPECIFIC_BOOLEAN(data, false);
5822 __attribute__((always_inline)) inline
5823 bool isMagic() const {
5824 return JSVAL_IS_MAGIC_IMPL(data);
5826 __attribute__((always_inline)) inline
5827 bool isMagic(JSWhyMagic why) const {
5829 return JSVAL_IS_MAGIC_IMPL(data);
5831 __attribute__((always_inline)) inline
5832 bool hasPtrPayload() const {
5833 return data.asBits >= JSVAL_SHIFTED_TAG_MAGIC;
5835 __attribute__((always_inline)) inline
5836 bool isMarkable() const {
5837 return JSVAL_IS_TRACEABLE_IMPL(data);
5839 __attribute__((always_inline)) inline
5840 int32 gcKind() const {
5842 return JSVAL_TRACE_KIND_IMPL(data);
5844 __attribute__((always_inline)) inline
5845 bool operator==(const Value &rhs) const {
5846 return data.asBits == rhs.data.asBits;
5848 __attribute__((always_inline)) inline
5849 bool operator!=(const Value &rhs) const {
5850 return data.asBits != rhs.data.asBits;
5852 friend bool SameType(const Value &lhs, const Value &rhs);
5853 __attribute__((always_inline)) inline
5854 int32 toInt32() const {
5856 return JSVAL_TO_INT32_IMPL(data);
5858 __attribute__((always_inline)) inline
5859 double toDouble() const {
5861 return data.asDouble;
5863 __attribute__((always_inline)) inline
5864 double toNumber() const {
5866 return isDouble() ? toDouble() : double(toInt32());
5868 __attribute__((always_inline)) inline
5869 JSString *toString() const {
5871 return JSVAL_TO_STRING_IMPL(data);
5873 __attribute__((always_inline)) inline
5874 JSObject &toObject() const {
5876 return *JSVAL_TO_OBJECT_IMPL(data);
5878 __attribute__((always_inline)) inline
5879 JSObject *toObjectOrNull() const {
5881 return JSVAL_TO_OBJECT_IMPL(data);
5883 __attribute__((always_inline)) inline
5884 void *toGCThing() const {
5886 return JSVAL_TO_GCTHING_IMPL(data);
5888 __attribute__((always_inline)) inline
5889 bool toBoolean() const {
5891 return JSVAL_TO_BOOLEAN_IMPL(data);
5893 __attribute__((always_inline)) inline
5894 uint32 payloadAsRawUint32() const {
5896 return data.s.payload.u32;
5898 __attribute__((always_inline)) inline
5899 uint64 asRawBits() const {
5902 __attribute__((always_inline)) inline
5903 JSValueType extractNonDoubleType() const {
5904 return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data);
5906 __attribute__((always_inline)) inline
5907 JSValueTag extractNonDoubleTag() const {
5908 return JSVAL_EXTRACT_NON_DOUBLE_TAG_IMPL(data);
5910 __attribute__((always_inline)) inline
5911 void unboxNonDoubleTo(uint64 *out) const {
5912 UNBOX_NON_DOUBLE_JSVAL(data, out);
5914 __attribute__((always_inline)) inline
5915 void boxNonDoubleFrom(JSValueType type, uint64 *out) {
5916 data = BOX_NON_DOUBLE_JSVAL(type, out);
5918 __attribute__((always_inline)) inline
5919 JSValueType extractNonDoubleObjectTraceType() const {
5921 return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data);
5923 __attribute__((always_inline)) inline
5924 JSValueTag extractNonDoubleObjectTraceTag() const {
5926 return JSVAL_EXTRACT_NON_DOUBLE_TAG_IMPL(data);
5928 __attribute__((always_inline)) inline
5929 void setPrivate(void *ptr) {
5930 data = PRIVATE_PTR_TO_JSVAL_IMPL(ptr);
5932 __attribute__((always_inline)) inline
5933 void *toPrivate() const {
5935 return JSVAL_TO_PRIVATE_PTR_IMPL(data);
5937 __attribute__((always_inline)) inline
5938 void setPrivateUint32(uint32 ui) {
5939 data = PRIVATE_UINT32_TO_JSVAL_IMPL(ui);
5941 __attribute__((always_inline)) inline
5942 uint32 toPrivateUint32() const {
5944 return JSVAL_TO_PRIVATE_UINT32_IMPL(data);
5946 __attribute__((always_inline)) inline
5947 uint32 &getPrivateUint32Ref() {
5949 return data.s.payload.u32;
5951 __attribute__((always_inline)) inline
5952 void setUnmarkedPtr(void *ptr) {
5955 __attribute__((always_inline)) inline
5956 void *toUnmarkedPtr() const {
5959 const jsuword *payloadWord() const {
5960 return &data.s.payload.word;
5963 void staticAssertions() {
5964 typedef int js_static_assert6[(sizeof(JSValueType) == 1) ? 1 : -1];
5965 typedef int js_static_assert7[(sizeof(JSValueTag) == 4) ? 1 : -1];
5966 typedef int js_static_assert8[(sizeof(JSBool) == 4) ? 1 : -1];
5967 typedef int js_static_assert9[(sizeof(JSWhyMagic) <= 4) ? 1 : -1];
5968 typedef int js_static_assert10[(sizeof(jsval) == 8) ? 1 : -1];
5971 } __attribute__((aligned (8)));
5972 __attribute__((always_inline)) inline
5974 SameType(const Value &lhs, const Value &rhs)
5976 return JSVAL_SAME_TYPE_IMPL(lhs.data, rhs.data);
5978 static __attribute__((always_inline)) inline Value
5985 static __attribute__((always_inline)) inline Value
5992 static __attribute__((always_inline)) inline Value
5993 Int32Value(int32 i32)
5999 static __attribute__((always_inline)) inline Value
6000 DoubleValue(double dbl)
6006 static __attribute__((always_inline)) inline Value
6007 StringValue(JSString *str)
6013 static __attribute__((always_inline)) inline Value
6014 BooleanValue(bool boo)
6020 static __attribute__((always_inline)) inline Value
6021 ObjectValue(JSObject &obj)
6027 static __attribute__((always_inline)) inline Value
6028 MagicValue(JSWhyMagic why)
6034 static __attribute__((always_inline)) inline Value
6035 NumberValue(double dbl)
6041 static __attribute__((always_inline)) inline Value
6042 ObjectOrNullValue(JSObject *obj)
6045 v.setObjectOrNull(obj);
6048 static __attribute__((always_inline)) inline Value
6049 PrivateValue(void *ptr)
6055 static __attribute__((always_inline)) inline void
6056 ClearValueRange(Value *vec, uintN len, bool useHoles)
6059 for (uintN i = 0; i < len; i++)
6060 vec[i].setMagic(JS_ARRAY_HOLE);
6062 for (uintN i = 0; i < len; i++)
6063 vec[i].setUndefined();
6066 static inline jsval * Jsvalify(Value *v) { return (jsval *)v; }
6067 static inline const jsval * Jsvalify(const Value *v) { return (const jsval *)v; }
6068 static inline jsval & Jsvalify(Value &v) { return (jsval &)v; }
6069 static inline const jsval & Jsvalify(const Value &v) { return (const jsval &)v; }
6070 static inline Value * Valueify(jsval *v) { return (Value *)v; }
6071 static inline const Value * Valueify(const jsval *v) { return (const Value *)v; }
6072 static inline Value ** Valueify(jsval **v) { return (Value **)v; }
6073 static inline Value & Valueify(jsval &v) { return (Value &)v; }
6074 static inline const Value & Valueify(const jsval &v) { return (const Value &)v; }
6077 (* Native)(JSContext *cx, uintN argc, Value *vp);
6079 (* PropertyOp)(JSContext *cx, JSObject *obj, jsid id, Value *vp);
6081 (* StrictPropertyOp)(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp);
6083 (* ConvertOp)(JSContext *cx, JSObject *obj, JSType type, Value *vp);
6085 (* NewEnumerateOp)(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
6086 Value *statep, jsid *idp);
6088 (* HasInstanceOp)(JSContext *cx, JSObject *obj, const Value *v, JSBool *bp);
6090 (* CheckAccessOp)(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
6093 (* EqualityOp)(JSContext *cx, JSObject *obj, const Value *v, JSBool *bp);
6095 (* DefinePropOp)(JSContext *cx, JSObject *obj, jsid id, const Value *value,
6096 PropertyOp getter, StrictPropertyOp setter, uintN attrs);
6098 (* PropertyIdOp)(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, Value *vp);
6100 (* StrictPropertyIdOp)(JSContext *cx, JSObject *obj, jsid id, Value *vp, JSBool strict);
6102 (* DeleteIdOp)(JSContext *cx, JSObject *obj, jsid id, Value *vp, JSBool strict);
6104 (* CallOp)(JSContext *cx, uintN argc, Value *vp);
6106 (* LookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
6107 JSProperty **propp);
6109 (* AttributesOp)(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
6111 (* TypeOfOp)(JSContext *cx, JSObject *obj);
6113 (* TraceOp)(JSTracer *trc, JSObject *obj);
6115 (* ObjectOp)(JSContext *cx, JSObject *obj);
6117 (* FinalizeOp)(JSContext *cx, JSObject *obj);
6120 (* FixOp)(JSContext *cx, JSObject *obj, bool *fixed, AutoIdVector *props);
6121 static inline Native Valueify(JSNative f) { return (Native)f; }
6122 static inline JSNative Jsvalify(Native f) { return (JSNative)f; }
6123 static inline PropertyOp Valueify(JSPropertyOp f) { return (PropertyOp)f; }
6124 static inline JSPropertyOp Jsvalify(PropertyOp f) { return (JSPropertyOp)f; }
6125 static inline StrictPropertyOp Valueify(JSStrictPropertyOp f) { return (StrictPropertyOp)f; }
6126 static inline JSStrictPropertyOp Jsvalify(StrictPropertyOp f) { return (JSStrictPropertyOp)f; }
6127 static inline ConvertOp Valueify(JSConvertOp f) { return (ConvertOp)f; }
6128 static inline JSConvertOp Jsvalify(ConvertOp f) { return (JSConvertOp)f; }
6129 static inline NewEnumerateOp Valueify(JSNewEnumerateOp f) { return (NewEnumerateOp)f; }
6130 static inline JSNewEnumerateOp Jsvalify(NewEnumerateOp f) { return (JSNewEnumerateOp)f; }
6131 static inline HasInstanceOp Valueify(JSHasInstanceOp f) { return (HasInstanceOp)f; }
6132 static inline JSHasInstanceOp Jsvalify(HasInstanceOp f) { return (JSHasInstanceOp)f; }
6133 static inline CheckAccessOp Valueify(JSCheckAccessOp f) { return (CheckAccessOp)f; }
6134 static inline JSCheckAccessOp Jsvalify(CheckAccessOp f) { return (JSCheckAccessOp)f; }
6135 static inline EqualityOp Valueify(JSEqualityOp f);
6136 static inline JSEqualityOp Jsvalify(EqualityOp f);
6137 static const PropertyOp PropertyStub = (PropertyOp)JS_PropertyStub;
6138 static const StrictPropertyOp StrictPropertyStub = (StrictPropertyOp)JS_StrictPropertyStub;
6139 static const JSEnumerateOp EnumerateStub = JS_EnumerateStub;
6140 static const JSResolveOp ResolveStub = JS_ResolveStub;
6141 static const ConvertOp ConvertStub = (ConvertOp)JS_ConvertStub;
6142 static const JSFinalizeOp FinalizeStub = JS_FinalizeStub;
6143 struct ClassSizeMeasurement {
6144 const char *name; uint32 flags; PropertyOp addProperty; PropertyOp delProperty; PropertyOp getProperty; StrictPropertyOp setProperty; JSEnumerateOp enumerate; JSResolveOp resolve; ConvertOp convert; JSFinalizeOp finalize; JSClassInternal reserved0; CheckAccessOp checkAccess; Native call; Native construct; JSXDRObjectOp xdrObject; HasInstanceOp hasInstance; JSMarkOp mark;
6146 struct ClassExtension {
6147 EqualityOp equality;
6148 JSObjectOp outerObject;
6149 JSObjectOp innerObject;
6150 JSIteratorOp iteratorObject;
6154 js::LookupPropOp lookupProperty;
6155 js::DefinePropOp defineProperty;
6156 js::PropertyIdOp getProperty;
6157 js::StrictPropertyIdOp setProperty;
6158 js::AttributesOp getAttributes;
6159 js::AttributesOp setAttributes;
6160 js::DeleteIdOp deleteProperty;
6161 js::NewEnumerateOp enumerate;
6162 js::TypeOfOp typeOf;
6165 js::ObjectOp thisObject;
6166 js::FinalizeOp clear;
6169 const char *name; uint32 flags; PropertyOp addProperty; PropertyOp delProperty; PropertyOp getProperty; StrictPropertyOp setProperty; JSEnumerateOp enumerate; JSResolveOp resolve; ConvertOp convert; JSFinalizeOp finalize; JSClassInternal reserved0; CheckAccessOp checkAccess; Native call; Native construct; JSXDRObjectOp xdrObject; HasInstanceOp hasInstance; JSMarkOp mark;
6172 uint8 pad[sizeof(JSClass) - sizeof(ClassSizeMeasurement) -
6173 sizeof(ClassExtension) - sizeof(ObjectOps)];
6174 static const uint32 NON_NATIVE = (1<<((8 + 8)+4));
6175 bool isNative() const {
6176 return !(flags & NON_NATIVE);
6179 typedef int js_static_assert11[(__builtin_offsetof (JSClass, name) == __builtin_offsetof (Class, name)) ? 1 : -1];
6180 typedef int js_static_assert12[(__builtin_offsetof (JSClass, flags) == __builtin_offsetof (Class, flags)) ? 1 : -1];
6181 typedef int js_static_assert13[(__builtin_offsetof (JSClass, addProperty) == __builtin_offsetof (Class, addProperty)) ? 1 : -1];
6182 typedef int js_static_assert14[(__builtin_offsetof (JSClass, delProperty) == __builtin_offsetof (Class, delProperty)) ? 1 : -1];
6183 typedef int js_static_assert15[(__builtin_offsetof (JSClass, getProperty) == __builtin_offsetof (Class, getProperty)) ? 1 : -1];
6184 typedef int js_static_assert16[(__builtin_offsetof (JSClass, setProperty) == __builtin_offsetof (Class, setProperty)) ? 1 : -1];
6185 typedef int js_static_assert17[(__builtin_offsetof (JSClass, enumerate) == __builtin_offsetof (Class, enumerate)) ? 1 : -1];
6186 typedef int js_static_assert18[(__builtin_offsetof (JSClass, resolve) == __builtin_offsetof (Class, resolve)) ? 1 : -1];
6187 typedef int js_static_assert19[(__builtin_offsetof (JSClass, convert) == __builtin_offsetof (Class, convert)) ? 1 : -1];
6188 typedef int js_static_assert20[(__builtin_offsetof (JSClass, finalize) == __builtin_offsetof (Class, finalize)) ? 1 : -1];
6189 typedef int js_static_assert21[(__builtin_offsetof (JSClass, reserved0) == __builtin_offsetof (Class, reserved0)) ? 1 : -1];
6190 typedef int js_static_assert22[(__builtin_offsetof (JSClass, checkAccess) == __builtin_offsetof (Class, checkAccess)) ? 1 : -1];
6191 typedef int js_static_assert23[(__builtin_offsetof (JSClass, call) == __builtin_offsetof (Class, call)) ? 1 : -1];
6192 typedef int js_static_assert24[(__builtin_offsetof (JSClass, construct) == __builtin_offsetof (Class, construct)) ? 1 : -1];
6193 typedef int js_static_assert25[(__builtin_offsetof (JSClass, xdrObject) == __builtin_offsetof (Class, xdrObject)) ? 1 : -1];
6194 typedef int js_static_assert26[(__builtin_offsetof (JSClass, hasInstance) == __builtin_offsetof (Class, hasInstance)) ? 1 : -1];
6195 typedef int js_static_assert27[(__builtin_offsetof (JSClass, mark) == __builtin_offsetof (Class, mark)) ? 1 : -1];
6196 typedef int js_static_assert28[(sizeof(JSClass) == sizeof(Class)) ? 1 : -1];
6197 struct PropertyDescriptor {
6201 StrictPropertyOp setter;
6205 typedef int js_static_assert29[(__builtin_offsetof (JSPropertyDescriptor, obj) == __builtin_offsetof (PropertyDescriptor, obj)) ? 1 : -1];
6206 typedef int js_static_assert30[(__builtin_offsetof (JSPropertyDescriptor, attrs) == __builtin_offsetof (PropertyDescriptor, attrs)) ? 1 : -1];
6207 typedef int js_static_assert31[(__builtin_offsetof (JSPropertyDescriptor, getter) == __builtin_offsetof (PropertyDescriptor, getter)) ? 1 : -1];
6208 typedef int js_static_assert32[(__builtin_offsetof (JSPropertyDescriptor, setter) == __builtin_offsetof (PropertyDescriptor, setter)) ? 1 : -1];
6209 typedef int js_static_assert33[(__builtin_offsetof (JSPropertyDescriptor, value) == __builtin_offsetof (PropertyDescriptor, value)) ? 1 : -1];
6210 typedef int js_static_assert34[(__builtin_offsetof (JSPropertyDescriptor, shortid) == __builtin_offsetof (PropertyDescriptor, shortid)) ? 1 : -1];
6211 typedef int js_static_assert35[(sizeof(JSPropertyDescriptor) == sizeof(PropertyDescriptor)) ? 1 : -1];
6212 static __attribute__((always_inline)) inline JSClass * Jsvalify(Class *c) { return (JSClass *)c; }
6213 static __attribute__((always_inline)) inline Class * Valueify(JSClass *c) { return (Class *)c; }
6214 static __attribute__((always_inline)) inline JSPropertyDescriptor * Jsvalify(PropertyDescriptor *p) { return (JSPropertyDescriptor *) p; }
6215 static __attribute__((always_inline)) inline PropertyDescriptor * Valueify(JSPropertyDescriptor *p) { return (PropertyDescriptor *) p; }
6216 typedef js::Value ValueArgType;
6217 static __attribute__((always_inline)) inline const Value &
6218 ValueArgToConstRef(const Value &v)
6222 static __attribute__((always_inline)) inline void
6223 MakeRangeGCSafe(Value *vec, size_t len)
6227 static __attribute__((always_inline)) inline void
6228 MakeRangeGCSafe(Value *beg, Value *end)
6230 PodZero(beg, end - beg);
6232 static __attribute__((always_inline)) inline void
6233 MakeRangeGCSafe(jsid *beg, jsid *end)
6235 for (jsid *id = beg; id != end; ++id)
6236 *id = INT_TO_JSID(0);
6238 static __attribute__((always_inline)) inline void
6239 MakeRangeGCSafe(jsid *vec, size_t len)
6241 MakeRangeGCSafe(vec, vec + len);
6243 static __attribute__((always_inline)) inline void
6244 MakeRangeGCSafe(const Shape **beg, const Shape **end)
6246 PodZero(beg, end - beg);
6248 static __attribute__((always_inline)) inline void
6249 MakeRangeGCSafe(const Shape **vec, size_t len)
6253 static __attribute__((always_inline)) inline void
6254 SetValueRangeToUndefined(Value *beg, Value *end)
6256 for (Value *v = beg; v != end; ++v)
6259 static __attribute__((always_inline)) inline void
6260 SetValueRangeToUndefined(Value *vec, size_t len)
6262 SetValueRangeToUndefined(vec, vec + len);
6264 static __attribute__((always_inline)) inline void
6265 SetValueRangeToNull(Value *beg, Value *end)
6267 for (Value *v = beg; v != end; ++v)
6270 static __attribute__((always_inline)) inline void
6271 SetValueRangeToNull(Value *vec, size_t len)
6273 SetValueRangeToNull(vec, vec + len);
6275 static __attribute__((always_inline)) inline void
6276 Debug_SetValueRangeToCrashOnTouch(Value *beg, Value *end)
6279 static __attribute__((always_inline)) inline void
6280 Debug_SetValueRangeToCrashOnTouch(Value *vec, size_t len)
6285 template <class T, size_t N, class AP, bool IsPod>
6288 static inline void destroy(T *begin, T *end) {
6289 for (T *p = begin; p != end; ++p)
6292 static inline void initialize(T *begin, T *end) {
6293 for (T *p = begin; p != end; ++p)
6297 static inline void copyConstruct(T *dst, const U *srcbeg, const U *srcend) {
6298 for (const U *p = srcbeg; p != srcend; ++p, ++dst)
6302 static inline void copyConstructN(T *dst, size_t n, const U &u) {
6303 for (T *end = dst + n; dst != end; ++dst)
6306 static inline bool growTo(Vector<T,N,AP> &v, size_t newcap) {
6308 T *newbuf = reinterpret_cast<T *>(v.malloc(newcap * sizeof(T)));
6311 for (T *dst = newbuf, *src = v.beginNoCheck(); src != v.endNoCheck(); ++dst, ++src)
6313 VectorImpl::destroy(v.beginNoCheck(), v.endNoCheck());
6316 v.mCapacity = newcap;
6320 template <class T, size_t N, class AP>
6321 struct VectorImpl<T, N, AP, true>
6323 static inline void destroy(T *, T *) {}
6324 static inline void initialize(T *begin, T *end) {
6325 for (T *p = begin; p != end; ++p)
6329 static inline void copyConstruct(T *dst, const U *srcbeg, const U *srcend) {
6330 for (const U *p = srcbeg; p != srcend; ++p, ++dst)
6333 static inline void copyConstructN(T *dst, size_t n, const T &t) {
6334 for (T *p = dst, *end = dst + n; p != end; ++p)
6337 static inline bool growTo(Vector<T,N,AP> &v, size_t newcap) {
6339 size_t bytes = sizeof(T) * newcap;
6340 T *newbuf = reinterpret_cast<T *>(v.realloc(v.mBegin, bytes));
6344 v.mCapacity = newcap;
6348 template <class T, size_t N, class AllocPolicy>
6349 class Vector : AllocPolicy
6351 static const bool sElemIsPod = tl::IsPodType<T>::result;
6352 typedef VectorImpl<T, N, AllocPolicy, sElemIsPod> Impl;
6353 friend struct VectorImpl<T, N, AllocPolicy, sElemIsPod>;
6354 bool calculateNewCapacity(size_t curLength, size_t lengthInc, size_t &newCap);
6355 bool growStorageBy(size_t lengthInc);
6356 bool growHeapStorageBy(size_t lengthInc);
6357 bool convertToHeapStorage(size_t lengthInc);
6358 template <bool InitNewElems> inline bool growByImpl(size_t inc);
6359 static const int sMaxInlineBytes = 1024;
6360 static const size_t sInlineCapacity =
6361 tl::Min<N, sMaxInlineBytes / sizeof(T)>::result;
6362 static const size_t sInlineBytes =
6363 tl::Max<1, sInlineCapacity * sizeof(T)>::result;
6367 AlignedStorage<sInlineBytes> storage;
6368 Vector(const Vector &);
6369 Vector &operator=(const Vector &);
6370 bool usingInlineStorage() const {
6371 return mBegin == (T *)storage.addr();
6373 T *beginNoCheck() const {
6377 return mBegin + mLength;
6379 const T *endNoCheck() const {
6380 return mBegin + mLength;
6383 typedef T ElementType;
6384 Vector(AllocPolicy = AllocPolicy());
6386 const AllocPolicy &allocPolicy() const {
6389 enum { InlineLength = N };
6390 size_t length() const {
6393 bool empty() const {
6394 return mLength == 0;
6396 size_t capacity() const {
6405 return mBegin + mLength;
6407 const T *end() const {
6409 return mBegin + mLength;
6411 T &operator[](size_t i) {
6415 const T &operator[](size_t i) const {
6421 return *(end() - 1);
6423 const T &back() const {
6425 return *(end() - 1);
6427 bool reserve(size_t capacity);
6428 void shrinkBy(size_t incr);
6429 bool growBy(size_t incr);
6430 bool resize(size_t newLength);
6431 bool growByUninitialized(size_t incr);
6432 bool resizeUninitialized(size_t newLength);
6434 bool append(const T &t);
6435 bool appendN(const T &t, size_t n);
6436 template <class U> bool append(const U *begin, const U *end);
6437 template <class U> bool append(const U *begin, size_t length);
6438 template <class U, size_t O, class BP> bool append(const Vector<U,O,BP> &other);
6441 T *extractRawBuffer();
6442 void replaceRawBuffer(T *p, size_t length);
6443 bool insert(T *p, const T &val);
6446 template <class T, size_t N, class AllocPolicy>
6447 __attribute__((always_inline)) inline
6448 Vector<T,N,AllocPolicy>::Vector(AllocPolicy ap)
6449 : AllocPolicy(ap), mBegin((T *)storage.addr()), mLength(0),
6450 mCapacity(sInlineCapacity)
6452 template <class T, size_t N, class AP>
6453 __attribute__((always_inline)) inline
6454 Vector<T,N,AP>::~Vector()
6456 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6457 Impl::destroy(beginNoCheck(), endNoCheck());
6458 if (!usingInlineStorage())
6459 this->free(beginNoCheck());
6461 template <class T, size_t N, class AP>
6464 Vector<T,N,AP>::calculateNewCapacity(size_t curLength, size_t lengthInc,
6467 size_t newMinCap = curLength + lengthInc;
6468 if (newMinCap < curLength ||
6469 newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::result) {
6470 this->reportAllocOverflow();
6473 newCap = RoundUpPow2(newMinCap);
6474 if (newCap & tl::UnsafeRangeSizeMask<T>::result) {
6475 this->reportAllocOverflow();
6480 template <class T, size_t N, class AP>
6481 __attribute__((always_inline)) inline
6483 Vector<T,N,AP>::growHeapStorageBy(size_t lengthInc)
6487 return calculateNewCapacity(mLength, lengthInc, newCap) &&
6488 Impl::growTo(*this, newCap);
6490 template <class T, size_t N, class AP>
6493 Vector<T,N,AP>::convertToHeapStorage(size_t lengthInc)
6497 if (!calculateNewCapacity(mLength, lengthInc, newCap))
6499 T *newBuf = reinterpret_cast<T *>(this->malloc(newCap * sizeof(T)));
6502 Impl::copyConstruct(newBuf, beginNoCheck(), endNoCheck());
6503 Impl::destroy(beginNoCheck(), endNoCheck());
6508 template <class T, size_t N, class AP>
6509 __attribute__((noinline))
6511 Vector<T,N,AP>::growStorageBy(size_t incr)
6514 return usingInlineStorage()
6515 ? convertToHeapStorage(incr)
6516 : growHeapStorageBy(incr);
6518 template <class T, size_t N, class AP>
6521 Vector<T,N,AP>::reserve(size_t request)
6523 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6524 if (request > mCapacity)
6525 return growStorageBy(request - mLength);
6528 template <class T, size_t N, class AP>
6530 Vector<T,N,AP>::shrinkBy(size_t incr)
6532 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6534 Impl::destroy(endNoCheck() - incr, endNoCheck());
6537 template <class T, size_t N, class AP>
6538 template <bool InitNewElems>
6539 __attribute__((always_inline)) inline
6541 Vector<T,N,AP>::growByImpl(size_t incr)
6543 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6544 if (incr > mCapacity - mLength && !growStorageBy(incr))
6547 T *newend = endNoCheck() + incr;
6549 Impl::initialize(endNoCheck(), newend);
6553 template <class T, size_t N, class AP>
6554 __attribute__((always_inline)) inline
6556 Vector<T,N,AP>::growBy(size_t incr)
6558 return growByImpl<true>(incr);
6560 template <class T, size_t N, class AP>
6561 __attribute__((always_inline)) inline
6563 Vector<T,N,AP>::growByUninitialized(size_t incr)
6565 return growByImpl<false>(incr);
6567 template <class T, size_t N, class AP>
6570 Vector<T,N,AP>::resize(size_t newLength)
6572 size_t curLength = mLength;
6573 if (newLength > curLength)
6574 return growBy(newLength - curLength);
6575 shrinkBy(curLength - newLength);
6578 template <class T, size_t N, class AP>
6579 __attribute__((always_inline)) inline
6581 Vector<T,N,AP>::resizeUninitialized(size_t newLength)
6583 size_t curLength = mLength;
6584 if (newLength > curLength)
6585 return growByUninitialized(newLength - curLength);
6586 shrinkBy(curLength - newLength);
6589 template <class T, size_t N, class AP>
6591 Vector<T,N,AP>::clear()
6593 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6594 Impl::destroy(beginNoCheck(), endNoCheck());
6597 template <class T, size_t N, class AP>
6598 __attribute__((always_inline)) inline
6600 Vector<T,N,AP>::append(const T &t)
6602 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6603 if (mLength == mCapacity && !growStorageBy(1))
6606 new(endNoCheck()) T(t);
6610 template <class T, size_t N, class AP>
6611 __attribute__((always_inline)) inline
6613 Vector<T,N,AP>::appendN(const T &t, size_t needed)
6615 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6616 if (mLength + needed > mCapacity && !growStorageBy(needed))
6619 Impl::copyConstructN(endNoCheck(), needed, t);
6623 template <class T, size_t N, class AP>
6626 Vector<T,N,AP>::insert(T *p, const T &val)
6629 size_t pos = p - begin();
6631 size_t oldLength = mLength;
6632 if (pos == oldLength)
6636 if (!append(oldBack))
6639 for (size_t i = oldLength; i > pos; --i)
6640 (*this)[i] = (*this)[i - 1];
6644 template<typename T, size_t N, class AP>
6646 Vector<T,N,AP>::erase(T *it)
6649 while (it + 1 != end()) {
6655 template <class T, size_t N, class AP>
6657 __attribute__((always_inline)) inline
6659 Vector<T,N,AP>::append(const U *insBegin, const U *insEnd)
6661 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6662 size_t needed = PointerRangeSize(insBegin, insEnd);
6663 if (mLength + needed > mCapacity && !growStorageBy(needed))
6666 Impl::copyConstruct(endNoCheck(), insBegin, insEnd);
6670 template <class T, size_t N, class AP>
6671 template <class U, size_t O, class BP>
6674 Vector<T,N,AP>::append(const Vector<U,O,BP> &other)
6676 return append(other.begin(), other.end());
6678 template <class T, size_t N, class AP>
6680 __attribute__((always_inline)) inline
6682 Vector<T,N,AP>::append(const U *insBegin, size_t length)
6684 return this->append(insBegin, insBegin + length);
6686 template <class T, size_t N, class AP>
6687 __attribute__((always_inline)) inline void
6688 Vector<T,N,AP>::popBack()
6690 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6695 template <class T, size_t N, class AP>
6696 __attribute__((always_inline)) inline T
6697 Vector<T,N,AP>::popCopy()
6703 template <class T, size_t N, class AP>
6705 Vector<T,N,AP>::extractRawBuffer()
6708 if (usingInlineStorage()) {
6709 ret = reinterpret_cast<T *>(this->malloc(mLength * sizeof(T)));
6712 Impl::copyConstruct(ret, beginNoCheck(), endNoCheck());
6713 Impl::destroy(beginNoCheck(), endNoCheck());
6717 mBegin = (T *)storage.addr();
6719 mCapacity = sInlineCapacity;
6723 template <class T, size_t N, class AP>
6725 Vector<T,N,AP>::replaceRawBuffer(T *p, size_t length)
6727 ReentrancyGuard g(*this); ((void) 0); ((void) 0);
6728 Impl::destroy(beginNoCheck(), endNoCheck());
6729 if (!usingInlineStorage())
6730 this->free(beginNoCheck());
6731 if (length <= sInlineCapacity) {
6732 mBegin = (T *)storage.addr();
6734 mCapacity = sInlineCapacity;
6735 Impl::copyConstruct(mBegin, p, p + length);
6736 Impl::destroy(p, p + length);
6745 struct JSCompartment;
6748 template <typename T> struct Arena;
6750 struct MarkingDelay;
6754 static const size_t CellShift = 3;
6755 static const size_t CellSize = size_t(1) << CellShift;
6756 static const size_t CellMask = CellSize - 1;
6757 inline Arena<Cell> *arena() const;
6758 inline Chunk *chunk() const;
6759 inline ArenaBitmap *bitmap() const;
6760 __attribute__((always_inline)) inline size_t cellIndex() const;
6761 __attribute__((always_inline)) inline bool isMarked(uint32 color) const;
6762 __attribute__((always_inline)) inline bool markIfUnmarked(uint32 color) const;
6763 __attribute__((always_inline)) inline void unmark(uint32 color) const;
6764 inline JSCompartment *compartment() const;
6765 __attribute__((always_inline)) inline js::gc::Cell *asCell() { return this; }
6766 __attribute__((always_inline)) inline js::gc::FreeCell *asFreeCell() {
6767 return reinterpret_cast<FreeCell *>(this);
6770 struct FreeCell : Cell {
6776 typedef int js_static_assert36[(sizeof(FreeCell) == 8) ? 1 : -1];
6780 class JSProxyHandler;
6781 class AutoPropDescArrayRooter;
6785 static inline PropertyOp
6786 CastAsPropertyOp(JSObject *object)
6788 return (__extension__ (PropertyOp) (size_t) (object));
6790 static inline StrictPropertyOp
6791 CastAsStrictPropertyOp(JSObject *object)
6793 return (__extension__ (StrictPropertyOp) (size_t) (object));
6795 static inline JSPropertyOp
6796 CastAsJSPropertyOp(JSObject *object)
6798 return (__extension__ (JSPropertyOp) (size_t) (object));
6800 static inline JSStrictPropertyOp
6801 CastAsJSStrictPropertyOp(JSObject *object)
6803 return (__extension__ (JSStrictPropertyOp) (size_t) (object));
6806 CastAsObject(PropertyOp op)
6808 return (__extension__ (JSObject *) (size_t) (op));
6811 CastAsObject(StrictPropertyOp op)
6813 return (__extension__ (JSObject *) (size_t) (op));
6816 CastAsObjectJsval(PropertyOp op)
6818 return ObjectOrNullValue(CastAsObject(op));
6821 CastAsObjectJsval(StrictPropertyOp op)
6823 return ObjectOrNullValue(CastAsObject(op));
6827 friend class js::AutoPropDescArrayRooter;
6830 bool initialize(JSContext* cx, jsid id, const js::Value &v);
6831 bool isAccessorDescriptor() const {
6832 return hasGet || hasSet;
6834 bool isDataDescriptor() const {
6835 return hasValue || hasWritable;
6837 bool isGenericDescriptor() const {
6838 return !isAccessorDescriptor() && !isDataDescriptor();
6840 bool configurable() const {
6841 return (attrs & 0x04) == 0;
6843 bool enumerable() const {
6844 return (attrs & 0x01) != 0;
6846 bool writable() const {
6847 return (attrs & 0x02) == 0;
6849 JSObject* getterObject() const {
6850 return get.isUndefined() ? __null : &get.toObject();
6852 JSObject* setterObject() const {
6853 return set.isUndefined() ? __null : &set.toObject();
6855 const js::Value &getterValue() const {
6858 const js::Value &setterValue() const {
6861 js::PropertyOp getter() const {
6862 return js::CastAsPropertyOp(getterObject());
6864 js::StrictPropertyOp setter() const {
6865 return js::CastAsStrictPropertyOp(setterObject());
6869 js::Value value, get, set;
6874 bool hasWritable : 1;
6875 bool hasEnumerable : 1;
6876 bool hasConfigurable : 1;
6879 typedef Vector<PropDesc, 1> PropDescArray;
6881 struct JSObjectMap {
6884 static __attribute__((visibility ("default"))) const JSObjectMap sharedNonNative;
6885 explicit JSObjectMap(uint32 shape) : shape(shape), slotSpan(0) {}
6886 JSObjectMap(uint32 shape, uint32 slotSpan) : shape(shape), slotSpan(slotSpan) {}
6887 enum { INVALID_SHAPE = 0x8fffffff, SHAPELESS = 0xffffffff };
6888 bool isNative() const { return this != &sharedNonNative; }
6890 JSObjectMap(JSObjectMap &);
6891 void operator=(JSObjectMap &);
6893 extern __attribute__((visibility ("default"))) JSBool
6894 js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
6895 JSProperty **propp);
6897 js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, const js::Value *value,
6898 js::PropertyOp getter, js::StrictPropertyOp setter, uintN attrs);
6900 js_GetProperty(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, js::Value *vp);
6902 js_GetProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *vp)
6904 return js_GetProperty(cx, obj, obj, id, vp);
6908 GetPropertyDefault(JSContext *cx, JSObject *obj, jsid id, const Value &def, Value *vp);
6911 js_SetProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *vp, JSBool strict);
6913 js_GetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
6915 js_SetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
6917 js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *rval, JSBool strict);
6918 extern __attribute__((visibility ("default"))) JSBool
6919 js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
6920 js::Value *statep, jsid *idp);
6922 js_TypeOf(JSContext *cx, JSObject *obj);
6924 struct NativeIterator;
6928 class ValidateWriter;
6930 struct JSObject : js::gc::Cell {
6931 friend class js::TraceRecorder;
6932 friend class nanojit::ValidateWriter;
6933 friend class GetPropCompiler;
6935 js::Shape *lastProp;
6940 inline void setLastProperty(const js::Shape *shape);
6941 inline void removeLastProperty();
6943 inline const js::Shape *lastProperty() const;
6944 inline js::Shape **nativeSearch(jsid id, bool adding = false);
6945 inline const js::Shape *nativeLookup(jsid id);
6946 inline bool nativeContains(jsid id);
6947 inline bool nativeContains(const js::Shape &shape);
6951 NOT_EXTENSIBLE = 0x04,
6954 METHOD_BARRIER = 0x20,
6957 BOUND_FUNCTION = 0x100,
6958 HAS_EQUALITY = 0x200,
6959 METHOD_THRASH_COUNT_MASK = 0xc00,
6960 METHOD_THRASH_COUNT_SHIFT = 10,
6961 METHOD_THRASH_COUNT_MAX = METHOD_THRASH_COUNT_MASK >> METHOD_THRASH_COUNT_SHIFT
6965 NSLOTS_LIMIT = ((JSUint32)1 << (NSLOTS_BITS))
6969 js::EmptyShape **emptyShapes;
6975 inline bool canProvideEmptyShape(js::Class *clasp);
6976 inline js::EmptyShape *getEmptyShape(JSContext *cx, js::Class *aclasp,
6978 bool isNative() const { return map->isNative(); }
6979 js::Class *getClass() const { return clasp; }
6980 JSClass *getJSClass() const { return Jsvalify(clasp); }
6981 bool hasClass(const js::Class *c) const {
6984 const js::ObjectOps *getOps() const {
6985 return &getClass()->ops;
6987 inline void trace(JSTracer *trc);
6988 uint32 shape() const {
6992 bool isDelegate() const { return !!(flags & DELEGATE); }
6993 void setDelegate() { flags |= DELEGATE; }
6994 void clearDelegate() { flags &= ~DELEGATE; }
6995 bool isBoundFunction() const { return !!(flags & BOUND_FUNCTION); }
6996 static void setDelegateNullSafe(JSObject *obj) {
7000 bool isSystem() const { return !!(flags & SYSTEM); }
7001 void setSystem() { flags |= SYSTEM; }
7002 bool branded() { return !!(flags & BRANDED); }
7003 bool brand(JSContext *cx);
7004 bool unbrand(JSContext *cx);
7005 bool generic() { return !!(flags & GENERIC); }
7006 void setGeneric() { flags |= GENERIC; }
7007 uintN getMethodThrashCount() const {
7008 return (flags & METHOD_THRASH_COUNT_MASK) >> METHOD_THRASH_COUNT_SHIFT;
7010 void setMethodThrashCount(uintN count) {
7012 flags = (flags & ~METHOD_THRASH_COUNT_MASK) | (count << METHOD_THRASH_COUNT_SHIFT);
7014 bool hasSpecialEquality() const { return !!(flags & HAS_EQUALITY); }
7015 void assertSpecialEqualitySynced() const {
7018 inline void syncSpecialEquality();
7020 void generateOwnShape(JSContext *cx);
7021 void setOwnShape(uint32 s) { flags |= OWN_SHAPE; objShape = s; }
7022 void clearOwnShape() { flags &= ~OWN_SHAPE; objShape = map->shape; }
7024 inline bool nativeEmpty() const;
7025 bool hasOwnShape() const { return !!(flags & OWN_SHAPE); }
7026 void setMap(const JSObjectMap *amap) {
7028 map = const_cast<JSObjectMap *>(amap);
7029 objShape = map->shape;
7031 void setSharedNonNativeMap() {
7032 setMap(&JSObjectMap::sharedNonNative);
7034 void deletingShapeChange(JSContext *cx, const js::Shape &shape);
7035 const js::Shape *methodShapeChange(JSContext *cx, const js::Shape &shape);
7036 bool methodShapeChange(JSContext *cx, uint32 slot);
7037 void protoShapeChange(JSContext *cx);
7038 void shadowingShapeChange(JSContext *cx, const js::Shape &shape);
7039 bool globalObjectOwnShapeChange(JSContext *cx);
7040 void watchpointOwnShapeChange(JSContext *cx) { generateOwnShape(cx); }
7041 void extensibleShapeChange(JSContext *cx) {
7042 generateOwnShape(cx);
7044 bool hasMethodBarrier() { return !!(flags & METHOD_BARRIER); }
7045 void setMethodBarrier() { flags |= METHOD_BARRIER; }
7046 bool brandedOrHasMethodBarrier() { return !!(flags & (BRANDED | METHOD_BARRIER)); }
7047 const js::Shape *methodReadBarrier(JSContext *cx, const js::Shape &shape, js::Value *vp);
7048 const js::Shape *methodWriteBarrier(JSContext *cx, const js::Shape &shape, const js::Value &v);
7049 bool methodWriteBarrier(JSContext *cx, uint32 slot, const js::Value &v);
7050 bool isIndexed() const { return !!(flags & INDEXED); }
7051 void setIndexed() { flags |= INDEXED; }
7052 inline bool inDictionaryMode() const;
7053 inline uint32 propertyCount() const;
7054 inline bool hasPropertyTable() const;
7055 unsigned finalizeKind() const;
7056 uint32 numSlots() const { return capacity; }
7057 size_t slotsAndStructSize(uint32 nslots) const;
7058 size_t slotsAndStructSize() const { return slotsAndStructSize(numSlots()); }
7059 inline js::Value* fixedSlots() const;
7060 inline size_t numFixedSlots() const;
7061 static inline size_t getFixedSlotOffset(size_t slot);
7063 static const uint32 SLOT_CAPACITY_MIN = 8;
7064 bool allocSlots(JSContext *cx, size_t nslots);
7065 bool growSlots(JSContext *cx, size_t nslots);
7066 void shrinkSlots(JSContext *cx, size_t nslots);
7067 bool ensureSlots(JSContext *cx, size_t nslots) {
7068 if (numSlots() < nslots)
7069 return growSlots(cx, nslots);
7072 bool ensureInstanceReservedSlots(JSContext *cx, size_t nreserved);
7073 js::Value *getSlots() const {
7076 bool ensureClassReservedSlotsForEmptyObject(JSContext *cx);
7077 inline bool ensureClassReservedSlots(JSContext *cx);
7078 uint32 slotSpan() const { return map->slotSpan; }
7079 bool containsSlot(uint32 slot) const { return slot < slotSpan(); }
7080 js::Value& getSlotRef(uintN slot) {
7084 js::Value &nativeGetSlotRef(uintN slot) {
7087 return getSlotRef(slot);
7089 const js::Value &getSlot(uintN slot) const {
7093 const js::Value &nativeGetSlot(uintN slot) const {
7096 return getSlot(slot);
7098 void setSlot(uintN slot, const js::Value &value) {
7100 slots[slot] = value;
7102 void nativeSetSlot(uintN slot, const js::Value &value) {
7105 return setSlot(slot, value);
7107 inline js::Value getReservedSlot(uintN index) const;
7108 inline void updateShape(JSContext *cx);
7109 inline void updateFlags(const js::Shape *shape, bool isDefinitelyAtom = false);
7110 inline void extend(JSContext *cx, const js::Shape *shape, bool isDefinitelyAtom = false);
7111 JSObject *getProto() const { return proto; }
7112 void clearProto() { proto = __null; }
7113 void setProto(JSObject *newProto) {
7114 setDelegateNullSafe(newProto);
7117 JSObject *getParent() const {
7120 void clearParent() {
7123 void setParent(JSObject *newParent) {
7124 setDelegateNullSafe(newParent);
7127 __attribute__((visibility ("default"))) JSObject * getGlobal() const;
7128 bool isGlobal() const {
7129 return !!(getClass()->flags & (1<<((8 + 8)+2)));
7131 void *getPrivate() const {
7135 void setPrivate(void *data) {
7140 enum ImmutabilityType { SEAL, FREEZE };
7141 bool sealOrFreeze(JSContext *cx, ImmutabilityType it);
7143 bool isExtensible() const { return !(flags & NOT_EXTENSIBLE); }
7144 bool preventExtensions(JSContext *cx, js::AutoIdVector *props);
7145 inline bool seal(JSContext *cx) { return sealOrFreeze(cx, SEAL); }
7146 bool freeze(JSContext *cx) { return sealOrFreeze(cx, FREEZE); }
7148 static const uint32 JSSLOT_PRIMITIVE_THIS = 0;
7150 inline const js::Value &getPrimitiveThis() const;
7151 inline void setPrimitiveThis(const js::Value &pthis);
7152 inline uint32 getArrayLength() const;
7153 inline void setArrayLength(uint32 length);
7154 inline uint32 getDenseArrayCapacity();
7155 inline js::Value* getDenseArrayElements();
7156 inline const js::Value &getDenseArrayElement(uintN idx);
7157 inline js::Value* addressOfDenseArrayElement(uintN idx);
7158 inline void setDenseArrayElement(uintN idx, const js::Value &val);
7159 inline void shrinkDenseArrayElements(JSContext *cx, uintN cap);
7160 enum EnsureDenseResult { ED_OK, ED_FAILED, ED_SPARSE };
7161 inline EnsureDenseResult ensureDenseArrayElements(JSContext *cx, uintN index, uintN extra);
7162 bool willBeSparseDenseArray(uintN requiredCapacity, uintN newElementsHint);
7163 JSBool makeDenseArraySlow(JSContext *cx);
7165 static const uint32 JSSLOT_ARGS_DATA = 1;
7167 static const uint32 JSSLOT_ARGS_LENGTH = 0;
7168 static const uint32 ARGS_CLASS_RESERVED_SLOTS = 2;
7169 static const uint32 ARGS_FIRST_FREE_SLOT = ARGS_CLASS_RESERVED_SLOTS + 1;
7170 static const uint32 ARGS_LENGTH_OVERRIDDEN_BIT = 0x1;
7171 static const uint32 ARGS_PACKED_BITS_COUNT = 1;
7172 inline void setArgsLength(uint32 argc);
7173 inline uint32 getArgsInitialLength() const;
7174 inline void setArgsLengthOverridden();
7175 inline bool isArgsLengthOverridden() const;
7176 inline js::ArgumentsData *getArgsData() const;
7177 inline void setArgsData(js::ArgumentsData *data);
7178 inline const js::Value &getArgsCallee() const;
7179 inline void setArgsCallee(const js::Value &callee);
7180 inline const js::Value &getArgsElement(uint32 i) const;
7181 inline js::Value *getArgsElements() const;
7182 inline js::Value *addressOfArgsElement(uint32 i);
7183 inline void setArgsElement(uint32 i, const js::Value &v);
7185 static const uint32 JSSLOT_CALL_CALLEE = 0;
7186 static const uint32 JSSLOT_CALL_ARGUMENTS = 1;
7188 static const uint32 CALL_RESERVED_SLOTS = 2;
7189 inline bool callIsForEval() const;
7190 inline JSStackFrame *maybeCallObjStackFrame() const;
7191 inline JSObject *getCallObjCallee() const;
7192 inline JSFunction *getCallObjCalleeFunction() const;
7193 inline void setCallObjCallee(JSObject *callee);
7194 inline const js::Value &getCallObjArguments() const;
7195 inline void setCallObjArguments(const js::Value &v);
7196 inline const js::Value &callObjArg(uintN i) const;
7197 inline js::Value &callObjArg(uintN i);
7198 inline const js::Value &callObjVar(uintN i) const;
7199 inline js::Value &callObjVar(uintN i);
7200 static const uint32 JSSLOT_DATE_UTC_TIME = 0;
7201 static const uint32 JSSLOT_DATE_COMPONENTS_START = 1;
7202 static const uint32 JSSLOT_DATE_LOCAL_TIME = 1;
7203 static const uint32 JSSLOT_DATE_LOCAL_YEAR = 2;
7204 static const uint32 JSSLOT_DATE_LOCAL_MONTH = 3;
7205 static const uint32 JSSLOT_DATE_LOCAL_DATE = 4;
7206 static const uint32 JSSLOT_DATE_LOCAL_DAY = 5;
7207 static const uint32 JSSLOT_DATE_LOCAL_HOURS = 6;
7208 static const uint32 JSSLOT_DATE_LOCAL_MINUTES = 7;
7209 static const uint32 JSSLOT_DATE_LOCAL_SECONDS = 8;
7210 static const uint32 DATE_CLASS_RESERVED_SLOTS = 9;
7211 inline const js::Value &getDateUTCTime() const;
7212 inline void setDateUTCTime(const js::Value &pthis);
7214 friend struct JSFunction;
7215 friend class js::mjit::Compiler;
7216 static const uint32 JSSLOT_FLAT_CLOSURE_UPVARS = 0;
7217 static const uint32 JSSLOT_FUN_METHOD_ATOM = 0;
7218 static const uint32 JSSLOT_FUN_METHOD_OBJ = 1;
7219 static const uint32 JSSLOT_BOUND_FUNCTION_THIS = 0;
7220 static const uint32 JSSLOT_BOUND_FUNCTION_ARGS_COUNT = 1;
7222 static const uint32 FUN_CLASS_RESERVED_SLOTS = 2;
7223 inline JSFunction *getFunctionPrivate() const;
7224 inline js::Value *getFlatClosureUpvars() const;
7225 inline js::Value getFlatClosureUpvar(uint32 i) const;
7226 inline js::Value &getFlatClosureUpvar(uint32 i);
7227 inline void setFlatClosureUpvars(js::Value *upvars);
7228 inline bool hasMethodObj(const JSObject& obj) const;
7229 inline void setMethodObj(JSObject& obj);
7230 inline bool initBoundFunction(JSContext *cx, const js::Value &thisArg,
7231 const js::Value *args, uintN argslen);
7232 inline JSObject *getBoundFunctionTarget() const;
7233 inline const js::Value &getBoundFunctionThis() const;
7234 inline const js::Value *getBoundFunctionArguments(uintN &argslen) const;
7236 static const uint32 JSSLOT_REGEXP_LAST_INDEX = 0;
7238 static const uint32 REGEXP_CLASS_RESERVED_SLOTS = 1;
7239 inline const js::Value &getRegExpLastIndex() const;
7240 inline void setRegExpLastIndex(const js::Value &v);
7241 inline void setRegExpLastIndex(jsdouble d);
7242 inline void zeroRegExpLastIndex();
7243 inline js::NativeIterator *getNativeIterator() const;
7244 inline void setNativeIterator(js::NativeIterator *);
7245 inline JSScript *getScript() const;
7247 static const uint32 JSSLOT_NAME_PREFIX = 0;
7248 static const uint32 JSSLOT_NAME_URI = 1;
7249 static const uint32 JSSLOT_NAMESPACE_DECLARED = 2;
7250 static const uint32 JSSLOT_QNAME_LOCAL_NAME = 2;
7252 static const uint32 NAMESPACE_CLASS_RESERVED_SLOTS = 3;
7253 static const uint32 QNAME_CLASS_RESERVED_SLOTS = 3;
7254 inline JSLinearString *getNamePrefix() const;
7255 inline jsval getNamePrefixVal() const;
7256 inline void setNamePrefix(JSLinearString *prefix);
7257 inline void clearNamePrefix();
7258 inline JSLinearString *getNameURI() const;
7259 inline jsval getNameURIVal() const;
7260 inline void setNameURI(JSLinearString *uri);
7261 inline jsval getNamespaceDeclared() const;
7262 inline void setNamespaceDeclared(jsval decl);
7263 inline JSLinearString *getQNameLocalName() const;
7264 inline jsval getQNameLocalNameVal() const;
7265 inline void setQNameLocalName(JSLinearString *name);
7266 inline js::JSProxyHandler *getProxyHandler() const;
7267 inline const js::Value &getProxyPrivate() const;
7268 inline void setProxyPrivate(const js::Value &priv);
7269 inline const js::Value &getProxyExtra() const;
7270 inline void setProxyExtra(const js::Value &extra);
7271 inline JSObject *getWithThis() const;
7272 inline void setWithThis(JSObject *thisp);
7273 inline bool isCallable();
7274 void init(JSContext *cx, js::Class *aclasp, JSObject *proto, JSObject *parent,
7275 void *priv, bool useHoles);
7276 inline void finish(JSContext *cx);
7277 __attribute__((always_inline)) inline void finalize(JSContext *cx);
7278 inline bool initSharingEmptyShape(JSContext *cx,
7284 inline bool hasSlotsArray() const;
7285 inline void freeSlotsArray(JSContext *cx);
7286 inline void revertToFixedSlots(JSContext *cx);
7287 inline bool hasProperty(JSContext *cx, jsid id, bool *foundp, uintN flags = 0);
7288 bool allocSlot(JSContext *cx, uint32 *slotp);
7289 bool freeSlot(JSContext *cx, uint32 slot);
7291 bool reportReadOnly(JSContext* cx, jsid id, uintN report = 0x0);
7292 bool reportNotConfigurable(JSContext* cx, jsid id, uintN report = 0x0);
7293 bool reportNotExtensible(JSContext *cx, uintN report = 0x0);
7295 js::Shape *getChildProperty(JSContext *cx, js::Shape *parent, js::Shape &child);
7296 const js::Shape *addPropertyInternal(JSContext *cx, jsid id,
7297 js::PropertyOp getter, js::StrictPropertyOp setter,
7298 uint32 slot, uintN attrs,
7299 uintN flags, intN shortid,
7301 bool toDictionaryMode(JSContext *cx);
7303 const js::Shape *addProperty(JSContext *cx, jsid id,
7304 js::PropertyOp getter, js::StrictPropertyOp setter,
7305 uint32 slot, uintN attrs,
7306 uintN flags, intN shortid);
7307 const js::Shape *addDataProperty(JSContext *cx, jsid id, uint32 slot, uintN attrs) {
7309 return addProperty(cx, id, __null, __null, slot, attrs, 0, 0);
7311 const js::Shape *putProperty(JSContext *cx, jsid id,
7312 js::PropertyOp getter, js::StrictPropertyOp setter,
7313 uint32 slot, uintN attrs,
7314 uintN flags, intN shortid);
7315 const js::Shape *changeProperty(JSContext *cx, const js::Shape *shape, uintN attrs, uintN mask,
7316 js::PropertyOp getter, js::StrictPropertyOp setter);
7317 bool removeProperty(JSContext *cx, jsid id);
7318 void clear(JSContext *cx);
7319 JSBool lookupProperty(JSContext *cx, jsid id, JSObject **objp, JSProperty **propp) {
7320 js::LookupPropOp op = getOps()->lookupProperty;
7321 return (op ? op : js_LookupProperty)(cx, this, id, objp, propp);
7323 JSBool defineProperty(JSContext *cx, jsid id, const js::Value &value,
7324 js::PropertyOp getter = js::PropertyStub,
7325 js::StrictPropertyOp setter = js::StrictPropertyStub,
7326 uintN attrs = 0x01) {
7327 js::DefinePropOp op = getOps()->defineProperty;
7328 return (op ? op : js_DefineProperty)(cx, this, id, &value, getter, setter, attrs);
7330 JSBool getProperty(JSContext *cx, JSObject *receiver, jsid id, js::Value *vp) {
7331 js::PropertyIdOp op = getOps()->getProperty;
7332 return (op ? op : (js::PropertyIdOp)js_GetProperty)(cx, this, receiver, id, vp);
7334 JSBool getProperty(JSContext *cx, jsid id, js::Value *vp) {
7335 return getProperty(cx, this, id, vp);
7337 JSBool setProperty(JSContext *cx, jsid id, js::Value *vp, JSBool strict) {
7338 js::StrictPropertyIdOp op = getOps()->setProperty;
7339 return (op ? op : js_SetProperty)(cx, this, id, vp, strict);
7341 JSBool getAttributes(JSContext *cx, jsid id, uintN *attrsp) {
7342 js::AttributesOp op = getOps()->getAttributes;
7343 return (op ? op : js_GetAttributes)(cx, this, id, attrsp);
7345 JSBool setAttributes(JSContext *cx, jsid id, uintN *attrsp) {
7346 js::AttributesOp op = getOps()->setAttributes;
7347 return (op ? op : js_SetAttributes)(cx, this, id, attrsp);
7349 JSBool deleteProperty(JSContext *cx, jsid id, js::Value *rval, JSBool strict) {
7350 js::DeleteIdOp op = getOps()->deleteProperty;
7351 return (op ? op : js_DeleteProperty)(cx, this, id, rval, strict);
7353 JSBool enumerate(JSContext *cx, JSIterateOp iterop, js::Value *statep, jsid *idp) {
7354 js::NewEnumerateOp op = getOps()->enumerate;
7355 return (op ? op : js_Enumerate)(cx, this, iterop, statep, idp);
7357 JSType typeOf(JSContext *cx) {
7358 js::TypeOfOp op = getOps()->typeOf;
7359 return (op ? op : js_TypeOf)(cx, this);
7361 JSObject *thisObject(JSContext *cx) {
7362 JSObjectOp op = getOps()->thisObject;
7363 return op ? op(cx, this) : this;
7365 static bool thisObject(JSContext *cx, const js::Value &v, js::Value *vp);
7366 inline JSCompartment *getCompartment() const;
7367 inline JSObject *getThrowTypeError() const;
7368 __attribute__((visibility ("default"))) JSObject * clone(JSContext *cx, JSObject *proto, JSObject *parent);
7369 __attribute__((visibility ("default"))) bool copyPropertiesFrom(JSContext *cx, JSObject *obj);
7370 bool swap(JSContext *cx, JSObject *other);
7371 const js::Shape *defineBlockVariable(JSContext *cx, jsid id, intN index);
7372 inline bool canHaveMethodBarrier() const;
7373 inline bool isArguments() const;
7374 inline bool isNormalArguments() const;
7375 inline bool isStrictArguments() const;
7376 inline bool isArray() const;
7377 inline bool isDenseArray() const;
7378 inline bool isSlowArray() const;
7379 inline bool isNumber() const;
7380 inline bool isBoolean() const;
7381 inline bool isString() const;
7382 inline bool isPrimitive() const;
7383 inline bool isDate() const;
7384 inline bool isFunction() const;
7385 inline bool isObject() const;
7386 inline bool isWith() const;
7387 inline bool isBlock() const;
7388 inline bool isStaticBlock() const;
7389 inline bool isClonedBlock() const;
7390 inline bool isCall() const;
7391 inline bool isRegExp() const;
7392 inline bool isScript() const;
7393 inline bool isXML() const;
7394 inline bool isXMLId() const;
7395 inline bool isNamespace() const;
7396 inline bool isQName() const;
7397 inline bool isProxy() const;
7398 inline bool isObjectProxy() const;
7399 inline bool isFunctionProxy() const;
7400 __attribute__((visibility ("default"))) bool isWrapper() const;
7401 __attribute__((visibility ("default"))) JSObject * unwrap(uintN *flagsp = __null);
7402 inline void initArrayClass();
7404 typedef int js_static_assert37[(sizeof(JSObject) % sizeof(js::Value) == 0) ? 1 : -1];
7406 JSObject::fixedSlots() const {
7407 return (js::Value*) (jsuword(this) + sizeof(JSObject));
7411 JSObject::hasSlotsArray() const { return this->slots != fixedSlots(); }
7413 JSObject::getFixedSlotOffset(size_t slot) {
7414 return sizeof(JSObject) + (slot * sizeof(js::Value));
7416 struct JSObject_Slots2 : JSObject { js::Value fslots[2]; };
7417 struct JSObject_Slots4 : JSObject { js::Value fslots[4]; };
7418 struct JSObject_Slots8 : JSObject { js::Value fslots[8]; };
7419 struct JSObject_Slots12 : JSObject { js::Value fslots[12]; };
7420 struct JSObject_Slots16 : JSObject { js::Value fslots[16]; };
7422 OBJ_TO_INNER_OBJECT(JSContext *cx, JSObject *&obj)
7424 if (JSObjectOp op = obj->getClass()->ext.innerObject)
7428 OBJ_TO_OUTER_OBJECT(JSContext *cx, JSObject *&obj)
7430 if (JSObjectOp op = obj->getClass()->ext.outerObject)
7433 class JSValueArray {
7437 JSValueArray(jsval *v, size_t c) : array(v), length(c) {}
7443 ValueArray(js::Value *v, size_t c) : array(v), length(c) {}
7445 extern js::Class js_ObjectClass;
7446 extern js::Class js_WithClass;
7447 extern js::Class js_BlockClass;
7448 inline bool JSObject::isObject() const { return getClass() == &js_ObjectClass; }
7449 inline bool JSObject::isWith() const { return getClass() == &js_WithClass; }
7450 inline bool JSObject::isBlock() const { return getClass() == &js_BlockClass; }
7451 static const uint32 JSSLOT_BLOCK_DEPTH = 0;
7452 static const uint32 JSSLOT_BLOCK_FIRST_FREE_SLOT = JSSLOT_BLOCK_DEPTH + 1;
7455 JSObject::isStaticBlock() const
7457 return isBlock() && !getProto();
7461 JSObject::isClonedBlock() const
7463 return isBlock() && !!getProto();
7465 static const uint32 JSSLOT_WITH_THIS = 1;
7467 js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth);
7469 js_UnwrapWithObject(JSContext *cx, JSObject *withobj)
7472 return withobj->getProto();
7475 js_NewBlockObject(JSContext *cx);
7477 js_CloneBlockObject(JSContext *cx, JSObject *proto, JSStackFrame *fp);
7479 js_PutBlockObject(JSContext *cx, JSBool normalUnwind);
7481 js_XDRBlockObject(JSXDRState *xdr, JSObject **objp);
7482 struct JSSharpObjectMap {
7487 extern JSHashEntry *
7488 js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
7491 js_LeaveSharpObject(JSContext *cx, JSIdArray **idap);
7493 js_TraceSharpMap(JSTracer *trc, JSSharpObjectMap *map);
7495 js_HasOwnPropertyHelper(JSContext *cx, js::LookupPropOp lookup, uintN argc,
7498 js_HasOwnProperty(JSContext *cx, js::LookupPropOp lookup, JSObject *obj, jsid id,
7499 JSObject **objp, JSProperty **propp);
7501 js_NewPropertyDescriptorObject(JSContext *cx, jsid id, uintN attrs,
7502 const js::Value &getter, const js::Value &setter,
7503 const js::Value &value, js::Value *vp);
7505 js_PropertyIsEnumerable(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
7506 __attribute__((visibility ("default"))) JSBool js_obj_defineGetter(JSContext *cx, uintN argc, js::Value *vp);
7507 __attribute__((visibility ("default"))) JSBool js_obj_defineSetter(JSContext *cx, uintN argc, js::Value *vp);
7509 js_InitObjectClass(JSContext *cx, JSObject *obj);
7512 DefineConstructorAndPrototype(JSContext *cx, JSObject *obj, JSProtoKey key, JSAtom *atom,
7513 JSObject *protoProto, Class *clasp,
7514 Native constructor, uintN nargs,
7515 JSPropertySpec *ps, JSFunctionSpec *fs,
7516 JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
7519 js_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
7520 js::Class *clasp, js::Native constructor, uintN nargs,
7521 JSPropertySpec *ps, JSFunctionSpec *fs,
7522 JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
7523 extern const char js_watch_str[];
7524 extern const char js_unwatch_str[];
7525 extern const char js_hasOwnProperty_str[];
7526 extern const char js_isPrototypeOf_str[];
7527 extern const char js_propertyIsEnumerable_str[];
7528 extern const char js_defineGetter_str[];
7529 extern const char js_defineSetter_str[];
7530 extern const char js_lookupGetter_str[];
7531 extern const char js_lookupSetter_str[];
7533 js_PopulateObject(JSContext *cx, JSObject *newborn, JSObject *props);
7535 js_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
7538 js_SetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
7539 JSObject *cobj, JSObject *prototype);
7541 js_FindClassObject(JSContext *cx, JSObject *start, JSProtoKey key,
7542 js::Value *vp, js::Class *clasp = __null);
7544 js_ConstructObject(JSContext *cx, js::Class *clasp, JSObject *proto,
7545 JSObject *parent, uintN argc, js::Value *argv);
7547 js_CreateThisForFunctionWithProto(JSContext *cx, JSObject *callee, JSObject *proto);
7549 js_CreateThisForFunction(JSContext *cx, JSObject *callee);
7551 js_CreateThis(JSContext *cx, JSObject *callee);
7553 js_CheckForStringIndex(jsid id);
7555 js_PurgeScopeChainHelper(JSContext *cx, JSObject *obj, jsid id);
7557 js_PurgeScopeChain(JSContext *cx, JSObject *obj, jsid id)
7559 if (obj->isDelegate())
7560 js_PurgeScopeChainHelper(cx, obj, id);
7562 extern const js::Shape *
7563 js_AddNativeProperty(JSContext *cx, JSObject *obj, jsid id,
7564 js::PropertyOp getter, js::StrictPropertyOp setter, uint32 slot,
7565 uintN attrs, uintN flags, intN shortid);
7566 extern const js::Shape *
7567 js_ChangeNativePropertyAttrs(JSContext *cx, JSObject *obj,
7568 const js::Shape *shape, uintN attrs, uintN mask,
7569 js::PropertyOp getter, js::StrictPropertyOp setter);
7571 js_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id,
7572 const js::Value &descriptor, JSBool *bp);
7573 const uintN JSDNP_CACHE_RESULT = 1;
7574 const uintN JSDNP_DONT_PURGE = 2;
7575 const uintN JSDNP_SET_METHOD = 4;
7576 const uintN JSDNP_UNQUALIFIED = 8;
7578 js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, const js::Value &value,
7579 js::PropertyOp getter, js::StrictPropertyOp setter, uintN attrs,
7580 uintN flags, intN shortid, JSProperty **propp,
7581 uintN defineHow = 0);
7583 js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,
7584 JSObject **objp, JSProperty **propp);
7585 extern __attribute__((visibility ("default"))) js::Class js_CallClass;
7586 extern __attribute__((visibility ("default"))) js::Class js_DeclEnvClass;
7590 IsCacheableNonGlobalScope(JSObject *obj)
7593 js::Class *clasp = obj->getClass();
7594 bool cacheable = (clasp == &js_CallClass ||
7595 clasp == &js_BlockClass ||
7596 clasp == &js_DeclEnvClass);
7601 extern js::PropertyCacheEntry *
7602 js_FindPropertyHelper(JSContext *cx, jsid id, JSBool cacheResult,
7603 JSObject **objp, JSObject **pobjp, JSProperty **propp);
7604 extern __attribute__((visibility ("default"))) JSBool
7605 js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
7606 JSProperty **propp);
7608 js_FindIdentifierBase(JSContext *cx, JSObject *scopeChain, jsid id);
7610 js_FindVariableScope(JSContext *cx, JSFunction **funp);
7611 const uintN JSGET_CACHE_RESULT = 1;
7612 const uintN JSGET_METHOD_BARRIER = 0;
7613 const uintN JSGET_NO_METHOD_BARRIER = 2;
7615 js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const js::Shape *shape, uintN getHow,
7618 js_NativeSet(JSContext *cx, JSObject *obj, const js::Shape *shape, bool added,
7619 bool strict, js::Value *vp);
7621 js_GetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, uint32 getHow, js::Value *vp);
7624 js_GetPropertyHelperWithShape(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id,
7625 uint32 getHow, js::Value *vp,
7626 const js::Shape **shapeOut, JSObject **holderOut);
7628 js_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
7630 js_GetMethod(JSContext *cx, JSObject *obj, jsid id, uintN getHow, js::Value *vp);
7631 extern __attribute__((visibility ("default"))) bool
7632 js_CheckUndeclaredVarAssignment(JSContext *cx, JSString *propname);
7634 js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, uintN defineHow,
7635 js::Value *vp, JSBool strict);
7637 js_SetNativeAttributes(JSContext *cx, JSObject *obj, js::Shape *shape,
7641 HasNativeMethod(JSObject *obj, jsid methodid, Native native);
7644 DefaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp);
7646 CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
7647 js::Value *vp, uintN *attrsp);
7651 js_IsDelegate(JSContext *cx, JSObject *obj, const js::Value &v);
7652 extern __attribute__((visibility ("default"))) JSBool
7653 js_GetClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey,
7654 JSObject **protop, js::Class *clasp = __null);
7656 js_SetClassPrototype(JSContext *cx, JSObject *ctor, JSObject *proto,
7659 js_PrimitiveToObject(JSContext *cx, js::Value *vp);
7661 js_ValueToObjectOrNull(JSContext *cx, const js::Value &v, JSObject **objp);
7664 ToObjectSlow(JSContext *cx, js::Value *vp);
7665 __attribute__((always_inline)) inline JSObject *
7666 ToObject(JSContext *cx, js::Value *vp)
7669 return &vp->toObject();
7670 return ToObjectSlow(cx, vp);
7674 js_ValueToNonNullObject(JSContext *cx, const js::Value &v);
7676 js_TryValueOf(JSContext *cx, JSObject *obj, JSType type, js::Value *rval);
7678 js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom,
7679 uintN argc, js::Value *argv, js::Value *rval);
7681 js_XDRObject(JSXDRState *xdr, JSObject **objp);
7683 js_TraceObject(JSTracer *trc, JSObject *obj);
7685 js_PrintObjectSlotName(JSTracer *trc, char *buf, size_t bufsize);
7687 js_ClearNative(JSContext *cx, JSObject *obj);
7690 js_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, js::Value *vp);
7693 js_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, const js::Value &v);
7695 js_CheckPrincipalsAccess(JSContext *cx, JSObject *scopeobj,
7696 JSPrincipals *principals, JSAtom *caller);
7698 js_CheckContentSecurityPolicy(JSContext *cx, JSObject *scopeObj);
7700 js_ComputeFilename(JSContext *cx, JSStackFrame *caller,
7701 JSPrincipals *principals, uintN *linenop);
7703 js_ReportGetterOnlyAssignment(JSContext *cx);
7704 extern __attribute__((visibility ("default"))) JSBool
7705 js_GetterOnlyPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
7707 js_InferFlags(JSContext *cx, uintN defaultFlags);
7709 js_Object(JSContext *cx, uintN argc, js::Value *vp);
7713 SetProto(JSContext *cx, JSObject *obj, JSObject *proto, bool checkForCycles);
7715 obj_toStringHelper(JSContext *cx, JSObject *obj);
7716 enum EvalType { INDIRECT_EVAL, DIRECT_EVAL };
7719 EvalKernel(JSContext *cx, uintN argc, js::Value *vp, EvalType evalType, JSStackFrame *caller,
7720 JSObject *scopeobj);
7721 extern __attribute__((visibility ("default"))) bool
7722 IsBuiltinEvalFunction(JSFunction *fun);
7725 UNIT_STRING_LIMIT = 256U,
7726 SMALL_CHAR_LIMIT = 128U,
7727 NUM_SMALL_CHARS = 64U,
7728 INT_STRING_LIMIT = 256U,
7729 NUM_HUNDRED_STRINGS = 156U
7732 js_GetDependentStringChars(JSString *str);
7734 js_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
7735 typedef int js_static_assert38[((8 * 8) >= 32) ? 1 : -1];
7736 struct JSRopeBufferInfo {
7739 namespace js { namespace mjit {
7742 struct JSLinearString;
7745 friend class js::TraceRecorder;
7746 friend class js::mjit::Compiler;
7747 friend JSAtom *js_AtomizeString(JSContext *cx, JSString *str, uintN flags);
7748 size_t lengthAndFlags;
7750 const jschar *chars;
7754 jschar inlineStorage[4];
7766 size_t externalStringType;
7768 static const size_t TYPE_FLAGS_MASK = (((JSUint32)1 << (4)) - 1);
7769 static const size_t LENGTH_SHIFT = 4;
7770 static const size_t TYPE_MASK = (((JSUint32)1 << (2)) - 1);
7771 static const size_t FLAT = 0x0;
7772 static const size_t DEPENDENT = 0x1;
7773 static const size_t ROPE = 0x2;
7774 static const size_t DEPENDENT_BIT = ((JSUint32)1 << (0));
7775 static const size_t ROPE_BIT = ((JSUint32)1 << (1));
7776 static const size_t ATOMIZED = ((JSUint32)1 << (2));
7777 static const size_t EXTENSIBLE = ((JSUint32)1 << (3));
7778 size_t buildLengthAndFlags(size_t length, size_t flags) {
7779 return (length << LENGTH_SHIFT) | flags;
7781 inline js::gc::Cell *asCell() {
7782 return reinterpret_cast<js::gc::Cell *>(this);
7784 inline js::gc::FreeCell *asFreeCell() {
7785 return reinterpret_cast<js::gc::FreeCell *>(this);
7787 static const size_t MAX_LENGTH = (1 << 28) - 1;
7788 __attribute__((always_inline)) inline bool isDependent() const {
7789 return lengthAndFlags & DEPENDENT_BIT;
7791 __attribute__((always_inline)) inline bool isFlat() const {
7792 return (lengthAndFlags & TYPE_MASK) == FLAT;
7794 __attribute__((always_inline)) inline bool isExtensible() const {
7796 return lengthAndFlags & EXTENSIBLE;
7798 __attribute__((always_inline)) inline bool isAtomized() const {
7800 return lengthAndFlags & ATOMIZED;
7802 __attribute__((always_inline)) inline bool isRope() const {
7803 return lengthAndFlags & ROPE_BIT;
7805 __attribute__((always_inline)) inline size_t length() const {
7806 return lengthAndFlags >> LENGTH_SHIFT;
7808 __attribute__((always_inline)) inline bool empty() const {
7809 return lengthAndFlags <= TYPE_FLAGS_MASK;
7811 __attribute__((always_inline)) inline const jschar *getChars(JSContext *cx) {
7814 return nonRopeChars();
7816 __attribute__((always_inline)) inline const jschar *getCharsZ(JSContext *cx) {
7818 return undepend(cx);
7821 __attribute__((always_inline)) inline void initFlatNotTerminated(jschar *chars, size_t length) {
7824 lengthAndFlags = buildLengthAndFlags(length, FLAT);
7827 __attribute__((always_inline)) inline void initFlat(jschar *chars, size_t length) {
7828 initFlatNotTerminated(chars, length);
7831 __attribute__((always_inline)) inline void initShortString(const jschar *chars, size_t length) {
7835 lengthAndFlags = buildLengthAndFlags(length, FLAT);
7838 __attribute__((always_inline)) inline void initFlatExtensible(jschar *chars, size_t length, size_t cap) {
7842 lengthAndFlags = buildLengthAndFlags(length, FLAT | EXTENSIBLE);
7846 __attribute__((always_inline)) inline JSFlatString *assertIsFlat() {
7848 return reinterpret_cast<JSFlatString *>(this);
7850 __attribute__((always_inline)) inline const jschar *flatChars() const {
7854 __attribute__((always_inline)) inline size_t flatLength() const {
7858 inline void flatSetAtomized() {
7861 lengthAndFlags |= ATOMIZED;
7863 inline void flatClearExtensible() {
7865 if (lengthAndFlags & EXTENSIBLE)
7866 lengthAndFlags &= ~EXTENSIBLE;
7868 inline void initDependent(JSString *base, const jschar *chars, size_t length) {
7873 lengthAndFlags = buildLengthAndFlags(length, DEPENDENT);
7877 inline JSLinearString *dependentBase() const {
7879 return s.base->assertIsLinear();
7881 __attribute__((always_inline)) inline const jschar *dependentChars() {
7885 inline size_t dependentLength() const {
7889 const jschar *undepend(JSContext *cx);
7890 const jschar *nonRopeChars() const {
7894 inline void initRopeNode(JSString *left, JSString *right, size_t length) {
7896 lengthAndFlags = buildLengthAndFlags(length, ROPE);
7900 inline JSString *ropeLeft() const {
7904 inline JSString *ropeRight() const {
7908 inline void finishTraversalConversion(JSString *base, const jschar *baseBegin, const jschar *end) {
7910 lengthAndFlags = buildLengthAndFlags(end - u.chars, DEPENDENT);
7913 const jschar *flatten(JSContext *maybecx);
7914 JSLinearString *ensureLinear(JSContext *cx) {
7915 if (isRope() && !flatten(cx))
7917 return reinterpret_cast<JSLinearString *>(this);
7919 bool isLinear() const {
7922 JSLinearString *assertIsLinear() {
7924 return reinterpret_cast<JSLinearString *>(this);
7926 typedef uint8 SmallChar;
7927 static inline bool fitsInSmallChar(jschar c) {
7928 return c < SMALL_CHAR_LIMIT && toSmallChar[c] != INVALID_SMALL_CHAR;
7930 static inline bool isUnitString(void *ptr) {
7931 jsuword delta = reinterpret_cast<jsuword>(ptr) -
7932 reinterpret_cast<jsuword>(unitStringTable);
7933 if (delta >= UNIT_STRING_LIMIT * sizeof(JSString))
7938 static inline bool isLength2String(void *ptr) {
7939 jsuword delta = reinterpret_cast<jsuword>(ptr) -
7940 reinterpret_cast<jsuword>(length2StringTable);
7941 if (delta >= NUM_SMALL_CHARS * NUM_SMALL_CHARS * sizeof(JSString))
7946 static inline bool isHundredString(void *ptr) {
7947 jsuword delta = reinterpret_cast<jsuword>(ptr) -
7948 reinterpret_cast<jsuword>(hundredStringTable);
7949 if (delta >= NUM_HUNDRED_STRINGS * sizeof(JSString))
7954 static inline bool isStatic(void *ptr) {
7955 return isUnitString(ptr) || isLength2String(ptr) || isHundredString(ptr);
7957 static const SmallChar INVALID_SMALL_CHAR = -1;
7958 static const jschar fromSmallChar[];
7959 static const SmallChar toSmallChar[];
7960 static const JSString unitStringTable[];
7961 static const JSString length2StringTable[];
7962 static const JSString hundredStringTable[];
7963 static const JSString *const intStringTable[];
7964 static JSFlatString *unitString(jschar c);
7965 static JSLinearString *getUnitString(JSContext *cx, JSString *str, size_t index);
7966 static JSFlatString *length2String(jschar c1, jschar c2);
7967 static JSFlatString *length2String(uint32 i);
7968 static JSFlatString *intString(jsint i);
7969 static JSFlatString *lookupStaticString(const jschar *chars, size_t length);
7970 __attribute__((always_inline)) inline void finalize(JSContext *cx);
7971 static size_t offsetOfLengthAndFlags() {
7972 return __builtin_offsetof (JSString, lengthAndFlags);
7974 static size_t offsetOfChars() {
7975 return __builtin_offsetof (JSString, u.chars);
7977 static void staticAsserts() {
7978 typedef int js_static_assert39[(((JSString::MAX_LENGTH << JSString::LENGTH_SHIFT) >> JSString::LENGTH_SHIFT) == JSString::MAX_LENGTH) ? 1 : -1]
7982 struct JSLinearString : JSString
7984 const jschar *chars() const { return JSString::nonRopeChars(); }
7986 typedef int js_static_assert40[(sizeof(JSLinearString) == sizeof(JSString)) ? 1 : -1];
7987 struct JSFlatString : JSLinearString
7989 const jschar *charsZ() const { return chars(); }
7991 typedef int js_static_assert41[(sizeof(JSFlatString) == sizeof(JSString)) ? 1 : -1];
7992 struct JSAtom : JSFlatString
7995 struct JSExternalString : JSString
7997 static const uintN TYPE_LIMIT = 8;
7998 static JSStringFinalizeOp str_finalizers[TYPE_LIMIT];
7999 static intN changeFinalizer(JSStringFinalizeOp oldop,
8000 JSStringFinalizeOp newop) {
8001 for (uintN i = 0; i != (sizeof (str_finalizers) / sizeof (str_finalizers)[0]); i++) {
8002 if (str_finalizers[i] == oldop) {
8003 str_finalizers[i] = newop;
8009 void finalize(JSContext *cx);
8012 typedef int js_static_assert42[(sizeof(JSString) == sizeof(JSExternalString)) ? 1 : -1];
8013 class JSShortString : public js::gc::Cell
8018 inline jschar *init(size_t length) {
8020 mHeader.initShortString(mHeader.inlineStorage, length);
8021 return mHeader.inlineStorage;
8023 inline jschar *getInlineStorageBeforeInit() {
8024 return mHeader.inlineStorage;
8026 inline void initAtOffsetInBuffer(jschar *p, size_t length) {
8028 mHeader.initShortString(p, length);
8030 inline void resetLength(size_t length) {
8031 mHeader.initShortString(mHeader.flatChars(), length);
8033 inline JSString *header() {
8036 static const size_t FREE_STRING_WORDS = 2;
8037 static const size_t MAX_SHORT_STRING_LENGTH =
8038 ((sizeof(JSString) + FREE_STRING_WORDS * sizeof(size_t)) / sizeof(jschar)) - 1;
8039 static inline bool fitsIntoShortString(size_t length) {
8040 return length <= MAX_SHORT_STRING_LENGTH;
8042 __attribute__((always_inline)) inline void finalize(JSContext *cx);
8043 static void staticAsserts() {
8044 typedef int js_static_assert43[(__builtin_offsetof (JSString, inlineStorage) == sizeof(JSString) - JSShortString::FREE_STRING_WORDS * sizeof(void *)) ? 1 : -1]
8046 typedef int js_static_assert44[(__builtin_offsetof (JSShortString, mDummy) == sizeof(JSString)) ? 1 : -1];
8047 typedef int js_static_assert45[(__builtin_offsetof (JSString, inlineStorage) + sizeof(jschar) * (JSShortString::MAX_SHORT_STRING_LENGTH + 1) == sizeof(JSShortString)) ? 1 : -1]
8053 class StringSegmentRange;
8054 class MutatingRopeSegmentRange;
8057 extern const jschar *
8058 js_GetStringChars(JSContext *cx, JSString *str);
8059 extern const jschar *
8060 js_UndependString(JSContext *cx, JSString *str);
8062 js_MakeStringImmutable(JSContext *cx, JSString *str);
8064 js_toLowerCase(JSContext *cx, JSString *str);
8066 js_toUpperCase(JSContext *cx, JSString *str);
8067 struct JSSubString {
8069 const jschar *chars;
8071 extern jschar js_empty_ucstr[];
8072 extern JSSubString js_EmptySubString;
8073 extern const uint8 js_X[];
8074 extern const uint8 js_Y[];
8075 extern const uint32 js_A[];
8076 typedef enum JSCharType {
8077 JSCT_UNASSIGNED = 0,
8078 JSCT_UPPERCASE_LETTER = 1,
8079 JSCT_LOWERCASE_LETTER = 2,
8080 JSCT_TITLECASE_LETTER = 3,
8081 JSCT_MODIFIER_LETTER = 4,
8082 JSCT_OTHER_LETTER = 5,
8083 JSCT_NON_SPACING_MARK = 6,
8084 JSCT_ENCLOSING_MARK = 7,
8085 JSCT_COMBINING_SPACING_MARK = 8,
8086 JSCT_DECIMAL_DIGIT_NUMBER = 9,
8087 JSCT_LETTER_NUMBER = 10,
8088 JSCT_OTHER_NUMBER = 11,
8089 JSCT_SPACE_SEPARATOR = 12,
8090 JSCT_LINE_SEPARATOR = 13,
8091 JSCT_PARAGRAPH_SEPARATOR = 14,
8094 JSCT_PRIVATE_USE = 18,
8095 JSCT_SURROGATE = 19,
8096 JSCT_DASH_PUNCTUATION = 20,
8097 JSCT_START_PUNCTUATION = 21,
8098 JSCT_END_PUNCTUATION = 22,
8099 JSCT_CONNECTOR_PUNCTUATION = 23,
8100 JSCT_OTHER_PUNCTUATION = 24,
8101 JSCT_MATH_SYMBOL = 25,
8102 JSCT_CURRENCY_SYMBOL = 26,
8103 JSCT_MODIFIER_SYMBOL = 27,
8104 JSCT_OTHER_SYMBOL = 28
8106 extern const bool js_alnum[];
8107 const jschar BYTE_ORDER_MARK = 0xFEFF;
8108 const jschar NO_BREAK_SPACE = 0x00A0;
8111 JS_ISSPACE(jschar c)
8115 return (w <= ' ' && (w == ' ' || (9 <= w && w <= 0xD))) || w == NO_BREAK_SPACE;
8116 return w == BYTE_ORDER_MARK || ((js_A[js_Y[(js_X[(uint16)(w)>>6]<<6)|((w)&0x3F)]]) & 0x00070000) == 0x00040000;
8118 extern js::Class js_StringClass;
8121 JSObject::isString() const
8123 return getClass() == &js_StringClass;
8126 js_InitStringClass(JSContext *cx, JSObject *obj);
8127 extern const char js_escape_str[];
8128 extern const char js_unescape_str[];
8129 extern const char js_uneval_str[];
8130 extern const char js_decodeURI_str[];
8131 extern const char js_encodeURI_str[];
8132 extern const char js_decodeURIComponent_str[];
8133 extern const char js_encodeURIComponent_str[];
8134 extern JSFlatString *
8135 js_NewString(JSContext *cx, jschar *chars, size_t length);
8136 extern JSLinearString *
8137 js_NewDependentString(JSContext *cx, JSString *base, size_t start,
8139 extern JSFlatString *
8140 js_NewStringCopyN(JSContext *cx, const jschar *s, size_t n);
8141 extern JSFlatString *
8142 js_NewStringCopyN(JSContext *cx, const char *s, size_t n);
8143 extern JSFlatString *
8144 js_NewStringCopyZ(JSContext *cx, const jschar *s);
8145 extern JSFlatString *
8146 js_NewStringCopyZ(JSContext *cx, const char *s);
8148 js_ValueToPrintable(JSContext *cx, const js::Value &,
8149 JSAutoByteString *bytes, bool asSource = false);
8151 js_ValueToString(JSContext *cx, const js::Value &v);
8153 static __attribute__((always_inline)) inline JSString *
8154 ValueToString_TestForStringInline(JSContext *cx, const Value &v)
8157 return v.toString();
8158 return js_ValueToString(cx, v);
8162 ValueToStringBuffer(JSContext *cx, const Value &v, StringBuffer &sb);
8164 extern __attribute__((visibility ("default"))) JSString *
8165 js_ValueToSource(JSContext *cx, const js::Value &v);
8167 js_HashString(JSLinearString *str)
8169 const jschar *s = str->chars();
8170 size_t n = str->length();
8172 for (h = 0; n; s++, n--)
8173 h = (((h) << (4)) | ((h) >> (32 - (4)))) ^ *s;
8179 EqualStrings(JSContext *cx, JSString *str1, JSString *str2, JSBool *result);
8182 EqualStrings(JSLinearString *str1, JSLinearString *str2);
8185 CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32 *result);
8188 StringEqualsAscii(JSLinearString *str, const char *asciiBytes);
8190 static const jsuint sBMHCharSetSize = 256;
8191 static const jsuint sBMHPatLenMax = 255;
8192 static const jsint sBMHBadPattern = -2;
8194 js_BoyerMooreHorspool(const jschar *text, jsuint textlen,
8195 const jschar *pat, jsuint patlen);
8197 js_strlen(const jschar *s);
8199 js_strchr(const jschar *s, jschar c);
8201 js_strchr_limit(const jschar *s, jschar c, const jschar *limit);
8203 js_short_strncpy(jschar *dest, const jschar *src, size_t num)
8206 for (size_t i = 0; i < num; i++)
8209 static inline const jschar *
8210 js_SkipWhiteSpace(const jschar *s, const jschar *end)
8213 while (s != end && JS_ISSPACE(*s))
8218 js_InflateString(JSContext *cx, const char *bytes, size_t *length);
8220 js_DeflateString(JSContext *cx, const jschar *chars, size_t length);
8222 js_InflateStringToBuffer(JSContext *cx, const char *bytes, size_t length,
8223 jschar *chars, size_t *charsLength);
8225 js_InflateUTF8StringToBuffer(JSContext *cx, const char *bytes, size_t length,
8226 jschar *chars, size_t *charsLength);
8228 js_GetDeflatedStringLength(JSContext *cx, const jschar *chars,
8229 size_t charsLength);
8231 js_GetDeflatedUTF8StringLength(JSContext *cx, const jschar *chars,
8232 size_t charsLength);
8234 js_DeflateStringToBuffer(JSContext *cx, const jschar *chars,
8235 size_t charsLength, char *bytes, size_t *length);
8237 js_DeflateStringToUTF8Buffer(JSContext *cx, const jschar *chars,
8238 size_t charsLength, char *bytes, size_t *length);
8240 js_str_escape(JSContext *cx, uintN argc, js::Value *argv, js::Value *rval);
8243 str_replace(JSContext *cx, uintN argc, js::Value *vp);
8246 js_str_toString(JSContext *cx, uintN argc, js::Value *vp);
8248 js_str_charAt(JSContext *cx, uintN argc, js::Value *vp);
8250 js_str_charCodeAt(JSContext *cx, uintN argc, js::Value *vp);
8252 js_OneUcs4ToUtf8Char(uint8 *utf8Buffer, uint32 ucs4Char);
8255 PutEscapedStringImpl(char *buffer, size_t size, FILE *fp, JSLinearString *str, uint32 quote);
8257 PutEscapedString(char *buffer, size_t size, JSLinearString *str, uint32 quote)
8259 size_t n = PutEscapedStringImpl(buffer, size, __null, str, quote);
8265 FileEscapedString(FILE *fp, JSLinearString *str, uint32 quote)
8267 return PutEscapedStringImpl(__null, 0, fp, str, quote) != size_t(-1);
8271 js_String(JSContext *cx, uintN argc, js::Value *vp);
8272 static __attribute__((always_inline)) inline jsid
8273 JSID_FROM_BITS(size_t bits)
8279 static __attribute__((always_inline)) inline jsid
8280 ATOM_TO_JSID(JSAtom *atom)
8283 return JSID_FROM_BITS((size_t)atom);
8285 static __attribute__((always_inline)) inline JSBool
8286 JSID_IS_ATOM(jsid id)
8288 return JSID_IS_STRING(id);
8290 static __attribute__((always_inline)) inline JSBool
8291 JSID_IS_ATOM(jsid id, JSAtom *atom)
8293 return (id) == (ATOM_TO_JSID(atom));
8295 static __attribute__((always_inline)) inline JSAtom *
8296 JSID_TO_ATOM(jsid id)
8298 return (JSAtom *)JSID_TO_STRING(id);
8301 static __attribute__((always_inline)) inline Value
8304 if (JSID_IS_STRING(id))
8305 return StringValue(JSID_TO_STRING(id));
8306 if ((__builtin_expect((JSID_IS_INT(id)), 1)))
8307 return Int32Value(JSID_TO_INT(id));
8308 if ((__builtin_expect((JSID_IS_OBJECT(id)), 1)))
8309 return ObjectValue(*JSID_TO_OBJECT(id));
8311 return UndefinedValue();
8313 static __attribute__((always_inline)) inline jsval
8316 return Jsvalify(IdToValue(id));
8320 js_AtomToPrintableString(JSContext *cx, JSAtom *atom, JSAutoByteString *bytes);
8321 struct JSAtomListElement {
8329 struct JSAtomList : public JSAtomSet
8332 list = __null; table = __null; count = 0;
8334 JSAtomList(const JSAtomSet& as) {
8335 list = as.list; table = as.table; count = as.count;
8337 void clear() { ((void) 0); list = __null; table = __null; count = 0; }
8338 JSAtomListElement *lookup(JSAtom *atom) {
8340 return rawLookup(atom, hep);
8342 JSAtomListElement *rawLookup(JSAtom *atom, JSHashEntry **&hep);
8343 enum AddHow { UNIQUE, SHADOW, HOIST };
8344 JSAtomListElement *add(js::Parser *parser, JSAtom *atom, AddHow how = UNIQUE);
8345 void remove(js::Parser *parser, JSAtom *atom) {
8347 JSAtomListElement *ale = rawLookup(atom, hep);
8349 rawRemove(parser, ale, hep);
8351 void rawRemove(js::Parser *parser, JSAtomListElement *ale, JSHashEntry **hep);
8353 struct JSAutoAtomList: public JSAtomList
8355 JSAutoAtomList(js::Parser *p): parser(p) {}
8360 class JSAtomListIterator {
8362 JSAtomListElement* next;
8365 JSAtomListIterator(JSAtomList* al) : list(al) { reset(); }
8367 next = (JSAtomListElement *) list->list;
8370 JSAtomListElement* operator ()();
8377 typedef int js_static_assert46[(((size_t)(0x1 | 0x2)) < JS_GCTHING_ALIGN) ? 1 : -1];
8378 typedef uintptr_t AtomEntryType;
8379 static __attribute__((always_inline)) inline JSAtom *
8380 AtomEntryToKey(AtomEntryType entry)
8383 return (JSAtom *)(entry & ~((size_t)(0x1 | 0x2)));
8387 typedef JSLinearString *Lookup;
8388 static HashNumber hash(JSLinearString *str) {
8389 return js_HashString(str);
8391 static bool match(AtomEntryType entry, JSLinearString *lookup) {
8392 return entry ? EqualStrings(AtomEntryToKey(entry), lookup) : false;
8395 typedef HashSet<AtomEntryType, AtomHasher, SystemAllocPolicy> AtomSet;
8402 JSAtom *booleanAtoms[2];
8403 JSAtom *typeAtoms[JSTYPE_LIMIT];
8405 JSAtom *classAtoms[JSProto_LIMIT];
8406 JSAtom *anonymousAtom;
8408 JSAtom *argumentsAtom;
8413 JSAtom *classPrototypeAtom;
8414 JSAtom *constructorAtom;
8417 JSAtom *fileNameAtom;
8420 JSAtom *ignoreCaseAtom;
8423 JSAtom *toISOStringAtom;
8424 JSAtom *iteratorAtom;
8426 JSAtom *lastIndexAtom;
8428 JSAtom *lineNumberAtom;
8429 JSAtom *messageAtom;
8430 JSAtom *multilineAtom;
8433 JSAtom *noSuchMethodAtom;
8434 JSAtom *objectNullAtom;
8435 JSAtom *objectUndefinedAtom;
8441 JSAtom *toGMTStringAtom;
8442 JSAtom *toLocaleStringAtom;
8443 JSAtom *toSourceAtom;
8444 JSAtom *toStringAtom;
8445 JSAtom *toUTCStringAtom;
8446 JSAtom *valueOfAtom;
8449 JSAtom *enumerableAtom;
8450 JSAtom *configurableAtom;
8451 JSAtom *writableAtom;
8454 JSAtom *useStrictAtom;
8457 JSAtom *InfinityAtom;
8459 JSAtom *builderAtom;
8461 JSAtom *namespaceAtom;
8463 JSAtom *qualifierAtom;
8467 JSAtom *starQualifierAtom;
8470 JSAtom *functionNamespaceURIAtom;
8472 JSAtom *getOwnPropertyDescriptorAtom;
8473 JSAtom *getPropertyDescriptorAtom;
8474 JSAtom *definePropertyAtom;
8476 JSAtom *getOwnPropertyNamesAtom;
8477 JSAtom *enumerateAtom;
8482 JSAtom *iterateAtom;
8484 JSAtom *XMLListAtom;
8485 JSAtom *decodeURIAtom;
8486 JSAtom *decodeURIComponentAtom;
8487 JSAtom *defineGetterAtom;
8488 JSAtom *defineSetterAtom;
8489 JSAtom *encodeURIAtom;
8490 JSAtom *encodeURIComponentAtom;
8492 JSAtom *hasOwnPropertyAtom;
8493 JSAtom *isFiniteAtom;
8495 JSAtom *isPrototypeOfAtom;
8496 JSAtom *isXMLNameAtom;
8497 JSAtom *lookupGetterAtom;
8498 JSAtom *lookupSetterAtom;
8499 JSAtom *parseFloatAtom;
8500 JSAtom *parseIntAtom;
8501 JSAtom *propertyIsEnumerableAtom;
8502 JSAtom *unescapeAtom;
8504 JSAtom *unwatchAtom;
8508 extern const char *const js_common_atom_names[];
8509 extern const size_t js_common_atom_count;
8510 extern const char js_Null_str[];
8511 extern const char js_Object_str[];
8512 extern const char js_Function_str[];
8513 extern const char js_Array_str[];
8514 extern const char js_Boolean_str[];
8515 extern const char js_JSON_str[];
8516 extern const char js_Date_str[];
8517 extern const char js_Math_str[];
8518 extern const char js_Number_str[];
8519 extern const char js_String_str[];
8520 extern const char js_RegExp_str[];
8521 extern const char js_XML_str[];
8522 extern const char js_Namespace_str[];
8523 extern const char js_QName_str[];
8524 extern const char js_Reflect_str[];
8525 extern const char js_ASTNode_str[];
8526 extern const char js_Error_str[];
8527 extern const char js_InternalError_str[];
8528 extern const char js_EvalError_str[];
8529 extern const char js_RangeError_str[];
8530 extern const char js_ReferenceError_str[];
8531 extern const char js_SyntaxError_str[];
8532 extern const char js_TypeError_str[];
8533 extern const char js_URIError_str[];
8534 extern const char js_Generator_str[];
8535 extern const char js_Iterator_str[];
8536 extern const char js_StopIteration_str[];
8537 extern const char js_ArrayBuffer_str[];
8538 extern const char js_Int8Array_str[];
8539 extern const char js_Uint8Array_str[];
8540 extern const char js_Int16Array_str[];
8541 extern const char js_Uint16Array_str[];
8542 extern const char js_Int32Array_str[];
8543 extern const char js_Uint32Array_str[];
8544 extern const char js_Float32Array_str[];
8545 extern const char js_Float64Array_str[];
8546 extern const char js_Uint8ClampedArray_str[];
8547 extern const char js_Proxy_str[];
8548 extern const char js_AnyName_str[];
8549 extern const char js_anonymous_str[];
8550 extern const char js_apply_str[];
8551 extern const char js_arguments_str[];
8552 extern const char js_arity_str[];
8553 extern const char js_call_str[];
8554 extern const char js_callee_str[];
8555 extern const char js_caller_str[];
8556 extern const char js_class_prototype_str[];
8557 extern const char js_close_str[];
8558 extern const char js_constructor_str[];
8559 extern const char js_count_str[];
8560 extern const char js_etago_str[];
8561 extern const char js_each_str[];
8562 extern const char js_eval_str[];
8563 extern const char js_fileName_str[];
8564 extern const char js_get_str[];
8565 extern const char js_getter_str[];
8566 extern const char js_global_str[];
8567 extern const char js_ignoreCase_str[];
8568 extern const char js_index_str[];
8569 extern const char js_input_str[];
8570 extern const char js_iterator_str[];
8571 extern const char js_join_str[];
8572 extern const char js_lastIndex_str[];
8573 extern const char js_length_str[];
8574 extern const char js_lineNumber_str[];
8575 extern const char js_message_str[];
8576 extern const char js_multiline_str[];
8577 extern const char js_name_str[];
8578 extern const char js_namespace_str[];
8579 extern const char js_next_str[];
8580 extern const char js_noSuchMethod_str[];
8581 extern const char js_object_str[];
8582 extern const char js_proto_str[];
8583 extern const char js_ptagc_str[];
8584 extern const char js_qualifier_str[];
8585 extern const char js_send_str[];
8586 extern const char js_setter_str[];
8587 extern const char js_set_str[];
8588 extern const char js_source_str[];
8589 extern const char js_space_str[];
8590 extern const char js_stack_str[];
8591 extern const char js_sticky_str[];
8592 extern const char js_stago_str[];
8593 extern const char js_star_str[];
8594 extern const char js_starQualifier_str[];
8595 extern const char js_tagc_str[];
8596 extern const char js_toGMTString_str[];
8597 extern const char js_toLocaleString_str[];
8598 extern const char js_toSource_str[];
8599 extern const char js_toString_str[];
8600 extern const char js_toUTCString_str[];
8601 extern const char js_undefined_str[];
8602 extern const char js_valueOf_str[];
8603 extern const char js_toJSON_str[];
8604 extern const char js_xml_str[];
8605 extern const char js_enumerable_str[];
8606 extern const char js_configurable_str[];
8607 extern const char js_writable_str[];
8608 extern const char js_value_str[];
8609 extern const char js_test_str[];
8611 js_InitAtomState(JSRuntime *rt);
8613 js_FinishAtomState(JSRuntime *rt);
8615 js_TraceAtomState(JSTracer *trc);
8617 js_SweepAtomState(JSContext *cx);
8619 js_InitCommonAtoms(JSContext *cx);
8621 js_FinishCommonAtoms(JSContext *cx);
8623 js_AtomizeString(JSContext *cx, JSString *str, uintN flags);
8625 js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags);
8627 js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags);
8629 js_GetExistingStringAtom(JSContext *cx, const jschar *chars, size_t length);
8632 js_ValueToAtom(JSContext *cx, const js::Value &v, JSAtom **atomp);
8635 js_ValueToStringId(JSContext *cx, const js::Value &v, jsid *idp);
8638 js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval,
8642 js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval,
8643 jsid *idp, js::Value *vp);
8645 js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al);
8646 const uintN MIN_SPARSE_INDEX = 256;
8647 inline JSObject::EnsureDenseResult
8648 JSObject::ensureDenseArrayElements(JSContext *cx, uintN index, uintN extra)
8651 uintN currentCapacity = numSlots();
8652 uintN requiredCapacity;
8654 if (index < currentCapacity)
8656 requiredCapacity = index + 1;
8657 if (requiredCapacity == 0) {
8661 requiredCapacity = index + extra;
8662 if (requiredCapacity < index) {
8665 if (requiredCapacity <= currentCapacity)
8668 if (requiredCapacity > MIN_SPARSE_INDEX &&
8669 willBeSparseDenseArray(requiredCapacity, extra)) {
8672 return growSlots(cx, requiredCapacity) ? ED_OK : ED_FAILED;
8676 js_StringIsIndex(JSLinearString *str, jsuint *indexp);
8678 js_IdIsIndex(jsid id, jsuint *indexp)
8680 if (JSID_IS_INT(id)) {
8682 i = JSID_TO_INT(id);
8685 *indexp = (jsuint)i;
8688 if ((__builtin_expect((!JSID_IS_STRING(id)), 0)))
8690 return js_StringIsIndex(JSID_TO_ATOM(id), indexp);
8694 js_IdValIsIndex(JSContext *cx, jsval id, jsuint *indexp, bool *isIndex)
8696 if (JSVAL_IS_INT(id)) {
8698 i = JSVAL_TO_INT(id);
8703 *indexp = (jsuint)i;
8707 if (!JSVAL_IS_STRING(id)) {
8711 JSLinearString *str = JSVAL_TO_STRING(id)->ensureLinear(cx);
8714 *isIndex = js_StringIsIndex(str, indexp);
8717 extern js::Class js_ArrayClass, js_SlowArrayClass;
8720 JSObject::isDenseArray() const
8722 return getClass() == &js_ArrayClass;
8726 JSObject::isSlowArray() const
8728 return getClass() == &js_SlowArrayClass;
8732 JSObject::isArray() const
8734 return isDenseArray() || isSlowArray();
8736 static inline JSObject *
8737 js_GetProtoIfDenseArray(JSObject *obj)
8739 return obj->isDenseArray() ? obj->getProto() : obj;
8742 js_InitArrayClass(JSContext *cx, JSObject *obj);
8745 js_InitContextBusyArrayTable(JSContext *cx);
8749 NewDenseEmptyArray(JSContext *cx, JSObject *proto=__null);
8751 NewDenseAllocatedArray(JSContext *cx, uint length, JSObject *proto=__null);
8753 NewDenseUnallocatedArray(JSContext *cx, uint length, JSObject *proto=__null);
8755 NewDenseCopiedArray(JSContext *cx, uint length, Value *vp, JSObject *proto=__null);
8757 NewSlowEmptyArray(JSContext *cx);
8760 js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
8762 js_SetLengthProperty(JSContext *cx, JSObject *obj, jsdouble length);
8764 js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
8766 js_IndexToId(JSContext *cx, jsuint index, jsid *idp);
8770 GetElements(JSContext *cx, JSObject *aobj, jsuint length, js::Value *vp);
8772 typedef JSBool (*JSComparator)(void *arg, const void *a, const void *b,
8774 enum JSMergeSortElemType {
8780 js_MergeSort(void *vec, size_t nel, size_t elsize, JSComparator cmp,
8781 void *arg, void *tmp, JSMergeSortElemType elemType);
8784 array_sort(JSContext *cx, uintN argc, js::Value *vp);
8787 js_ArrayCompPush(JSContext *cx, JSObject *obj, const js::Value &vp);
8788 __attribute__((visibility ("default"))) JSBool
8789 js_CoerceArrayToCanvasImageData(JSObject *obj, jsuint offset, jsuint count,
8792 js_PrototypeHasIndexedProperties(JSContext *cx, JSObject *obj);
8794 js_GetDenseArrayElementValue(JSContext *cx, JSObject *obj, jsid id,
8797 js_Array(JSContext *cx, uintN argc, js::Value *vp);
8798 __attribute__((visibility ("default"))) JSBool
8799 js_CloneDensePrimitiveArray(JSContext *cx, JSObject *obj, JSObject **clone);
8800 __attribute__((visibility ("default"))) JSBool
8801 js_IsDensePrimitiveArray(JSObject *obj);
8803 js_EnsureDenseArrayCapacity(JSContext *cx, JSObject *obj, jsint i);
8804 extern js::Class js_BooleanClass;
8807 JSObject::isBoolean() const
8809 return getClass() == &js_BooleanClass;
8812 js_InitBooleanClass(JSContext *cx, JSObject *obj);
8814 js_BooleanToString(JSContext *cx, JSBool b);
8818 BooleanToStringBuffer(JSContext *cx, JSBool b, StringBuffer &sb);
8821 js_ValueToBoolean(const js::Value &v);
8823 typedef struct JSArena JSArena;
8824 typedef struct JSArenaPool JSArenaPool;
8831 struct JSArenaPool {
8838 extern __attribute__((visibility ("default"))) void
8839 JS_InitArenaPool(JSArenaPool *pool, const char *name, size_t size,
8840 size_t align, size_t *quotap);
8841 extern __attribute__((visibility ("default"))) void
8842 JS_FreeArenaPool(JSArenaPool *pool);
8843 extern __attribute__((visibility ("default"))) void
8844 JS_FinishArenaPool(JSArenaPool *pool);
8845 extern __attribute__((visibility ("default"))) void
8846 JS_ArenaFinish(void);
8847 extern __attribute__((visibility ("default"))) void
8848 JS_ArenaShutDown(void);
8849 extern __attribute__((visibility ("default"))) void *
8850 JS_ArenaAllocate(JSArenaPool *pool, size_t nb);
8851 extern __attribute__((visibility ("default"))) void *
8852 JS_ArenaRealloc(JSArenaPool *pool, void *p, size_t size, size_t incr);
8853 extern __attribute__((visibility ("default"))) void *
8854 JS_ArenaGrow(JSArenaPool *pool, void *p, size_t size, size_t incr);
8855 extern __attribute__((visibility ("default"))) void
8856 JS_ArenaRelease(JSArenaPool *pool, char *mark);
8858 typedef struct JSCListStr {
8859 struct JSCListStr *next;
8860 struct JSCListStr *prev;
8863 typedef uint32 JSDHashNumber;
8864 typedef struct JSDHashEntryHdr JSDHashEntryHdr;
8865 typedef struct JSDHashEntryStub JSDHashEntryStub;
8866 typedef struct JSDHashTable JSDHashTable;
8867 typedef struct JSDHashTableOps JSDHashTableOps;
8868 struct JSDHashEntryHdr {
8869 JSDHashNumber keyHash;
8871 struct JSDHashTable {
8872 const JSDHashTableOps *ops;
8879 uint32 removedCount;
8884 (* JSDHashAllocTable)(JSDHashTable *table, uint32 nbytes);
8886 (* JSDHashFreeTable) (JSDHashTable *table, void *ptr);
8887 typedef JSDHashNumber
8888 (* JSDHashHashKey) (JSDHashTable *table, const void *key);
8890 (* JSDHashMatchEntry)(JSDHashTable *table, const JSDHashEntryHdr *entry,
8893 (* JSDHashMoveEntry)(JSDHashTable *table, const JSDHashEntryHdr *from,
8894 JSDHashEntryHdr *to);
8896 (* JSDHashClearEntry)(JSDHashTable *table, JSDHashEntryHdr *entry);
8898 (* JSDHashFinalize) (JSDHashTable *table);
8900 (* JSDHashInitEntry)(JSDHashTable *table, JSDHashEntryHdr *entry,
8902 struct JSDHashTableOps {
8903 JSDHashAllocTable allocTable;
8904 JSDHashFreeTable freeTable;
8905 JSDHashHashKey hashKey;
8906 JSDHashMatchEntry matchEntry;
8907 JSDHashMoveEntry moveEntry;
8908 JSDHashClearEntry clearEntry;
8909 JSDHashFinalize finalize;
8910 JSDHashInitEntry initEntry;
8912 extern __attribute__((visibility ("default"))) void *
8913 JS_DHashAllocTable(JSDHashTable *table, uint32 nbytes);
8914 extern __attribute__((visibility ("default"))) void
8915 JS_DHashFreeTable(JSDHashTable *table, void *ptr);
8916 extern __attribute__((visibility ("default"))) JSDHashNumber
8917 JS_DHashStringKey(JSDHashTable *table, const void *key);
8918 struct JSDHashEntryStub {
8919 JSDHashEntryHdr hdr;
8922 extern __attribute__((visibility ("default"))) JSDHashNumber
8923 JS_DHashVoidPtrKeyStub(JSDHashTable *table, const void *key);
8924 extern __attribute__((visibility ("default"))) JSBool
8925 JS_DHashMatchEntryStub(JSDHashTable *table,
8926 const JSDHashEntryHdr *entry,
8928 extern __attribute__((visibility ("default"))) JSBool
8929 JS_DHashMatchStringKey(JSDHashTable *table,
8930 const JSDHashEntryHdr *entry,
8932 extern __attribute__((visibility ("default"))) void
8933 JS_DHashMoveEntryStub(JSDHashTable *table,
8934 const JSDHashEntryHdr *from,
8935 JSDHashEntryHdr *to);
8936 extern __attribute__((visibility ("default"))) void
8937 JS_DHashClearEntryStub(JSDHashTable *table, JSDHashEntryHdr *entry);
8938 extern __attribute__((visibility ("default"))) void
8939 JS_DHashFreeStringKey(JSDHashTable *table, JSDHashEntryHdr *entry);
8940 extern __attribute__((visibility ("default"))) void
8941 JS_DHashFinalizeStub(JSDHashTable *table);
8942 extern __attribute__((visibility ("default"))) const JSDHashTableOps *
8943 JS_DHashGetStubOps(void);
8944 extern __attribute__((visibility ("default"))) JSDHashTable *
8945 JS_NewDHashTable(const JSDHashTableOps *ops, void *data, uint32 entrySize,
8947 extern __attribute__((visibility ("default"))) void
8948 JS_DHashTableDestroy(JSDHashTable *table);
8949 extern __attribute__((visibility ("default"))) JSBool
8950 JS_DHashTableInit(JSDHashTable *table, const JSDHashTableOps *ops, void *data,
8951 uint32 entrySize, uint32 capacity);
8952 extern __attribute__((visibility ("default"))) void
8953 JS_DHashTableSetAlphaBounds(JSDHashTable *table,
8956 extern __attribute__((visibility ("default"))) void
8957 JS_DHashTableFinish(JSDHashTable *table);
8958 typedef enum JSDHashOperator {
8959 JS_DHASH_LOOKUP = 0,
8961 JS_DHASH_REMOVE = 2,
8965 extern __attribute__((visibility ("default"))) JSDHashEntryHdr *
8966 JS_DHashTableOperate(JSDHashTable *table, const void *key, JSDHashOperator op);
8967 extern __attribute__((visibility ("default"))) void
8968 JS_DHashTableRawRemove(JSDHashTable *table, JSDHashEntryHdr *entry);
8969 typedef JSDHashOperator
8970 (* JSDHashEnumerator)(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 number,
8972 extern __attribute__((visibility ("default"))) uint32
8973 JS_DHashTableEnumerate(JSDHashTable *table, JSDHashEnumerator etor, void *arg);
8980 js_DestroyDtoaState(DtoaState *state);
8982 js_strtod_harder(DtoaState *state, const char *s00, char **se, int *err);
8983 typedef enum JSDToStrMode {
8985 DTOSTR_STANDARD_EXPONENTIAL,
8991 js_dtostr(DtoaState *state, char *buffer, size_t bufferSize, JSDToStrMode mode, int precision,
8994 js_dtobasestr(DtoaState *state, int base, double d);
9068 JSOP_TABLESWITCH = 70,
9069 JSOP_LOOKUPSWITCH = 71,
9089 JSOP_NEWOBJECT = 91,
9099 JSOP_INCLOCAL = 101,
9100 JSOP_DECLOCAL = 102,
9101 JSOP_LOCALINC = 103,
9102 JSOP_LOCALDEC = 104,
9108 JSOP_BINDNAME = 110,
9112 JSOP_INSTANCEOF = 114,
9113 JSOP_DEBUGGER = 115,
9116 JSOP_EXCEPTION = 118,
9118 JSOP_CONDSWITCH = 120,
9122 JSOP_ENUMELEM = 124,
9126 JSOP_DEFCONST = 128,
9130 JSOP_SETLOCALPOP = 132,
9134 JSOP_GETFCSLOT = 136,
9135 JSOP_CALLFCSLOT = 137,
9138 JSOP_DEFLOCALFUN = 140,
9146 JSOP_DEFAULTX = 148,
9147 JSOP_TABLESWITCHX = 149,
9148 JSOP_LOOKUPSWITCHX = 150,
9149 JSOP_BACKPATCH = 151,
9150 JSOP_BACKPATCH_POP = 152,
9151 JSOP_THROWING = 153,
9154 JSOP_GETGNAME = 156,
9155 JSOP_SETGNAME = 157,
9156 JSOP_INCGNAME = 158,
9157 JSOP_DECGNAME = 159,
9158 JSOP_GNAMEINC = 160,
9159 JSOP_GNAMEDEC = 161,
9161 JSOP_DEFXMLNS = 163,
9163 JSOP_QNAMEPART = 165,
9164 JSOP_QNAMECONST = 166,
9166 JSOP_TOATTRNAME = 168,
9167 JSOP_TOATTRVAL = 169,
9168 JSOP_ADDATTRNAME = 170,
9169 JSOP_ADDATTRVAL = 171,
9170 JSOP_BINDXMLNAME = 172,
9171 JSOP_SETXMLNAME = 173,
9173 JSOP_DESCENDANTS = 175,
9175 JSOP_ENDFILTER = 177,
9177 JSOP_TOXMLLIST = 179,
9178 JSOP_XMLTAGEXPR = 180,
9179 JSOP_XMLELTEXPR = 181,
9181 JSOP_XMLCDATA = 183,
9182 JSOP_XMLCOMMENT = 184,
9185 JSOP_CALLPROP = 187,
9186 JSOP_BLOCKCHAIN = 188,
9187 JSOP_NULLBLOCKCHAIN = 189,
9189 JSOP_INDEXBASE = 191,
9190 JSOP_RESETBASE = 192,
9191 JSOP_RESETBASE0 = 193,
9192 JSOP_STARTXML = 194,
9193 JSOP_STARTXMLEXPR = 195,
9194 JSOP_CALLELEM = 196,
9196 JSOP_GETXPROP = 198,
9197 JSOP_CALLXMLNAME = 199,
9198 JSOP_TYPEOFEXPR = 200,
9199 JSOP_ENTERBLOCK = 201,
9200 JSOP_LEAVEBLOCK = 202,
9201 JSOP_IFPRIMTOP = 203,
9203 JSOP_GENERATOR = 205,
9205 JSOP_ARRAYPUSH = 207,
9206 JSOP_GETFUNNS = 208,
9207 JSOP_ENUMCONSTELEM = 209,
9208 JSOP_LEAVEBLOCKEXPR = 210,
9209 JSOP_GETTHISPROP = 211,
9210 JSOP_GETARGPROP = 212,
9211 JSOP_GETLOCALPROP = 213,
9212 JSOP_INDEXBASE1 = 214,
9213 JSOP_INDEXBASE2 = 215,
9214 JSOP_INDEXBASE3 = 216,
9215 JSOP_CALLGNAME = 217,
9216 JSOP_CALLLOCAL = 218,
9218 JSOP_BINDGNAME = 220,
9223 JSOP_DEFFUN_FC = 225,
9224 JSOP_DEFLOCALFUN_FC = 226,
9225 JSOP_LAMBDA_FC = 227,
9228 JSOP_GETUPVAR_DBG = 230,
9229 JSOP_CALLUPVAR_DBG = 231,
9230 JSOP_DEFFUN_DBGFC = 232,
9231 JSOP_DEFLOCALFUN_DBGFC = 233,
9232 JSOP_LAMBDA_DBGFC = 234,
9233 JSOP_SETMETHOD = 235,
9234 JSOP_INITMETHOD = 236,
9236 JSOP_UNBRANDTHIS = 238,
9237 JSOP_SHARPINIT = 239,
9238 JSOP_GETGLOBAL = 240,
9239 JSOP_CALLGLOBAL = 241,
9241 JSOP_FORGNAME = 243,
9243 JSOP_GETPROP2 = JSOP_LIMIT,
9244 JSOP_GETELEM2 = JSOP_LIMIT + 1,
9245 JSOP_FAKE_LIMIT = JSOP_GETELEM2
9253 uint32 type() const { return ((format) & 0x001f); }
9255 extern const JSCodeSpec js_CodeSpec[];
9256 extern uintN js_NumCodeSpecs;
9257 extern const char *js_CodeName[];
9258 extern const char js_EscapeMap[];
9260 js_QuoteString(JSContext *cx, JSString *str, jschar quote);
9262 js_NewPrinter(JSContext *cx, const char *name, JSFunction *fun,
9263 uintN indent, JSBool pretty, JSBool grouped, JSBool strict);
9265 js_DestroyPrinter(JSPrinter *jp);
9267 js_GetPrinterOutput(JSPrinter *jp);
9269 js_printf(JSPrinter *jp, const char *format, ...);
9271 js_puts(JSPrinter *jp, const char *s);
9273 js_GetIndexFromBytecode(JSContext *cx, JSScript *script, jsbytecode *pc,
9276 js_GetVariableBytecodeLength(jsbytecode *pc);
9278 js_GetVariableStackUses(JSOp op, jsbytecode *pc);
9280 js_GetEnterBlockStackDefs(JSContext *cx, JSScript *script, jsbytecode *pc);
9282 js_GetStackUses(const JSCodeSpec *cs, JSOp op, jsbytecode *pc)
9287 return js_GetVariableStackUses(op, pc);
9290 js_GetStackDefs(JSContext *cx, const JSCodeSpec *cs, JSOp op, JSScript *script,
9297 return js_GetEnterBlockStackDefs(cx, script, pc);
9300 js_DecompileScript(JSPrinter *jp, JSScript *script);
9302 js_DecompileFunctionBody(JSPrinter *jp);
9304 js_DecompileFunction(JSPrinter *jp);
9305 typedef JSBool (* JSDecompilerPtr)(JSPrinter *);
9307 js_DecompileToString(JSContext *cx, const char *name, JSFunction *fun,
9308 uintN indent, JSBool pretty, JSBool grouped, JSBool strict,
9309 JSDecompilerPtr decompiler);
9311 js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v,
9312 JSString *fallback);
9314 static inline char *
9315 DecompileValueGenerator(JSContext *cx, intN spindex, const Value &v,
9318 return js_DecompileValueGenerator(cx, spindex, Jsvalify(v), fallback);
9322 js_ReconstructStackDepth(JSContext *cx, JSScript *script, jsbytecode *pc);
9325 extern __attribute__((visibility ("default"))) JSCrossCompartmentCall *
9326 JS_EnterCrossCompartmentCallScript(JSContext *cx, JSScript *target);
9329 class __attribute__((visibility ("default"))) AutoEnterScriptCompartment
9331 JSCrossCompartmentCall *call;
9333 AutoEnterScriptCompartment() : call(__null) {}
9334 bool enter(JSContext *cx, JSScript *target);
9335 bool entered() const { return call != __null; }
9336 ~AutoEnterScriptCompartment() {
9337 if (call && call != reinterpret_cast<JSCrossCompartmentCall*>(1))
9338 JS_LeaveCrossCompartmentCall(call);
9343 extern __attribute__((visibility ("default"))) JSScript *
9344 JS_GetScriptFromObject(JSObject *scriptObject);
9345 extern __attribute__((visibility ("default"))) JSString *
9346 JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, uintN indent);
9347 extern __attribute__((visibility ("default"))) void
9348 JS_SetRuntimeDebugMode(JSRuntime *rt, JSBool debug);
9349 extern __attribute__((visibility ("default"))) JSBool
9350 JS_GetDebugMode(JSContext *cx);
9351 __attribute__((visibility ("default"))) JSBool
9352 JS_SetDebugModeForCompartment(JSContext *cx, JSCompartment *comp, JSBool debug);
9353 __attribute__((visibility ("default"))) JSBool
9354 JS_SetDebugMode(JSContext *cx, JSBool debug);
9355 extern __attribute__((visibility ("default"))) JSBool
9356 js_SetSingleStepMode(JSContext *cx, JSScript *script, JSBool singleStep);
9357 extern __attribute__((visibility ("default"))) JSBool
9358 JS_SetSingleStepMode(JSContext *cx, JSScript *script, JSBool singleStep);
9360 js_UntrapScriptCode(JSContext *cx, JSScript *script);
9361 extern __attribute__((visibility ("default"))) JSBool
9362 JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
9363 JSTrapHandler handler, jsval closure);
9364 extern __attribute__((visibility ("default"))) JSOp
9365 JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc);
9366 extern __attribute__((visibility ("default"))) void
9367 JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
9368 JSTrapHandler *handlerp, jsval *closurep);
9369 extern __attribute__((visibility ("default"))) void
9370 JS_ClearScriptTraps(JSContext *cx, JSScript *script);
9371 extern __attribute__((visibility ("default"))) void
9372 JS_ClearAllTraps(JSContext *cx);
9373 extern __attribute__((visibility ("default"))) JSTrapStatus
9374 JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval);
9375 extern __attribute__((visibility ("default"))) JSBool
9376 JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure);
9377 extern __attribute__((visibility ("default"))) JSBool
9378 JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep);
9379 extern __attribute__((visibility ("default"))) JSBool
9380 JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id,
9381 JSWatchPointHandler handler, JSObject *closure);
9382 extern __attribute__((visibility ("default"))) JSBool
9383 JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id,
9384 JSWatchPointHandler *handlerp, JSObject **closurep);
9385 extern __attribute__((visibility ("default"))) JSBool
9386 JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj);
9387 extern __attribute__((visibility ("default"))) JSBool
9388 JS_ClearAllWatchPoints(JSContext *cx);
9390 js_TraceWatchPoints(JSTracer *trc, JSObject *obj);
9392 js_SweepWatchPoints(JSContext *cx);
9394 js_watch_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp);
9397 IsWatchedProperty(JSContext *cx, const Shape *shape);
9399 extern __attribute__((visibility ("default"))) uintN
9400 JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
9401 extern __attribute__((visibility ("default"))) jsbytecode *
9402 JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno);
9403 extern __attribute__((visibility ("default"))) jsbytecode *
9404 JS_EndPC(JSContext *cx, JSScript *script);
9405 extern __attribute__((visibility ("default"))) uintN
9406 JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun);
9407 extern __attribute__((visibility ("default"))) JSBool
9408 JS_FunctionHasLocalNames(JSContext *cx, JSFunction *fun);
9409 extern __attribute__((visibility ("default"))) jsuword *
9410 JS_GetFunctionLocalNameArray(JSContext *cx, JSFunction *fun, void **markp);
9411 extern __attribute__((visibility ("default"))) JSAtom *
9412 JS_LocalNameToAtom(jsuword w);
9413 extern __attribute__((visibility ("default"))) JSString *
9414 JS_AtomKey(JSAtom *atom);
9415 extern __attribute__((visibility ("default"))) void
9416 JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark);
9417 extern __attribute__((visibility ("default"))) JSScript *
9418 JS_GetFunctionScript(JSContext *cx, JSFunction *fun);
9419 extern __attribute__((visibility ("default"))) JSNative
9420 JS_GetFunctionNative(JSContext *cx, JSFunction *fun);
9421 extern __attribute__((visibility ("default"))) JSPrincipals *
9422 JS_GetScriptPrincipals(JSContext *cx, JSScript *script);
9423 extern __attribute__((visibility ("default"))) JSStackFrame *
9424 JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp);
9425 extern __attribute__((visibility ("default"))) JSScript *
9426 JS_GetFrameScript(JSContext *cx, JSStackFrame *fp);
9427 extern __attribute__((visibility ("default"))) jsbytecode *
9428 JS_GetFramePC(JSContext *cx, JSStackFrame *fp);
9429 extern __attribute__((visibility ("default"))) JSStackFrame *
9430 JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp);
9431 extern JSPrincipals *
9432 js_StackFramePrincipals(JSContext *cx, JSStackFrame *fp);
9434 js_EvalFramePrincipals(JSContext *cx, JSObject *callee, JSStackFrame *caller);
9435 extern __attribute__((visibility ("default"))) void *
9436 JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp);
9437 extern __attribute__((visibility ("default"))) void
9438 JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation);
9439 extern __attribute__((visibility ("default"))) void *
9440 JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp);
9441 extern __attribute__((visibility ("default"))) JSBool
9442 JS_IsScriptFrame(JSContext *cx, JSStackFrame *fp);
9443 extern __attribute__((visibility ("default"))) JSObject *
9444 JS_GetFrameObject(JSContext *cx, JSStackFrame *fp);
9445 extern __attribute__((visibility ("default"))) JSObject *
9446 JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp);
9447 extern __attribute__((visibility ("default"))) JSObject *
9448 JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp);
9449 extern __attribute__((visibility ("default"))) JSBool
9450 JS_GetFrameThis(JSContext *cx, JSStackFrame *fp, jsval *thisv);
9451 extern __attribute__((visibility ("default"))) JSFunction *
9452 JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp);
9453 extern __attribute__((visibility ("default"))) JSObject *
9454 JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp);
9455 extern __attribute__((visibility ("default"))) JSBool
9456 JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp);
9457 extern __attribute__((visibility ("default"))) JSBool
9458 JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp);
9459 extern __attribute__((visibility ("default"))) jsval
9460 JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp);
9461 extern __attribute__((visibility ("default"))) void
9462 JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval);
9463 extern __attribute__((visibility ("default"))) JSObject *
9464 JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp);
9465 extern __attribute__((visibility ("default"))) JSBool
9466 JS_GetValidFrameCalleeObject(JSContext *cx, JSStackFrame *fp, jsval *vp);
9467 extern __attribute__((visibility ("default"))) const char *
9468 JS_GetScriptFilename(JSContext *cx, JSScript *script);
9469 extern __attribute__((visibility ("default"))) uintN
9470 JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script);
9471 extern __attribute__((visibility ("default"))) uintN
9472 JS_GetScriptLineExtent(JSContext *cx, JSScript *script);
9473 extern __attribute__((visibility ("default"))) JSVersion
9474 JS_GetScriptVersion(JSContext *cx, JSScript *script);
9475 extern __attribute__((visibility ("default"))) void
9476 JS_SetNewScriptHookProc(JSRuntime *rt, JSNewScriptHook hook, void *callerdata);
9477 extern __attribute__((visibility ("default"))) void
9478 JS_SetDestroyScriptHookProc(JSRuntime *rt, JSDestroyScriptHook hook,
9480 extern __attribute__((visibility ("default"))) JSBool
9481 JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
9482 const jschar *chars, uintN length,
9483 const char *filename, uintN lineno,
9485 extern __attribute__((visibility ("default"))) JSBool
9486 JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
9487 const char *bytes, uintN length,
9488 const char *filename, uintN lineno,
9490 typedef struct JSPropertyDesc {
9498 typedef struct JSPropertyDescArray {
9500 JSPropertyDesc *array;
9501 } JSPropertyDescArray;
9502 typedef struct JSScopeProperty JSScopeProperty;
9503 extern __attribute__((visibility ("default"))) JSScopeProperty *
9504 JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp);
9505 extern __attribute__((visibility ("default"))) JSBool
9506 JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *shape,
9507 JSPropertyDesc *pd);
9508 extern __attribute__((visibility ("default"))) JSBool
9509 JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda);
9510 extern __attribute__((visibility ("default"))) void
9511 JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
9512 extern __attribute__((visibility ("default"))) JSBool
9513 JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure);
9514 extern __attribute__((visibility ("default"))) JSBool
9515 JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
9516 extern __attribute__((visibility ("default"))) JSBool
9517 JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
9518 extern __attribute__((visibility ("default"))) JSBool
9519 JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
9520 extern __attribute__((visibility ("default"))) JSBool
9521 JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure);
9522 extern __attribute__((visibility ("default"))) JSBool
9523 JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure);
9524 extern __attribute__((visibility ("default"))) size_t
9525 JS_GetObjectTotalSize(JSContext *cx, JSObject *obj);
9526 extern __attribute__((visibility ("default"))) size_t
9527 JS_GetFunctionTotalSize(JSContext *cx, JSFunction *fun);
9528 extern __attribute__((visibility ("default"))) size_t
9529 JS_GetScriptTotalSize(JSContext *cx, JSScript *script);
9530 extern __attribute__((visibility ("default"))) uint32
9531 JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp);
9532 extern __attribute__((visibility ("default"))) uint32
9533 JS_GetScriptFilenameFlags(JSScript *script);
9534 extern __attribute__((visibility ("default"))) JSBool
9535 JS_FlagScriptFilenamePrefix(JSRuntime *rt, const char *prefix, uint32 flags);
9536 extern __attribute__((visibility ("default"))) JSBool
9537 JS_IsSystemObject(JSContext *cx, JSObject *obj);
9538 extern __attribute__((visibility ("default"))) JSBool
9539 JS_MakeSystemObject(JSContext *cx, JSObject *obj);
9540 extern __attribute__((visibility ("default"))) JSObject *
9541 JS_UnwrapObject(JSContext *cx, JSObject *obj);
9542 extern __attribute__((visibility ("default"))) void
9543 js_RevertVersion(JSContext *cx);
9544 extern __attribute__((visibility ("default"))) const JSDebugHooks *
9545 JS_GetGlobalDebugHooks(JSRuntime *rt);
9546 extern __attribute__((visibility ("default"))) JSDebugHooks *
9547 JS_SetContextDebugHooks(JSContext *cx, const JSDebugHooks *hooks);
9548 extern __attribute__((visibility ("default"))) JSDebugHooks *
9549 JS_ClearContextDebugHooks(JSContext *cx);
9550 extern __attribute__((visibility ("default"))) JSBool
9551 JS_StartProfiling();
9552 extern __attribute__((visibility ("default"))) void
9554 extern __attribute__((visibility ("default"))) JSBool
9555 JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj);
9557 typedef enum JSTryNoteKind {
9566 static const uint32 FREE_VALUE = 0xfffffffful;
9567 void checkInvariants() {
9568 typedef int js_static_assert47[(sizeof(UpvarCookie) == sizeof(uint32)) ? 1 : -1];
9569 typedef int js_static_assert48[(UPVAR_LEVEL_LIMIT < FREE_LEVEL) ? 1 : -1];
9572 static const uint16 FREE_LEVEL = 0x3fff;
9573 static const uint16 UPVAR_LEVEL_LIMIT = 16;
9574 static const uint16 CALLEE_SLOT = 0xffff;
9575 static bool isLevelReserved(uint16 level) { return level >= FREE_LEVEL; }
9576 bool isFree() const { return value == FREE_VALUE; }
9577 uint32 asInteger() const { return value; }
9578 uint16 level() const { ((void) 0); return uint16(value >> 16); }
9579 uint16 slot() const { ((void) 0); return uint16(value); }
9580 void set(const UpvarCookie &other) { set(other.level(), other.slot()); }
9581 void set(uint16 newLevel, uint16 newSlot) { value = (uint32(newLevel) << 16) | newSlot; }
9582 void makeFree() { set(0xffff, 0xffff); ((void) 0); }
9583 void fromInteger(uint32 u32) { value = u32; }
9593 typedef struct JSTryNoteArray {
9597 typedef struct JSObjectArray {
9601 typedef struct JSUpvarArray {
9602 js::UpvarCookie *vector;
9605 typedef struct JSConstArray {
9611 struct GlobalSlotArray {
9620 enum BindingKind { NONE, ARGUMENT, VARIABLE, CONSTANT, UPVAR };
9622 js::Shape *lastBinding;
9627 inline Bindings(JSContext *cx);
9628 inline void transfer(JSContext *cx, Bindings *bindings);
9629 inline void clone(JSContext *cx, Bindings *bindings);
9630 uint16 countArgs() const { return nargs; }
9631 uint16 countVars() const { return nvars; }
9632 uint16 countUpvars() const { return nupvars; }
9633 uintN countArgsAndVars() const { return nargs + nvars; }
9634 uintN countLocalNames() const { return nargs + nvars + nupvars; }
9635 bool hasUpvars() const { return nupvars > 0; }
9636 bool hasLocalNames() const { return countLocalNames() > 0; }
9637 inline const js::Shape *lastShape() const;
9639 BINDING_COUNT_LIMIT = 0xFFFF
9641 bool add(JSContext *cx, JSAtom *name, BindingKind kind);
9642 bool addVariable(JSContext *cx, JSAtom *name) {
9643 return add(cx, name, VARIABLE);
9645 bool addConstant(JSContext *cx, JSAtom *name) {
9646 return add(cx, name, CONSTANT);
9648 bool addUpvar(JSContext *cx, JSAtom *name) {
9649 return add(cx, name, UPVAR);
9651 bool addArgument(JSContext *cx, JSAtom *name, uint16 *slotp) {
9654 return add(cx, name, ARGUMENT);
9656 bool addDestructuring(JSContext *cx, uint16 *slotp) {
9658 return add(cx, __null, ARGUMENT);
9660 BindingKind lookup(JSContext *cx, JSAtom *name, uintN *indexp) const;
9661 bool hasBinding(JSContext *cx, JSAtom *name) const {
9662 return lookup(cx, name, __null) != NONE;
9665 getLocalNameArray(JSContext *cx, JSArenaPool *pool);
9666 int sharpSlotBase(JSContext *cx);
9667 void makeImmutable();
9668 const js::Shape *lastArgument() const;
9669 const js::Shape *lastVariable() const;
9670 const js::Shape *lastUpvar() const;
9671 void trace(JSTracer *trc);
9675 static JSScript *NewScript(JSContext *cx, uint32 length, uint32 nsrcnotes, uint32 natoms,
9676 uint32 nobjects, uint32 nupvars, uint32 nregexps,
9677 uint32 ntrynotes, uint32 nconsts, uint32 nglobals,
9678 uint16 nClosedArgs, uint16 nClosedVars, JSVersion version);
9679 static JSScript *NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg);
9688 uint8 objectsOffset;
9690 uint8 regexpsOffset;
9691 uint8 trynotesOffset;
9692 uint8 globalsOffset;
9694 bool noScriptRval:1;
9695 bool savedCallerFun:1;
9697 bool strictModeCode:1;
9698 bool compileAndGo:1;
9700 bool usesArguments:1;
9701 bool warnedAboutTwoArgumentEval:1;
9702 bool hasSingletons:1;
9705 JSCompartment *compartment;
9706 const char *filename;
9712 js::Bindings bindings;
9713 JSPrincipals *principals;
9718 uint32 *closedSlots;
9720 jssrcnote *notes() { return (jssrcnote *)(code + length); }
9721 static const uint8 INVALID_OFFSET = 0xFF;
9722 static bool isValidOffset(uint8 offset) { return offset != INVALID_OFFSET; }
9723 JSObjectArray *objects() {
9725 return (JSObjectArray *)((uint8 *) (this + 1) + objectsOffset);
9727 JSUpvarArray *upvars() {
9729 return (JSUpvarArray *) ((uint8 *) (this + 1) + upvarsOffset);
9731 JSObjectArray *regexps() {
9733 return (JSObjectArray *) ((uint8 *) (this + 1) + regexpsOffset);
9735 JSTryNoteArray *trynotes() {
9737 return (JSTryNoteArray *) ((uint8 *) (this + 1) + trynotesOffset);
9739 js::GlobalSlotArray *globals() {
9741 return (js::GlobalSlotArray *) ((uint8 *) (this + 1) + globalsOffset);
9743 JSConstArray *consts() {
9745 return (JSConstArray *) ((uint8 *) (this + 1) + constOffset);
9747 JSAtom *getAtom(size_t index) {
9749 return atomMap.vector[index];
9751 JSObject *getObject(size_t index) {
9752 JSObjectArray *arr = objects();
9754 return arr->vector[index];
9756 uint32 getGlobalSlot(size_t index) {
9757 js::GlobalSlotArray *arr = globals();
9759 return arr->vector[index].slot;
9761 JSAtom *getGlobalAtom(size_t index) {
9762 js::GlobalSlotArray *arr = globals();
9764 return getAtom(arr->vector[index].atomIndex);
9766 JSVersion getVersion() const {
9767 return JSVersion(version);
9769 inline JSFunction *getFunction(size_t index);
9770 inline JSObject *getRegExp(size_t index);
9771 const js::Value &getConst(size_t index) {
9772 JSConstArray *arr = consts();
9774 return arr->vector[index];
9776 inline bool isEmpty() const;
9777 uint32 getClosedArg(uint32 index) {
9779 return closedSlots[index];
9781 uint32 getClosedVar(uint32 index) {
9783 return closedSlots[nClosedArgs + index];
9785 void copyClosedSlotsTo(JSScript *other);
9788 StackDepth(JSScript *script)
9790 return script->nslots - script->nfixed;
9792 extern __attribute__((visibility ("default"))) js::Class js_ScriptClass;
9794 js_InitScriptClass(JSContext *cx, JSObject *obj);
9796 js_InitRuntimeScriptState(JSRuntime *rt);
9798 js_FreeRuntimeScriptState(JSRuntime *rt);
9800 js_SaveScriptFilename(JSContext *cx, const char *filename);
9802 js_SaveScriptFilenameRT(JSRuntime *rt, const char *filename, uint32 flags);
9804 js_GetScriptFilenameFlags(const char *filename);
9806 js_MarkScriptFilename(const char *filename);
9808 js_MarkScriptFilenames(JSRuntime *rt);
9810 js_SweepScriptFilenames(JSRuntime *rt);
9811 extern __attribute__((visibility ("default"))) void
9812 js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun);
9814 js_CallDestroyScriptHook(JSContext *cx, JSScript *script);
9816 js_DestroyScript(JSContext *cx, JSScript *script);
9818 js_DestroyScriptFromGC(JSContext *cx, JSScript *script);
9820 js_DestroyCachedScript(JSContext *cx, JSScript *script);
9822 js_TraceScript(JSTracer *trc, JSScript *script);
9824 js_NewScriptObject(JSContext *cx, JSScript *script);
9826 js_GetSrcNoteCached(JSContext *cx, JSScript *script, jsbytecode *pc);
9828 js_FramePCToLineNumber(JSContext *cx, JSStackFrame *fp);
9830 js_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
9832 js_LineNumberToPC(JSScript *script, uintN lineno);
9833 extern __attribute__((visibility ("default"))) uintN
9834 js_GetScriptLineExtent(JSScript *script);
9836 js_GetOpcode(JSContext *cx, JSScript *script, jsbytecode *pc)
9838 JSOp op = (JSOp) *pc;
9839 if (op == JSOP_TRAP)
9840 op = JS_GetTrapOpcode(cx, script, pc);
9844 js_CloneScript(JSContext *cx, JSScript *script);
9846 js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic);
9849 JSObject::isScript() const
9851 return getClass() == &js_ScriptClass;
9854 JSObject::getScript() const
9857 return static_cast<JSScript *>(getPrivate());
9859 struct JSFunction : public JSObject_Slots2
9867 JSNativeTraceInfo *trcinfo;
9872 JSPackedBool wrapper;
9875 void *nativeOrScript;
9878 bool optimizedClosure() const { return ((this)->flags & 0xc000) > 0x4000; }
9879 bool needsWrapper() const { return (((this)->flags & 0xc000) == 0xc000) && u.i.skipmin != 0; }
9880 bool isInterpreted() const { return (((this)->flags & 0xc000) >= 0x4000); }
9881 bool isNative() const { return !(((this)->flags & 0xc000) >= 0x4000); }
9882 bool isConstructor() const { return flags & 0x0200; }
9883 bool isHeavyweight() const { return ((flags) & 0x80); }
9884 bool isFlatClosure() const { return ((this)->flags & 0xc000) == 0x8000; }
9885 bool isFunctionPrototype() const { return flags & 0x0800; }
9886 inline bool inStrictMode() const;
9887 void setArgCount(uint16 nargs) {
9889 this->nargs = nargs;
9891 enum { MAX_ARGS_AND_VARS = 2 * ((1U << 16) - 1) };
9892 bool mightEscape() const {
9893 return isInterpreted() && (isFlatClosure() || !script()->bindings.hasUpvars());
9895 bool joinable() const {
9896 return flags & 0x0001;
9898 JSObject &compiledFunObj() {
9903 METHOD_ATOM_SLOT = JSSLOT_FUN_METHOD_ATOM
9906 void setJoinable() {
9908 getSlotRef(METHOD_ATOM_SLOT).setNull();
9911 JSAtom *methodAtom() const {
9912 return (joinable() && getSlot(METHOD_ATOM_SLOT).isString())
9913 ? (((void) 0), (JSAtom *)getSlot(METHOD_ATOM_SLOT).toString())
9916 void setMethodAtom(JSAtom *atom) {
9918 getSlotRef(METHOD_ATOM_SLOT).setString((atom));
9920 js::Native maybeNative() const {
9921 return isInterpreted() ? __null : u.n.native;
9923 JSScript *script() const {
9927 static uintN offsetOfNativeOrScript() {
9928 typedef int js_static_assert49[(__builtin_offsetof (U, n.native) == __builtin_offsetof (U, i.script)) ? 1 : -1];
9929 typedef int js_static_assert50[(__builtin_offsetof (U, n.native) == __builtin_offsetof (U, nativeOrScript)) ? 1 : -1];
9930 return __builtin_offsetof (JSFunction, u.nativeOrScript);
9932 static const uint32 CLASS_RESERVED_SLOTS = JSObject::FUN_CLASS_RESERVED_SLOTS;
9934 extern js::Class js_ArgumentsClass;
9936 extern Class StrictArgumentsClass;
9937 struct ArgumentsData {
9944 JSObject::isNormalArguments() const
9946 return getClass() == &js_ArgumentsClass;
9950 JSObject::isStrictArguments() const
9952 return getClass() == &js::StrictArgumentsClass;
9956 JSObject::isArguments() const
9958 return isNormalArguments() || isStrictArguments();
9960 extern __attribute__((visibility ("default"))) js::Class js_CallClass;
9961 extern __attribute__((visibility ("default"))) js::Class js_FunctionClass;
9962 extern js::Class js_DeclEnvClass;
9965 JSObject::isCall() const
9967 return getClass() == &js_CallClass;
9971 JSObject::isFunction() const
9973 return getClass() == &js_FunctionClass;
9976 JSObject::getFunctionPrivate() const
9979 return reinterpret_cast<JSFunction *>(getPrivate());
9983 NewCallObject(JSContext *cx, js::Bindings *bindings, JSObject &scopeChain, JSObject *callee);
9984 static __attribute__((always_inline)) inline
9986 IsFunctionObject(const js::Value &v)
9988 return v.isObject() && v.toObject().isFunction();
9990 static __attribute__((always_inline)) inline
9992 IsFunctionObject(const js::Value &v, JSObject **funobj)
9994 return v.isObject() && (*funobj = &v.toObject())->isFunction();
9996 static __attribute__((always_inline)) inline
9998 IsFunctionObject(const js::Value &v, JSFunction **fun)
10001 bool b = IsFunctionObject(v, &funobj);
10003 *fun = funobj->getFunctionPrivate();
10006 extern __attribute__((always_inline)) inline
10008 SameTraceType(const Value &lhs, const Value &rhs)
10010 return SameType(lhs, rhs) &&
10011 (lhs.isPrimitive() ||
10012 lhs.toObject().isFunction() == rhs.toObject().isFunction());
10016 IsInternalFunctionObject(JSObject *funobj)
10019 JSFunction *fun = (JSFunction *) funobj->getPrivate();
10020 return funobj == fun && (fun->flags & 0x08) && !funobj->getParent();
10022 static __attribute__((always_inline)) inline
10024 IsConstructing(const Value *vp)
10026 return vp[1].isMagic();
10028 static __attribute__((always_inline)) inline
10030 IsConstructing_PossiblyWithGivenThisObject(const Value *vp, JSObject **ctorThis)
10032 bool isCtor = vp[1].isMagic();
10034 *ctorThis = vp[1].getMagicObjectOrNullPayload();
10037 inline const char *
10038 GetFunctionNameBytes(JSContext *cx, JSFunction *fun, JSAutoByteString *bytes)
10041 return bytes->encode(cx, (fun->atom));
10042 return js_anonymous_str;
10044 extern __attribute__((visibility ("default"))) bool
10045 IsBuiltinFunctionConstructor(JSFunction *fun);
10047 LookupInterpretedFunctionPrototype(JSContext *cx, JSObject *funobj);
10050 fun_toStringHelper(JSContext *cx, JSObject *obj, uintN indent);
10051 extern JSFunction *
10052 js_NewFunction(JSContext *cx, JSObject *funobj, js::Native native, uintN nargs,
10053 uintN flags, JSObject *parent, JSAtom *atom);
10055 js_InitFunctionClass(JSContext *cx, JSObject *obj);
10057 js_InitArgumentsClass(JSContext *cx, JSObject *obj);
10059 js_TraceFunction(JSTracer *trc, JSFunction *fun);
10061 js_FinalizeFunction(JSContext *cx, JSFunction *fun);
10063 js_CloneFunctionObject(JSContext *cx, JSFunction *fun, JSObject *parent,
10066 CloneFunctionObject(JSContext *cx, JSFunction *fun, JSObject *parent)
10070 if (!js_GetClassPrototype(cx, parent, JSProto_Function, &proto))
10072 return js_CloneFunctionObject(cx, fun, parent, proto);
10075 js_AllocFlatClosure(JSContext *cx, JSFunction *fun, JSObject *scopeChain);
10077 js_NewFlatClosure(JSContext *cx, JSFunction *fun, JSOp op, size_t oplen);
10079 js_NewDebuggableFlatClosure(JSContext *cx, JSFunction *fun);
10080 extern JSFunction *
10081 js_DefineFunction(JSContext *cx, JSObject *obj, jsid id, js::Native native,
10082 uintN nargs, uintN flags);
10083 extern JSFunction *
10084 js_ValueToFunction(JSContext *cx, const js::Value *vp, uintN flags);
10086 js_ValueToFunctionObject(JSContext *cx, js::Value *vp, uintN flags);
10088 js_ValueToCallableObject(JSContext *cx, js::Value *vp, uintN flags);
10090 js_ReportIsNotFunction(JSContext *cx, const js::Value *vp, uintN flags);
10092 js_GetCallObject(JSContext *cx, JSStackFrame *fp);
10094 js_CreateCallObjectOnTrace(JSContext *cx, JSFunction *fun, JSObject *callee, JSObject *scopeChain);
10096 js_PutCallObject(JSContext *cx, JSStackFrame *fp);
10098 js_PutCallObjectOnTrace(JSContext *cx, JSObject *scopeChain, uint32 nargs,
10099 js::Value *argv, uint32 nvars, js::Value *slots);
10102 GetCallArg(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
10104 GetCallVar(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
10106 GetCallVarChecked(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
10108 GetCallUpvar(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
10110 SetCallArg(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp);
10112 SetCallVar(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp);
10114 SetCallUpvar(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp);
10117 js_GetArgsValue(JSContext *cx, JSStackFrame *fp, js::Value *vp);
10119 js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, js::Value *vp);
10121 js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
10123 js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
10126 js_IsNamedLambda(JSFunction *fun) { return (fun->flags & 0x08) && fun->atom; }
10127 const uint32 JS_ARGS_LENGTH_MAX = ((JSUint32)1 << (19)) - 1024;
10128 typedef int js_static_assert51[(JS_ARGS_LENGTH_MAX <= ((JSUint32)1 << (30))) ? 1 : -1];
10129 typedef int js_static_assert52[(((JS_ARGS_LENGTH_MAX << 1) | 1) <= ((jsint)0x7fffffff)) ? 1 : -1];
10131 js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp);
10133 js_fun_apply(JSContext *cx, uintN argc, js::Value *vp);
10135 js_fun_call(JSContext *cx, uintN argc, js::Value *vp);
10137 typedef long int __jmp_buf[64] __attribute__ ((__aligned__ (16)));
10138 struct __jmp_buf_tag
10140 __jmp_buf __jmpbuf;
10141 int __mask_was_saved;
10142 __sigset_t __saved_mask;
10144 typedef struct __jmp_buf_tag jmp_buf[1];
10145 extern int setjmp (jmp_buf __env) throw ();
10146 extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) throw ();
10147 extern int _setjmp (struct __jmp_buf_tag __env[1]) throw ();
10148 extern void longjmp (struct __jmp_buf_tag __env[1], int __val)
10149 throw () __attribute__ ((__noreturn__));
10150 extern void _longjmp (struct __jmp_buf_tag __env[1], int __val)
10151 throw () __attribute__ ((__noreturn__));
10152 typedef struct __jmp_buf_tag sigjmp_buf[1];
10153 extern void siglongjmp (sigjmp_buf __env, int __val)
10154 throw () __attribute__ ((__noreturn__));
10155 extern void longjmp (struct __jmp_buf_tag __env[1], int __val) throw () __asm__ ("" "__longjmp_chk")
10156 __attribute__ ((__noreturn__));
10157 extern void _longjmp (struct __jmp_buf_tag __env[1], int __val) throw () __asm__ ("" "__longjmp_chk")
10158 __attribute__ ((__noreturn__));
10159 extern void siglongjmp (struct __jmp_buf_tag __env[1], int __val) throw () __asm__ ("" "__longjmp_chk")
10160 __attribute__ ((__noreturn__));
10163 const size_t GC_CHUNK_SHIFT = 20;
10164 const size_t GC_CHUNK_SIZE = size_t(1) << GC_CHUNK_SHIFT;
10165 const size_t GC_CHUNK_MASK = GC_CHUNK_SIZE - 1;
10166 __attribute__((visibility ("default"))) void *
10168 __attribute__((visibility ("default"))) void
10169 FreeGCChunk(void *p);
10170 class GCChunkAllocator {
10172 GCChunkAllocator() {}
10174 void *chunk = doAlloc();
10178 void free(void *chunk) {
10184 virtual void *doAlloc() {
10185 return AllocGCChunk();
10187 virtual void doFree(void *chunk) {
10188 FreeGCChunk(chunk);
10190 GCChunkAllocator(const GCChunkAllocator &);
10191 void operator=(const GCChunkAllocator &);
10193 extern GCChunkAllocator defaultGCChunkAllocator;
10197 enum ConservativeGCTest {
10199 CGCT_VALIDWITHOFFSET,
10208 struct ConservativeGCStats {
10209 uint32 counter[gc::CGCT_END];
10210 void add(const ConservativeGCStats &another) {
10211 for (size_t i = 0; i != (sizeof (counter) / sizeof (counter)[0]); ++i)
10212 counter[i] += another.counter[i];
10214 void dump(FILE *fp);
10218 extern __attribute__((visibility ("default"))) void
10219 js_DumpGCStats(JSRuntime *rt, FILE *fp);
10220 struct JSCompartment;
10222 js_TraceXML(JSTracer *trc, JSXML* thing);
10226 enum FinalizeKind {
10233 FINALIZE_OBJECT_LAST = FINALIZE_OBJECT16,
10236 FINALIZE_SHORT_STRING,
10238 FINALIZE_EXTERNAL_STRING,
10241 const uintN JS_FINALIZE_OBJECT_LIMIT = 6;
10242 struct ArenaHeader {
10243 JSCompartment *compartment;
10244 Arena<FreeCell> *next;
10245 FreeCell *freeList;
10246 unsigned thingKind;
10250 template <typename T>
10251 union ThingOrCell {
10255 template <typename T, size_t N, size_t R>
10257 ThingOrCell<T> things[N];
10260 template <typename T, size_t N>
10261 struct Things<T, N, 0> {
10262 ThingOrCell<T> things[N];
10264 template <typename T>
10266 static const size_t ArenaSize = 4096;
10267 struct AlignedArenaHeader {
10268 T align[(sizeof(ArenaHeader) + sizeof(T) - 1) / sizeof(T)];
10271 ArenaHeader aheader;
10272 AlignedArenaHeader align;
10274 static const size_t ThingsPerArena = (ArenaSize - sizeof(AlignedArenaHeader)) / sizeof(T);
10275 static const size_t FillerSize = ArenaSize - sizeof(AlignedArenaHeader) - sizeof(T) * ThingsPerArena;
10276 Things<T, ThingsPerArena, FillerSize> t;
10277 inline Chunk *chunk() const;
10278 inline size_t arenaIndex() const;
10279 inline ArenaHeader *header() { return &aheader; };
10280 inline MarkingDelay *getMarkingDelay() const;
10281 inline ArenaBitmap *bitmap() const;
10282 inline ConservativeGCTest mark(T *thing, JSTracer *trc);
10283 void markDelayedChildren(JSTracer *trc);
10284 inline bool inFreeList(void *thing) const;
10285 inline T *getAlignedThing(void *thing);
10286 void init(JSCompartment *compartment, unsigned thingKind);
10288 typedef int js_static_assert53[(sizeof(Arena<FreeCell>) == 4096) ? 1 : -1];
10289 static const uint32 BLACK = 0;
10290 struct ArenaBitmap {
10291 static const size_t BitCount = Arena<FreeCell>::ArenaSize / Cell::CellSize;
10292 static const size_t BitWords = BitCount / (8 * 8);
10293 uintptr_t bitmap[BitWords];
10294 __attribute__((always_inline)) inline bool isMarked(size_t bit, uint32 color) {
10297 uintptr_t *word = &bitmap[bit / (8 * 8)];
10298 return *word & (uintptr_t(1) << (bit % (8 * 8)));
10300 __attribute__((always_inline)) inline bool markIfUnmarked(size_t bit, uint32 color) {
10302 uintptr_t *word = &bitmap[bit / (8 * 8)];
10303 uintptr_t mask = (uintptr_t(1) << (bit % (8 * 8)));
10307 if (color != BLACK) {
10309 word = &bitmap[bit / (8 * 8)];
10310 mask = (uintptr_t(1) << (bit % (8 * 8)));
10317 __attribute__((always_inline)) inline void unmark(size_t bit, uint32 color) {
10320 uintptr_t *word = &bitmap[bit / (8 * 8)];
10321 *word &= ~(uintptr_t(1) << (bit % (8 * 8)));
10324 typedef int js_static_assert54[(Arena<FreeCell>::ArenaSize % Cell::CellSize == 0) ? 1 : -1];
10325 typedef int js_static_assert55[(ArenaBitmap::BitCount % (8 * 8) == 0) ? 1 : -1];
10326 struct MarkingDelay {
10328 uintptr_t unmarkedChildren;
10333 unmarkedChildren = 0;
10336 struct EmptyArenaLists {
10337 Arena<FreeCell> *cellFreeList;
10338 Arena<FreeCell> *freeLists[FINALIZE_LIMIT];
10342 Arena<FreeCell> *getOtherArena() {
10343 Arena<FreeCell> *arena = cellFreeList;
10345 cellFreeList = arena->header()->next;
10348 for (int i = 0; i < FINALIZE_LIMIT; i++) {
10349 if ((arena = (Arena<FreeCell> *) freeLists[i])) {
10350 freeLists[i] = freeLists[i]->header()->next;
10357 template <typename T>
10358 inline Arena<T> *getTypedFreeList(unsigned thingKind);
10359 template <typename T>
10360 inline Arena<T> *getNext(JSCompartment *comp, unsigned thingKind);
10361 template <typename T>
10362 inline void insert(Arena<T> *arena);
10364 template <typename T>
10366 EmptyArenaLists::getTypedFreeList(unsigned thingKind) {
10368 Arena<T> *arena = (Arena<T>*) freeLists[thingKind];
10370 freeLists[thingKind] = freeLists[thingKind]->header()->next;
10375 template<typename T>
10377 EmptyArenaLists::getNext(JSCompartment *comp, unsigned thingKind) {
10378 Arena<T> *arena = getTypedFreeList<T>(thingKind);
10382 arena->header()->isUsed = true;
10383 arena->header()->thingKind = thingKind;
10384 arena->header()->compartment = comp;
10387 arena = (Arena<T> *)getOtherArena();
10389 arena->init(comp, thingKind);
10392 template <typename T>
10394 EmptyArenaLists::insert(Arena<T> *arena) {
10395 unsigned thingKind = arena->header()->thingKind;
10397 arena->header()->next = freeLists[thingKind];
10398 freeLists[thingKind] = (Arena<FreeCell> *) arena;
10402 JSRuntime *runtime;
10403 EmptyArenaLists emptyArenaLists;
10408 static const size_t BytesPerArena = sizeof(Arena<FreeCell>) +
10409 sizeof(ArenaBitmap) +
10410 sizeof(MarkingDelay);
10411 static const size_t ArenasPerChunk = (GC_CHUNK_SIZE - sizeof(ChunkInfo)) / BytesPerArena;
10412 Arena<FreeCell> arenas[ArenasPerChunk];
10413 ArenaBitmap bitmaps[ArenasPerChunk];
10414 MarkingDelay markingDelay[ArenasPerChunk];
10416 void clearMarkBitmap();
10417 void init(JSRuntime *rt);
10419 bool hasAvailableArenas();
10420 bool withinArenasRange(Cell *cell);
10421 template <typename T>
10422 Arena<T> *allocateArena(JSCompartment *comp, unsigned thingKind);
10423 template <typename T>
10424 void releaseArena(Arena<T> *a);
10425 JSRuntime *getRuntime();
10427 typedef int js_static_assert56[(sizeof(Chunk) <= GC_CHUNK_SIZE) ? 1 : -1];
10428 typedef int js_static_assert57[(sizeof(Chunk) + Chunk::BytesPerArena > GC_CHUNK_SIZE) ? 1 : -1];
10430 Cell::arena() const
10432 uintptr_t addr = uintptr_t(this);
10434 addr &= ~(Arena<FreeCell>::ArenaSize - 1);
10435 return reinterpret_cast<Arena<Cell> *>(addr);
10438 Cell::chunk() const
10440 uintptr_t addr = uintptr_t(this);
10442 addr &= ~(GC_CHUNK_SIZE - 1);
10443 return reinterpret_cast<Chunk *>(addr);
10446 Cell::bitmap() const
10448 return &chunk()->bitmaps[arena()->arenaIndex()];
10451 Cell::cellIndex() const
10453 return reinterpret_cast<const FreeCell *>(this) - reinterpret_cast<FreeCell *>(&arena()->t);
10455 template <typename T>
10457 Arena<T>::chunk() const
10459 uintptr_t addr = uintptr_t(this);
10461 addr &= ~(GC_CHUNK_SIZE - 1);
10462 return reinterpret_cast<Chunk *>(addr);
10464 template <typename T>
10466 Arena<T>::arenaIndex() const
10468 return reinterpret_cast<const Arena<FreeCell> *>(this) - chunk()->arenas;
10470 template <typename T>
10472 Arena<T>::getMarkingDelay() const
10474 return &chunk()->markingDelay[arenaIndex()];
10476 template <typename T>
10478 Arena<T>::bitmap() const
10480 return &chunk()->bitmaps[arenaIndex()];
10482 template <typename T>
10484 Arena<T>::getAlignedThing(void *thing)
10486 jsuword start = reinterpret_cast<jsuword>(&t.things[0]);
10487 jsuword offset = reinterpret_cast<jsuword>(thing) - start;
10488 offset -= offset % aheader.thingSize;
10489 return reinterpret_cast<T *>(start + offset);
10492 AssertValidColor(const void *thing, uint32 color)
10498 Cell::isMarked(uint32 color = BLACK) const
10500 AssertValidColor(this, color);
10501 return bitmap()->isMarked(cellIndex(), color);
10504 Cell::markIfUnmarked(uint32 color = BLACK) const
10506 AssertValidColor(this, color);
10507 return bitmap()->markIfUnmarked(cellIndex(), color);
10510 Cell::unmark(uint32 color) const
10513 AssertValidColor(this, color);
10514 bitmap()->unmark(cellIndex(), color);
10517 Cell::compartment() const
10519 return arena()->header()->compartment;
10521 template <typename T>
10524 GetArena(Cell *cell)
10526 return reinterpret_cast<Arena<T> *>(cell->arena());
10528 const size_t GC_ARENA_ALLOCATION_TRIGGER = 30 * js::GC_CHUNK_SIZE;
10529 const float GC_HEAP_GROWTH_FACTOR = 3.0f;
10530 static inline size_t
10531 GetFinalizableTraceKind(size_t thingKind)
10533 typedef int js_static_assert58[(JSExternalString::TYPE_LIMIT == 8) ? 1 : -1];
10534 static const uint8 map[FINALIZE_LIMIT] = {
10548 return map[thingKind];
10552 IsFinalizableStringKind(unsigned thingKind)
10554 return unsigned(FINALIZE_SHORT_STRING) <= thingKind &&
10555 thingKind <= unsigned(FINALIZE_EXTERNAL_STRING);
10558 GetExternalStringGCType(JSExternalString *str)
10560 typedef int js_static_assert59[(FINALIZE_STRING + 1 == FINALIZE_EXTERNAL_STRING) ? 1 : -1];
10562 unsigned thingKind = str->externalStringType;
10564 return intN(thingKind);
10566 static inline uint32
10567 GetGCThingTraceKind(void *thing)
10570 if (JSString::isStatic(thing))
10572 Cell *cell = reinterpret_cast<Cell *>(thing);
10573 return GetFinalizableTraceKind(cell->arena()->header()->thingKind);
10575 static inline JSRuntime *
10576 GetGCThingRuntime(void *thing)
10578 return reinterpret_cast<FreeCell *>(thing)->chunk()->info.runtime;
10581 Arena<FreeCell> *head;
10582 Arena<FreeCell> *cursor;
10583 inline void init() {
10587 inline Arena<FreeCell> *getNextWithFreeList() {
10588 Arena<FreeCell> *a;
10589 while (cursor != __null) {
10590 ArenaHeader *aheader = cursor->header();
10592 cursor = aheader->next;
10593 if (aheader->freeList)
10598 inline void insert(Arena<FreeCell> *a) {
10599 a->header()->next = head;
10602 void releaseAll() {
10604 Arena<FreeCell> *next = head->header()->next;
10605 head->chunk()->releaseArena(head);
10611 inline bool isEmpty() const {
10612 return (head == __null);
10616 FreeCell **finalizables[FINALIZE_LIMIT];
10618 inline FreeCell *getNext(uint32 kind) {
10619 FreeCell *top = __null;
10620 if (finalizables[kind]) {
10621 top = *finalizables[kind];
10623 *finalizables[kind] = top->link;
10625 finalizables[kind] = __null;
10630 template <typename T>
10631 inline void populate(Arena<T> *a, uint32 thingKind) {
10632 finalizables[thingKind] = &a->header()->freeList;
10636 typedef Vector<gc::Chunk *, 32, SystemAllocPolicy> GCChunks;
10639 typedef void *Lookup;
10640 static HashNumber hash(void *key) {
10641 return HashNumber(uintptr_t(key) >> JS_GCTHING_ZEROBITS);
10643 static bool match(void *l, void *k) { return l == k; }
10645 typedef HashMap<void *, uint32, GCPtrHasher, SystemAllocPolicy> GCLocks;
10648 RootInfo(const char *name, JSGCRootType type) : name(name), type(type) {}
10652 typedef js::HashMap<void *,
10654 js::DefaultHasher<void *>,
10655 js::SystemAllocPolicy> RootedValueMap;
10656 typedef int js_static_assert60[(sizeof(HashNumber) == 4) ? 1 : -1];
10657 struct WrapperHasher
10659 typedef Value Lookup;
10660 static HashNumber hash(Value key) {
10661 uint64 bits = (Jsvalify(key));
10662 return (uint32)bits ^ (uint32)(bits >> 32);
10664 static bool match(const Value &l, const Value &k) { return l == k; }
10666 typedef HashMap<Value, Value, WrapperHasher, SystemAllocPolicy> WrapperMap;
10667 class AutoValueVector;
10668 class AutoIdVector;
10671 CheckGCFreeListLink(js::gc::FreeCell *cell)
10679 RefillFinalizableFreeList(JSContext *cx, unsigned thingKind);
10681 js_GetExternalStringGCType(JSString *str);
10682 extern __attribute__((visibility ("default"))) uint32
10683 js_GetGCThingTraceKind(void *thing);
10685 js_InitGC(JSRuntime *rt, uint32 maxbytes);
10687 js_FinishGC(JSRuntime *rt);
10689 js_AddRoot(JSContext *cx, js::Value *vp, const char *name);
10691 js_AddGCThingRoot(JSContext *cx, void **rp, const char *name);
10693 js_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data);
10694 typedef struct JSPtrTable {
10699 js_RegisterCloseableIterator(JSContext *cx, JSObject *obj);
10701 js_LockGCThingRT(JSRuntime *rt, void *thing);
10703 js_UnlockGCThingRT(JSRuntime *rt, void *thing);
10704 extern __attribute__((visibility ("default"))) bool
10705 IsAboutToBeFinalized(JSContext *cx, void *thing);
10706 extern __attribute__((visibility ("default"))) bool
10707 js_GCThingIsMarked(void *thing, uintN color);
10709 js_TraceStackFrame(JSTracer *trc, JSStackFrame *fp);
10712 MarkRuntime(JSTracer *trc);
10714 TraceRuntime(JSTracer *trc);
10715 extern __attribute__((visibility ("default"))) void
10716 MarkContext(JSTracer *trc, JSContext *acx);
10718 TriggerGC(JSRuntime *rt);
10720 TriggerCompartmentGC(JSCompartment *comp);
10722 MaybeGC(JSContext *cx);
10724 typedef enum JSGCInvocationKind {
10726 GC_LAST_CONTEXT = 1
10727 } JSGCInvocationKind;
10729 js_GC(JSContext *cx, JSCompartment *comp, JSGCInvocationKind gckind);
10731 js_WaitForGC(JSRuntime *rt);
10733 js_DestroyScriptsToGC(JSContext *cx, JSCompartment *comp);
10735 class GCHelperThread {
10736 static const size_t FREE_ARRAY_SIZE = size_t(1) << 16;
10737 static const size_t FREE_ARRAY_LENGTH = FREE_ARRAY_SIZE / sizeof(void *);
10740 PRCondVar* sweepingDone;
10743 Vector<void **, 16, js::SystemAllocPolicy> freeVector;
10745 void **freeCursorEnd;
10746 __attribute__((visibility ("default"))) void
10747 replenishAndFreeLater(void *ptr);
10748 static void freeElementsAndArray(void **array, void **end) {
10750 for (void **p = array; p != end; ++p)
10754 static void threadMain(void* arg);
10755 void threadLoop(JSRuntime *rt);
10761 sweepingDone(__null),
10764 freeCursor(__null),
10765 freeCursorEnd(__null) { }
10766 bool init(JSRuntime *rt);
10767 void finish(JSRuntime *rt);
10768 void startBackgroundSweep(JSRuntime *rt);
10769 void waitBackgroundSweepEnd(JSRuntime *rt);
10770 void freeLater(void *ptr) {
10772 if (freeCursor != freeCursorEnd)
10773 *freeCursor++ = ptr;
10775 replenishAndFreeLater(ptr);
10778 struct GCChunkHasher {
10779 typedef gc::Chunk *Lookup;
10780 static HashNumber hash(gc::Chunk *chunk) {
10782 return HashNumber(jsuword(chunk) >> GC_CHUNK_SHIFT);
10784 static bool match(gc::Chunk *k, gc::Chunk *l) {
10790 typedef HashSet<js::gc::Chunk *, GCChunkHasher, SystemAllocPolicy> GCChunkSet;
10791 struct ConservativeGCThreadData {
10792 jsuword *nativeStackTop;
10795 jsuword words[(((sizeof(jmp_buf))+(sizeof(jsuword))-1)/(sizeof(jsuword)))];
10796 } registerSnapshot;
10797 unsigned requestThreshold;
10798 __attribute__((noinline)) void recordStackTop();
10799 void updateForRequestEnd(unsigned suspendCount) {
10803 nativeStackTop = __null;
10805 bool hasStackToScan() const {
10806 return !!nativeStackTop;
10809 struct GCMarker : public JSTracer {
10813 jsuword stackLimit;
10814 js::gc::Arena<js::gc::Cell> *unmarkedArenaStackTop;
10816 explicit GCMarker(JSContext *cx);
10818 uint32 getMarkColor() const {
10821 void setMarkColor(uint32 newColor) {
10822 markDelayedChildren();
10825 void delayMarkingChildren(void *thing);
10826 __attribute__((visibility ("default"))) void markDelayedChildren();
10829 MarkStackRangeConservatively(JSTracer *trc, Value *begin, Value *end);
10832 js_FinalizeStringRT(JSRuntime *rt, JSString *str);
10834 js_MarkTraps(JSTracer *trc);
10839 SetProtoCheckingForCycles(JSContext *cx, JSObject *obj, JSObject *proto);
10841 NewCompartment(JSContext *cx, JSPrincipals *principals);
10844 inline JSCompartment *
10845 JSObject::getCompartment() const
10847 return compartment();
10858 JSINTERP_NORMAL = 0,
10859 JSINTERP_RECORD = 1,
10860 JSINTERP_SAFEPOINT = 2,
10861 JSINTERP_PROFILE = 3
10865 JSFRAME_GLOBAL = 0x1,
10866 JSFRAME_FUNCTION = 0x2,
10867 JSFRAME_DUMMY = 0x4,
10868 JSFRAME_EVAL = 0x8,
10869 JSFRAME_DEBUGGER = 0x10,
10870 JSFRAME_GENERATOR = 0x20,
10871 JSFRAME_FLOATING_GENERATOR = 0x40,
10872 JSFRAME_CONSTRUCTING = 0x80,
10873 JSFRAME_ASSIGNING = 0x100,
10874 JSFRAME_YIELDING = 0x200,
10875 JSFRAME_FINISHED_IN_INTERPRETER = 0x400,
10876 JSFRAME_OVERRIDE_ARGS = 0x1000,
10877 JSFRAME_OVERFLOW_ARGS = 0x2000,
10878 JSFRAME_UNDERFLOW_ARGS = 0x4000,
10879 JSFRAME_HAS_IMACRO_PC = 0x8000,
10880 JSFRAME_HAS_CALL_OBJ = 0x10000,
10881 JSFRAME_HAS_ARGS_OBJ = 0x20000,
10882 JSFRAME_HAS_HOOK_DATA = 0x40000,
10883 JSFRAME_HAS_ANNOTATION = 0x80000,
10884 JSFRAME_HAS_RVAL = 0x100000,
10885 JSFRAME_HAS_SCOPECHAIN = 0x200000,
10886 JSFRAME_HAS_PREVPC = 0x400000
10888 namespace js { namespace mjit { struct JITScript; } }
10889 struct JSStackFrame
10892 mutable uint32 flags_;
10902 mutable JSObject *scopeChain_;
10903 JSStackFrame *prev_;
10906 jsbytecode *prevpc_;
10907 jsbytecode *imacropc_;
10910 friend class js::StackSpace;
10911 friend class js::FrameRegsIter;
10912 friend struct JSContext;
10913 inline void initPrev(JSContext *cx);
10915 bool isFunctionFrame() const {
10916 return !!(flags_ & JSFRAME_FUNCTION);
10918 bool isGlobalFrame() const {
10919 return !!(flags_ & JSFRAME_GLOBAL);
10921 bool isDummyFrame() const {
10922 return !!(flags_ & JSFRAME_DUMMY);
10924 bool isScriptFrame() const {
10925 return !!(flags_ & (JSFRAME_FUNCTION | JSFRAME_GLOBAL));
10927 bool isEvalFrame() const {
10929 return flags_ & JSFRAME_EVAL;
10931 bool isExecuteFrame() const {
10932 return !!(flags_ & (JSFRAME_GLOBAL | JSFRAME_EVAL));
10934 inline void initCallFrame(JSContext *cx, JSObject &callee, JSFunction *fun,
10935 uint32 nactual, uint32 flags);
10936 inline void resetInvokeCallFrame();
10937 inline void initCallFrameCallerHalf(JSContext *cx, uint32 flags, void *ncode);
10938 inline void initCallFrameEarlyPrologue(JSFunction *fun, uint32 nactual);
10939 inline void initCallFrameLatePrologue();
10940 inline void initEvalFrame(JSContext *cx, JSScript *script, JSStackFrame *prev,
10942 inline void initGlobalFrame(JSScript *script, JSObject &chain, uint32 flags);
10943 inline void stealFrameAndSlots(js::Value *vp, JSStackFrame *otherfp,
10944 js::Value *othervp, js::Value *othersp);
10945 inline void initDummyFrame(JSContext *cx, JSObject &chain);
10946 JSStackFrame *prev() const {
10949 inline void resetGeneratorPrev(JSContext *cx);
10950 js::Value *slots() const {
10951 return (js::Value *)(this + 1);
10953 js::Value *base() const {
10954 return slots() + script()->nfixed;
10956 js::Value &varSlot(uintN i) {
10961 jsbytecode *pc(JSContext *cx, JSStackFrame *next = __null);
10962 jsbytecode *prevpc() {
10966 JSScript *script() const {
10968 return isFunctionFrame()
10969 ? isEvalFrame() ? args.script : fun()->script()
10972 JSScript *functionScript() const {
10974 return isEvalFrame() ? args.script : fun()->script();
10976 JSScript *globalScript() const {
10978 return exec.script;
10980 JSScript *maybeScript() const {
10981 return isScriptFrame() ? script() : __null;
10983 size_t numFixed() const {
10984 return script()->nfixed;
10986 size_t numSlots() const {
10987 return script()->nslots;
10989 size_t numGlobalVars() const {
10991 return exec.script->nfixed;
10993 JSFunction* fun() const {
10997 JSFunction* maybeFun() const {
10998 return isFunctionFrame() ? fun() : __null;
11000 bool hasArgs() const {
11001 return isFunctionFrame() && !isEvalFrame();
11003 uintN numFormalArgs() const {
11005 return fun()->nargs;
11007 js::Value &formalArg(uintN i) const {
11009 return formalArgs()[i];
11011 js::Value *formalArgs() const {
11013 return (js::Value *)this - numFormalArgs();
11015 js::Value *formalArgsEnd() const {
11017 return (js::Value *)this;
11019 js::Value *maybeFormalArgs() const {
11020 return (flags_ & (JSFRAME_FUNCTION | JSFRAME_EVAL)) == JSFRAME_FUNCTION
11024 inline uintN numActualArgs() const;
11025 inline js::Value *actualArgs() const;
11026 inline js::Value *actualArgsEnd() const;
11027 inline js::Value &canonicalActualArg(uintN i) const;
11028 template <class Op> inline void forEachCanonicalActualArg(Op op);
11029 template <class Op> inline void forEachFormalArg(Op op);
11030 inline void clearMissingArgs();
11031 bool hasArgsObj() const {
11032 return !!(flags_ & JSFRAME_HAS_ARGS_OBJ);
11034 JSObject &argsObj() const {
11039 JSObject *maybeArgsObj() const {
11040 return hasArgsObj() ? &argsObj() : __null;
11042 inline void setArgsObj(JSObject &obj);
11043 inline void clearArgsObj();
11044 js::Value &functionThis() const {
11047 return ((js::Value *)this)[-1];
11048 return formalArgs()[-1];
11050 JSObject &constructorThis() const {
11052 return formalArgs()[-1].toObject();
11054 js::Value &globalThis() const {
11056 return ((js::Value *)this)[-1];
11058 js::Value &thisValue() const {
11059 if (flags_ & (JSFRAME_EVAL | JSFRAME_GLOBAL))
11060 return ((js::Value *)this)[-1];
11061 return formalArgs()[-1];
11063 inline bool computeThis(JSContext *cx);
11064 js::Value &calleeValue() const {
11067 return ((js::Value *)this)[-2];
11068 return formalArgs()[-2];
11070 JSObject &callee() const {
11072 return calleeValue().toObject();
11074 JSObject *maybeCallee() const {
11075 return isFunctionFrame() ? &callee() : __null;
11077 bool getValidCalleeObject(JSContext *cx, js::Value *vp);
11078 JSObject &scopeChain() const {
11080 if (!(flags_ & JSFRAME_HAS_SCOPECHAIN)) {
11081 scopeChain_ = callee().getParent();
11082 flags_ |= JSFRAME_HAS_SCOPECHAIN;
11084 return *scopeChain_;
11086 bool hasCallObj() const {
11087 return !!(flags_ & JSFRAME_HAS_CALL_OBJ);
11089 inline JSObject &callObj() const;
11090 inline JSObject *maybeCallObj() const;
11091 inline void setScopeChainNoCallObj(JSObject &obj);
11092 inline void setScopeChainAndCallObj(JSObject &obj);
11093 inline void clearCallObj();
11094 bool hasImacropc() const {
11095 return flags_ & JSFRAME_HAS_IMACRO_PC;
11097 jsbytecode *imacropc() const {
11101 jsbytecode *maybeImacropc() const {
11102 return hasImacropc() ? imacropc() : __null;
11104 void clearImacropc() {
11105 flags_ &= ~JSFRAME_HAS_IMACRO_PC;
11107 void setImacropc(jsbytecode *pc) {
11111 flags_ |= JSFRAME_HAS_IMACRO_PC;
11113 void* annotation() const {
11114 return (flags_ & JSFRAME_HAS_ANNOTATION) ? annotation_ : __null;
11116 void setAnnotation(void *annot) {
11117 flags_ |= JSFRAME_HAS_ANNOTATION;
11118 annotation_ = annot;
11120 bool hasHookData() const {
11121 return !!(flags_ & JSFRAME_HAS_HOOK_DATA);
11123 void* hookData() const {
11127 void* maybeHookData() const {
11128 return hasHookData() ? hookData_ : __null;
11130 void setHookData(void *v) {
11132 flags_ |= JSFRAME_HAS_HOOK_DATA;
11134 const js::Value &returnValue() {
11135 if (!(flags_ & JSFRAME_HAS_RVAL))
11136 rval_.setUndefined();
11139 void markReturnValue() {
11140 flags_ |= JSFRAME_HAS_RVAL;
11142 void setReturnValue(const js::Value &v) {
11146 void clearReturnValue() {
11147 rval_.setUndefined();
11150 void *nativeReturnAddress() const {
11153 void setNativeReturnAddress(void *addr) {
11156 void **addressOfNativeReturnAddress() {
11159 bool isGeneratorFrame() const {
11160 return !!(flags_ & JSFRAME_GENERATOR);
11162 bool isFloatingGenerator() const {
11164 return !!(flags_ & JSFRAME_FLOATING_GENERATOR);
11166 void initFloatingGenerator() {
11168 flags_ |= (JSFRAME_GENERATOR | JSFRAME_FLOATING_GENERATOR);
11170 void unsetFloatingGenerator() {
11171 flags_ &= ~JSFRAME_FLOATING_GENERATOR;
11173 void setFloatingGenerator() {
11174 flags_ |= JSFRAME_FLOATING_GENERATOR;
11176 bool isConstructing() const {
11177 return !!(flags_ & JSFRAME_CONSTRUCTING);
11179 uint32 isConstructingFlag() const {
11184 bool isDebuggerFrame() const {
11185 return !!(flags_ & JSFRAME_DEBUGGER);
11187 bool isEvalOrDebuggerFrame() const {
11188 return !!(flags_ & (JSFRAME_EVAL | JSFRAME_DEBUGGER));
11190 bool hasOverriddenArgs() const {
11191 return !!(flags_ & JSFRAME_OVERRIDE_ARGS);
11193 bool hasOverflowArgs() const {
11194 return !!(flags_ & JSFRAME_OVERFLOW_ARGS);
11196 void setOverriddenArgs() {
11197 flags_ |= JSFRAME_OVERRIDE_ARGS;
11199 bool isAssigning() const {
11200 return !!(flags_ & JSFRAME_ASSIGNING);
11202 void setAssigning() {
11203 flags_ |= JSFRAME_ASSIGNING;
11205 void clearAssigning() {
11206 flags_ &= ~JSFRAME_ASSIGNING;
11208 bool isYielding() {
11209 return !!(flags_ & JSFRAME_YIELDING);
11211 void setYielding() {
11212 flags_ |= JSFRAME_YIELDING;
11214 void clearYielding() {
11215 flags_ &= ~JSFRAME_YIELDING;
11217 void setFinishedInInterpreter() {
11218 flags_ |= JSFRAME_FINISHED_IN_INTERPRETER;
11220 bool finishedInInterpreter() const {
11221 return !!(flags_ & JSFRAME_FINISHED_IN_INTERPRETER);
11223 inline JSObject &varobj(js::StackSegment *seg) const;
11224 inline JSObject &varobj(JSContext *cx) const;
11225 static size_t offsetOfFlags() {
11226 return __builtin_offsetof (JSStackFrame, flags_);
11228 static size_t offsetOfExec() {
11229 return __builtin_offsetof (JSStackFrame, exec);
11231 void *addressOfArgs() {
11234 static size_t offsetOfScopeChain() {
11235 return __builtin_offsetof (JSStackFrame, scopeChain_);
11237 JSObject **addressOfScopeChain() {
11239 return &scopeChain_;
11241 static size_t offsetOfPrev() {
11242 return __builtin_offsetof (JSStackFrame, prev_);
11244 static size_t offsetOfReturnValue() {
11245 return __builtin_offsetof (JSStackFrame, rval_);
11247 static ptrdiff_t offsetOfncode() {
11248 return __builtin_offsetof (JSStackFrame, ncode_);
11250 static ptrdiff_t offsetOfCallee(JSFunction *fun) {
11252 return -(fun->nargs + 2) * sizeof(js::Value);
11254 static ptrdiff_t offsetOfThis(JSFunction *fun) {
11255 return fun == __null
11256 ? -1 * ptrdiff_t(sizeof(js::Value))
11257 : -(fun->nargs + 1) * ptrdiff_t(sizeof(js::Value));
11259 static ptrdiff_t offsetOfFormalArg(JSFunction *fun, uintN i) {
11261 return (-(int)fun->nargs + i) * sizeof(js::Value);
11263 static size_t offsetOfFixed(uintN i) {
11264 return sizeof(JSStackFrame) + i * sizeof(js::Value);
11266 void staticAsserts() {
11267 typedef int js_static_assert61[(__builtin_offsetof (JSStackFrame, rval_) % sizeof(js::Value) == 0) ? 1 : -1];
11268 typedef int js_static_assert62[(sizeof(JSStackFrame) % sizeof(js::Value) == 0) ? 1 : -1];
11270 void methodjitStaticAsserts();
11273 static const size_t VALUES_PER_STACK_FRAME = sizeof(JSStackFrame) / sizeof(Value);
11275 GetBlockChain(JSContext *cx, JSStackFrame *fp);
11277 GetBlockChainFast(JSContext *cx, JSStackFrame *fp, JSOp op, size_t oplen);
11279 GetScopeChain(JSContext *cx);
11281 GetScopeChain(JSContext *cx, JSStackFrame *fp);
11283 GetScopeChainFast(JSContext *cx, JSStackFrame *fp, JSOp op, size_t oplen);
11285 ReportIncompatibleMethod(JSContext *cx, Value *vp, Class *clasp);
11286 template <typename T>
11287 bool GetPrimitiveThis(JSContext *cx, Value *vp, T *v);
11289 PutActivationObjects(JSContext *cx, JSStackFrame *fp);
11291 PutOwnedActivationObjects(JSContext *cx, JSStackFrame *fp);
11294 BoxThisForVp(JSContext *cx, js::Value *vp);
11301 CallArgs(Value *argv, uintN argc) : argv_(argv), argc_(argc) {}
11303 Value *base() const { return argv_ - 2; }
11304 Value &callee() const { return argv_[-2]; }
11305 Value &thisv() const { return argv_[-1]; }
11306 Value &operator[](unsigned i) const { ((void) 0); return argv_[i]; }
11307 Value *argv() const { return argv_; }
11308 uintN argc() const { return argc_; }
11309 Value &rval() const { return argv_[-2]; }
11313 Invoke(JSContext *cx, const CallArgs &args, uint32 flags);
11314 class InvokeSessionGuard;
11317 ExternalInvoke(JSContext *cx, const Value &thisv, const Value &fval,
11318 uintN argc, Value *argv, Value *rval);
11321 ExternalGetOrSet(JSContext *cx, JSObject *obj, jsid id, const Value &fval,
11322 JSAccessMode mode, uintN argc, Value *argv, Value *rval);
11325 InvokeConstructor(JSContext *cx, const CallArgs &args);
11328 InvokeConstructorWithGivenThis(JSContext *cx, JSObject *thisobj, const Value &fval,
11329 uintN argc, Value *argv, Value *rval);
11332 ExternalInvokeConstructor(JSContext *cx, const Value &fval, uintN argc, Value *argv,
11336 DirectEval(JSContext *cx, JSFunction *evalfun, uint32 argc, Value *vp);
11339 DirectEval(JSContext *cx, JSFunction *evalfun, uint32 argc, Value *vp);
11342 Execute(JSContext *cx, JSObject *chain, JSScript *script,
11343 JSStackFrame *prev, uintN flags, Value *result);
11344 extern __attribute__((noinline))
11346 Interpret(JSContext *cx, JSStackFrame *stopFp, uintN inlineCallCount = 0, JSInterpMode mode = JSINTERP_NORMAL);
11349 RunScript(JSContext *cx, JSScript *script, JSStackFrame *fp);
11352 CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs);
11355 StrictlyEqual(JSContext *cx, const Value &lval, const Value &rval, JSBool *equal);
11358 SameValue(JSContext *cx, const Value &v1, const Value &v2, JSBool *same);
11360 TypeOfValue(JSContext *cx, const Value &v);
11363 InstanceOf(JSContext *cx, JSObject *obj, Class *clasp, Value *argv)
11365 if (obj && obj->getClass() == clasp)
11367 extern bool InstanceOfSlow(JSContext *, JSObject *, Class *, Value *);
11368 return InstanceOfSlow(cx, obj, clasp, argv);
11371 HasInstance(JSContext *cx, JSObject *obj, const js::Value *v, JSBool *bp);
11373 GetInstancePrivate(JSContext *cx, JSObject *obj, Class *clasp, Value *argv)
11375 if (!InstanceOf(cx, obj, clasp, argv))
11377 return obj->getPrivate();
11381 ValueToId(JSContext *cx, const Value &v, jsid *idp);
11382 extern const js::Value &
11383 GetUpvar(JSContext *cx, uintN level, js::UpvarCookie cookie);
11386 js_EnterWith(JSContext *cx, jsint stackIndex, JSOp op, size_t oplen);
11388 js_LeaveWith(JSContext *cx);
11390 js_DoIncDec(JSContext *cx, const JSCodeSpec *cs, js::Value *vp, js::Value *vp2);
11392 js_LogOpcode(JSContext *cx);
11394 js_MeterOpcodePair(JSOp op1, JSOp op2);
11396 js_MeterSlotOpcode(JSOp op, uint32 slot);
11398 js_UnwindScope(JSContext *cx, jsint stackDepth, JSBool normalUnwind);
11400 js_OnUnknownMethod(JSContext *cx, js::Value *vp);
11402 js_IsActiveWithOrBlock(JSContext *cx, JSObject *obj, int stackDepth);
11404 typedef double (*UnaryFunType)(double);
11407 static const unsigned SizeLog2 = 12;
11408 static const unsigned Size = 1 << SizeLog2;
11409 struct Entry { double in; UnaryFunType f; double out; };
11413 uintN hash(double x) {
11414 union { double d; struct { uint32 one, two; } s; } u = { x };
11415 uint32 hash32 = u.s.one ^ u.s.two;
11416 uint16 hash16 = (uint16)(hash32 ^ (hash32 >> 16));
11417 return (hash16 & (Size - 1)) ^ (hash16 >> (16 - SizeLog2));
11419 double lookup(UnaryFunType f, double x) {
11420 uintN index = hash(x);
11421 Entry &e = table[index];
11422 if (e.in == x && e.f == f)
11426 return (e.out = f(x));
11430 extern js::Class js_MathClass;
11432 js_InitMathClass(JSContext *cx, JSObject *obj);
11435 js_IsMathFunction(JSNative native);
11437 js_InitRandom(JSContext *cx);
11439 js_math_abs(JSContext *cx, uintN argc, js::Value *vp);
11441 js_math_ceil(JSContext *cx, uintN argc, js::Value *vp);
11443 js_math_floor(JSContext *cx, uintN argc, js::Value *vp);
11445 js_math_max(JSContext *cx, uintN argc, js::Value *vp);
11447 js_math_min(JSContext *cx, uintN argc, js::Value *vp);
11449 js_math_round(JSContext *cx, uintN argc, js::Value *vp);
11451 js_math_ceil_impl(jsdouble x);
11453 js_math_floor_impl(jsdouble x);
11455 js_math_round_impl(jsdouble x);
11458 PCVCAP_PROTOBITS = 4,
11459 PCVCAP_PROTOSIZE = ((JSUint32)1 << (PCVCAP_PROTOBITS)),
11460 PCVCAP_PROTOMASK = (((JSUint32)1 << (PCVCAP_PROTOBITS)) - 1),
11461 PCVCAP_SCOPEBITS = 4,
11462 PCVCAP_SCOPESIZE = ((JSUint32)1 << (PCVCAP_SCOPEBITS)),
11463 PCVCAP_SCOPEMASK = (((JSUint32)1 << (PCVCAP_SCOPEBITS)) - 1),
11464 PCVCAP_TAGBITS = PCVCAP_PROTOBITS + PCVCAP_SCOPEBITS,
11465 PCVCAP_TAGMASK = (((JSUint32)1 << (PCVCAP_TAGBITS)) - 1)
11467 const uint32 SHAPE_OVERFLOW_BIT = ((JSUint32)1 << (32 - PCVCAP_TAGBITS));
11479 bool isNull() const { return v == 0; }
11480 void setNull() { v = 0; }
11481 bool isFunObj() const { return (v & TAG) == OBJECT; }
11482 JSObject &toFunObj() const {
11484 return *reinterpret_cast<JSObject *>(v);
11486 void setFunObj(JSObject &obj) {
11487 v = reinterpret_cast<jsuword>(&obj);
11489 bool isSlot() const { return v & SLOT; }
11490 uint32 toSlot() const { ((void) 0); return uint32(v) >> 1; }
11491 void setSlot(uint32 slot) { v = (jsuword(slot) << 1) | SLOT; }
11492 bool isShape() const { return (v & TAG) == SHAPE; }
11493 const js::Shape *toShape() const {
11495 return reinterpret_cast<js::Shape *>(v & ~TAG);
11497 void setShape(const js::Shape *shape) {
11499 v = reinterpret_cast<jsuword>(shape) | SHAPE;
11502 struct PropertyCacheEntry
11508 bool adding() const { return vcapTag() == 0 && kshape != vshape(); }
11509 bool directHit() const { return vcapTag() == 0 && kshape == vshape(); }
11510 jsuword vcapTag() const { return vcap & PCVCAP_TAGMASK; }
11511 uint32 vshape() const { return uint32(vcap >> PCVCAP_TAGBITS); }
11512 jsuword scopeIndex() const { return (vcap >> PCVCAP_PROTOBITS) & PCVCAP_SCOPEMASK; }
11513 jsuword protoIndex() const { return vcap & PCVCAP_PROTOMASK; }
11514 void assign(jsbytecode *kpc, jsuword kshape, jsuword vshape,
11515 uintN scopeIndex, uintN protoIndex, PCVal vword) {
11521 this->kshape = kshape;
11522 this->vcap = (vshape << PCVCAP_TAGBITS) | (scopeIndex << PCVCAP_PROTOBITS) | protoIndex;
11523 this->vword = vword;
11526 class PropertyCache
11531 SIZE = ((JSUint32)1 << (SIZE_LOG2)),
11532 MASK = (((JSUint32)1 << (SIZE_LOG2)) - 1)
11534 PropertyCacheEntry table[SIZE];
11536 static inline jsuword
11537 hash(jsbytecode *pc, jsuword kshape)
11539 return ((((jsuword(pc) >> SIZE_LOG2) ^ jsuword(pc)) + kshape) & MASK);
11541 static inline bool matchShape(JSContext *cx, JSObject *obj, uint32 shape);
11542 JSAtom *fullTest(JSContext *cx, jsbytecode *pc, JSObject **objp,
11543 JSObject **pobjp, PropertyCacheEntry *entry);
11544 inline void assertEmpty() {}
11546 __attribute__((always_inline)) inline void test(JSContext *cx, jsbytecode *pc,
11547 JSObject *&obj, JSObject *&pobj,
11548 PropertyCacheEntry *&entry, JSAtom *&atom);
11549 __attribute__((always_inline)) inline bool testForSet(JSContext *cx, jsbytecode *pc, JSObject *obj,
11550 PropertyCacheEntry **entryp, JSObject **obj2p,
11552 __attribute__((always_inline)) inline bool testForInit(JSRuntime *rt, jsbytecode *pc, JSObject *obj,
11553 const js::Shape **shapep, PropertyCacheEntry **entryp);
11554 PropertyCacheEntry *fill(JSContext *cx, JSObject *obj, uintN scopeIndex,
11555 uintN protoIndex, JSObject *pobj,
11556 const js::Shape *shape, JSBool adding = false);
11557 void purge(JSContext *cx);
11558 void purgeForScript(JSContext *cx, JSScript *script);
11562 struct ShapeHasher {
11563 typedef js::Shape *Key;
11564 typedef const js::Shape *Lookup;
11565 static inline HashNumber hash(const Lookup l);
11566 static inline bool match(Key k, Lookup l);
11568 typedef HashSet<js::Shape *, ShapeHasher, SystemAllocPolicy> KidsHash;
11569 class KidsPointer {
11578 bool isNull() const { return !w; }
11579 void setNull() { w = 0; }
11580 bool isShape() const { return (w & TAG) == SHAPE && !isNull(); }
11581 js::Shape *toShape() const {
11583 return reinterpret_cast<js::Shape *>(w & ~jsuword(TAG));
11585 void setShape(js::Shape *shape) {
11588 w = reinterpret_cast<jsuword>(shape) | SHAPE;
11590 bool isHash() const { return (w & TAG) == HASH; }
11591 KidsHash *toHash() const {
11593 return reinterpret_cast<KidsHash *>(w & ~jsuword(TAG));
11595 void setHash(KidsHash *hash) {
11598 w = reinterpret_cast<jsuword>(hash) | HASH;
11603 friend struct ::JSFunction;
11604 JSCompartment *compartment;
11605 JSArenaPool arenaPool;
11606 js::Shape *freeList;
11607 bool insertChild(JSContext *cx, js::Shape *parent, js::Shape *child);
11608 void removeChild(js::Shape *child);
11611 enum { MAX_HEIGHT = 128 };
11612 PropertyTree(JSCompartment *comp)
11613 : compartment(comp), freeList(__null)
11615 PodZero(&arenaPool);
11619 js::Shape *newShapeUnchecked();
11620 js::Shape *newShape(JSContext *cx);
11621 js::Shape *getChild(JSContext *cx, js::Shape *parent, const js::Shape &child);
11622 void orphanChildren(js::Shape *shape);
11623 void sweepShapes(JSContext *cx);
11624 void unmarkShapes(JSContext *cx);
11625 static void dumpShapes(JSContext *cx);
11631 unsigned int modes;
11632 __syscall_slong_t offset;
11633 __syscall_slong_t freq;
11634 __syscall_slong_t maxerror;
11635 __syscall_slong_t esterror;
11637 __syscall_slong_t constant;
11638 __syscall_slong_t precision;
11639 __syscall_slong_t tolerance;
11640 struct timeval time;
11641 __syscall_slong_t tick;
11642 __syscall_slong_t ppsfreq;
11643 __syscall_slong_t jitter;
11645 __syscall_slong_t stabil;
11646 __syscall_slong_t jitcnt;
11647 __syscall_slong_t calcnt;
11648 __syscall_slong_t errcnt;
11649 __syscall_slong_t stbcnt;
11651 int :32; int :32; int :32; int :32;
11652 int :32; int :32; int :32; int :32;
11653 int :32; int :32; int :32;
11656 extern int clock_adjtime (__clockid_t __clock_id, struct timex *__utx) throw ();
11669 long int tm_gmtoff;
11670 const char *tm_zone;
11674 struct timespec it_interval;
11675 struct timespec it_value;
11678 extern clock_t clock (void) throw ();
11679 extern time_t time (time_t *__timer) throw ();
11680 extern double difftime (time_t __time1, time_t __time0)
11681 throw () __attribute__ ((__const__));
11682 extern time_t mktime (struct tm *__tp) throw ();
11683 extern size_t strftime (char *__restrict __s, size_t __maxsize,
11684 const char *__restrict __format,
11685 const struct tm *__restrict __tp) throw ();
11686 extern char *strptime (const char *__restrict __s,
11687 const char *__restrict __fmt, struct tm *__tp)
11689 extern size_t strftime_l (char *__restrict __s, size_t __maxsize,
11690 const char *__restrict __format,
11691 const struct tm *__restrict __tp,
11692 __locale_t __loc) throw ();
11693 extern char *strptime_l (const char *__restrict __s,
11694 const char *__restrict __fmt, struct tm *__tp,
11695 __locale_t __loc) throw ();
11696 extern struct tm *gmtime (const time_t *__timer) throw ();
11697 extern struct tm *localtime (const time_t *__timer) throw ();
11698 extern struct tm *gmtime_r (const time_t *__restrict __timer,
11699 struct tm *__restrict __tp) throw ();
11700 extern struct tm *localtime_r (const time_t *__restrict __timer,
11701 struct tm *__restrict __tp) throw ();
11702 extern char *asctime (const struct tm *__tp) throw ();
11703 extern char *ctime (const time_t *__timer) throw ();
11704 extern char *asctime_r (const struct tm *__restrict __tp,
11705 char *__restrict __buf) throw ();
11706 extern char *ctime_r (const time_t *__restrict __timer,
11707 char *__restrict __buf) throw ();
11708 extern char *__tzname[2];
11709 extern int __daylight;
11710 extern long int __timezone;
11711 extern char *tzname[2];
11712 extern void tzset (void) throw ();
11713 extern int daylight;
11714 extern long int timezone;
11715 extern int stime (const time_t *__when) throw ();
11716 extern time_t timegm (struct tm *__tp) throw ();
11717 extern time_t timelocal (struct tm *__tp) throw ();
11718 extern int dysize (int __year) throw () __attribute__ ((__const__));
11719 extern int nanosleep (const struct timespec *__requested_time,
11720 struct timespec *__remaining);
11721 extern int clock_getres (clockid_t __clock_id, struct timespec *__res) throw ();
11722 extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) throw ();
11723 extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
11725 extern int clock_nanosleep (clockid_t __clock_id, int __flags,
11726 const struct timespec *__req,
11727 struct timespec *__rem);
11728 extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) throw ();
11729 extern int timer_create (clockid_t __clock_id,
11730 struct sigevent *__restrict __evp,
11731 timer_t *__restrict __timerid) throw ();
11732 extern int timer_delete (timer_t __timerid) throw ();
11733 extern int timer_settime (timer_t __timerid, int __flags,
11734 const struct itimerspec *__restrict __value,
11735 struct itimerspec *__restrict __ovalue) throw ();
11736 extern int timer_gettime (timer_t __timerid, struct itimerspec *__value)
11738 extern int timer_getoverrun (timer_t __timerid) throw ();
11739 extern int timespec_get (struct timespec *__ts, int __base)
11740 throw () __attribute__ ((__nonnull__ (1)));
11741 extern int getdate_err;
11742 extern struct tm *getdate (const char *__string);
11743 extern int getdate_r (const char *__restrict __string,
11744 struct tm *__restrict __resbufp);
11747 class DSTOffsetCache {
11749 inline DSTOffsetCache();
11750 JSInt64 getDSTOffsetMilliseconds(int64 localTimeMilliseconds, JSContext *cx);
11751 inline void purge();
11753 JSInt64 computeDSTOffsetMilliseconds(int64 localTimeSeconds);
11754 JSInt64 offsetMilliseconds;
11755 JSInt64 rangeStartSeconds, rangeEndSeconds;
11756 JSInt64 oldOffsetMilliseconds;
11757 JSInt64 oldRangeStartSeconds, oldRangeEndSeconds;
11758 static const JSInt64 MAX_UNIX_TIMET = 2145859200;
11759 static const JSInt64 MILLISECONDS_PER_SECOND = 1000;
11760 static const JSInt64 SECONDS_PER_MINUTE = 60;
11761 static const JSInt64 SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
11762 static const JSInt64 SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
11763 static const JSInt64 RANGE_EXPANSION_AMOUNT = 30 * SECONDS_PER_DAY;
11765 void sanityCheck();
11766 void noteOffsetCalculation() {
11769 void noteCacheHit() {
11772 void noteCacheMissIncrease() {
11775 void noteCacheMissDecrease() {
11778 void noteCacheMissIncreasingOffsetChangeUpper() {
11781 void noteCacheMissIncreasingOffsetChangeExpand() {
11784 void noteCacheMissLargeIncrease() {
11787 void noteCacheMissDecreasingOffsetChangeLower() {
11790 void noteCacheMissDecreasingOffsetChangeExpand() {
11793 void noteCacheMissLargeDecrease() {
11798 typedef struct PRMJTime PRMJTime;
11814 PRMJ_LocalGMTDifference(void);
11816 PRMJ_FormatTime(char *buf, int buflen, const char *fmt, PRMJTime *tm);
11818 typedef struct JSGSNCache {
11820 JSDHashTable table;
11823 js_PurgeGSNCache(JSGSNCache *cache);
11824 namespace nanojit {
11828 template<typename K> struct DefaultHash;
11829 template<typename K, typename V, typename H> class HashMap;
11830 template<typename T> class Seq;
11833 static const size_t MONITOR_N_GLOBAL_STATES = 4;
11834 static const size_t FRAGMENT_TABLE_SIZE = 512;
11835 static const size_t MAX_NATIVE_STACK_SLOTS = 4096;
11836 static const size_t MAX_CALL_STACK_ENTRIES = 500;
11837 static const size_t MAX_GLOBAL_SLOTS = 4096;
11838 static const size_t GLOBAL_SLOTS_BUFFER_SIZE = MAX_GLOBAL_SLOTS + 1;
11839 static const size_t MAX_SLOW_NATIVE_EXTRA_SLOTS = 16;
11841 class FrameInfoCache;
11844 struct TreeFragment;
11845 struct TracerState;
11846 template<typename T> class Queue;
11847 typedef Queue<uint16> SlotList;
11851 class JaegerCompartment;
11853 class ContextAllocPolicy
11857 ContextAllocPolicy(JSContext *cx) : cx(cx) {}
11858 JSContext *context() const { return cx; }
11859 void *malloc(size_t bytes);
11860 void free(void *p);
11861 void *realloc(void *p, size_t bytes);
11862 void reportAllocOverflow() const;
11867 StackSegment *previousInContext;
11868 StackSegment *previousInMemory;
11869 JSStackFrame *initialFrame;
11870 JSFrameRegs *suspendedRegs;
11871 JSObject *initialVarObj;
11875 : cx(__null), previousInContext(__null), previousInMemory(__null),
11876 initialFrame(__null), suspendedRegs(((JSFrameRegs *)0x1)),
11877 initialVarObj(__null), saved(false)
11881 Value *valueRangeBegin() const {
11882 return (Value *)(this + 1);
11884 bool inContext() const {
11889 bool isActive() const {
11892 return !suspendedRegs;
11894 bool isSuspended() const {
11897 return cx && suspendedRegs;
11899 bool isSaved() const {
11903 void joinContext(JSContext *cx, JSStackFrame *f) {
11907 suspendedRegs = __null;
11910 void leaveContext() {
11913 initialFrame = __null;
11914 suspendedRegs = ((JSFrameRegs *)0x1);
11917 JSContext *maybeContext() const {
11920 void suspend(JSFrameRegs *regs) {
11923 suspendedRegs = regs;
11928 suspendedRegs = __null;
11931 void save(JSFrameRegs *regs) {
11943 JSStackFrame *getInitialFrame() const {
11945 return initialFrame;
11947 inline JSFrameRegs *getCurrentRegs() const;
11948 inline JSStackFrame *getCurrentFrame() const;
11949 JSFrameRegs *getSuspendedRegs() const {
11951 return suspendedRegs;
11953 JSStackFrame *getSuspendedFrame() const {
11954 return suspendedRegs->fp;
11956 void setPreviousInContext(StackSegment *seg) {
11957 previousInContext = seg;
11959 StackSegment *getPreviousInContext() const {
11960 return previousInContext;
11962 void setPreviousInMemory(StackSegment *seg) {
11963 previousInMemory = seg;
11965 StackSegment *getPreviousInMemory() const {
11966 return previousInMemory;
11968 void setInitialVarObj(JSObject *obj) {
11970 initialVarObj = obj;
11972 bool hasInitialVarObj() {
11974 return initialVarObj != __null;
11976 JSObject &getInitialVarObj() const {
11978 return *initialVarObj;
11981 static const size_t VALUES_PER_STACK_SEGMENT = sizeof(StackSegment) / sizeof(Value);
11982 typedef int js_static_assert63[(sizeof(StackSegment) % sizeof(Value) == 0) ? 1 : -1];
11983 class InvokeArgsGuard : public CallArgs
11985 friend class StackSpace;
11988 Value *prevInvokeArgEnd;
11990 InvokeArgsGuard() : cx(__null), seg(__null) {}
11991 ~InvokeArgsGuard();
11992 bool pushed() const { return cx != __null; }
11994 struct InvokeArgsAlreadyOnTheStack : CallArgs
11996 InvokeArgsAlreadyOnTheStack(Value *vp, uintN argc) : CallArgs(vp + 2, argc) {}
11998 class InvokeFrameGuard
12000 friend class StackSpace;
12003 JSFrameRegs *prevRegs_;
12005 InvokeFrameGuard() : cx_(__null) {}
12006 ~InvokeFrameGuard() { if (pushed()) pop(); }
12007 bool pushed() const { return cx_ != __null; }
12008 JSContext *pushedFrameContext() const { ((void) 0); return cx_; }
12010 JSStackFrame *fp() const { return regs_.fp; }
12014 friend class StackSpace;
12016 StackSegment *seg_;
12020 FrameGuard() : cx_(__null), vp_(__null), fp_(__null) {}
12022 bool pushed() const { return cx_ != __null; }
12023 StackSegment *segment() const { return seg_; }
12024 Value *vp() const { return vp_; }
12025 JSStackFrame *fp() const { return fp_; }
12027 class ExecuteFrameGuard : public FrameGuard
12029 friend class StackSpace;
12032 class DummyFrameGuard : public FrameGuard
12034 friend class StackSpace;
12037 class GeneratorFrameGuard : public FrameGuard
12043 StackSegment *currentSegment;
12044 Value *invokeArgEnd;
12045 friend class InvokeArgsGuard;
12046 friend class InvokeFrameGuard;
12047 friend class FrameGuard;
12048 bool pushSegmentForInvoke(JSContext *cx, uintN argc, InvokeArgsGuard *ag);
12049 void popSegmentForInvoke(const InvokeArgsGuard &ag);
12050 bool pushInvokeFrameSlow(JSContext *cx, const InvokeArgsGuard &ag,
12051 InvokeFrameGuard *fg);
12052 void popInvokeFrameSlow(const CallArgs &args);
12053 bool getSegmentAndFrame(JSContext *cx, uintN vplen, uintN nslots,
12054 FrameGuard *fg) const;
12055 void pushSegmentAndFrame(JSContext *cx, JSFrameRegs *regs, FrameGuard *fg);
12056 void popSegmentAndFrame(JSContext *cx);
12057 struct EnsureSpaceCheck {
12058 inline bool operator()(const StackSpace &, JSContext *, Value *, uintN);
12060 struct LimitCheck {
12061 JSStackFrame *base;
12063 LimitCheck(JSStackFrame *base, Value **limit) : base(base), limit(limit) {}
12064 inline bool operator()(const StackSpace &, JSContext *, Value *, uintN);
12066 template <class Check>
12067 inline JSStackFrame *getCallFrame(JSContext *cx, Value *sp, uintN nactual,
12068 JSFunction *fun, JSScript *script,
12069 uint32 *pflags, Check check) const;
12070 inline void popInvokeArgs(const InvokeArgsGuard &args);
12071 inline void popInvokeFrame(const InvokeFrameGuard &ag);
12072 inline Value *firstUnused() const;
12073 inline bool isCurrentAndActive(JSContext *cx) const;
12074 friend class AllFramesIter;
12075 StackSegment *getCurrentSegment() const { return currentSegment; }
12077 static const size_t CAPACITY_VALS = 512 * 1024;
12078 static const size_t CAPACITY_BYTES = CAPACITY_VALS * sizeof(Value);
12079 static const size_t COMMIT_VALS = 16 * 1024;
12080 static const size_t COMMIT_BYTES = COMMIT_VALS * sizeof(Value);
12081 static const size_t STACK_QUOTA = (VALUES_PER_STACK_FRAME + 18) *
12085 inline bool ensureEnoughSpaceToEnterTrace();
12086 static const ptrdiff_t MAX_TRACE_SPACE_VALS =
12087 MAX_NATIVE_STACK_SLOTS + MAX_CALL_STACK_ENTRIES * VALUES_PER_STACK_FRAME +
12088 (VALUES_PER_STACK_SEGMENT + VALUES_PER_STACK_FRAME );
12089 void mark(JSTracer *trc);
12090 bool pushInvokeArgs(JSContext *cx, uintN argc, InvokeArgsGuard *ag);
12091 bool getInvokeFrame(JSContext *cx, const CallArgs &args, JSFunction *fun,
12092 JSScript *script, uint32 *flags, InvokeFrameGuard *fg) const;
12093 void pushInvokeFrame(JSContext *cx, const CallArgs &args, InvokeFrameGuard *fg);
12094 bool getExecuteFrame(JSContext *cx, JSScript *script, ExecuteFrameGuard *fg) const;
12095 void pushExecuteFrame(JSContext *cx, JSObject *initialVarObj, ExecuteFrameGuard *fg);
12096 inline JSStackFrame *getInlineFrame(JSContext *cx, Value *sp, uintN nactual,
12097 JSFunction *fun, JSScript *script,
12098 uint32 *flags) const;
12099 inline void pushInlineFrame(JSContext *cx, JSScript *script, JSStackFrame *fp,
12100 JSFrameRegs *regs);
12101 inline void popInlineFrame(JSContext *cx, JSStackFrame *prev, js::Value *newsp);
12102 bool getGeneratorFrame(JSContext *cx, uintN vplen, uintN nslots,
12103 GeneratorFrameGuard *fg);
12104 void pushGeneratorFrame(JSContext *cx, JSFrameRegs *regs, GeneratorFrameGuard *fg);
12105 bool pushDummyFrame(JSContext *cx, JSObject &scopeChain, DummyFrameGuard *fg);
12106 inline JSStackFrame *getInlineFrameWithinLimit(JSContext *cx, Value *sp, uintN nactual,
12107 JSFunction *fun, JSScript *script, uint32 *flags,
12108 JSStackFrame *base, Value **limit) const;
12109 inline Value *getStackLimit(JSContext *cx);
12110 bool bumpCommitAndLimit(JSStackFrame *base, Value *from, uintN nvals, Value **limit) const;
12111 inline bool ensureSpace(JSContext *maybecx, Value *from, ptrdiff_t nvals) const;
12113 typedef int js_static_assert64[(StackSpace::CAPACITY_VALS % StackSpace::COMMIT_VALS == 0) ? 1 : -1];
12114 class FrameRegsIter
12117 StackSegment *curseg;
12118 JSStackFrame *curfp;
12122 void incSlow(JSStackFrame *fp, JSStackFrame *prev);
12124 inline FrameRegsIter(JSContext *cx);
12125 bool done() const { return curfp == __null; }
12126 inline FrameRegsIter &operator++();
12127 JSStackFrame *fp() const { return curfp; }
12128 Value *sp() const { return cursp; }
12129 jsbytecode *pc() const { return curpc; }
12131 class AllFramesIter
12134 AllFramesIter(JSContext *cx);
12135 bool done() const { return curfp == __null; }
12136 AllFramesIter& operator++();
12137 JSStackFrame *fp() const { return curfp; }
12139 StackSegment *curcs;
12140 JSStackFrame *curfp;
12143 struct JSPendingProxyOperation {
12144 JSPendingProxyOperation *next;
12147 struct JSThreadData {
12148 unsigned requestDepth;
12149 volatile int32 interruptFlags;
12150 js::StackSpace stackSpace;
12152 JSGSNCache gsnCache;
12153 js::PropertyCache propertyCache;
12154 DtoaState *dtoaState;
12155 jsuword *nativeStackBase;
12156 JSPendingProxyOperation *pendingProxyOperation;
12157 js::ConservativeGCThreadData conservativeGC;
12160 void mark(JSTracer *trc);
12161 void purge(JSContext *cx);
12162 inline void triggerOperationCallback(JSRuntime *rt);
12165 typedef js::HashMap<void *,
12167 js::DefaultHasher<void *>,
12168 js::SystemAllocPolicy> Map;
12169 JSCList contextList;
12171 unsigned suspendCount;
12175 js_CurrentThread(JSRuntime *rt);
12177 js_InitContextThread(JSContext *cx);
12179 js_ClearContextThread(JSContext *cx);
12180 typedef enum JSDestroyContextMode {
12185 } JSDestroyContextMode;
12186 typedef enum JSRuntimeState {
12192 typedef struct JSPropertyTreeEntry {
12193 JSDHashEntryHdr hdr;
12195 } JSPropertyTreeEntry;
12197 (* JSActivityCallback)(void *arg, JSBool active);
12199 typedef js::Vector<JSCompartment *, 0, js::SystemAllocPolicy> WrapperVector;
12202 JSCompartment *atomsCompartment;
12203 bool atomsCompartmentIsLocked;
12204 js::WrapperVector compartments;
12205 JSRuntimeState state;
12206 JSContextCallback cxCallback;
12207 JSCompartmentCallback compartmentCallback;
12208 void setActivityCallback(JSActivityCallback cb, void *arg) {
12209 activityCallback = cb;
12210 activityCallbackArg = arg;
12212 JSActivityCallback activityCallback;
12213 void *activityCallbackArg;
12214 uint32 protoHazardShape;
12215 js::GCChunkSet gcChunkSet;
12216 js::RootedValueMap gcRootsHash;
12217 js::GCLocks gcLocksHash;
12218 jsrefcount gcKeepAtoms;
12220 size_t gcTriggerBytes;
12221 size_t gcLastBytes;
12223 size_t gcMaxMallocBytes;
12224 size_t gcChunksWaitingToExpire;
12225 uint32 gcEmptyArenaPoolLifespan;
12227 js::GCMarker *gcMarkingTracer;
12228 uint32 gcTriggerFactor;
12229 int64 gcJitReleaseTime;
12231 volatile bool gcIsNeeded;
12232 JSCompartment *gcTriggerCompartment;
12233 JSCompartment *gcCurrentCompartment;
12235 bool gcMarkAndSweep;
12237 bool gcRegenShapes;
12238 JSGCCallback gcCallback;
12240 volatile ptrdiff_t gcMallocBytes;
12242 js::GCChunkAllocator *gcChunkAllocator;
12243 void setCustomGCChunkAllocator(js::GCChunkAllocator *allocator) {
12246 gcChunkAllocator = allocator;
12248 JSTraceDataOp gcExtraRootsTraceOp;
12249 void *gcExtraRootsData;
12250 js::Value NaNValue;
12251 js::Value negativeInfinityValue;
12252 js::Value positiveInfinityValue;
12253 JSFlatString *emptyString;
12254 JSCList contextList;
12255 JSDebugHooks globalDebugHooks;
12258 JSCList watchPointList;
12262 PRCondVar *requestDone;
12263 uint32 requestCount;
12264 JSThread *gcThread;
12265 js::GCHelperThread gcHelperThread;
12267 PRCondVar *stateChange;
12268 PRLock *debuggerLock;
12269 JSThread::Map threads;
12270 uint32 debuggerMutations;
12271 JSSecurityCallbacks *securityCallbacks;
12272 const JSStructuredCloneCallbacks *structuredCloneCallbacks;
12273 int32 propertyRemovals;
12274 struct JSHashTable *scriptFilenameTable;
12275 JSCList scriptFilenamePrefixes;
12276 PRLock *scriptFilenameTableLock;
12277 const char *thousandsSeparator;
12278 const char *decimalSeparator;
12279 const char *numGrouping;
12280 JSObject *anynameObject;
12281 JSObject *functionNamespaceObject;
12282 volatile int32 interruptCounter;
12283 volatile uint32 shapeGen;
12284 JSAtomState atomState;
12285 JSWrapObjectCallback wrapObjectCallback;
12286 JSPreWrapCallback preWrapObjectCallback;
12287 uint32 stringMemoryUsed;
12290 bool init(uint32 maxbytes);
12291 void setGCTriggerFactor(uint32 factor);
12292 void setGCLastBytes(size_t lastBytes);
12293 void* malloc(size_t bytes, JSContext *cx = __null) {
12294 updateMallocCounter(bytes);
12295 void *p = ::js_malloc(bytes);
12296 return (__builtin_expect((!!p), 1)) ? p : onOutOfMemory(__null, bytes, cx);
12298 void* calloc(size_t bytes, JSContext *cx = __null) {
12299 updateMallocCounter(bytes);
12300 void *p = ::js_calloc(bytes);
12301 return (__builtin_expect((!!p), 1)) ? p : onOutOfMemory(reinterpret_cast<void *>(1), bytes, cx);
12303 void* realloc(void* p, size_t oldBytes, size_t newBytes, JSContext *cx = __null) {
12305 updateMallocCounter(newBytes - oldBytes);
12306 void *p2 = ::js_realloc(p, newBytes);
12307 return (__builtin_expect((!!p2), 1)) ? p2 : onOutOfMemory(p, newBytes, cx);
12309 void* realloc(void* p, size_t bytes, JSContext *cx = __null) {
12311 updateMallocCounter(bytes);
12312 void *p2 = ::js_realloc(p, bytes);
12313 return (__builtin_expect((!!p2), 1)) ? p2 : onOutOfMemory(p, bytes, cx);
12315 void free(void* p) { ::js_free(p); }
12316 bool isGCMallocLimitReached() const { return gcMallocBytes <= 0; }
12317 void resetGCMallocBytes() { gcMallocBytes = ptrdiff_t(gcMaxMallocBytes); }
12318 void setGCMaxMallocBytes(size_t value) {
12319 gcMaxMallocBytes = (ptrdiff_t(value) >= 0) ? value : size_t(-1) >> 1;
12320 resetGCMallocBytes();
12322 void updateMallocCounter(size_t nbytes) {
12323 ptrdiff_t newCount = gcMallocBytes - ptrdiff_t(nbytes);
12324 gcMallocBytes = newCount;
12325 if ((__builtin_expect((newCount <= 0), 0)))
12329 __attribute__((visibility ("default"))) void onTooMuchMalloc();
12330 __attribute__((visibility ("default"))) void * onOutOfMemory(void *p, size_t nbytes, JSContext *cx);
12332 struct JSArgumentFormatMap {
12333 const char *format;
12335 JSArgumentFormatter formatter;
12336 JSArgumentFormatMap *next;
12338 typedef struct JSResolvingKey {
12342 typedef struct JSResolvingEntry {
12343 JSDHashEntryHdr hdr;
12344 JSResolvingKey key;
12346 } JSResolvingEntry;
12347 extern const JSDebugHooks js_NullDebugHooks;
12349 class AutoGCRooter;
12352 OptionsHasXML(uint32 options)
12354 return !!(options & ((JSUint32)1 << (6)));
12358 OptionsHasAnonFunFix(uint32 options)
12360 return !!(options & ((JSUint32)1 << (10)));
12364 OptionsSameVersionFlags(uint32 self, uint32 other)
12366 static const uint32 mask = ((JSUint32)1 << (6)) | ((JSUint32)1 << (10));
12367 return !((self & mask) ^ (other & mask));
12369 namespace VersionFlags {
12370 static const uintN MASK = 0x0FFF;
12371 static const uintN HAS_XML = 0x1000;
12372 static const uintN ANONFUNFIX = 0x2000;
12373 static const uintN FULL_MASK = 0x3FFF;
12375 static inline JSVersion
12376 VersionNumber(JSVersion version)
12378 return JSVersion(uint32(version) & VersionFlags::MASK);
12382 VersionHasXML(JSVersion version)
12384 return !!(version & VersionFlags::HAS_XML);
12388 VersionShouldParseXML(JSVersion version)
12390 return VersionHasXML(version) || VersionNumber(version) >= JSVERSION_1_6;
12394 VersionHasAnonFunFix(JSVersion version)
12396 return !!(version & VersionFlags::ANONFUNFIX);
12399 VersionSetXML(JSVersion *version, bool enable)
12402 *version = JSVersion(uint32(*version) | VersionFlags::HAS_XML);
12404 *version = JSVersion(uint32(*version) & ~VersionFlags::HAS_XML);
12407 VersionSetAnonFunFix(JSVersion *version, bool enable)
12410 *version = JSVersion(uint32(*version) | VersionFlags::ANONFUNFIX);
12412 *version = JSVersion(uint32(*version) & ~VersionFlags::ANONFUNFIX);
12414 static inline JSVersion
12415 VersionExtractFlags(JSVersion version)
12417 return JSVersion(uint32(version) & ~VersionFlags::MASK);
12420 VersionCopyFlags(JSVersion *version, JSVersion from)
12422 *version = JSVersion(VersionNumber(*version) | VersionExtractFlags(from));
12426 VersionHasFlags(JSVersion version)
12428 return !!VersionExtractFlags(version);
12430 static inline uintN
12431 VersionFlagsToOptions(JSVersion version)
12433 uintN copts = (VersionHasXML(version) ? ((JSUint32)1 << (6)) : 0) |
12434 (VersionHasAnonFunFix(version) ? ((JSUint32)1 << (10)) : 0);
12438 static inline JSVersion
12439 OptionFlagsToVersion(uintN options, JSVersion version)
12441 VersionSetXML(&version, OptionsHasXML(options));
12442 VersionSetAnonFunFix(&version, OptionsHasAnonFunFix(options));
12447 VersionIsKnown(JSVersion version)
12449 return VersionNumber(version) != JSVERSION_UNKNOWN;
12451 typedef js::HashSet<JSObject *,
12452 js::DefaultHasher<JSObject *>,
12453 js::SystemAllocPolicy> BusyArraysMap;
12457 explicit JSContext(JSRuntime *rt);
12460 JSVersion defaultVersion;
12461 JSVersion versionOverride;
12462 bool hasVersionOverride;
12464 js::Value exception;
12467 JSLocaleCallbacks *localeCallbacks;
12468 JSDHashTable *resolvingTable;
12469 JSPackedBool generatingError;
12470 jsuword stackLimit;
12471 size_t scriptStackQuota;
12472 JSRuntime *const runtime;
12473 JSCompartment *compartment;
12476 JSStackFrame* fp() {
12480 JSStackFrame* maybefp() {
12482 return regs ? regs->fp : __null;
12489 friend class js::StackSpace;
12490 friend bool js::Interpret(JSContext *, JSStackFrame *, uintN, JSInterpMode);
12491 void resetCompartment();
12492 void wrapPendingException();
12493 void setCurrentRegs(JSFrameRegs *regs) {
12497 JSArenaPool tempPool;
12498 JSArenaPool regExpPool;
12499 JSObject *globalObject;
12500 JSSharpObjectMap sharpObjectMap;
12501 js::BusyArraysMap busyArrays;
12502 JSArgumentFormatMap *argumentFormatMap;
12504 JSErrorReporter errorReporter;
12505 JSOperationCallback operationCallback;
12510 js::StackSegment *currentSegment;
12512 void assertSegmentsInSync() const {
12514 bool hasActiveSegment() const {
12515 assertSegmentsInSync();
12518 js::StackSegment *activeSegment() const {
12520 return currentSegment;
12522 js::StackSegment *getCurrentSegment() const {
12523 assertSegmentsInSync();
12524 return currentSegment;
12526 inline js::RegExpStatics *regExpStatics();
12527 void pushSegmentAndFrame(js::StackSegment *newseg, JSFrameRegs ®s);
12528 void popSegmentAndFrame();
12529 void saveActiveSegment();
12530 void restoreSegment();
12531 inline JSStackFrame *computeNextFrame(JSStackFrame *fp);
12532 js::StackSegment *containingSegment(const JSStackFrame *target);
12533 JSStackFrame *findFrameAtLevel(uintN targetLevel) const {
12534 JSStackFrame *fp = regs->fp;
12537 if (fp->script()->staticLevel == targetLevel)
12544 bool canSetDefaultVersion() const {
12545 return !regs && !hasVersionOverride;
12547 void overrideVersion(JSVersion newVersion) {
12549 versionOverride = newVersion;
12550 hasVersionOverride = true;
12552 void setDefaultVersion(JSVersion version) {
12553 defaultVersion = version;
12555 void clearVersionOverride() { hasVersionOverride = false; }
12556 JSVersion getDefaultVersion() const { return defaultVersion; }
12557 bool isVersionOverridden() const { return hasVersionOverride; }
12558 JSVersion getVersionOverride() const {
12560 return versionOverride;
12562 bool maybeOverrideVersion(JSVersion newVersion) {
12563 if (canSetDefaultVersion()) {
12564 setDefaultVersion(newVersion);
12567 overrideVersion(newVersion);
12571 void maybeMigrateVersionOverride() {
12572 if ((__builtin_expect((!isVersionOverridden() || currentSegment), 1)))
12574 defaultVersion = versionOverride;
12575 clearVersionOverride();
12578 JSVersion findVersion() const {
12579 if (hasVersionOverride)
12580 return versionOverride;
12582 JSStackFrame *fp = regs->fp;
12583 while (fp && !fp->isScriptFrame())
12586 return fp->script()->getVersion();
12588 return defaultVersion;
12590 void setRunOptions(uintN ropts) {
12592 runOptions = ropts;
12594 void setCompileOptions(uintN newcopts) {
12596 if ((__builtin_expect((getCompileOptions() == newcopts), 1)))
12598 JSVersion version = findVersion();
12599 JSVersion newVersion = js::OptionFlagsToVersion(newcopts, version);
12600 maybeOverrideVersion(newVersion);
12602 uintN getRunOptions() const { return runOptions; }
12603 uintN getCompileOptions() const { return js::VersionFlagsToOptions(findVersion()); }
12604 uintN allOptions() const { return getRunOptions() | getCompileOptions(); }
12605 bool hasRunOption(uintN ropt) const {
12607 return !!(runOptions & ropt);
12609 bool hasStrictOption() const { return hasRunOption(((JSUint32)1 << (0))); }
12610 bool hasWErrorOption() const { return hasRunOption(((JSUint32)1 << (1))); }
12611 bool hasAtLineOption() const { return hasRunOption(((JSUint32)1 << (5))); }
12613 unsigned outstandingRequests;
12614 JSCList threadLinks;
12615 js::AutoGCRooter *autoGCRooters;
12616 const JSDebugHooks *debugHooks;
12617 JSSecurityCallbacks *securityCallbacks;
12618 uintN resolveFlags;
12620 js::Value iterValue;
12621 void updateJITEnabled();
12622 DSTOffsetCache dstOffsetCache;
12623 JSObject *enumerators;
12625 js::Vector<JSGenerator *, 2, js::SystemAllocPolicy> genStack;
12627 JSGenerator *generatorFor(JSStackFrame *fp) const;
12628 inline bool ensureGeneratorStackSpace();
12629 bool enterGenerator(JSGenerator *gen) {
12630 return genStack.append(gen);
12632 void leaveGenerator(JSGenerator *gen) {
12634 genStack.popBack();
12636 js::GCHelperThread *gcBackgroundFree;
12637 inline void* malloc(size_t bytes) {
12638 return runtime->malloc(bytes, this);
12640 inline void* mallocNoReport(size_t bytes) {
12642 return runtime->malloc(bytes, __null);
12644 inline void* calloc(size_t bytes) {
12646 return runtime->calloc(bytes, this);
12648 inline void* realloc(void* p, size_t bytes) {
12649 return runtime->realloc(p, bytes, this);
12651 inline void* realloc(void* p, size_t oldBytes, size_t newBytes) {
12652 return runtime->realloc(p, oldBytes, newBytes, this);
12654 inline void free(void* p) {
12655 if (gcBackgroundFree) {
12656 gcBackgroundFree->freeLater(p);
12662 __attribute__((always_inline)) inline T *create() {
12663 void *memory = this->malloc(sizeof(T)); if (!memory) return __null; return new(memory) T ();
12665 template <class T, class P1>
12666 __attribute__((always_inline)) inline T *create(const P1 &p1) {
12667 void *memory = this->malloc(sizeof(T)); if (!memory) return __null; return new(memory) T (p1);
12669 template <class T, class P1, class P2>
12670 __attribute__((always_inline)) inline T *create(const P1 &p1, const P2 &p2) {
12671 void *memory = this->malloc(sizeof(T)); if (!memory) return __null; return new(memory) T (p1, p2);
12673 template <class T, class P1, class P2, class P3>
12674 __attribute__((always_inline)) inline T *create(const P1 &p1, const P2 &p2, const P3 &p3) {
12675 void *memory = this->malloc(sizeof(T)); if (!memory) return __null; return new(memory) T (p1, p2, p3);
12678 __attribute__((always_inline)) inline void destroy(T *p) {
12683 js::StackSpace &stack() const {
12684 return (&(this)->thread->data)->stackSpace;
12686 void assertValidStackDepth(uintN ) {}
12687 bool isExceptionPending() {
12690 js::Value getPendingException() {
12694 void setPendingException(js::Value v);
12695 void clearPendingException() {
12696 this->throwing = false;
12697 this->exception.setUndefined();
12700 __attribute__((visibility ("default"))) void checkMallocGCPressure(void *p);
12702 static inline uintN
12703 FramePCOffset(JSContext *cx, JSStackFrame* fp)
12705 jsbytecode *pc = fp->hasImacropc() ? fp->imacropc() : fp->pc(cx);
12706 return uintN(pc - fp->script()->code);
12708 static inline JSAtom **
12709 FrameAtomBase(JSContext *cx, JSStackFrame *fp)
12711 return fp->hasImacropc()
12712 ? ((JSAtom **)((uint8 *)(&cx->runtime->atomState) + __builtin_offsetof (JSAtomState, emptyAtom)))
12713 : fp->script()->atomMap.vector;
12716 class AutoGCRooter {
12718 AutoGCRooter(JSContext *cx, ptrdiff_t tag)
12719 : down(cx->autoGCRooters), tag(tag), context(cx)
12723 cx->autoGCRooters = this;
12728 context->autoGCRooters = down;
12730 inline void trace(JSTracer *trc);
12731 friend __attribute__((visibility ("default"))) void MarkContext(JSTracer *trc, JSContext *acx);
12732 friend void MarkRuntime(JSTracer *trc);
12734 AutoGCRooter * const down;
12736 JSContext * const context;
12757 AutoGCRooter(AutoGCRooter &ida);
12758 void operator=(AutoGCRooter &ida);
12760 class AutoValueRooter : private AutoGCRooter
12763 explicit AutoValueRooter(JSContext *cx
12765 : AutoGCRooter(cx, JSVAL), val(js::NullValue())
12769 AutoValueRooter(JSContext *cx, const Value &v
12771 : AutoGCRooter(cx, JSVAL), val(v)
12775 AutoValueRooter(JSContext *cx, jsval v
12777 : AutoGCRooter(cx, JSVAL), val(js::Valueify(v))
12781 void set(Value v) {
12785 void set(jsval v) {
12787 val = js::Valueify(v);
12789 const Value &value() const {
12797 const jsval &jsval_value() const {
12799 return Jsvalify(val);
12801 jsval *jsval_addr() {
12803 return Jsvalify(&val);
12805 friend void AutoGCRooter::trace(JSTracer *trc);
12806 friend void MarkRuntime(JSTracer *trc);
12811 class AutoObjectRooter : private AutoGCRooter {
12813 AutoObjectRooter(JSContext *cx, JSObject *obj = __null
12815 : AutoGCRooter(cx, OBJECT), obj(obj)
12819 void setObject(JSObject *obj) {
12822 JSObject * object() const {
12825 JSObject ** addr() {
12828 friend void AutoGCRooter::trace(JSTracer *trc);
12829 friend void MarkRuntime(JSTracer *trc);
12834 class AutoStringRooter : private AutoGCRooter {
12836 AutoStringRooter(JSContext *cx, JSString *str = __null
12838 : AutoGCRooter(cx, STRING), str(str)
12842 void setString(JSString *str) {
12845 JSString * string() const {
12848 JSString ** addr() {
12851 friend void AutoGCRooter::trace(JSTracer *trc);
12856 class AutoArrayRooter : private AutoGCRooter {
12858 AutoArrayRooter(JSContext *cx, size_t len, Value *vec
12860 : AutoGCRooter(cx, len), array(vec)
12865 AutoArrayRooter(JSContext *cx, size_t len, jsval *vec
12867 : AutoGCRooter(cx, len), array(Valueify(vec))
12872 void changeLength(size_t newLength) {
12873 tag = ptrdiff_t(newLength);
12876 void changeArray(Value *newArray, size_t newLength) {
12877 changeLength(newLength);
12881 friend void AutoGCRooter::trace(JSTracer *trc);
12885 class AutoShapeRooter : private AutoGCRooter {
12887 AutoShapeRooter(JSContext *cx, const js::Shape *shape
12889 : AutoGCRooter(cx, SHAPE), shape(shape)
12893 friend void AutoGCRooter::trace(JSTracer *trc);
12894 friend void MarkRuntime(JSTracer *trc);
12896 const js::Shape * const shape;
12899 class AutoScriptRooter : private AutoGCRooter {
12901 AutoScriptRooter(JSContext *cx, JSScript *script
12903 : AutoGCRooter(cx, SCRIPT), script(script)
12907 void setScript(JSScript *script) {
12908 this->script = script;
12910 friend void AutoGCRooter::trace(JSTracer *trc);
12915 class AutoIdRooter : private AutoGCRooter
12918 explicit AutoIdRooter(JSContext *cx, jsid id = INT_TO_JSID(0)
12920 : AutoGCRooter(cx, ID), id_(id)
12930 friend void AutoGCRooter::trace(JSTracer *trc);
12931 friend void MarkRuntime(JSTracer *trc);
12936 class AutoIdArray : private AutoGCRooter {
12938 AutoIdArray(JSContext *cx, JSIdArray *ida )
12939 : AutoGCRooter(cx, IDARRAY), idArray(ida)
12945 JS_DestroyIdArray(context, idArray);
12948 return idArray == __null;
12950 jsid operator[](size_t i) const {
12953 return idArray->vector[i];
12955 size_t length() const {
12956 return idArray->length;
12958 friend void AutoGCRooter::trace(JSTracer *trc);
12959 JSIdArray *steal() {
12960 JSIdArray *copy = idArray;
12965 inline void trace(JSTracer *trc);
12967 JSIdArray * idArray;
12969 AutoIdArray(AutoIdArray &ida);
12970 void operator=(AutoIdArray &ida);
12972 class AutoEnumStateRooter : private AutoGCRooter
12975 AutoEnumStateRooter(JSContext *cx, JSObject *obj
12977 : AutoGCRooter(cx, ENUMERATOR), obj(obj), stateValue()
12982 ~AutoEnumStateRooter() {
12983 if (!stateValue.isNull()) {
12984 obj->enumerate(context, JSENUMERATE_DESTROY, &stateValue, 0);
12988 friend void AutoGCRooter::trace(JSTracer *trc);
12989 const Value &state() const { return stateValue; }
12990 Value *addr() { return &stateValue; }
12992 void trace(JSTracer *trc);
12993 JSObject * const obj;
12998 class AutoXMLRooter : private AutoGCRooter {
13000 AutoXMLRooter(JSContext *cx, JSXML *xml
13002 : AutoGCRooter(cx, XML), xml(xml)
13007 friend void AutoGCRooter::trace(JSTracer *trc);
13008 friend void MarkRuntime(JSTracer *trc);
13013 class AutoBindingsRooter : private AutoGCRooter {
13015 AutoBindingsRooter(JSContext *cx, Bindings &bindings
13017 : AutoGCRooter(cx, BINDINGS), bindings(bindings)
13021 friend void AutoGCRooter::trace(JSTracer *trc);
13023 Bindings &bindings;
13028 explicit AutoLockGC(JSRuntime *rt
13033 PR_Lock((rt)->gcLock);
13035 ~AutoLockGC() { PR_Unlock((rt)->gcLock); }
13040 class AutoUnlockGC {
13045 explicit AutoUnlockGC(JSRuntime *rt
13050 PR_Unlock((rt)->gcLock);
13052 ~AutoUnlockGC() { PR_Lock((rt)->gcLock); }
13054 class AutoLockAtomsCompartment {
13059 AutoLockAtomsCompartment(JSContext *cx
13064 js_Lock(cx, &cx->runtime->atomState.lock);
13065 cx->runtime->atomsCompartmentIsLocked = true;
13067 ~AutoLockAtomsCompartment() {
13068 cx->runtime->atomsCompartmentIsLocked = false;
13069 js_Unlock(cx, &cx->runtime->atomState.lock);
13072 class AutoUnlockAtomsCompartment {
13076 AutoUnlockAtomsCompartment(JSContext *cx
13081 cx->runtime->atomsCompartmentIsLocked = false;
13082 js_Unlock(cx, &cx->runtime->atomState.lock);
13084 ~AutoUnlockAtomsCompartment() {
13085 js_Lock(cx, &cx->runtime->atomState.lock);
13086 cx->runtime->atomsCompartmentIsLocked = true;
13089 class AutoKeepAtoms {
13093 explicit AutoKeepAtoms(JSRuntime *rt
13098 PR_AtomicIncrement((PRInt32 *)(&(rt)->gcKeepAtoms));;
13100 ~AutoKeepAtoms() { PR_AtomicDecrement((PRInt32 *)(&(rt)->gcKeepAtoms));; }
13102 class AutoArenaAllocator {
13107 explicit AutoArenaAllocator(JSArenaPool *pool
13109 : pool(pool), mark(((void *) (pool)->current->avail))
13113 ~AutoArenaAllocator() { do { char *_m = (char *)(mark); JSArena *_a = (pool)->current; if (_a != &(pool)->first && (((jsuword)(_m) - (jsuword)((_a)->base)) <= ((jsuword)((_a)->avail) - (jsuword)((_a)->base)))) { _a->avail = (jsuword)(((jsuword)(_m) + (pool)->mask) & ~(pool)->mask); ((void) 0); ; ; } else { JS_ArenaRelease(pool, _m); } ; } while (0); }
13114 template <typename T>
13115 T *alloc(size_t elems) {
13117 do { JSArena *_a = (pool)->current; size_t _nb = (((jsuword)(elems * sizeof(T)) + (pool)->mask) & ~(pool)->mask); jsuword _p = _a->avail; if ((_nb > _a->limit) || _p > _a->limit - _nb) _p = (jsuword)JS_ArenaAllocate(pool, _nb); else _a->avail = _p + _nb; ptr = (void *) _p; do { } while (0) ; } while (0);
13118 return static_cast<T *>(ptr);
13121 class AutoReleasePtr {
13125 AutoReleasePtr operator=(const AutoReleasePtr &other);
13127 explicit AutoReleasePtr(JSContext *cx, void *ptr
13133 ~AutoReleasePtr() { cx->free(ptr); }
13135 class AutoReleaseNullablePtr {
13139 AutoReleaseNullablePtr operator=(const AutoReleaseNullablePtr &other);
13141 explicit AutoReleaseNullablePtr(JSContext *cx, void *ptr
13147 void reset(void *ptr2) {
13152 ~AutoReleaseNullablePtr() { if (ptr) cx->free(ptr); }
13154 class AutoLocalNameArray {
13156 explicit AutoLocalNameArray(JSContext *cx, JSFunction *fun
13159 mark(((void *) (&cx->tempPool)->current->avail)),
13160 names(fun->script()->bindings.getLocalNameArray(cx, &cx->tempPool)),
13161 count(fun->script()->bindings.countLocalNames())
13165 ~AutoLocalNameArray() {
13166 do { char *_m = (char *)(mark); JSArena *_a = (&context->tempPool)->current; if (_a != &(&context->tempPool)->first && (((jsuword)(_m) - (jsuword)((_a)->base)) <= ((jsuword)((_a)->avail) - (jsuword)((_a)->base)))) { _a->avail = (jsuword)(((jsuword)(_m) + (&context->tempPool)->mask) & ~(&context->tempPool)->mask); ((void) 0); ; ; } else { JS_ArenaRelease(&context->tempPool, _m); } ; } while (0);
13168 operator bool() const { return !!names; }
13169 uint32 length() const { return count; }
13170 const jsuword &operator [](unsigned i) const { return names[i]; }
13172 JSContext *context;
13178 template <class RefCountable>
13179 class AlreadyIncRefed
13181 typedef RefCountable *****ConvertibleToBool;
13184 explicit AlreadyIncRefed(RefCountable *obj) : obj(obj) {}
13185 bool null() const { return obj == __null; }
13186 operator ConvertibleToBool() const { return (ConvertibleToBool)obj; }
13187 RefCountable *operator->() const { ((void) 0); return obj; }
13188 RefCountable &operator*() const { ((void) 0); return *obj; }
13189 RefCountable *get() const { return obj; }
13191 template <class RefCountable>
13194 typedef RefCountable *****ConvertibleToBool;
13197 explicit NeedsIncRef(RefCountable *obj) : obj(obj) {}
13198 bool null() const { return obj == __null; }
13199 operator ConvertibleToBool() const { return (ConvertibleToBool)obj; }
13200 RefCountable *operator->() const { ((void) 0); return obj; }
13201 RefCountable &operator*() const { ((void) 0); return *obj; }
13202 RefCountable *get() const { return obj; }
13204 template <class RefCountable>
13207 typedef RefCountable *****ConvertibleToBool;
13208 JSContext *const cx;
13210 AutoRefCount(const AutoRefCount &);
13211 void operator=(const AutoRefCount &);
13213 explicit AutoRefCount(JSContext *cx)
13214 : cx(cx), obj(__null)
13216 AutoRefCount(JSContext *cx, NeedsIncRef<RefCountable> aobj)
13217 : cx(cx), obj(aobj.get())
13222 AutoRefCount(JSContext *cx, AlreadyIncRefed<RefCountable> aobj)
13223 : cx(cx), obj(aobj.get())
13229 void reset(NeedsIncRef<RefCountable> aobj) {
13236 void reset(AlreadyIncRefed<RefCountable> aobj) {
13241 bool null() const { return obj == __null; }
13242 operator ConvertibleToBool() const { return (ConvertibleToBool)obj; }
13243 RefCountable *operator->() const { ((void) 0); return obj; }
13244 RefCountable &operator*() const { ((void) 0); return *obj; }
13245 RefCountable *get() const { return obj; }
13248 class JSAutoResolveFlags
13251 JSAutoResolveFlags(JSContext *cx, uintN flags
13253 : mContext(cx), mSaved(cx->resolveFlags)
13256 cx->resolveFlags = flags;
13258 ~JSAutoResolveFlags() { mContext->resolveFlags = mSaved; }
13260 JSContext *mContext;
13264 extern JSThreadData *
13265 js_CurrentThreadData(JSRuntime *rt);
13267 js_InitThreads(JSRuntime *rt);
13269 js_FinishThreads(JSRuntime *rt);
13271 js_PurgeThreads(JSContext *cx);
13273 class ThreadDataIter : public JSThread::Map::Range
13276 ThreadDataIter(JSRuntime *rt) : JSThread::Map::Range(rt->threads.all()) {}
13277 JSThreadData *threadData() const {
13278 return &front().value->data;
13283 js_NewContext(JSRuntime *rt, size_t stackChunkSize);
13285 js_DestroyContext(JSContext *cx, JSDestroyContextMode mode);
13286 static inline JSContext *
13287 js_ContextFromLinkField(JSCList *link)
13290 return (JSContext *) ((uint8 *) link - __builtin_offsetof (JSContext, link));
13293 js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp);
13294 extern __attribute__((visibility ("default"))) JSContext *
13295 js_NextActiveContext(JSRuntime *, JSContext *);
13297 js_StartResolving(JSContext *cx, JSResolvingKey *key, uint32 flag,
13298 JSResolvingEntry **entryp);
13300 js_StopResolving(JSContext *cx, JSResolvingKey *key, uint32 flag,
13301 JSResolvingEntry *entry, uint32 generation);
13302 typedef enum JSErrNum {
13303 JSMSG_NOT_AN_ERROR = 0,
13304 JSMSG_NOT_DEFINED = 1,
13305 JSMSG_INACTIVE = 2,
13306 JSMSG_MORE_ARGS_NEEDED = 3,
13307 JSMSG_BAD_CHAR = 4,
13308 JSMSG_BAD_TYPE = 5,
13309 JSMSG_ALLOC_OVERFLOW = 6,
13310 JSMSG_MISSING_HEXDIGITS = 7,
13311 JSMSG_INCOMPATIBLE_PROTO = 8,
13312 JSMSG_NO_CONSTRUCTOR = 9,
13313 JSMSG_CANT_ALIAS = 10,
13314 JSMSG_NOT_SCRIPTED_FUNCTION = 11,
13315 JSMSG_BAD_SORT_ARG = 12,
13316 JSMSG_BAD_ATOMIC_NUMBER = 13,
13317 JSMSG_TOO_MANY_LITERALS = 14,
13318 JSMSG_CANT_WATCH = 15,
13319 JSMSG_STACK_UNDERFLOW = 16,
13320 JSMSG_NEED_DIET = 17,
13321 JSMSG_TOO_MANY_LOCAL_ROOTS = 18,
13322 JSMSG_READ_ONLY = 19,
13323 JSMSG_BAD_FORMAL = 20,
13324 JSMSG_CANT_DELETE = 21,
13325 JSMSG_NOT_FUNCTION = 22,
13326 JSMSG_NOT_CONSTRUCTOR = 23,
13327 JSMSG_SCRIPT_STACK_QUOTA = 24,
13328 JSMSG_TOO_DEEP = 25,
13329 JSMSG_OVER_RECURSED = 26,
13330 JSMSG_IN_NOT_OBJECT = 27,
13331 JSMSG_BAD_NEW_RESULT = 28,
13332 JSMSG_BAD_SHARP_DEF = 29,
13333 JSMSG_BAD_SHARP_USE = 30,
13334 JSMSG_BAD_INSTANCEOF_RHS = 31,
13335 JSMSG_BAD_BYTECODE = 32,
13336 JSMSG_BAD_RADIX = 33,
13337 JSMSG_PAREN_BEFORE_LET = 34,
13338 JSMSG_CANT_CONVERT = 35,
13339 JSMSG_CYCLIC_VALUE = 36,
13340 JSMSG_COMPILE_EXECED_SCRIPT = 37,
13341 JSMSG_CANT_CONVERT_TO = 38,
13342 JSMSG_NO_PROPERTIES = 39,
13343 JSMSG_CANT_FIND_CLASS = 40,
13344 JSMSG_CANT_XDR_CLASS = 41,
13345 JSMSG_BYTECODE_TOO_BIG = 42,
13346 JSMSG_UNKNOWN_FORMAT = 43,
13347 JSMSG_TOO_MANY_CON_ARGS = 44,
13348 JSMSG_TOO_MANY_FUN_ARGS = 45,
13349 JSMSG_BAD_QUANTIFIER = 46,
13350 JSMSG_MIN_TOO_BIG = 47,
13351 JSMSG_MAX_TOO_BIG = 48,
13352 JSMSG_OUT_OF_ORDER = 49,
13353 JSMSG_BAD_DESTRUCT_DECL = 50,
13354 JSMSG_BAD_DESTRUCT_ASS = 51,
13355 JSMSG_PAREN_AFTER_LET = 52,
13356 JSMSG_CURLY_AFTER_LET = 53,
13357 JSMSG_MISSING_PAREN = 54,
13358 JSMSG_UNTERM_CLASS = 55,
13359 JSMSG_TRAILING_SLASH = 56,
13360 JSMSG_BAD_CLASS_RANGE = 57,
13361 JSMSG_BAD_REGEXP_FLAG = 58,
13362 JSMSG_NO_INPUT = 59,
13363 JSMSG_CANT_OPEN = 60,
13364 JSMSG_BAD_STRING_MASK = 61,
13365 JSMSG_UNMATCHED_RIGHT_PAREN = 62,
13366 JSMSG_END_OF_DATA = 63,
13367 JSMSG_SEEK_BEYOND_START = 64,
13368 JSMSG_SEEK_BEYOND_END = 65,
13369 JSMSG_END_SEEK = 66,
13370 JSMSG_WHITHER_WHENCE = 67,
13371 JSMSG_BAD_SCRIPT_MAGIC = 68,
13372 JSMSG_PAREN_BEFORE_FORMAL = 69,
13373 JSMSG_MISSING_FORMAL = 70,
13374 JSMSG_PAREN_AFTER_FORMAL = 71,
13375 JSMSG_CURLY_BEFORE_BODY = 72,
13376 JSMSG_CURLY_AFTER_BODY = 73,
13377 JSMSG_PAREN_BEFORE_COND = 74,
13378 JSMSG_PAREN_AFTER_COND = 75,
13379 JSMSG_DESTRUCT_DUP_ARG = 76,
13380 JSMSG_NAME_AFTER_DOT = 77,
13381 JSMSG_BRACKET_IN_INDEX = 78,
13382 JSMSG_XML_WHOLE_PROGRAM = 79,
13383 JSMSG_PAREN_BEFORE_SWITCH = 80,
13384 JSMSG_PAREN_AFTER_SWITCH = 81,
13385 JSMSG_CURLY_BEFORE_SWITCH = 82,
13386 JSMSG_COLON_AFTER_CASE = 83,
13387 JSMSG_WHILE_AFTER_DO = 84,
13388 JSMSG_PAREN_AFTER_FOR = 85,
13389 JSMSG_SEMI_AFTER_FOR_INIT = 86,
13390 JSMSG_SEMI_AFTER_FOR_COND = 87,
13391 JSMSG_PAREN_AFTER_FOR_CTRL = 88,
13392 JSMSG_CURLY_BEFORE_TRY = 89,
13393 JSMSG_CURLY_AFTER_TRY = 90,
13394 JSMSG_PAREN_BEFORE_CATCH = 91,
13395 JSMSG_CATCH_IDENTIFIER = 92,
13396 JSMSG_PAREN_AFTER_CATCH = 93,
13397 JSMSG_CURLY_BEFORE_CATCH = 94,
13398 JSMSG_CURLY_AFTER_CATCH = 95,
13399 JSMSG_CURLY_BEFORE_FINALLY = 96,
13400 JSMSG_CURLY_AFTER_FINALLY = 97,
13401 JSMSG_CATCH_OR_FINALLY = 98,
13402 JSMSG_PAREN_BEFORE_WITH = 99,
13403 JSMSG_PAREN_AFTER_WITH = 100,
13404 JSMSG_CURLY_IN_COMPOUND = 101,
13405 JSMSG_NO_VARIABLE_NAME = 102,
13406 JSMSG_COLON_IN_COND = 103,
13407 JSMSG_PAREN_AFTER_ARGS = 104,
13408 JSMSG_BRACKET_AFTER_LIST = 105,
13409 JSMSG_COLON_AFTER_ID = 106,
13410 JSMSG_CURLY_AFTER_LIST = 107,
13411 JSMSG_PAREN_IN_PAREN = 108,
13412 JSMSG_SEMI_BEFORE_STMNT = 109,
13413 JSMSG_NO_RETURN_VALUE = 110,
13414 JSMSG_DUPLICATE_FORMAL = 111,
13415 JSMSG_EQUAL_AS_ASSIGN = 112,
13416 JSMSG_OPTIMIZED_CLOSURE_LEAK = 113,
13417 JSMSG_TOO_MANY_DEFAULTS = 114,
13418 JSMSG_TOO_MANY_CASES = 115,
13419 JSMSG_BAD_SWITCH = 116,
13420 JSMSG_BAD_FOR_LEFTSIDE = 117,
13421 JSMSG_CATCH_AFTER_GENERAL = 118,
13422 JSMSG_CATCH_WITHOUT_TRY = 119,
13423 JSMSG_FINALLY_WITHOUT_TRY = 120,
13424 JSMSG_LABEL_NOT_FOUND = 121,
13425 JSMSG_TOUGH_BREAK = 122,
13426 JSMSG_BAD_CONTINUE = 123,
13427 JSMSG_BAD_RETURN_OR_YIELD = 124,
13428 JSMSG_BAD_LABEL = 125,
13429 JSMSG_DUPLICATE_LABEL = 126,
13430 JSMSG_VAR_HIDES_ARG = 127,
13431 JSMSG_BAD_VAR_INIT = 128,
13432 JSMSG_BAD_LEFTSIDE_OF_ASS = 129,
13433 JSMSG_BAD_OPERAND = 130,
13434 JSMSG_BAD_PROP_ID = 131,
13435 JSMSG_RESERVED_ID = 132,
13436 JSMSG_SYNTAX_ERROR = 133,
13437 JSMSG_BAD_SHARP_VAR_DEF = 134,
13438 JSMSG_BAD_PROTOTYPE = 135,
13439 JSMSG_MISSING_EXPONENT = 136,
13440 JSMSG_OUT_OF_MEMORY = 137,
13441 JSMSG_UNTERMINATED_STRING = 138,
13442 JSMSG_TOO_MANY_PARENS = 139,
13443 JSMSG_UNTERMINATED_COMMENT = 140,
13444 JSMSG_UNTERMINATED_REGEXP = 141,
13445 JSMSG_BAD_CLONE_FUNOBJ_SCOPE = 142,
13446 JSMSG_SHARPVAR_TOO_BIG = 143,
13447 JSMSG_ILLEGAL_CHARACTER = 144,
13448 JSMSG_BAD_OCTAL = 145,
13449 JSMSG_BAD_INDIRECT_CALL = 146,
13450 JSMSG_UNCAUGHT_EXCEPTION = 147,
13451 JSMSG_INVALID_BACKREF = 148,
13452 JSMSG_BAD_BACKREF = 149,
13453 JSMSG_PRECISION_RANGE = 150,
13454 JSMSG_BAD_GETTER_OR_SETTER = 151,
13455 JSMSG_BAD_ARRAY_LENGTH = 152,
13456 JSMSG_CANT_DESCRIBE_PROPS = 153,
13457 JSMSG_BAD_APPLY_ARGS = 154,
13458 JSMSG_REDECLARED_VAR = 155,
13459 JSMSG_UNDECLARED_VAR = 156,
13460 JSMSG_ANON_NO_RETURN_VALUE = 157,
13461 JSMSG_DEPRECATED_USAGE = 158,
13462 JSMSG_BAD_URI = 159,
13463 JSMSG_GETTER_ONLY = 160,
13464 JSMSG_IDSTART_AFTER_NUMBER = 161,
13465 JSMSG_UNDEFINED_PROP = 162,
13466 JSMSG_USELESS_EXPR = 163,
13467 JSMSG_REDECLARED_PARAM = 164,
13468 JSMSG_NEWREGEXP_FLAGGED = 165,
13469 JSMSG_RESERVED_SLOT_RANGE = 166,
13470 JSMSG_CANT_DECODE_PRINCIPALS = 167,
13471 JSMSG_CANT_SEAL_OBJECT = 168,
13472 JSMSG_TOO_MANY_CATCH_VARS = 169,
13473 JSMSG_BAD_XML_MARKUP = 170,
13474 JSMSG_BAD_XML_CHARACTER = 171,
13475 JSMSG_BAD_DEFAULT_XML_NAMESPACE = 172,
13476 JSMSG_BAD_XML_NAME_SYNTAX = 173,
13477 JSMSG_BRACKET_AFTER_ATTR_EXPR = 174,
13478 JSMSG_NESTING_GENERATOR = 175,
13479 JSMSG_CURLY_IN_XML_EXPR = 176,
13480 JSMSG_BAD_XML_NAMESPACE = 177,
13481 JSMSG_BAD_XML_ATTR_NAME = 178,
13482 JSMSG_BAD_XML_NAME = 179,
13483 JSMSG_BAD_XML_CONVERSION = 180,
13484 JSMSG_BAD_XMLLIST_CONVERSION = 181,
13485 JSMSG_BAD_GENERATOR_SEND = 182,
13486 JSMSG_NO_ASSIGN_IN_XML_ATTR = 183,
13487 JSMSG_BAD_XML_ATTR_VALUE = 184,
13488 JSMSG_XML_TAG_NAME_MISMATCH = 185,
13489 JSMSG_BAD_XML_TAG_SYNTAX = 186,
13490 JSMSG_BAD_XML_LIST_SYNTAX = 187,
13491 JSMSG_INCOMPATIBLE_METHOD = 188,
13492 JSMSG_CANT_SET_XML_ATTRS = 189,
13493 JSMSG_END_OF_XML_SOURCE = 190,
13494 JSMSG_END_OF_XML_ENTITY = 191,
13495 JSMSG_BAD_XML_QNAME = 192,
13496 JSMSG_BAD_FOR_EACH_LOOP = 193,
13497 JSMSG_BAD_XMLLIST_PUT = 194,
13498 JSMSG_UNKNOWN_XML_ENTITY = 195,
13499 JSMSG_BAD_XML_NCR = 196,
13500 JSMSG_UNDEFINED_XML_NAME = 197,
13501 JSMSG_DUPLICATE_XML_ATTR = 198,
13502 JSMSG_TOO_MANY_LOCALS = 199,
13503 JSMSG_ARRAY_INIT_TOO_BIG = 200,
13504 JSMSG_REGEXP_TOO_COMPLEX = 201,
13505 JSMSG_BUFFER_TOO_SMALL = 202,
13506 JSMSG_BAD_SURROGATE_CHAR = 203,
13507 JSMSG_UTF8_CHAR_TOO_LARGE = 204,
13508 JSMSG_MALFORMED_UTF8_CHAR = 205,
13509 JSMSG_USER_DEFINED_ERROR = 206,
13510 JSMSG_WRONG_CONSTRUCTOR = 207,
13511 JSMSG_BAD_GENERATOR_RETURN = 208,
13512 JSMSG_BAD_ANON_GENERATOR_RETURN = 209,
13513 JSMSG_NAME_AFTER_FOR_PAREN = 210,
13514 JSMSG_IN_AFTER_FOR_NAME = 211,
13515 JSMSG_BAD_TRAP_RETURN_VALUE = 212,
13516 JSMSG_KEYWORD_NOT_NS = 213,
13517 JSMSG_BAD_GENERATOR_YIELD = 214,
13518 JSMSG_BAD_GENERATOR_SYNTAX = 215,
13519 JSMSG_ARRAY_COMP_LEFTSIDE = 216,
13520 JSMSG_NON_XML_FILTER = 217,
13521 JSMSG_EMPTY_ARRAY_REDUCE = 218,
13522 JSMSG_NON_LIST_XML_METHOD = 219,
13523 JSMSG_BAD_DELETE_OPERAND = 220,
13524 JSMSG_BAD_INCOP_OPERAND = 221,
13525 JSMSG_UNEXPECTED_TYPE = 222,
13526 JSMSG_LET_DECL_NOT_IN_BLOCK = 223,
13527 JSMSG_BAD_OBJECT_INIT = 224,
13528 JSMSG_CANT_SET_ARRAY_ATTRS = 225,
13529 JSMSG_EVAL_ARITY = 226,
13530 JSMSG_MISSING_FUN_ARG = 227,
13531 JSMSG_JSON_BAD_PARSE = 228,
13532 JSMSG_JSON_BAD_STRINGIFY = 229,
13533 JSMSG_XDR_CLOSURE_WRAPPER = 230,
13534 JSMSG_NOT_NONNULL_OBJECT = 231,
13535 JSMSG_DEPRECATED_OCTAL = 232,
13536 JSMSG_STRICT_CODE_WITH = 233,
13537 JSMSG_DUPLICATE_PROPERTY = 234,
13538 JSMSG_DEPRECATED_DELETE_OPERAND = 235,
13539 JSMSG_DEPRECATED_ASSIGN = 236,
13540 JSMSG_BAD_BINDING = 237,
13541 JSMSG_INVALID_DESCRIPTOR = 238,
13542 JSMSG_OBJECT_NOT_EXTENSIBLE = 239,
13543 JSMSG_CANT_REDEFINE_PROP = 240,
13544 JSMSG_CANT_APPEND_TO_ARRAY = 241,
13545 JSMSG_CANT_DEFINE_ARRAY_LENGTH = 242,
13546 JSMSG_CANT_DEFINE_ARRAY_INDEX = 243,
13547 JSMSG_TYPED_ARRAY_BAD_INDEX = 244,
13548 JSMSG_TYPED_ARRAY_NEGATIVE_ARG = 245,
13549 JSMSG_TYPED_ARRAY_BAD_ARGS = 246,
13550 JSMSG_CSP_BLOCKED_FUNCTION = 247,
13551 JSMSG_BAD_GET_SET_FIELD = 248,
13552 JSMSG_BAD_PROXY_FIX = 249,
13553 JSMSG_INVALID_EVAL_SCOPE_ARG = 250,
13554 JSMSG_ACCESSOR_WRONG_ARGS = 251,
13555 JSMSG_THROW_TYPE_ERROR = 252,
13556 JSMSG_BAD_TOISOSTRING_PROP = 253,
13557 JSMSG_BAD_PARSE_NODE = 254,
13558 JSMSG_NOT_EXPECTED_TYPE = 255,
13559 JSMSG_CALLER_IS_STRICT = 256,
13560 JSMSG_NEED_DEBUG_MODE = 257,
13561 JSMSG_STRICT_CODE_LET_EXPR_STMT = 258,
13562 JSMSG_CANT_CHANGE_EXTENSIBILITY = 259,
13563 JSMSG_SC_BAD_SERIALIZED_DATA = 260,
13564 JSMSG_SC_UNSUPPORTED_TYPE = 261,
13565 JSMSG_SC_RECURSION = 262,
13566 JSMSG_CANT_WRAP_XML_OBJECT = 263,
13567 JSMSG_BAD_CLONE_VERSION = 264,
13568 JSMSG_CANT_CLONE_OBJECT = 265,
13569 JSMSG_NON_NATIVE_SCOPE = 266,
13570 JSMSG_STRICT_FUNCTION_STATEMENT = 267,
13571 JSMSG_INVALID_FOR_IN_INIT = 268,
13572 JSMSG_CLEARED_SCOPE = 269,
13575 extern __attribute__((visibility ("default"))) const JSErrorFormatString *
13576 js_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber);
13578 js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap);
13580 js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
13581 void *userRef, const uintN errorNumber,
13582 JSBool charArgs, va_list ap);
13584 js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
13585 void *userRef, const uintN errorNumber,
13586 char **message, JSErrorReport *reportp,
13587 bool charArgs, va_list ap);
13589 js_ReportOutOfMemory(JSContext *cx);
13591 js_ReportOutOfScriptQuota(JSContext *cx);
13592 extern __attribute__((visibility ("default"))) void
13593 js_ReportOverRecursed(JSContext *cx);
13594 extern __attribute__((visibility ("default"))) void
13595 js_ReportAllocationOverflow(JSContext *cx);
13596 extern __attribute__((visibility ("default"))) void
13597 js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
13599 js_ReportIsNotDefined(JSContext *cx, const char *name);
13601 js_ReportIsNullOrUndefined(JSContext *cx, intN spindex, const js::Value &v,
13602 JSString *fallback);
13604 js_ReportMissingArg(JSContext *cx, const js::Value &v, uintN arg);
13606 js_ReportValueErrorFlags(JSContext *cx, uintN flags, const uintN errorNumber,
13607 intN spindex, const js::Value &v, JSString *fallback,
13608 const char *arg1, const char *arg2);
13609 extern JSErrorFormatString js_ErrorFormatString[JSErr_Limit];
13610 __attribute__((always_inline)) inline void
13611 JSThreadData::triggerOperationCallback(JSRuntime *rt)
13613 if (interruptFlags)
13615 PR_AtomicSet((PRInt32 *)(&interruptFlags), (PRInt32)(1));
13616 if (requestDepth != 0)
13617 PR_AtomicIncrement((PRInt32 *)(&rt->interruptCounter));
13620 js_InvokeOperationCallback(JSContext *cx);
13622 js_HandleExecutionInterrupt(JSContext *cx);
13624 __attribute__((visibility ("default"))) void
13625 TriggerOperationCallback(JSContext *cx);
13627 TriggerAllOperationCallbacks(JSRuntime *rt);
13629 extern JSStackFrame *
13630 js_GetScriptedCaller(JSContext *cx, JSStackFrame *fp);
13632 js_GetCurrentBytecodePC(JSContext* cx);
13635 js_CurrentPCIsInImacro(JSContext *cx);
13637 class RegExpStatics;
13638 extern __attribute__((visibility ("default"))) void
13639 LeaveTrace(JSContext *cx);
13641 static inline JSStackFrame *
13642 js_GetTopStackFrame(JSContext *cx)
13644 js::LeaveTrace(cx);
13645 return cx->maybefp();
13647 static inline JSBool
13648 js_IsPropertyCacheDisabled(JSContext *cx)
13650 return cx->runtime->shapeGen >= js::SHAPE_OVERFLOW_BIT;
13652 static inline uint32
13653 js_RegenerateShapeForGC(JSRuntime *rt)
13657 uint32 shape = rt->shapeGen;
13658 shape = (shape + 1) | (shape & js::SHAPE_OVERFLOW_BIT);
13659 rt->shapeGen = shape;
13664 ContextAllocPolicy::malloc(size_t bytes)
13666 return cx->malloc(bytes);
13669 ContextAllocPolicy::free(void *p)
13674 ContextAllocPolicy::realloc(void *p, size_t bytes)
13676 return cx->realloc(p, bytes);
13679 ContextAllocPolicy::reportAllocOverflow() const
13681 js_ReportAllocationOverflow(cx);
13684 class AutoVectorRooter : protected AutoGCRooter
13687 explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag
13689 : AutoGCRooter(cx, tag), vector(cx)
13693 size_t length() const { return vector.length(); }
13694 bool append(const T &v) { return vector.append(v); }
13695 void popBack() { vector.popBack(); }
13696 bool growBy(size_t inc) {
13697 size_t oldLength = vector.length();
13698 if (!vector.growByUninitialized(inc))
13700 MakeRangeGCSafe(vector.begin() + oldLength, vector.end());
13703 bool resize(size_t newLength) {
13704 size_t oldLength = vector.length();
13705 if (newLength <= oldLength) {
13706 vector.shrinkBy(oldLength - newLength);
13709 if (!vector.growByUninitialized(newLength - oldLength))
13711 MakeRangeGCSafe(vector.begin() + oldLength, vector.end());
13714 bool reserve(size_t newLength) {
13715 return vector.reserve(newLength);
13717 T &operator[](size_t i) { return vector[i]; }
13718 const T &operator[](size_t i) const { return vector[i]; }
13719 const T *begin() const { return vector.begin(); }
13720 T *begin() { return vector.begin(); }
13721 const T *end() const { return vector.end(); }
13722 T *end() { return vector.end(); }
13723 const T &back() const { return vector.back(); }
13724 friend void AutoGCRooter::trace(JSTracer *trc);
13726 Vector<T, 8> vector;
13729 class AutoValueVector : public AutoVectorRooter<Value>
13732 explicit AutoValueVector(JSContext *cx
13734 : AutoVectorRooter<Value>(cx, VALVECTOR)
13738 const jsval *jsval_begin() const { return Jsvalify(begin()); }
13739 jsval *jsval_begin() { return Jsvalify(begin()); }
13740 const jsval *jsval_end() const { return Jsvalify(end()); }
13741 jsval *jsval_end() { return Jsvalify(end()); }
13744 class AutoIdVector : public AutoVectorRooter<jsid>
13747 explicit AutoIdVector(JSContext *cx
13749 : AutoVectorRooter<jsid>(cx, IDVECTOR)
13755 class AutoShapeVector : public AutoVectorRooter<const Shape *>
13758 explicit AutoShapeVector(JSContext *cx
13760 : AutoVectorRooter<const Shape *>(cx, SHAPEVECTOR)
13767 NewIdArray(JSContext *cx, jsint length);
13769 typedef union jsdpun {
13777 JSDOUBLE_IS_NaN(jsdouble d)
13779 return (sizeof (d) == sizeof (float) ? __isnanf (d) : sizeof (d) == sizeof (double) ? __isnan (d) : __isnanl (d));
13782 JSDOUBLE_IS_FINITE(jsdouble d)
13787 JSDOUBLE_IS_INFINITE(jsdouble d)
13789 return (sizeof (d) == sizeof (float) ? __isinff (d) : sizeof (d) == sizeof (double) ? __isinf (d) : __isinfl (d));
13793 JSDOUBLE_IS_NEG(jsdouble d)
13795 return (sizeof (d) == sizeof (float) ? __signbitf (d) : sizeof (d) == sizeof (double) ? __signbit (d) : __signbitl (d));
13797 static inline uint32
13798 JS_HASH_DOUBLE(jsdouble d)
13802 return u.s.lo ^ u.s.hi;
13804 extern jsdouble js_NaN;
13805 extern jsdouble js_PositiveInfinity;
13806 extern jsdouble js_NegativeInfinity;
13808 js_InitRuntimeNumberState(JSContext *cx);
13810 js_FinishRuntimeNumberState(JSContext *cx);
13811 extern js::Class js_NumberClass;
13814 JSObject::isNumber() const
13816 return getClass() == &js_NumberClass;
13819 js_InitNumberClass(JSContext *cx, JSObject *obj);
13820 extern const char js_Infinity_str[];
13821 extern const char js_NaN_str[];
13822 extern const char js_isNaN_str[];
13823 extern const char js_isFinite_str[];
13824 extern const char js_parseFloat_str[];
13825 extern const char js_parseInt_str[];
13827 js_IntToString(JSContext *cx, jsint i);
13829 js_NumberToString(JSContext *cx, jsdouble d);
13832 NumberValueToStringBuffer(JSContext *cx, const Value &v, StringBuffer &sb);
13833 extern JSFlatString *
13834 NumberToString(JSContext *cx, jsdouble d);
13835 struct ToCStringBuf
13837 static const size_t sbufSize = 34;
13838 char sbuf[sbufSize];
13844 NumberToCString(JSContext *cx, ToCStringBuf *cbuf, jsdouble d, jsint base = 10);
13845 const double DOUBLE_INTEGRAL_PRECISION_LIMIT = uint64(1) << 53;
13848 GetPrefixInteger(JSContext *cx, const jschar *start, const jschar *end, int base,
13849 const jschar **endp, jsdouble *dp);
13850 __attribute__((always_inline)) inline
13852 ValueToNumber(JSContext *cx, const js::Value &v, double *out)
13854 if (v.isNumber()) {
13855 *out = v.toNumber();
13858 extern bool ValueToNumberSlow(JSContext *, js::Value, double *);
13859 return ValueToNumberSlow(cx, v, out);
13861 __attribute__((always_inline)) inline
13863 ValueToNumber(JSContext *cx, js::Value *vp)
13865 if (vp->isNumber())
13868 extern bool ValueToNumberSlow(JSContext *, js::Value, double *);
13869 if (!ValueToNumberSlow(cx, *vp, &d))
13874 __attribute__((always_inline)) inline
13876 ValueToECMAInt32(JSContext *cx, const js::Value &v, int32_t *out)
13879 *out = v.toInt32();
13882 extern bool ValueToECMAInt32Slow(JSContext *, const js::Value &, int32_t *);
13883 return ValueToECMAInt32Slow(cx, v, out);
13885 __attribute__((always_inline)) inline
13887 ValueToECMAUint32(JSContext *cx, const js::Value &v, uint32_t *out)
13890 *out = (uint32_t)v.toInt32();
13893 extern bool ValueToECMAUint32Slow(JSContext *, const js::Value &, uint32_t *);
13894 return ValueToECMAUint32Slow(cx, v, out);
13896 __attribute__((always_inline)) inline
13898 ValueToInt32(JSContext *cx, const js::Value &v, int32_t *out)
13901 *out = v.toInt32();
13904 extern bool ValueToInt32Slow(JSContext *, const js::Value &, int32_t *);
13905 return ValueToInt32Slow(cx, v, out);
13907 __attribute__((always_inline)) inline
13909 ValueToUint16(JSContext *cx, const js::Value &v, uint16_t *out)
13912 *out = (uint16_t)v.toInt32();
13915 extern bool ValueToUint16Slow(JSContext *, const js::Value &, uint16_t *);
13916 return ValueToUint16Slow(cx, v, out);
13919 static inline int32
13920 js_DoubleToECMAInt32(jsdouble d)
13923 jsdouble two32, two31;
13924 if (!JSDOUBLE_IS_FINITE(d))
13927 if ((jsdouble) i == d)
13929 two32 = 4294967296.0;
13930 two31 = 2147483648.0;
13931 d = fmod(d, two32);
13932 d = (d >= 0) ? floor(d) : ceil(d) + two32;
13933 return (int32) (d >= two31 ? d - two32 : d);
13936 js_DoubleToECMAUint32(jsdouble d);
13937 static inline jsdouble
13938 js_DoubleToInteger(jsdouble d)
13942 if (!JSDOUBLE_IS_FINITE(d)) {
13943 if (JSDOUBLE_IS_NaN(d))
13947 JSBool neg = (d < 0);
13948 d = floor(neg ? -d : d);
13949 return neg ? -d : d;
13952 js_strtod(JSContext *cx, const jschar *s, const jschar *send,
13953 const jschar **ep, jsdouble *dp);
13955 js_num_valueOf(JSContext *cx, uintN argc, js::Value *vp);
13957 static __attribute__((always_inline)) inline
13959 ValueFitsInInt32(const Value &v, int32_t *pi)
13965 return v.isDouble() && JSDOUBLE_IS_INT32(v.toDouble(), pi);
13967 template<typename T> struct NumberTraits { };
13968 template<> struct NumberTraits<int32> {
13969 static __attribute__((always_inline)) inline int32 NaN() { return 0; }
13970 static __attribute__((always_inline)) inline int32 toSelfType(int32 i) { return i; }
13971 static __attribute__((always_inline)) inline int32 toSelfType(jsdouble d) { return js_DoubleToECMAUint32(d); }
13973 template<> struct NumberTraits<jsdouble> {
13974 static __attribute__((always_inline)) inline jsdouble NaN() { return js_NaN; }
13975 static __attribute__((always_inline)) inline jsdouble toSelfType(int32 i) { return i; }
13976 static __attribute__((always_inline)) inline jsdouble toSelfType(jsdouble d) { return d; }
13978 template<typename T>
13979 static __attribute__((always_inline)) inline
13981 StringToNumberType(JSContext *cx, JSString *str, T *result)
13983 size_t length = str->length();
13984 const jschar *chars = str->getChars(__null);
13988 jschar c = chars[0];
13989 if ('0' <= c && c <= '9') {
13990 *result = NumberTraits<T>::toSelfType(T(c - '0'));
13993 if (JS_ISSPACE(c)) {
13994 *result = NumberTraits<T>::toSelfType(T(0));
13997 *result = NumberTraits<T>::NaN();
14000 const jschar *bp = chars;
14001 const jschar *end = chars + length;
14002 bp = js_SkipWhiteSpace(bp, end);
14003 if (end - bp >= 2 && bp[0] == '0' && (bp[1] == 'x' || bp[1] == 'X')) {
14004 const jschar *endptr;
14006 if (!GetPrefixInteger(cx, bp + 2, end, 16, &endptr, &d) ||
14007 js_SkipWhiteSpace(endptr, end) != end) {
14008 *result = NumberTraits<T>::NaN();
14011 *result = NumberTraits<T>::toSelfType(d);
14016 if (!js_strtod(cx, bp, end, &ep, &d) || js_SkipWhiteSpace(ep, end) != end) {
14017 *result = NumberTraits<T>::NaN();
14020 *result = NumberTraits<T>::toSelfType(d);
14024 extern const char js_false_str[];
14025 extern const char js_true_str[];
14026 extern const char js_null_str[];
14027 extern const char js_break_str[];
14028 extern const char js_case_str[];
14029 extern const char js_catch_str[];
14030 extern const char js_continue_str[];
14031 extern const char js_debugger_str[];
14032 extern const char js_default_str[];
14033 extern const char js_delete_str[];
14034 extern const char js_do_str[];
14035 extern const char js_else_str[];
14036 extern const char js_finally_str[];
14037 extern const char js_for_str[];
14038 extern const char js_function_str[];
14039 extern const char js_if_str[];
14040 extern const char js_in_str[];
14041 extern const char js_instanceof_str[];
14042 extern const char js_new_str[];
14043 extern const char js_return_str[];
14044 extern const char js_switch_str[];
14045 extern const char js_this_str[];
14046 extern const char js_throw_str[];
14047 extern const char js_try_str[];
14048 extern const char js_typeof_str[];
14049 extern const char js_var_str[];
14050 extern const char js_void_str[];
14051 extern const char js_while_str[];
14052 extern const char js_with_str[];
14053 extern const char js_class_str[];
14054 extern const char js_enum_str[];
14055 extern const char js_export_str[];
14056 extern const char js_extends_str[];
14057 extern const char js_import_str[];
14058 extern const char js_super_str[];
14059 extern const char js_const_str[];
14060 extern const char js_let_str[];
14061 extern const char js_yield_str[];
14062 extern const char js_implements_str[];
14063 extern const char js_interface_str[];
14064 extern const char js_package_str[];
14065 extern const char js_private_str[];
14066 extern const char js_protected_str[];
14067 extern const char js_public_str[];
14068 extern const char js_static_str[];
14077 TOK_HOOK = 5, TOK_COLON = 6,
14088 TOK_STAR = 17, TOK_DIVOP = 18,
14090 TOK_INC = 20, TOK_DEC = 21,
14092 TOK_LB = 23, TOK_RB = 24,
14093 TOK_LC = 25, TOK_RC = 26,
14094 TOK_LP = 27, TOK_RP = 28,
14123 TOK_INSTANCEOF = 57,
14133 TOK_XMLCOMMENT = 67,
14144 TOK_ARRAYCOMP = 78,
14145 TOK_ARRAYPUSH = 79,
14146 TOK_LEXICALSCOPE = 80,
14153 TOK_STRICT_RESERVED,
14158 TokenKindIsXML(TokenKind tt)
14160 return tt == TOK_AT || tt == TOK_DBLCOLON || tt == TOK_ANYNAME;
14164 TreeTypeIsXML(TokenKind tt)
14166 return tt == TOK_XMLCOMMENT || tt == TOK_XMLCDATA || tt == TOK_XMLPI ||
14167 tt == TOK_XMLELEM || tt == TOK_XMLLIST;
14171 TokenKindIsDecl(TokenKind tt)
14173 return tt == TOK_VAR || tt == TOK_LET;
14178 bool operator==(const TokenPtr& bptr) {
14179 return index == bptr.index && lineno == bptr.lineno;
14181 bool operator!=(const TokenPtr& bptr) {
14182 return index != bptr.index || lineno != bptr.lineno;
14184 bool operator <(const TokenPtr& bptr) {
14185 return lineno < bptr.lineno ||
14186 (lineno == bptr.lineno && index < bptr.index);
14188 bool operator <=(const TokenPtr& bptr) {
14189 return lineno < bptr.lineno ||
14190 (lineno == bptr.lineno && index <= bptr.index);
14192 bool operator >(const TokenPtr& bptr) {
14193 return !(*this <= bptr);
14195 bool operator >=(const TokenPtr& bptr) {
14196 return !(*this < bptr);
14202 bool operator==(const TokenPos& bpos) {
14203 return begin == bpos.begin && end == bpos.end;
14205 bool operator!=(const TokenPos& bpos) {
14206 return begin != bpos.begin || end != bpos.end;
14208 bool operator <(const TokenPos& bpos) {
14209 return begin < bpos.begin;
14211 bool operator <=(const TokenPos& bpos) {
14212 return begin <= bpos.begin;
14214 bool operator >(const TokenPos& bpos) {
14215 return !(*this <= bpos);
14217 bool operator >=(const TokenPos& bpos) {
14218 return !(*this < bpos);
14238 enum TokenStreamFlags
14242 TSF_NEWLINES = 0x04,
14243 TSF_OPERAND = 0x08,
14244 TSF_UNEXPECTED_EOF = 0x10,
14245 TSF_KEYWORD_IS_NAME = 0x20,
14246 TSF_STRICT_MODE_CODE = 0x40,
14247 TSF_DIRTYLINE = 0x80,
14248 TSF_OWNFILENAME = 0x100,
14249 TSF_XMLTAGMODE = 0x200,
14250 TSF_XMLTEXTMODE = 0x400,
14251 TSF_XMLONLYMODE = 0x800,
14252 TSF_OCTAL_CHAR = 0x1000,
14253 TSF_IN_HTML_COMMENT = 0x2000
14257 static const size_t ntokens = 4;
14258 static const uintN ntokensMask = ntokens - 1;
14260 typedef Vector<jschar, 32> CharBuffer;
14261 TokenStream(JSContext *);
14262 bool init(const jschar *base, size_t length, const char *filename, uintN lineno,
14263 JSVersion version);
14266 JSContext *getContext() const { return cx; }
14267 bool onCurrentLine(const TokenPos &pos) const { return lineno == pos.end.lineno; }
14268 const Token ¤tToken() const { return tokens[cursor]; }
14269 const CharBuffer &getTokenbuf() const { return tokenbuf; }
14270 const char *getFilename() const { return filename; }
14271 uintN getLineno() const { return lineno; }
14272 JSVersion versionNumber() const { return VersionNumber(version); }
14273 JSVersion versionWithFlags() const { return version; }
14274 bool hasAnonFunFix() const { return VersionHasAnonFunFix(version); }
14275 bool hasXML() const { return xml || VersionShouldParseXML(versionNumber()); }
14276 void setXML(bool enabled) { xml = enabled; }
14277 void setStrictMode(bool enabled = true) { setFlag(enabled, TSF_STRICT_MODE_CODE); }
14278 void setXMLTagMode(bool enabled = true) { setFlag(enabled, TSF_XMLTAGMODE); }
14279 void setXMLOnlyMode(bool enabled = true) { setFlag(enabled, TSF_XMLONLYMODE); }
14280 void setUnexpectedEOF(bool enabled = true) { setFlag(enabled, TSF_UNEXPECTED_EOF); }
14281 void setOctalCharacterEscape(bool enabled = true) { setFlag(enabled, TSF_OCTAL_CHAR); }
14282 bool isStrictMode() { return !!(flags & TSF_STRICT_MODE_CODE); }
14283 bool isXMLTagMode() { return !!(flags & TSF_XMLTAGMODE); }
14284 bool isXMLOnlyMode() { return !!(flags & TSF_XMLONLYMODE); }
14285 bool isUnexpectedEOF() { return !!(flags & TSF_UNEXPECTED_EOF); }
14286 bool isEOF() const { return !!(flags & TSF_EOF); }
14287 bool isError() const { return !!(flags & TSF_ERROR); }
14288 bool hasOctalCharacterEscape() const { return flags & TSF_OCTAL_CHAR; }
14289 bool reportCompileErrorNumberVA(JSParseNode *pn, uintN flags, uintN errorNumber, va_list ap);
14290 void mungeCurrentToken(TokenKind newKind) { tokens[cursor].type = newKind; }
14291 void mungeCurrentToken(JSOp newOp) { tokens[cursor].u.s.op = newOp; }
14292 void mungeCurrentToken(TokenKind newKind, JSOp newOp) {
14293 mungeCurrentToken(newKind);
14294 mungeCurrentToken(newOp);
14297 static JSAtom *atomize(JSContext *cx, CharBuffer &cb);
14299 TokenStream * const parent;
14302 Flagger(TokenStream *parent, uintN withFlags) : parent(parent), flags(withFlags) {
14303 parent->flags |= flags;
14305 ~Flagger() { parent->flags &= ~flags; }
14307 friend class Flagger;
14308 void setFlag(bool enabled, TokenStreamFlags flag) {
14315 TokenKind getToken() {
14316 while (lookahead != 0) {
14319 cursor = (cursor + 1) & ntokensMask;
14320 TokenKind tt = currentToken().type;
14325 if (flags & TSF_ERROR)
14327 return getTokenInternal();
14329 TokenKind getToken(uintN withFlags) {
14330 Flagger flagger(this, withFlags);
14333 void ungetToken() {
14336 cursor = (cursor - 1) & ntokensMask;
14338 TokenKind peekToken(uintN withFlags = 0) {
14339 Flagger flagger(this, withFlags);
14340 if (lookahead != 0) {
14342 return tokens[(cursor + lookahead) & ntokensMask].type;
14344 TokenKind tt = getToken();
14348 TokenKind peekTokenSameLine(uintN withFlags = 0) {
14349 Flagger flagger(this, withFlags);
14350 if (!onCurrentLine(currentToken().pos))
14352 TokenKind tt = peekToken(TSF_NEWLINES);
14355 JSBool matchToken(TokenKind tt, uintN withFlags = 0) {
14356 Flagger flagger(this, withFlags);
14357 if (getToken() == tt)
14363 typedef struct TokenBuf {
14368 TokenKind getTokenInternal();
14370 int32 getCharIgnoreEOL();
14371 void ungetChar(int32 c);
14372 void ungetCharIgnoreEOL(int32 c);
14373 Token *newToken(ptrdiff_t adjust);
14374 bool peekUnicodeEscape(int32 *c);
14375 bool matchUnicodeEscapeIdStart(int32 *c);
14376 bool matchUnicodeEscapeIdent(int32 *c);
14377 JSBool peekChars(intN n, jschar *cp);
14378 JSBool getXMLEntity();
14380 JSBool matchChar(int32 expect) {
14381 int32 c = getChar();
14388 int32 c = getChar();
14392 void skipChars(intN n) {
14396 JSContext * const cx;
14397 Token tokens[ntokens];
14403 jschar *prevLinebase;
14405 const char *filename;
14406 JSSourceHandler listener;
14407 void *listenerData;
14408 void *listenerTSData;
14409 CharBuffer tokenbuf;
14410 bool maybeEOL[256];
14411 bool maybeStrSpecial[256];
14417 js_CloseTokenStream(JSContext *cx, js::TokenStream *ts);
14418 extern __attribute__((visibility ("default"))) int
14419 js_fgets(char *buf, int size, FILE *file);
14421 struct KeywordInfo {
14423 TokenKind tokentype;
14427 extern const KeywordInfo *
14428 FindKeyword(const jschar *s, size_t length);
14430 typedef void (*JSMapKeywordFun)(const char *);
14432 js_IsIdentifier(JSLinearString *str);
14435 ReportCompileErrorNumber(JSContext *cx, TokenStream *ts, JSParseNode *pn, uintN flags,
14436 uintN errorNumber, ...);
14438 ReportStrictModeError(JSContext *cx, TokenStream *ts, JSTreeContext *tc, JSParseNode *pn,
14439 uintN errorNumber, ...);
14442 typedef enum JSParseNodeArity {
14451 } JSParseNodeArity;
14452 struct JSDefinition;
14454 struct GlobalScope {
14455 GlobalScope(JSContext *cx, JSObject *globalObj, JSCodeGenerator *cg)
14456 : globalObj(globalObj), cg(cg), defs(ContextAllocPolicy(cx))
14460 JSFunctionBox *funbox;
14463 GlobalDef(uint32 knownSlot)
14464 : atom(__null), knownSlot(knownSlot)
14466 GlobalDef(JSAtom *atom, JSFunctionBox *box) :
14467 atom(atom), funbox(box)
14470 JSObject *globalObj;
14471 JSCodeGenerator *cg;
14472 Vector<GlobalDef, 16, ContextAllocPolicy> defs;
14476 struct JSParseNode {
14483 js::TokenPos pn_pos;
14485 JSParseNode *pn_next;
14486 JSParseNode *pn_link;
14490 JSParseNode **tail;
14502 JSParseNode *right;
14514 JSFunctionBox *funbox;
14515 JSObjectBox *objbox;
14519 JSDefinition *lexdef;
14521 js::UpvarCookie cookie;
14536 void inline init(js::TokenKind type, JSOp op, JSParseNodeArity arity) {
14543 pn_next = pn_link = __null;
14545 static JSParseNode *create(JSParseNodeArity arity, JSTreeContext *tc);
14547 static JSParseNode *newBinaryOrAppend(js::TokenKind tt, JSOp op, JSParseNode *left,
14548 JSParseNode *right, JSTreeContext *tc);
14549 JSParseNode *expr() const {
14552 return pn_u.name.expr;
14554 JSDefinition *lexdef() const {
14557 return pn_u.name.lexdef;
14559 JSParseNode *maybeExpr() { return pn_used ? __null : expr(); }
14560 JSDefinition *maybeLexDef() { return pn_used ? lexdef() : __null; }
14561 uintN frameLevel() const {
14563 return pn_u.name.cookie.level();
14565 uintN frameSlot() const {
14567 return pn_u.name.cookie.slot();
14569 inline bool test(uintN flag) const;
14570 bool isLet() const { return test(0x01); }
14571 bool isConst() const { return test(0x02); }
14572 bool isInitialized() const { return test(0x04); }
14573 bool isBlockChild() const { return test(0x20); }
14574 bool isPlaceholder() const { return test(0x80); }
14575 bool isDeoptimized() const { return test(0x400); }
14576 bool isAssigned() const { return test(0x08); }
14577 bool isFunArg() const { return test(0x100); }
14578 bool isClosed() const { return test(0x800); }
14579 bool isTopLevel() const { return test(0x10); }
14581 void become(JSParseNode *pn2);
14583 bool isLiteral() const {
14584 return ((js::TokenKind)(this)->pn_type) == js::TOK_NUMBER ||
14585 ((js::TokenKind)(this)->pn_type) == js::TOK_STRING ||
14586 (((js::TokenKind)(this)->pn_type) == js::TOK_PRIMARY && ((JSOp)(this)->pn_op) != JSOP_THIS);
14588 bool isStringExprStatement() const {
14589 if (((js::TokenKind)(this)->pn_type) == js::TOK_SEMI) {
14591 JSParseNode *kid = pn_u.unary.kid;
14592 return kid && ((js::TokenKind)(kid)->pn_type) == js::TOK_STRING && !kid->pn_parens;
14596 bool isEscapeFreeStringLiteral() const {
14598 JSString *str = (pn_u.name.atom);
14599 return (pn_pos.begin.lineno == pn_pos.end.lineno &&
14600 pn_pos.begin.index + str->length() + 2 == pn_pos.end.index);
14602 bool isDirectivePrologueMember() const { return pn_u.unary.hidden; }
14603 bool isGeneratorExpr() const {
14604 if (((js::TokenKind)(this)->pn_type) == js::TOK_LP) {
14605 JSParseNode *callee = this->pn_u.list.head;
14606 if (((js::TokenKind)(callee)->pn_type) == js::TOK_FUNCTION) {
14607 JSParseNode *body = (((js::TokenKind)(callee->pn_u.name.expr)->pn_type) == js::TOK_UPVARS)
14608 ? callee->pn_u.name.expr->pn_u.nameset.tree
14609 : callee->pn_u.name.expr;
14610 if (((js::TokenKind)(body)->pn_type) == js::TOK_LEXICALSCOPE)
14616 JSParseNode *generatorExpr() const {
14618 JSParseNode *callee = this->pn_u.list.head;
14619 JSParseNode *body = ((js::TokenKind)(callee->pn_u.name.expr)->pn_type) == js::TOK_UPVARS
14620 ? callee->pn_u.name.expr->pn_u.nameset.tree
14621 : callee->pn_u.name.expr;
14623 return body->pn_u.name.expr;
14625 JSParseNode *last() const {
14628 return (JSParseNode *)((char *)pn_u.list.tail - __builtin_offsetof (JSParseNode, pn_next));
14632 pn_u.list.head = __null;
14633 pn_u.list.tail = &pn_u.list.head;
14634 pn_u.list.count = 0;
14635 pn_u.list.xflags = 0;
14636 pn_u.name.blockid = 0;
14638 void initList(JSParseNode *pn) {
14640 pn_u.list.head = pn;
14641 pn_u.list.tail = &pn->pn_next;
14642 pn_u.list.count = 1;
14643 pn_u.list.xflags = 0;
14644 pn_u.name.blockid = 0;
14646 void append(JSParseNode *pn) {
14648 *pn_u.list.tail = pn;
14649 pn_u.list.tail = &pn->pn_next;
14652 bool getConstantValue(JSContext *cx, bool strictChecks, js::Value *vp);
14653 inline bool isConstant();
14656 struct NullaryNode : public JSParseNode {
14657 static inline NullaryNode *create(JSTreeContext *tc) {
14658 return (NullaryNode *)JSParseNode::create(PN_NULLARY, tc);
14661 struct UnaryNode : public JSParseNode {
14662 static inline UnaryNode *create(JSTreeContext *tc) {
14663 return (UnaryNode *)JSParseNode::create(PN_UNARY, tc);
14666 struct BinaryNode : public JSParseNode {
14667 static inline BinaryNode *create(JSTreeContext *tc) {
14668 return (BinaryNode *)JSParseNode::create(PN_BINARY, tc);
14671 struct TernaryNode : public JSParseNode {
14672 static inline TernaryNode *create(JSTreeContext *tc) {
14673 return (TernaryNode *)JSParseNode::create(PN_TERNARY, tc);
14676 struct ListNode : public JSParseNode {
14677 static inline ListNode *create(JSTreeContext *tc) {
14678 return (ListNode *)JSParseNode::create(PN_LIST, tc);
14681 struct FunctionNode : public JSParseNode {
14682 static inline FunctionNode *create(JSTreeContext *tc) {
14683 return (FunctionNode *)JSParseNode::create(PN_FUNC, tc);
14686 struct NameNode : public JSParseNode {
14687 static NameNode *create(JSAtom *atom, JSTreeContext *tc);
14688 void inline initCommon(JSTreeContext *tc);
14690 struct NameSetNode : public JSParseNode {
14691 static inline NameSetNode *create(JSTreeContext *tc) {
14692 return (NameSetNode *)JSParseNode::create(PN_NAMESET, tc);
14695 struct LexicalScopeNode : public JSParseNode {
14696 static inline LexicalScopeNode *create(JSTreeContext *tc) {
14697 return (LexicalScopeNode *)JSParseNode::create(PN_NAME, tc);
14701 struct JSDefinition : public JSParseNode
14703 JSDefinition *resolve() {
14704 JSParseNode *pn = this;
14705 while (!pn->pn_defn) {
14706 if (pn->pn_type == js::TOK_ASSIGN) {
14707 pn = pn->pn_u.binary.left;
14712 return (JSDefinition *) pn;
14714 bool isFreeVar() const {
14716 return pn_u.name.cookie.isFree() || test(0x40);
14718 bool isGlobal() const {
14722 enum Kind { VAR, CONST, LET, FUNCTION, ARG, UNKNOWN };
14723 bool isBindingForm() { return int(kind()) <= int(LET); }
14724 static const char *kindString(Kind kind);
14726 if (((js::TokenKind)(this)->pn_type) == js::TOK_FUNCTION)
14729 if (((JSOp)(this)->pn_op) == JSOP_NOP)
14731 if (((JSOp)(this)->pn_op) == JSOP_GETARG)
14742 JSParseNode::test(uintN flag) const
14745 return !!(pn_u.name.dflags & flag);
14748 JSParseNode::setFunArg()
14752 pn_u.name.lexdef->pn_u.name.dflags |= 0x100;
14753 pn_u.name.dflags |= 0x100;
14755 struct JSObjectBox {
14756 JSObjectBox *traceLink;
14757 JSObjectBox *emitLink;
14759 JSObjectBox *parent;
14761 bool isFunctionBox;
14763 struct JSFunctionBox : public JSObjectBox
14766 JSFunctionBox *siblings;
14767 JSFunctionBox *kids;
14768 JSFunctionBox *parent;
14769 JSParseNode *methods;
14770 js::Bindings bindings;
14775 bool joinable() const;
14776 bool inAnyDynamicScope() const;
14777 bool shouldUnbrand(uintN methods, uintN slowMethods) const;
14779 struct JSFunctionBoxQueue {
14780 JSFunctionBox **vector;
14783 size_t count() { return head - tail; }
14784 size_t length() { return lengthMask + 1; }
14785 JSFunctionBoxQueue()
14786 : vector(__null), head(0), tail(0), lengthMask(0) { }
14787 bool init(uint32 count) {
14788 lengthMask = (((JSUint32)1 << (JS_CeilingLog2(count))) - 1);
14789 vector = js_array_new<JSFunctionBox*>(length());
14792 ~JSFunctionBoxQueue() { js_array_delete(vector); }
14793 void push(JSFunctionBox *funbox) {
14794 if (!funbox->queued) {
14796 vector[head++ & lengthMask] = funbox;
14797 funbox->queued = true;
14800 JSFunctionBox *pull() {
14804 JSFunctionBox *funbox = vector[tail++ & lengthMask];
14805 funbox->queued = false;
14809 typedef struct BindData BindData;
14811 struct Parser : private js::AutoGCRooter
14813 JSContext * const context;
14814 JSAtomListElement *aleFreeList;
14815 void *tempFreeList[6U];
14816 TokenStream tokenStream;
14817 void *tempPoolMark;
14818 JSPrincipals *principals;
14819 JSStackFrame *const callerFrame;
14820 JSObject *const callerVarObj;
14821 JSParseNode *nodeList;
14822 uint32 functionCount;
14823 JSObjectBox *traceListHead;
14825 js::AutoKeepAtoms keepAtoms;
14826 Parser(JSContext *cx, JSPrincipals *prin = __null, JSStackFrame *cfp = __null);
14828 friend void js::AutoGCRooter::trace(JSTracer *trc);
14829 friend struct ::JSTreeContext;
14830 friend struct Compiler;
14831 bool init(const jschar *base, size_t length, const char *filename, uintN lineno,
14832 JSVersion version);
14833 void setPrincipals(JSPrincipals *prin);
14834 const char *getFilename() const { return tokenStream.getFilename(); }
14835 JSVersion versionWithFlags() const { return tokenStream.versionWithFlags(); }
14836 JSVersion versionNumber() const { return tokenStream.versionNumber(); }
14837 bool hasXML() const { return tokenStream.hasXML(); }
14838 bool hasAnonFunFix() const { return tokenStream.hasAnonFunFix(); }
14839 JSParseNode *parse(JSObject *chain);
14840 JSParseNode *parseXMLText(JSObject *chain, bool allowList);
14841 JSObjectBox *newObjectBox(JSObject *obj);
14842 JSFunctionBox *newFunctionBox(JSObject *obj, JSParseNode *fn, JSTreeContext *tc);
14843 JSFunction *newFunction(JSTreeContext *tc, JSAtom *atom, uintN lambda);
14844 bool analyzeFunctions(JSTreeContext *tc);
14845 void cleanFunctionList(JSFunctionBox **funbox);
14846 bool markFunArgs(JSFunctionBox *funbox);
14847 void setFunctionKinds(JSFunctionBox *funbox, uint32 *tcflags);
14848 void trace(JSTracer *trc);
14849 inline bool reportErrorNumber(JSParseNode *pn, uintN flags, uintN errorNumber, ...);
14851 JSParseNode *functionStmt();
14852 JSParseNode *functionExpr();
14853 JSParseNode *statements();
14854 JSParseNode *statement();
14855 JSParseNode *switchStatement();
14856 JSParseNode *forStatement();
14857 JSParseNode *tryStatement();
14858 JSParseNode *withStatement();
14859 JSParseNode *letStatement();
14860 JSParseNode *expressionStatement();
14861 JSParseNode *variables(bool inLetHead);
14862 JSParseNode *expr();
14863 JSParseNode *assignExpr();
14864 JSParseNode *condExpr();
14865 JSParseNode *orExpr();
14866 JSParseNode *andExpr();
14867 JSParseNode *bitOrExpr();
14868 JSParseNode *bitXorExpr();
14869 JSParseNode *bitAndExpr();
14870 JSParseNode *eqExpr();
14871 JSParseNode *relExpr();
14872 JSParseNode *shiftExpr();
14873 JSParseNode *addExpr();
14874 JSParseNode *mulExpr();
14875 JSParseNode *unaryExpr();
14876 JSParseNode *memberExpr(JSBool allowCallSyntax);
14877 JSParseNode *primaryExpr(js::TokenKind tt, JSBool afterDot);
14878 JSParseNode *parenExpr(JSBool *genexp = __null);
14879 bool recognizeDirectivePrologue(JSParseNode *pn, bool *isDirectivePrologueMember);
14880 enum FunctionType { GETTER, SETTER, GENERAL };
14881 bool functionArguments(JSTreeContext &funtc, JSFunctionBox *funbox, JSParseNode **list);
14882 JSParseNode *functionBody();
14883 JSParseNode *functionDef(JSAtom *name, FunctionType type, uintN lambda);
14884 JSParseNode *condition();
14885 JSParseNode *comprehensionTail(JSParseNode *kid, uintN blockid,
14886 js::TokenKind type = js::TOK_SEMI, JSOp op = JSOP_NOP);
14887 JSParseNode *generatorExpr(JSParseNode *kid);
14888 JSBool argumentList(JSParseNode *listNode);
14889 JSParseNode *bracketedExpr();
14890 JSParseNode *letBlock(JSBool statement);
14891 JSParseNode *returnOrYield(bool useAssignExpr);
14892 JSParseNode *destructuringExpr(BindData *data, js::TokenKind tt);
14893 JSParseNode *endBracketedExpr();
14894 JSParseNode *propertySelector();
14895 JSParseNode *qualifiedSuffix(JSParseNode *pn);
14896 JSParseNode *qualifiedIdentifier();
14897 JSParseNode *attributeIdentifier();
14898 JSParseNode *xmlExpr(JSBool inTag);
14899 JSParseNode *xmlAtomNode();
14900 JSParseNode *xmlNameExpr();
14901 JSParseNode *xmlTagContent(js::TokenKind tagtype, JSAtom **namep);
14902 JSBool xmlElementContent(JSParseNode *pn);
14903 JSParseNode *xmlElementOrList(JSBool allowList);
14904 JSParseNode *xmlElementOrListRoot(JSBool allowList);
14908 Parser::reportErrorNumber(JSParseNode *pn, uintN flags, uintN errorNumber, ...)
14911 __builtin_va_start(args,errorNumber);
14912 bool result = tokenStream.reportCompileErrorNumberVA(pn, flags, errorNumber, args);
14913 __builtin_va_end(args);
14919 GlobalScope *globalScope;
14920 Compiler(JSContext *cx, JSPrincipals *prin = __null, JSStackFrame *cfp = __null);
14925 init(const jschar *base, size_t length, const char *filename, uintN lineno, JSVersion version)
14927 return parser.init(base, length, filename, lineno, version);
14933 compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *principals,
14934 js::Bindings *bindings, const jschar *chars, size_t length,
14935 const char *filename, uintN lineno, JSVersion version);
14937 compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *callerFrame,
14938 JSPrincipals *principals, uint32 tcflags,
14939 const jschar *chars, size_t length,
14940 const char *filename, uintN lineno, JSVersion version,
14941 JSString *source = __null, uintN staticLevel = 0);
14943 static bool defineGlobals(JSContext *cx, GlobalScope &globalScope, JSScript *script);
14947 js_FoldConstants(JSContext *cx, JSParseNode *pn, JSTreeContext *tc,
14948 bool inCond = false);
14950 extern const char js_AnyName_str[];
14951 extern const char js_AttributeName_str[];
14952 extern const char js_isXMLName_str[];
14953 extern const char js_XMLList_str[];
14954 extern const char js_amp_entity_str[];
14955 extern const char js_gt_entity_str[];
14956 extern const char js_lt_entity_str[];
14957 extern const char js_quot_entity_str[];
14959 (* JSIdentityOp)(const void *a, const void *b);
14960 struct JSXMLArray {
14964 JSXMLArrayCursor *cursors;
14966 length = capacity = 0;
14970 void finish(JSContext *cx);
14971 bool setCapacity(JSContext *cx, uint32 capacity);
14974 struct JSXMLArrayCursor
14978 JSXMLArrayCursor *next;
14979 JSXMLArrayCursor **prevp;
14981 JSXMLArrayCursor(JSXMLArray *array)
14982 : array(array), index(0), next(array->cursors), prevp(&array->cursors),
14986 next->prevp = &next;
14987 array->cursors = this;
14989 ~JSXMLArrayCursor() { disconnect(); }
14990 void disconnect() {
14994 next->prevp = prevp;
14999 if (!array || index >= array->length)
15001 return root = array->vector[index++];
15003 void *getCurrent() {
15004 if (!array || index >= array->length)
15006 return root = array->vector[index];
15008 void trace(JSTracer *trc);
15010 typedef enum JSXMLClass {
15012 JSXML_CLASS_ELEMENT,
15013 JSXML_CLASS_ATTRIBUTE,
15014 JSXML_CLASS_PROCESSING_INSTRUCTION,
15016 JSXML_CLASS_COMMENT,
15019 typedef struct JSXMLListVar {
15022 JSObject *targetprop;
15024 typedef struct JSXMLElemVar {
15026 JSXMLArray namespaces;
15029 struct JSXML : js::gc::Cell {
15041 void finalize(JSContext *cx) {
15042 if ((((this)->xml_class) < JSXML_CLASS_ATTRIBUTE)) {
15043 u.list.kids.finish(cx);
15044 if (xml_class == JSXML_CLASS_ELEMENT) {
15045 u.elem.namespaces.finish(cx);
15046 u.elem.attrs.finish(cx);
15052 js_NewXML(JSContext *cx, JSXMLClass xml_class);
15054 js_TraceXML(JSTracer *trc, JSXML *xml);
15056 js_NewXMLObject(JSContext *cx, JSXMLClass xml_class);
15058 js_GetXMLObject(JSContext *cx, JSXML *xml);
15059 extern __attribute__((visibility ("default"))) js::Class js_XMLClass;
15060 extern __attribute__((visibility ("default"))) js::Class js_NamespaceClass;
15061 extern __attribute__((visibility ("default"))) js::Class js_QNameClass;
15062 extern __attribute__((visibility ("default"))) js::Class js_AttributeNameClass;
15063 extern __attribute__((visibility ("default"))) js::Class js_AnyNameClass;
15064 extern js::Class js_XMLFilterClass;
15067 JSObject::isXML() const
15069 return getClass() == &js_XMLClass;
15073 JSObject::isXMLId() const
15075 js::Class *clasp = getClass();
15076 return clasp == &js_QNameClass ||
15077 clasp == &js_AttributeNameClass ||
15078 clasp == &js_AnyNameClass;
15082 JSObject::isNamespace() const
15084 return getClass() == &js_NamespaceClass;
15088 JSObject::isQName() const
15090 js::Class* clasp = getClass();
15091 return clasp == &js_QNameClass ||
15092 clasp == &js_AttributeNameClass ||
15093 clasp == &js_AnyNameClass;
15097 IsXML(const js::Value &v)
15099 return v.isObject() && v.toObject().isXML();
15102 js_InitNamespaceClass(JSContext *cx, JSObject *obj);
15104 js_InitQNameClass(JSContext *cx, JSObject *obj);
15106 js_InitXMLClass(JSContext *cx, JSObject *obj);
15108 js_InitXMLClasses(JSContext *cx, JSObject *obj);
15110 js_GetFunctionNamespace(JSContext *cx, js::Value *vp);
15112 js_IsFunctionQName(JSContext *cx, JSObject *obj, jsid *funidp);
15114 js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp);
15116 js_SetDefaultXMLNamespace(JSContext *cx, const js::Value &v);
15118 js_IsXMLName(JSContext *cx, jsval v);
15120 js_ToAttributeName(JSContext *cx, js::Value *vp);
15121 extern JSFlatString *
15122 js_EscapeAttributeValue(JSContext *cx, JSString *str, JSBool quote);
15124 js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str,
15126 extern JSFlatString *
15127 js_EscapeElementValue(JSContext *cx, JSString *str);
15129 js_ValueToXMLString(JSContext *cx, const js::Value &v);
15131 js_ConstructXMLQNameObject(JSContext *cx, const js::Value & nsval,
15132 const js::Value & lnval);
15134 js_GetAnyName(JSContext *cx, jsid *idp);
15136 js_FindXMLProperty(JSContext *cx, const js::Value &nameval, JSObject **objp, jsid *idp);
15138 js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
15140 js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
15142 js_DeleteXMLListElements(JSContext *cx, JSObject *listobj);
15144 js_StepXMLListFilter(JSContext *cx, JSBool initialized);
15146 js_ValueToXMLObject(JSContext *cx, const js::Value &v);
15148 js_ValueToXMLListObject(JSContext *cx, const js::Value &v);
15150 js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
15153 js_MakeXMLCDATAString(JSContext *cx, JSString *str);
15155 js_MakeXMLCommentString(JSContext *cx, JSString *str);
15157 js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str);
15159 js_TestXMLEquality(JSContext *cx, const js::Value &v1, const js::Value &v2,
15162 js_ConcatenateXML(JSContext *cx, JSObject *obj1, JSObject *obj2, js::Value *vp);
15164 class ExecutableAllocator;
15167 typedef HashMap<jsbytecode*,
15169 DefaultHasher<jsbytecode*>,
15170 SystemAllocPolicy> RecordAttemptMap;
15171 typedef HashMap<jsbytecode*,
15173 DefaultHasher<jsbytecode*>,
15174 SystemAllocPolicy> LoopProfileMap;
15176 typedef HashSet<JSScript *,
15177 DefaultHasher<JSScript *>,
15178 SystemAllocPolicy> TracedScriptSet;
15179 typedef HashMap<JSFunction *,
15181 DefaultHasher<JSFunction *>,
15182 SystemAllocPolicy> ToSourceCache;
15183 struct TraceMonitor;
15187 TraceMonitor* traceMonitor;
15191 FrameInfo** callstackBase;
15195 VMSideExit* lastTreeExitGuard;
15196 VMSideExit* lastTreeCallGuard;
15197 void* rpAtLastTreeCall;
15198 VMSideExit* outermostTreeExitGuard;
15199 TreeFragment* outermostTree;
15200 uintN* inlineCallCountp;
15201 VMSideExit** innermostNestedGuardp;
15202 VMSideExit* innermost;
15205 uint32 builtinStatus;
15206 double* deepBailSp;
15208 js::Value* nativeVp;
15209 TracerState(JSContext *cx, TraceMonitor *tm, TreeFragment *ti,
15210 uintN &inlineCallCountp, VMSideExit** innermostNestedGuardp);
15213 struct TraceNativeStorage
15215 double stack_global_buf[MAX_NATIVE_STACK_SLOTS + GLOBAL_SLOTS_BUFFER_SIZE];
15216 FrameInfo *callstack_buf[MAX_CALL_STACK_ENTRIES];
15217 double *stack() { return stack_global_buf; }
15218 double *global() { return stack_global_buf + MAX_NATIVE_STACK_SLOTS; }
15219 FrameInfo **callstack() { return callstack_buf; }
15221 struct GlobalState {
15222 JSObject* globalObj;
15223 uint32 globalShape;
15224 SlotList* globalSlots;
15226 struct TraceMonitor {
15227 JSContext *tracecx;
15228 js::TracerState *tracerState;
15229 js::VMSideExit *bailExit;
15230 unsigned iterationCounter;
15231 TraceNativeStorage *storage;
15232 VMAllocator* dataAlloc;
15233 VMAllocator* traceAlloc;
15234 VMAllocator* tempAlloc;
15235 nanojit::CodeAlloc* codeAlloc;
15236 nanojit::Assembler* assembler;
15237 FrameInfoCache* frameCache;
15240 TraceRecorder* recorder;
15241 LoopProfile* profile;
15242 GlobalState globalStates[MONITOR_N_GLOBAL_STATES];
15243 TreeFragment *vmfragments[FRAGMENT_TABLE_SIZE];
15244 RecordAttemptMap* recordAttempts;
15245 LoopProfileMap* loopProfiles;
15246 uint32 maxCodeCacheBytes;
15248 TypeMap* cachedTempTypeMap;
15249 TracedScriptSet tracedScripts;
15250 bool ontrace() const {
15254 void sweep(JSContext *cx);
15255 void mark(JSTracer *trc);
15256 bool outOfMemory() const;
15259 class JaegerCompartment;
15263 class NativeIterCache {
15264 static const size_t SIZE = size_t(1) << 8;
15265 JSObject *data[SIZE];
15266 static size_t getIndex(uint32 key) {
15267 return size_t(key) % SIZE;
15273 PodArrayZero(data);
15276 PodArrayZero(data);
15279 JSObject *get(uint32 key) const {
15280 return data[getIndex(key)];
15282 void set(uint32 key, JSObject *iterobj) {
15283 data[getIndex(key)] = iterobj;
15291 DtoaCache() : s(__null) {}
15292 void purge() { s = __null; }
15293 JSString *lookup(jsint base, double d) {
15294 return this->s && base == this->base && d == this->d ? this->s : __null;
15296 void cache(jsint base, double d, JSString *s) {
15303 struct __attribute__((visibility ("default"))) JSCompartment {
15305 JSPrincipals *principals;
15306 js::gc::Chunk *chunk;
15307 js::gc::ArenaList arenas[js::gc::FINALIZE_LIMIT];
15308 js::gc::FreeLists freeLists;
15310 size_t gcTriggerBytes;
15311 size_t gcLastBytes;
15312 JSScript *scriptsToGC[((JSUint32)1 << (6))];
15315 js::WrapperMap crossCompartmentWrappers;
15316 js::PropertyTree propertyTree;
15317 js::EmptyShape *emptyArgumentsShape;
15318 js::EmptyShape *emptyBlockShape;
15319 js::EmptyShape *emptyCallShape;
15320 js::EmptyShape *emptyDeclEnvShape;
15321 js::EmptyShape *emptyEnumeratorShape;
15322 js::EmptyShape *emptyWithShape;
15323 typedef js::HashSet<js::EmptyShape *,
15324 js::DefaultHasher<js::EmptyShape *>,
15325 js::SystemAllocPolicy> EmptyShapeSet;
15326 EmptyShapeSet emptyShapes;
15329 JSC::ExecutableAllocator *regExpAllocator;
15330 js::NativeIterCache nativeIterCache;
15331 js::ToSourceCache toSourceCache;
15332 JSCompartment(JSRuntime *rt);
15335 void markCrossCompartment(JSTracer *trc);
15336 void mark(JSTracer *trc);
15337 bool wrap(JSContext *cx, js::Value *vp);
15338 bool wrap(JSContext *cx, JSString **strp);
15339 bool wrap(JSContext *cx, JSObject **objp);
15340 bool wrapId(JSContext *cx, jsid *idp);
15341 bool wrap(JSContext *cx, js::PropertyOp *op);
15342 bool wrap(JSContext *cx, js::StrictPropertyOp *op);
15343 bool wrap(JSContext *cx, js::PropertyDescriptor *desc);
15344 bool wrap(JSContext *cx, js::AutoIdVector &props);
15345 void sweep(JSContext *cx, uint32 releaseInterval);
15346 void purge(JSContext *cx);
15347 void finishArenaLists();
15348 void finalizeObjectArenaLists(JSContext *cx);
15349 void finalizeStringArenaLists(JSContext *cx);
15350 bool arenaListsAreEmpty();
15351 void setGCLastBytes(size_t lastBytes);
15352 js::DtoaCache dtoaCache;
15354 js::MathCache *mathCache;
15355 js::MathCache *allocMathCache(JSContext *cx);
15357 typedef js::HashMap<jsbytecode*,
15359 js::DefaultHasher<jsbytecode*>,
15360 js::SystemAllocPolicy> BackEdgeMap;
15361 BackEdgeMap backEdgeTable;
15362 JSCompartment *thisForCtor() { return this; }
15364 js::MathCache *getMathCache(JSContext *cx) {
15365 return mathCache ? mathCache : allocMathCache(cx);
15367 bool isMarked() { return marked; }
15368 void clearMark() { marked = false; }
15369 size_t backEdgeCount(jsbytecode *pc) const;
15370 size_t incBackEdgeCount(jsbytecode *pc);
15374 JS_ON_TRACE(JSContext *cx)
15378 static inline js::TraceRecorder *
15379 TRACE_RECORDER(JSContext *cx)
15383 static inline js::LoopProfile *
15384 TRACE_PROFILER(JSContext *cx)
15389 static inline MathCache *
15390 GetMathCache(JSContext *cx)
15392 return cx->compartment->getMathCache(cx);
15396 class PreserveCompartment {
15400 JSCompartment *oldCompartment;
15403 PreserveCompartment(JSContext *cx ) : cx(cx) {
15405 oldCompartment = cx->compartment;
15407 ~PreserveCompartment() {
15408 cx->compartment = oldCompartment;
15411 class SwitchToCompartment : public PreserveCompartment {
15413 SwitchToCompartment(JSContext *cx, JSCompartment *newCompartment) : PreserveCompartment(cx) {
15414 cx->compartment = newCompartment;
15416 SwitchToCompartment(JSContext *cx, JSObject *target) : PreserveCompartment(cx) {
15417 cx->compartment = target->getCompartment();
15420 class AssertCompartmentUnchanged {
15422 JSContext * const cx;
15423 JSCompartment * const oldCompartment;
15426 AssertCompartmentUnchanged(JSContext *cx )
15427 : cx(cx), oldCompartment(cx->compartment) {
15430 ~AssertCompartmentUnchanged() {
15435 extern js::Class js_RegExpClass;
15437 class RegExpStatics
15439 typedef Vector<int, 20, SystemAllocPolicy> MatchPairs;
15440 MatchPairs matchPairs;
15441 JSLinearString *matchPairsInput;
15442 JSString *pendingInput;
15444 RegExpStatics *bufferLink;
15446 bool createDependent(JSContext *cx, size_t start, size_t end, Value *out) const;
15447 void copyTo(RegExpStatics &dst) {
15448 dst.matchPairs.clear();
15449 ((void) (dst.matchPairs.append(matchPairs)));
15450 dst.matchPairsInput = matchPairsInput;
15451 dst.pendingInput = pendingInput;
15454 void aboutToWrite() {
15455 if (bufferLink && !bufferLink->copied) {
15456 copyTo(*bufferLink);
15457 bufferLink->copied = true;
15460 bool save(JSContext *cx, RegExpStatics *buffer) {
15462 buffer->bufferLink = bufferLink;
15463 bufferLink = buffer;
15464 if (!buffer->matchPairs.reserve(matchPairs.length())) {
15465 js_ReportOutOfMemory(cx);
15471 if (bufferLink->copied)
15472 bufferLink->copyTo(*this);
15473 bufferLink = bufferLink->bufferLink;
15475 void checkInvariants() {
15477 void checkParenNum(size_t pairNum) const {
15481 bool pairIsPresent(size_t pairNum) const {
15482 return get(pairNum, 0) >= 0;
15484 size_t getParenLength(size_t pairNum) const {
15485 checkParenNum(pairNum);
15487 return get(pairNum, 1) - get(pairNum, 0);
15489 int get(size_t pairNum, bool which) const {
15491 return matchPairs[2 * pairNum + which];
15493 bool makeMatch(JSContext *cx, size_t checkValidIndex, size_t pairNum, Value *out) const;
15494 static const uintN allFlags = 0x01 | 0x02 | 0x08 | 0x04;
15495 struct InitBuffer {};
15496 explicit RegExpStatics(InitBuffer) : bufferLink(__null), copied(false) {}
15497 friend class PreserveRegExpStatics;
15499 RegExpStatics() : bufferLink(__null), copied(false) { clear(); }
15500 static RegExpStatics *extractFrom(JSObject *global);
15501 bool updateFromMatch(JSContext *cx, JSLinearString *input, int *buf, size_t matchItemCount) {
15503 pendingInput = input;
15504 if (!matchPairs.resizeUninitialized(matchItemCount)) {
15505 js_ReportOutOfMemory(cx);
15508 for (size_t i = 0; i < matchItemCount; ++i)
15509 matchPairs[i] = buf[i];
15510 matchPairsInput = input;
15513 void setMultiline(bool enabled) {
15516 flags = flags | 0x04;
15518 flags = flags & ~0x04;
15523 pendingInput = __null;
15524 matchPairsInput = __null;
15525 matchPairs.clear();
15527 void reset(JSString *newInput, bool newMultiline) {
15530 pendingInput = newInput;
15531 setMultiline(newMultiline);
15534 void setPendingInput(JSString *newInput) {
15536 pendingInput = newInput;
15539 size_t pairCount() const {
15541 return matchPairs.length() / 2;
15544 size_t parenCount() const {
15545 size_t pc = pairCount();
15549 JSString *getPendingInput() const { return pendingInput; }
15550 uintN getFlags() const { return flags; }
15551 bool multiline() const { return flags & 0x04; }
15552 size_t matchStart() const {
15553 int start = get(0, 0);
15555 return size_t(start);
15557 size_t matchLimit() const {
15558 int limit = get(0, 1);
15560 return size_t(limit);
15562 bool matched() const {
15565 return get(0, 1) - get(0, 0) > 0;
15567 void mark(JSTracer *trc) const {
15569 do { JSString *str_ = (pendingInput); ((void) 0); do { do { } while (0); JS_CallTracer(((trc)), (str_), (1)); } while (0); } while (0);
15570 if (matchPairsInput)
15571 do { JSString *str_ = (matchPairsInput); ((void) 0); do { do { } while (0); JS_CallTracer(((trc)), (str_), (1)); } while (0); } while (0);
15573 bool createPendingInput(JSContext *cx, Value *out) const;
15574 bool createLastMatch(JSContext *cx, Value *out) const { return makeMatch(cx, 0, 0, out); }
15575 bool createLastParen(JSContext *cx, Value *out) const;
15576 bool createLeftContext(JSContext *cx, Value *out) const;
15577 bool createRightContext(JSContext *cx, Value *out) const;
15578 bool createParen(JSContext *cx, size_t pairNum, Value *out) const {
15580 if (pairNum >= pairCount()) {
15581 out->setString(cx->runtime->emptyString);
15584 return makeMatch(cx, pairNum * 2, pairNum, out);
15586 void getParen(size_t pairNum, JSSubString *out) const;
15587 void getLastMatch(JSSubString *out) const;
15588 void getLastParen(JSSubString *out) const;
15589 void getLeftContext(JSSubString *out) const;
15590 void getRightContext(JSSubString *out) const;
15592 class PreserveRegExpStatics
15594 RegExpStatics *const original;
15595 RegExpStatics buffer;
15597 explicit PreserveRegExpStatics(RegExpStatics *original)
15598 : original(original),
15599 buffer(RegExpStatics::InitBuffer())
15601 bool init(JSContext *cx) {
15602 return original->save(cx, &buffer);
15604 ~PreserveRegExpStatics() {
15605 original->restore();
15611 VALUE_IS_REGEXP(JSContext *cx, js::Value v)
15613 return !v.isPrimitive() && v.toObject().isRegExp();
15615 inline const js::Value &
15616 JSObject::getRegExpLastIndex() const
15619 return getSlot(JSSLOT_REGEXP_LAST_INDEX);
15622 JSObject::setRegExpLastIndex(const js::Value &v)
15625 setSlot(JSSLOT_REGEXP_LAST_INDEX, v);
15628 JSObject::setRegExpLastIndex(jsdouble d)
15631 setSlot(JSSLOT_REGEXP_LAST_INDEX, js::NumberValue(d));
15634 JSObject::zeroRegExpLastIndex()
15637 getSlotRef(JSSLOT_REGEXP_LAST_INDEX).setInt32(0);
15639 namespace js { class AutoStringRooter; }
15642 JSObject::isRegExp() const
15644 return getClass() == &js_RegExpClass;
15646 extern __attribute__((visibility ("default"))) JSBool
15647 js_ObjectIsRegExp(JSObject *obj);
15649 js_InitRegExpClass(JSContext *cx, JSObject *obj);
15651 js_regexp_toString(JSContext *cx, JSObject *obj, js::Value *vp);
15652 extern __attribute__((visibility ("default"))) JSObject *
15653 js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *proto);
15654 extern __attribute__((visibility ("default"))) void
15655 js_SaveAndClearRegExpStatics(JSContext *cx, js::RegExpStatics *res, js::AutoStringRooter *tvr);
15656 extern __attribute__((visibility ("default"))) void
15657 js_RestoreRegExpStatics(JSContext *cx, js::RegExpStatics *res);
15659 js_XDRRegExpObject(JSXDRState *xdr, JSObject **objp);
15661 js_regexp_exec(JSContext *cx, uintN argc, js::Value *vp);
15663 js_regexp_test(JSContext *cx, uintN argc, js::Value *vp);
15665 static inline JSObject *
15666 GetGlobalForScopeChain(JSContext *cx)
15670 return cx->fp()->scopeChain().getGlobal();
15671 JSObject *scope = cx->globalObject;
15673 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_INACTIVE);
15676 OBJ_TO_INNER_OBJECT(cx, scope);
15682 JSContext::ensureGeneratorStackSpace()
15684 bool ok = genStack.reserve(genStack.length() + 1);
15686 js_ReportOutOfMemory(this);
15690 JSContext::computeNextFrame(JSStackFrame *fp)
15692 JSStackFrame *next = __null;
15693 for (js::StackSegment *ss = currentSegment; ; ss = ss->getPreviousInContext()) {
15694 JSStackFrame *end = ss->getInitialFrame()->prev();
15695 for (JSStackFrame *f = ss->getCurrentFrame(); f != end; next = f, f = f->prev()) {
15699 if (end != ss->getPreviousInContext()->getCurrentFrame())
15703 inline js::RegExpStatics *
15704 JSContext::regExpStatics()
15706 return js::RegExpStatics::extractFrom(js::GetGlobalForScopeChain(this));
15709 __attribute__((always_inline)) inline JSFrameRegs *
15710 StackSegment::getCurrentRegs() const
15713 return isActive() ? cx->regs : getSuspendedRegs();
15715 __attribute__((always_inline)) inline JSStackFrame *
15716 StackSegment::getCurrentFrame() const
15718 return getCurrentRegs()->fp;
15721 StackSpace::firstUnused() const
15723 StackSegment *seg = currentSegment;
15728 if (seg->inContext()) {
15729 Value *sp = seg->getCurrentRegs()->sp;
15730 if (invokeArgEnd > sp) {
15734 return invokeArgEnd;
15740 return invokeArgEnd;
15742 __attribute__((always_inline)) inline
15744 StackSpace::isCurrentAndActive(JSContext *cx) const
15746 return currentSegment &&
15747 currentSegment->isActive() &&
15748 currentSegment == cx->getCurrentSegment();
15750 __attribute__((always_inline)) inline
15752 StackSpace::ensureSpace(JSContext *maybecx, Value *from, ptrdiff_t nvals) const
15755 if (end - from < nvals) {
15757 js_ReportOutOfScriptQuota(maybecx);
15764 __attribute__((always_inline)) inline
15766 StackSpace::ensureEnoughSpaceToEnterTrace()
15768 return end - firstUnused() > MAX_TRACE_SPACE_VALS;
15770 __attribute__((always_inline)) inline
15772 StackSpace::EnsureSpaceCheck::operator()(const StackSpace &stack, JSContext *cx,
15773 Value *from, uintN nvals)
15775 return stack.ensureSpace(cx, from, nvals);
15777 __attribute__((always_inline)) inline
15779 StackSpace::LimitCheck::operator()(const StackSpace &stack, JSContext *cx,
15780 Value *from, uintN nvals)
15784 if (*limit - from >= ptrdiff_t(nvals))
15786 if (stack.bumpCommitAndLimit(base, from, nvals, limit))
15788 js_ReportOverRecursed(cx);
15791 __attribute__((always_inline)) inline
15793 StackSpace::pushInvokeArgs(JSContext *cx, uintN argc, InvokeArgsGuard *ag)
15795 if ((__builtin_expect((!isCurrentAndActive(cx)), 0)))
15796 return pushSegmentForInvoke(cx, argc, ag);
15797 Value *sp = cx->regs->sp;
15798 Value *start = invokeArgEnd > sp ? invokeArgEnd : sp;
15800 uintN nvals = 2 + argc;
15801 if (!ensureSpace(cx, start, nvals))
15804 Value *vpend = vp + nvals;
15805 ag->prevInvokeArgEnd = invokeArgEnd;
15806 invokeArgEnd = vpend;
15808 ag->argv_ = vp + 2;
15812 __attribute__((always_inline)) inline void
15813 StackSpace::popInvokeArgs(const InvokeArgsGuard &ag)
15815 if ((__builtin_expect((ag.seg != __null), 0))) {
15816 popSegmentForInvoke(ag);
15823 invokeArgEnd = ag.prevInvokeArgEnd;
15825 __attribute__((always_inline)) inline
15826 InvokeArgsGuard::~InvokeArgsGuard()
15828 if ((__builtin_expect((!pushed()), 0)))
15830 cx->stack().popInvokeArgs(*this);
15832 template <class Check>
15833 __attribute__((always_inline)) inline JSStackFrame *
15834 StackSpace::getCallFrame(JSContext *cx, Value *firstUnused, uintN nactual,
15835 JSFunction *fun, JSScript *script, uint32 *flags,
15839 uintN nvals = VALUES_PER_STACK_FRAME + script->nslots;
15840 uintN nformal = fun->nargs;
15841 if (nactual == nformal) {
15842 if ((__builtin_expect((!check(*this, cx, firstUnused, nvals)), 0)))
15844 return reinterpret_cast<JSStackFrame *>(firstUnused);
15846 if (nactual < nformal) {
15847 *flags |= JSFRAME_UNDERFLOW_ARGS;
15848 uintN nmissing = nformal - nactual;
15849 if ((__builtin_expect((!check(*this, cx, firstUnused, nmissing + nvals)), 0)))
15851 SetValueRangeToUndefined(firstUnused, nmissing);
15852 return reinterpret_cast<JSStackFrame *>(firstUnused + nmissing);
15854 *flags |= JSFRAME_OVERFLOW_ARGS;
15855 uintN ncopy = 2 + nformal;
15856 if ((__builtin_expect((!check(*this, cx, firstUnused, ncopy + nvals)), 0)))
15858 Value *dst = firstUnused;
15859 Value *src = firstUnused - (2 + nactual);
15860 PodCopy(dst, src, ncopy);
15861 Debug_SetValueRangeToCrashOnTouch(src, ncopy);
15862 return reinterpret_cast<JSStackFrame *>(firstUnused + ncopy);
15864 __attribute__((always_inline)) inline
15866 StackSpace::getInvokeFrame(JSContext *cx, const CallArgs &args,
15867 JSFunction *fun, JSScript *script,
15868 uint32 *flags, InvokeFrameGuard *fg) const
15871 Value *firstUnused = args.argv() + args.argc();
15872 fg->regs_.fp = getCallFrame(cx, firstUnused, args.argc(), fun, script, flags,
15873 EnsureSpaceCheck());
15874 fg->regs_.sp = fg->regs_.fp->slots() + script->nfixed;
15875 fg->regs_.pc = script->code;
15876 return fg->regs_.fp != __null;
15878 __attribute__((always_inline)) inline void
15879 StackSpace::pushInvokeFrame(JSContext *cx, const CallArgs &args,
15880 InvokeFrameGuard *fg)
15883 if ((__builtin_expect((!currentSegment->inContext()), 0))) {
15884 cx->pushSegmentAndFrame(currentSegment, fg->regs_);
15886 fg->prevRegs_ = cx->regs;
15887 cx->setCurrentRegs(&fg->regs_);
15892 __attribute__((always_inline)) inline void
15893 StackSpace::popInvokeFrame(const InvokeFrameGuard &fg)
15895 JSContext *cx = fg.cx_;
15896 JSStackFrame *fp = fg.regs_.fp;
15898 if ((__builtin_expect((currentSegment->getInitialFrame() == fp), 0))) {
15899 cx->popSegmentAndFrame();
15904 cx->setCurrentRegs(fg.prevRegs_);
15907 __attribute__((always_inline)) inline void
15908 InvokeFrameGuard::pop()
15911 cx_->stack().popInvokeFrame(*this);
15914 __attribute__((always_inline)) inline JSStackFrame *
15915 StackSpace::getInlineFrame(JSContext *cx, Value *sp, uintN nactual,
15916 JSFunction *fun, JSScript *script, uint32 *flags) const
15921 return getCallFrame(cx, sp, nactual, fun, script, flags, EnsureSpaceCheck());
15923 __attribute__((always_inline)) inline JSStackFrame *
15924 StackSpace::getInlineFrameWithinLimit(JSContext *cx, Value *sp, uintN nactual,
15925 JSFunction *fun, JSScript *script, uint32 *flags,
15926 JSStackFrame *base, Value **limit) const
15931 return getCallFrame(cx, sp, nactual, fun, script, flags, LimitCheck(base, limit));
15933 __attribute__((always_inline)) inline void
15934 StackSpace::pushInlineFrame(JSContext *cx, JSScript *script, JSStackFrame *fp,
15940 regs->pc = script->code;
15941 regs->sp = fp->slots() + script->nfixed;
15943 __attribute__((always_inline)) inline void
15944 StackSpace::popInlineFrame(JSContext *cx, JSStackFrame *prev, Value *newsp)
15951 JSFrameRegs *regs = cx->regs;
15952 regs->pc = prev->pc(cx, regs->fp);
15956 __attribute__((always_inline)) inline Value *
15957 StackSpace::getStackLimit(JSContext *cx)
15959 Value *sp = cx->regs->sp;
15961 Value *limit = sp + STACK_QUOTA;
15962 if ((__builtin_expect((limit <= end), 1)))
15964 uintN minimum = cx->fp()->numSlots() + VALUES_PER_STACK_FRAME;
15965 return ensureSpace(cx, sp, minimum) ? sp + minimum : __null;
15968 FrameRegsIter::FrameRegsIter(JSContext *cx)
15971 curseg = cx->getCurrentSegment();
15972 if ((__builtin_expect((!curseg || !curseg->isActive()), 0))) {
15977 curfp = cx->regs->fp;
15978 cursp = cx->regs->sp;
15979 curpc = cx->regs->pc;
15982 inline FrameRegsIter &
15983 FrameRegsIter::operator++()
15985 JSStackFrame *fp = curfp;
15986 JSStackFrame *prev = curfp = curfp->prev();
15989 curpc = curfp->pc(cx, fp);
15990 if ((__builtin_expect((fp == curseg->getInitialFrame()), 0))) {
15994 cursp = fp->formalArgsEnd();
15997 class AutoNamespaceArray : protected AutoGCRooter {
15999 AutoNamespaceArray(JSContext *cx) : AutoGCRooter(cx, NAMESPACES) {
16002 ~AutoNamespaceArray() {
16003 array.finish(context);
16005 uint32 length() const { return array.length; }
16007 friend void AutoGCRooter::trace(JSTracer *trc);
16010 template <class T1> inline void
16011 assertSameCompartment(JSContext *cx, T1 t1)
16014 template <class T1, class T2> inline void
16015 assertSameCompartment(JSContext *cx, T1 t1, T2 t2)
16018 template <class T1, class T2, class T3> inline void
16019 assertSameCompartment(JSContext *cx, T1 t1, T2 t2, T3 t3)
16022 template <class T1, class T2, class T3, class T4> inline void
16023 assertSameCompartment(JSContext *cx, T1 t1, T2 t2, T3 t3, T4 t4)
16026 template <class T1, class T2, class T3, class T4, class T5> inline void
16027 assertSameCompartment(JSContext *cx, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
16030 __attribute__((always_inline)) inline
16032 CallJSNative(JSContext *cx, js::Native native, uintN argc, js::Value *vp)
16034 assertSameCompartment(cx, ValueArray(vp, argc + 2));
16035 JSBool ok = native(cx, argc, vp);
16037 assertSameCompartment(cx, vp[0]);
16042 extern JSBool CallOrConstructBoundFunction(JSContext *, uintN, js::Value *);
16043 __attribute__((always_inline)) inline
16045 CallJSNativeConstructor(JSContext *cx, js::Native native, uintN argc, js::Value *vp)
16048 if (!CallJSNative(cx, native, argc, vp))
16050 extern JSBool proxy_Construct(JSContext *, uintN, Value *);
16055 __attribute__((always_inline)) inline
16057 CallJSPropertyOp(JSContext *cx, js::PropertyOp op, JSObject *obj, jsid id, js::Value *vp)
16059 assertSameCompartment(cx, obj, id, *vp);
16060 JSBool ok = op(cx, obj, id, vp);
16062 assertSameCompartment(cx, obj, *vp);
16065 __attribute__((always_inline)) inline
16067 CallJSPropertyOpSetter(JSContext *cx, js::StrictPropertyOp op, JSObject *obj, jsid id,
16068 JSBool strict, js::Value *vp)
16070 assertSameCompartment(cx, obj, id, *vp);
16071 return op(cx, obj, id, strict, vp);
16075 CallSetter(JSContext *cx, JSObject *obj, jsid id, js::StrictPropertyOp op, uintN attrs,
16076 uintN shortid, JSBool strict, js::Value *vp)
16079 return ExternalGetOrSet(cx, obj, id, CastAsObjectJsval(op), JSACC_WRITE, 1, vp, vp);
16081 return js_ReportGetterOnlyAssignment(cx);
16083 id = INT_TO_JSID(shortid);
16084 return CallJSPropertyOpSetter(cx, op, obj, id, strict, vp);
16087 LeaveTraceIfGlobalObject(JSContext *cx, JSObject *obj)
16093 LeaveTraceIfArgumentsObject(JSContext *cx, JSObject *obj)
16095 if (obj->isArguments())
16098 static inline JSBool
16099 CanLeaveTrace(JSContext *cx)
16106 JSContext::setPendingException(js::Value v) {
16107 this->throwing = true;
16108 this->exception = v;
16109 assertSameCompartment(this, v);
16114 CheckStringLength(JSContext *cx, size_t length)
16116 if ((__builtin_expect((length > JSString::MAX_LENGTH), 0))) {
16117 js_ReportAllocationOverflow(cx);
16124 typedef Vector<jschar, 32> CharBuffer;
16126 static inline bool checkLength(JSContext *cx, size_t length);
16127 inline bool checkLength(size_t length);
16128 JSContext *context() const { return cb.allocPolicy().context(); }
16130 explicit inline StringBuffer(JSContext *cx);
16131 bool reserve(size_t len);
16132 bool resize(size_t len);
16133 bool append(const jschar c);
16134 bool append(const jschar *chars, size_t len);
16135 bool append(const jschar *begin, const jschar *end);
16136 bool append(JSString *str);
16137 bool append(JSAtom *atom);
16138 bool appendN(const jschar c, size_t n);
16139 bool appendInflated(const char *cstr, size_t len);
16140 JSAtom *atomize(uintN flags = 0);
16141 static JSAtom *atomize(JSContext *cx, const CharBuffer &cb, uintN flags = 0);
16142 static JSAtom *atomize(JSContext *cx, const jschar *begin, size_t length, uintN flags = 0);
16143 void replaceRawBuffer(jschar *chars, size_t len) { cb.replaceRawBuffer(chars, len); }
16144 jschar *begin() { return cb.begin(); }
16145 jschar *end() { return cb.end(); }
16146 const jschar *begin() const { return cb.begin(); }
16147 const jschar *end() const { return cb.end(); }
16148 bool empty() const { return cb.empty(); }
16149 inline jsint length() const;
16150 JSFlatString *finishString();
16151 template <size_t ArrayLength>
16152 bool append(const char (&array)[ArrayLength]) {
16153 return cb.append(array, array + ArrayLength - 1);
16157 StringBuffer::StringBuffer(JSContext *cx)
16162 StringBuffer::reserve(size_t len)
16164 if (!checkLength(len))
16166 return cb.reserve(len);
16170 StringBuffer::resize(size_t len)
16172 if (!checkLength(len))
16174 return cb.resize(len);
16178 StringBuffer::append(const jschar c)
16180 if (!checkLength(cb.length() + 1))
16182 return cb.append(c);
16186 StringBuffer::append(const jschar *chars, size_t len)
16188 if (!checkLength(cb.length() + len))
16190 return cb.append(chars, len);
16194 StringBuffer::append(const jschar *begin, const jschar *end)
16196 if (!checkLength(cb.length() + (end - begin)))
16198 return cb.append(begin, end);
16202 StringBuffer::append(JSString *str)
16204 JSLinearString *linear = str->ensureLinear(context());
16205 size_t strLen = linear->length();
16206 if (!checkLength(cb.length() + strLen))
16208 return cb.append(linear->chars(), strLen);
16212 StringBuffer::append(JSAtom *atom)
16214 size_t strLen = atom->length();
16215 if (!checkLength(cb.length() + strLen))
16217 return cb.append(atom->chars(), strLen);
16221 StringBuffer::appendN(const jschar c, size_t n)
16223 if (!checkLength(cb.length() + n))
16225 return cb.appendN(c, n);
16229 StringBuffer::appendInflated(const char *cstr, size_t cstrlen)
16231 size_t lengthBefore = length();
16232 if (!cb.growByUninitialized(cstrlen))
16234 js_InflateStringToBuffer(context(), cstr, cstrlen, begin() + lengthBefore, &cstrlen);
16239 StringBuffer::length() const
16241 typedef int js_static_assert65[(jsint(JSString::MAX_LENGTH) == JSString::MAX_LENGTH) ? 1 : -1];
16243 return jsint(cb.length());
16247 StringBuffer::checkLength(size_t length)
16249 return CheckStringLength(context(), length);
16252 inline JSFlatString *
16253 JSString::unitString(jschar c)
16256 return const_cast<JSString *>(&unitStringTable[c])->assertIsFlat();
16258 inline JSLinearString *
16259 JSString::getUnitString(JSContext *cx, JSString *str, size_t index)
16262 const jschar *chars = str->getChars(cx);
16265 jschar c = chars[index];
16266 if (c < UNIT_STRING_LIMIT)
16267 return unitString(c);
16268 return js_NewDependentString(cx, str, index, 1);
16270 inline JSFlatString *
16271 JSString::length2String(jschar c1, jschar c2)
16275 return const_cast<JSString *> (
16276 &length2StringTable[(((size_t)toSmallChar[c1]) << 6) + toSmallChar[c2]]
16279 inline JSFlatString *
16280 JSString::length2String(uint32 i)
16283 return length2String('0' + i / 10, '0' + i % 10);
16285 inline JSFlatString *
16286 JSString::intString(jsint i)
16288 jsuint u = jsuint(i);
16290 return const_cast<JSString *>(JSString::intStringTable[u])->assertIsFlat();
16292 inline JSFlatString *
16293 JSString::lookupStaticString(const jschar *chars, size_t length)
16296 if (chars[0] < UNIT_STRING_LIMIT)
16297 return unitString(chars[0]);
16300 if (fitsInSmallChar(chars[0]) && fitsInSmallChar(chars[1]))
16301 return length2String(chars[0], chars[1]);
16303 typedef int js_static_assert66[(INT_STRING_LIMIT <= 999) ? 1 : -1];
16305 if ('1' <= chars[0] && chars[0] <= '9' &&
16306 '0' <= chars[1] && chars[1] <= '9' &&
16307 '0' <= chars[2] && chars[2] <= '9') {
16308 jsint i = (chars[0] - '0') * 100 +
16309 (chars[1] - '0') * 10 +
16311 if (jsuint(i) < INT_STRING_LIMIT)
16312 return intString(i);
16318 JSString::finalize(JSContext *cx) {
16321 if (isDependent()) {
16323 } else if (isFlat()) {
16324 cx->runtime->stringMemoryUsed -= length() * 2;
16325 cx->free(const_cast<jschar *>(flatChars()));
16329 JSShortString::finalize(JSContext *cx)
16336 JSExternalString::finalize(JSContext *cx)
16342 jschar *chars = const_cast<jschar *>(flatChars());
16345 JSStringFinalizeOp finalizer = str_finalizers[externalStringType];
16347 finalizer(cx, this);
16350 JSExternalString::finalize()
16353 JSStringFinalizeOp finalizer = str_finalizers[externalStringType];
16355 finalizer(__null, this);
16359 class RopeBuilder {
16363 RopeBuilder(JSContext *cx)
16364 : cx(cx), res(cx->runtime->emptyString)
16366 inline bool append(JSString *str) {
16367 res = js_ConcatStrings(cx, res, str);
16370 inline JSString *result() {
16374 class StringSegmentRange
16376 Vector<JSString *, 32> stack;
16378 bool settle(JSString *str) {
16379 while (str->isRope()) {
16380 if (!stack.append(str->ropeRight()))
16382 str = str->ropeLeft();
16388 StringSegmentRange(JSContext *cx)
16389 : stack(cx), cur(__null)
16391 __attribute__((warn_unused_result)) bool init(JSString *str) {
16393 return settle(str);
16395 bool empty() const {
16396 return cur == __null;
16398 JSString *front() const {
16402 __attribute__((warn_unused_result)) bool popFront() {
16404 if (stack.empty()) {
16408 return settle(stack.popCopy());
16413 struct PropertyTable {
16414 static const uint32 MAX_LINEAR_SEARCHES = 7;
16415 static const uint32 MIN_SIZE_LOG2 = 4;
16416 static const uint32 MIN_SIZE = ((JSUint32)1 << (MIN_SIZE_LOG2));
16419 uint32 removedCount;
16421 js::Shape **entries;
16422 PropertyTable(uint32 nentries)
16423 : hashShift(32 - MIN_SIZE_LOG2),
16424 entryCount(nentries),
16426 freelist(0xffffffff)
16432 uint32 capacity() const { return ((JSUint32)1 << (32 - hashShift)); }
16433 bool needsToGrow() const {
16434 uint32 size = capacity();
16435 return entryCount + removedCount >= size - (size >> 2);
16437 bool grow(JSContext *cx);
16438 bool init(JSRuntime *rt, js::Shape *lastProp);
16439 bool change(int log2Delta, JSContext *cx);
16440 js::Shape **search(jsid id, bool adding);
16445 class PropertyTree;
16446 static inline PropertyOp
16447 CastAsPropertyOp(js::Class *clasp)
16449 return (__extension__ (PropertyOp) (size_t) (clasp));
16451 struct Shape : public JSObjectMap
16453 friend struct ::JSObject;
16454 friend struct ::JSFunction;
16455 friend class js::PropertyTree;
16456 friend class js::Bindings;
16457 friend bool IsShapeAboutToBeFinalized(JSContext *cx, const js::Shape *shape);
16459 mutable size_t numLinearSearches;
16460 mutable js::PropertyTable *table;
16463 inline void freeTable(JSContext *cx);
16464 static bool initEmptyShapes(JSCompartment *comp);
16465 static void finishEmptyShapes(JSCompartment *comp);
16469 js::PropertyOp rawGetter;
16470 JSObject *getterObj;
16474 js::StrictPropertyOp rawSetter;
16475 JSObject *setterObj;
16481 mutable uint8 flags;
16485 mutable js::Shape *parent;
16487 mutable js::KidsPointer kids;
16488 mutable js::Shape **listp;
16490 static inline js::Shape **search(JSRuntime *rt, js::Shape **startp, jsid id,
16491 bool adding = false);
16492 static js::Shape *newDictionaryShape(JSContext *cx, const js::Shape &child, js::Shape **listp);
16493 static js::Shape *newDictionaryList(JSContext *cx, js::Shape **listp);
16494 inline void removeFromDictionary(JSObject *obj) const;
16495 inline void insertIntoDictionary(js::Shape **dictp);
16496 js::Shape *getChild(JSContext *cx, const js::Shape &child, js::Shape **listp);
16497 bool hashify(JSRuntime *rt);
16498 bool hasTable() const {
16499 return numLinearSearches > PropertyTable::MAX_LINEAR_SEARCHES;
16501 js::PropertyTable *getTable() const {
16505 void setTable(js::PropertyTable *t) const {
16509 void setParent(js::Shape *p) {
16510 typedef int js_static_assert67[(uint32(0xffffffff) == ~uint32(0)) ? 1 : -1];
16512 slotSpan = ((p->slotSpan)>(slot + 1)?(p->slotSpan):(slot + 1));
16516 void insertFree(js::Shape **freep) {
16520 parent->listp = &parent;
16524 void removeFree() {
16528 parent->listp = listp;
16531 const js::Shape *previous() const {
16536 friend struct Shape;
16537 const Shape *cursor;
16540 Range(const Shape *shape) : cursor(shape) { }
16541 bool empty() const {
16543 return !cursor->parent;
16545 const Shape &front() const {
16551 cursor = cursor->parent;
16554 Range all() const {
16555 return Range(this);
16560 SHARED_EMPTY = 0x02,
16561 SHAPE_REGEN = 0x04,
16562 IN_DICTIONARY = 0x08,
16565 Shape(jsid id, js::PropertyOp getter, js::StrictPropertyOp setter, uint32 slot, uintN attrs,
16566 uintN flags, intN shortid, uint32 shape = INVALID_SHAPE, uint32 slotSpan = 0);
16567 Shape(JSCompartment *comp, Class *aclasp);
16568 bool marked() const { return (flags & MARK) != 0; }
16569 void mark() const { flags |= MARK; }
16570 void clearMark() { flags &= ~MARK; }
16571 bool hasRegenFlag() const { return (flags & SHAPE_REGEN) != 0; }
16572 void setRegenFlag() { flags |= SHAPE_REGEN; }
16573 void clearRegenFlag() { flags &= ~SHAPE_REGEN; }
16574 bool inDictionary() const { return (flags & IN_DICTIONARY) != 0; }
16575 bool frozen() const { return (flags & FROZEN) != 0; }
16576 void setFrozen() { flags |= FROZEN; }
16577 bool isEmptyShape() const { ((void) 0); return !parent; }
16581 HAS_SHORTID = 0x40,
16583 PUBLIC_FLAGS = ALIAS | HAS_SHORTID | METHOD
16585 uintN getFlags() const { return flags & PUBLIC_FLAGS; }
16586 bool isAlias() const { return (flags & ALIAS) != 0; }
16587 bool hasShortID() const { return (flags & HAS_SHORTID) != 0; }
16588 bool isMethod() const { return (flags & METHOD) != 0; }
16589 JSObject &methodObject() const { ((void) 0); return *getterObj; }
16590 js::PropertyOp getter() const { return rawGetter; }
16591 bool hasDefaultGetter() const { return !rawGetter; }
16592 js::PropertyOp getterOp() const { ((void) 0); return rawGetter; }
16593 JSObject *getterObject() const { ((void) 0); return getterObj; }
16594 js::Value getterValue() const {
16596 return getterObj ? js::ObjectValue(*getterObj) : js::UndefinedValue();
16598 js::Value getterOrUndefined() const {
16599 return hasGetterValue() && getterObj ? js::ObjectValue(*getterObj) : js::UndefinedValue();
16601 js::StrictPropertyOp setter() const { return rawSetter; }
16602 bool hasDefaultSetter() const { return !rawSetter; }
16603 js::StrictPropertyOp setterOp() const { ((void) 0); return rawSetter; }
16604 JSObject *setterObject() const { ((void) 0); return setterObj; }
16605 js::Value setterValue() const {
16607 return setterObj ? js::ObjectValue(*setterObj) : js::UndefinedValue();
16609 js::Value setterOrUndefined() const {
16610 return hasSetterValue() && setterObj ? js::ObjectValue(*setterObj) : js::UndefinedValue();
16612 inline JSDHashNumber hash() const;
16613 inline bool matches(const js::Shape *p) const;
16614 inline bool matchesParamsAfterId(js::PropertyOp agetter, js::StrictPropertyOp asetter,
16615 uint32 aslot, uintN aattrs, uintN aflags,
16616 intN ashortid) const;
16617 bool get(JSContext* cx, JSObject *receiver, JSObject *obj, JSObject *pobj, js::Value* vp) const;
16618 bool set(JSContext* cx, JSObject *obj, bool strict, js::Value* vp) const;
16619 inline bool isSharedPermanent() const;
16620 void trace(JSTracer *trc) const;
16621 bool hasSlot() const { return (attrs & 0x40) == 0; }
16622 uint8 attributes() const { return attrs; }
16623 bool configurable() const { return (attrs & 0x04) == 0; }
16624 bool enumerable() const { return (attrs & 0x01) != 0; }
16625 bool writable() const {
16626 return (attrs & 0x02) == 0;
16628 bool hasGetterValue() const { return attrs & 0x10; }
16629 bool hasSetterValue() const { return attrs & 0x20; }
16630 bool hasDefaultGetterOrIsMethod() const {
16631 return hasDefaultGetter() || isMethod();
16633 bool isDataDescriptor() const {
16634 return (attrs & (0x20 | 0x10)) == 0;
16636 bool isAccessorDescriptor() const {
16637 return (attrs & (0x20 | 0x10)) != 0;
16639 bool shadowable() const {
16641 return hasSlot() || (attrs & 0x80);
16643 uint32 entryCount() const {
16645 return getTable()->entryCount;
16646 const js::Shape *shape = this;
16648 for (js::Shape::Range r = shape->all(); !r.empty(); r.popFront())
16653 struct EmptyShape : public js::Shape
16655 EmptyShape(JSCompartment *comp, js::Class *aclasp);
16656 js::Class *getClass() const { return clasp; };
16657 static EmptyShape *create(JSCompartment *comp, js::Class *clasp) {
16658 js::Shape *eprop = comp->propertyTree.newShapeUnchecked();
16661 return new (eprop) EmptyShape(comp, clasp);
16663 static EmptyShape *create(JSContext *cx, js::Class *clasp) {
16664 js::Shape *eprop = ((cx)->compartment->propertyTree).newShape(cx);
16667 return new (eprop) EmptyShape(cx->compartment, clasp);
16671 inline js::Shape **
16672 JSObject::nativeSearch(jsid id, bool adding)
16674 return js::Shape::search(compartment()->rt, &lastProp, id, adding);
16676 inline const js::Shape *
16677 JSObject::nativeLookup(jsid id)
16680 return ((js::Shape *) (jsuword(*(nativeSearch(id))) & ~(jsuword(1))));
16684 JSObject::nativeContains(jsid id)
16686 return nativeLookup(id) != __null;
16690 JSObject::nativeContains(const js::Shape &shape)
16692 return nativeLookup(shape.id) == &shape;
16694 inline const js::Shape *
16695 JSObject::lastProperty() const
16703 JSObject::nativeEmpty() const
16705 return lastProperty()->isEmptyShape();
16709 JSObject::inDictionaryMode() const
16711 return lastProperty()->inDictionary();
16714 JSObject::propertyCount() const
16716 return lastProperty()->entryCount();
16720 JSObject::hasPropertyTable() const
16722 return lastProperty()->hasTable();
16725 JSObject::setLastProperty(const js::Shape *shape)
16731 lastProp = const_cast<js::Shape *>(shape);
16734 JSObject::removeLastProperty()
16738 lastProp = lastProp->parent;
16742 Shape::removeFromDictionary(JSObject *obj) const
16754 parent->listp = listp;
16759 Shape::insertIntoDictionary(js::Shape **dictp)
16770 parent->listp = &parent;
16776 js_GenerateShape(JSRuntime *rt);
16778 js_GenerateShape(JSContext *cx);
16780 __attribute__((always_inline)) inline js::Shape **
16781 Shape::search(JSRuntime *rt, js::Shape **startp, jsid id, bool adding)
16783 js::Shape *start = *startp;
16785 if (start->hasTable())
16786 return start->getTable()->search(id, adding);
16787 if (start->numLinearSearches == PropertyTable::MAX_LINEAR_SEARCHES) {
16788 if (start->hashify(rt))
16789 return start->getTable()->search(id, adding);
16793 start->numLinearSearches++;
16796 for (spp = startp; js::Shape *shape = *spp; spp = &shape->parent) {
16797 if (shape->id == id) {
16807 Shape::isSharedPermanent() const
16809 return (~attrs & (0x40 | 0x04)) == 0;
16814 js_ValueToAtom(JSContext *cx, const js::Value &v, JSAtom **atomp)
16818 if (v.isString()) {
16819 str = v.toString();
16820 if (str->isAtomized()) {
16821 *atomp = (((void) 0), (JSAtom *)str);
16825 str = js_ValueToString(cx, v);
16829 atom = js_AtomizeString(cx, str, 0);
16837 js_ValueToStringId(JSContext *cx, const js::Value &v, jsid *idp)
16840 if (js_ValueToAtom(cx, v, &atom)) {
16841 *idp = ATOM_TO_JSID(atom);
16848 js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval,
16852 extern bool js_InternNonIntElementIdSlow(JSContext *, JSObject *,
16853 const js::Value &, jsid *);
16854 if (idval.isObject())
16855 return js_InternNonIntElementIdSlow(cx, obj, idval, idp);
16856 return js_ValueToStringId(cx, idval, idp);
16860 js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval,
16861 jsid *idp, js::Value *vp)
16864 extern bool js_InternNonIntElementIdSlow(JSContext *, JSObject *,
16866 jsid *, js::Value *);
16867 if (idval.isObject())
16868 return js_InternNonIntElementIdSlow(cx, obj, idval, idp, vp);
16870 if (js_ValueToAtom(cx, idval, &atom)) {
16871 *idp = ATOM_TO_JSID(atom);
16872 vp->setString((atom));
16879 js_Int32ToId(JSContext* cx, int32 index, jsid* id)
16881 if (INT_FITS_IN_JSID(index)) {
16882 *id = INT_TO_JSID(index);
16885 JSString* str = js_NumberToString(cx, index);
16888 return js_ValueToStringId(cx, js::StringValue(str), id);
16892 static const char nullName[];
16893 static const char *FunctionClassname(const JSFunction *fun);
16894 static const char *ScriptFilename(JSScript *script);
16895 static int FunctionLineNumber(JSContext *cx, const JSFunction *fun);
16896 static const char *FunctionName(JSContext *cx, const JSFunction *fun, JSAutoByteString *bytes);
16897 static void enterJSFunImpl(JSContext *cx, JSFunction *fun, JSScript *script);
16898 static void handleFunctionReturn(JSContext *cx, JSFunction *fun, JSScript *script);
16899 static void finalizeObjectImpl(JSObject *obj);
16901 static bool callTrackingActive(JSContext *);
16902 static void enterJSFun(JSContext *, JSFunction *, JSScript *, int counter = 1);
16903 static void exitJSFun(JSContext *, JSFunction *, JSScript *, int counter = 0);
16904 static void startExecution(JSContext *cx, JSScript *script);
16905 static void stopExecution(JSContext *cx, JSScript *script);
16906 static void resizeHeap(JSCompartment *compartment, size_t oldSize, size_t newSize);
16907 static void createObject(JSContext *cx, JSObject *obj);
16908 static void resizeObject(JSContext *cx, JSObject *obj, size_t oldSize, size_t newSize);
16909 static void finalizeObject(JSObject *obj);
16910 static void createString(JSContext *cx, JSString *string, size_t length);
16911 static void finalizeString(JSString *string);
16912 static void compileScriptBegin(JSContext *cx, const char *filename, int lineno);
16913 static void compileScriptEnd(JSContext *cx, JSScript *script, const char *filename, int lineno);
16914 static void calloutBegin(JSContext *cx, JSFunction *fun);
16915 static void calloutEnd(JSContext *cx, JSFunction *fun);
16916 static void acquireMemory(JSContext *cx, void *address, size_t nbytes);
16917 static void releaseMemory(JSContext *cx, void *address, size_t nbytes);
16918 static void GCStart(JSCompartment *compartment);
16919 static void GCEnd(JSCompartment *compartment);
16920 static void GCStartMarkPhase(JSCompartment *compartment);
16921 static void GCEndMarkPhase(JSCompartment *compartment);
16922 static void GCStartSweepPhase(JSCompartment *compartment);
16923 static void GCEndSweepPhase(JSCompartment *compartment);
16924 static bool CustomMark(JSString *string);
16925 static bool CustomMark(const char *string);
16926 static bool CustomMark(int marker);
16927 static bool startProfiling();
16928 static void stopProfiling();
16932 Probes::callTrackingActive(JSContext *cx)
16937 Probes::enterJSFun(JSContext *cx, JSFunction *fun, JSScript *script, int counter)
16941 Probes::exitJSFun(JSContext *cx, JSFunction *fun, JSScript *script, int counter)
16945 Probes::createObject(JSContext *cx, JSObject *obj)
16949 Probes::finalizeObject(JSObject *obj)
16953 Probes::startExecution(JSContext *cx, JSScript *script)
16957 Probes::stopExecution(JSContext *cx, JSScript *script)
16960 inline void Probes::resizeHeap(JSCompartment *compartment, size_t oldSize, size_t newSize) {}
16961 inline void Probes::resizeObject(JSContext *cx, JSObject *obj, size_t oldSize, size_t newSize) {}
16962 inline void Probes::createString(JSContext *cx, JSString *string, size_t length) {}
16963 inline void Probes::finalizeString(JSString *string) {}
16964 inline void Probes::compileScriptBegin(JSContext *cx, const char *filename, int lineno) {}
16965 inline void Probes::compileScriptEnd(JSContext *cx, JSScript *script, const char *filename, int lineno) {}
16966 inline void Probes::calloutBegin(JSContext *cx, JSFunction *fun) {}
16967 inline void Probes::calloutEnd(JSContext *cx, JSFunction *fun) {}
16968 inline void Probes::acquireMemory(JSContext *cx, void *address, size_t nbytes) {}
16969 inline void Probes::releaseMemory(JSContext *cx, void *address, size_t nbytes) {}
16970 inline void Probes::GCStart(JSCompartment *compartment) {}
16971 inline void Probes::GCEnd(JSCompartment *compartment) {}
16972 inline void Probes::GCStartMarkPhase(JSCompartment *compartment) {}
16973 inline void Probes::GCEndMarkPhase(JSCompartment *compartment) {}
16974 inline void Probes::GCStartSweepPhase(JSCompartment *compartment) {}
16975 inline void Probes::GCEndSweepPhase(JSCompartment *compartment) {}
16976 inline bool Probes::CustomMark(JSString *string) { return (JSIntn)1; }
16977 inline bool Probes::CustomMark(const char *string) { return (JSIntn)1; }
16978 inline bool Probes::CustomMark(int marker) { return (JSIntn)1; }
16979 struct AutoFunctionCallProbe {
16980 JSContext * const cx;
16984 AutoFunctionCallProbe(JSContext *cx, JSFunction *fun, JSScript *script
16986 : cx(cx), fun(fun), script(script)
16989 Probes::enterJSFun(cx, fun, script);
16991 ~AutoFunctionCallProbe() {
16992 Probes::exitJSFun(cx, fun, script);
16998 JSFunction::inStrictMode() const
17000 return script()->strictModeCode;
17003 JSStackFrame::initPrev(JSContext *cx)
17006 if (JSFrameRegs *regs = cx->regs) {
17008 prevpc_ = regs->pc;
17016 JSStackFrame::resetGeneratorPrev(JSContext *cx)
17018 flags_ |= JSFRAME_HAS_PREVPC;
17022 JSStackFrame::initCallFrame(JSContext *cx, JSObject &callee, JSFunction *fun,
17023 uint32 nactual, uint32 flagsArg)
17028 flags_ = JSFRAME_FUNCTION | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN | flagsArg;
17030 args.nactual = nactual;
17031 scopeChain_ = callee.getParent();
17039 JSStackFrame::resetInvokeCallFrame()
17043 flags_ &= JSFRAME_FUNCTION |
17044 JSFRAME_OVERFLOW_ARGS |
17045 JSFRAME_HAS_PREVPC |
17046 JSFRAME_UNDERFLOW_ARGS;
17048 scopeChain_ = callee().getParent();
17051 JSStackFrame::initCallFrameCallerHalf(JSContext *cx, uint32 flagsArg,
17056 flags_ = JSFRAME_FUNCTION | flagsArg;
17057 prev_ = cx->regs->fp;
17061 JSStackFrame::initCallFrameEarlyPrologue(JSFunction *fun, uint32 nactual)
17064 if (flags_ & (JSFRAME_OVERFLOW_ARGS | JSFRAME_UNDERFLOW_ARGS))
17065 args.nactual = nactual;
17068 JSStackFrame::initCallFrameLatePrologue()
17070 SetValueRangeToUndefined(slots(), script()->nfixed);
17073 JSStackFrame::initEvalFrame(JSContext *cx, JSScript *script, JSStackFrame *prev, uint32 flagsArg)
17078 js::Value *dstvp = (js::Value *)this - 2;
17079 js::Value *srcvp = prev->flags_ & (JSFRAME_GLOBAL | JSFRAME_EVAL)
17080 ? (js::Value *)prev - 2
17081 : prev->formalArgs() - 2;
17082 dstvp[0] = srcvp[0];
17083 dstvp[1] = srcvp[1];
17086 flags_ = flagsArg | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN |
17087 (prev->flags_ & (JSFRAME_FUNCTION | JSFRAME_GLOBAL | JSFRAME_HAS_CALL_OBJ));
17088 if (isFunctionFrame()) {
17090 args.script = script;
17092 exec.script = script;
17094 scopeChain_ = &prev->scopeChain();
17097 prevpc_ = prev->pc(cx);
17100 setAnnotation(prev->annotation());
17103 JSStackFrame::initGlobalFrame(JSScript *script, JSObject &chain, uint32 flagsArg)
17106 js::Value *vp = (js::Value *)this - 2;
17107 vp[0].setUndefined();
17108 vp[1].setUndefined();
17109 flags_ = flagsArg | JSFRAME_GLOBAL | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN;
17110 exec.script = script;
17111 args.script = (JSScript *)0xbad;
17112 scopeChain_ = &chain;
17119 JSStackFrame::initDummyFrame(JSContext *cx, JSObject &chain)
17122 flags_ = JSFRAME_DUMMY | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN;
17125 setScopeChainNoCallObj(chain);
17128 JSStackFrame::stealFrameAndSlots(js::Value *vp, JSStackFrame *otherfp,
17129 js::Value *othervp, js::Value *othersp)
17135 PodCopy(vp, othervp, othersp - othervp);
17137 if (otherfp->hasOverflowArgs())
17138 Debug_SetValueRangeToCrashOnTouch(othervp, othervp + 2 + otherfp->numFormalArgs());
17139 if (hasCallObj()) {
17140 callObj().setPrivate(this);
17141 otherfp->flags_ &= ~JSFRAME_HAS_CALL_OBJ;
17142 if (js_IsNamedLambda(fun())) {
17143 JSObject *env = callObj().getParent();
17145 env->setPrivate(this);
17148 if (hasArgsObj()) {
17149 JSObject &args = argsObj();
17151 if (args.isNormalArguments())
17152 args.setPrivate(this);
17155 otherfp->flags_ &= ~JSFRAME_HAS_ARGS_OBJ;
17159 JSStackFrame::canonicalActualArg(uintN i) const
17161 if (i < numFormalArgs())
17162 return formalArg(i);
17164 return actualArgs()[i];
17166 template <class Op>
17168 JSStackFrame::forEachCanonicalActualArg(Op op)
17170 uintN nformal = fun()->nargs;
17171 js::Value *formals = formalArgsEnd() - nformal;
17172 uintN nactual = numActualArgs();
17173 if (nactual <= nformal) {
17175 js::Value *actualsEnd = formals + nactual;
17176 for (js::Value *p = formals; p != actualsEnd; ++p, ++i)
17180 js::Value *formalsEnd = formalArgsEnd();
17181 for (js::Value *p = formals; p != formalsEnd; ++p, ++i)
17183 js::Value *actuals = formalsEnd - (nactual + 2);
17184 js::Value *actualsEnd = formals - 2;
17185 for (js::Value *p = actuals; p != actualsEnd; ++p, ++i)
17189 template <class Op>
17191 JSStackFrame::forEachFormalArg(Op op)
17193 js::Value *formals = formalArgsEnd() - fun()->nargs;
17194 js::Value *formalsEnd = formalArgsEnd();
17196 for (js::Value *p = formals; p != formalsEnd; ++p, ++i)
17200 struct CopyNonHoleArgsTo
17202 CopyNonHoleArgsTo(JSObject *aobj, Value *dst) : aobj(aobj), dst(dst) {}
17205 void operator()(uintN argi, Value *src) {
17206 if (aobj->getArgsElement(argi).isMagic(JS_ARGS_HOLE))
17207 dst->setUndefined();
17216 CopyTo(Value *dst) : dst(dst) {}
17217 void operator()(uintN, Value *src) {
17222 __attribute__((always_inline)) inline void
17223 JSStackFrame::clearMissingArgs()
17225 if (flags_ & JSFRAME_UNDERFLOW_ARGS)
17226 SetValueRangeToUndefined(formalArgs() + numActualArgs(), formalArgsEnd());
17230 JSStackFrame::computeThis(JSContext *cx)
17232 js::Value &thisv = thisValue();
17233 if (thisv.isObject())
17235 if (isFunctionFrame()) {
17236 if (fun()->inStrictMode())
17240 if (!js::BoxThisForVp(cx, &thisv - 1))
17245 JSStackFrame::varobj(js::StackSegment *seg) const
17248 return isFunctionFrame() ? callObj() : seg->getInitialVarObj();
17251 JSStackFrame::varobj(JSContext *cx) const
17254 return isFunctionFrame() ? callObj() : cx->activeSegment()->getInitialVarObj();
17257 JSStackFrame::numActualArgs() const
17260 if ((__builtin_expect((flags_ & (JSFRAME_OVERFLOW_ARGS | JSFRAME_UNDERFLOW_ARGS)), 0)))
17261 return hasArgsObj() ? argsObj().getArgsInitialLength() : args.nactual;
17262 return numFormalArgs();
17265 JSStackFrame::actualArgs() const
17268 js::Value *argv = formalArgs();
17269 if ((__builtin_expect((flags_ & JSFRAME_OVERFLOW_ARGS), 0))) {
17270 uintN nactual = hasArgsObj() ? argsObj().getArgsInitialLength() : args.nactual;
17271 return argv - (2 + nactual);
17276 JSStackFrame::actualArgsEnd() const
17279 if ((__builtin_expect((flags_ & JSFRAME_OVERFLOW_ARGS), 0)))
17280 return formalArgs() - 2;
17281 return formalArgs() + numActualArgs();
17284 JSStackFrame::setArgsObj(JSObject &obj)
17289 flags_ |= JSFRAME_HAS_ARGS_OBJ;
17292 JSStackFrame::clearArgsObj()
17295 args.nactual = args.obj->getArgsInitialLength();
17296 flags_ ^= JSFRAME_HAS_ARGS_OBJ;
17299 JSStackFrame::setScopeChainNoCallObj(JSObject &obj)
17301 scopeChain_ = &obj;
17302 flags_ |= JSFRAME_HAS_SCOPECHAIN;
17306 JSStackFrame::setScopeChainAndCallObj(JSObject &obj)
17310 scopeChain_ = &obj;
17311 flags_ |= JSFRAME_HAS_SCOPECHAIN | JSFRAME_HAS_CALL_OBJ;
17314 JSStackFrame::clearCallObj()
17317 flags_ ^= JSFRAME_HAS_CALL_OBJ;
17320 JSStackFrame::callObj() const
17323 JSObject *pobj = &scopeChain();
17324 while ((__builtin_expect((pobj->getClass() != &js_CallClass), 0))) {
17326 pobj = pobj->getParent();
17331 JSStackFrame::maybeCallObj() const
17333 return hasCallObj() ? &callObj() : __null;
17336 class AutoPreserveEnumerators {
17338 JSObject *enumerators;
17340 AutoPreserveEnumerators(JSContext *cx) : cx(cx), enumerators(cx->enumerators)
17343 ~AutoPreserveEnumerators()
17345 cx->enumerators = enumerators;
17348 struct AutoInterpPreparer {
17351 AutoInterpPreparer(JSContext *cx, JSScript *script)
17352 : cx(cx), script(script)
17356 ~AutoInterpPreparer()
17362 PutActivationObjects(JSContext *cx, JSStackFrame *fp)
17366 if (fp->hasCallObj()) {
17367 js_PutCallObject(cx, fp);
17368 } else if (fp->hasArgsObj()) {
17369 js_PutArgsObject(cx, fp);
17373 PutOwnedActivationObjects(JSContext *cx, JSStackFrame *fp)
17376 if (!fp->isEvalFrame() || fp->script()->strictModeCode)
17377 PutActivationObjects(cx, fp);
17379 class InvokeSessionGuard
17381 InvokeArgsGuard args_;
17382 InvokeFrameGuard frame_;
17383 Value savedCallee_, savedThis_;
17384 Value *formals_, *actuals_;
17385 unsigned nformals_;
17387 Value *stackLimit_;
17389 bool optimized() const { return frame_.pushed(); }
17391 InvokeSessionGuard() : args_(), frame_() {}
17392 inline ~InvokeSessionGuard();
17393 bool start(JSContext *cx, const Value &callee, const Value &thisv, uintN argc);
17394 bool invoke(JSContext *cx) const;
17395 bool started() const {
17396 return args_.pushed();
17398 Value &operator[](unsigned i) const {
17400 Value &arg = i < nformals_ ? formals_[i] : actuals_[i];
17405 uintN argc() const {
17406 return args_.argc();
17408 const Value &rval() const {
17409 return optimized() ? frame_.fp()->returnValue() : args_.rval();
17413 InvokeSessionGuard::~InvokeSessionGuard()
17415 if (frame_.pushed())
17416 PutActivationObjects(frame_.pushedFrameContext(), frame_.fp());
17420 InvokeSessionGuard::invoke(JSContext *cx) const
17422 formals_[-2] = savedCallee_;
17423 formals_[-1] = savedThis_;
17425 return Invoke(cx, args_, 0);
17426 JSStackFrame *fp = frame_.fp();
17427 fp->clearMissingArgs();
17428 PutActivationObjects(cx, frame_.fp());
17429 fp->resetInvokeCallFrame();
17430 SetValueRangeToUndefined(fp->slots(), script_->nfixed);
17433 AutoPreserveEnumerators preserve(cx);
17434 Probes::enterJSFun(cx, fp->fun(), script_);
17435 cx->regs->pc = script_->code;
17436 ok = Interpret(cx, cx->fp());
17437 Probes::exitJSFun(cx, fp->fun(), script_);
17442 template<typename T> class PrimitiveBehavior { };
17444 class PrimitiveBehavior<JSString *> {
17446 static inline bool isType(const Value &v) { return v.isString(); }
17447 static inline JSString *extract(const Value &v) { return v.toString(); }
17448 static inline Class *getClass() { return &js_StringClass; }
17451 class PrimitiveBehavior<bool> {
17453 static inline bool isType(const Value &v) { return v.isBoolean(); }
17454 static inline bool extract(const Value &v) { return v.toBoolean(); }
17455 static inline Class *getClass() { return &js_BooleanClass; }
17458 class PrimitiveBehavior<double> {
17460 static inline bool isType(const Value &v) { return v.isNumber(); }
17461 static inline double extract(const Value &v) { return v.toNumber(); }
17462 static inline Class *getClass() { return &js_NumberClass; }
17467 ComputeImplicitThis(JSContext *cx, JSObject *obj, const Value &funval, Value *vp)
17469 vp->setUndefined();
17470 if (!funval.isObject())
17472 if (!obj->isGlobal()) {
17473 if (IsCacheableNonGlobalScope(obj))
17476 JSObject *callee = &funval.toObject();
17477 if (callee->isProxy()) {
17478 callee = callee->unwrap();
17479 if (!callee->isFunction())
17482 if (callee->isFunction()) {
17483 JSFunction *fun = callee->getFunctionPrivate();
17484 if (fun->isInterpreted() && fun->inStrictMode())
17487 if (callee->getGlobal() == cx->fp()->scopeChain().getGlobal())
17490 obj = obj->thisObject(cx);
17493 vp->setObject(*obj);
17496 template <typename T>
17498 GetPrimitiveThis(JSContext *cx, Value *vp, T *v)
17500 typedef detail::PrimitiveBehavior<T> Behavior;
17501 const Value &thisv = vp[1];
17502 if (Behavior::isType(thisv)) {
17503 *v = Behavior::extract(thisv);
17506 if (thisv.isObject() && thisv.toObject().getClass() == Behavior::getClass()) {
17507 *v = Behavior::extract(thisv.toObject().getPrimitiveThis());
17510 ReportIncompatibleMethod(cx, vp, Behavior::getClass());
17513 __attribute__((always_inline)) inline JSObject *
17514 ValuePropertyBearer(JSContext *cx, const Value &v, int spindex)
17517 return &v.toObject();
17518 JSProtoKey protoKey;
17519 if (v.isString()) {
17520 protoKey = JSProto_String;
17521 } else if (v.isNumber()) {
17522 protoKey = JSProto_Number;
17523 } else if (v.isBoolean()) {
17524 protoKey = JSProto_Boolean;
17527 js_ReportIsNullOrUndefined(cx, spindex, v, __null);
17531 if (!js_GetClassPrototype(cx, __null, protoKey, &pobj))
17537 ScriptEpilogue(JSContext *cx, JSStackFrame *fp, JSBool ok)
17539 if (!fp->isExecuteFrame())
17540 Probes::exitJSFun(cx, fp->maybeFun(), fp->maybeScript());
17541 JSInterpreterHook hook =
17542 fp->isExecuteFrame() ? cx->debugHooks->executeHook : cx->debugHooks->callHook;
17544 if ((__builtin_expect((hook != __null), 0)) && (hookData = fp->maybeHookData()))
17545 hook(cx, fp, (JSIntn)0, &ok, hookData);
17546 if (fp->isEvalFrame()) {
17547 if (fp->script()->strictModeCode) {
17552 js_PutCallObject(cx, fp);
17555 if (fp->isFunctionFrame() && !fp->isYielding()) {
17557 PutActivationObjects(cx, fp);
17560 if (fp->isConstructing() && ok) {
17561 if (fp->returnValue().isPrimitive())
17562 fp->setReturnValue(ObjectValue(fp->constructorThis()));
17568 extern js::Class js_DateClass;
17571 JSObject::isDate() const
17573 return getClass() == &js_DateClass;
17576 js_InitDateClass(JSContext *cx, JSObject *obj);
17577 extern __attribute__((visibility ("default"))) JSObject*
17578 js_NewDateObjectMsec(JSContext* cx, jsdouble msec_time);
17579 extern __attribute__((visibility ("default"))) JSObject*
17580 js_NewDateObject(JSContext* cx, int year, int mon, int mday,
17581 int hour, int min, int sec);
17582 extern __attribute__((visibility ("default"))) JSBool
17583 js_DateIsValid(JSContext *cx, JSObject* obj);
17584 extern __attribute__((visibility ("default"))) int
17585 js_DateGetYear(JSContext *cx, JSObject* obj);
17586 extern __attribute__((visibility ("default"))) int
17587 js_DateGetMonth(JSContext *cx, JSObject* obj);
17588 extern __attribute__((visibility ("default"))) int
17589 js_DateGetDate(JSContext *cx, JSObject* obj);
17590 extern __attribute__((visibility ("default"))) int
17591 js_DateGetHours(JSContext *cx, JSObject* obj);
17592 extern __attribute__((visibility ("default"))) int
17593 js_DateGetMinutes(JSContext *cx, JSObject* obj);
17594 extern __attribute__((visibility ("default"))) int
17595 js_DateGetSeconds(JSContext *cx, JSObject* obj);
17596 extern __attribute__((visibility ("default"))) jsdouble
17597 js_DateGetMsecSinceEpoch(JSContext *cx, JSObject *obj);
17598 typedef uint32 JSIntervalTime;
17599 extern __attribute__((visibility ("default"))) JSIntervalTime
17602 js_Date(JSContext *cx, uintN argc, js::Value *vp);
17604 struct NativeIterator {
17607 jsid *props_cursor;
17609 uint32 *shapes_array;
17610 uint32 shapes_length;
17614 bool isKeyIter() const { return (flags & 0x2) == 0; }
17615 inline jsid *begin() const {
17616 return props_array;
17618 inline jsid *end() const {
17621 size_t numKeys() const {
17622 return end() - begin();
17624 jsid *current() const {
17626 return props_cursor;
17629 props_cursor = props_cursor + 1;
17631 static NativeIterator *allocateIterator(JSContext *cx, uint32 slength,
17632 const js::AutoIdVector &props);
17633 void init(JSObject *obj, uintN flags, uint32 slength, uint32 key);
17634 void mark(JSTracer *trc);
17637 VectorToIdArray(JSContext *cx, js::AutoIdVector &props, JSIdArray **idap);
17638 __attribute__((visibility ("default"))) bool
17639 GetPropertyNames(JSContext *cx, JSObject *obj, uintN flags, js::AutoIdVector *props);
17641 GetIterator(JSContext *cx, JSObject *obj, uintN flags, js::Value *vp);
17643 VectorToKeyIterator(JSContext *cx, JSObject *obj, uintN flags, js::AutoIdVector &props, js::Value *vp);
17645 VectorToValueIterator(JSContext *cx, JSObject *obj, uintN flags, js::AutoIdVector &props, js::Value *vp);
17647 EnumeratedIdVectorToIterator(JSContext *cx, JSObject *obj, uintN flags, js::AutoIdVector &props, js::Value *vp);
17649 extern __attribute__((visibility ("default"))) JSBool
17650 js_ValueToIterator(JSContext *cx, uintN flags, js::Value *vp);
17651 extern __attribute__((visibility ("default"))) JSBool
17652 js_CloseIterator(JSContext *cx, JSObject *iterObj);
17654 js_SuppressDeletedProperty(JSContext *cx, JSObject *obj, jsid id);
17656 js_SuppressDeletedIndexProperties(JSContext *cx, JSObject *obj, jsint begin, jsint end);
17658 js_IteratorMore(JSContext *cx, JSObject *iterobj, js::Value *rval);
17660 js_IteratorNext(JSContext *cx, JSObject *iterobj, js::Value *rval);
17662 js_ThrowStopIteration(JSContext *cx);
17663 typedef enum JSGeneratorState {
17669 } JSGeneratorState;
17670 struct JSGenerator {
17672 JSGeneratorState state;
17674 JSObject *enumerators;
17675 JSStackFrame *floating;
17676 js::Value floatingStack[1];
17677 JSStackFrame *floatingFrame() {
17680 JSStackFrame *liveFrame() {
17687 js_NewGenerator(JSContext *cx);
17688 inline JSStackFrame *
17689 js_FloatingFrameIfGenerator(JSContext *cx, JSStackFrame *fp)
17692 if ((__builtin_expect((fp->isGeneratorFrame()), 0)))
17693 return cx->generatorFor(fp)->floatingFrame();
17696 extern JSGenerator *
17697 js_FloatingFrameToGenerator(JSStackFrame *fp);
17698 inline JSStackFrame *
17699 js_LiveFrameIfGenerator(JSStackFrame *fp)
17701 return fp->isGeneratorFrame() ? js_FloatingFrameToGenerator(fp)->liveFrame() : fp;
17703 extern js::Class js_GeneratorClass;
17704 extern js::Class js_IteratorClass;
17705 extern js::Class js_StopIterationClass;
17708 js_ValueIsStopIteration(const js::Value &v)
17710 return v.isObject() && v.toObject().getClass() == &js_StopIterationClass;
17713 js_InitIteratorClasses(JSContext *cx, JSObject *obj);
17715 class __attribute__((visibility ("default"))) JSProxyHandler {
17718 explicit JSProxyHandler(void *family);
17719 virtual ~JSProxyHandler();
17720 virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
17721 PropertyDescriptor *desc) = 0;
17722 virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
17723 PropertyDescriptor *desc) = 0;
17724 virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id,
17725 PropertyDescriptor *desc) = 0;
17726 virtual bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, js::AutoIdVector &props) = 0;
17727 virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) = 0;
17728 virtual bool enumerate(JSContext *cx, JSObject *proxy, js::AutoIdVector &props) = 0;
17729 virtual bool fix(JSContext *cx, JSObject *proxy, Value *vp) = 0;
17730 virtual bool has(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
17731 virtual bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
17732 virtual bool get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, js::Value *vp);
17733 virtual bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict,
17735 virtual bool keys(JSContext *cx, JSObject *proxy, js::AutoIdVector &props);
17736 virtual bool iterate(JSContext *cx, JSObject *proxy, uintN flags, js::Value *vp);
17737 virtual bool call(JSContext *cx, JSObject *proxy, uintN argc, js::Value *vp);
17738 virtual bool construct(JSContext *cx, JSObject *proxy,
17739 uintN argc, js::Value *argv, js::Value *rval);
17740 virtual bool hasInstance(JSContext *cx, JSObject *proxy, const js::Value *vp, bool *bp);
17741 virtual JSType typeOf(JSContext *cx, JSObject *proxy);
17742 virtual JSString *obj_toString(JSContext *cx, JSObject *proxy);
17743 virtual JSString *fun_toString(JSContext *cx, JSObject *proxy, uintN indent);
17744 virtual void finalize(JSContext *cx, JSObject *proxy);
17745 virtual void trace(JSTracer *trc, JSObject *proxy);
17746 virtual bool isOuterWindow() {
17749 inline void *family() {
17755 static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
17756 PropertyDescriptor *desc);
17757 static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, Value *vp);
17758 static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
17759 PropertyDescriptor *desc);
17760 static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
17762 static bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc);
17763 static bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, const Value &v);
17764 static bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, js::AutoIdVector &props);
17765 static bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
17766 static bool enumerate(JSContext *cx, JSObject *proxy, js::AutoIdVector &props);
17767 static bool fix(JSContext *cx, JSObject *proxy, Value *vp);
17768 static bool has(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
17769 static bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
17770 static bool get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, Value *vp);
17771 static bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict,
17773 static bool keys(JSContext *cx, JSObject *proxy, js::AutoIdVector &props);
17774 static bool iterate(JSContext *cx, JSObject *proxy, uintN flags, Value *vp);
17775 static bool call(JSContext *cx, JSObject *proxy, uintN argc, js::Value *vp);
17776 static bool construct(JSContext *cx, JSObject *proxy, uintN argc, js::Value *argv, js::Value *rval);
17777 static bool hasInstance(JSContext *cx, JSObject *proxy, const js::Value *vp, bool *bp);
17778 static JSType typeOf(JSContext *cx, JSObject *proxy);
17779 static JSString *obj_toString(JSContext *cx, JSObject *proxy);
17780 static JSString *fun_toString(JSContext *cx, JSObject *proxy, uintN indent);
17782 const uint32 JSSLOT_PROXY_HANDLER = 0;
17783 const uint32 JSSLOT_PROXY_PRIVATE = 1;
17784 const uint32 JSSLOT_PROXY_EXTRA = 2;
17785 const uint32 JSSLOT_PROXY_CALL = 3;
17786 const uint32 JSSLOT_PROXY_CONSTRUCT = 4;
17787 extern __attribute__((visibility ("default"))) js::Class ObjectProxyClass;
17788 extern __attribute__((visibility ("default"))) js::Class FunctionProxyClass;
17789 extern __attribute__((visibility ("default"))) js::Class OuterWindowProxyClass;
17790 extern js::Class CallableObjectClass;
17794 JSObject::isObjectProxy() const
17796 return getClass() == &js::ObjectProxyClass ||
17797 getClass() == &js::OuterWindowProxyClass;
17801 JSObject::isFunctionProxy() const
17803 return getClass() == &js::FunctionProxyClass;
17807 JSObject::isProxy() const
17809 return isObjectProxy() || isFunctionProxy();
17811 inline js::JSProxyHandler *
17812 JSObject::getProxyHandler() const
17815 return (js::JSProxyHandler *) getSlot(js::JSSLOT_PROXY_HANDLER).toPrivate();
17817 inline const js::Value &
17818 JSObject::getProxyPrivate() const
17821 return getSlot(js::JSSLOT_PROXY_PRIVATE);
17824 JSObject::setProxyPrivate(const js::Value &priv)
17827 setSlot(js::JSSLOT_PROXY_PRIVATE, priv);
17829 inline const js::Value &
17830 JSObject::getProxyExtra() const
17833 return getSlot(js::JSSLOT_PROXY_EXTRA);
17836 JSObject::setProxyExtra(const js::Value &extra)
17839 setSlot(js::JSSLOT_PROXY_EXTRA, extra);
17842 __attribute__((visibility ("default"))) JSObject *
17843 NewProxyObject(JSContext *cx, JSProxyHandler *handler, const js::Value &priv,
17844 JSObject *proto, JSObject *parent,
17845 JSObject *call = __null, JSObject *construct = __null);
17846 __attribute__((visibility ("default"))) JSBool
17847 FixProxy(JSContext *cx, JSObject *proxy, JSBool *bp);
17850 extern js::Class js_ProxyClass;
17851 extern __attribute__((visibility ("default"))) JSObject *
17852 js_InitProxyClass(JSContext *cx, JSObject *obj);
17855 js::Shape::freeTable(JSContext *cx)
17858 cx->destroy(getTable());
17862 inline js::EmptyShape *
17863 JSObject::getEmptyShape(JSContext *cx, js::Class *aclasp,
17867 int i = kind - js::gc::FINALIZE_OBJECT0;
17868 if (!emptyShapes) {
17869 emptyShapes = (js::EmptyShape**)
17870 cx->calloc(sizeof(js::EmptyShape*) * js::gc::JS_FINALIZE_OBJECT_LIMIT);
17873 emptyShapes[0] = js::EmptyShape::create(cx, aclasp);
17874 if (!emptyShapes[0]) {
17875 cx->free(emptyShapes);
17876 emptyShapes = __null;
17881 if (!emptyShapes[i]) {
17882 emptyShapes[i] = js::EmptyShape::create(cx, aclasp);
17883 if (!emptyShapes[i])
17886 return emptyShapes[i];
17890 JSObject::canProvideEmptyShape(js::Class *aclasp)
17892 return !emptyShapes || emptyShapes[0]->getClass() == aclasp;
17895 JSObject::updateShape(JSContext *cx)
17898 js::LeaveTraceIfGlobalObject(cx, this);
17900 setOwnShape(js_GenerateShape(cx));
17902 objShape = lastProp->shape;
17905 JSObject::updateFlags(const js::Shape *shape, bool isDefinitelyAtom)
17908 if (!isDefinitelyAtom && js_IdIsIndex(shape->id, &index))
17910 if (shape->isMethod())
17911 setMethodBarrier();
17914 JSObject::extend(JSContext *cx, const js::Shape *shape, bool isDefinitelyAtom)
17916 setLastProperty(shape);
17917 updateFlags(shape, isDefinitelyAtom);
17921 JSObject::trace(JSTracer *trc)
17925 JSContext *cx = trc->context;
17926 js::Shape *shape = lastProp;
17927 if (((trc)->callback == __null) && cx->runtime->gcRegenShapes) {
17928 if (!shape->hasRegenFlag()) {
17929 shape->shape = js_RegenerateShapeForGC(cx->runtime);
17930 shape->setRegenFlag();
17932 uint32 newShape = shape->shape;
17933 if (hasOwnShape()) {
17934 newShape = js_RegenerateShapeForGC(cx->runtime);
17937 objShape = newShape;
17941 } while ((shape = shape->parent) != __null);
17945 Shape::Shape(jsid id, js::PropertyOp getter, js::StrictPropertyOp setter, uint32 slot, uintN attrs,
17946 uintN flags, intN shortid, uint32 shape, uint32 slotSpan)
17947 : JSObjectMap(shape, slotSpan),
17948 numLinearSearches(0), id(id), rawGetter(getter), rawSetter(setter), slot(slot),
17949 attrs(uint8(attrs)), flags(uint8(flags)), shortid(int16(shortid)), parent(__null)
17957 Shape::Shape(JSCompartment *comp, Class *aclasp)
17958 : JSObjectMap(js_GenerateShape(comp->rt), (((aclasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1))),
17959 numLinearSearches(0),
17965 flags(SHARED_EMPTY),
17971 inline JSDHashNumber
17972 Shape::hash() const
17974 JSDHashNumber hash = 0;
17977 hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ jsuword(rawGetter);
17979 hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ jsuword(rawSetter);
17980 hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ (flags & PUBLIC_FLAGS);
17981 hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ attrs;
17982 hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ shortid;
17983 hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ slot;
17984 hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ (id);
17989 Shape::matches(const js::Shape *other) const
17993 return id == other->id &&
17994 matchesParamsAfterId(other->rawGetter, other->rawSetter, other->slot, other->attrs,
17995 other->flags, other->shortid);
17999 Shape::matchesParamsAfterId(js::PropertyOp agetter, js::StrictPropertyOp asetter, uint32 aslot,
18000 uintN aattrs, uintN aflags, intN ashortid) const
18003 return rawGetter == agetter &&
18004 rawSetter == asetter &&
18007 ((flags ^ aflags) & PUBLIC_FLAGS) == 0 &&
18008 shortid == ashortid;
18012 Shape::get(JSContext* cx, JSObject *receiver, JSObject* obj, JSObject *pobj, js::Value* vp) const
18016 if (hasGetterValue()) {
18018 js::Value fval = getterValue();
18019 return js::ExternalGetOrSet(cx, receiver, id, fval, JSACC_READ, 0, 0, vp);
18022 vp->setObject(methodObject());
18023 return pobj->methodReadBarrier(cx, *this, vp);
18025 if (obj->getClass() == &js_WithClass)
18026 obj = js_UnwrapWithObject(cx, obj);
18027 return js::CallJSPropertyOp(cx, getterOp(), obj, ((this)->hasShortID() ? INT_TO_JSID((this)->shortid) : (this)->id), vp);
18031 Shape::set(JSContext* cx, JSObject* obj, bool strict, js::Value* vp) const
18034 if (attrs & 0x20) {
18035 js::Value fval = setterValue();
18036 return js::ExternalGetOrSet(cx, obj, id, fval, JSACC_WRITE, 1, vp, vp);
18039 return js_ReportGetterOnlyAssignment(cx);
18040 if (obj->getClass() == &js_WithClass)
18041 obj = js_UnwrapWithObject(cx, obj);
18042 return js::CallJSPropertyOpSetter(cx, setterOp(), obj, ((this)->hasShortID() ? INT_TO_JSID((this)->shortid) : (this)->id), strict, vp);
18045 EmptyShape::EmptyShape(JSCompartment *comp, js::Class *aclasp)
18046 : js::Shape(comp, aclasp)
18052 const size_t SLOTS_TO_THING_KIND_LIMIT = 17;
18053 static inline FinalizeKind
18054 GetGCObjectKind(size_t numSlots)
18056 extern FinalizeKind slotsToThingKind[];
18057 if (numSlots >= SLOTS_TO_THING_KIND_LIMIT)
18058 return FINALIZE_OBJECT0;
18059 return slotsToThingKind[numSlots];
18061 static inline size_t
18062 GetGCKindSlots(FinalizeKind thingKind)
18064 switch (thingKind) {
18065 case FINALIZE_OBJECT0:
18067 case FINALIZE_OBJECT2:
18069 case FINALIZE_OBJECT4:
18071 case FINALIZE_OBJECT8:
18073 case FINALIZE_OBJECT12:
18075 case FINALIZE_OBJECT16:
18084 template <typename T>
18085 __attribute__((always_inline)) inline T *
18086 NewFinalizableGCThing(JSContext *cx, unsigned thingKind)
18093 js::gc::FreeCell *cell = cx->compartment->freeLists.getNext(thingKind);
18095 CheckGCFreeListLink(cell);
18098 if (!RefillFinalizableFreeList(cx, thingKind))
18103 js_NewGCObject(JSContext *cx, js::gc::FinalizeKind kind)
18106 JSObject *obj = NewFinalizableGCThing<JSObject>(cx, kind);
18108 obj->capacity = js::gc::GetGCKindSlots(kind);
18112 js_NewGCString(JSContext *cx)
18114 return NewFinalizableGCThing<JSString>(cx, js::gc::FINALIZE_STRING);
18116 inline JSShortString *
18117 js_NewGCShortString(JSContext *cx)
18119 return NewFinalizableGCThing<JSShortString>(cx, js::gc::FINALIZE_SHORT_STRING);
18121 inline JSExternalString *
18122 js_NewGCExternalString(JSContext *cx, uintN type)
18125 JSExternalString *str = NewFinalizableGCThing<JSExternalString>(cx, js::gc::FINALIZE_EXTERNAL_STRING);
18129 js_NewGCFunction(JSContext *cx)
18131 JSFunction *fun = NewFinalizableGCThing<JSFunction>(cx, js::gc::FINALIZE_FUNCTION);
18133 fun->capacity = JSObject::FUN_CLASS_RESERVED_SLOTS;
18137 js_NewGCXML(JSContext *cx)
18139 return NewFinalizableGCThing<JSXML>(cx, js::gc::FINALIZE_XML);
18143 static __attribute__((always_inline)) inline void
18144 TypedMarker(JSTracer *trc, JSXML *thing);
18145 static __attribute__((always_inline)) inline void
18146 TypedMarker(JSTracer *trc, JSObject *thing);
18147 static __attribute__((always_inline)) inline void
18148 TypedMarker(JSTracer *trc, JSFunction *thing);
18149 static __attribute__((always_inline)) inline void
18150 TypedMarker(JSTracer *trc, JSShortString *thing);
18151 static __attribute__((always_inline)) inline void
18152 TypedMarker(JSTracer *trc, JSString *thing);
18153 template<typename T>
18154 static __attribute__((always_inline)) inline void
18155 Mark(JSTracer *trc, T *thing)
18161 JSRuntime *rt = trc->context->runtime;
18162 if (rt->gcCurrentCompartment && thing->asCell()->compartment() != rt->gcCurrentCompartment)
18164 if (!((trc)->callback == __null)) {
18165 uint32 kind = GetGCThingTraceKind(thing);
18166 trc->callback(trc, thing, kind);
18169 TypedMarker(trc, thing);
18174 MarkString(JSTracer *trc, JSString *str)
18177 if (JSString::isStatic(str))
18183 MarkString(JSTracer *trc, JSString *str, const char *name)
18187 MarkString(trc, str);
18190 MarkObject(JSTracer *trc, JSObject &obj, const char *name)
18200 MarkChildren(JSTracer *trc, JSObject *obj)
18204 if (JSObject *proto = obj->getProto())
18205 MarkObject(trc, *proto, "proto");
18206 if (JSObject *parent = obj->getParent())
18207 MarkObject(trc, *parent, "parent");
18208 if (obj->emptyShapes) {
18209 int count = FINALIZE_OBJECT_LAST - FINALIZE_OBJECT0 + 1;
18210 for (int i = 0; i < count; i++) {
18211 if (obj->emptyShapes[i])
18212 obj->emptyShapes[i]->trace(trc);
18215 TraceOp op = obj->getOps()->trace;
18216 (op ? op : js_TraceObject)(trc, obj);
18219 MarkChildren(JSTracer *trc, JSString *str)
18221 if (str->isDependent())
18222 MarkString(trc, str->dependentBase(), "base");
18223 else if (str->isRope()) {
18224 MarkString(trc, str->ropeLeft(), "left child");
18225 MarkString(trc, str->ropeRight(), "right child");
18229 MarkChildren(JSTracer *trc, JSXML *xml)
18231 js_TraceXML(trc, xml);
18235 RecursionTooDeep(GCMarker *gcmarker) {
18237 return !((jsuword)(&stackDummy) > gcmarker->stackLimit);
18239 static __attribute__((always_inline)) inline void
18240 TypedMarker(JSTracer *trc, JSXML *thing)
18242 if (!reinterpret_cast<Cell *>(thing)->markIfUnmarked(reinterpret_cast<GCMarker *>(trc)->getMarkColor()))
18244 GCMarker *gcmarker = static_cast<GCMarker *>(trc);
18245 if (RecursionTooDeep(gcmarker)) {
18246 gcmarker->delayMarkingChildren(thing);
18248 MarkChildren(trc, thing);
18251 static __attribute__((always_inline)) inline void
18252 TypedMarker(JSTracer *trc, JSObject *thing)
18256 GCMarker *gcmarker = static_cast<GCMarker *>(trc);
18257 if (!thing->markIfUnmarked(gcmarker->getMarkColor()))
18259 if (RecursionTooDeep(gcmarker)) {
18260 gcmarker->delayMarkingChildren(thing);
18262 MarkChildren(trc, thing);
18265 static __attribute__((always_inline)) inline void
18266 TypedMarker(JSTracer *trc, JSFunction *thing)
18270 GCMarker *gcmarker = static_cast<GCMarker *>(trc);
18271 if (!thing->markIfUnmarked(gcmarker->getMarkColor()))
18273 if (RecursionTooDeep(gcmarker)) {
18274 gcmarker->delayMarkingChildren(thing);
18276 MarkChildren(trc, static_cast<JSObject *>(thing));
18279 static __attribute__((always_inline)) inline void
18280 TypedMarker(JSTracer *trc, JSShortString *thing)
18282 (void) thing->asCell()->markIfUnmarked();
18286 static __attribute__((always_inline)) inline JSString *
18290 return (JSString *)(size_t(str) | 1);
18292 static __attribute__((always_inline)) inline
18294 Tagged(JSString *str)
18296 return (size_t(str) & 1) != 0;
18298 static __attribute__((always_inline)) inline JSString *
18299 Untag(JSString *str)
18302 return (JSString *)(size_t(str) & ~size_t(1));
18304 static __attribute__((always_inline)) inline void
18305 NonRopeTypedMarker(JSRuntime *rt, JSString *str)
18308 if (rt->gcCurrentCompartment) {
18310 if (JSString::isStatic(str))
18312 if (str->asCell()->compartment() != rt->gcCurrentCompartment) {
18316 if (!str->asCell()->markIfUnmarked())
18318 if (!str->isDependent())
18320 str = str->dependentBase();
18323 while (!JSString::isStatic(str) &&
18324 str->asCell()->markIfUnmarked() &&
18325 str->isDependent()) {
18326 str = str->dependentBase();
18332 static __attribute__((always_inline)) inline void
18333 TypedMarker(JSTracer *trc, JSString *str)
18335 using namespace detail;
18336 JSRuntime *rt = trc->context->runtime;
18338 if (!str->isRope()) {
18339 NonRopeTypedMarker(rt, str);
18342 JSString *parent = __null;
18343 first_visit_node: {
18346 if (!str->asCell()->markIfUnmarked())
18348 JSString *left = str->ropeLeft();
18349 if (left->isRope()) {
18351 str->u.left = Tag(parent);
18354 goto first_visit_node;
18358 NonRopeTypedMarker(rt, left);
18360 visit_right_child: {
18361 JSString *right = str->ropeRight();
18362 if (right->isRope()) {
18364 str->s.right = Tag(parent);
18367 goto first_visit_node;
18371 NonRopeTypedMarker(rt, right);
18376 if (Tagged(parent->u.left)) {
18378 JSString *nextParent = Untag(parent->u.left);
18379 parent->u.left = str;
18381 parent = nextParent;
18382 goto visit_right_child;
18385 JSString *nextParent = Untag(parent->s.right);
18386 parent->s.right = str;
18388 parent = nextParent;
18393 MarkAtomRange(JSTracer *trc, size_t len, JSAtom **vec, const char *name)
18395 for (uint32 i = 0; i < len; i++) {
18396 if (JSAtom *atom = vec[i]) {
18398 JSString *str = (atom);
18399 if (!JSString::isStatic(str))
18405 MarkObjectRange(JSTracer *trc, size_t len, JSObject **vec, const char *name)
18407 for (uint32 i = 0; i < len; i++) {
18408 if (JSObject *obj = vec[i]) {
18415 MarkId(JSTracer *trc, jsid id)
18417 if (JSID_IS_STRING(id)) {
18418 JSString *str = JSID_TO_STRING(id);
18419 if (!JSString::isStatic(str))
18422 else if ((__builtin_expect((JSID_IS_OBJECT(id)), 0)))
18423 Mark(trc, JSID_TO_OBJECT(id));
18426 MarkId(JSTracer *trc, jsid id, const char *name)
18432 MarkIdRange(JSTracer *trc, jsid *beg, jsid *end, const char *name)
18434 for (jsid *idp = beg; idp != end; ++idp) {
18440 MarkIdRange(JSTracer *trc, size_t len, jsid *vec, const char *name)
18442 MarkIdRange(trc, vec, vec + len, name);
18445 MarkKind(JSTracer *trc, void *thing, uint32 kind)
18451 Mark(trc, reinterpret_cast<JSObject *>(thing));
18454 MarkString(trc, reinterpret_cast<JSString *>(thing));
18457 Mark(trc, reinterpret_cast<JSXML *>(thing));
18464 MarkValueRaw(JSTracer *trc, const js::Value &v)
18466 if (v.isMarkable()) {
18468 return MarkKind(trc, v.toGCThing(), v.gcKind());
18472 MarkValue(JSTracer *trc, const js::Value &v, const char *name)
18475 MarkValueRaw(trc, v);
18478 MarkValueRange(JSTracer *trc, Value *beg, Value *end, const char *name)
18480 for (Value *vp = beg; vp < end; ++vp) {
18482 MarkValueRaw(trc, *vp);
18486 MarkValueRange(JSTracer *trc, size_t len, Value *vec, const char *name)
18488 MarkValueRange(trc, vec, vec + len, name);
18491 MarkShapeRange(JSTracer *trc, const Shape **beg, const Shape **end, const char *name)
18493 for (const Shape **sp = beg; sp < end; ++sp) {
18499 MarkShapeRange(JSTracer *trc, size_t len, const Shape **vec, const char *name)
18501 MarkShapeRange(trc, vec, vec + len, name);
18504 MarkGCThing(JSTracer *trc, void *thing, uint32 kind)
18508 MarkKind(trc, thing, kind);
18511 MarkGCThing(JSTracer *trc, void *thing)
18515 MarkKind(trc, thing, GetGCThingTraceKind(thing));
18518 MarkGCThing(JSTracer *trc, void *thing, const char *name)
18521 MarkGCThing(trc, thing);
18524 MarkGCThing(JSTracer *trc, void *thing, const char *name, size_t index)
18527 MarkGCThing(trc, thing);
18530 Mark(JSTracer *trc, void *thing, uint32 kind, const char *name)
18534 MarkKind(trc, thing, kind);
18539 JSObject::preventExtensions(JSContext *cx, js::AutoIdVector *props)
18542 if (js::FixOp fix = getOps()->fix) {
18544 if (!fix(cx, this, &success, props))
18547 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_CANT_CHANGE_EXTENSIBILITY);
18551 if (!GetPropertyNames(cx, this, 0x10 | 0x8, props))
18555 extensibleShapeChange(cx);
18556 flags |= NOT_EXTENSIBLE;
18561 JSObject::brand(JSContext *cx)
18566 generateOwnShape(cx);
18567 if (js_IsPropertyCacheDisabled(cx))
18574 JSObject::unbrand(JSContext *cx)
18578 generateOwnShape(cx);
18579 if (js_IsPropertyCacheDisabled(cx))
18587 JSObject::syncSpecialEquality()
18589 if (clasp->ext.equality)
18590 flags |= JSObject::HAS_EQUALITY;
18593 JSObject::finalize(JSContext *cx)
18597 js::Class *clasp = getClass();
18598 if (clasp->finalize)
18599 clasp->finalize(cx, this);
18600 js::Probes::finalizeObject(this);
18603 inline const js::Shape *
18604 JSObject::methodReadBarrier(JSContext *cx, const js::Shape &shape, js::Value *vp)
18615 JSObject *funobj = &vp->toObject();
18616 JSFunction *fun = funobj->getFunctionPrivate();
18619 funobj = CloneFunctionObject(cx, fun, funobj->getParent());
18622 funobj->setMethodObj(*this);
18623 uint32 slot = shape.slot;
18624 const js::Shape *newshape = methodShapeChange(cx, shape);
18629 vp->setObject(*funobj);
18630 nativeSetSlot(slot, *vp);
18633 static __attribute__((always_inline)) inline
18635 ChangesMethodValue(const js::Value &prev, const js::Value &v)
18638 return prev.isObject() && (prevObj = &prev.toObject())->isFunction() &&
18639 (!v.isObject() || &v.toObject() != prevObj);
18641 inline const js::Shape *
18642 JSObject::methodWriteBarrier(JSContext *cx, const js::Shape &shape, const js::Value &v)
18644 if (brandedOrHasMethodBarrier() && shape.slot != 0xffffffff) {
18645 const js::Value &prev = nativeGetSlot(shape.slot);
18646 if (ChangesMethodValue(prev, v)) {
18648 return methodShapeChange(cx, shape);
18655 JSObject::methodWriteBarrier(JSContext *cx, uint32 slot, const js::Value &v)
18657 if (brandedOrHasMethodBarrier()) {
18658 const js::Value &prev = nativeGetSlot(slot);
18659 if (ChangesMethodValue(prev, v)) {
18661 return methodShapeChange(cx, slot);
18668 JSObject::ensureClassReservedSlots(JSContext *cx)
18670 return !nativeEmpty() || ensureClassReservedSlotsForEmptyObject(cx);
18673 JSObject::getReservedSlot(uintN index) const
18675 return (index < numSlots()) ? getSlot(index) : js::UndefinedValue();
18679 JSObject::canHaveMethodBarrier() const
18681 return isObject() || isFunction() || isPrimitive() || isDate();
18685 JSObject::isPrimitive() const
18687 return isNumber() || isString() || isBoolean();
18689 inline const js::Value &
18690 JSObject::getPrimitiveThis() const
18693 return getSlot(JSSLOT_PRIMITIVE_THIS);
18696 JSObject::setPrimitiveThis(const js::Value &pthis)
18699 setSlot(JSSLOT_PRIMITIVE_THIS, pthis);
18702 JSObject::finalizeKind() const
18704 return js::gc::FinalizeKind(arena()->header()->thingKind);
18707 JSObject::numFixedSlots() const
18710 return JSObject::FUN_CLASS_RESERVED_SLOTS;
18711 if (!hasSlotsArray())
18713 return js::gc::GetGCKindSlots(js::gc::FinalizeKind(finalizeKind()));
18716 JSObject::slotsAndStructSize(uint32 nslots) const
18718 bool isFun = isFunction() && this == (JSObject*) getPrivate();
18719 int ndslots = hasSlotsArray() ? nslots : 0;
18720 int nfslots = isFun ? 0 : numFixedSlots();
18721 return sizeof(js::Value) * (ndslots + nfslots)
18722 + isFun ? sizeof(JSFunction) : sizeof(JSObject);
18725 JSObject::getArrayLength() const
18728 return (uint32)(size_t) getPrivate();
18731 JSObject::setArrayLength(uint32 length)
18734 setPrivate((void*) length);
18737 JSObject::getDenseArrayCapacity()
18743 JSObject::getDenseArrayElements()
18748 inline const js::Value &
18749 JSObject::getDenseArrayElement(uintN idx)
18752 return getSlot(idx);
18755 JSObject::addressOfDenseArrayElement(uintN idx)
18758 return &getSlotRef(idx);
18761 JSObject::setDenseArrayElement(uintN idx, const js::Value &val)
18767 JSObject::shrinkDenseArrayElements(JSContext *cx, uintN cap)
18770 shrinkSlots(cx, cap);
18773 JSObject::setArgsLength(uint32 argc)
18778 getSlotRef(JSSLOT_ARGS_LENGTH).setInt32(argc << ARGS_PACKED_BITS_COUNT);
18782 JSObject::getArgsInitialLength() const
18785 uint32 argc = uint32(getSlot(JSSLOT_ARGS_LENGTH).toInt32()) >> ARGS_PACKED_BITS_COUNT;
18790 JSObject::setArgsLengthOverridden()
18793 getSlotRef(JSSLOT_ARGS_LENGTH).getInt32Ref() |= ARGS_LENGTH_OVERRIDDEN_BIT;
18797 JSObject::isArgsLengthOverridden() const
18800 const js::Value &v = getSlot(JSSLOT_ARGS_LENGTH);
18801 return v.toInt32() & ARGS_LENGTH_OVERRIDDEN_BIT;
18803 inline js::ArgumentsData *
18804 JSObject::getArgsData() const
18807 return (js::ArgumentsData *) getSlot(JSSLOT_ARGS_DATA).toPrivate();
18810 JSObject::setArgsData(js::ArgumentsData *data)
18813 getSlotRef(JSSLOT_ARGS_DATA).setPrivate(data);
18815 inline const js::Value &
18816 JSObject::getArgsCallee() const
18818 return getArgsData()->callee;
18821 JSObject::setArgsCallee(const js::Value &callee)
18823 getArgsData()->callee = callee;
18825 inline const js::Value &
18826 JSObject::getArgsElement(uint32 i) const
18830 return getArgsData()->slots[i];
18833 JSObject::getArgsElements() const
18836 return getArgsData()->slots;
18839 JSObject::addressOfArgsElement(uint32 i)
18843 return &getArgsData()->slots[i];
18846 JSObject::setArgsElement(uint32 i, const js::Value &v)
18850 getArgsData()->slots[i] = v;
18854 JSObject::callIsForEval() const
18860 return getSlot(JSSLOT_CALL_CALLEE).isNull();
18862 inline JSStackFrame *
18863 JSObject::maybeCallObjStackFrame() const
18866 return reinterpret_cast<JSStackFrame *>(getPrivate());
18869 JSObject::setCallObjCallee(JSObject *callee)
18873 return getSlotRef(JSSLOT_CALL_CALLEE).setObjectOrNull(callee);
18876 JSObject::getCallObjCallee() const
18879 return getSlot(JSSLOT_CALL_CALLEE).toObjectOrNull();
18881 inline JSFunction *
18882 JSObject::getCallObjCalleeFunction() const
18885 return getSlot(JSSLOT_CALL_CALLEE).toObject().getFunctionPrivate();
18887 inline const js::Value &
18888 JSObject::getCallObjArguments() const
18892 return getSlot(JSSLOT_CALL_ARGUMENTS);
18895 JSObject::setCallObjArguments(const js::Value &v)
18899 setSlot(JSSLOT_CALL_ARGUMENTS, v);
18901 inline const js::Value &
18902 JSObject::callObjArg(uintN i) const
18906 return getSlot(JSObject::CALL_RESERVED_SLOTS + i);
18909 JSObject::callObjArg(uintN i)
18913 return getSlotRef(JSObject::CALL_RESERVED_SLOTS + i);
18915 inline const js::Value &
18916 JSObject::callObjVar(uintN i) const
18918 JSFunction *fun = getCallObjCalleeFunction();
18921 return getSlot(JSObject::CALL_RESERVED_SLOTS + fun->nargs + i);
18924 JSObject::callObjVar(uintN i)
18926 JSFunction *fun = getCallObjCalleeFunction();
18929 return getSlotRef(JSObject::CALL_RESERVED_SLOTS + fun->nargs + i);
18931 inline const js::Value &
18932 JSObject::getDateUTCTime() const
18935 return getSlot(JSSLOT_DATE_UTC_TIME);
18938 JSObject::setDateUTCTime(const js::Value &time)
18941 setSlot(JSSLOT_DATE_UTC_TIME, time);
18944 JSObject::getFlatClosureUpvars() const
18946 return (js::Value *) getSlot(JSSLOT_FLAT_CLOSURE_UPVARS).toPrivate();
18949 JSObject::getFlatClosureUpvar(uint32 i) const
18952 return getFlatClosureUpvars()[i];
18955 JSObject::getFlatClosureUpvar(uint32 i)
18958 return getFlatClosureUpvars()[i];
18961 JSObject::setFlatClosureUpvars(js::Value *upvars)
18965 getSlotRef(JSSLOT_FLAT_CLOSURE_UPVARS).setPrivate(upvars);
18969 JSObject::hasMethodObj(const JSObject& obj) const
18971 return JSSLOT_FUN_METHOD_OBJ < numSlots() &&
18972 getSlot(JSSLOT_FUN_METHOD_OBJ).isObject() &&
18973 &getSlot(JSSLOT_FUN_METHOD_OBJ).toObject() == &obj;
18976 JSObject::setMethodObj(JSObject& obj)
18978 getSlotRef(JSSLOT_FUN_METHOD_OBJ).setObject(obj);
18980 inline js::NativeIterator *
18981 JSObject::getNativeIterator() const
18983 return (js::NativeIterator *) getPrivate();
18986 JSObject::setNativeIterator(js::NativeIterator *ni)
18990 inline JSLinearString *
18991 JSObject::getNamePrefix() const
18994 const js::Value &v = getSlot(JSSLOT_NAME_PREFIX);
18995 return !v.isUndefined() ? v.toString()->assertIsLinear() : __null;
18998 JSObject::getNamePrefixVal() const
19001 return js::Jsvalify(getSlot(JSSLOT_NAME_PREFIX));
19004 JSObject::setNamePrefix(JSLinearString *prefix)
19007 setSlot(JSSLOT_NAME_PREFIX, prefix ? js::StringValue(prefix) : js::UndefinedValue());
19010 JSObject::clearNamePrefix()
19013 setSlot(JSSLOT_NAME_PREFIX, js::UndefinedValue());
19015 inline JSLinearString *
19016 JSObject::getNameURI() const
19019 const js::Value &v = getSlot(JSSLOT_NAME_URI);
19020 return !v.isUndefined() ? v.toString()->assertIsLinear() : __null;
19023 JSObject::getNameURIVal() const
19026 return js::Jsvalify(getSlot(JSSLOT_NAME_URI));
19029 JSObject::setNameURI(JSLinearString *uri)
19032 setSlot(JSSLOT_NAME_URI, uri ? js::StringValue(uri) : js::UndefinedValue());
19035 JSObject::getNamespaceDeclared() const
19038 return js::Jsvalify(getSlot(JSSLOT_NAMESPACE_DECLARED));
19041 JSObject::setNamespaceDeclared(jsval decl)
19044 setSlot(JSSLOT_NAMESPACE_DECLARED, js::Valueify(decl));
19046 inline JSLinearString *
19047 JSObject::getQNameLocalName() const
19050 const js::Value &v = getSlot(JSSLOT_QNAME_LOCAL_NAME);
19051 return !v.isUndefined() ? v.toString()->assertIsLinear() : __null;
19054 JSObject::getQNameLocalNameVal() const
19057 return js::Jsvalify(getSlot(JSSLOT_QNAME_LOCAL_NAME));
19060 JSObject::setQNameLocalName(JSLinearString *name)
19063 setSlot(JSSLOT_QNAME_LOCAL_NAME, name ? js::StringValue(name) : js::UndefinedValue());
19066 JSObject::getWithThis() const
19068 return &getSlot(JSSLOT_WITH_THIS).toObject();
19071 JSObject::setWithThis(JSObject *thisp)
19073 getSlotRef(JSSLOT_WITH_THIS).setObject(*thisp);
19076 JSObject::init(JSContext *cx, js::Class *aclasp, JSObject *proto, JSObject *parent,
19077 void *priv, bool useHoles)
19083 privateData = priv;
19084 slots = fixedSlots();
19086 ClearValueRange(slots, capacity, useHoles);
19087 emptyShapes = __null;
19090 JSObject::finish(JSContext *cx)
19092 if (hasSlotsArray())
19093 freeSlotsArray(cx);
19095 cx->free(emptyShapes);
19099 JSObject::initSharingEmptyShape(JSContext *cx,
19103 void *privateValue,
19106 init(cx, aclasp, proto, parent, privateValue, false);
19108 js::EmptyShape *empty = proto->getEmptyShape(cx, aclasp, kind);
19115 JSObject::freeSlotsArray(JSContext *cx)
19121 JSObject::revertToFixedSlots(JSContext *cx)
19124 size_t fixed = numFixedSlots();
19126 memcpy(fixedSlots(), slots, fixed * sizeof(js::Value));
19127 freeSlotsArray(cx);
19128 slots = fixedSlots();
19133 JSObject::hasProperty(JSContext *cx, jsid id, bool *foundp, uintN flags)
19137 JSAutoResolveFlags rf(cx, flags);
19138 if (!lookupProperty(cx, id, &pobj, &prop))
19145 JSObject::isCallable()
19147 return isFunction() || getClass()->call;
19151 js_IsCallable(const js::Value &v)
19153 return v.isObject() && v.toObject().isCallable();
19156 class AutoPropDescArrayRooter : private AutoGCRooter
19159 AutoPropDescArrayRooter(JSContext *cx)
19160 : AutoGCRooter(cx, DESCRIPTORS), descriptors(cx)
19162 PropDesc *append() {
19163 if (!descriptors.append(PropDesc()))
19165 return &descriptors.back();
19167 PropDesc& operator[](size_t i) {
19169 return descriptors[i];
19171 friend void AutoGCRooter::trace(JSTracer *trc);
19173 PropDescArray descriptors;
19175 class AutoPropertyDescriptorRooter : private AutoGCRooter, public PropertyDescriptor
19178 AutoPropertyDescriptorRooter(JSContext *cx) : AutoGCRooter(cx, DESCRIPTOR) {
19181 getter = (PropertyOp) __null;
19182 setter = (StrictPropertyOp) __null;
19183 value.setUndefined();
19185 AutoPropertyDescriptorRooter(JSContext *cx, PropertyDescriptor *desc)
19186 : AutoGCRooter(cx, DESCRIPTOR)
19189 attrs = desc->attrs;
19190 getter = desc->getter;
19191 setter = desc->setter;
19192 value = desc->value;
19194 friend void AutoGCRooter::trace(JSTracer *trc);
19198 InitScopeForObject(JSContext* cx, JSObject* obj, js::Class *clasp, JSObject* proto,
19199 gc::FinalizeKind kind)
19203 js::EmptyShape *empty = __null;
19205 if (proto->canProvideEmptyShape(clasp)) {
19206 empty = proto->getEmptyShape(cx, clasp, kind);
19212 empty = js::EmptyShape::create(cx, clasp);
19215 uint32 freeslot = (((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1));
19216 if (freeslot > obj->numSlots() && !obj->allocSlots(cx, freeslot))
19219 obj->setMap(empty);
19225 static inline JSObject *
19226 NewNativeClassInstance(JSContext *cx, Class *clasp, JSObject *proto,
19227 JSObject *parent, gc::FinalizeKind kind)
19231 JSObject* obj = js_NewGCObject(cx, kind);
19233 bool useHoles = (clasp == &js_ArrayClass);
19234 obj->init(cx, clasp, proto, parent, __null, useHoles);
19236 js::EmptyShape *empty = proto->getEmptyShape(cx, clasp, kind);
19238 obj->setMap(empty);
19244 static inline JSObject *
19245 NewNativeClassInstance(JSContext *cx, Class *clasp, JSObject *proto, JSObject *parent)
19247 gc::FinalizeKind kind = gc::GetGCObjectKind((((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1)));
19248 return NewNativeClassInstance(cx, clasp, proto, parent, kind);
19251 FindClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey, JSObject **protop,
19253 static inline JSObject *
19254 NewBuiltinClassInstance(JSContext *cx, Class *clasp, gc::FinalizeKind kind)
19257 JSProtoKey protoKey = ((JSProtoKey) (((clasp)->flags >> ((8 + 8) + 8)) & (((JSUint32)1 << (8)) - 1)));
19260 if (!cx->hasfp()) {
19261 global = cx->globalObject;
19262 OBJ_TO_INNER_OBJECT(cx, global);
19266 global = cx->fp()->scopeChain().getGlobal();
19269 const Value &v = global->getReservedSlot(JSProto_LIMIT + protoKey);
19271 if (v.isObject()) {
19272 proto = &v.toObject();
19275 if (!FindClassPrototype(cx, global, protoKey, &proto, clasp))
19278 return NewNativeClassInstance(cx, clasp, proto, global, kind);
19280 static inline JSObject *
19281 NewBuiltinClassInstance(JSContext *cx, Class *clasp)
19283 gc::FinalizeKind kind = gc::GetGCObjectKind((((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1)));
19284 return NewBuiltinClassInstance(cx, clasp, kind);
19286 static inline JSProtoKey
19287 GetClassProtoKey(js::Class *clasp)
19289 JSProtoKey key = ((JSProtoKey) (((clasp)->flags >> ((8 + 8) + 8)) & (((JSUint32)1 << (8)) - 1)));
19290 if (key != JSProto_Null)
19292 if (clasp->flags & (1<<((8 + 8)+1)))
19293 return JSProto_Object;
19294 return JSProto_Null;
19296 namespace WithProto {
19302 static __attribute__((always_inline)) inline
19304 FindProto(JSContext *cx, js::Class *clasp, JSObject *parent, JSObject ** proto)
19306 JSProtoKey protoKey = GetClassProtoKey(clasp);
19307 if (!js_GetClassPrototype(cx, parent, protoKey, proto, clasp))
19309 if (!(*proto) && !js_GetClassPrototype(cx, parent, JSProto_Object, proto))
19315 template <bool withProto, bool isFunction>
19316 static __attribute__((always_inline)) inline JSObject *
19317 NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
19318 gc::FinalizeKind kind)
19320 if (withProto == WithProto::Class && !proto) {
19321 if (!FindProto(cx, clasp, parent, &proto))
19324 JSObject* obj = isFunction ? js_NewGCFunction(cx) : js_NewGCObject(cx, kind);
19328 obj->init(cx, clasp, proto,
19329 (!parent && proto) ? proto->getParent() : parent,
19330 __null, clasp == &js_ArrayClass);
19331 if (clasp->isNative()) {
19332 if (!InitScopeForObject(cx, obj, clasp, proto, kind)) {
19337 obj->setSharedNonNativeMap();
19340 Probes::createObject(cx, obj);
19344 static __attribute__((always_inline)) inline JSObject *
19345 NewFunction(JSContext *cx, JSObject *parent)
19347 return detail::NewObject<WithProto::Class, true>(cx, &js_FunctionClass, __null, parent,
19348 gc::FINALIZE_OBJECT2);
19350 template <WithProto::e withProto>
19351 static __attribute__((always_inline)) inline JSObject *
19352 NewNonFunction(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
19353 gc::FinalizeKind kind)
19355 return detail::NewObject<withProto, false>(cx, clasp, proto, parent, kind);
19357 template <WithProto::e withProto>
19358 static __attribute__((always_inline)) inline JSObject *
19359 NewNonFunction(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent)
19361 gc::FinalizeKind kind = gc::GetGCObjectKind((((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1)));
19362 return detail::NewObject<withProto, false>(cx, clasp, proto, parent, kind);
19364 template <WithProto::e withProto>
19365 static __attribute__((always_inline)) inline JSObject *
19366 NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
19367 gc::FinalizeKind kind)
19369 if (clasp == &js_FunctionClass)
19370 return detail::NewObject<withProto, true>(cx, clasp, proto, parent, kind);
19371 return detail::NewObject<withProto, false>(cx, clasp, proto, parent, kind);
19373 template <WithProto::e withProto>
19374 static __attribute__((always_inline)) inline JSObject *
19375 NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent)
19377 gc::FinalizeKind kind = gc::GetGCObjectKind((((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1)));
19378 return NewObject<withProto>(cx, clasp, proto, parent, kind);
19380 static inline gc::FinalizeKind
19381 GuessObjectGCKind(size_t numSlots, bool isArray)
19384 return gc::GetGCObjectKind(numSlots);
19385 return isArray ? gc::FINALIZE_OBJECT8 : gc::FINALIZE_OBJECT4;
19387 static inline gc::FinalizeKind
19388 NewObjectGCKind(JSContext *cx, js::Class *clasp)
19390 if (clasp == &js_ArrayClass || clasp == &js_SlowArrayClass)
19391 return gc::FINALIZE_OBJECT8;
19392 if (clasp == &js_FunctionClass)
19393 return gc::FINALIZE_OBJECT2;
19394 return gc::FINALIZE_OBJECT4;
19396 static inline JSObject *
19397 CopyInitializerObject(JSContext *cx, JSObject *baseobj)
19401 gc::FinalizeKind kind = gc::FinalizeKind(baseobj->finalizeKind());
19402 JSObject *obj = NewBuiltinClassInstance(cx, &js_ObjectClass, kind);
19403 if (!obj || !obj->ensureSlots(cx, baseobj->numSlots()))
19405 obj->flags = baseobj->flags;
19406 obj->lastProp = baseobj->lastProp;
19407 obj->objShape = baseobj->objShape;
19410 static __attribute__((always_inline)) inline
19412 ClassMethodIsNative(JSContext *cx, JSObject *obj, Class *clasp, jsid methodid,
19416 if (HasNativeMethod(obj, methodid, native))
19418 JSObject *pobj = obj->getProto();
19419 return pobj && pobj->getClass() == clasp &&
19420 HasNativeMethod(pobj, methodid, native);
19423 using namespace js;
19424 using namespace js::gc;
19427 js_EnterLocalRootScope(JSContext *cx)
19432 js_LeaveLocalRootScope(JSContext *cx)
19436 js_LeaveLocalRootScopeWithResult(JSContext *cx, jsval rval)
19440 js_LeaveLocalRootScopeWithResult(JSContext *cx, Value rval)
19444 js_LeaveLocalRootScopeWithResult(JSContext *cx, void *rval)
19447 const char js_AttributeName_str[] = "AttributeName";
19448 const char js_isXMLName_str[] = "isXMLName";
19449 const char js_XMLList_str[] = "XMLList";
19450 const char js_localName_str[] = "localName";
19451 const char js_xml_parent_str[] = "parent";
19452 const char js_prefix_str[] = "prefix";
19453 const char js_toXMLString_str[] = "toXMLString";
19454 const char js_uri_str[] = "uri";
19455 const char js_amp_entity_str[] = "&";
19456 const char js_gt_entity_str[] = ">";
19457 const char js_lt_entity_str[] = "<";
19458 const char js_quot_entity_str[] = """;
19459 const char js_leftcurly_entity_str[] = "{";
19461 GetXMLFunction(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
19463 IsDeclared(const JSObject *obj)
19467 v = obj->getNamespaceDeclared();
19469 return v == ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1));
19472 xml_isXMLName(JSContext *cx, uintN argc, jsval *vp)
19474 *vp = BOOLEAN_TO_JSVAL(js_IsXMLName(cx, argc ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0))));
19477 static inline JSObject *
19478 NewBuiltinClassInstanceXML(JSContext *cx, Class *clasp)
19480 JSObject *obj = NewBuiltinClassInstance(cx, clasp);
19482 obj->syncSpecialEquality();
19485 static JSBool NamePrefix_getter(JSContext *cx, JSObject *obj, jsid id, jsval *vp) { if (obj->getClass() == &js_NamespaceClass) *vp = obj->getNamePrefixVal(); return true; }
19486 static JSBool NameURI_getter(JSContext *cx, JSObject *obj, jsid id, jsval *vp) { if (obj->getClass() == &js_NamespaceClass) *vp = obj->getNameURIVal(); return true; }
19488 namespace_equality(JSContext *cx, JSObject *obj, const Value *v, JSBool *bp)
19492 obj2 = v->toObjectOrNull();
19493 *bp = (!obj2 || obj2->getClass() != &js_NamespaceClass)
19495 : EqualStrings(obj->getNameURI(), obj2->getNameURI());
19498 __attribute__((visibility ("default"))) Class js_NamespaceClass = {
19501 (((JSObject::NAMESPACE_CLASS_RESERVED_SLOTS) & (((JSUint32)1 << (8)) - 1)) << 8) |
19502 (1<<((8 + 8)+3)) | ((JSProto_Namespace) << ((8 + 8) + 8)),
19506 StrictPropertyStub,
19519 namespace_equality,
19526 static JSPropertySpec namespace_props[] = {
19527 {js_prefix_str, 0, (0x01 | 0x02 | 0x04 | 0x40), NamePrefix_getter, 0},
19528 {js_uri_str, 0, (0x01 | 0x02 | 0x04 | 0x40), NameURI_getter, 0},
19532 namespace_toString(JSContext *cx, uintN argc, Value *vp)
19534 JSObject *obj = ToObject(cx, &vp[1]);
19537 if (!JS_InstanceOf(cx, obj, Jsvalify(&js_NamespaceClass), Jsvalify(vp + 2)))
19539 *vp = Valueify(obj->getNameURIVal());
19542 static JSFunctionSpec namespace_methods[] = {
19543 {js_toString_str, ((JSNative)(namespace_toString)), 0, (0) | 0x1000},
19544 {__null, __null, 0, 0}
19547 NewXMLNamespace(JSContext *cx, JSLinearString *prefix, JSLinearString *uri, JSBool declared)
19550 obj = NewBuiltinClassInstanceXML(cx, &js_NamespaceClass);
19557 obj->setNamePrefix(prefix);
19559 obj->setNameURI(uri);
19561 obj->setNamespaceDeclared(((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1)));
19565 static JSBool QNameNameURI_getter(JSContext *cx, JSObject *obj, jsid id, jsval *vp) { if (obj->getClass() == &js_QNameClass) *vp = JSVAL_IS_VOID(obj->getNameURIVal()) ? ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)) : obj->getNameURIVal(); return true; }
19566 static JSBool QNameLocalName_getter(JSContext *cx, JSObject *obj, jsid id, jsval *vp) { if (obj->getClass() == &js_QNameClass) *vp = obj->getQNameLocalNameVal(); return true; }
19568 qname_identity(JSObject *qna, JSObject *qnb)
19570 JSLinearString *uri1 = qna->getNameURI();
19571 JSLinearString *uri2 = qnb->getNameURI();
19574 if (uri1 && !EqualStrings(uri1, uri2))
19576 return EqualStrings(qna->getQNameLocalName(), qnb->getQNameLocalName());
19579 qname_equality(JSContext *cx, JSObject *qn, const Value *v, JSBool *bp)
19582 obj2 = v->toObjectOrNull();
19583 *bp = (!obj2 || obj2->getClass() != &js_QNameClass)
19585 : qname_identity(qn, obj2);
19588 __attribute__((visibility ("default"))) Class js_QNameClass = {
19591 (((JSObject::QNAME_CLASS_RESERVED_SLOTS) & (((JSUint32)1 << (8)) - 1)) << 8) |
19592 (1<<((8 + 8)+3)) | ((JSProto_QName) << ((8 + 8) + 8)),
19596 StrictPropertyStub,
19616 __attribute__((visibility ("default"))) Class js_AttributeNameClass = {
19617 js_AttributeName_str,
19619 (((JSObject::QNAME_CLASS_RESERVED_SLOTS) & (((JSUint32)1 << (8)) - 1)) << 8) |
19620 (1<<((8 + 8)+3)) | (1<<((8 + 8)+1)),
19624 StrictPropertyStub,
19630 __attribute__((visibility ("default"))) Class js_AnyNameClass = {
19633 (((JSObject::QNAME_CLASS_RESERVED_SLOTS) & (((JSUint32)1 << (8)) - 1)) << 8) |
19634 (1<<((8 + 8)+3)) | (1<<((8 + 8)+1)),
19638 StrictPropertyStub,
19644 static JSPropertySpec qname_props[] = {
19645 {js_uri_str, 0, (0x01 | 0x02 | 0x04 | 0x40), QNameNameURI_getter, 0},
19646 {js_localName_str, 0, (0x01 | 0x02 | 0x04 | 0x40), QNameLocalName_getter, 0},
19650 ConvertQNameToString(JSContext *cx, JSObject *obj)
19653 JSString *uri = obj->getNameURI();
19656 str = (cx->runtime->atomState.starQualifierAtom);
19657 } else if (uri->empty()) {
19658 str = cx->runtime->emptyString;
19660 JSString *qualstr = (cx->runtime->atomState.qualifierAtom);
19661 str = js_ConcatStrings(cx, uri, qualstr);
19665 str = js_ConcatStrings(cx, str, obj->getQNameLocalName());
19668 if (obj->getClass() == &js_AttributeNameClass) {
19669 JS::Anchor<JSString *> anchor(str);
19670 size_t length = str->length();
19671 jschar *chars = (jschar *) cx->malloc((length + 2) * sizeof(jschar));
19675 const jschar *strChars = str->getChars(cx);
19680 memcpy((chars + 1), (strChars), (length) * sizeof(jschar));
19681 chars[++length] = 0;
19682 str = js_NewString(cx, chars, length);
19691 qname_toString(JSContext *cx, uintN argc, Value *vp)
19693 JSObject *obj = ToObject(cx, &vp[1]);
19696 if (!InstanceOf(cx, obj, &js_QNameClass, vp + 2))
19698 JSString *str = ConvertQNameToString(cx, obj);
19701 vp->setString(str);
19704 static JSFunctionSpec qname_methods[] = {
19705 {js_toString_str, ((JSNative)(qname_toString)), 0, (0) | 0x1000},
19706 {__null, __null, 0, 0}
19709 InitXMLQName(JSObject *obj, JSLinearString *uri, JSLinearString *prefix,
19710 JSLinearString *localName)
19717 obj->setNameURI(uri);
19719 obj->setNamePrefix(prefix);
19721 obj->setQNameLocalName(localName);
19724 NewXMLQName(JSContext *cx, JSLinearString *uri, JSLinearString *prefix,
19725 JSLinearString *localName)
19727 JSObject *obj = NewBuiltinClassInstanceXML(cx, &js_QNameClass);
19730 InitXMLQName(obj, uri, prefix, localName);
19735 NewXMLAttributeName(JSContext *cx, JSLinearString *uri, JSLinearString *prefix,
19736 JSLinearString *localName)
19738 JSObject *obj = NewNonFunction<WithProto::Given>(cx, &js_AttributeNameClass, __null, __null);
19742 InitXMLQName(obj, uri, prefix, localName);
19747 js_ConstructXMLQNameObject(JSContext *cx, const Value &nsval, const Value &lnval)
19750 if (nsval.isObject() &&
19751 nsval.toObject().getClass() == &js_AnyNameClass) {
19757 return js_ConstructObject(cx, &js_QNameClass, __null, __null, 2, argv);
19760 IsXMLName(const jschar *cp, size_t n)
19765 if (n != 0 && (((js_A[js_Y[(js_X[(uint16)(*cp)>>6]<<6)|((*cp)&0x3F)]]) & 0x00000100) || (*cp) == '_')) {
19768 if (!(((js_A[js_Y[(js_X[(uint16)(c)>>6]<<6)|((c)&0x3F)]]) & 0x00000080) || (c) == '.' || (c) == '-' || (c) == '_'))
19776 js_IsXMLName(JSContext *cx, jsval v)
19778 JSLinearString *name = __null;
19779 JSErrorReporter older;
19780 if (!JSVAL_IS_PRIMITIVE(v) &&
19781 JSVAL_TO_OBJECT(v)->isQName()) {
19782 name = JSVAL_TO_OBJECT(v)->getQNameLocalName();
19784 older = JS_SetErrorReporter(cx, __null);
19785 JSString *str = js_ValueToString(cx, Valueify(v));
19787 name = str->ensureLinear(cx);
19788 JS_SetErrorReporter(cx, older);
19790 JS_ClearPendingException(cx);
19794 return IsXMLName(name->chars(), name->length());
19797 NamespaceHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv,
19800 jsval urival, prefixval;
19802 JSBool isNamespace, isQName;
19804 JSLinearString *empty, *prefix, *uri;
19805 isNamespace = isQName = (JSIntn)0;
19808 urival = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
19810 urival = argv[argc > 1];
19811 if (!JSVAL_IS_PRIMITIVE(urival)) {
19812 uriobj = JSVAL_TO_OBJECT(urival);
19813 clasp = uriobj->getClass();
19814 isNamespace = (clasp == &js_NamespaceClass);
19815 isQName = (clasp == &js_QNameClass);
19819 if (argc == 1 && isNamespace) {
19823 obj = NewBuiltinClassInstanceXML(cx, &js_NamespaceClass);
19827 *rval = OBJECT_TO_JSVAL(obj);
19829 empty = cx->runtime->emptyString;
19830 obj->setNamePrefix(empty);
19831 obj->setNameURI(empty);
19832 if (argc == 1 || argc == -1) {
19834 obj->setNameURI(uriobj->getNameURI());
19835 obj->setNamePrefix(uriobj->getNamePrefix());
19836 } else if (isQName && (uri = uriobj->getNameURI())) {
19837 obj->setNameURI(uri);
19838 obj->setNamePrefix(uriobj->getNamePrefix());
19840 JSString *str = js_ValueToString(cx, Valueify(urival));
19843 uri = str->ensureLinear(cx);
19846 obj->setNameURI(uri);
19848 obj->clearNamePrefix();
19850 } else if (argc == 2) {
19851 if (!isQName || !(uri = uriobj->getNameURI())) {
19852 JSString *str = js_ValueToString(cx, Valueify(urival));
19855 uri = str->ensureLinear(cx);
19859 obj->setNameURI(uri);
19860 prefixval = argv[0];
19861 if (uri->empty()) {
19862 if (!JSVAL_IS_VOID(prefixval)) {
19863 JSString *str = js_ValueToString(cx, Valueify(prefixval));
19866 if (!str->empty()) {
19867 JSAutoByteString bytes;
19868 if (js_ValueToPrintable(cx, StringValue(str), &bytes)) {
19869 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null,
19870 JSMSG_BAD_XML_NAMESPACE, bytes.ptr());
19875 } else if (JSVAL_IS_VOID(prefixval) || !js_IsXMLName(cx, prefixval)) {
19876 obj->clearNamePrefix();
19878 JSString *str = js_ValueToString(cx, Valueify(prefixval));
19881 prefix = str->ensureLinear(cx);
19884 obj->setNamePrefix(prefix);
19890 Namespace(JSContext *cx, uintN argc, Value *vp)
19892 JSObject *thisobj = __null;
19893 (void)IsConstructing_PossiblyWithGivenThisObject(vp, &thisobj);
19894 return NamespaceHelper(cx, thisobj, argc, Jsvalify(vp + 2), Jsvalify(vp));
19897 QNameHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv, jsval *rval)
19899 jsval nameval, nsval;
19900 JSBool isQName, isNamespace;
19902 JSLinearString *uri, *prefix, *name;
19905 nameval = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
19906 isQName = (JSIntn)0;
19908 nameval = argv[argc > 1];
19910 !JSVAL_IS_PRIMITIVE(nameval) &&
19911 JSVAL_TO_OBJECT(nameval)->getClass() == &js_QNameClass;
19914 if (argc == 1 && isQName) {
19918 obj = NewBuiltinClassInstanceXML(cx, &js_QNameClass);
19922 *rval = OBJECT_TO_JSVAL(obj);
19925 qn = JSVAL_TO_OBJECT(nameval);
19927 uri = qn->getNameURI();
19928 prefix = qn->getNamePrefix();
19929 name = qn->getQNameLocalName();
19932 nameval = qn->getQNameLocalNameVal();
19935 name = cx->runtime->emptyString;
19936 } else if (argc < 0) {
19937 name = (cx->runtime->atomState.typeAtoms[JSTYPE_VOID]);
19939 JSString *str = js_ValueToString(cx, Valueify(nameval));
19942 name = str->ensureLinear(cx);
19945 argv[argc > 1] = STRING_TO_JSVAL(name);
19947 if (argc > 1 && !JSVAL_IS_VOID(argv[0])) {
19949 } else if (((name)->length() == 1 && *(name)->chars() == '*')) {
19950 nsval = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
19952 if (!js_GetDefaultXMLNamespace(cx, &nsval))
19958 if (JSVAL_IS_NULL(nsval)) {
19959 prefix = uri = __null;
19961 isNamespace = isQName = (JSIntn)0;
19962 if (!JSVAL_IS_PRIMITIVE(nsval)) {
19963 obj2 = JSVAL_TO_OBJECT(nsval);
19964 isNamespace = (obj2->getClass() == &js_NamespaceClass);
19965 isQName = (obj2->getClass() == &js_QNameClass);
19967 else obj2 = __null;
19969 uri = obj2->getNameURI();
19970 prefix = obj2->getNamePrefix();
19971 } else if (isQName && (uri = obj2->getNameURI())) {
19973 prefix = obj2->getNamePrefix();
19976 JSString *str = js_ValueToString(cx, Valueify(nsval));
19979 uri = str->ensureLinear(cx);
19982 argv[0] = STRING_TO_JSVAL(uri);
19983 prefix = uri->empty() ? cx->runtime->emptyString : __null;
19987 InitXMLQName(obj, uri, prefix, name);
19991 QName(JSContext *cx, uintN argc, Value *vp)
19993 JSObject *thisobj = __null;
19994 (void)IsConstructing_PossiblyWithGivenThisObject(vp, &thisobj);
19995 return QNameHelper(cx, thisobj, argc, Jsvalify(vp + 2), Jsvalify(vp));
19998 namespace_identity(const void *a, const void *b)
20000 const JSObject *nsa = (const JSObject *) a;
20001 const JSObject *nsb = (const JSObject *) b;
20002 JSLinearString *prefixa = nsa->getNamePrefix();
20003 JSLinearString *prefixb = nsb->getNamePrefix();
20004 if (prefixa && prefixb) {
20005 if (!EqualStrings(prefixa, prefixb))
20008 if (prefixa || prefixb)
20011 return EqualStrings(nsa->getNameURI(), nsb->getNameURI());
20014 attr_identity(const void *a, const void *b)
20016 const JSXML *xmla = (const JSXML *) a;
20017 const JSXML *xmlb = (const JSXML *) b;
20018 return qname_identity(xmla->name, xmlb->name);
20021 JSXMLArrayCursor::trace(JSTracer *trc) {
20022 for (JSXMLArrayCursor *cursor = this; cursor; cursor = cursor->next)
20023 js::gc::MarkGCThing(trc, cursor->root, "cursor_root", index++);
20026 XMLArrayCursorTrace(JSTracer *trc, JSXMLArrayCursor *cursor)
20028 cursor->trace(trc);
20031 JSXMLArray::setCapacity(JSContext *cx, uint32 newCapacity)
20033 if (newCapacity == 0) {
20044 !(tmp = (void **) js_realloc(vector, newCapacity * sizeof(void *)))) {
20046 JS_ReportOutOfMemory(cx);
20051 capacity = ((JSUint32)1 << (31)) | newCapacity;
20057 if (capacity & ((JSUint32)1 << (31)))
20059 if (length < capacity)
20060 setCapacity(__null, length);
20063 JSXMLArray::finish(JSContext *cx)
20066 while (JSXMLArrayCursor *cursor = cursors)
20067 cursor->disconnect();
20070 XMLArrayFindMember(const JSXMLArray *array, void *elt, JSIdentityOp identity)
20074 vector = array->vector;
20076 for (i = 0, n = array->length; i < n; i++) {
20077 if (identity(vector[i], elt))
20081 for (i = 0, n = array->length; i < n; i++) {
20082 if (vector[i] == elt)
20086 return ((uint32) -1);
20089 XMLArrayAddMember(JSContext *cx, JSXMLArray *array, uint32 index, void *elt)
20091 uint32 capacity, i;
20094 if (index >= array->length) {
20095 if (index >= ((array)->capacity & (((JSUint32)1 << (31)) - 1))) {
20096 capacity = index + 1;
20097 if (index >= 256) {
20098 capacity = ((((capacity)+(32)-1)/(32))*(32));
20100 do { unsigned int j_ = (unsigned int)(capacity); (log2) = (j_ <= 1 ? 0 : 32 - __builtin_clz(j_ - 1)); } while (0);
20101 capacity = ((JSUint32)1 << (log2));
20104 !(vector = (void **)
20105 js_realloc(array->vector, capacity * sizeof(void *)))) {
20106 JS_ReportOutOfMemory(cx);
20109 array->capacity = capacity;
20110 array->vector = vector;
20111 for (i = array->length; i < index; i++)
20112 vector[i] = __null;
20114 array->length = index + 1;
20116 array->vector[index] = elt;
20120 XMLArrayInsert(JSContext *cx, JSXMLArray *array, uint32 i, uint32 n)
20123 JSXMLArrayCursor *cursor;
20126 if (!array->setCapacity(cx, j + n))
20128 array->length = j + n;
20132 array->vector[j + n] = array->vector[j];
20134 for (cursor = array->cursors; cursor; cursor = cursor->next) {
20135 if (cursor->index > i)
20136 cursor->index += n;
20141 XMLArrayDelete(JSContext *cx, JSXMLArray *array, uint32 index, JSBool compress)
20144 void **vector, *elt;
20145 JSXMLArrayCursor *cursor;
20146 length = array->length;
20147 if (index >= length)
20149 vector = array->vector;
20150 elt = vector[index];
20152 while (++index < length)
20153 vector[index-1] = vector[index];
20154 array->length = length - 1;
20155 array->capacity = ((array)->capacity & (((JSUint32)1 << (31)) - 1));
20157 vector[index] = __null;
20159 for (cursor = array->cursors; cursor; cursor = cursor->next) {
20160 if (cursor->index > index)
20166 XMLArrayTruncate(JSContext *cx, JSXMLArray *array, uint32 length)
20170 if (length >= array->length)
20174 cx->free(array->vector);
20177 vector = (void **) js_realloc(array->vector, length * sizeof(void *));
20181 if (array->length > length)
20182 array->length = length;
20183 array->capacity = length;
20184 array->vector = vector;
20186 static const char js_ignoreComments_str[] = "ignoreComments";
20187 static const char js_ignoreProcessingInstructions_str[]
20188 = "ignoreProcessingInstructions";
20189 static const char js_ignoreWhitespace_str[] = "ignoreWhitespace";
20190 static const char js_prettyPrinting_str[] = "prettyPrinting";
20191 static const char js_prettyIndent_str[] = "prettyIndent";
20192 static JSPropertySpec xml_static_props[] = {
20193 {js_ignoreComments_str, 0, 0x04, __null, __null},
20194 {js_ignoreProcessingInstructions_str, 0, 0x04, __null, __null},
20195 {js_ignoreWhitespace_str, 0, 0x04, __null, __null},
20196 {js_prettyPrinting_str, 0, 0x04, __null, __null},
20197 {js_prettyIndent_str, 0, 0x04, __null, __null},
20200 static const char xml_namespace_str[] = "http://www.w3.org/XML/1998/namespace";
20201 static const char xmlns_namespace_str[] = "http://www.w3.org/2000/xmlns/";
20203 ParseNodeToQName(Parser *parser, JSParseNode *pn,
20204 JSXMLArray *inScopeNSes, JSBool isAttributeName)
20206 JSContext *cx = parser->context;
20207 JSLinearString *str, *uri, *prefix, *localName;
20208 size_t length, offset;
20209 const jschar *start, *limit, *colon;
20212 JSLinearString *nsprefix;
20214 str = pn->pn_u.name.atom;
20215 start = str->chars();
20216 length = str->length();
20219 uri = cx->runtime->emptyString;
20220 limit = start + length;
20221 colon = js_strchr_limit(start, ':', limit);
20223 offset = colon - start;
20224 prefix = js_NewDependentString(cx, str, 0, offset);
20227 if ((offset >= 3 && (((jschar) (((js_A[js_Y[(js_X[(uint16)((start)[0])>>6]<<6)|(((start)[0])&0x3F)]]) & 0x00200000) ? ((start)[0]) + ((int32)(js_A[js_Y[(js_X[(uint16)((start)[0])>>6]<<6)|(((start)[0])&0x3F)]]) >> 22) : ((start)[0]))) == 'x' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((start)[1])>>6]<<6)|(((start)[1])&0x3F)]]) & 0x00200000) ? ((start)[1]) + ((int32)(js_A[js_Y[(js_X[(uint16)((start)[1])>>6]<<6)|(((start)[1])&0x3F)]]) >> 22) : ((start)[1]))) == 'm' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((start)[2])>>6]<<6)|(((start)[2])&0x3F)]]) & 0x00200000) ? ((start)[2]) + ((int32)(js_A[js_Y[(js_X[(uint16)((start)[2])>>6]<<6)|(((start)[2])&0x3F)]]) >> 22) : ((start)[2]))) == 'l'))) {
20229 uri = JS_ASSERT_STRING_IS_FLAT(JS_InternString(cx, xml_namespace_str));
20232 } else if (offset == 5 && (((jschar) (((js_A[js_Y[(js_X[(uint16)((start)[3])>>6]<<6)|(((start)[3])&0x3F)]]) & 0x00200000) ? ((start)[3]) + ((int32)(js_A[js_Y[(js_X[(uint16)((start)[3])>>6]<<6)|(((start)[3])&0x3F)]]) >> 22) : ((start)[3]))) == 'n' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((start)[4])>>6]<<6)|(((start)[4])&0x3F)]]) & 0x00200000) ? ((start)[4]) + ((int32)(js_A[js_Y[(js_X[(uint16)((start)[4])>>6]<<6)|(((start)[4])&0x3F)]]) >> 22) : ((start)[4]))) == 's')) {
20233 uri = JS_ASSERT_STRING_IS_FLAT(JS_InternString(cx, xmlns_namespace_str));
20241 n = inScopeNSes->length;
20244 ns = (((n) < (inScopeNSes)->length) ? (JSObject *) (inScopeNSes)->vector[n] : __null);
20245 nsprefix = ns->getNamePrefix();
20246 if (nsprefix && EqualStrings(nsprefix, prefix)) {
20247 uri = ns->getNameURI();
20253 Value v = StringValue(prefix);
20254 JSAutoByteString bytes;
20255 if (js_ValueToPrintable(parser->context, v, &bytes)) {
20256 ReportCompileErrorNumber(parser->context, &parser->tokenStream, pn,
20257 0x0, JSMSG_BAD_XML_NAMESPACE, bytes.ptr());
20261 localName = js_NewStringCopyN(parser->context, colon + 1, length - (offset + 1));
20265 if (isAttributeName) {
20268 n = inScopeNSes->length;
20271 ns = (((n) < (inScopeNSes)->length) ? (JSObject *) (inScopeNSes)->vector[n] : __null);
20272 nsprefix = ns->getNamePrefix();
20273 if (!nsprefix || nsprefix->empty()) {
20274 uri = ns->getNameURI();
20278 prefix = uri->empty() ? parser->context->runtime->emptyString : __null;
20282 return NewXMLQName(parser->context, uri, prefix, localName);
20285 ChompXMLWhitespace(JSContext *cx, JSString *str)
20287 size_t length, newlength, offset;
20288 const jschar *cp, *start, *end;
20290 length = str->length();
20291 start = str->getChars(cx);
20294 for (cp = start, end = cp + length; cp < end; cp++) {
20296 if (!((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n'))
20301 if (!((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n'))
20305 newlength = end - cp;
20306 if (newlength == length)
20308 offset = cp - start;
20309 return js_NewDependentString(cx, str, offset, newlength);
20312 ParseNodeToXML(Parser *parser, JSParseNode *pn,
20313 JSXMLArray *inScopeNSes, uintN flags)
20315 JSContext *cx = parser->context;
20316 JSXML *xml, *kid, *attr, *attrj;
20317 JSLinearString *str;
20318 uint32 length, n, i, j;
20319 JSParseNode *pn2, *pn3, *head, **pnp;
20321 JSObject *qn, *attrjqn;
20322 JSXMLClass xml_class;
20324 if (!((jsuword)(&stackDummy) > cx->stackLimit)) {
20325 ReportCompileErrorNumber(cx, &parser->tokenStream, pn, 0x0,
20326 JSMSG_OVER_RECURSED);
20330 if (!js_EnterLocalRootScope(cx))
20332 switch (pn->pn_type) {
20334 length = inScopeNSes->length;
20335 pn2 = pn->pn_u.list.head;
20336 xml = ParseNodeToXML(parser, pn2, inScopeNSes, flags);
20339 n = pn->pn_u.list.count;
20342 if (!xml->u.list.kids.setCapacity(cx, n))
20345 while ((pn2 = pn2->pn_next) != __null) {
20346 if (!pn2->pn_next) {
20350 if ((flags & ((JSUint32)1 << (2))) &&
20351 n > 1 && pn2->pn_type == TOK_XMLSPACE) {
20355 kid = ParseNodeToXML(parser, pn2, inScopeNSes, flags);
20356 if (kid == ((JSXML *) 1)) {
20362 do { if ((&xml->u.list.kids)->length <= (i)) (&xml->u.list.kids)->length = (i) + 1; ((&xml->u.list.kids)->vector[i] = (void *)(kid)); } while (0);
20365 if ((flags & ((JSUint32)1 << (2))) &&
20366 n > 1 && kid->xml_class == JSXML_CLASS_TEXT) {
20367 JSString *str = ChompXMLWhitespace(cx, kid->u.value);
20370 kid->u.value = str;
20374 if (n < pn->pn_u.list.count - 2)
20375 xml->u.list.kids.trim();
20376 XMLArrayTruncate(cx, inScopeNSes, length);
20379 xml = js_NewXML(cx, JSXML_CLASS_LIST);
20382 n = pn->pn_u.list.count;
20383 if (!xml->u.list.kids.setCapacity(cx, n))
20386 for (pn2 = pn->pn_u.list.head; pn2; pn2 = pn2->pn_next) {
20387 if (pn2->pn_type == TOK_XMLSPACE) {
20391 kid = ParseNodeToXML(parser, pn2, inScopeNSes, flags);
20392 if (kid == ((JSXML *) 1)) {
20398 do { if ((&xml->u.list.kids)->length <= (i)) (&xml->u.list.kids)->length = (i) + 1; ((&xml->u.list.kids)->vector[i] = (void *)(kid)); } while (0);
20401 if (n < pn->pn_u.list.count)
20402 xml->u.list.kids.trim();
20406 length = inScopeNSes->length;
20407 pn2 = pn->pn_u.list.head;
20409 if (pn2->pn_arity == PN_LIST)
20411 xml = js_NewXML(cx, JSXML_CLASS_ELEMENT);
20415 n = pn->pn_u.list.count - 1;
20416 pnp = &pn2->pn_next;
20418 while ((pn2 = *pnp) != __null) {
20420 const jschar *chars;
20421 if (pn2->pn_type != TOK_XMLNAME || pn2->pn_arity != PN_NULLARY)
20423 for (pn3 = head; pn3 != pn2; pn3 = pn3->pn_next->pn_next) {
20424 if (pn3->pn_u.name.atom == pn2->pn_u.name.atom) {
20425 Value v = StringValue((pn2->pn_u.name.atom));
20426 JSAutoByteString bytes;
20427 if (js_ValueToPrintable(cx, v, &bytes)) {
20428 ReportCompileErrorNumber(cx, &parser->tokenStream, pn2,
20429 0x0, JSMSG_DUPLICATE_XML_ATTR,
20435 JSAtom *atom = pn2->pn_u.name.atom;
20436 pn2 = pn2->pn_next;
20438 if (pn2->pn_type != TOK_XMLATTR)
20440 chars = atom->chars();
20441 length = atom->length();
20443 ((((jschar) (((js_A[js_Y[(js_X[(uint16)((chars)[0])>>6]<<6)|(((chars)[0])&0x3F)]]) & 0x00200000) ? ((chars)[0]) + ((int32)(js_A[js_Y[(js_X[(uint16)((chars)[0])>>6]<<6)|(((chars)[0])&0x3F)]]) >> 22) : ((chars)[0]))) == 'x' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((chars)[1])>>6]<<6)|(((chars)[1])&0x3F)]]) & 0x00200000) ? ((chars)[1]) + ((int32)(js_A[js_Y[(js_X[(uint16)((chars)[1])>>6]<<6)|(((chars)[1])&0x3F)]]) >> 22) : ((chars)[1]))) == 'm' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((chars)[2])>>6]<<6)|(((chars)[2])&0x3F)]]) & 0x00200000) ? ((chars)[2]) + ((int32)(js_A[js_Y[(js_X[(uint16)((chars)[2])>>6]<<6)|(((chars)[2])&0x3F)]]) >> 22) : ((chars)[2]))) == 'l') && (((jschar) (((js_A[js_Y[(js_X[(uint16)((chars)[3])>>6]<<6)|(((chars)[3])&0x3F)]]) & 0x00200000) ? ((chars)[3]) + ((int32)(js_A[js_Y[(js_X[(uint16)((chars)[3])>>6]<<6)|(((chars)[3])&0x3F)]]) >> 22) : ((chars)[3]))) == 'n' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((chars)[4])>>6]<<6)|(((chars)[4])&0x3F)]]) & 0x00200000) ? ((chars)[4]) + ((int32)(js_A[js_Y[(js_X[(uint16)((chars)[4])>>6]<<6)|(((chars)[4])&0x3F)]]) >> 22) : ((chars)[4]))) == 's')) &&
20444 (length == 5 || chars[5] == ':')) {
20445 JSLinearString *uri, *prefix;
20446 uri = (pn2->pn_u.name.atom);
20448 prefix = cx->runtime->emptyString;
20450 prefix = js_NewStringCopyN(cx, chars + 6, length - 6);
20454 ns = NewXMLNamespace(cx, prefix, uri, (JSIntn)1);
20457 if (!(XMLArrayFindMember(inScopeNSes, (void *)(ns), namespace_identity) != ((uint32) -1))) {
20458 if (!XMLArrayAddMember(cx, inScopeNSes, (inScopeNSes)->length, (void *)((ns))) ||
20459 !XMLArrayAddMember(cx, &xml->u.elem.namespaces, (&xml->u.elem.namespaces)->length, (void *)((ns)))) {
20465 *pnp = pn2->pn_next;
20468 pnp = &pn2->pn_next;
20470 xml->u.elem.namespaces.trim();
20471 pn2 = pn->pn_u.list.head;
20472 qn = ParseNodeToQName(parser, pn2, inScopeNSes, (JSIntn)0);
20478 if (!xml->u.elem.attrs.setCapacity(cx, n))
20480 for (i = 0; (pn2 = pn2->pn_next) != __null; i++) {
20481 qn = ParseNodeToQName(parser, pn2, inScopeNSes, (JSIntn)1);
20483 xml->u.elem.attrs.length = i;
20486 for (j = 0; j < i; j++) {
20487 attrj = (((j) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[j] : __null);
20488 attrjqn = attrj->name;
20489 if (EqualStrings(attrjqn->getNameURI(), qn->getNameURI()) &&
20490 EqualStrings(attrjqn->getQNameLocalName(), qn->getQNameLocalName())) {
20491 Value v = StringValue((pn2->pn_u.name.atom));
20492 JSAutoByteString bytes;
20493 if (js_ValueToPrintable(cx, v, &bytes)) {
20494 ReportCompileErrorNumber(cx, &parser->tokenStream, pn2,
20495 0x0, JSMSG_DUPLICATE_XML_ATTR,
20501 pn2 = pn2->pn_next;
20504 attr = js_NewXML(cx, JSXML_CLASS_ATTRIBUTE);
20507 do { if ((&xml->u.elem.attrs)->length <= (i)) (&xml->u.elem.attrs)->length = (i) + 1; ((&xml->u.elem.attrs)->vector[i] = (void *)(attr)); } while (0);
20508 attr->parent = xml;
20510 attr->u.value = (pn2->pn_u.name.atom);
20512 if (pn->pn_type == TOK_XMLPTAGC)
20513 XMLArrayTruncate(cx, inScopeNSes, length);
20518 case TOK_XMLCOMMENT:
20520 str = (pn->pn_u.name.atom);
20522 if (pn->pn_type == TOK_XMLCOMMENT) {
20523 if (flags & ((JSUint32)1 << (0)))
20525 xml_class = JSXML_CLASS_COMMENT;
20526 } else if (pn->pn_type == TOK_XMLPI) {
20527 if ((str->length() == 3 && (((jschar) (((js_A[js_Y[(js_X[(uint16)((str->chars())[0])>>6]<<6)|(((str->chars())[0])&0x3F)]]) & 0x00200000) ? ((str->chars())[0]) + ((int32)(js_A[js_Y[(js_X[(uint16)((str->chars())[0])>>6]<<6)|(((str->chars())[0])&0x3F)]]) >> 22) : ((str->chars())[0]))) == 'x' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((str->chars())[1])>>6]<<6)|(((str->chars())[1])&0x3F)]]) & 0x00200000) ? ((str->chars())[1]) + ((int32)(js_A[js_Y[(js_X[(uint16)((str->chars())[1])>>6]<<6)|(((str->chars())[1])&0x3F)]]) >> 22) : ((str->chars())[1]))) == 'm' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((str->chars())[2])>>6]<<6)|(((str->chars())[2])&0x3F)]]) & 0x00200000) ? ((str->chars())[2]) + ((int32)(js_A[js_Y[(js_X[(uint16)((str->chars())[2])>>6]<<6)|(((str->chars())[2])&0x3F)]]) >> 22) : ((str->chars())[2]))) == 'l'))) {
20528 Value v = StringValue(str);
20529 JSAutoByteString bytes;
20530 if (js_ValueToPrintable(cx, v, &bytes)) {
20531 ReportCompileErrorNumber(cx, &parser->tokenStream, pn,
20532 0x0, JSMSG_RESERVED_ID, bytes.ptr());
20536 if (flags & ((JSUint32)1 << (1)))
20538 qn = ParseNodeToQName(parser, pn, inScopeNSes, (JSIntn)0);
20541 str = pn->pn_u.apair.atom2
20542 ? (pn->pn_u.apair.atom2)
20543 : cx->runtime->emptyString;
20544 xml_class = JSXML_CLASS_PROCESSING_INSTRUCTION;
20546 xml_class = JSXML_CLASS_TEXT;
20548 xml = js_NewXML(cx, xml_class);
20552 if (pn->pn_type == TOK_XMLSPACE)
20553 xml->xml_flags |= 0x1;
20554 xml->u.value = str;
20559 js_LeaveLocalRootScopeWithResult(cx, xml);
20562 js_LeaveLocalRootScope(cx);
20563 return ((JSXML *) 1);
20565 ReportCompileErrorNumber(cx, &parser->tokenStream, pn, 0x0, JSMSG_BAD_XML_MARKUP);
20567 js_LeaveLocalRootScope(cx);
20571 GetXMLSetting(JSContext *cx, const char *name, jsval *vp)
20574 if (!js_FindClassObject(cx, __null, JSProto_XML, Valueify(&v)))
20576 if (!(!JSVAL_IS_PRIMITIVE(v) && JSVAL_TO_OBJECT(v)->isFunction())) {
20577 *vp = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
20580 return JS_GetProperty(cx, JSVAL_TO_OBJECT(v), name, vp);
20583 GetBooleanXMLSetting(JSContext *cx, const char *name, JSBool *bp)
20586 return GetXMLSetting(cx, name, &v) && JS_ValueToBoolean(cx, v, bp);
20589 GetUint32XMLSetting(JSContext *cx, const char *name, uint32 *uip)
20592 return GetXMLSetting(cx, name, &v) && JS_ValueToECMAUint32(cx, v, uip);
20595 GetXMLSettingFlags(JSContext *cx, uintN *flagsp)
20598 if (!GetBooleanXMLSetting(cx, js_ignoreComments_str, &flag[0]) ||
20599 !GetBooleanXMLSetting(cx, js_ignoreProcessingInstructions_str, &flag[1]) ||
20600 !GetBooleanXMLSetting(cx, js_ignoreWhitespace_str, &flag[2]) ||
20601 !GetBooleanXMLSetting(cx, js_prettyPrinting_str, &flag[3])) {
20605 for (size_t n = 0; n < 4; ++n)
20607 *flagsp |= ((JSUint32)1 << (n));
20611 ParseXMLSource(JSContext *cx, JSString *src)
20614 JSLinearString *uri;
20615 size_t urilen, srclen, length, offset, dstlen;
20617 const jschar *srcp, *endp;
20619 const char *filename;
20622 static const char prefix[] = "<parent xmlns=\"";
20623 static const char middle[] = "\">";
20624 static const char suffix[] = "</parent>";
20625 if (!js_GetDefaultXMLNamespace(cx, &nsval))
20627 uri = JSVAL_TO_OBJECT(nsval)->getNameURI();
20628 uri = js_EscapeAttributeValue(cx, uri, (JSIntn)0);
20631 urilen = uri->length();
20632 srclen = src->length();
20633 length = (sizeof(prefix) - 1) + urilen + (sizeof(middle) - 1) + srclen +
20634 (sizeof(suffix) - 1);
20635 chars = (jschar *) cx->malloc((length + 1) * sizeof(jschar));
20639 js_InflateStringToBuffer(cx, prefix, (sizeof(prefix) - 1), chars, &dstlen);
20641 memcpy((chars + offset), (uri->chars()), (urilen) * sizeof(jschar));
20643 dstlen = length - offset + 1;
20644 js_InflateStringToBuffer(cx, middle, (sizeof(middle) - 1), chars + offset,
20647 srcp = src->getChars(cx);
20652 memcpy((chars + offset), (srcp), (srclen) * sizeof(jschar));
20654 dstlen = length - offset + 1;
20655 js_InflateStringToBuffer(cx, suffix, (sizeof(suffix) - 1), chars + offset,
20657 chars [offset + dstlen] = 0;
20660 FrameRegsIter i(cx);
20661 for (; !i.done() && !i.pc(); ++i)
20666 JSStackFrame *fp = i.fp();
20667 op = (JSOp) *i.pc();
20668 if (op == JSOP_TOXML || op == JSOP_TOXMLLIST) {
20669 filename = fp->script()->filename;
20670 lineno = js_FramePCToLineNumber(cx, fp);
20671 for (endp = srcp + srclen; srcp < endp; srcp++) {
20679 if (parser.init(chars, length, filename, lineno, cx->findVersion())) {
20680 JSObject *scopeChain = GetScopeChain(cx);
20685 JSParseNode *pn = parser.parseXMLText(scopeChain, false);
20687 if (pn && GetXMLSettingFlags(cx, &flags)) {
20688 AutoNamespaceArray namespaces(cx);
20689 if (namespaces.array.setCapacity(cx, 1))
20690 xml = ParseNodeToXML(&parser, pn, &namespaces.array, flags);
20698 OrphanXMLChild(JSContext *cx, JSXML *xml, uint32 i)
20701 ns = (((0) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[0] : __null);
20702 xml = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
20705 if (xml->xml_class == JSXML_CLASS_ELEMENT) {
20706 if (!XMLArrayAddMember(cx, &xml->u.elem.namespaces, (&xml->u.elem.namespaces)->length, (void *)((ns))))
20708 ns->setNamespaceDeclared(((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)));
20710 xml->parent = __null;
20714 ToXML(JSContext *cx, jsval v)
20721 if (JSVAL_IS_PRIMITIVE(v)) {
20722 if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
20725 obj = JSVAL_TO_OBJECT(v);
20726 if (obj->isXML()) {
20727 xml = (JSXML *) obj->getPrivate();
20728 if (xml->xml_class == JSXML_CLASS_LIST) {
20729 if (xml->u.list.kids.length != 1)
20731 xml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null);
20734 return js_GetXMLObject(cx, xml);
20739 clasp = obj->getClass();
20740 if (clasp->flags & (1<<7)) {
20743 if (clasp != &js_StringClass &&
20744 clasp != &js_NumberClass &&
20745 clasp != &js_BooleanClass) {
20749 str = js_ValueToString(cx, Valueify(v));
20752 if (str->empty()) {
20756 xml = ParseXMLSource(cx, str);
20759 length = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0);
20762 obj = js_NewXMLObject(cx, JSXML_CLASS_TEXT);
20765 } else if (length == 1) {
20766 xml = OrphanXMLChild(cx, xml, 0);
20769 obj = js_GetXMLObject(cx, xml);
20773 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_SYNTAX_ERROR);
20778 ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_BAD_XML_CONVERSION, 0, Valueify(v), __null, __null, __null))
20783 Append(JSContext *cx, JSXML *list, JSXML *kid);
20785 ToXMLList(JSContext *cx, jsval v)
20787 JSObject *obj, *listobj;
20788 JSXML *xml, *list, *kid;
20792 if (JSVAL_IS_PRIMITIVE(v)) {
20793 if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
20796 obj = JSVAL_TO_OBJECT(v);
20797 if (obj->isXML()) {
20798 xml = (JSXML *) obj->getPrivate();
20799 if (xml->xml_class != JSXML_CLASS_LIST) {
20800 listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
20803 list = (JSXML *) listobj->getPrivate();
20804 if (!Append(cx, list, xml))
20810 clasp = obj->getClass();
20811 if (clasp->flags & (1<<7)) {
20814 if (clasp != &js_StringClass &&
20815 clasp != &js_NumberClass &&
20816 clasp != &js_BooleanClass) {
20820 str = js_ValueToString(cx, Valueify(v));
20823 if (str->empty()) {
20827 if (!js_EnterLocalRootScope(cx))
20829 xml = ParseXMLSource(cx, str);
20831 js_LeaveLocalRootScope(cx);
20834 length = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0);
20836 listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
20838 list = (JSXML *) listobj->getPrivate();
20839 for (i = 0; i < length; i++) {
20840 kid = OrphanXMLChild(cx, xml, i);
20841 if (!kid || !Append(cx, list, kid)) {
20848 js_LeaveLocalRootScopeWithResult(cx, listobj);
20851 ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_BAD_XMLLIST_CONVERSION, 0, Valueify(v), __null, __null, __null))
20855 static JSFlatString *
20856 MakeXMLSpecialString(JSContext *cx, StringBuffer &sb,
20857 JSString *str, JSString *str2,
20858 const jschar *prefix, size_t prefixlength,
20859 const jschar *suffix, size_t suffixlength)
20861 if (!sb.append(prefix, prefixlength) || !sb.append(str))
20863 if (str2 && !str2->empty()) {
20864 if (!sb.append(' ') || !sb.append(str2))
20867 if (!sb.append(suffix, suffixlength))
20869 return sb.finishString();
20871 static JSFlatString *
20872 MakeXMLCDATAString(JSContext *cx, StringBuffer &sb, JSString *str)
20874 static const jschar cdata_prefix_ucNstr[] = {'<', '!', '[',
20875 'C', 'D', 'A', 'T', 'A',
20877 static const jschar cdata_suffix_ucNstr[] = {']', ']', '>'};
20878 return MakeXMLSpecialString(cx, sb, str, __null,
20879 cdata_prefix_ucNstr, 9,
20880 cdata_suffix_ucNstr, 3);
20882 static JSFlatString *
20883 MakeXMLCommentString(JSContext *cx, StringBuffer &sb, JSString *str)
20885 static const jschar comment_prefix_ucNstr[] = {'<', '!', '-', '-'};
20886 static const jschar comment_suffix_ucNstr[] = {'-', '-', '>'};
20887 return MakeXMLSpecialString(cx, sb, str, __null,
20888 comment_prefix_ucNstr, 4,
20889 comment_suffix_ucNstr, 3);
20891 static JSFlatString *
20892 MakeXMLPIString(JSContext *cx, StringBuffer &sb, JSString *name,
20895 static const jschar pi_prefix_ucNstr[] = {'<', '?'};
20896 static const jschar pi_suffix_ucNstr[] = {'?', '>'};
20897 return MakeXMLSpecialString(cx, sb, name, value,
20898 pi_prefix_ucNstr, 2,
20899 pi_suffix_ucNstr, 2);
20903 AppendAttributeValue(JSContext *cx, StringBuffer &sb, JSString *valstr)
20905 if (!sb.append('='))
20907 valstr = js_EscapeAttributeValue(cx, valstr, (JSIntn)1);
20908 return valstr && sb.append(valstr);
20910 static JSFlatString *
20911 EscapeElementValue(JSContext *cx, StringBuffer &sb, JSString *str, uint32 toSourceFlag)
20913 size_t length = str->length();
20914 const jschar *start = str->getChars(cx);
20917 for (const jschar *cp = start, *end = start + length; cp != end; ++cp) {
20921 if (!sb.append(js_lt_entity_str))
20925 if (!sb.append(js_gt_entity_str))
20929 if (!sb.append(js_amp_entity_str))
20933 if (toSourceFlag) {
20934 if (!sb.append(js_leftcurly_entity_str))
20943 return sb.finishString();
20945 static JSFlatString *
20946 EscapeAttributeValue(JSContext *cx, StringBuffer &sb, JSString *str, JSBool quote)
20948 size_t length = str->length();
20949 const jschar *start = str->getChars(cx);
20952 if (quote && !sb.append('"'))
20954 for (const jschar *cp = start, *end = start + length; cp != end; ++cp) {
20958 if (!sb.append(js_quot_entity_str))
20962 if (!sb.append(js_lt_entity_str))
20966 if (!sb.append(js_amp_entity_str))
20970 if (!sb.append("
"))
20974 if (!sb.append("
"))
20978 if (!sb.append("	"))
20986 if (quote && !sb.append('"'))
20988 return sb.finishString();
20991 GetNamespace(JSContext *cx, JSObject *qn, const JSXMLArray *inScopeNSes)
20993 JSLinearString *uri, *prefix, *nsprefix;
20994 JSObject *match, *ns;
20997 uri = qn->getNameURI();
20998 prefix = qn->getNamePrefix();
21001 JSAutoByteString bytes;
21002 const char *s = !prefix ?
21004 : js_ValueToPrintable(cx, StringValue(prefix), &bytes);
21006 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_BAD_XML_NAMESPACE, s);
21011 for (i = 0, n = inScopeNSes->length; i < n; i++) {
21012 ns = (((i) < (inScopeNSes)->length) ? (JSObject *) (inScopeNSes)->vector[i] : __null);
21015 if (EqualStrings(ns->getNameURI(), uri)) {
21016 nsprefix = ns->getNamePrefix();
21017 if (nsprefix == prefix ||
21018 ((nsprefix && prefix)
21019 ? EqualStrings(nsprefix, prefix)
21020 : (nsprefix ? nsprefix : prefix)->empty())) {
21028 argv[0] = prefix ? STRING_TO_JSVAL(prefix) : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
21029 argv[1] = STRING_TO_JSVAL(uri);
21030 ns = js_ConstructObject(cx, &js_NamespaceClass, __null, __null,
21031 2, Valueify(argv));
21038 static JSLinearString *
21039 GeneratePrefix(JSContext *cx, JSLinearString *uri, JSXMLArray *decls)
21041 const jschar *cp, *start, *end;
21042 size_t length, newlength, offset;
21043 uint32 i, n, m, serial;
21047 JSLinearString *nsprefix, *prefix;
21049 if (decls->length == 0)
21050 return js_NewStringCopyZ(cx, "a");
21051 start = uri->chars();
21052 end = start + uri->length();
21054 while (--cp > start) {
21055 if (*cp == '.' || *cp == '/' || *cp == ':') {
21058 if (IsXMLName(cp, length) && !(length >= 3 && (((jschar) (((js_A[js_Y[(js_X[(uint16)((cp)[0])>>6]<<6)|(((cp)[0])&0x3F)]]) & 0x00200000) ? ((cp)[0]) + ((int32)(js_A[js_Y[(js_X[(uint16)((cp)[0])>>6]<<6)|(((cp)[0])&0x3F)]]) >> 22) : ((cp)[0]))) == 'x' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((cp)[1])>>6]<<6)|(((cp)[1])&0x3F)]]) & 0x00200000) ? ((cp)[1]) + ((int32)(js_A[js_Y[(js_X[(uint16)((cp)[1])>>6]<<6)|(((cp)[1])&0x3F)]]) >> 22) : ((cp)[1]))) == 'm' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((cp)[2])>>6]<<6)|(((cp)[2])&0x3F)]]) & 0x00200000) ? ((cp)[2]) + ((int32)(js_A[js_Y[(js_X[(uint16)((cp)[2])>>6]<<6)|(((cp)[2])&0x3F)]]) >> 22) : ((cp)[2]))) == 'l')))
21064 bp = (jschar *) cp;
21065 newlength = length;
21066 if ((length >= 3 && (((jschar) (((js_A[js_Y[(js_X[(uint16)((cp)[0])>>6]<<6)|(((cp)[0])&0x3F)]]) & 0x00200000) ? ((cp)[0]) + ((int32)(js_A[js_Y[(js_X[(uint16)((cp)[0])>>6]<<6)|(((cp)[0])&0x3F)]]) >> 22) : ((cp)[0]))) == 'x' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((cp)[1])>>6]<<6)|(((cp)[1])&0x3F)]]) & 0x00200000) ? ((cp)[1]) + ((int32)(js_A[js_Y[(js_X[(uint16)((cp)[1])>>6]<<6)|(((cp)[1])&0x3F)]]) >> 22) : ((cp)[1]))) == 'm' && ((jschar) (((js_A[js_Y[(js_X[(uint16)((cp)[2])>>6]<<6)|(((cp)[2])&0x3F)]]) & 0x00200000) ? ((cp)[2]) + ((int32)(js_A[js_Y[(js_X[(uint16)((cp)[2])>>6]<<6)|(((cp)[2])&0x3F)]]) >> 22) : ((cp)[2]))) == 'l')) || !IsXMLName(cp, length)) {
21067 newlength = length + 2 + (size_t) log10((double) decls->length);
21069 cx->malloc((newlength + 1) * sizeof(jschar));
21073 for (i = 0; i < newlength; i++)
21079 for (i = 0, n = decls->length; i < n; i++) {
21080 ns = (((i) < (decls)->length) ? (JSObject *) (decls)->vector[i] : __null);
21081 if (ns && (nsprefix = ns->getNamePrefix()) &&
21082 nsprefix->length() == newlength &&
21083 !memcmp(nsprefix->chars(), bp,
21084 newlength * sizeof(jschar))) {
21086 newlength = length + 2 + (size_t) log10((double) n);
21088 cx->malloc((newlength + 1) * sizeof(jschar));
21091 memcpy((bp), (cp), (length) * sizeof(jschar));
21095 dp = bp + length + 2 + (size_t) log10((double) serial);
21097 for (m = serial; m != 0; m /= 10)
21098 *--dp = (jschar)('0' + m % 10);
21107 offset = cp - start;
21108 prefix = js_NewDependentString(cx, uri, offset, length);
21110 prefix = js_NewString(cx, bp, newlength);
21117 namespace_match(const void *a, const void *b)
21119 const JSObject *nsa = (const JSObject *) a;
21120 const JSObject *nsb = (const JSObject *) b;
21121 JSLinearString *prefixa, *prefixb = nsb->getNamePrefix();
21123 prefixa = nsa->getNamePrefix();
21124 return prefixa && EqualStrings(prefixa, prefixb);
21126 return EqualStrings(nsa->getNameURI(), nsb->getNameURI());
21129 XMLToXMLString(JSContext *cx, JSXML *xml, const JSXMLArray *ancestorNSes,
21130 uint32 indentLevel)
21132 JSBool pretty, indentKids;
21133 StringBuffer sb(cx);
21135 JSLinearString *prefix, *nsuri;
21136 uint32 i, n, nextIndentLevel;
21137 JSObject *ns, *ns2;
21138 AutoNamespaceArray empty(cx), decls(cx), ancdecls(cx);
21139 if (!GetBooleanXMLSetting(cx, js_prettyPrinting_str, &pretty))
21142 if (!sb.appendN(' ', indentLevel & ~0x80000000))
21146 switch (xml->xml_class) {
21147 case JSXML_CLASS_TEXT:
21149 str = ChompXMLWhitespace(cx, xml->u.value);
21153 str = xml->u.value;
21155 return EscapeElementValue(cx, sb, str, indentLevel & 0x80000000);
21156 case JSXML_CLASS_ATTRIBUTE:
21157 return EscapeAttributeValue(cx, sb, xml->u.value,
21158 (indentLevel & 0x80000000) != 0);
21159 case JSXML_CLASS_COMMENT:
21160 return MakeXMLCommentString(cx, sb, xml->u.value);
21161 case JSXML_CLASS_PROCESSING_INSTRUCTION:
21162 return MakeXMLPIString(cx, sb, xml->name->getQNameLocalName(),
21164 case JSXML_CLASS_LIST:
21166 JSXMLArrayCursor cursor(&xml->u.list.kids);
21168 while (JSXML *kid = (JSXML *) cursor.getNext()) {
21169 if (pretty && i != 0) {
21170 if (!sb.append('\n'))
21173 JSString *kidstr = XMLToXMLString(cx, kid, ancestorNSes, indentLevel);
21174 if (!kidstr || !sb.append(kidstr))
21180 return cx->runtime->emptyString;
21181 return sb.finishString();
21184 if (!js_EnterLocalRootScope(cx))
21187 ancestorNSes = &empty.array;
21189 JSXMLArrayCursor cursor(&xml->u.elem.namespaces);
21190 while ((ns = (JSObject *) cursor.getNext()) != __null) {
21191 if (!IsDeclared(ns))
21193 if (!(XMLArrayFindMember(ancestorNSes, (void *)(ns), namespace_identity) != ((uint32) -1))) {
21194 ns2 = NewXMLNamespace(cx, ns->getNamePrefix(), ns->getNameURI(), (JSIntn)1);
21195 if (!ns2 || !XMLArrayAddMember(cx, &decls.array, (&decls.array)->length, (void *)((ns2))))
21200 if (!ancdecls.array.setCapacity(cx, ancestorNSes->length + decls.length()))
21202 for (i = 0, n = ancestorNSes->length; i < n; i++) {
21203 ns2 = (((i) < (ancestorNSes)->length) ? (JSObject *) (ancestorNSes)->vector[i] : __null);
21207 if (!XMLArrayAddMember(cx, &ancdecls.array, (&ancdecls.array)->length, (void *)((ns2))))
21210 for (i = 0, n = decls.length(); i < n; i++) {
21211 ns2 = (((i) < (&decls.array)->length) ? (JSObject *) (&decls.array)->vector[i] : __null);
21215 if (!XMLArrayAddMember(cx, &ancdecls.array, (&ancdecls.array)->length, (void *)((ns2))))
21218 ns = GetNamespace(cx, xml->name, &ancdecls.array);
21221 prefix = ns->getNamePrefix();
21223 nsuri = ns->getNameURI();
21224 if (!xml->name->getNamePrefix()) {
21225 prefix = cx->runtime->emptyString;
21227 prefix = GeneratePrefix(cx, nsuri, &ancdecls.array);
21231 ns = NewXMLNamespace(cx, prefix, nsuri, (JSIntn)1);
21234 if (prefix->empty()) {
21235 i = XMLArrayFindMember(&decls.array, ns, namespace_match);
21236 if (i != ((uint32) -1))
21237 XMLArrayDelete(cx, &decls.array, i, (JSIntn)1);
21239 if (!XMLArrayAddMember(cx, &ancdecls.array, (&ancdecls.array)->length, (void *)((ns))) ||
21240 !XMLArrayAddMember(cx, &decls.array, (&decls.array)->length, (void *)((ns)))) {
21244 if (!sb.append('<'))
21246 if (!prefix->empty()) {
21247 if (!sb.append(prefix) || !sb.append(':'))
21250 if (!sb.append(xml->name->getQNameLocalName()))
21253 JSXMLArrayCursor cursor(&xml->u.elem.attrs);
21254 while (JSXML *attr = (JSXML *) cursor.getNext()) {
21255 if (!sb.append(' '))
21257 ns2 = GetNamespace(cx, attr->name, &ancdecls.array);
21260 prefix = ns2->getNamePrefix();
21262 prefix = GeneratePrefix(cx, ns2->getNameURI(), &ancdecls.array);
21265 ns2 = NewXMLNamespace(cx, prefix, ns2->getNameURI(), (JSIntn)1);
21268 if (!XMLArrayAddMember(cx, &ancdecls.array, (&ancdecls.array)->length, (void *)((ns2))) ||
21269 !XMLArrayAddMember(cx, &decls.array, (&decls.array)->length, (void *)((ns2)))) {
21273 if (!prefix->empty()) {
21274 if (!sb.append(prefix) || !sb.append(':'))
21277 if (!sb.append(attr->name->getQNameLocalName()))
21279 if (!AppendAttributeValue(cx, sb, attr->u.value))
21284 JSXMLArrayCursor cursor(&decls.array);
21285 while (JSObject *ns3 = (JSObject *) cursor.getNext()) {
21287 if (!sb.append(" xmlns"))
21289 prefix = ns3->getNamePrefix();
21291 prefix = GeneratePrefix(cx, ns3->getNameURI(), &ancdecls.array);
21294 ns3->setNamePrefix(prefix);
21296 if (!prefix->empty()) {
21297 if (!sb.append(':') || !sb.append(prefix))
21300 if (!AppendAttributeValue(cx, sb, ns3->getNameURI()))
21304 n = xml->u.list.kids.length;
21306 if (!sb.append("/>"))
21309 if (!sb.append('>'))
21313 indentKids = n > 1 ||
21315 (kid = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null)) &&
21316 kid->xml_class != JSXML_CLASS_TEXT);
21318 if (pretty && indentKids) {
21319 if (!GetUint32XMLSetting(cx, js_prettyIndent_str, &i))
21321 nextIndentLevel = indentLevel + i;
21323 nextIndentLevel = indentLevel & 0x80000000;
21326 JSXMLArrayCursor cursor(&xml->u.list.kids);
21327 while (JSXML *kid = (JSXML *) cursor.getNext()) {
21328 if (pretty && indentKids) {
21329 if (!sb.append('\n'))
21332 JSString *kidstr = XMLToXMLString(cx, kid, &ancdecls.array, nextIndentLevel);
21335 if (!sb.append(kidstr))
21339 if (pretty && indentKids) {
21340 if (!sb.append('\n') ||
21341 !sb.appendN(' ', indentLevel & ~0x80000000))
21344 if (!sb.append("</"))
21346 prefix = ns->getNamePrefix();
21347 if (prefix && !prefix->empty()) {
21348 if (!sb.append(prefix) || !sb.append(':'))
21351 if (!sb.append(xml->name->getQNameLocalName()) || !sb.append('>'))
21354 str = sb.finishString();
21356 js_LeaveLocalRootScopeWithResult(cx, str);
21360 ToXMLString(JSContext *cx, jsval v, uint32 toSourceFlag)
21365 if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
21366 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null,
21367 JSMSG_BAD_XML_CONVERSION,
21368 JSVAL_IS_NULL(v) ? js_null_str : js_undefined_str);
21371 if (JSVAL_IS_BOOLEAN(v) || JSVAL_IS_NUMBER(v))
21372 return js_ValueToString(cx, Valueify(v));
21373 if (JSVAL_IS_STRING(v)) {
21374 StringBuffer sb(cx);
21375 return EscapeElementValue(cx, sb, JSVAL_TO_STRING(v), toSourceFlag);
21377 obj = JSVAL_TO_OBJECT(v);
21378 if (!obj->isXML()) {
21379 if (!DefaultValue(cx, obj, JSTYPE_STRING, Valueify(&v)))
21381 str = js_ValueToString(cx, Valueify(v));
21384 StringBuffer sb(cx);
21385 return EscapeElementValue(cx, sb, str, toSourceFlag);
21387 xml = (JSXML *) obj->getPrivate();
21388 return XMLToXMLString(cx, xml, __null, toSourceFlag | 0);
21391 ToAttributeName(JSContext *cx, jsval v)
21393 JSLinearString *name, *uri, *prefix;
21397 if (JSVAL_IS_STRING(v)) {
21398 name = JSVAL_TO_STRING(v)->ensureLinear(cx);
21401 uri = prefix = cx->runtime->emptyString;
21403 if (JSVAL_IS_PRIMITIVE(v)) {
21404 ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_BAD_XML_ATTR_NAME, 0, Valueify(v), __null, __null, __null))
21408 obj = JSVAL_TO_OBJECT(v);
21409 clasp = obj->getClass();
21410 if (clasp == &js_AttributeNameClass)
21412 if (clasp == &js_QNameClass) {
21414 uri = qn->getNameURI();
21415 prefix = qn->getNamePrefix();
21416 name = qn->getQNameLocalName();
21418 if (clasp == &js_AnyNameClass) {
21419 name = (cx->runtime->atomState.starAtom);
21421 JSString *str = js_ValueToString(cx, Valueify(v));
21424 name = str->ensureLinear(cx);
21428 uri = prefix = cx->runtime->emptyString;
21431 qn = NewXMLAttributeName(cx, uri, prefix, name);
21437 ReportBadXMLName(JSContext *cx, const Value &idval)
21439 ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_BAD_XML_NAME, 0, idval, __null, __null, __null));
21442 IsFunctionQName(JSContext *cx, JSObject *qn, jsid *funidp)
21445 JSLinearString *uri;
21446 atom = cx->runtime->atomState.functionNamespaceURIAtom;
21447 uri = qn->getNameURI();
21450 EqualStrings(uri, (atom)))) {
21451 return JS_ValueToId(cx, STRING_TO_JSVAL(qn->getQNameLocalName()), funidp);
21453 *funidp = ((jsid)0x2);
21457 js_IsFunctionQName(JSContext *cx, JSObject *obj, jsid *funidp)
21459 if (obj->getClass() == &js_QNameClass)
21460 return IsFunctionQName(cx, obj, funidp);
21461 *funidp = ((jsid)0x2);
21465 ToXMLName(JSContext *cx, jsval v, jsid *funidp)
21467 JSAtom *atomizedName;
21472 if (JSVAL_IS_STRING(v)) {
21473 name = JSVAL_TO_STRING(v);
21475 if (JSVAL_IS_PRIMITIVE(v)) {
21476 ReportBadXMLName(cx, Valueify(v));
21479 obj = JSVAL_TO_OBJECT(v);
21480 clasp = obj->getClass();
21481 if (clasp == &js_AttributeNameClass || clasp == &js_QNameClass)
21483 if (clasp == &js_AnyNameClass) {
21484 name = (cx->runtime->atomState.starAtom);
21487 name = js_ValueToString(cx, Valueify(v));
21491 atomizedName = js_AtomizeString(cx, name, 0);
21494 if (js_IdIsIndex(ATOM_TO_JSID(atomizedName), &index))
21496 if (*atomizedName->chars() == '@') {
21497 name = js_NewDependentString(cx, name, 1, name->length() - 1);
21500 *funidp = ((jsid)0x2);
21501 return ToAttributeName(cx, STRING_TO_JSVAL(name));
21504 v = STRING_TO_JSVAL(name);
21505 obj = js_ConstructObject(cx, &js_QNameClass, __null, __null, 1, Valueify(&v));
21509 if (!IsFunctionQName(cx, obj, funidp))
21513 JSAutoByteString bytes;
21514 if (js_ValueToPrintable(cx, StringValue(name), &bytes))
21515 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_BAD_XML_NAME, bytes.ptr());
21519 AddInScopeNamespace(JSContext *cx, JSXML *xml, JSObject *ns)
21521 JSLinearString *prefix, *prefix2;
21522 JSObject *match, *ns2;
21524 if (xml->xml_class != JSXML_CLASS_ELEMENT)
21526 prefix = ns->getNamePrefix();
21529 for (i = 0, n = xml->u.elem.namespaces.length; i < n; i++) {
21530 ns2 = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null);
21531 if (ns2 && EqualStrings(ns2->getNameURI(), ns->getNameURI())) {
21536 if (!match && !XMLArrayAddMember(cx, &xml->u.elem.namespaces, n, (void *)(ns)))
21539 if (prefix->empty() && xml->name->getNameURI()->empty())
21543 for (i = 0, n = xml->u.elem.namespaces.length; i < n; i++) {
21544 ns2 = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null);
21545 if (ns2 && (prefix2 = ns2->getNamePrefix()) &&
21546 EqualStrings(prefix2, prefix)) {
21552 if (match && !EqualStrings(match->getNameURI(), ns->getNameURI())) {
21553 ns2 = ((JSObject *) XMLArrayDelete(cx, &xml->u.elem.namespaces, m, (JSIntn)1))
21556 match->clearNamePrefix();
21557 if (!AddInScopeNamespace(cx, xml, match))
21560 if (!XMLArrayAddMember(cx, &xml->u.elem.namespaces, (&xml->u.elem.namespaces)->length, (void *)((ns))))
21566 Append(JSContext *cx, JSXML *list, JSXML *xml)
21571 i = list->u.list.kids.length;
21573 if (xml->xml_class == JSXML_CLASS_LIST) {
21574 list->u.list.target = xml->u.list.target;
21575 list->u.list.targetprop = xml->u.list.targetprop;
21576 n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0);
21578 if (!list->u.list.kids.setCapacity(cx, k))
21580 for (j = 0; j < n; j++) {
21581 kid = (((j) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[j] : __null);
21583 do { if ((&list->u.list.kids)->length <= (i + j)) (&list->u.list.kids)->length = (i + j) + 1; ((&list->u.list.kids)->vector[i + j] = (void *)(kid)); } while (0);
21587 list->u.list.target = xml->parent;
21588 if (xml->xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION)
21589 list->u.list.targetprop = __null;
21591 list->u.list.targetprop = xml->name;
21592 if (!XMLArrayAddMember(cx, &list->u.list.kids, i, (void *)(xml)))
21597 DeepCopyInLRS(JSContext *cx, JSXML *xml, uintN flags);
21599 DeepCopy(JSContext *cx, JSXML *xml, JSObject *obj, uintN flags)
21602 if (!js_EnterLocalRootScope(cx))
21604 copy = DeepCopyInLRS(cx, xml, flags);
21607 obj->setPrivate(copy);
21608 copy->object = obj;
21609 } else if (!js_GetXMLObject(cx, copy)) {
21613 js_LeaveLocalRootScopeWithResult(cx, copy);
21617 DeepCopySetInLRS(JSContext *cx, JSXMLArray *from, JSXMLArray *to, JSXML *parent,
21624 if (!to->setCapacity(cx, n))
21626 JSXMLArrayCursor cursor(from);
21628 while (JSXML *kid = (JSXML *) cursor.getNext()) {
21629 if ((flags & ((JSUint32)1 << (0))) &&
21630 kid->xml_class == JSXML_CLASS_COMMENT) {
21633 if ((flags & ((JSUint32)1 << (1))) &&
21634 kid->xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION) {
21637 if ((flags & ((JSUint32)1 << (2))) &&
21638 (kid->xml_flags & 0x1)) {
21641 kid2 = DeepCopyInLRS(cx, kid, flags);
21646 if ((flags & ((JSUint32)1 << (2))) &&
21647 n > 1 && kid2->xml_class == JSXML_CLASS_TEXT) {
21648 str = ChompXMLWhitespace(cx, kid2->u.value);
21653 kid2->u.value = str;
21655 do { if ((to)->length <= (j)) (to)->length = (j) + 1; ((to)->vector[j] = (void *)(kid2)); } while (0);
21657 if (parent->xml_class != JSXML_CLASS_LIST)
21658 kid2->parent = parent;
21665 DeepCopyInLRS(JSContext *cx, JSXML *xml, uintN flags)
21671 JSObject *ns, *ns2;
21672 do { int stackDummy_; if (!((jsuword)(&stackDummy_) > cx->stackLimit)) { js_ReportOverRecursed(cx); return __null; } } while (0);
21673 copy = js_NewXML(cx, JSXMLClass(xml->xml_class));
21678 qn = NewXMLQName(cx, qn->getNameURI(), qn->getNamePrefix(), qn->getQNameLocalName());
21685 copy->xml_flags = xml->xml_flags;
21686 if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) {
21687 copy->u.value = xml->u.value;
21690 ok = DeepCopySetInLRS(cx, &xml->u.list.kids, ©->u.list.kids, copy, flags);
21693 if (xml->xml_class == JSXML_CLASS_LIST) {
21694 copy->u.list.target = xml->u.list.target;
21695 copy->u.list.targetprop = xml->u.list.targetprop;
21697 n = xml->u.elem.namespaces.length;
21698 ok = copy->u.elem.namespaces.setCapacity(cx, n);
21701 for (i = 0; i < n; i++) {
21702 ns = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null);
21705 ns2 = NewXMLNamespace(cx, ns->getNamePrefix(), ns->getNameURI(),
21708 copy->u.elem.namespaces.length = i;
21712 do { if ((©->u.elem.namespaces)->length <= (i)) (©->u.elem.namespaces)->length = (i) + 1; ((©->u.elem.namespaces)->vector[i] = (void *)(ns2)); } while (0);
21714 ok = DeepCopySetInLRS(cx, &xml->u.elem.attrs, ©->u.elem.attrs, copy,
21726 DeleteByIndex(JSContext *cx, JSXML *xml, uint32 index)
21729 if ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) && index < xml->u.list.kids.length) {
21730 kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null);
21732 kid->parent = __null;
21733 XMLArrayDelete(cx, &xml->u.list.kids, index, (JSIntn)1);
21736 typedef JSBool (*JSXMLNameMatcher)(JSObject *nameqn, JSXML *xml);
21738 MatchAttrName(JSObject *nameqn, JSXML *attr)
21740 JSObject *attrqn = attr->name;
21741 JSLinearString *localName = nameqn->getQNameLocalName();
21742 JSLinearString *uri;
21743 return (((localName)->length() == 1 && *(localName)->chars() == '*') ||
21744 EqualStrings(attrqn->getQNameLocalName(), localName)) &&
21745 (!(uri = nameqn->getNameURI()) ||
21746 EqualStrings(attrqn->getNameURI(), uri));
21749 MatchElemName(JSObject *nameqn, JSXML *elem)
21751 JSLinearString *localName = nameqn->getQNameLocalName();
21752 JSLinearString *uri;
21753 return (((localName)->length() == 1 && *(localName)->chars() == '*') ||
21754 (elem->xml_class == JSXML_CLASS_ELEMENT &&
21755 EqualStrings(elem->name->getQNameLocalName(), localName))) &&
21756 (!(uri = nameqn->getNameURI()) ||
21757 (elem->xml_class == JSXML_CLASS_ELEMENT &&
21758 EqualStrings(elem->name->getNameURI(), uri)));
21761 DescendantsHelper(JSContext *cx, JSXML *xml, JSObject *nameqn, JSXML *list)
21765 do { int stackDummy_; if (!((jsuword)(&stackDummy_) > cx->stackLimit)) { js_ReportOverRecursed(cx); return (JSIntn)0; } } while (0);
21766 if (xml->xml_class == JSXML_CLASS_ELEMENT &&
21767 nameqn->getClass() == &js_AttributeNameClass) {
21768 for (i = 0, n = xml->u.elem.attrs.length; i < n; i++) {
21769 attr = (((i) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[i] : __null);
21770 if (attr && MatchAttrName(nameqn, attr)) {
21771 if (!Append(cx, list, attr))
21776 for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) {
21777 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
21780 if (nameqn->getClass() != &js_AttributeNameClass &&
21781 MatchElemName(nameqn, kid)) {
21782 if (!Append(cx, list, kid))
21785 if (!DescendantsHelper(cx, kid, nameqn, list))
21791 Descendants(JSContext *cx, JSXML *xml, jsval id)
21799 nameqn = ToXMLName(cx, id, &funid);
21802 listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
21805 list = (JSXML *) listobj->getPrivate();
21806 if (!JSID_IS_VOID(funid))
21808 list->name = nameqn;
21809 if (!js_EnterLocalRootScope(cx))
21811 if (xml->xml_class == JSXML_CLASS_LIST) {
21813 for (i = 0, n = xml->u.list.kids.length; i < n; i++) {
21814 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
21815 if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) {
21816 ok = DescendantsHelper(cx, kid, nameqn, list);
21822 ok = DescendantsHelper(cx, xml, nameqn, list);
21824 js_LeaveLocalRootScopeWithResult(cx, list);
21827 list->name = __null;
21831 XMLEquals(JSContext *cx, JSXML *xml, JSXML *vxml, JSBool *bp)
21833 JSObject *qn, *vqn;
21835 JSXML *kid, *vkid, *attr, *vattr;
21836 JSObject *xobj, *vobj;
21838 if (xml->xml_class != vxml->xml_class) {
21839 if (xml->xml_class == JSXML_CLASS_LIST && xml->u.list.kids.length == 1) {
21840 xml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null);
21844 if (vxml->xml_class == JSXML_CLASS_LIST && vxml->u.list.kids.length == 1) {
21845 vxml = (((0) < (&vxml->u.list.kids)->length) ? (JSXML *) (&vxml->u.list.kids)->vector[0] : __null);
21856 EqualStrings(qn->getQNameLocalName(), vqn->getQNameLocalName()) &&
21857 EqualStrings(qn->getNameURI(), vqn->getNameURI());
21859 *bp = vqn == __null;
21863 if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) {
21864 if (!EqualStrings(cx, xml->u.value, vxml->u.value, bp))
21866 } else if (xml->u.list.kids.length != vxml->u.list.kids.length) {
21870 JSXMLArrayCursor cursor(&xml->u.list.kids);
21871 JSXMLArrayCursor vcursor(&vxml->u.list.kids);
21873 kid = (JSXML *) cursor.getNext();
21874 vkid = (JSXML *) vcursor.getNext();
21875 if (!kid || !vkid) {
21876 *bp = !kid && !vkid;
21879 xobj = js_GetXMLObject(cx, kid);
21880 vobj = js_GetXMLObject(cx, vkid);
21881 if (!xobj || !vobj ||
21882 !js_TestXMLEquality(cx, ObjectValue(*xobj), ObjectValue(*vobj), bp))
21888 if (*bp && xml->xml_class == JSXML_CLASS_ELEMENT) {
21889 n = xml->u.elem.attrs.length;
21890 if (n != vxml->u.elem.attrs.length)
21892 for (i = 0; *bp && i < n; i++) {
21893 attr = (((i) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[i] : __null);
21896 j = XMLArrayFindMember(&vxml->u.elem.attrs, (void *)(attr), attr_identity);
21897 if (j == ((uint32) -1)) {
21901 vattr = (((j) < (&vxml->u.elem.attrs)->length) ? (JSXML *) (&vxml->u.elem.attrs)->vector[j] : __null);
21904 if (!EqualStrings(cx, attr->u.value, vattr->u.value, bp))
21912 Equals(JSContext *cx, JSXML *xml, jsval v, JSBool *bp)
21916 if (JSVAL_IS_PRIMITIVE(v)) {
21918 if (xml->xml_class == JSXML_CLASS_LIST) {
21919 if (xml->u.list.kids.length == 1) {
21920 vxml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null);
21923 vobj = js_GetXMLObject(cx, vxml);
21926 return js_TestXMLEquality(cx, ObjectValue(*vobj), Valueify(v), bp);
21928 if (JSVAL_IS_VOID(v) && xml->u.list.kids.length == 0)
21932 vobj = JSVAL_TO_OBJECT(v);
21933 if (!vobj->isXML()) {
21936 vxml = (JSXML *) vobj->getPrivate();
21937 if (!XMLEquals(cx, xml, vxml, bp))
21944 CheckCycle(JSContext *cx, JSXML *xml, JSXML *kid)
21949 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null,
21950 JSMSG_CYCLIC_VALUE, js_XML_str);
21953 } while ((xml = xml->parent) != __null);
21957 Insert(JSContext *cx, JSXML *xml, uint32 i, jsval v)
21963 if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE))
21967 if (!JSVAL_IS_PRIMITIVE(v)) {
21968 vobj = JSVAL_TO_OBJECT(v);
21969 if (vobj->isXML()) {
21970 vxml = (JSXML *) vobj->getPrivate();
21971 if (vxml->xml_class == JSXML_CLASS_LIST) {
21972 n = vxml->u.list.kids.length;
21975 for (j = 0; j < n; j++) {
21976 kid = (((j) < (&vxml->u.list.kids)->length) ? (JSXML *) (&vxml->u.list.kids)->vector[j] : __null);
21979 if (!CheckCycle(cx, xml, kid))
21982 } else if (vxml->xml_class == JSXML_CLASS_ELEMENT) {
21983 if (!CheckCycle(cx, xml, vxml))
21989 str = js_ValueToString(cx, Valueify(v));
21992 vxml = js_NewXML(cx, JSXML_CLASS_TEXT);
21995 vxml->u.value = str;
21997 if (i > xml->u.list.kids.length)
21998 i = xml->u.list.kids.length;
21999 if (!XMLArrayInsert(cx, &xml->u.list.kids, i, n))
22001 if (vxml->xml_class == JSXML_CLASS_LIST) {
22002 for (j = 0; j < n; j++) {
22003 kid = (((j) < (&vxml->u.list.kids)->length) ? (JSXML *) (&vxml->u.list.kids)->vector[j] : __null);
22007 do { if ((&xml->u.list.kids)->length <= (i + j)) (&xml->u.list.kids)->length = (i + j) + 1; ((&xml->u.list.kids)->vector[i + j] = (void *)(kid)); } while (0);
22010 vxml->parent = xml;
22011 do { if ((&xml->u.list.kids)->length <= (i)) (&xml->u.list.kids)->length = (i) + 1; ((&xml->u.list.kids)->vector[i] = (void *)(vxml)); } while (0);
22016 IndexToId(JSContext *cx, uint32 index, jsid *idp)
22020 if (index <= ((1 << 30) - 1)) {
22021 *idp = INT_TO_JSID(index);
22023 str = js_NumberToString(cx, (jsdouble) index);
22026 atom = js_AtomizeString(cx, str, 0);
22029 *idp = ATOM_TO_JSID(atom);
22034 Replace(JSContext *cx, JSXML *xml, uint32 i, jsval v)
22040 if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE))
22042 n = xml->u.list.kids.length;
22046 if (!JSVAL_IS_PRIMITIVE(v)) {
22047 vobj = JSVAL_TO_OBJECT(v);
22049 vxml = (JSXML *) vobj->getPrivate();
22051 switch (vxml ? JSXMLClass(vxml->xml_class) : JSXML_CLASS_LIMIT) {
22052 case JSXML_CLASS_ELEMENT:
22053 if (!CheckCycle(cx, xml, vxml))
22055 case JSXML_CLASS_COMMENT:
22056 case JSXML_CLASS_PROCESSING_INSTRUCTION:
22057 case JSXML_CLASS_TEXT:
22059 case JSXML_CLASS_LIST:
22061 DeleteByIndex(cx, xml, i);
22062 if (!Insert(cx, xml, i, v))
22066 str = js_ValueToString(cx, Valueify(v));
22069 vxml = js_NewXML(cx, JSXML_CLASS_TEXT);
22072 vxml->u.value = str;
22074 vxml->parent = xml;
22076 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
22078 kid->parent = __null;
22080 if (!XMLArrayAddMember(cx, &xml->u.list.kids, i, (void *)(vxml)))
22087 DeleteNamedProperty(JSContext *cx, JSXML *xml, JSObject *nameqn,
22091 uint32 index, deleteCount;
22093 JSXMLNameMatcher matcher;
22094 if (xml->xml_class == JSXML_CLASS_LIST) {
22095 array = &xml->u.list.kids;
22096 for (index = 0; index < array->length; index++) {
22097 kid = (((index) < (array)->length) ? (JSXML *) (array)->vector[index] : __null);
22098 if (kid && kid->xml_class == JSXML_CLASS_ELEMENT)
22099 DeleteNamedProperty(cx, kid, nameqn, attributes);
22101 } else if (xml->xml_class == JSXML_CLASS_ELEMENT) {
22103 array = &xml->u.elem.attrs;
22104 matcher = MatchAttrName;
22106 array = &xml->u.list.kids;
22107 matcher = MatchElemName;
22110 for (index = 0; index < array->length; index++) {
22111 kid = (((index) < (array)->length) ? (JSXML *) (array)->vector[index] : __null);
22112 if (kid && matcher(nameqn, kid)) {
22113 kid->parent = __null;
22114 XMLArrayDelete(cx, array, index, (JSIntn)0);
22116 } else if (deleteCount != 0) {
22117 do { if ((array)->length <= (index - deleteCount)) (array)->length = (index - deleteCount) + 1; ((array)->vector[index - deleteCount] = (void *)(array->vector[index])); } while (0)
22121 array->length -= deleteCount;
22125 DeleteListElement(JSContext *cx, JSXML *xml, uint32 index)
22127 JSXML *kid, *parent;
22130 if (index < xml->u.list.kids.length) {
22131 kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null);
22133 parent = kid->parent;
22137 if (kid->xml_class == JSXML_CLASS_ATTRIBUTE) {
22138 DeleteNamedProperty(cx, parent, kid->name, (JSIntn)1);
22140 kidIndex = XMLArrayFindMember(&parent->u.list.kids, (void *)(kid), __null)
22143 DeleteByIndex(cx, parent, kidIndex);
22146 XMLArrayDelete(cx, &xml->u.list.kids, index, (JSIntn)1);
22151 SyncInScopeNamespaces(JSContext *cx, JSXML *xml)
22153 JSXMLArray *nsarray;
22156 nsarray = &xml->u.elem.namespaces;
22157 while ((xml = xml->parent) != __null) {
22158 for (i = 0, n = xml->u.elem.namespaces.length; i < n; i++) {
22159 ns = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null);
22160 if (ns && !(XMLArrayFindMember(nsarray, (void *)(ns), namespace_identity) != ((uint32) -1))) {
22161 if (!XMLArrayAddMember(cx, nsarray, (nsarray)->length, (void *)((ns))))
22169 GetNamedProperty(JSContext *cx, JSXML *xml, JSObject* nameqn, JSXML *list)
22172 JSXMLNameMatcher matcher;
22174 if (xml->xml_class == JSXML_CLASS_LIST) {
22175 JSXMLArrayCursor cursor(&xml->u.list.kids);
22176 while (JSXML *kid = (JSXML *) cursor.getNext()) {
22177 if (kid->xml_class == JSXML_CLASS_ELEMENT &&
22178 !GetNamedProperty(cx, kid, nameqn, list)) {
22182 } else if (xml->xml_class == JSXML_CLASS_ELEMENT) {
22183 attrs = (nameqn->getClass() == &js_AttributeNameClass);
22185 array = &xml->u.elem.attrs;
22186 matcher = MatchAttrName;
22188 array = &xml->u.list.kids;
22189 matcher = MatchElemName;
22191 JSXMLArrayCursor cursor(array);
22192 while (JSXML *kid = (JSXML *) cursor.getNext()) {
22193 if (matcher(nameqn, kid)) {
22195 kid->xml_class == JSXML_CLASS_ELEMENT &&
22196 !SyncInScopeNamespaces(cx, kid)) {
22199 if (!Append(cx, list, kid))
22207 GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
22209 JSXML *xml, *list, *kid;
22211 JSObject *kidobj, *listobj;
22214 xml = (JSXML *) GetInstancePrivate(cx, obj, &js_XMLClass, __null);
22217 if (js_IdIsIndex(id, &index)) {
22218 if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE)) {
22219 *vp = (index == 0) ? OBJECT_TO_JSVAL(obj) : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
22221 if (index < xml->u.list.kids.length) {
22222 kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null);
22224 *vp = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
22227 kidobj = js_GetXMLObject(cx, kid);
22230 *vp = OBJECT_TO_JSVAL(kidobj);
22232 *vp = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
22237 nameqn = ToXMLName(cx, IdToJsval(id), &funid);
22240 if (!JSID_IS_VOID(funid))
22241 return GetXMLFunction(cx, obj, funid, vp);
22242 jsval roots[2] = { OBJECT_TO_JSVAL(nameqn), ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)) };
22243 AutoArrayRooter tvr(cx, (sizeof (roots) / sizeof (roots)[0]), Valueify(roots));
22244 listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
22247 roots[1] = OBJECT_TO_JSVAL(listobj);
22248 list = (JSXML *) listobj->getPrivate();
22249 if (!GetNamedProperty(cx, xml, nameqn, list))
22251 list->u.list.target = xml;
22252 list->u.list.targetprop = nameqn;
22253 *vp = OBJECT_TO_JSVAL(listobj);
22257 CopyOnWrite(JSContext *cx, JSXML *xml, JSObject *obj)
22260 xml = DeepCopy(cx, xml, obj, 0);
22267 KidToString(JSContext *cx, JSXML *xml, uint32 index)
22271 kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null);
22273 return cx->runtime->emptyString;
22274 kidobj = js_GetXMLObject(cx, kid);
22277 return js_ValueToString(cx, ObjectValue(*kidobj));
22280 ResolveValue(JSContext *cx, JSXML *list, JSXML **result);
22282 PutProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
22284 JSBool ok, primitiveAssign;
22285 enum { OBJ_ROOT, ID_ROOT, VAL_ROOT };
22286 JSXML *xml, *vxml, *rxml, *kid, *attr, *parent, *copy, *kid2, *match;
22287 JSObject *vobj, *nameobj, *attrobj, *parentobj, *kidobj, *copyobj;
22288 JSObject *targetprop, *nameqn, *attrqn;
22289 uint32 index, i, j, k, n, q, matchIndex;
22290 jsval attrval, nsval;
22293 xml = (JSXML *) GetInstancePrivate(cx, obj, &js_XMLClass, __null);
22296 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
22300 if (!JSVAL_IS_PRIMITIVE(*vp)) {
22301 vobj = JSVAL_TO_OBJECT(*vp);
22303 vxml = (JSXML *) vobj->getPrivate();
22305 ok = js_EnterLocalRootScope(cx);
22310 roots[OBJ_ROOT] = OBJECT_TO_JSVAL(obj);
22311 roots[ID_ROOT] = IdToJsval(id);
22312 roots[VAL_ROOT] = *vp;
22313 AutoArrayRooter tvr(cx, (sizeof (roots) / sizeof (roots)[0]), Valueify(roots));
22314 if (js_IdIsIndex(id, &index)) {
22315 if (xml->xml_class != JSXML_CLASS_LIST) {
22316 ReportBadXMLName(cx, IdToValue(id));
22320 if (xml->u.list.target) {
22321 ok = ResolveValue(cx, xml->u.list.target, &rxml);
22330 if (index >= xml->u.list.kids.length) {
22332 if (rxml->xml_class == JSXML_CLASS_LIST) {
22333 if (rxml->u.list.kids.length != 1)
22335 rxml = (((0) < (&rxml->u.list.kids)->length) ? (JSXML *) (&rxml->u.list.kids)->vector[0] : __null);
22338 ok = js_GetXMLObject(cx, rxml) != __null;
22342 if (!(((rxml)->xml_class) < JSXML_CLASS_ATTRIBUTE))
22345 targetprop = xml->u.list.targetprop;
22346 if (!targetprop || ((targetprop->getQNameLocalName())->length() == 1 && *(targetprop->getQNameLocalName())->chars() == '*')) {
22347 kid = js_NewXML(cx, JSXML_CLASS_TEXT);
22351 nameobj = targetprop;
22352 if (nameobj->getClass() == &js_AttributeNameClass) {
22353 ok = GetProperty(cx, rxml->object, id, &attrval);
22356 if (JSVAL_IS_PRIMITIVE(attrval))
22358 attrobj = JSVAL_TO_OBJECT(attrval);
22359 attr = (JSXML *) attrobj->getPrivate();
22360 if (((((attr)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (attr)->u.list.kids.length : 0) != 0)
22362 kid = js_NewXML(cx, JSXML_CLASS_ATTRIBUTE);
22364 kid = js_NewXML(cx, JSXML_CLASS_ELEMENT);
22368 kid->name = targetprop;
22370 kid->parent = rxml;
22371 i = xml->u.list.kids.length;
22372 if (kid->xml_class != JSXML_CLASS_ATTRIBUTE) {
22375 n = rxml->u.list.kids.length;
22377 if (n != 0 && i != 0) {
22378 for (n = j, j = 0; j < n; j++) {
22379 if (rxml->u.list.kids.vector[j] ==
22380 xml->u.list.kids.vector[i-1]) {
22385 kidobj = js_GetXMLObject(cx, kid);
22388 ok = Insert(cx, rxml, j + 1, OBJECT_TO_JSVAL(kidobj));
22393 kid->name = (vxml->xml_class == JSXML_CLASS_LIST)
22394 ? vxml->u.list.targetprop
22398 ok = Append(cx, xml, kid);
22403 vxml->xml_class == JSXML_CLASS_TEXT ||
22404 vxml->xml_class == JSXML_CLASS_ATTRIBUTE) {
22405 ok = JS_ConvertValue(cx, *vp, JSTYPE_STRING, vp);
22408 roots[VAL_ROOT] = *vp;
22410 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
22413 parent = kid->parent;
22414 if (kid->xml_class == JSXML_CLASS_ATTRIBUTE) {
22415 nameobj = kid->name;
22416 if (nameobj->getClass() != &js_AttributeNameClass) {
22417 nameobj = NewXMLAttributeName(cx, nameobj->getNameURI(), nameobj->getNamePrefix(),
22418 nameobj->getQNameLocalName());
22422 id = OBJECT_TO_JSID(nameobj);
22424 parentobj = js_GetXMLObject(cx, parent);
22427 ok = PutProperty(cx, parentobj, id, strict, vp);
22430 ok = GetProperty(cx, parentobj, id, vp);
22433 attr = (JSXML *) JSVAL_TO_OBJECT(*vp)->getPrivate();
22434 if (attr->u.list.kids.length != 0)
22435 xml->u.list.kids.vector[i] = attr->u.list.kids.vector[0];
22438 else if (vxml && vxml->xml_class == JSXML_CLASS_LIST) {
22439 copy = DeepCopyInLRS(cx, vxml, 0);
22442 copyobj = js_GetXMLObject(cx, copy);
22447 q = XMLArrayFindMember(&parent->u.list.kids, (void *)(kid), __null);
22449 ok = Replace(cx, parent, q, OBJECT_TO_JSVAL(copyobj));
22453 n = copy->u.list.kids.length;
22455 XMLArrayDelete(cx, &xml->u.list.kids, i, (JSIntn)1);
22457 ok = XMLArrayInsert(cx, &xml->u.list.kids, i + 1, n - 1);
22460 for (j = 0; j < n; j++)
22461 xml->u.list.kids.vector[i + j] = copy->u.list.kids.vector[j];
22464 else if (vxml || (((kid)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) {
22466 q = XMLArrayFindMember(&parent->u.list.kids, (void *)(kid), __null);
22468 ok = Replace(cx, parent, q, *vp);
22471 vxml = (((q) < (&parent->u.list.kids)->length) ? (JSXML *) (&parent->u.list.kids)->vector[q] : __null);
22474 roots[VAL_ROOT] = *vp = OBJECT_TO_JSVAL(vxml->object);
22478 vobj = ToXML(cx, *vp);
22481 roots[VAL_ROOT] = *vp = OBJECT_TO_JSVAL(vobj);
22482 vxml = (JSXML *) vobj->getPrivate();
22484 do { if ((&xml->u.list.kids)->length <= (i)) (&xml->u.list.kids)->length = (i) + 1; ((&xml->u.list.kids)->vector[i] = (void *)(vxml)); } while (0);
22487 kidobj = js_GetXMLObject(cx, kid);
22490 id = ATOM_TO_JSID(cx->runtime->atomState.starAtom);
22491 ok = PutProperty(cx, kidobj, id, strict, vp);
22496 nameqn = ToXMLName(cx, IdToJsval(id), &funid);
22499 if (!JSID_IS_VOID(funid)) {
22500 ok = js_SetProperty(cx, obj, funid, Valueify(vp), false);
22504 roots[ID_ROOT] = OBJECT_TO_JSVAL(nameobj);
22505 if (xml->xml_class == JSXML_CLASS_LIST) {
22506 n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0);
22510 ok = ResolveValue(cx, xml, &rxml);
22513 if (!rxml || ((((rxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (rxml)->u.list.kids.length : 0) != 1)
22515 ok = Append(cx, xml, rxml);
22520 xml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null);
22524 obj = js_GetXMLObject(cx, xml);
22527 roots[OBJ_ROOT] = OBJECT_TO_JSVAL(obj);
22529 if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE))
22532 vxml->xml_class == JSXML_CLASS_TEXT ||
22533 vxml->xml_class == JSXML_CLASS_ATTRIBUTE) {
22534 ok = JS_ConvertValue(cx, *vp, JSTYPE_STRING, vp);
22538 rxml = DeepCopyInLRS(cx, vxml, 0);
22539 if (!rxml || !js_GetXMLObject(cx, rxml))
22542 *vp = OBJECT_TO_JSVAL(vxml->object);
22544 roots[VAL_ROOT] = *vp;
22545 ok = js_GetDefaultXMLNamespace(cx, &nsval);
22548 if (nameobj->getClass() == &js_AttributeNameClass) {
22549 if (!js_IsXMLName(cx, OBJECT_TO_JSVAL(nameobj)))
22551 if (vxml && vxml->xml_class == JSXML_CLASS_LIST) {
22552 n = vxml->u.list.kids.length;
22554 *vp = STRING_TO_JSVAL(cx->runtime->emptyString);
22556 JSString *left = KidToString(cx, vxml, 0);
22559 JSString *space = cx->runtime->atomState.spaceAtom;
22560 for (i = 1; i < n; i++) {
22561 left = js_ConcatStrings(cx, left, space);
22564 JSString *right = KidToString(cx, vxml, i);
22567 left = js_ConcatStrings(cx, left, right);
22571 roots[VAL_ROOT] = *vp = STRING_TO_JSVAL(left);
22574 ok = JS_ConvertValue(cx, *vp, JSTYPE_STRING, vp);
22577 roots[VAL_ROOT] = *vp;
22580 for (i = 0, n = xml->u.elem.attrs.length; i < n; i++) {
22581 attr = (((i) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[i] : __null);
22584 attrqn = attr->name;
22585 if (EqualStrings(attrqn->getQNameLocalName(), nameqn->getQNameLocalName())) {
22586 JSLinearString *uri = nameqn->getNameURI();
22587 if (!uri || EqualStrings(attrqn->getNameURI(), uri)) {
22591 DeleteNamedProperty(cx, xml, attrqn, (JSIntn)1);
22599 JSLinearString *uri = nameqn->getNameURI();
22600 JSLinearString *left, *right;
22602 left = right = cx->runtime->emptyString;
22605 right = nameqn->getNamePrefix();
22607 nameqn = NewXMLQName(cx, left, right, nameqn->getQNameLocalName());
22610 attr = js_NewXML(cx, JSXML_CLASS_ATTRIBUTE);
22613 attr->parent = xml;
22614 attr->name = nameqn;
22615 ok = XMLArrayAddMember(cx, &xml->u.elem.attrs, n, (void *)(attr));
22618 ns = GetNamespace(cx, nameqn, __null);
22621 ok = AddInScopeNamespace(cx, xml, ns);
22625 attr->u.value = JSVAL_TO_STRING(*vp);
22628 if (!js_IsXMLName(cx, OBJECT_TO_JSVAL(nameobj)) &&
22629 !((nameqn->getQNameLocalName())->length() == 1 && *(nameqn->getQNameLocalName())->chars() == '*')) {
22633 primitiveAssign = !vxml && !((nameqn->getQNameLocalName())->length() == 1 && *(nameqn->getQNameLocalName())->chars() == '*');
22634 k = n = xml->u.list.kids.length;
22635 matchIndex = ((uint32) -1);
22639 kid = (((k) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[k] : __null);
22640 if (kid && MatchElemName(nameqn, kid)) {
22641 if (matchIndex != ((uint32) -1))
22642 DeleteByIndex(cx, xml, matchIndex);
22650 kid2->parent = xml;
22652 if (matchIndex == ((uint32) -1)) {
22654 if (primitiveAssign) {
22655 JSLinearString *uri = nameqn->getNameURI();
22656 JSLinearString *left, *right;
22658 ns = JSVAL_TO_OBJECT(nsval);
22659 left = ns->getNameURI();
22660 right = ns->getNamePrefix();
22663 right = nameqn->getNamePrefix();
22665 nameqn = NewXMLQName(cx, left, right, nameqn->getQNameLocalName());
22668 vobj = js_NewXMLObject(cx, JSXML_CLASS_ELEMENT);
22671 vxml = (JSXML *) vobj->getPrivate();
22672 vxml->parent = xml;
22673 vxml->name = nameqn;
22674 ns = GetNamespace(cx, nameqn, __null);
22677 ok = Replace(cx, xml, matchIndex, OBJECT_TO_JSVAL(vobj));
22680 ok = AddInScopeNamespace(cx, vxml, ns);
22685 if (primitiveAssign) {
22686 JSXMLArrayCursor cursor(&xml->u.list.kids);
22687 cursor.index = matchIndex;
22688 kid = (JSXML *) cursor.getCurrent();
22689 if ((((kid)->xml_class) < JSXML_CLASS_ATTRIBUTE)) {
22690 kid->u.list.kids.finish(cx);
22691 kid->u.list.kids.init();
22692 ok = kid->u.list.kids.setCapacity(cx, 1);
22695 ok = JS_ConvertValue(cx, *vp, JSTYPE_STRING, vp);
22696 if (ok && !JSVAL_TO_STRING(*vp)->empty()) {
22697 roots[VAL_ROOT] = *vp;
22698 if ((JSXML *) cursor.getCurrent() == kid)
22699 ok = Replace(cx, kid, 0, *vp);
22703 ok = Replace(cx, xml, matchIndex, *vp);
22707 js_LeaveLocalRootScope(cx);
22711 JSAutoByteString bytes;
22712 if (js_ValueToPrintable(cx, IdToValue(id), &bytes))
22713 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_BAD_XMLLIST_PUT, bytes.ptr());
22720 ResolveValue(JSContext *cx, JSXML *list, JSXML **result)
22722 JSXML *target, *base;
22723 JSObject *targetprop;
22726 if (list->xml_class != JSXML_CLASS_LIST || list->u.list.kids.length != 0) {
22727 if (!js_GetXMLObject(cx, list))
22732 target = list->u.list.target;
22733 targetprop = list->u.list.targetprop;
22734 if (!target || !targetprop || ((targetprop->getQNameLocalName())->length() == 1 && *(targetprop->getQNameLocalName())->chars() == '*')) {
22738 if (targetprop->getClass() == &js_AttributeNameClass) {
22742 if (!ResolveValue(cx, target, &base))
22748 if (!js_GetXMLObject(cx, base))
22750 id = OBJECT_TO_JSID(targetprop);
22751 if (!GetProperty(cx, base->object, id, &tv))
22753 target = (JSXML *) JSVAL_TO_OBJECT(tv)->getPrivate();
22754 if (((((target)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (target)->u.list.kids.length : 0) == 0) {
22755 if (base->xml_class == JSXML_CLASS_LIST && ((((base)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (base)->u.list.kids.length : 0) > 1) {
22759 tv = STRING_TO_JSVAL(cx->runtime->emptyString);
22760 if (!PutProperty(cx, base->object, id, false, &tv))
22762 if (!GetProperty(cx, base->object, id, &tv))
22764 target = (JSXML *) JSVAL_TO_OBJECT(tv)->getPrivate();
22770 HasNamedProperty(JSXML *xml, JSObject *nameqn)
22774 JSXMLNameMatcher matcher;
22776 if (xml->xml_class == JSXML_CLASS_LIST) {
22778 JSXMLArrayCursor cursor(&xml->u.list.kids);
22779 while (JSXML *kid = (JSXML *) cursor.getNext()) {
22780 found = HasNamedProperty(kid, nameqn);
22786 if (xml->xml_class == JSXML_CLASS_ELEMENT) {
22787 if (nameqn->getClass() == &js_AttributeNameClass) {
22788 array = &xml->u.elem.attrs;
22789 matcher = MatchAttrName;
22791 array = &xml->u.list.kids;
22792 matcher = MatchElemName;
22794 for (i = 0, n = array->length; i < n; i++) {
22795 JSXML *kid = (((i) < (array)->length) ? (JSXML *) (array)->vector[i] : __null);
22796 if (kid && matcher(nameqn, kid))
22803 HasIndexedProperty(JSXML *xml, uint32 i)
22805 if (xml->xml_class == JSXML_CLASS_LIST)
22806 return i < ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0);
22807 if (xml->xml_class == JSXML_CLASS_ELEMENT)
22812 HasSimpleContent(JSXML *xml);
22814 HasFunctionProperty(JSContext *cx, JSObject *obj, jsid funid, JSBool *found)
22820 if (!js_LookupProperty(cx, obj, funid, &pobj, &prop))
22823 xml = (JSXML *) obj->getPrivate();
22824 if (HasSimpleContent(xml)) {
22825 AutoObjectRooter tvr(cx);
22826 if (!js_GetClassPrototype(cx, __null, JSProto_String, tvr.addr()))
22829 if (!js_LookupProperty(cx, tvr.object(), funid, &pobj, &prop))
22833 *found = (prop != __null);
22837 HasProperty(JSContext *cx, JSObject *obj, jsval id, JSBool *found)
22844 xml = (JSXML *) obj->getPrivate();
22845 if (!js_IdValIsIndex(cx, id, &i, &isIndex))
22848 *found = HasIndexedProperty(xml, i);
22850 qn = ToXMLName(cx, id, &funid);
22853 if (!JSID_IS_VOID(funid)) {
22854 if (!HasFunctionProperty(cx, obj, funid, found))
22857 *found = HasNamedProperty(xml, qn);
22863 xml_finalize(JSContext *cx, JSObject *obj)
22865 JSXML *xml = (JSXML *) obj->getPrivate();
22868 if (xml->object == obj)
22869 xml->object = __null;
22872 xml_trace_vector(JSTracer *trc, JSXML **vec, uint32 len)
22876 for (i = 0; i < len; i++) {
22885 xml_lookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
22886 JSProperty **propp)
22893 xml = (JSXML *) obj->getPrivate();
22894 if (js_IdIsIndex(id, &i)) {
22895 found = HasIndexedProperty(xml, i);
22897 qn = ToXMLName(cx, IdToJsval(id), &funid);
22900 if (!JSID_IS_VOID(funid))
22901 return js_LookupProperty(cx, obj, funid, objp, propp);
22902 found = HasNamedProperty(xml, qn);
22908 const Shape *shape =
22909 js_AddNativeProperty(cx, obj, id,
22910 Valueify(GetProperty), Valueify(PutProperty),
22916 *propp = (JSProperty *) shape;
22921 xml_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *v,
22922 PropertyOp getter, StrictPropertyOp setter, uintN attrs)
22924 if (IsFunctionObject(*v) || getter || setter ||
22925 (attrs & 0x01) == 0 ||
22926 (attrs & (0x02 | 0x04 | 0x40))) {
22927 return js_DefineProperty(cx, obj, id, v, getter, setter, attrs);
22929 jsval tmp = Jsvalify(*v);
22930 return PutProperty(cx, obj, id, false, &tmp);
22933 xml_getProperty(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, Value *vp)
22935 if (JSID_IS_DEFAULT_XML_NAMESPACE(id)) {
22936 vp->setUndefined();
22939 return GetProperty(cx, obj, id, Jsvalify(vp));
22942 xml_setProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp, JSBool strict)
22944 return PutProperty(cx, obj, id, strict, Jsvalify(vp));
22947 xml_getAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp)
22950 if (!HasProperty(cx, obj, IdToJsval(id), &found))
22952 *attrsp = found ? 0x01 : 0;
22956 xml_setAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp)
22959 if (!HasProperty(cx, obj, IdToJsval(id), &found))
22962 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null,
22963 JSMSG_CANT_SET_XML_ATTRS);
22969 xml_deleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool strict)
22976 idval = IdToJsval(id);
22977 xml = (JSXML *) obj->getPrivate();
22978 if (js_IdIsIndex(id, &index)) {
22979 if (xml->xml_class != JSXML_CLASS_LIST) {
22980 ReportBadXMLName(cx, IdToValue(id));
22983 DeleteListElement(cx, xml, index);
22985 nameqn = ToXMLName(cx, idval, &funid);
22988 if (!JSID_IS_VOID(funid))
22989 return js_DeleteProperty(cx, obj, funid, rval, false);
22990 DeleteNamedProperty(cx, xml, nameqn,
22991 nameqn->getClass() == &js_AttributeNameClass);
22993 if (!obj->nativeEmpty() && !js_DeleteProperty(cx, obj, id, rval, false))
22995 rval->setBoolean(true);
22999 xml_convert(JSContext *cx, JSObject *obj, JSType type, Value *rval)
23001 return js_TryMethod(cx, obj, cx->runtime->atomState.toStringAtom, 0, __null, rval);
23004 xml_enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, Value *statep, jsid *idp)
23007 uint32 length, index;
23008 JSXMLArrayCursor *cursor;
23009 xml = (JSXML *)obj->getPrivate();
23010 length = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0);
23012 case JSENUMERATE_INIT:
23013 case JSENUMERATE_INIT_ALL:
23015 statep->setInt32(0);
23017 cursor = cx->create<JSXMLArrayCursor>(&xml->u.list.kids);
23020 statep->setPrivate(cursor);
23023 *idp = INT_TO_JSID(length);
23025 case JSENUMERATE_NEXT:
23026 if (statep->isInt32(0)) {
23030 cursor = (JSXMLArrayCursor *) statep->toPrivate();
23031 if (cursor && cursor->array && (index = cursor->index) < length) {
23032 *idp = INT_TO_JSID(index);
23033 cursor->index = index + 1;
23036 case JSENUMERATE_DESTROY:
23037 if (!statep->isInt32(0)) {
23038 cursor = (JSXMLArrayCursor *) statep->toPrivate();
23040 cx->destroy(cursor);
23048 xml_typeOf(JSContext *cx, JSObject *obj)
23053 xml_hasInstance(JSContext *cx, JSObject *obj, const Value *, JSBool *bp)
23058 xml_trace(JSTracer *trc, JSObject *obj)
23060 JSXML *xml = (JSXML *) obj->getPrivate();
23062 do { do { } while (0); JS_CallTracer((trc), (xml), (2)); } while (0);
23065 xml_fix(JSContext *cx, JSObject *obj, bool *success, AutoIdVector *props)
23072 xml_clear(JSContext *cx, JSObject *obj)
23076 HasSimpleContent(JSXML *xml)
23082 switch (xml->xml_class) {
23083 case JSXML_CLASS_COMMENT:
23084 case JSXML_CLASS_PROCESSING_INSTRUCTION:
23086 case JSXML_CLASS_LIST:
23087 if (xml->u.list.kids.length == 0)
23089 if (xml->u.list.kids.length == 1) {
23090 kid = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null);
23097 simple = (JSIntn)1;
23098 for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) {
23099 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
23100 if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) {
23101 simple = (JSIntn)0;
23109 js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, Value *vp)
23112 if (JSID_IS_OBJECT(id)) {
23114 if (!js_IsFunctionQName(cx, JSID_TO_OBJECT(id), &funid))
23116 if (!JSID_IS_VOID(funid))
23119 AutoValueRooter tvr(cx);
23120 JSBool ok = GetXMLFunction(cx, obj, id, Jsvalify(tvr.addr()));
23125 js_TestXMLEquality(JSContext *cx, const Value &v1, const Value &v2, JSBool *bp)
23130 JSString *str, *vstr;
23134 if (v1.isObject() && v1.toObject().isXML()) {
23135 obj = &v1.toObject();
23139 obj = &v2.toObject();
23142 xml = (JSXML *) obj->getPrivate();
23144 if (!JSVAL_IS_PRIMITIVE(v)) {
23145 vobj = JSVAL_TO_OBJECT(v);
23147 vxml = (JSXML *) vobj->getPrivate();
23149 if (xml->xml_class == JSXML_CLASS_LIST) {
23150 ok = Equals(cx, xml, v, bp);
23152 if (vxml->xml_class == JSXML_CLASS_LIST) {
23153 ok = Equals(cx, vxml, OBJECT_TO_JSVAL(obj), bp);
23155 if (((xml->xml_class == JSXML_CLASS_TEXT ||
23156 xml->xml_class == JSXML_CLASS_ATTRIBUTE) &&
23157 HasSimpleContent(vxml)) ||
23158 ((vxml->xml_class == JSXML_CLASS_TEXT ||
23159 vxml->xml_class == JSXML_CLASS_ATTRIBUTE) &&
23160 HasSimpleContent(xml))) {
23161 ok = js_EnterLocalRootScope(cx);
23163 ok = (str = js_ValueToString(cx, ObjectValue(*obj))) &&
23164 (vstr = js_ValueToString(cx, Valueify(v)));
23166 ok = EqualStrings(cx, str, vstr, bp);
23167 js_LeaveLocalRootScope(cx);
23170 ok = XMLEquals(cx, xml, vxml, bp);
23174 ok = js_EnterLocalRootScope(cx);
23176 if (HasSimpleContent(xml)) {
23177 ok = (str = js_ValueToString(cx, ObjectValue(*obj))) &&
23178 (vstr = js_ValueToString(cx, Valueify(v)));
23180 ok = EqualStrings(cx, str, vstr, bp);
23181 } else if (JSVAL_IS_STRING(v) || JSVAL_IS_NUMBER(v)) {
23182 str = js_ValueToString(cx, ObjectValue(*obj));
23185 } else if (JSVAL_IS_STRING(v)) {
23186 ok = EqualStrings(cx, str, JSVAL_TO_STRING(v), bp);
23188 ok = JS_ValueToNumber(cx, STRING_TO_JSVAL(str), &d);
23190 d2 = JSVAL_IS_INT(v) ? JSVAL_TO_INT(v)
23191 : JSVAL_TO_DOUBLE(v);
23192 *bp = ((d) == (d2));
23198 js_LeaveLocalRootScope(cx);
23204 js_ConcatenateXML(JSContext *cx, JSObject *obj, JSObject *robj, Value *vp)
23208 JSXML *list, *lxml, *rxml;
23210 ok = js_EnterLocalRootScope(cx);
23213 listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
23218 list = (JSXML *) listobj->getPrivate();
23219 lxml = (JSXML *) obj->getPrivate();
23220 ok = Append(cx, list, lxml);
23224 rxml = (JSXML *) robj->getPrivate();
23225 ok = Append(cx, list, rxml);
23228 vp->setObject(*listobj);
23230 js_LeaveLocalRootScopeWithResult(cx, *vp);
23233 __attribute__((visibility ("default"))) Class js_XMLClass = {
23235 (1<<0) | (1<<((8 + 8)+3)) |
23236 ((JSProto_XML) << ((8 + 8) + 8)),
23240 StrictPropertyStub,
23251 ((JSMarkOp)(xml_trace)),
23252 {__null,__null,__null,__null,__null},
23254 xml_lookupProperty,
23255 xml_defineProperty,
23260 xml_deleteProperty,
23270 StartNonListXMLMethod(JSContext *cx, jsval *vp, JSObject **objp)
23276 *objp = ToObject(cx, Valueify(&vp[1]));
23279 xml = (JSXML *) GetInstancePrivate(cx, *objp, &js_XMLClass, Valueify(vp + 2));
23280 if (!xml || xml->xml_class != JSXML_CLASS_LIST)
23282 if (xml->u.list.kids.length == 1) {
23283 xml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null);
23285 *objp = js_GetXMLObject(cx, xml);
23288 vp[1] = OBJECT_TO_JSVAL(*objp);
23292 fun = (((void) 0), (JSFunction *) (JSVAL_TO_OBJECT(*vp))->getPrivate());
23293 JS_snprintf(numBuf, sizeof numBuf, "%u", xml->u.list.kids.length);
23294 JSAutoByteString funNameBytes;
23295 if (const char *funName = GetFunctionNameBytes(cx, fun, &funNameBytes)) {
23296 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_NON_LIST_XML_METHOD,
23302 xml_addNamespace(JSContext *cx, uintN argc, jsval *vp)
23305 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23306 if (xml->xml_class != JSXML_CLASS_ELEMENT)
23308 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
23311 if (!NamespaceHelper(cx, __null, argc == 0 ? -1 : 1, vp + 2, vp))
23314 ns = JSVAL_TO_OBJECT(*vp);
23315 if (!AddInScopeNamespace(cx, xml, ns))
23317 ns->setNamespaceDeclared(((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1)));
23319 *vp = OBJECT_TO_JSVAL(obj);
23323 xml_appendChild(JSContext *cx, uintN argc, jsval *vp)
23328 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23329 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
23333 if (!js_GetAnyName(cx, &name))
23335 if (!GetProperty(cx, obj, name, &v))
23338 vobj = JSVAL_TO_OBJECT(v);
23340 vxml = (JSXML *) vobj->getPrivate();
23342 if (!IndexToId(cx, vxml->u.list.kids.length, &name))
23344 *vp = (argc != 0) ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
23345 if (!PutProperty(cx, JSVAL_TO_OBJECT(v), name, false, vp))
23347 *vp = OBJECT_TO_JSVAL(obj);
23351 xml_attribute(JSContext *cx, uintN argc, jsval *vp)
23355 js_ReportMissingArg(cx, Valueify(*vp), 0);
23358 qn = ToAttributeName(cx, vp[2]);
23361 vp[2] = OBJECT_TO_JSVAL(qn);
23362 jsid id = OBJECT_TO_JSID(qn);
23363 JSObject *obj = ToObject(cx, Valueify(&vp[1]));
23366 return GetProperty(cx, obj, id, vp);
23369 xml_attributes(JSContext *cx, uintN argc, jsval *vp)
23371 jsval name = STRING_TO_JSVAL((cx->runtime->atomState.starAtom));
23372 JSObject *qn = ToAttributeName(cx, name);
23375 AutoObjectRooter tvr(cx, qn);
23376 jsid id = OBJECT_TO_JSID(qn);
23377 JSObject *obj = ToObject(cx, Valueify(&vp[1]));
23380 return GetProperty(cx, obj, id, vp);
23383 xml_list_helper(JSContext *cx, JSXML *xml, jsval *rval)
23387 listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
23390 *rval = OBJECT_TO_JSVAL(listobj);
23391 list = (JSXML *) listobj->getPrivate();
23392 list->u.list.target = xml;
23396 ValueToId(JSContext *cx, jsval v, AutoIdRooter *idr)
23398 if (JSVAL_IS_INT(v)) {
23399 jsint i = JSVAL_TO_INT(v);
23400 if (INT_FITS_IN_JSID(i))
23401 *idr->addr() = INT_TO_JSID(i);
23402 else if (!js_ValueToStringId(cx, Valueify(v), idr->addr()))
23404 } else if (JSVAL_IS_STRING(v)) {
23405 JSAtom *atom = js_AtomizeString(cx, JSVAL_TO_STRING(v), 0);
23408 *idr->addr() = ATOM_TO_JSID(atom);
23409 } else if (!JSVAL_IS_PRIMITIVE(v)) {
23410 *idr->addr() = OBJECT_TO_JSID(JSVAL_TO_OBJECT(v));
23412 ReportBadXMLName(cx, Valueify(v));
23418 xml_child_helper(JSContext *cx, JSObject *obj, JSXML *xml, jsval name,
23426 if (!js_IdValIsIndex(cx, name, &index, &isIndex))
23429 if (index >= ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0)) {
23430 *rval = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
23432 kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null);
23434 *rval = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
23436 kidobj = js_GetXMLObject(cx, kid);
23439 *rval = OBJECT_TO_JSVAL(kidobj);
23444 AutoIdRooter idr(cx);
23445 if (!ValueToId(cx, name, &idr))
23447 return GetProperty(cx, obj, idr.id(), rval);
23450 xml_child(JSContext *cx, uintN argc, jsval *vp)
23453 JSXML *list, *vxml;
23455 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
23456 jsval name = argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
23457 if (xml->xml_class == JSXML_CLASS_LIST) {
23458 list = xml_list_helper(cx, xml, vp);
23461 JSXMLArrayCursor cursor(&xml->u.list.kids);
23462 while (JSXML *kid = (JSXML *) cursor.getNext()) {
23463 kidobj = js_GetXMLObject(cx, kid);
23466 if (!xml_child_helper(cx, kidobj, kid, name, &v))
23468 if (JSVAL_IS_VOID(v)) {
23472 vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
23473 if ((!(((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) || vxml->u.list.kids.length != 0) &&
23474 !Append(cx, list, vxml)) {
23480 if (!xml_child_helper(cx, obj, xml, name, vp))
23482 if (JSVAL_IS_VOID(*vp) && !xml_list_helper(cx, xml, vp))
23487 xml_childIndex(JSContext *cx, uintN argc, jsval *vp)
23491 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23492 parent = xml->parent;
23493 if (!parent || xml->xml_class == JSXML_CLASS_ATTRIBUTE) {
23494 *vp = DOUBLE_TO_JSVAL(js_NaN);
23497 for (i = 0, n = ((((parent)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (parent)->u.list.kids.length : 0); i < n; i++) {
23498 if ((((i) < (&parent->u.list.kids)->length) ? (JSXML *) (&parent->u.list.kids)->vector[i] : __null) == xml)
23502 if (i <= ((jsint)0x7fffffff))
23503 *vp = INT_TO_JSVAL(i);
23505 *vp = DOUBLE_TO_JSVAL(i);
23509 xml_children(JSContext *cx, uintN argc, jsval *vp)
23511 JSObject *obj = ToObject(cx, Valueify(&vp[1]));
23514 jsid name = ATOM_TO_JSID(cx->runtime->atomState.starAtom);
23515 return GetProperty(cx, obj, name, vp);
23518 xml_comments_helper(JSContext *cx, JSObject *obj, JSXML *xml, jsval *vp)
23520 JSXML *list, *kid, *vxml;
23525 list = xml_list_helper(cx, xml, vp);
23529 if (xml->xml_class == JSXML_CLASS_LIST) {
23530 for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) {
23531 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
23532 if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) {
23533 ok = js_EnterLocalRootScope(cx);
23536 kidobj = js_GetXMLObject(cx, kid);
23538 ok = xml_comments_helper(cx, kidobj, kid, &v);
23541 v = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
23543 js_LeaveLocalRootScopeWithResult(cx, Valueify(v));
23546 vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
23547 if (((((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (vxml)->u.list.kids.length : 0) != 0) {
23548 ok = Append(cx, list, vxml);
23555 for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) {
23556 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
23557 if (kid && kid->xml_class == JSXML_CLASS_COMMENT) {
23558 ok = Append(cx, list, kid);
23567 xml_comments(JSContext *cx, uintN argc, jsval *vp)
23569 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
23570 return xml_comments_helper(cx, obj, xml, vp);
23573 xml_contains(JSContext *cx, uintN argc, jsval *vp)
23578 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
23579 value = argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
23580 if (xml->xml_class == JSXML_CLASS_LIST) {
23582 JSXMLArrayCursor cursor(&xml->u.list.kids);
23583 while (JSXML *kid = (JSXML *) cursor.getNext()) {
23584 kidobj = js_GetXMLObject(cx, kid);
23585 if (!kidobj || !js_TestXMLEquality(cx, ObjectValue(*kidobj), Valueify(value), &eq))
23591 if (!js_TestXMLEquality(cx, ObjectValue(*obj), Valueify(value), &eq))
23594 *vp = BOOLEAN_TO_JSVAL(eq);
23598 xml_copy(JSContext *cx, uintN argc, jsval *vp)
23601 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
23602 copy = DeepCopy(cx, xml, __null, 0);
23605 *vp = OBJECT_TO_JSVAL(copy->object);
23609 xml_descendants(JSContext *cx, uintN argc, jsval *vp)
23613 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
23614 name = argc == 0 ? STRING_TO_JSVAL((cx->runtime->atomState.starAtom)) : vp[2];
23615 list = Descendants(cx, xml, name);
23618 *vp = OBJECT_TO_JSVAL(list->object);
23622 xml_elements_helper(JSContext *cx, JSObject *obj, JSXML *xml,
23623 JSObject *nameqn, jsval *vp)
23625 JSXML *list, *vxml;
23630 list = xml_list_helper(cx, xml, vp);
23633 list->u.list.targetprop = nameqn;
23635 if (xml->xml_class == JSXML_CLASS_LIST) {
23636 JSXMLArrayCursor cursor(&xml->u.list.kids);
23637 while (JSXML *kid = (JSXML *) cursor.getNext()) {
23638 if (kid->xml_class == JSXML_CLASS_ELEMENT) {
23639 ok = js_EnterLocalRootScope(cx);
23642 kidobj = js_GetXMLObject(cx, kid);
23644 ok = xml_elements_helper(cx, kidobj, kid, nameqn, &v);
23647 v = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
23649 js_LeaveLocalRootScopeWithResult(cx, Valueify(v));
23652 vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
23653 if (((((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (vxml)->u.list.kids.length : 0) != 0) {
23654 ok = Append(cx, list, vxml);
23661 for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) {
23662 JSXML *kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
23663 if (kid && kid->xml_class == JSXML_CLASS_ELEMENT &&
23664 MatchElemName(nameqn, kid)) {
23665 ok = Append(cx, list, kid);
23674 xml_elements(JSContext *cx, uintN argc, jsval *vp)
23679 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
23680 name = (argc == 0) ? STRING_TO_JSVAL((cx->runtime->atomState.starAtom)) : vp[2];
23681 nameqn = ToXMLName(cx, name, &funid);
23684 if (!JSID_IS_VOID(funid))
23685 return xml_list_helper(cx, xml, vp) != __null;
23686 return xml_elements_helper(cx, obj, xml, nameqn, vp);
23689 xml_hasOwnProperty(JSContext *cx, uintN argc, jsval *vp)
23693 JSObject *obj = ToObject(cx, Valueify(&vp[1]));
23696 if (!InstanceOf(cx, obj, &js_XMLClass, Valueify(vp + 2)))
23698 name = argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
23699 if (!HasProperty(cx, obj, name, &found))
23702 *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1));
23705 return js_HasOwnPropertyHelper(cx, js_LookupProperty, argc, Valueify(vp));
23708 xml_hasComplexContent(JSContext *cx, uintN argc, jsval *vp)
23713 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
23715 switch (xml->xml_class) {
23716 case JSXML_CLASS_ATTRIBUTE:
23717 case JSXML_CLASS_COMMENT:
23718 case JSXML_CLASS_PROCESSING_INSTRUCTION:
23719 case JSXML_CLASS_TEXT:
23720 *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)0));
23722 case JSXML_CLASS_LIST:
23723 if (xml->u.list.kids.length == 0) {
23724 *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1));
23725 } else if (xml->u.list.kids.length == 1) {
23726 kid = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null);
23728 kidobj = js_GetXMLObject(cx, kid);
23732 xml = (JSXML *) obj->getPrivate();
23737 *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)0));
23738 for (i = 0, n = xml->u.list.kids.length; i < n; i++) {
23739 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
23740 if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) {
23741 *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1));
23750 xml_hasSimpleContent(JSContext *cx, uintN argc, jsval *vp)
23752 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
23753 *vp = BOOLEAN_TO_JSVAL(HasSimpleContent(xml));
23757 FindInScopeNamespaces(JSContext *cx, JSXML *xml, JSXMLArray *nsarray)
23759 uint32 length, i, j, n;
23760 JSObject *ns, *ns2;
23761 JSLinearString *prefix, *prefix2;
23762 length = nsarray->length;
23764 if (xml->xml_class != JSXML_CLASS_ELEMENT)
23766 for (i = 0, n = xml->u.elem.namespaces.length; i < n; i++) {
23767 ns = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null);
23770 prefix = ns->getNamePrefix();
23771 for (j = 0; j < length; j++) {
23772 ns2 = (((j) < (nsarray)->length) ? (JSObject *) (nsarray)->vector[j] : __null);
23774 prefix2 = ns2->getNamePrefix();
23775 if ((prefix2 && prefix)
23776 ? EqualStrings(prefix2, prefix)
23777 : EqualStrings(ns2->getNameURI(), ns->getNameURI())) {
23783 if (!XMLArrayAddMember(cx, nsarray, (nsarray)->length, (void *)((ns))))
23788 } while ((xml = xml->parent) != __null);
23794 NamespacesToJSArray(JSContext *cx, JSXMLArray *array, jsval *rval)
23796 JSObject *arrayobj = NewDenseEmptyArray(cx);
23799 *rval = OBJECT_TO_JSVAL(arrayobj);
23800 AutoValueRooter tvr(cx);
23801 for (uint32 i = 0, n = array->length; i < n; i++) {
23802 JSObject *ns = (((i) < (array)->length) ? (JSObject *) (array)->vector[i] : __null);
23805 tvr.set(ObjectValue(*ns));
23806 if (!arrayobj->setProperty(cx, INT_TO_JSID(i), tvr.addr(), false))
23812 xml_inScopeNamespaces(JSContext *cx, uintN argc, jsval *vp)
23814 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23815 AutoNamespaceArray namespaces(cx);
23816 return FindInScopeNamespaces(cx, xml, &namespaces.array) &&
23817 NamespacesToJSArray(cx, &namespaces.array, vp);
23820 xml_insertChildAfter(JSContext *cx, uintN argc, jsval *vp)
23825 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23826 *vp = OBJECT_TO_JSVAL(obj);
23827 if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) || argc == 0)
23830 if (JSVAL_IS_NULL(arg)) {
23834 if (!(!JSVAL_IS_PRIMITIVE(arg) && JSVAL_TO_OBJECT(arg)->isXML()))
23836 kid = (JSXML *) JSVAL_TO_OBJECT(arg)->getPrivate();
23837 i = XMLArrayFindMember(&xml->u.list.kids, (void *)(kid), __null);
23838 if (i == ((uint32) -1))
23842 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
23845 return Insert(cx, xml, i, argc >= 2 ? vp[3] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)));
23848 xml_insertChildBefore(JSContext *cx, uintN argc, jsval *vp)
23853 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23854 *vp = OBJECT_TO_JSVAL(obj);
23855 if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) || argc == 0)
23858 if (JSVAL_IS_NULL(arg)) {
23860 i = xml->u.list.kids.length;
23862 if (!(!JSVAL_IS_PRIMITIVE(arg) && JSVAL_TO_OBJECT(arg)->isXML()))
23864 kid = (JSXML *) JSVAL_TO_OBJECT(arg)->getPrivate();
23865 i = XMLArrayFindMember(&xml->u.list.kids, (void *)(kid), __null);
23866 if (i == ((uint32) -1))
23869 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
23872 return Insert(cx, xml, i, argc >= 2 ? vp[3] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)));
23875 xml_length(JSContext *cx, uintN argc, jsval *vp)
23877 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
23878 if (xml->xml_class != JSXML_CLASS_LIST) {
23879 *vp = ((((uint64)(uint32)(JSVAL_TAG_INT32)) << 47) | (1));
23881 uint32 l = xml->u.list.kids.length;
23882 if (l <= ((jsint)0x7fffffff))
23883 *vp = INT_TO_JSVAL(l);
23885 *vp = DOUBLE_TO_JSVAL(l);
23890 xml_localName(JSContext *cx, uintN argc, jsval *vp)
23892 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23893 *vp = xml->name ? xml->name->getQNameLocalNameVal() : ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
23897 xml_name(JSContext *cx, uintN argc, jsval *vp)
23899 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23900 *vp = OBJECT_TO_JSVAL(xml->name);
23904 xml_namespace(JSContext *cx, uintN argc, jsval *vp)
23906 JSLinearString *prefix, *nsprefix;
23909 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23910 if (argc == 0 && !((uintN)(((xml)->xml_class) - JSXML_CLASS_ELEMENT) <= (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))) {
23911 *vp = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
23917 JSString *str = js_ValueToString(cx, Valueify(vp[2]));
23920 prefix = str->ensureLinear(cx);
23923 vp[2] = STRING_TO_JSVAL(prefix);
23925 AutoNamespaceArray inScopeNSes(cx);
23926 if (!FindInScopeNamespaces(cx, xml, &inScopeNSes.array))
23929 ns = GetNamespace(cx, xml->name, &inScopeNSes.array);
23934 for (i = 0, length = inScopeNSes.array.length; i < length; i++) {
23935 ns = (((i) < (&inScopeNSes.array)->length) ? (JSObject *) (&inScopeNSes.array)->vector[i] : __null);
23937 nsprefix = ns->getNamePrefix();
23938 if (nsprefix && EqualStrings(nsprefix, prefix))
23944 *vp = (!ns) ? ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)) : OBJECT_TO_JSVAL(ns);
23948 xml_namespaceDeclarations(JSContext *cx, uintN argc, jsval *vp)
23950 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23951 if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE))
23953 AutoNamespaceArray ancestors(cx);
23954 AutoNamespaceArray declared(cx);
23956 while ((yml = yml->parent) != __null) {
23958 for (uint32 i = 0, n = yml->u.elem.namespaces.length; i < n; i++) {
23959 JSObject *ns = (((i) < (&yml->u.elem.namespaces)->length) ? (JSObject *) (&yml->u.elem.namespaces)->vector[i] : __null);
23960 if (ns && !(XMLArrayFindMember(&ancestors.array, (void *)(ns), namespace_match) != ((uint32) -1))) {
23961 if (!XMLArrayAddMember(cx, &ancestors.array, (&ancestors.array)->length, (void *)((ns))))
23966 for (uint32 i = 0, n = xml->u.elem.namespaces.length; i < n; i++) {
23967 JSObject *ns = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null);
23970 if (!IsDeclared(ns))
23972 if (!(XMLArrayFindMember(&ancestors.array, (void *)(ns), namespace_match) != ((uint32) -1))) {
23973 if (!XMLArrayAddMember(cx, &declared.array, (&declared.array)->length, (void *)((ns))))
23977 return NamespacesToJSArray(cx, &declared.array, vp);
23979 static const char js_attribute_str[] = "attribute";
23980 static const char js_text_str[] = "text";
23981 const char *js_xml_class_str[] = {
23985 "processing-instruction",
23990 xml_nodeKind(JSContext *cx, uintN argc, jsval *vp)
23993 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
23994 str = JS_InternString(cx, js_xml_class_str[xml->xml_class]);
23997 *vp = STRING_TO_JSVAL(str);
24001 NormalizingDelete(JSContext *cx, JSXML *xml, uint32 index)
24003 if (xml->xml_class == JSXML_CLASS_LIST)
24004 DeleteListElement(cx, xml, index);
24006 DeleteByIndex(cx, xml, index);
24009 xml_normalize_helper(JSContext *cx, JSObject *obj, JSXML *xml)
24015 if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE))
24017 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
24020 for (i = 0, n = xml->u.list.kids.length; i < n; i++) {
24021 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
24024 if (kid->xml_class == JSXML_CLASS_ELEMENT) {
24025 kidobj = js_GetXMLObject(cx, kid);
24026 if (!kidobj || !xml_normalize_helper(cx, kidobj, kid))
24028 } else if (kid->xml_class == JSXML_CLASS_TEXT) {
24029 while (i + 1 < n &&
24030 (kid2 = (((i + 1) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i + 1] : __null)) &&
24031 kid2->xml_class == JSXML_CLASS_TEXT) {
24032 str = js_ConcatStrings(cx, kid->u.value, kid2->u.value);
24035 NormalizingDelete(cx, xml, i + 1);
24036 n = xml->u.list.kids.length;
24037 kid->u.value = str;
24039 if (kid->u.value->empty()) {
24040 NormalizingDelete(cx, xml, i);
24041 n = xml->u.list.kids.length;
24049 xml_normalize(JSContext *cx, uintN argc, jsval *vp)
24051 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
24052 *vp = OBJECT_TO_JSVAL(obj);
24053 return xml_normalize_helper(cx, obj, xml);
24056 xml_parent(JSContext *cx, uintN argc, jsval *vp)
24058 JSXML *parent, *kid;
24060 JSObject *parentobj;
24061 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
24062 parent = xml->parent;
24063 if (xml->xml_class == JSXML_CLASS_LIST) {
24064 *vp = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
24065 n = xml->u.list.kids.length;
24068 kid = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null);
24071 parent = kid->parent;
24072 for (i = 1; i < n; i++) {
24073 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
24074 if (kid && kid->parent != parent)
24079 *vp = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
24082 parentobj = js_GetXMLObject(cx, parent);
24085 *vp = OBJECT_TO_JSVAL(parentobj);
24089 xml_processingInstructions_helper(JSContext *cx, JSObject *obj, JSXML *xml,
24090 JSObject *nameqn, jsval *vp)
24092 JSXML *list, *vxml;
24097 list = xml_list_helper(cx, xml, vp);
24100 list->u.list.targetprop = nameqn;
24102 if (xml->xml_class == JSXML_CLASS_LIST) {
24103 JSXMLArrayCursor cursor(&xml->u.list.kids);
24104 while (JSXML *kid = (JSXML *) cursor.getNext()) {
24105 if (kid->xml_class == JSXML_CLASS_ELEMENT) {
24106 ok = js_EnterLocalRootScope(cx);
24109 kidobj = js_GetXMLObject(cx, kid);
24111 ok = xml_processingInstructions_helper(cx, kidobj, kid,
24115 v = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
24117 js_LeaveLocalRootScopeWithResult(cx, Valueify(v));
24120 vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
24121 if (((((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (vxml)->u.list.kids.length : 0) != 0) {
24122 ok = Append(cx, list, vxml);
24129 for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) {
24130 JSXML *kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
24131 if (kid && kid->xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION) {
24132 JSLinearString *localName = nameqn->getQNameLocalName();
24133 if (((localName)->length() == 1 && *(localName)->chars() == '*') ||
24134 EqualStrings(localName, kid->name->getQNameLocalName())) {
24135 ok = Append(cx, list, kid);
24145 xml_processingInstructions(JSContext *cx, uintN argc, jsval *vp)
24150 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
24151 name = (argc == 0) ? STRING_TO_JSVAL((cx->runtime->atomState.starAtom)) : vp[2];
24152 nameqn = ToXMLName(cx, name, &funid);
24155 vp[2] = OBJECT_TO_JSVAL(nameqn);
24156 if (!JSID_IS_VOID(funid))
24157 return xml_list_helper(cx, xml, vp) != __null;
24158 return xml_processingInstructions_helper(cx, obj, xml, nameqn, vp);
24161 xml_prependChild(JSContext *cx, uintN argc, jsval *vp)
24163 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
24164 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
24167 *vp = OBJECT_TO_JSVAL(obj);
24168 return Insert(cx, xml, 0, argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)));
24171 xml_propertyIsEnumerable(JSContext *cx, uintN argc, jsval *vp)
24175 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
24176 *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)0));
24178 if (!js_IdValIsIndex(cx, vp[2], &index, &isIndex))
24181 if (xml->xml_class == JSXML_CLASS_LIST) {
24182 *vp = BOOLEAN_TO_JSVAL(index < xml->u.list.kids.length);
24184 *vp = BOOLEAN_TO_JSVAL(index == 0);
24191 namespace_full_match(const void *a, const void *b)
24193 const JSObject *nsa = (const JSObject *) a;
24194 const JSObject *nsb = (const JSObject *) b;
24195 JSLinearString *prefixa = nsa->getNamePrefix();
24196 JSLinearString *prefixb;
24198 prefixb = nsb->getNamePrefix();
24199 if (prefixb && !EqualStrings(prefixa, prefixb))
24202 return EqualStrings(nsa->getNameURI(), nsb->getNameURI());
24205 xml_removeNamespace_helper(JSContext *cx, JSXML *xml, JSObject *ns)
24207 JSObject *thisns, *attrns;
24210 thisns = GetNamespace(cx, xml->name, &xml->u.elem.namespaces);
24214 for (i = 0, n = xml->u.elem.attrs.length; i < n; i++) {
24215 attr = (((i) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[i] : __null);
24218 attrns = GetNamespace(cx, attr->name, &xml->u.elem.namespaces);
24223 i = XMLArrayFindMember(&xml->u.elem.namespaces, (void *)(ns), namespace_full_match);
24224 if (i != ((uint32) -1))
24225 XMLArrayDelete(cx, &xml->u.elem.namespaces, i, (JSIntn)1);
24226 for (i = 0, n = xml->u.list.kids.length; i < n; i++) {
24227 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
24228 if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) {
24229 if (!xml_removeNamespace_helper(cx, kid, ns))
24236 xml_removeNamespace(JSContext *cx, uintN argc, jsval *vp)
24239 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
24240 if (xml->xml_class != JSXML_CLASS_ELEMENT)
24242 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
24245 if (!NamespaceHelper(cx, __null, argc == 0 ? -1 : 1, vp + 2, vp))
24248 ns = JSVAL_TO_OBJECT(*vp);
24249 if (!xml_removeNamespace_helper(cx, xml, ns))
24252 *vp = OBJECT_TO_JSVAL(obj);
24256 xml_replace(JSContext *cx, uintN argc, jsval *vp)
24262 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
24263 if (xml->xml_class != JSXML_CLASS_ELEMENT)
24266 value = STRING_TO_JSVAL((cx->runtime->atomState.typeAtoms[JSTYPE_VOID]));
24269 vxml = (!JSVAL_IS_PRIMITIVE(value) && JSVAL_TO_OBJECT(value)->isXML())
24270 ? (JSXML *) JSVAL_TO_OBJECT(value)->getPrivate()
24273 if (!JS_ConvertValue(cx, value, JSTYPE_STRING, &vp[3]))
24277 vxml = DeepCopy(cx, vxml, __null, 0);
24280 value = vp[3] = OBJECT_TO_JSVAL(vxml->object);
24283 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
24290 if (!js_IdValIsIndex(cx, vp[2], &index, &haveIndex))
24294 if (!QNameHelper(cx, __null, argc == 0 ? -1 : 1, vp + 2, vp))
24297 nameqn = JSVAL_TO_OBJECT(*vp);
24298 i = xml->u.list.kids.length;
24299 index = ((uint32) -1);
24302 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
24303 if (kid && MatchElemName(nameqn, kid)) {
24304 if (i != ((uint32) -1))
24305 DeleteByIndex(cx, xml, i);
24309 if (index == ((uint32) -1))
24312 if (!Replace(cx, xml, index, value))
24315 *vp = OBJECT_TO_JSVAL(obj);
24319 xml_setChildren(JSContext *cx, uintN argc, jsval *vp)
24322 if (!StartNonListXMLMethod(cx, vp, &obj))
24324 *vp = argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
24325 if (!PutProperty(cx, obj, ATOM_TO_JSID(cx->runtime->atomState.starAtom), false, vp))
24327 *vp = OBJECT_TO_JSVAL(obj);
24331 xml_setLocalName(JSContext *cx, uintN argc, jsval *vp)
24335 JSLinearString *namestr;
24336 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
24337 if (!((uintN)(((xml)->xml_class) - JSXML_CLASS_ELEMENT) <= (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT)))
24340 namestr = (cx->runtime->atomState.typeAtoms[JSTYPE_VOID]);
24343 if (!JSVAL_IS_PRIMITIVE(name) &&
24344 JSVAL_TO_OBJECT(name)->getClass() == &js_QNameClass) {
24345 nameqn = JSVAL_TO_OBJECT(name);
24346 namestr = nameqn->getQNameLocalName();
24348 if (!JS_ConvertValue(cx, name, JSTYPE_STRING, &vp[2]))
24351 namestr = JSVAL_TO_STRING(name)->ensureLinear(cx);
24356 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
24360 xml->name->setQNameLocalName(namestr);
24364 xml_setName(JSContext *cx, uintN argc, jsval *vp)
24369 JSXMLArray *nsarray;
24372 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
24373 if (!((uintN)(((xml)->xml_class) - JSXML_CLASS_ELEMENT) <= (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT)))
24376 name = STRING_TO_JSVAL((cx->runtime->atomState.typeAtoms[JSTYPE_VOID]));
24379 if (!JSVAL_IS_PRIMITIVE(name) &&
24380 JSVAL_TO_OBJECT(name)->getClass() == &js_QNameClass &&
24381 !(nameqn = JSVAL_TO_OBJECT(name))->getNameURI()) {
24382 name = vp[2] = nameqn->getQNameLocalNameVal();
24385 nameqn = js_ConstructObject(cx, &js_QNameClass, __null, __null, 1, Valueify(&name));
24388 if (xml->xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION)
24389 nameqn->setNameURI(cx->runtime->emptyString);
24390 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
24393 xml->name = nameqn;
24394 if (xml->xml_class == JSXML_CLASS_ELEMENT) {
24397 if (!xml->parent || xml->parent->xml_class != JSXML_CLASS_ELEMENT)
24399 nsowner = xml->parent;
24401 if (nameqn->getNamePrefix()) {
24402 ns = GetNamespace(cx, nameqn, &nsowner->u.elem.namespaces);
24405 if ((XMLArrayFindMember(&nsowner->u.elem.namespaces, (void *)(ns), __null) != ((uint32) -1)))
24409 nsarray = &nsowner->u.elem.namespaces;
24410 for (i = 0, n = nsarray->length; i < n; i++) {
24411 ns = (((i) < (nsarray)->length) ? (JSObject *) (nsarray)->vector[i] : __null);
24412 if (ns && EqualStrings(ns->getNameURI(), nameqn->getNameURI())) {
24413 nameqn->setNamePrefix(ns->getNamePrefix());
24417 ns = NewXMLNamespace(cx, __null, nameqn->getNameURI(), (JSIntn)1);
24421 if (!AddInScopeNamespace(cx, nsowner, ns))
24423 vp[0] = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
24427 xml_setNamespace(JSContext *cx, uintN argc, jsval *vp)
24433 JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0);
24434 if (!((uintN)(((xml)->xml_class) - JSXML_CLASS_ELEMENT) <= (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT)))
24436 xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj));
24439 ns = js_ConstructObject(cx, &js_NamespaceClass, __null, obj,
24440 argc == 0 ? 0 : 1, Valueify(vp + 2));
24443 vp[0] = OBJECT_TO_JSVAL(ns);
24444 ns->setNamespaceDeclared(((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1)));
24445 qnargv[0] = OBJECT_TO_JSVAL(ns);
24446 qnargv[1] = OBJECT_TO_JSVAL(xml->name);
24447 qn = js_ConstructObject(cx, &js_QNameClass, __null, __null, 2, Valueify(qnargv));
24451 if (xml->xml_class == JSXML_CLASS_ELEMENT) {
24454 if (!xml->parent || xml->parent->xml_class != JSXML_CLASS_ELEMENT)
24456 nsowner = xml->parent;
24458 if (!AddInScopeNamespace(cx, nsowner, ns))
24460 vp[0] = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
24464 xml_text_helper(JSContext *cx, JSObject *obj, JSXML *xml, jsval *vp)
24466 JSXML *list, *kid, *vxml;
24471 list = xml_list_helper(cx, xml, vp);
24474 if (xml->xml_class == JSXML_CLASS_LIST) {
24476 for (i = 0, n = xml->u.list.kids.length; i < n; i++) {
24477 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
24478 if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) {
24479 ok = js_EnterLocalRootScope(cx);
24482 kidobj = js_GetXMLObject(cx, kid);
24484 ok = xml_text_helper(cx, kidobj, kid, &v);
24487 v = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
24489 js_LeaveLocalRootScopeWithResult(cx, Valueify(v));
24492 vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
24493 if (((((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (vxml)->u.list.kids.length : 0) != 0 && !Append(cx, list, vxml))
24498 for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) {
24499 kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null);
24500 if (kid && kid->xml_class == JSXML_CLASS_TEXT) {
24501 if (!Append(cx, list, kid))
24509 xml_text(JSContext *cx, uintN argc, jsval *vp)
24511 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
24512 return xml_text_helper(cx, obj, xml, vp);
24515 xml_toString_helper(JSContext *cx, JSXML *xml)
24517 JSString *str, *kidstr;
24518 if (xml->xml_class == JSXML_CLASS_ATTRIBUTE ||
24519 xml->xml_class == JSXML_CLASS_TEXT) {
24520 return xml->u.value;
24522 if (!HasSimpleContent(xml))
24523 return ToXMLString(cx, OBJECT_TO_JSVAL(xml->object), 0);
24524 str = cx->runtime->emptyString;
24525 if (!js_EnterLocalRootScope(cx))
24527 JSXMLArrayCursor cursor(&xml->u.list.kids);
24528 while (JSXML *kid = (JSXML *) cursor.getNext()) {
24529 if (kid->xml_class != JSXML_CLASS_COMMENT &&
24530 kid->xml_class != JSXML_CLASS_PROCESSING_INSTRUCTION) {
24531 kidstr = xml_toString_helper(cx, kid);
24536 str = js_ConcatStrings(cx, str, kidstr);
24541 js_LeaveLocalRootScopeWithResult(cx, str);
24545 xml_toSource(JSContext *cx, uintN argc, jsval *vp)
24547 JSObject *obj = ToObject(cx, Valueify(&vp[1]));
24550 JSString *str = ToXMLString(cx, OBJECT_TO_JSVAL(obj), 0x80000000);
24553 *vp = STRING_TO_JSVAL(str);
24557 xml_toString(JSContext *cx, uintN argc, jsval *vp)
24560 JSObject *obj = ToObject(cx, Valueify(&vp[1])); if (!obj) return (JSIntn)0; JSXML *xml = (JSXML *)GetInstancePrivate(cx, obj, &js_XMLClass, Valueify(vp+2)); if (!xml) return (JSIntn)0;
24561 str = xml_toString_helper(cx, xml);
24564 *vp = STRING_TO_JSVAL(str);
24568 xml_toXMLString(JSContext *cx, uintN argc, jsval *vp)
24570 JSObject *obj = ToObject(cx, Valueify(&vp[1]));
24573 JSString *str = ToXMLString(cx, OBJECT_TO_JSVAL(obj), 0);
24576 *vp = STRING_TO_JSVAL(str);
24580 xml_valueOf(JSContext *cx, uintN argc, jsval *vp)
24582 JSObject *obj = ToObject(cx, Valueify(&vp[1]));
24585 *vp = OBJECT_TO_JSVAL(obj);
24588 static JSFunctionSpec xml_methods[] = {
24589 {"addNamespace", ((JSNative)(xml_addNamespace)), 1, (0) | 0x1000},
24590 {"appendChild", ((JSNative)(xml_appendChild)), 1, (0) | 0x1000},
24591 {js_attribute_str, ((JSNative)(xml_attribute)), 1, (0) | 0x1000},
24592 {"attributes", ((JSNative)(xml_attributes)), 0, (0) | 0x1000},
24593 {"child", ((JSNative)(xml_child)), 1, (0) | 0x1000},
24594 {"childIndex", ((JSNative)(xml_childIndex)), 0, (0) | 0x1000},
24595 {"children", ((JSNative)(xml_children)), 0, (0) | 0x1000},
24596 {"comments", ((JSNative)(xml_comments)), 0, (0) | 0x1000},
24597 {"contains", ((JSNative)(xml_contains)), 1, (0) | 0x1000},
24598 {"copy", ((JSNative)(xml_copy)), 0, (0) | 0x1000},
24599 {"descendants", ((JSNative)(xml_descendants)), 1, (0) | 0x1000},
24600 {"elements", ((JSNative)(xml_elements)), 1, (0) | 0x1000},
24601 {"hasOwnProperty", ((JSNative)(xml_hasOwnProperty)), 1, (0) | 0x1000},
24602 {"hasComplexContent", ((JSNative)(xml_hasComplexContent)), 1, (0) | 0x1000},
24603 {"hasSimpleContent", ((JSNative)(xml_hasSimpleContent)), 1, (0) | 0x1000},
24604 {"inScopeNamespaces", ((JSNative)(xml_inScopeNamespaces)), 0, (0) | 0x1000},
24605 {"insertChildAfter", ((JSNative)(xml_insertChildAfter)), 2, (0) | 0x1000},
24606 {"insertChildBefore", ((JSNative)(xml_insertChildBefore)), 2, (0) | 0x1000},
24607 {js_length_str, ((JSNative)(xml_length)), 0, (0) | 0x1000},
24608 {js_localName_str, ((JSNative)(xml_localName)), 0, (0) | 0x1000},
24609 {js_name_str, ((JSNative)(xml_name)), 0, (0) | 0x1000},
24610 {js_namespace_str, ((JSNative)(xml_namespace)), 1, (0) | 0x1000},
24611 {"namespaceDeclarations", ((JSNative)(xml_namespaceDeclarations)), 0, (0) | 0x1000},
24612 {"nodeKind", ((JSNative)(xml_nodeKind)), 0, (0) | 0x1000},
24613 {"normalize", ((JSNative)(xml_normalize)), 0, (0) | 0x1000},
24614 {js_xml_parent_str, ((JSNative)(xml_parent)), 0, (0) | 0x1000},
24615 {"processingInstructions", ((JSNative)(xml_processingInstructions)), 1, (0) | 0x1000},
24616 {"prependChild", ((JSNative)(xml_prependChild)), 1, (0) | 0x1000},
24617 {"propertyIsEnumerable", ((JSNative)(xml_propertyIsEnumerable)), 1, (0) | 0x1000},
24618 {"removeNamespace", ((JSNative)(xml_removeNamespace)), 1, (0) | 0x1000},
24619 {"replace", ((JSNative)(xml_replace)), 2, (0) | 0x1000},
24620 {"setChildren", ((JSNative)(xml_setChildren)), 1, (0) | 0x1000},
24621 {"setLocalName", ((JSNative)(xml_setLocalName)), 1, (0) | 0x1000},
24622 {"setName", ((JSNative)(xml_setName)), 1, (0) | 0x1000},
24623 {"setNamespace", ((JSNative)(xml_setNamespace)), 1, (0) | 0x1000},
24624 {js_text_str, ((JSNative)(xml_text)), 0, (0) | 0x1000},
24625 {js_toSource_str, ((JSNative)(xml_toSource)), 0, (0) | 0x1000},
24626 {js_toString_str, ((JSNative)(xml_toString)), 0, (0) | 0x1000},
24627 {js_toXMLString_str, ((JSNative)(xml_toXMLString)), 0, (0) | 0x1000},
24628 {js_valueOf_str, ((JSNative)(xml_valueOf)), 0, (0) | 0x1000},
24629 {__null, __null, 0, 0}
24632 CopyXMLSettings(JSContext *cx, JSObject *from, JSObject *to)
24637 for (i = 0; xml_static_props[i].name; i++) {
24638 name = xml_static_props[i].name;
24639 if (!JS_GetProperty(cx, from, name, &v))
24641 if (name == js_prettyIndent_str) {
24642 if (!JSVAL_IS_NUMBER(v))
24645 if (!JSVAL_IS_BOOLEAN(v))
24648 if (!JS_SetProperty(cx, to, name, &v))
24654 SetDefaultXMLSettings(JSContext *cx, JSObject *obj)
24658 for (i = 0; xml_static_props[i].name; i++) {
24659 v = (xml_static_props[i].name != js_prettyIndent_str)
24660 ? ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1)) : INT_TO_JSVAL(2);
24661 if (!JS_SetProperty(cx, obj, xml_static_props[i].name, &v))
24667 xml_settings(JSContext *cx, uintN argc, jsval *vp)
24669 JSObject *settings = JS_NewObject(cx, __null, __null, __null);
24672 *vp = OBJECT_TO_JSVAL(settings);
24673 JSObject *obj = ToObject(cx, Valueify(&vp[1]));
24676 return CopyXMLSettings(cx, obj, settings);
24679 xml_setSettings(JSContext *cx, uintN argc, jsval *vp)
24681 JSObject *settings;
24684 JSObject *obj = ToObject(cx, Valueify(&vp[1]));
24687 v = (argc == 0) ? ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)) : vp[2];
24688 if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
24689 ok = SetDefaultXMLSettings(cx, obj);
24691 if (JSVAL_IS_PRIMITIVE(v))
24693 settings = JSVAL_TO_OBJECT(v);
24694 ok = CopyXMLSettings(cx, settings, obj);
24699 xml_defaultSettings(JSContext *cx, uintN argc, jsval *vp)
24701 JSObject *settings;
24702 settings = JS_NewObject(cx, __null, __null, __null);
24705 *vp = OBJECT_TO_JSVAL(settings);
24706 return SetDefaultXMLSettings(cx, settings);
24708 static JSFunctionSpec xml_static_methods[] = {
24709 {"settings", ((JSNative)(xml_settings)), 0, (0) | 0x1000},
24710 {"setSettings", ((JSNative)(xml_setSettings)), 1, (0) | 0x1000},
24711 {"defaultSettings", ((JSNative)(xml_defaultSettings)), 0, (0) | 0x1000},
24712 {__null, __null, 0, 0}
24715 XML(JSContext *cx, uintN argc, Value *vp)
24718 JSObject *xobj, *vobj;
24720 jsval v = argc ? Jsvalify(vp[2]) : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
24721 if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
24722 v = STRING_TO_JSVAL(cx->runtime->emptyString);
24723 xobj = ToXML(cx, v);
24726 xml = (JSXML *) xobj->getPrivate();
24727 if (IsConstructing(vp) && !JSVAL_IS_PRIMITIVE(v)) {
24728 vobj = JSVAL_TO_OBJECT(v);
24729 clasp = vobj->getClass();
24730 if (clasp == &js_XMLClass ||
24731 (clasp->flags & (1<<7))) {
24732 copy = DeepCopy(cx, xml, __null, 0);
24735 vp->setObject(*copy->object);
24739 vp->setObject(*xobj);
24743 XMLList(JSContext *cx, uintN argc, jsval *vp)
24745 JSObject *vobj, *listobj;
24747 jsval v = argc ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
24748 if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
24749 v = STRING_TO_JSVAL(cx->runtime->emptyString);
24750 if (IsConstructing(Valueify(vp)) && !JSVAL_IS_PRIMITIVE(v)) {
24751 vobj = JSVAL_TO_OBJECT(v);
24752 if (vobj->isXML()) {
24753 xml = (JSXML *) vobj->getPrivate();
24754 if (xml->xml_class == JSXML_CLASS_LIST) {
24755 listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
24758 *vp = OBJECT_TO_JSVAL(listobj);
24759 list = (JSXML *) listobj->getPrivate();
24760 if (!Append(cx, list, xml))
24766 listobj = ToXMLList(cx, v);
24769 *vp = OBJECT_TO_JSVAL(listobj);
24773 js_NewXML(JSContext *cx, JSXMLClass xml_class)
24775 JSXML *xml = js_NewGCXML(cx);
24778 xml->object = __null;
24779 xml->domnode = __null;
24780 xml->parent = __null;
24781 xml->name = __null;
24782 xml->xml_class = xml_class;
24783 xml->xml_flags = 0;
24784 if (((xml_class) >= JSXML_CLASS_ATTRIBUTE)) {
24785 xml->u.value = cx->runtime->emptyString;
24787 xml->u.list.kids.init();
24788 if (xml_class == JSXML_CLASS_LIST) {
24789 xml->u.list.target = __null;
24790 xml->u.list.targetprop = __null;
24792 xml->u.elem.namespaces.init();
24793 xml->u.elem.attrs.init();
24800 js_TraceXML(JSTracer *trc, JSXML *xml)
24803 MarkObject(trc, *xml->object, "object");
24805 MarkObject(trc, *xml->name, "name");
24807 do { do { } while (0); JS_CallTracer((trc), (xml->parent), (2)); } while (0);
24808 if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) {
24810 MarkString(trc, xml->u.value, "value");
24813 xml_trace_vector(trc,
24814 (JSXML **) xml->u.list.kids.vector,
24815 xml->u.list.kids.length);
24816 XMLArrayCursorTrace(trc, xml->u.list.kids.cursors);
24817 if (((trc)->callback == __null))
24818 xml->u.list.kids.trim();
24819 if (xml->xml_class == JSXML_CLASS_LIST) {
24820 if (xml->u.list.target)
24821 do { do { } while (0); JS_CallTracer((trc), (xml->u.list.target), (2)); } while (0);
24822 if (xml->u.list.targetprop)
24823 MarkObject(trc, *xml->u.list.targetprop, "targetprop");
24825 MarkObjectRange(trc, xml->u.elem.namespaces.length,
24826 (JSObject **) xml->u.elem.namespaces.vector,
24828 XMLArrayCursorTrace(trc, xml->u.elem.namespaces.cursors);
24829 if (((trc)->callback == __null))
24830 xml->u.elem.namespaces.trim();
24831 xml_trace_vector(trc,
24832 (JSXML **) xml->u.elem.attrs.vector,
24833 xml->u.elem.attrs.length);
24834 XMLArrayCursorTrace(trc, xml->u.elem.attrs.cursors);
24835 if (((trc)->callback == __null))
24836 xml->u.elem.attrs.trim();
24840 js_NewXMLObject(JSContext *cx, JSXMLClass xml_class)
24842 JSXML *xml = js_NewXML(cx, xml_class);
24845 AutoXMLRooter root(cx, xml);
24846 return js_GetXMLObject(cx, xml);
24849 NewXMLObject(JSContext *cx, JSXML *xml)
24852 obj = NewNonFunction<WithProto::Class>(cx, &js_XMLClass, __null, __null);
24855 obj->setPrivate(xml);
24860 js_GetXMLObject(JSContext *cx, JSXML *xml)
24868 obj = NewXMLObject(cx, xml);
24875 js_InitNamespaceClass(JSContext *cx, JSObject *obj)
24877 return js_InitClass(cx, obj, __null, &js_NamespaceClass, Namespace, 2,
24878 namespace_props, namespace_methods, __null, __null);
24881 js_InitQNameClass(JSContext *cx, JSObject *obj)
24883 return js_InitClass(cx, obj, __null, &js_QNameClass, QName, 2,
24884 qname_props, qname_methods, __null, __null);
24887 js_InitXMLClass(JSContext *cx, JSObject *obj)
24889 JSObject *proto, *pobj;
24895 if (!JS_DefineFunction(cx, obj, js_isXMLName_str, xml_isXMLName, 1, 0))
24897 proto = js_InitClass(cx, obj, __null, &js_XMLClass, XML, 1,
24898 __null, xml_methods,
24899 xml_static_props, xml_static_methods);
24902 xml = js_NewXML(cx, JSXML_CLASS_TEXT);
24905 proto->setPrivate(xml);
24906 xml->object = proto;
24908 if (!js_LookupProperty(cx, proto,
24909 ATOM_TO_JSID(cx->runtime->atomState.constructorAtom),
24914 shape = (Shape *) prop;
24915 cval = Jsvalify(pobj->nativeGetSlot(shape->slot));
24917 vp[0] = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0));
24919 vp[2] = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0));
24920 if (!xml_setSettings(cx, 1, vp))
24922 fun = JS_DefineFunction(cx, obj, js_XMLList_str, XMLList, 1, 0x0200);
24925 if (!js_SetClassPrototype(cx, (static_cast<JSObject *>(fun)), proto,
24932 js_InitXMLClasses(JSContext *cx, JSObject *obj)
24934 if (!js_InitNamespaceClass(cx, obj))
24936 if (!js_InitQNameClass(cx, obj))
24938 return js_InitXMLClass(cx, obj);
24941 js_GetFunctionNamespace(JSContext *cx, Value *vp)
24943 JSObject *global = cx->hasfp() ? cx->fp()->scopeChain().getGlobal() : cx->globalObject;
24944 *vp = global->getReservedSlot(((((JSProto_LIMIT * 3) + 1) + 1) + 1));
24945 if (vp->isUndefined()) {
24946 JSRuntime *rt = cx->runtime;
24947 JSLinearString *prefix = rt->atomState.typeAtoms[JSTYPE_FUNCTION];
24948 JSLinearString *uri = rt->atomState.functionNamespaceURIAtom;
24949 JSObject *obj = NewXMLNamespace(cx, prefix, uri, (JSIntn)0);
24953 vp->setObject(*obj);
24954 if (!js_SetReservedSlot(cx, global, ((((JSProto_LIMIT * 3) + 1) + 1) + 1), *vp))
24960 js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp)
24962 JSObject *ns, *obj, *tmp;
24964 JSObject *scopeChain = GetScopeChain(cx);
24966 for (tmp = scopeChain; tmp; tmp = tmp->getParent()) {
24967 Class *clasp = tmp->getClass();
24968 if (clasp == &js_BlockClass || clasp == &js_WithClass)
24970 if (!tmp->getProperty(cx, ((jsid)0x6), Valueify(&v)))
24972 if (!JSVAL_IS_PRIMITIVE(v)) {
24978 ns = js_ConstructObject(cx, &js_NamespaceClass, __null, obj, 0, __null);
24981 v = OBJECT_TO_JSVAL(ns);
24982 if (!obj->defineProperty(cx, ((jsid)0x6), Valueify(v),
24983 PropertyStub, StrictPropertyStub, 0x04)) {
24990 js_SetDefaultXMLNamespace(JSContext *cx, const Value &v)
24993 argv[0].setString(cx->runtime->emptyString);
24995 JSObject *ns = js_ConstructObject(cx, &js_NamespaceClass, __null, __null, 2, argv);
24998 JSStackFrame *fp = js_GetTopStackFrame(cx);
24999 JSObject &varobj = fp->varobj(cx);
25000 if (!varobj.defineProperty(cx, ((jsid)0x6), ObjectValue(*ns),
25001 PropertyStub, StrictPropertyStub, 0x04)) {
25007 js_ToAttributeName(JSContext *cx, Value *vp)
25010 qn = ToAttributeName(cx, Jsvalify(*vp));
25013 vp->setObject(*qn);
25017 js_EscapeAttributeValue(JSContext *cx, JSString *str, JSBool quote)
25019 StringBuffer sb(cx);
25020 return EscapeAttributeValue(cx, sb, str, quote);
25023 js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str, JSString *str2)
25025 size_t len = str->length();
25026 const jschar *chars = str->getChars(cx);
25029 size_t len2 = str2->length();
25030 const jschar *chars2 = str2->getChars(cx);
25033 size_t newlen = (isName) ? len + 1 + len2 : len + 2 + len2 + 1;
25034 jschar *newchars = (jschar *) cx->malloc((newlen+1) * sizeof(jschar));
25037 memcpy((newchars), (chars), (len) * sizeof(jschar));
25041 memcpy((newchars), (chars2), (len2) * sizeof(jschar));
25046 memcpy((newchars), (chars2), (len2) * sizeof(jschar));
25051 return js_NewString(cx, newchars - newlen, newlen);
25054 js_EscapeElementValue(JSContext *cx, JSString *str)
25056 StringBuffer sb(cx);
25057 return EscapeElementValue(cx, sb, str, 0);
25060 js_ValueToXMLString(JSContext *cx, const Value &v)
25062 return ToXMLString(cx, Jsvalify(v), 0);
25065 js_GetAnyName(JSContext *cx, jsid *idp)
25067 JSObject *global = cx->hasfp() ? cx->fp()->scopeChain().getGlobal() : cx->globalObject;
25068 Value v = global->getReservedSlot(JSProto_AnyName);
25069 if (v.isUndefined()) {
25070 JSObject *obj = NewNonFunction<WithProto::Given>(cx, &js_AnyNameClass, __null, global);
25074 JSRuntime *rt = cx->runtime;
25075 InitXMLQName(obj, rt->emptyString, rt->emptyString,
25076 (rt->atomState.starAtom));
25079 if (!js_SetReservedSlot(cx, global, JSProto_AnyName, v))
25082 *idp = OBJECT_TO_JSID(&v.toObject());
25086 js_FindXMLProperty(JSContext *cx, const Value &nameval, JSObject **objp, jsid *idp)
25092 JSObject *obj, *target, *proto, *pobj;
25097 nameobj = &nameval.toObject();
25098 if (nameobj->getClass() == &js_AnyNameClass) {
25099 v = STRING_TO_JSVAL((cx->runtime->atomState.starAtom));
25100 nameobj = js_ConstructObject(cx, &js_QNameClass, __null, __null, 1,
25109 if (!IsFunctionQName(cx, qn, &funid))
25111 obj = &js_GetTopStackFrame(cx)->scopeChain();
25114 while (target->getClass() == &js_WithClass) {
25115 proto = target->getProto();
25120 if (target->isXML()) {
25121 if (JSID_IS_VOID(funid)) {
25122 xml = (JSXML *) target->getPrivate();
25123 found = HasNamedProperty(xml, qn);
25125 if (!HasFunctionProperty(cx, target, funid, &found))
25129 *idp = OBJECT_TO_JSID(nameobj);
25133 } else if (!JSID_IS_VOID(funid)) {
25134 if (!target->lookupProperty(cx, funid, &pobj, &prop))
25142 } while ((obj = obj->getParent()) != __null);
25143 JSAutoByteString printable;
25144 JSString *str = ConvertQNameToString(cx, nameobj);
25145 if (str && js_ValueToPrintable(cx, StringValue(str), &printable)) {
25146 JS_ReportErrorFlagsAndNumber(cx, 0x0, js_GetErrorMessage, __null,
25147 JSMSG_UNDEFINED_XML_NAME, printable.ptr());
25152 GetXMLFunction(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
25155 JSObject *target = obj;
25156 AutoObjectRooter tvr(cx);
25158 if (!js_GetProperty(cx, target, id, Valueify(vp)))
25160 if ((!JSVAL_IS_PRIMITIVE(*vp) && JSVAL_TO_OBJECT(*vp)->isFunction()))
25162 target = target->getProto();
25163 if (target == __null || !target->isNative())
25165 tvr.setObject(target);
25167 JSXML *xml = (JSXML *) obj->getPrivate();
25168 if (!HasSimpleContent(xml))
25170 if (!js_GetClassPrototype(cx, __null, JSProto_String, tvr.addr()))
25173 return tvr.object()->getProperty(cx, id, Valueify(vp));
25176 GetPrivate(JSContext *cx, JSObject *obj, const char *method)
25179 xml = (JSXML *) GetInstancePrivate(cx, obj, &js_XMLClass, __null);
25181 JS_ReportErrorNumber(cx, js_GetErrorMessage, __null,
25182 JSMSG_INCOMPATIBLE_METHOD,
25183 js_XML_str, method, obj->getClass()->name);
25188 js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
25191 xml = GetPrivate(cx, obj, "descendants internal method");
25194 list = Descendants(cx, xml, id);
25197 *vp = OBJECT_TO_JSVAL(list->object);
25201 js_DeleteXMLListElements(JSContext *cx, JSObject *listobj)
25205 list = (JSXML *) listobj->getPrivate();
25206 for (n = list->u.list.kids.length; n != 0; --n)
25207 DeleteListElement(cx, list, 0);
25215 JSXMLArrayCursor cursor;
25216 JSXMLFilter(JSXML *list, JSXMLArray *array)
25217 : list(list), result(__null), kid(__null), cursor(array) {}
25221 xmlfilter_trace(JSTracer *trc, JSObject *obj)
25223 JSXMLFilter *filter = (JSXMLFilter *) obj->getPrivate();
25227 do { do { } while (0); JS_CallTracer((trc), (filter->list), (2)); } while (0);
25228 if (filter->result)
25229 do { do { } while (0); JS_CallTracer((trc), (filter->result), (2)); } while (0);
25231 do { do { } while (0); JS_CallTracer((trc), (filter->kid), (2)); } while (0);
25234 xmlfilter_finalize(JSContext *cx, JSObject *obj)
25236 JSXMLFilter *filter = (JSXMLFilter *) obj->getPrivate();
25239 cx->destroy(filter);
25241 Class js_XMLFilterClass = {
25243 (1<<0) | (1<<((8 + 8)+1)) | (1<<((8 + 8)+3)),
25247 StrictPropertyStub,
25251 xmlfilter_finalize,
25258 ((JSMarkOp)(xmlfilter_trace))
25261 js_StepXMLListFilter(JSContext *cx, JSBool initialized)
25264 JSObject *obj, *filterobj, *resobj, *kidobj;
25266 JSXMLFilter *filter;
25268 sp = Jsvalify(cx->regs->sp);
25269 if (!initialized) {
25270 if (!(!JSVAL_IS_PRIMITIVE(sp[-2]) && JSVAL_TO_OBJECT(sp[-2])->isXML())) {
25271 ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_NON_XML_FILTER, -2, Valueify(sp[-2]), __null, __null, __null));
25274 obj = JSVAL_TO_OBJECT(sp[-2]);
25275 xml = (JSXML *) obj->getPrivate();
25276 if (xml->xml_class == JSXML_CLASS_LIST) {
25279 obj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
25282 sp[-1] = OBJECT_TO_JSVAL(obj);
25283 list = (JSXML *) obj->getPrivate();
25284 if (!Append(cx, list, xml))
25287 filterobj = NewNonFunction<WithProto::Given>(cx, &js_XMLFilterClass, __null, __null);
25290 filter = cx->create<JSXMLFilter>(list, &list->u.list.kids);
25293 filterobj->setPrivate(filter);
25294 sp[-2] = OBJECT_TO_JSVAL(filterobj);
25295 resobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
25298 filter->result = (JSXML *) resobj->getPrivate();
25302 filter = (JSXMLFilter *) JSVAL_TO_OBJECT(sp[-2])->getPrivate();
25304 if (js_ValueToBoolean(Valueify(sp[-1])) &&
25305 !Append(cx, filter->result, filter->kid)) {
25309 filter->kid = (JSXML *) filter->cursor.getNext();
25310 if (!filter->kid) {
25311 filter->cursor.disconnect();
25313 sp[-2] = OBJECT_TO_JSVAL(filter->result->object);
25316 kidobj = js_GetXMLObject(cx, filter->kid);
25320 sp[-1] = OBJECT_TO_JSVAL(kidobj);
25324 js_ValueToXMLObject(JSContext *cx, const Value &v)
25326 return ToXML(cx, Jsvalify(v));
25329 js_ValueToXMLListObject(JSContext *cx, const Value &v)
25331 return ToXMLList(cx, Jsvalify(v));
25334 js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
25341 if (!GetXMLSettingFlags(cx, &flags))
25343 if ((xml_class == JSXML_CLASS_COMMENT &&
25344 (flags & ((JSUint32)1 << (0)))) ||
25345 (xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION &&
25346 (flags & ((JSUint32)1 << (1))))) {
25347 return js_NewXMLObject(cx, JSXML_CLASS_TEXT);
25349 obj = js_NewXMLObject(cx, xml_class);
25352 xml = (JSXML *) obj->getPrivate();
25354 JSLinearString *linearName = name->ensureLinear(cx);
25357 qn = NewXMLQName(cx, cx->runtime->emptyString, __null, linearName);
25362 xml->u.value = value;
25366 js_MakeXMLCDATAString(JSContext *cx, JSString *str)
25368 StringBuffer sb(cx);
25369 return MakeXMLCDATAString(cx, sb, str);
25372 js_MakeXMLCommentString(JSContext *cx, JSString *str)
25374 StringBuffer sb(cx);
25375 return MakeXMLCommentString(cx, sb, str);
25378 js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str)
25380 StringBuffer sb(cx);
25381 return MakeXMLPIString(cx, sb, name, str);