X-Git-Url: https://git.wh0rd.org/?p=ICEs.git;a=blobdiff_plain;f=571482%2Fjsxml.ii.1;fp=571482%2Fjsxml.ii.1;h=0aa11d543135c18be9e87a02c569af2857fc7185;hp=0000000000000000000000000000000000000000;hb=bd3239d2bbe0de3a200b266503e3330b1e391489;hpb=dbff64cb4b7530861c2309c794efdd4e0cf47a23 diff --git a/571482/jsxml.ii.1 b/571482/jsxml.ii.1 new file mode 100644 index 0000000..0aa11d5 --- /dev/null +++ b/571482/jsxml.ii.1 @@ -0,0 +1,25382 @@ +extern "C" { +typedef float float_t; +typedef double double_t; +extern double acos (double __x) throw (); extern double __acos (double __x) throw (); +extern double asin (double __x) throw (); extern double __asin (double __x) throw (); +extern double atan (double __x) throw (); extern double __atan (double __x) throw (); +extern double atan2 (double __y, double __x) throw (); extern double __atan2 (double __y, double __x) throw (); + extern double cos (double __x) throw (); extern double __cos (double __x) throw (); + extern double sin (double __x) throw (); extern double __sin (double __x) throw (); +extern double tan (double __x) throw (); extern double __tan (double __x) throw (); +extern double cosh (double __x) throw (); extern double __cosh (double __x) throw (); +extern double sinh (double __x) throw (); extern double __sinh (double __x) throw (); +extern double tanh (double __x) throw (); extern double __tanh (double __x) throw (); + extern void sincos (double __x, double *__sinx, double *__cosx) throw (); extern void __sincos (double __x, double *__sinx, double *__cosx) throw () + ; +extern double acosh (double __x) throw (); extern double __acosh (double __x) throw (); +extern double asinh (double __x) throw (); extern double __asinh (double __x) throw (); +extern double atanh (double __x) throw (); extern double __atanh (double __x) throw (); + extern double exp (double __x) throw (); extern double __exp (double __x) throw (); +extern double frexp (double __x, int *__exponent) throw (); extern double __frexp (double __x, int *__exponent) throw (); +extern double ldexp (double __x, int __exponent) throw (); extern double __ldexp (double __x, int __exponent) throw (); + extern double log (double __x) throw (); extern double __log (double __x) throw (); +extern double log10 (double __x) throw (); extern double __log10 (double __x) throw (); +extern double modf (double __x, double *__iptr) throw (); extern double __modf (double __x, double *__iptr) throw () __attribute__ ((__nonnull__ (2))); +extern double exp10 (double __x) throw (); extern double __exp10 (double __x) throw (); +extern double pow10 (double __x) throw (); extern double __pow10 (double __x) throw (); +extern double expm1 (double __x) throw (); extern double __expm1 (double __x) throw (); +extern double log1p (double __x) throw (); extern double __log1p (double __x) throw (); +extern double logb (double __x) throw (); extern double __logb (double __x) throw (); +extern double exp2 (double __x) throw (); extern double __exp2 (double __x) throw (); +extern double log2 (double __x) throw (); extern double __log2 (double __x) throw (); + extern double pow (double __x, double __y) throw (); extern double __pow (double __x, double __y) throw (); +extern double sqrt (double __x) throw (); extern double __sqrt (double __x) throw (); +extern double hypot (double __x, double __y) throw (); extern double __hypot (double __x, double __y) throw (); +extern double cbrt (double __x) throw (); extern double __cbrt (double __x) throw (); +extern double ceil (double __x) throw () __attribute__ ((__const__)); extern double __ceil (double __x) throw () __attribute__ ((__const__)); +extern double fabs (double __x) throw () __attribute__ ((__const__)); extern double __fabs (double __x) throw () __attribute__ ((__const__)); +extern double floor (double __x) throw () __attribute__ ((__const__)); extern double __floor (double __x) throw () __attribute__ ((__const__)); +extern double fmod (double __x, double __y) throw (); extern double __fmod (double __x, double __y) throw (); +extern int __isinf (double __value) throw () __attribute__ ((__const__)); +extern int __finite (double __value) throw () __attribute__ ((__const__)); +extern int isinf (double __value) throw () __attribute__ ((__const__)); +extern int finite (double __value) throw () __attribute__ ((__const__)); +extern double drem (double __x, double __y) throw (); extern double __drem (double __x, double __y) throw (); +extern double significand (double __x) throw (); extern double __significand (double __x) throw (); +extern double copysign (double __x, double __y) throw () __attribute__ ((__const__)); extern double __copysign (double __x, double __y) throw () __attribute__ ((__const__)); +extern double nan (const char *__tagb) throw () __attribute__ ((__const__)); extern double __nan (const char *__tagb) throw () __attribute__ ((__const__)); +extern int __isnan (double __value) throw () __attribute__ ((__const__)); +extern int isnan (double __value) throw () __attribute__ ((__const__)); +extern double j0 (double) throw (); extern double __j0 (double) throw (); +extern double j1 (double) throw (); extern double __j1 (double) throw (); +extern double jn (int, double) throw (); extern double __jn (int, double) throw (); +extern double y0 (double) throw (); extern double __y0 (double) throw (); +extern double y1 (double) throw (); extern double __y1 (double) throw (); +extern double yn (int, double) throw (); extern double __yn (int, double) throw (); +extern double erf (double) throw (); extern double __erf (double) throw (); +extern double erfc (double) throw (); extern double __erfc (double) throw (); +extern double lgamma (double) throw (); extern double __lgamma (double) throw (); +extern double tgamma (double) throw (); extern double __tgamma (double) throw (); +extern double gamma (double) throw (); extern double __gamma (double) throw (); +extern double lgamma_r (double, int *__signgamp) throw (); extern double __lgamma_r (double, int *__signgamp) throw (); +extern double rint (double __x) throw (); extern double __rint (double __x) throw (); +extern double nextafter (double __x, double __y) throw () __attribute__ ((__const__)); extern double __nextafter (double __x, double __y) throw () __attribute__ ((__const__)); +extern double nexttoward (double __x, long double __y) throw () __attribute__ ((__const__)); extern double __nexttoward (double __x, long double __y) throw () __attribute__ ((__const__)); +extern double remainder (double __x, double __y) throw (); extern double __remainder (double __x, double __y) throw (); +extern double scalbn (double __x, int __n) throw (); extern double __scalbn (double __x, int __n) throw (); +extern int ilogb (double __x) throw (); extern int __ilogb (double __x) throw (); +extern double scalbln (double __x, long int __n) throw (); extern double __scalbln (double __x, long int __n) throw (); +extern double nearbyint (double __x) throw (); extern double __nearbyint (double __x) throw (); +extern double round (double __x) throw () __attribute__ ((__const__)); extern double __round (double __x) throw () __attribute__ ((__const__)); +extern double trunc (double __x) throw () __attribute__ ((__const__)); extern double __trunc (double __x) throw () __attribute__ ((__const__)); +extern double remquo (double __x, double __y, int *__quo) throw (); extern double __remquo (double __x, double __y, int *__quo) throw (); +extern long int lrint (double __x) throw (); extern long int __lrint (double __x) throw (); +__extension__ +extern long long int llrint (double __x) throw (); extern long long int __llrint (double __x) throw (); +extern long int lround (double __x) throw (); extern long int __lround (double __x) throw (); +__extension__ +extern long long int llround (double __x) throw (); extern long long int __llround (double __x) throw (); +extern double fdim (double __x, double __y) throw (); extern double __fdim (double __x, double __y) throw (); +extern double fmax (double __x, double __y) throw () __attribute__ ((__const__)); extern double __fmax (double __x, double __y) throw () __attribute__ ((__const__)); +extern double fmin (double __x, double __y) throw () __attribute__ ((__const__)); extern double __fmin (double __x, double __y) throw () __attribute__ ((__const__)); +extern int __fpclassify (double __value) throw () + __attribute__ ((__const__)); +extern int __signbit (double __value) throw () + __attribute__ ((__const__)); +extern double fma (double __x, double __y, double __z) throw (); extern double __fma (double __x, double __y, double __z) throw (); +extern int __issignaling (double __value) throw () + __attribute__ ((__const__)); +extern double scalb (double __x, double __n) throw (); extern double __scalb (double __x, double __n) throw (); +extern float acosf (float __x) throw (); extern float __acosf (float __x) throw (); +extern float asinf (float __x) throw (); extern float __asinf (float __x) throw (); +extern float atanf (float __x) throw (); extern float __atanf (float __x) throw (); +extern float atan2f (float __y, float __x) throw (); extern float __atan2f (float __y, float __x) throw (); + extern float cosf (float __x) throw (); extern float __cosf (float __x) throw (); + extern float sinf (float __x) throw (); extern float __sinf (float __x) throw (); +extern float tanf (float __x) throw (); extern float __tanf (float __x) throw (); +extern float coshf (float __x) throw (); extern float __coshf (float __x) throw (); +extern float sinhf (float __x) throw (); extern float __sinhf (float __x) throw (); +extern float tanhf (float __x) throw (); extern float __tanhf (float __x) throw (); + extern void sincosf (float __x, float *__sinx, float *__cosx) throw (); extern void __sincosf (float __x, float *__sinx, float *__cosx) throw () + ; +extern float acoshf (float __x) throw (); extern float __acoshf (float __x) throw (); +extern float asinhf (float __x) throw (); extern float __asinhf (float __x) throw (); +extern float atanhf (float __x) throw (); extern float __atanhf (float __x) throw (); + extern float expf (float __x) throw (); extern float __expf (float __x) throw (); +extern float frexpf (float __x, int *__exponent) throw (); extern float __frexpf (float __x, int *__exponent) throw (); +extern float ldexpf (float __x, int __exponent) throw (); extern float __ldexpf (float __x, int __exponent) throw (); + extern float logf (float __x) throw (); extern float __logf (float __x) throw (); +extern float log10f (float __x) throw (); extern float __log10f (float __x) throw (); +extern float modff (float __x, float *__iptr) throw (); extern float __modff (float __x, float *__iptr) throw () __attribute__ ((__nonnull__ (2))); +extern float exp10f (float __x) throw (); extern float __exp10f (float __x) throw (); +extern float pow10f (float __x) throw (); extern float __pow10f (float __x) throw (); +extern float expm1f (float __x) throw (); extern float __expm1f (float __x) throw (); +extern float log1pf (float __x) throw (); extern float __log1pf (float __x) throw (); +extern float logbf (float __x) throw (); extern float __logbf (float __x) throw (); +extern float exp2f (float __x) throw (); extern float __exp2f (float __x) throw (); +extern float log2f (float __x) throw (); extern float __log2f (float __x) throw (); + extern float powf (float __x, float __y) throw (); extern float __powf (float __x, float __y) throw (); +extern float sqrtf (float __x) throw (); extern float __sqrtf (float __x) throw (); +extern float hypotf (float __x, float __y) throw (); extern float __hypotf (float __x, float __y) throw (); +extern float cbrtf (float __x) throw (); extern float __cbrtf (float __x) throw (); +extern float ceilf (float __x) throw () __attribute__ ((__const__)); extern float __ceilf (float __x) throw () __attribute__ ((__const__)); +extern float fabsf (float __x) throw () __attribute__ ((__const__)); extern float __fabsf (float __x) throw () __attribute__ ((__const__)); +extern float floorf (float __x) throw () __attribute__ ((__const__)); extern float __floorf (float __x) throw () __attribute__ ((__const__)); +extern float fmodf (float __x, float __y) throw (); extern float __fmodf (float __x, float __y) throw (); +extern int __isinff (float __value) throw () __attribute__ ((__const__)); +extern int __finitef (float __value) throw () __attribute__ ((__const__)); +extern int isinff (float __value) throw () __attribute__ ((__const__)); +extern int finitef (float __value) throw () __attribute__ ((__const__)); +extern float dremf (float __x, float __y) throw (); extern float __dremf (float __x, float __y) throw (); +extern float significandf (float __x) throw (); extern float __significandf (float __x) throw (); +extern float copysignf (float __x, float __y) throw () __attribute__ ((__const__)); extern float __copysignf (float __x, float __y) throw () __attribute__ ((__const__)); +extern float nanf (const char *__tagb) throw () __attribute__ ((__const__)); extern float __nanf (const char *__tagb) throw () __attribute__ ((__const__)); +extern int __isnanf (float __value) throw () __attribute__ ((__const__)); +extern int isnanf (float __value) throw () __attribute__ ((__const__)); +extern float j0f (float) throw (); extern float __j0f (float) throw (); +extern float j1f (float) throw (); extern float __j1f (float) throw (); +extern float jnf (int, float) throw (); extern float __jnf (int, float) throw (); +extern float y0f (float) throw (); extern float __y0f (float) throw (); +extern float y1f (float) throw (); extern float __y1f (float) throw (); +extern float ynf (int, float) throw (); extern float __ynf (int, float) throw (); +extern float erff (float) throw (); extern float __erff (float) throw (); +extern float erfcf (float) throw (); extern float __erfcf (float) throw (); +extern float lgammaf (float) throw (); extern float __lgammaf (float) throw (); +extern float tgammaf (float) throw (); extern float __tgammaf (float) throw (); +extern float gammaf (float) throw (); extern float __gammaf (float) throw (); +extern float lgammaf_r (float, int *__signgamp) throw (); extern float __lgammaf_r (float, int *__signgamp) throw (); +extern float rintf (float __x) throw (); extern float __rintf (float __x) throw (); +extern float nextafterf (float __x, float __y) throw () __attribute__ ((__const__)); extern float __nextafterf (float __x, float __y) throw () __attribute__ ((__const__)); +extern float nexttowardf (float __x, long double __y) throw () __attribute__ ((__const__)); extern float __nexttowardf (float __x, long double __y) throw () __attribute__ ((__const__)); +extern float remainderf (float __x, float __y) throw (); extern float __remainderf (float __x, float __y) throw (); +extern float scalbnf (float __x, int __n) throw (); extern float __scalbnf (float __x, int __n) throw (); +extern int ilogbf (float __x) throw (); extern int __ilogbf (float __x) throw (); +extern float scalblnf (float __x, long int __n) throw (); extern float __scalblnf (float __x, long int __n) throw (); +extern float nearbyintf (float __x) throw (); extern float __nearbyintf (float __x) throw (); +extern float roundf (float __x) throw () __attribute__ ((__const__)); extern float __roundf (float __x) throw () __attribute__ ((__const__)); +extern float truncf (float __x) throw () __attribute__ ((__const__)); extern float __truncf (float __x) throw () __attribute__ ((__const__)); +extern float remquof (float __x, float __y, int *__quo) throw (); extern float __remquof (float __x, float __y, int *__quo) throw (); +extern long int lrintf (float __x) throw (); extern long int __lrintf (float __x) throw (); +__extension__ +extern long long int llrintf (float __x) throw (); extern long long int __llrintf (float __x) throw (); +extern long int lroundf (float __x) throw (); extern long int __lroundf (float __x) throw (); +__extension__ +extern long long int llroundf (float __x) throw (); extern long long int __llroundf (float __x) throw (); +extern float fdimf (float __x, float __y) throw (); extern float __fdimf (float __x, float __y) throw (); +extern float fmaxf (float __x, float __y) throw () __attribute__ ((__const__)); extern float __fmaxf (float __x, float __y) throw () __attribute__ ((__const__)); +extern float fminf (float __x, float __y) throw () __attribute__ ((__const__)); extern float __fminf (float __x, float __y) throw () __attribute__ ((__const__)); +extern int __fpclassifyf (float __value) throw () + __attribute__ ((__const__)); +extern int __signbitf (float __value) throw () + __attribute__ ((__const__)); +extern float fmaf (float __x, float __y, float __z) throw (); extern float __fmaf (float __x, float __y, float __z) throw (); +extern int __issignalingf (float __value) throw () + __attribute__ ((__const__)); +extern float scalbf (float __x, float __n) throw (); extern float __scalbf (float __x, float __n) throw (); +extern long double acosl (long double __x) throw (); extern long double __acosl (long double __x) throw (); +extern long double asinl (long double __x) throw (); extern long double __asinl (long double __x) throw (); +extern long double atanl (long double __x) throw (); extern long double __atanl (long double __x) throw (); +extern long double atan2l (long double __y, long double __x) throw (); extern long double __atan2l (long double __y, long double __x) throw (); + extern long double cosl (long double __x) throw (); extern long double __cosl (long double __x) throw (); + extern long double sinl (long double __x) throw (); extern long double __sinl (long double __x) throw (); +extern long double tanl (long double __x) throw (); extern long double __tanl (long double __x) throw (); +extern long double coshl (long double __x) throw (); extern long double __coshl (long double __x) throw (); +extern long double sinhl (long double __x) throw (); extern long double __sinhl (long double __x) throw (); +extern long double tanhl (long double __x) throw (); extern long double __tanhl (long double __x) throw (); + 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 () + ; +extern long double acoshl (long double __x) throw (); extern long double __acoshl (long double __x) throw (); +extern long double asinhl (long double __x) throw (); extern long double __asinhl (long double __x) throw (); +extern long double atanhl (long double __x) throw (); extern long double __atanhl (long double __x) throw (); + extern long double expl (long double __x) throw (); extern long double __expl (long double __x) throw (); +extern long double frexpl (long double __x, int *__exponent) throw (); extern long double __frexpl (long double __x, int *__exponent) throw (); +extern long double ldexpl (long double __x, int __exponent) throw (); extern long double __ldexpl (long double __x, int __exponent) throw (); + extern long double logl (long double __x) throw (); extern long double __logl (long double __x) throw (); +extern long double log10l (long double __x) throw (); extern long double __log10l (long double __x) throw (); +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))); +extern long double exp10l (long double __x) throw (); extern long double __exp10l (long double __x) throw (); +extern long double pow10l (long double __x) throw (); extern long double __pow10l (long double __x) throw (); +extern long double expm1l (long double __x) throw (); extern long double __expm1l (long double __x) throw (); +extern long double log1pl (long double __x) throw (); extern long double __log1pl (long double __x) throw (); +extern long double logbl (long double __x) throw (); extern long double __logbl (long double __x) throw (); +extern long double exp2l (long double __x) throw (); extern long double __exp2l (long double __x) throw (); +extern long double log2l (long double __x) throw (); extern long double __log2l (long double __x) throw (); + extern long double powl (long double __x, long double __y) throw (); extern long double __powl (long double __x, long double __y) throw (); +extern long double sqrtl (long double __x) throw (); extern long double __sqrtl (long double __x) throw (); +extern long double hypotl (long double __x, long double __y) throw (); extern long double __hypotl (long double __x, long double __y) throw (); +extern long double cbrtl (long double __x) throw (); extern long double __cbrtl (long double __x) throw (); +extern long double ceill (long double __x) throw () __attribute__ ((__const__)); extern long double __ceill (long double __x) throw () __attribute__ ((__const__)); +extern long double fabsl (long double __x) throw () __attribute__ ((__const__)); extern long double __fabsl (long double __x) throw () __attribute__ ((__const__)); +extern long double floorl (long double __x) throw () __attribute__ ((__const__)); extern long double __floorl (long double __x) throw () __attribute__ ((__const__)); +extern long double fmodl (long double __x, long double __y) throw (); extern long double __fmodl (long double __x, long double __y) throw (); +extern int __isinfl (long double __value) throw () __attribute__ ((__const__)); +extern int __finitel (long double __value) throw () __attribute__ ((__const__)); +extern int isinfl (long double __value) throw () __attribute__ ((__const__)); +extern int finitel (long double __value) throw () __attribute__ ((__const__)); +extern long double dreml (long double __x, long double __y) throw (); extern long double __dreml (long double __x, long double __y) throw (); +extern long double significandl (long double __x) throw (); extern long double __significandl (long double __x) throw (); +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__)); +extern long double nanl (const char *__tagb) throw () __attribute__ ((__const__)); extern long double __nanl (const char *__tagb) throw () __attribute__ ((__const__)); +extern int __isnanl (long double __value) throw () __attribute__ ((__const__)); +extern int isnanl (long double __value) throw () __attribute__ ((__const__)); +extern long double j0l (long double) throw (); extern long double __j0l (long double) throw (); +extern long double j1l (long double) throw (); extern long double __j1l (long double) throw (); +extern long double jnl (int, long double) throw (); extern long double __jnl (int, long double) throw (); +extern long double y0l (long double) throw (); extern long double __y0l (long double) throw (); +extern long double y1l (long double) throw (); extern long double __y1l (long double) throw (); +extern long double ynl (int, long double) throw (); extern long double __ynl (int, long double) throw (); +extern long double erfl (long double) throw (); extern long double __erfl (long double) throw (); +extern long double erfcl (long double) throw (); extern long double __erfcl (long double) throw (); +extern long double lgammal (long double) throw (); extern long double __lgammal (long double) throw (); +extern long double tgammal (long double) throw (); extern long double __tgammal (long double) throw (); +extern long double gammal (long double) throw (); extern long double __gammal (long double) throw (); +extern long double lgammal_r (long double, int *__signgamp) throw (); extern long double __lgammal_r (long double, int *__signgamp) throw (); +extern long double rintl (long double __x) throw (); extern long double __rintl (long double __x) throw (); +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__)); +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__)); +extern long double remainderl (long double __x, long double __y) throw (); extern long double __remainderl (long double __x, long double __y) throw (); +extern long double scalbnl (long double __x, int __n) throw (); extern long double __scalbnl (long double __x, int __n) throw (); +extern int ilogbl (long double __x) throw (); extern int __ilogbl (long double __x) throw (); +extern long double scalblnl (long double __x, long int __n) throw (); extern long double __scalblnl (long double __x, long int __n) throw (); +extern long double nearbyintl (long double __x) throw (); extern long double __nearbyintl (long double __x) throw (); +extern long double roundl (long double __x) throw () __attribute__ ((__const__)); extern long double __roundl (long double __x) throw () __attribute__ ((__const__)); +extern long double truncl (long double __x) throw () __attribute__ ((__const__)); extern long double __truncl (long double __x) throw () __attribute__ ((__const__)); +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 (); +extern long int lrintl (long double __x) throw (); extern long int __lrintl (long double __x) throw (); +__extension__ +extern long long int llrintl (long double __x) throw (); extern long long int __llrintl (long double __x) throw (); +extern long int lroundl (long double __x) throw (); extern long int __lroundl (long double __x) throw (); +__extension__ +extern long long int llroundl (long double __x) throw (); extern long long int __llroundl (long double __x) throw (); +extern long double fdiml (long double __x, long double __y) throw (); extern long double __fdiml (long double __x, long double __y) throw (); +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__)); +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__)); +extern int __fpclassifyl (long double __value) throw () + __attribute__ ((__const__)); +extern int __signbitl (long double __value) throw () + __attribute__ ((__const__)); +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 (); +extern int __issignalingl (long double __value) throw () + __attribute__ ((__const__)); +extern long double scalbl (long double __x, long double __n) throw (); extern long double __scalbl (long double __x, long double __n) throw (); +extern int signgam; +enum + { + FP_NAN = + 0, + FP_INFINITE = + 1, + FP_ZERO = + 2, + FP_SUBNORMAL = + 3, + FP_NORMAL = + 4 + }; +typedef enum +{ + _IEEE_ = -1, + _SVID_, + _XOPEN_, + _POSIX_, + _ISOC_ +} _LIB_VERSION_TYPE; +extern _LIB_VERSION_TYPE _LIB_VERSION; +struct __exception + { + int type; + char *name; + double arg1; + double arg2; + double retval; + }; +extern int matherr (struct __exception *__exc) throw (); +extern __inline __attribute__ ((__gnu_inline__)) int +__attribute__ ((__leaf__)) __signbitf (float __x) throw () +{ + return __builtin_signbitf (__x); +} +extern __inline __attribute__ ((__gnu_inline__)) int +__attribute__ ((__leaf__)) __signbit (double __x) throw () +{ + return __builtin_signbit (__x); +} +extern __inline __attribute__ ((__gnu_inline__)) int +__attribute__ ((__leaf__)) __signbitl (long double __x) throw () +{ + return __signbit ((double) __x); +} +extern __inline __attribute__ ((__gnu_inline__)) double fdim (double __x, double __y) throw (); +extern __inline __attribute__ ((__gnu_inline__)) double +__attribute__ ((__leaf__)) fdim (double __x, double __y) throw () +{ + return __x <= __y ? 0 : __x - __y; +} +extern __inline __attribute__ ((__gnu_inline__)) float fdimf (float __x, float __y) throw (); +extern __inline __attribute__ ((__gnu_inline__)) float +__attribute__ ((__leaf__)) fdimf (float __x, float __y) throw () +{ + return __x <= __y ? 0 : __x - __y; +} +} +typedef long unsigned int size_t; +extern "C" { +typedef unsigned char __u_char; +typedef unsigned short int __u_short; +typedef unsigned int __u_int; +typedef unsigned long int __u_long; +typedef signed char __int8_t; +typedef unsigned char __uint8_t; +typedef signed short int __int16_t; +typedef unsigned short int __uint16_t; +typedef signed int __int32_t; +typedef unsigned int __uint32_t; +typedef signed long int __int64_t; +typedef unsigned long int __uint64_t; +typedef long int __quad_t; +typedef unsigned long int __u_quad_t; +typedef unsigned long int __dev_t; +typedef unsigned int __uid_t; +typedef unsigned int __gid_t; +typedef unsigned long int __ino_t; +typedef unsigned long int __ino64_t; +typedef unsigned int __mode_t; +typedef unsigned long int __nlink_t; +typedef long int __off_t; +typedef long int __off64_t; +typedef int __pid_t; +typedef struct { int __val[2]; } __fsid_t; +typedef long int __clock_t; +typedef unsigned long int __rlim_t; +typedef unsigned long int __rlim64_t; +typedef unsigned int __id_t; +typedef long int __time_t; +typedef unsigned int __useconds_t; +typedef long int __suseconds_t; +typedef int __daddr_t; +typedef int __key_t; +typedef int __clockid_t; +typedef void * __timer_t; +typedef long int __blksize_t; +typedef long int __blkcnt_t; +typedef long int __blkcnt64_t; +typedef unsigned long int __fsblkcnt_t; +typedef unsigned long int __fsblkcnt64_t; +typedef unsigned long int __fsfilcnt_t; +typedef unsigned long int __fsfilcnt64_t; +typedef long int __fsword_t; +typedef long int __ssize_t; +typedef long int __syscall_slong_t; +typedef unsigned long int __syscall_ulong_t; +typedef __off64_t __loff_t; +typedef __quad_t *__qaddr_t; +typedef char *__caddr_t; +typedef long int __intptr_t; +typedef unsigned int __socklen_t; +static __inline unsigned int +__bswap_32 (unsigned int __bsx) +{ + return __builtin_bswap32 (__bsx); +} +static __inline __uint64_t +__bswap_64 (__uint64_t __bsx) +{ + return __builtin_bswap64 (__bsx); +} +union wait + { + int w_status; + struct + { + unsigned int:16; + unsigned int __w_retcode:8; + unsigned int __w_coredump:1; + unsigned int __w_termsig:7; + } __wait_terminated; + struct + { + unsigned int:16; + unsigned int __w_stopsig:8; + unsigned int __w_stopval:8; + } __wait_stopped; + }; +typedef struct + { + int quot; + int rem; + } div_t; +typedef struct + { + long int quot; + long int rem; + } ldiv_t; +__extension__ typedef struct + { + long long int quot; + long long int rem; + } lldiv_t; +extern size_t __ctype_get_mb_cur_max (void) throw () __attribute__ ((__warn_unused_result__)); +extern double atof (const char *__nptr) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int atoi (const char *__nptr) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern long int atol (const char *__nptr) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +__extension__ extern long long int atoll (const char *__nptr) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern double strtod (const char *__restrict __nptr, + char **__restrict __endptr) + throw () __attribute__ ((__nonnull__ (1))); +extern float strtof (const char *__restrict __nptr, + char **__restrict __endptr) throw () __attribute__ ((__nonnull__ (1))); +extern long double strtold (const char *__restrict __nptr, + char **__restrict __endptr) + throw () __attribute__ ((__nonnull__ (1))); +extern long int strtol (const char *__restrict __nptr, + char **__restrict __endptr, int __base) + throw () __attribute__ ((__nonnull__ (1))); +extern unsigned long int strtoul (const char *__restrict __nptr, + char **__restrict __endptr, int __base) + throw () __attribute__ ((__nonnull__ (1))); +__extension__ +extern long long int strtoq (const char *__restrict __nptr, + char **__restrict __endptr, int __base) + throw () __attribute__ ((__nonnull__ (1))); +__extension__ +extern unsigned long long int strtouq (const char *__restrict __nptr, + char **__restrict __endptr, int __base) + throw () __attribute__ ((__nonnull__ (1))); +__extension__ +extern long long int strtoll (const char *__restrict __nptr, + char **__restrict __endptr, int __base) + throw () __attribute__ ((__nonnull__ (1))); +__extension__ +extern unsigned long long int strtoull (const char *__restrict __nptr, + char **__restrict __endptr, int __base) + throw () __attribute__ ((__nonnull__ (1))); +typedef struct __locale_struct +{ + struct __locale_data *__locales[13]; + const unsigned short int *__ctype_b; + const int *__ctype_tolower; + const int *__ctype_toupper; + const char *__names[13]; +} *__locale_t; +typedef __locale_t locale_t; +extern long int strtol_l (const char *__restrict __nptr, + char **__restrict __endptr, int __base, + __locale_t __loc) throw () __attribute__ ((__nonnull__ (1, 4))); +extern unsigned long int strtoul_l (const char *__restrict __nptr, + char **__restrict __endptr, + int __base, __locale_t __loc) + throw () __attribute__ ((__nonnull__ (1, 4))); +__extension__ +extern long long int strtoll_l (const char *__restrict __nptr, + char **__restrict __endptr, int __base, + __locale_t __loc) + throw () __attribute__ ((__nonnull__ (1, 4))); +__extension__ +extern unsigned long long int strtoull_l (const char *__restrict __nptr, + char **__restrict __endptr, + int __base, __locale_t __loc) + throw () __attribute__ ((__nonnull__ (1, 4))); +extern double strtod_l (const char *__restrict __nptr, + char **__restrict __endptr, __locale_t __loc) + throw () __attribute__ ((__nonnull__ (1, 3))); +extern float strtof_l (const char *__restrict __nptr, + char **__restrict __endptr, __locale_t __loc) + throw () __attribute__ ((__nonnull__ (1, 3))); +extern long double strtold_l (const char *__restrict __nptr, + char **__restrict __endptr, + __locale_t __loc) + throw () __attribute__ ((__nonnull__ (1, 3))); +extern __inline __attribute__ ((__gnu_inline__)) int +__attribute__ ((__leaf__)) atoi (const char *__nptr) throw () +{ + return (int) strtol (__nptr, (char **) __null, 10); +} +extern __inline __attribute__ ((__gnu_inline__)) long int +__attribute__ ((__leaf__)) atol (const char *__nptr) throw () +{ + return strtol (__nptr, (char **) __null, 10); +} +__extension__ extern __inline __attribute__ ((__gnu_inline__)) long long int +__attribute__ ((__leaf__)) atoll (const char *__nptr) throw () +{ + return strtoll (__nptr, (char **) __null, 10); +} +extern char *l64a (long int __n) throw () __attribute__ ((__warn_unused_result__)); +extern long int a64l (const char *__s) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern "C" { +typedef __u_char u_char; +typedef __u_short u_short; +typedef __u_int u_int; +typedef __u_long u_long; +typedef __quad_t quad_t; +typedef __u_quad_t u_quad_t; +typedef __fsid_t fsid_t; +typedef __loff_t loff_t; +typedef __ino_t ino_t; +typedef __ino64_t ino64_t; +typedef __dev_t dev_t; +typedef __gid_t gid_t; +typedef __mode_t mode_t; +typedef __nlink_t nlink_t; +typedef __uid_t uid_t; +typedef __off_t off_t; +typedef __off64_t off64_t; +typedef __pid_t pid_t; +typedef __id_t id_t; +typedef __ssize_t ssize_t; +typedef __daddr_t daddr_t; +typedef __caddr_t caddr_t; +typedef __key_t key_t; +typedef __clock_t clock_t; +typedef __time_t time_t; +typedef __clockid_t clockid_t; +typedef __timer_t timer_t; +typedef __useconds_t useconds_t; +typedef __suseconds_t suseconds_t; +typedef unsigned long int ulong; +typedef unsigned short int ushort; +typedef unsigned int uint; +typedef int int8_t __attribute__ ((__mode__ (__QI__))); +typedef int int16_t __attribute__ ((__mode__ (__HI__))); +typedef int int32_t __attribute__ ((__mode__ (__SI__))); +typedef int int64_t __attribute__ ((__mode__ (__DI__))); +typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__))); +typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__))); +typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__))); +typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__))); +typedef int register_t __attribute__ ((__mode__ (__word__))); +typedef int __sig_atomic_t; +typedef struct + { + unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))]; + } __sigset_t; +typedef __sigset_t sigset_t; +struct timespec + { + __time_t tv_sec; + __syscall_slong_t tv_nsec; + }; +struct timeval + { + __time_t tv_sec; + __suseconds_t tv_usec; + }; +typedef long int __fd_mask; +typedef struct + { + __fd_mask fds_bits[1024 / (8 * (int) sizeof (__fd_mask))]; + } fd_set; +typedef __fd_mask fd_mask; +extern "C" { +extern int select (int __nfds, fd_set *__restrict __readfds, + fd_set *__restrict __writefds, + fd_set *__restrict __exceptfds, + struct timeval *__restrict __timeout); +extern int pselect (int __nfds, fd_set *__restrict __readfds, + fd_set *__restrict __writefds, + fd_set *__restrict __exceptfds, + const struct timespec *__restrict __timeout, + const __sigset_t *__restrict __sigmask); +extern long int __fdelt_chk (long int __d); +extern long int __fdelt_warn (long int __d) + __attribute__((__warning__ ("bit outside of fd_set selected"))); +} +extern "C" { +__extension__ +extern unsigned int gnu_dev_major (unsigned long long int __dev) + throw () __attribute__ ((__const__)); +__extension__ +extern unsigned int gnu_dev_minor (unsigned long long int __dev) + throw () __attribute__ ((__const__)); +__extension__ +extern unsigned long long int gnu_dev_makedev (unsigned int __major, + unsigned int __minor) + throw () __attribute__ ((__const__)); +__extension__ extern __inline __attribute__ ((__gnu_inline__)) __attribute__ ((__const__)) unsigned int +__attribute__ ((__leaf__)) gnu_dev_major (unsigned long long int __dev) throw () +{ + return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff); +} +__extension__ extern __inline __attribute__ ((__gnu_inline__)) __attribute__ ((__const__)) unsigned int +__attribute__ ((__leaf__)) gnu_dev_minor (unsigned long long int __dev) throw () +{ + return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff); +} +__extension__ extern __inline __attribute__ ((__gnu_inline__)) __attribute__ ((__const__)) unsigned long long int +__attribute__ ((__leaf__)) gnu_dev_makedev (unsigned int __major, unsigned int __minor) throw () +{ + return ((__minor & 0xff) | ((__major & 0xfff) << 8) + | (((unsigned long long int) (__minor & ~0xff)) << 12) + | (((unsigned long long int) (__major & ~0xfff)) << 32)); +} +} +typedef __blksize_t blksize_t; +typedef __blkcnt_t blkcnt_t; +typedef __fsblkcnt_t fsblkcnt_t; +typedef __fsfilcnt_t fsfilcnt_t; +typedef __blkcnt64_t blkcnt64_t; +typedef __fsblkcnt64_t fsblkcnt64_t; +typedef __fsfilcnt64_t fsfilcnt64_t; +typedef unsigned long int pthread_t; +union pthread_attr_t +{ + char __size[56]; + long int __align; +}; +typedef union pthread_attr_t pthread_attr_t; +typedef struct __pthread_internal_list +{ + struct __pthread_internal_list *__prev; + struct __pthread_internal_list *__next; +} __pthread_list_t; +typedef union +{ + struct __pthread_mutex_s + { + int __lock; + unsigned int __count; + int __owner; + unsigned int __nusers; + int __kind; + short __spins; + short __elision; + __pthread_list_t __list; + } __data; + char __size[40]; + long int __align; +} pthread_mutex_t; +typedef union +{ + char __size[4]; + int __align; +} pthread_mutexattr_t; +typedef union +{ + struct + { + int __lock; + unsigned int __futex; + __extension__ unsigned long long int __total_seq; + __extension__ unsigned long long int __wakeup_seq; + __extension__ unsigned long long int __woken_seq; + void *__mutex; + unsigned int __nwaiters; + unsigned int __broadcast_seq; + } __data; + char __size[48]; + __extension__ long long int __align; +} pthread_cond_t; +typedef union +{ + char __size[4]; + int __align; +} pthread_condattr_t; +typedef unsigned int pthread_key_t; +typedef int pthread_once_t; +typedef union +{ + struct + { + int __lock; + unsigned int __nr_readers; + unsigned int __readers_wakeup; + unsigned int __writer_wakeup; + unsigned int __nr_readers_queued; + unsigned int __nr_writers_queued; + int __writer; + int __shared; + unsigned char __rwelision; + unsigned char __pad1[7]; + unsigned long int __pad2; + unsigned int __flags; + } __data; + char __size[56]; + long int __align; +} pthread_rwlock_t; +typedef union +{ + char __size[8]; + long int __align; +} pthread_rwlockattr_t; +typedef volatile int pthread_spinlock_t; +typedef union +{ + char __size[32]; + long int __align; +} pthread_barrier_t; +typedef union +{ + char __size[4]; + int __align; +} pthread_barrierattr_t; +} +extern long int random (void) throw (); +extern void srandom (unsigned int __seed) throw (); +extern char *initstate (unsigned int __seed, char *__statebuf, + size_t __statelen) throw () __attribute__ ((__nonnull__ (2))); +extern char *setstate (char *__statebuf) throw () __attribute__ ((__nonnull__ (1))); +struct random_data + { + int32_t *fptr; + int32_t *rptr; + int32_t *state; + int rand_type; + int rand_deg; + int rand_sep; + int32_t *end_ptr; + }; +extern int random_r (struct random_data *__restrict __buf, + int32_t *__restrict __result) throw () __attribute__ ((__nonnull__ (1, 2))); +extern int srandom_r (unsigned int __seed, struct random_data *__buf) + throw () __attribute__ ((__nonnull__ (2))); +extern int initstate_r (unsigned int __seed, char *__restrict __statebuf, + size_t __statelen, + struct random_data *__restrict __buf) + throw () __attribute__ ((__nonnull__ (2, 4))); +extern int setstate_r (char *__restrict __statebuf, + struct random_data *__restrict __buf) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern int rand (void) throw (); +extern void srand (unsigned int __seed) throw (); +extern int rand_r (unsigned int *__seed) throw (); +extern double drand48 (void) throw (); +extern double erand48 (unsigned short int __xsubi[3]) throw () __attribute__ ((__nonnull__ (1))); +extern long int lrand48 (void) throw (); +extern long int nrand48 (unsigned short int __xsubi[3]) + throw () __attribute__ ((__nonnull__ (1))); +extern long int mrand48 (void) throw (); +extern long int jrand48 (unsigned short int __xsubi[3]) + throw () __attribute__ ((__nonnull__ (1))); +extern void srand48 (long int __seedval) throw (); +extern unsigned short int *seed48 (unsigned short int __seed16v[3]) + throw () __attribute__ ((__nonnull__ (1))); +extern void lcong48 (unsigned short int __param[7]) throw () __attribute__ ((__nonnull__ (1))); +struct drand48_data + { + unsigned short int __x[3]; + unsigned short int __old_x[3]; + unsigned short int __c; + unsigned short int __init; + __extension__ unsigned long long int __a; + }; +extern int drand48_r (struct drand48_data *__restrict __buffer, + double *__restrict __result) throw () __attribute__ ((__nonnull__ (1, 2))); +extern int erand48_r (unsigned short int __xsubi[3], + struct drand48_data *__restrict __buffer, + double *__restrict __result) throw () __attribute__ ((__nonnull__ (1, 2))); +extern int lrand48_r (struct drand48_data *__restrict __buffer, + long int *__restrict __result) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern int nrand48_r (unsigned short int __xsubi[3], + struct drand48_data *__restrict __buffer, + long int *__restrict __result) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern int mrand48_r (struct drand48_data *__restrict __buffer, + long int *__restrict __result) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern int jrand48_r (unsigned short int __xsubi[3], + struct drand48_data *__restrict __buffer, + long int *__restrict __result) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern int srand48_r (long int __seedval, struct drand48_data *__buffer) + throw () __attribute__ ((__nonnull__ (2))); +extern int seed48_r (unsigned short int __seed16v[3], + struct drand48_data *__buffer) throw () __attribute__ ((__nonnull__ (1, 2))); +extern int lcong48_r (unsigned short int __param[7], + struct drand48_data *__buffer) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern void *malloc (size_t __size) throw () __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__)); +extern void *calloc (size_t __nmemb, size_t __size) + throw () __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__)); +extern void *realloc (void *__ptr, size_t __size) + throw () __attribute__ ((__warn_unused_result__)); +extern void free (void *__ptr) throw (); +extern void cfree (void *__ptr) throw (); +extern "C" { +extern void *alloca (size_t __size) throw (); +} +extern void *valloc (size_t __size) throw () __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__)); +extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size) + throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern void *aligned_alloc (size_t __alignment, size_t __size) + throw () __attribute__ ((__malloc__)) __attribute__ ((__alloc_size__ (2))) __attribute__ ((__warn_unused_result__)); +extern void abort (void) throw () __attribute__ ((__noreturn__)); +extern int atexit (void (*__func) (void)) throw () __attribute__ ((__nonnull__ (1))); +extern "C++" int at_quick_exit (void (*__func) (void)) + throw () __asm ("at_quick_exit") __attribute__ ((__nonnull__ (1))); +extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg) + throw () __attribute__ ((__nonnull__ (1))); +extern void exit (int __status) throw () __attribute__ ((__noreturn__)); +extern void quick_exit (int __status) throw () __attribute__ ((__noreturn__)); +extern void _Exit (int __status) throw () __attribute__ ((__noreturn__)); +extern char *getenv (const char *__name) throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern char *secure_getenv (const char *__name) + throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int putenv (char *__string) throw () __attribute__ ((__nonnull__ (1))); +extern int setenv (const char *__name, const char *__value, int __replace) + throw () __attribute__ ((__nonnull__ (2))); +extern int unsetenv (const char *__name) throw () __attribute__ ((__nonnull__ (1))); +extern int clearenv (void) throw (); +extern char *mktemp (char *__template) throw () __attribute__ ((__nonnull__ (1))); +extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int mkstemp64 (char *__template) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int mkstemps (char *__template, int __suffixlen) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int mkstemps64 (char *__template, int __suffixlen) + __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern char *mkdtemp (char *__template) throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int mkostemp (char *__template, int __flags) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int mkostemp64 (char *__template, int __flags) __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int mkostemps (char *__template, int __suffixlen, int __flags) + __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int mkostemps64 (char *__template, int __suffixlen, int __flags) + __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int system (const char *__command) __attribute__ ((__warn_unused_result__)); +extern char *canonicalize_file_name (const char *__name) + throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern char *realpath (const char *__restrict __name, + char *__restrict __resolved) throw () __attribute__ ((__warn_unused_result__)); +typedef int (*__compar_fn_t) (const void *, const void *); +typedef __compar_fn_t comparison_fn_t; +typedef int (*__compar_d_fn_t) (const void *, const void *, void *); +extern void *bsearch (const void *__key, const void *__base, + size_t __nmemb, size_t __size, __compar_fn_t __compar) + __attribute__ ((__nonnull__ (1, 2, 5))) __attribute__ ((__warn_unused_result__)); +extern __inline __attribute__ ((__gnu_inline__)) void * +bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, + __compar_fn_t __compar) +{ + size_t __l, __u, __idx; + const void *__p; + int __comparison; + __l = 0; + __u = __nmemb; + while (__l < __u) + { + __idx = (__l + __u) / 2; + __p = (void *) (((const char *) __base) + (__idx * __size)); + __comparison = (*__compar) (__key, __p); + if (__comparison < 0) + __u = __idx; + else if (__comparison > 0) + __l = __idx + 1; + else + return (void *) __p; + } + return __null; +} +extern void qsort (void *__base, size_t __nmemb, size_t __size, + __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4))); +extern void qsort_r (void *__base, size_t __nmemb, size_t __size, + __compar_d_fn_t __compar, void *__arg) + __attribute__ ((__nonnull__ (1, 4))); +extern int abs (int __x) throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__)); +extern long int labs (long int __x) throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__)); +__extension__ extern long long int llabs (long long int __x) + throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__)); +extern div_t div (int __numer, int __denom) + throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__)); +extern ldiv_t ldiv (long int __numer, long int __denom) + throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__)); +__extension__ extern lldiv_t lldiv (long long int __numer, + long long int __denom) + throw () __attribute__ ((__const__)) __attribute__ ((__warn_unused_result__)); +extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt, + int *__restrict __sign) throw () __attribute__ ((__nonnull__ (3, 4))) __attribute__ ((__warn_unused_result__)); +extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt, + int *__restrict __sign) throw () __attribute__ ((__nonnull__ (3, 4))) __attribute__ ((__warn_unused_result__)); +extern char *gcvt (double __value, int __ndigit, char *__buf) + throw () __attribute__ ((__nonnull__ (3))) __attribute__ ((__warn_unused_result__)); +extern char *qecvt (long double __value, int __ndigit, + int *__restrict __decpt, int *__restrict __sign) + throw () __attribute__ ((__nonnull__ (3, 4))) __attribute__ ((__warn_unused_result__)); +extern char *qfcvt (long double __value, int __ndigit, + int *__restrict __decpt, int *__restrict __sign) + throw () __attribute__ ((__nonnull__ (3, 4))) __attribute__ ((__warn_unused_result__)); +extern char *qgcvt (long double __value, int __ndigit, char *__buf) + throw () __attribute__ ((__nonnull__ (3))) __attribute__ ((__warn_unused_result__)); +extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt, + int *__restrict __sign, char *__restrict __buf, + size_t __len) throw () __attribute__ ((__nonnull__ (3, 4, 5))); +extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt, + int *__restrict __sign, char *__restrict __buf, + size_t __len) throw () __attribute__ ((__nonnull__ (3, 4, 5))); +extern int qecvt_r (long double __value, int __ndigit, + int *__restrict __decpt, int *__restrict __sign, + char *__restrict __buf, size_t __len) + throw () __attribute__ ((__nonnull__ (3, 4, 5))); +extern int qfcvt_r (long double __value, int __ndigit, + int *__restrict __decpt, int *__restrict __sign, + char *__restrict __buf, size_t __len) + throw () __attribute__ ((__nonnull__ (3, 4, 5))); +extern int mblen (const char *__s, size_t __n) throw (); +extern int mbtowc (wchar_t *__restrict __pwc, + const char *__restrict __s, size_t __n) throw (); +extern int wctomb (char *__s, wchar_t __wchar) throw (); +extern size_t mbstowcs (wchar_t *__restrict __pwcs, + const char *__restrict __s, size_t __n) throw (); +extern size_t wcstombs (char *__restrict __s, + const wchar_t *__restrict __pwcs, size_t __n) + throw (); +extern int rpmatch (const char *__response) throw () __attribute__ ((__nonnull__ (1))) __attribute__ ((__warn_unused_result__)); +extern int getsubopt (char **__restrict __optionp, + char *const *__restrict __tokens, + char **__restrict __valuep) + throw () __attribute__ ((__nonnull__ (1, 2, 3))) __attribute__ ((__warn_unused_result__)); +extern void setkey (const char *__key) throw () __attribute__ ((__nonnull__ (1))); +extern int posix_openpt (int __oflag) __attribute__ ((__warn_unused_result__)); +extern int grantpt (int __fd) throw (); +extern int unlockpt (int __fd) throw (); +extern char *ptsname (int __fd) throw () __attribute__ ((__warn_unused_result__)); +extern int ptsname_r (int __fd, char *__buf, size_t __buflen) + throw () __attribute__ ((__nonnull__ (2))); +extern int getpt (void); +extern int getloadavg (double __loadavg[], int __nelem) + throw () __attribute__ ((__nonnull__ (1))); +extern __inline __attribute__ ((__gnu_inline__)) double +__attribute__ ((__leaf__)) atof (const char *__nptr) throw () +{ + return strtod (__nptr, (char **) __null); +} +extern char *__realpath_chk (const char *__restrict __name, + char *__restrict __resolved, + size_t __resolvedlen) throw () __attribute__ ((__warn_unused_result__)); +extern char *__realpath_alias (const char *__restrict __name, char *__restrict __resolved) throw () __asm__ ("" "realpath") + __attribute__ ((__warn_unused_result__)); +extern char *__realpath_chk_warn (const char *__restrict __name, char *__restrict __resolved, size_t __resolvedlen) throw () __asm__ ("" "__realpath_chk") + __attribute__ ((__warn_unused_result__)) + __attribute__((__warning__ ("second argument of realpath must be either NULL or at " "least PATH_MAX bytes long buffer"))) + ; +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) char * +__attribute__ ((__leaf__)) realpath (const char *__restrict __name, char *__restrict __resolved) throw () +{ + if (__builtin_object_size (__resolved, 2 > 1) != (size_t) -1) + { + return __realpath_chk (__name, __resolved, __builtin_object_size (__resolved, 2 > 1)); + } + return __realpath_alias (__name, __resolved); +} +extern int __ptsname_r_chk (int __fd, char *__buf, size_t __buflen, + size_t __nreal) throw () __attribute__ ((__nonnull__ (2))); +extern int __ptsname_r_alias (int __fd, char *__buf, size_t __buflen) throw () __asm__ ("" "ptsname_r") + __attribute__ ((__nonnull__ (2))); +extern int __ptsname_r_chk_warn (int __fd, char *__buf, size_t __buflen, size_t __nreal) throw () __asm__ ("" "__ptsname_r_chk") + __attribute__ ((__nonnull__ (2))) __attribute__((__warning__ ("ptsname_r called with buflen bigger than " "size of buf"))) + ; +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) ptsname_r (int __fd, char *__buf, size_t __buflen) throw () +{ + if (__builtin_object_size (__buf, 2 > 1) != (size_t) -1) + { + if (!__builtin_constant_p (__buflen)) + return __ptsname_r_chk (__fd, __buf, __buflen, __builtin_object_size (__buf, 2 > 1)); + if (__buflen > __builtin_object_size (__buf, 2 > 1)) + return __ptsname_r_chk_warn (__fd, __buf, __buflen, __builtin_object_size (__buf, 2 > 1)); + } + return __ptsname_r_alias (__fd, __buf, __buflen); +} +extern int __wctomb_chk (char *__s, wchar_t __wchar, size_t __buflen) + throw () __attribute__ ((__warn_unused_result__)); +extern int __wctomb_alias (char *__s, wchar_t __wchar) throw () __asm__ ("" "wctomb") + __attribute__ ((__warn_unused_result__)); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) int +__attribute__ ((__leaf__)) wctomb (char *__s, wchar_t __wchar) throw () +{ + if (__builtin_object_size (__s, 2 > 1) != (size_t) -1 && 16 > __builtin_object_size (__s, 2 > 1)) + return __wctomb_chk (__s, __wchar, __builtin_object_size (__s, 2 > 1)); + return __wctomb_alias (__s, __wchar); +} +extern size_t __mbstowcs_chk (wchar_t *__restrict __dst, + const char *__restrict __src, + size_t __len, size_t __dstlen) throw (); +extern size_t __mbstowcs_alias (wchar_t *__restrict __dst, const char *__restrict __src, size_t __len) throw () __asm__ ("" "mbstowcs") + ; +extern size_t __mbstowcs_chk_warn (wchar_t *__restrict __dst, const char *__restrict __src, size_t __len, size_t __dstlen) throw () __asm__ ("" "__mbstowcs_chk") + __attribute__((__warning__ ("mbstowcs called with dst buffer smaller than len " "* sizeof (wchar_t)"))) + ; +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) size_t +__attribute__ ((__leaf__)) mbstowcs (wchar_t *__restrict __dst, const char *__restrict __src, size_t __len) throw () +{ + if (__builtin_object_size (__dst, 2 > 1) != (size_t) -1) + { + if (!__builtin_constant_p (__len)) + return __mbstowcs_chk (__dst, __src, __len, + __builtin_object_size (__dst, 2 > 1) / sizeof (wchar_t)); + if (__len > __builtin_object_size (__dst, 2 > 1) / sizeof (wchar_t)) + return __mbstowcs_chk_warn (__dst, __src, __len, + __builtin_object_size (__dst, 2 > 1) / sizeof (wchar_t)); + } + return __mbstowcs_alias (__dst, __src, __len); +} +extern size_t __wcstombs_chk (char *__restrict __dst, + const wchar_t *__restrict __src, + size_t __len, size_t __dstlen) throw (); +extern size_t __wcstombs_alias (char *__restrict __dst, const wchar_t *__restrict __src, size_t __len) throw () __asm__ ("" "wcstombs") + ; +extern size_t __wcstombs_chk_warn (char *__restrict __dst, const wchar_t *__restrict __src, size_t __len, size_t __dstlen) throw () __asm__ ("" "__wcstombs_chk") + __attribute__((__warning__ ("wcstombs called with dst buffer smaller than len"))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) size_t +__attribute__ ((__leaf__)) wcstombs (char *__restrict __dst, const wchar_t *__restrict __src, size_t __len) throw () +{ + if (__builtin_object_size (__dst, 2 > 1) != (size_t) -1) + { + if (!__builtin_constant_p (__len)) + return __wcstombs_chk (__dst, __src, __len, __builtin_object_size (__dst, 2 > 1)); + if (__len > __builtin_object_size (__dst, 2 > 1)) + return __wcstombs_chk_warn (__dst, __src, __len, __builtin_object_size (__dst, 2 > 1)); + } + return __wcstombs_alias (__dst, __src, __len); +} +} +extern "C" { +extern void *memcpy (void *__restrict __dest, const void *__restrict __src, + size_t __n) throw () __attribute__ ((__nonnull__ (1, 2))); +extern void *memmove (void *__dest, const void *__src, size_t __n) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern void *memccpy (void *__restrict __dest, const void *__restrict __src, + int __c, size_t __n) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern void *memset (void *__s, int __c, size_t __n) throw () __attribute__ ((__nonnull__ (1))); +extern int memcmp (const void *__s1, const void *__s2, size_t __n) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern "C++" +{ +extern void *memchr (void *__s, int __c, size_t __n) + throw () __asm ("memchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern const void *memchr (const void *__s, int __c, size_t __n) + throw () __asm ("memchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) void * +memchr (void *__s, int __c, size_t __n) throw () +{ + return __builtin_memchr (__s, __c, __n); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const void * +memchr (const void *__s, int __c, size_t __n) throw () +{ + return __builtin_memchr (__s, __c, __n); +} +} +extern "C++" void *rawmemchr (void *__s, int __c) + throw () __asm ("rawmemchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern "C++" const void *rawmemchr (const void *__s, int __c) + throw () __asm ("rawmemchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern "C++" void *memrchr (void *__s, int __c, size_t __n) + throw () __asm ("memrchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern "C++" const void *memrchr (const void *__s, int __c, size_t __n) + throw () __asm ("memrchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern char *strcpy (char *__restrict __dest, const char *__restrict __src) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern char *strncpy (char *__restrict __dest, + const char *__restrict __src, size_t __n) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern char *strcat (char *__restrict __dest, const char *__restrict __src) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern char *strncat (char *__restrict __dest, const char *__restrict __src, + size_t __n) throw () __attribute__ ((__nonnull__ (1, 2))); +extern int strcmp (const char *__s1, const char *__s2) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern int strncmp (const char *__s1, const char *__s2, size_t __n) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern int strcoll (const char *__s1, const char *__s2) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern size_t strxfrm (char *__restrict __dest, + const char *__restrict __src, size_t __n) + throw () __attribute__ ((__nonnull__ (2))); +extern int strcoll_l (const char *__s1, const char *__s2, __locale_t __l) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3))); +extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n, + __locale_t __l) throw () __attribute__ ((__nonnull__ (2, 4))); +extern char *strdup (const char *__s) + throw () __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); +extern char *strndup (const char *__string, size_t __n) + throw () __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); +extern "C++" +{ +extern char *strchr (char *__s, int __c) + throw () __asm ("strchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern const char *strchr (const char *__s, int __c) + throw () __asm ("strchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char * +strchr (char *__s, int __c) throw () +{ + return __builtin_strchr (__s, __c); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char * +strchr (const char *__s, int __c) throw () +{ + return __builtin_strchr (__s, __c); +} +} +extern "C++" +{ +extern char *strrchr (char *__s, int __c) + throw () __asm ("strrchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern const char *strrchr (const char *__s, int __c) + throw () __asm ("strrchr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char * +strrchr (char *__s, int __c) throw () +{ + return __builtin_strrchr (__s, __c); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char * +strrchr (const char *__s, int __c) throw () +{ + return __builtin_strrchr (__s, __c); +} +} +extern "C++" char *strchrnul (char *__s, int __c) + throw () __asm ("strchrnul") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern "C++" const char *strchrnul (const char *__s, int __c) + throw () __asm ("strchrnul") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern size_t strcspn (const char *__s, const char *__reject) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern size_t strspn (const char *__s, const char *__accept) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern "C++" +{ +extern char *strpbrk (char *__s, const char *__accept) + throw () __asm ("strpbrk") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern const char *strpbrk (const char *__s, const char *__accept) + throw () __asm ("strpbrk") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char * +strpbrk (char *__s, const char *__accept) throw () +{ + return __builtin_strpbrk (__s, __accept); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char * +strpbrk (const char *__s, const char *__accept) throw () +{ + return __builtin_strpbrk (__s, __accept); +} +} +extern "C++" +{ +extern char *strstr (char *__haystack, const char *__needle) + throw () __asm ("strstr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern const char *strstr (const char *__haystack, const char *__needle) + throw () __asm ("strstr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char * +strstr (char *__haystack, const char *__needle) throw () +{ + return __builtin_strstr (__haystack, __needle); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char * +strstr (const char *__haystack, const char *__needle) throw () +{ + return __builtin_strstr (__haystack, __needle); +} +} +extern char *strtok (char *__restrict __s, const char *__restrict __delim) + throw () __attribute__ ((__nonnull__ (2))); +extern char *__strtok_r (char *__restrict __s, + const char *__restrict __delim, + char **__restrict __save_ptr) + throw () __attribute__ ((__nonnull__ (2, 3))); +extern char *strtok_r (char *__restrict __s, const char *__restrict __delim, + char **__restrict __save_ptr) + throw () __attribute__ ((__nonnull__ (2, 3))); +extern "C++" char *strcasestr (char *__haystack, const char *__needle) + throw () __asm ("strcasestr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern "C++" const char *strcasestr (const char *__haystack, + const char *__needle) + throw () __asm ("strcasestr") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern void *memmem (const void *__haystack, size_t __haystacklen, + const void *__needle, size_t __needlelen) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 3))); +extern void *__mempcpy (void *__restrict __dest, + const void *__restrict __src, size_t __n) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern void *mempcpy (void *__restrict __dest, + const void *__restrict __src, size_t __n) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern size_t strlen (const char *__s) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern size_t strnlen (const char *__string, size_t __maxlen) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern char *strerror (int __errnum) throw (); +extern char *strerror_r (int __errnum, char *__buf, size_t __buflen) + throw () __attribute__ ((__nonnull__ (2))) __attribute__ ((__warn_unused_result__)); +extern char *strerror_l (int __errnum, __locale_t __l) throw (); +extern void __bzero (void *__s, size_t __n) throw () __attribute__ ((__nonnull__ (1))); +extern void bcopy (const void *__src, void *__dest, size_t __n) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern void bzero (void *__s, size_t __n) throw () __attribute__ ((__nonnull__ (1))); +extern int bcmp (const void *__s1, const void *__s2, size_t __n) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern "C++" +{ +extern char *index (char *__s, int __c) + throw () __asm ("index") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern const char *index (const char *__s, int __c) + throw () __asm ("index") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char * +index (char *__s, int __c) throw () +{ + return __builtin_index (__s, __c); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char * +index (const char *__s, int __c) throw () +{ + return __builtin_index (__s, __c); +} +} +extern "C++" +{ +extern char *rindex (char *__s, int __c) + throw () __asm ("rindex") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern const char *rindex (const char *__s, int __c) + throw () __asm ("rindex") __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char * +rindex (char *__s, int __c) throw () +{ + return __builtin_rindex (__s, __c); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) const char * +rindex (const char *__s, int __c) throw () +{ + return __builtin_rindex (__s, __c); +} +} +extern int ffs (int __i) throw () __attribute__ ((__const__)); +extern int ffsl (long int __l) throw () __attribute__ ((__const__)); +__extension__ extern int ffsll (long long int __ll) + throw () __attribute__ ((__const__)); +extern int strcasecmp (const char *__s1, const char *__s2) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern int strncasecmp (const char *__s1, const char *__s2, size_t __n) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern int strcasecmp_l (const char *__s1, const char *__s2, + __locale_t __loc) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3))); +extern int strncasecmp_l (const char *__s1, const char *__s2, + size_t __n, __locale_t __loc) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 4))); +extern char *strsep (char **__restrict __stringp, + const char *__restrict __delim) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern char *strsignal (int __sig) throw (); +extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern char *stpcpy (char *__restrict __dest, const char *__restrict __src) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern char *__stpncpy (char *__restrict __dest, + const char *__restrict __src, size_t __n) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern char *stpncpy (char *__restrict __dest, + const char *__restrict __src, size_t __n) + throw () __attribute__ ((__nonnull__ (1, 2))); +extern int strverscmp (const char *__s1, const char *__s2) + throw () __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); +extern char *strfry (char *__string) throw () __attribute__ ((__nonnull__ (1))); +extern void *memfrob (void *__s, size_t __n) throw () __attribute__ ((__nonnull__ (1))); +extern "C++" char *basename (char *__filename) + throw () __asm ("basename") __attribute__ ((__nonnull__ (1))); +extern "C++" const char *basename (const char *__filename) + throw () __asm ("basename") __attribute__ ((__nonnull__ (1))); +extern void __warn_memset_zero_len (void) __attribute__((__warning__ ("memset used with constant zero length parameter; this could be due to transposed parameters"))) + ; +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void * +__attribute__ ((__leaf__)) memcpy (void *__restrict __dest, const void *__restrict __src, size_t __len) throw () +{ + return __builtin___memcpy_chk (__dest, __src, __len, __builtin_object_size (__dest, 0)); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void * +__attribute__ ((__leaf__)) memmove (void *__dest, const void *__src, size_t __len) throw () +{ + return __builtin___memmove_chk (__dest, __src, __len, __builtin_object_size (__dest, 0)); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void * +__attribute__ ((__leaf__)) mempcpy (void *__restrict __dest, const void *__restrict __src, size_t __len) throw () +{ + return __builtin___mempcpy_chk (__dest, __src, __len, __builtin_object_size (__dest, 0)); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void * +__attribute__ ((__leaf__)) memset (void *__dest, int __ch, size_t __len) throw () +{ + if (__builtin_constant_p (__len) && __len == 0 + && (!__builtin_constant_p (__ch) || __ch != 0)) + { + __warn_memset_zero_len (); + return __dest; + } + return __builtin___memset_chk (__dest, __ch, __len, __builtin_object_size (__dest, 0)); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void +__attribute__ ((__leaf__)) bcopy (const void *__src, void *__dest, size_t __len) throw () +{ + (void) __builtin___memmove_chk (__dest, __src, __len, __builtin_object_size (__dest, 0)); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) void +__attribute__ ((__leaf__)) bzero (void *__dest, size_t __len) throw () +{ + (void) __builtin___memset_chk (__dest, '\0', __len, __builtin_object_size (__dest, 0)); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char * +__attribute__ ((__leaf__)) strcpy (char *__restrict __dest, const char *__restrict __src) throw () +{ + return __builtin___strcpy_chk (__dest, __src, __builtin_object_size (__dest, 2 > 1)); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char * +__attribute__ ((__leaf__)) stpcpy (char *__restrict __dest, const char *__restrict __src) throw () +{ + return __builtin___stpcpy_chk (__dest, __src, __builtin_object_size (__dest, 2 > 1)); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char * +__attribute__ ((__leaf__)) strncpy (char *__restrict __dest, const char *__restrict __src, size_t __len) throw () +{ + return __builtin___strncpy_chk (__dest, __src, __len, __builtin_object_size (__dest, 2 > 1)); +} +extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n, + size_t __destlen) throw (); +extern char *__stpncpy_alias (char *__dest, const char *__src, size_t __n) throw () __asm__ ("" "stpncpy") + ; +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char * +__attribute__ ((__leaf__)) stpncpy (char *__dest, const char *__src, size_t __n) throw () +{ + if (__builtin_object_size (__dest, 2 > 1) != (size_t) -1 + && (!__builtin_constant_p (__n) || __n <= __builtin_object_size (__dest, 2 > 1))) + return __stpncpy_chk (__dest, __src, __n, __builtin_object_size (__dest, 2 > 1)); + return __stpncpy_alias (__dest, __src, __n); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char * +__attribute__ ((__leaf__)) strcat (char *__restrict __dest, const char *__restrict __src) throw () +{ + return __builtin___strcat_chk (__dest, __src, __builtin_object_size (__dest, 2 > 1)); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) char * +__attribute__ ((__leaf__)) strncat (char *__restrict __dest, const char *__restrict __src, size_t __len) throw () +{ + return __builtin___strncat_chk (__dest, __src, __len, __builtin_object_size (__dest, 2 > 1)); +} +} +typedef long int ptrdiff_t; +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long int uint64_t; +typedef signed char int_least8_t; +typedef short int int_least16_t; +typedef int int_least32_t; +typedef long int int_least64_t; +typedef unsigned char uint_least8_t; +typedef unsigned short int uint_least16_t; +typedef unsigned int uint_least32_t; +typedef unsigned long int uint_least64_t; +typedef signed char int_fast8_t; +typedef long int int_fast16_t; +typedef long int int_fast32_t; +typedef long int int_fast64_t; +typedef unsigned char uint_fast8_t; +typedef unsigned long int uint_fast16_t; +typedef unsigned long int uint_fast32_t; +typedef unsigned long int uint_fast64_t; +typedef long int intptr_t; +typedef unsigned long int uintptr_t; +typedef long int intmax_t; +typedef unsigned long int uintmax_t; +typedef int8_t JSInt8; +typedef int16_t JSInt16; +typedef int32_t JSInt32; +typedef int64_t JSInt64; +typedef intptr_t JSIntPtr; +typedef uint8_t JSUint8; +typedef uint16_t JSUint16; +typedef uint32_t JSUint32; +typedef uint64_t JSUint64; +typedef uintptr_t JSUintPtr; +extern "C" { +typedef int JSIntn; +typedef unsigned int JSUintn; +typedef double JSFloat64; +typedef size_t JSSize; +typedef ptrdiff_t JSPtrdiff; +typedef JSUintPtr JSUptrdiff; +typedef JSIntn JSBool; +typedef JSUint8 JSPackedBool; +typedef JSIntPtr JSWord; +typedef JSUintPtr JSUword; +typedef JSUintn uintn; +typedef JSUint64 uint64; +typedef JSUint32 uint32; +typedef JSUint16 uint16; +typedef JSUint8 uint8; +typedef JSIntn intn; +typedef JSInt64 int64; +typedef JSInt32 int32; +typedef JSInt16 int16; +typedef JSInt8 int8; +typedef JSFloat64 float64; +} +extern "C" { +} +typedef JSIntn intN; +typedef JSUintn uintN; +typedef JSUword jsuword; +typedef JSWord jsword; +typedef float float32; +extern "C" { +extern __attribute__((visibility ("default"))) void +JS_Assert(const char *s, const char *file, JSIntn ln); +extern __attribute__((visibility ("default"))) void JS_Abort(void); +static inline void* js_malloc(size_t bytes) { + return malloc(bytes); +} +static inline void* js_calloc(size_t bytes) { + return calloc(bytes, 1); +} +static inline void* js_realloc(void* p, size_t bytes) { + return realloc(p, bytes); +} +static inline void js_free(void* p) { + free(p); +} +} +template +__attribute__((always_inline)) inline T *js_new() { + void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T () : __null; +} +template +__attribute__((always_inline)) inline T *js_new(const P1 &p1) { + void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T (p1) : __null; +} +template +__attribute__((always_inline)) inline T *js_new(const P1 &p1, const P2 &p2) { + void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T (p1, p2) : __null; +} +template +__attribute__((always_inline)) inline T *js_new(const P1 &p1, const P2 &p2, const P3 &p3) { + void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T (p1, p2, p3) : __null; +} +template +__attribute__((always_inline)) inline T *js_new(const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4) { + void *memory = js_malloc(sizeof(T)); return memory ? new(memory) T (p1, p2, p3, p4) : __null; +} +template +__attribute__((always_inline)) inline void js_delete(T *p) { + if (p) { + p->~T(); + js_free(p); + } +} +static const int JSMinAlignment = 8; +template +__attribute__((always_inline)) inline T *js_array_new(size_t n) { + uint64 numBytes64 = uint64(JSMinAlignment) + uint64(sizeof(T)) * uint64(n); + size_t numBytes = size_t(numBytes64); + if (numBytes64 != numBytes) { + ((void) 0); + return __null; + } + void *memory = js_malloc(numBytes); + if (!memory) + return __null; + *(size_t *)memory = n; + memory = (void*)(uintptr_t(memory) + JSMinAlignment); + return new(memory) T[n]; +} +template +__attribute__((always_inline)) inline void js_array_delete(T *p) { + if (p) { + void* p0 = (void *)(uintptr_t(p) - JSMinAlignment); + size_t n = *(size_t *)p0; + for (size_t i = 0; i < n; i++) + (p + i)->~T(); + js_free(p0); + } +} +namespace js { +template +__attribute__((always_inline)) inline static void +PodZero(T *t) +{ + memset(t, 0, sizeof(T)); +} +template +__attribute__((always_inline)) inline static void +PodZero(T *t, size_t nelem) +{ + memset(t, 0, nelem * sizeof(T)); +} +template static void PodZero(T (&)[N]); +template static void PodZero(T (&)[N], size_t); +template +__attribute__((always_inline)) inline static void +PodArrayZero(T (&t)[N]) +{ + memset(t, 0, N * sizeof(T)); +} +template +__attribute__((always_inline)) inline static void +PodCopy(T *dst, const T *src, size_t nelem) +{ + ((void) 0); + ((void) 0); + if (nelem < 128) { + for (const T *srcend = src + nelem; src != srcend; ++src, ++dst) + *dst = *src; + } else { + memcpy(dst, src, nelem * sizeof(T)); + } +} +} +extern "C" { +typedef jsuword jsbitmap_t; +typedef jsbitmap_t jsbitmap; +extern __attribute__((visibility ("default"))) JSIntn JS_CeilingLog2(JSUint32 i); +extern __attribute__((visibility ("default"))) JSIntn JS_FloorLog2(JSUint32 i); +namespace js { +inline size_t +CountTrailingZeros(size_t n) +{ + ((void) 0); + return __builtin_ctzll(n); +} +} +} +extern "C" { +struct _IO_FILE; +typedef struct _IO_FILE FILE; +typedef struct _IO_FILE __FILE; +typedef struct +{ + int __count; + union + { + unsigned int __wch; + char __wchb[4]; + } __value; +} __mbstate_t; +typedef struct +{ + __off_t __pos; + __mbstate_t __state; +} _G_fpos_t; +typedef struct +{ + __off64_t __pos; + __mbstate_t __state; +} _G_fpos64_t; +typedef __builtin_va_list __gnuc_va_list; +struct _IO_jump_t; struct _IO_FILE; +typedef void _IO_lock_t; +struct _IO_marker { + struct _IO_marker *_next; + struct _IO_FILE *_sbuf; + int _pos; +}; +enum __codecvt_result +{ + __codecvt_ok, + __codecvt_partial, + __codecvt_error, + __codecvt_noconv +}; +struct _IO_FILE { + int _flags; + char* _IO_read_ptr; + char* _IO_read_end; + char* _IO_read_base; + char* _IO_write_base; + char* _IO_write_ptr; + char* _IO_write_end; + char* _IO_buf_base; + char* _IO_buf_end; + char *_IO_save_base; + char *_IO_backup_base; + char *_IO_save_end; + struct _IO_marker *_markers; + struct _IO_FILE *_chain; + int _fileno; + int _flags2; + __off_t _old_offset; + unsigned short _cur_column; + signed char _vtable_offset; + char _shortbuf[1]; + _IO_lock_t *_lock; + __off64_t _offset; + void *__pad1; + void *__pad2; + void *__pad3; + void *__pad4; + size_t __pad5; + int _mode; + char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; +}; +struct _IO_FILE_plus; +extern struct _IO_FILE_plus _IO_2_1_stdin_; +extern struct _IO_FILE_plus _IO_2_1_stdout_; +extern struct _IO_FILE_plus _IO_2_1_stderr_; +typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes); +typedef __ssize_t __io_write_fn (void *__cookie, const char *__buf, + size_t __n); +typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w); +typedef int __io_close_fn (void *__cookie); +typedef __io_read_fn cookie_read_function_t; +typedef __io_write_fn cookie_write_function_t; +typedef __io_seek_fn cookie_seek_function_t; +typedef __io_close_fn cookie_close_function_t; +typedef struct +{ + __io_read_fn *read; + __io_write_fn *write; + __io_seek_fn *seek; + __io_close_fn *close; +} _IO_cookie_io_functions_t; +typedef _IO_cookie_io_functions_t cookie_io_functions_t; +struct _IO_cookie_file; +extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write, + void *__cookie, _IO_cookie_io_functions_t __fns); +extern "C" { +extern int __underflow (_IO_FILE *); +extern int __uflow (_IO_FILE *); +extern int __overflow (_IO_FILE *, int); +extern int _IO_getc (_IO_FILE *__fp); +extern int _IO_putc (int __c, _IO_FILE *__fp); +extern int _IO_feof (_IO_FILE *__fp) throw (); +extern int _IO_ferror (_IO_FILE *__fp) throw (); +extern int _IO_peekc_locked (_IO_FILE *__fp); +extern void _IO_flockfile (_IO_FILE *) throw (); +extern void _IO_funlockfile (_IO_FILE *) throw (); +extern int _IO_ftrylockfile (_IO_FILE *) throw (); +extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict, + __gnuc_va_list, int *__restrict); +extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict, + __gnuc_va_list); +extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t); +extern size_t _IO_sgetn (_IO_FILE *, void *, size_t); +extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int); +extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int); +extern void _IO_free_backup_area (_IO_FILE *) throw (); +} +typedef __gnuc_va_list va_list; +typedef _G_fpos_t fpos_t; +typedef _G_fpos64_t fpos64_t; +extern struct _IO_FILE *stdin; +extern struct _IO_FILE *stdout; +extern struct _IO_FILE *stderr; +extern int remove (const char *__filename) throw (); +extern int rename (const char *__old, const char *__new) throw (); +extern int renameat (int __oldfd, const char *__old, int __newfd, + const char *__new) throw (); +extern FILE *tmpfile (void) __attribute__ ((__warn_unused_result__)); +extern FILE *tmpfile64 (void) __attribute__ ((__warn_unused_result__)); +extern char *tmpnam (char *__s) throw () __attribute__ ((__warn_unused_result__)); +extern char *tmpnam_r (char *__s) throw () __attribute__ ((__warn_unused_result__)); +extern char *tempnam (const char *__dir, const char *__pfx) + throw () __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__)); +extern int fclose (FILE *__stream); +extern int fflush (FILE *__stream); +extern int fflush_unlocked (FILE *__stream); +extern int fcloseall (void); +extern FILE *fopen (const char *__restrict __filename, + const char *__restrict __modes) __attribute__ ((__warn_unused_result__)); +extern FILE *freopen (const char *__restrict __filename, + const char *__restrict __modes, + FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern FILE *fopen64 (const char *__restrict __filename, + const char *__restrict __modes) __attribute__ ((__warn_unused_result__)); +extern FILE *freopen64 (const char *__restrict __filename, + const char *__restrict __modes, + FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern FILE *fdopen (int __fd, const char *__modes) throw () __attribute__ ((__warn_unused_result__)); +extern FILE *fopencookie (void *__restrict __magic_cookie, + const char *__restrict __modes, + _IO_cookie_io_functions_t __io_funcs) throw () __attribute__ ((__warn_unused_result__)); +extern FILE *fmemopen (void *__s, size_t __len, const char *__modes) + throw () __attribute__ ((__warn_unused_result__)); +extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) throw () __attribute__ ((__warn_unused_result__)); +extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) throw (); +extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, + int __modes, size_t __n) throw (); +extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, + size_t __size) throw (); +extern void setlinebuf (FILE *__stream) throw (); +extern int fprintf (FILE *__restrict __stream, + const char *__restrict __format, ...); +extern int printf (const char *__restrict __format, ...); +extern int sprintf (char *__restrict __s, + const char *__restrict __format, ...) throw (); +extern int vfprintf (FILE *__restrict __s, const char *__restrict __format, + __gnuc_va_list __arg); +extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); +extern int vsprintf (char *__restrict __s, const char *__restrict __format, + __gnuc_va_list __arg) throw (); +extern int snprintf (char *__restrict __s, size_t __maxlen, + const char *__restrict __format, ...) + throw () __attribute__ ((__format__ (__printf__, 3, 4))); +extern int vsnprintf (char *__restrict __s, size_t __maxlen, + const char *__restrict __format, __gnuc_va_list __arg) + throw () __attribute__ ((__format__ (__printf__, 3, 0))); +extern int vasprintf (char **__restrict __ptr, const char *__restrict __f, + __gnuc_va_list __arg) + throw () __attribute__ ((__format__ (__printf__, 2, 0))) __attribute__ ((__warn_unused_result__)); +extern int __asprintf (char **__restrict __ptr, + const char *__restrict __fmt, ...) + throw () __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__ ((__warn_unused_result__)); +extern int asprintf (char **__restrict __ptr, + const char *__restrict __fmt, ...) + throw () __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__ ((__warn_unused_result__)); +extern int vdprintf (int __fd, const char *__restrict __fmt, + __gnuc_va_list __arg) + __attribute__ ((__format__ (__printf__, 2, 0))); +extern int dprintf (int __fd, const char *__restrict __fmt, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); +extern int fscanf (FILE *__restrict __stream, + const char *__restrict __format, ...) __attribute__ ((__warn_unused_result__)); +extern int scanf (const char *__restrict __format, ...) __attribute__ ((__warn_unused_result__)); +extern int sscanf (const char *__restrict __s, + const char *__restrict __format, ...) throw (); +extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, + __gnuc_va_list __arg) + __attribute__ ((__format__ (__scanf__, 2, 0))) __attribute__ ((__warn_unused_result__)); +extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) + __attribute__ ((__format__ (__scanf__, 1, 0))) __attribute__ ((__warn_unused_result__)); +extern int vsscanf (const char *__restrict __s, + const char *__restrict __format, __gnuc_va_list __arg) + throw () __attribute__ ((__format__ (__scanf__, 2, 0))); +extern int fgetc (FILE *__stream); +extern int getc (FILE *__stream); +extern int getchar (void); +extern int getc_unlocked (FILE *__stream); +extern int getchar_unlocked (void); +extern int fgetc_unlocked (FILE *__stream); +extern int fputc (int __c, FILE *__stream); +extern int putc (int __c, FILE *__stream); +extern int putchar (int __c); +extern int fputc_unlocked (int __c, FILE *__stream); +extern int putc_unlocked (int __c, FILE *__stream); +extern int putchar_unlocked (int __c); +extern int getw (FILE *__stream); +extern int putw (int __w, FILE *__stream); +extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) + __attribute__ ((__warn_unused_result__)); +extern char *gets (char *__s) __attribute__ ((__warn_unused_result__)) __attribute__ ((__deprecated__)); +extern char *fgets_unlocked (char *__restrict __s, int __n, + FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern __ssize_t __getdelim (char **__restrict __lineptr, + size_t *__restrict __n, int __delimiter, + FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern __ssize_t getdelim (char **__restrict __lineptr, + size_t *__restrict __n, int __delimiter, + FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern __ssize_t getline (char **__restrict __lineptr, + size_t *__restrict __n, + FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern int fputs (const char *__restrict __s, FILE *__restrict __stream); +extern int puts (const char *__s); +extern int ungetc (int __c, FILE *__stream); +extern size_t fread (void *__restrict __ptr, size_t __size, + size_t __n, FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern size_t fwrite (const void *__restrict __ptr, size_t __size, + size_t __n, FILE *__restrict __s); +extern int fputs_unlocked (const char *__restrict __s, + FILE *__restrict __stream); +extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, + size_t __n, FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size, + size_t __n, FILE *__restrict __stream); +extern int fseek (FILE *__stream, long int __off, int __whence); +extern long int ftell (FILE *__stream) __attribute__ ((__warn_unused_result__)); +extern void rewind (FILE *__stream); +extern int fseeko (FILE *__stream, __off_t __off, int __whence); +extern __off_t ftello (FILE *__stream) __attribute__ ((__warn_unused_result__)); +extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); +extern int fsetpos (FILE *__stream, const fpos_t *__pos); +extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence); +extern __off64_t ftello64 (FILE *__stream) __attribute__ ((__warn_unused_result__)); +extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos); +extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos); +extern void clearerr (FILE *__stream) throw (); +extern int feof (FILE *__stream) throw () __attribute__ ((__warn_unused_result__)); +extern int ferror (FILE *__stream) throw () __attribute__ ((__warn_unused_result__)); +extern void clearerr_unlocked (FILE *__stream) throw (); +extern int feof_unlocked (FILE *__stream) throw () __attribute__ ((__warn_unused_result__)); +extern int ferror_unlocked (FILE *__stream) throw () __attribute__ ((__warn_unused_result__)); +extern void perror (const char *__s); +extern int sys_nerr; +extern const char *const sys_errlist[]; +extern int _sys_nerr; +extern const char *const _sys_errlist[]; +extern int fileno (FILE *__stream) throw () __attribute__ ((__warn_unused_result__)); +extern int fileno_unlocked (FILE *__stream) throw () __attribute__ ((__warn_unused_result__)); +extern FILE *popen (const char *__command, const char *__modes) __attribute__ ((__warn_unused_result__)); +extern int pclose (FILE *__stream); +extern char *ctermid (char *__s) throw (); +extern char *cuserid (char *__s); +struct obstack; +extern int obstack_printf (struct obstack *__restrict __obstack, + const char *__restrict __format, ...) + throw () __attribute__ ((__format__ (__printf__, 2, 3))); +extern int obstack_vprintf (struct obstack *__restrict __obstack, + const char *__restrict __format, + __gnuc_va_list __args) + throw () __attribute__ ((__format__ (__printf__, 2, 0))); +extern void flockfile (FILE *__stream) throw (); +extern int ftrylockfile (FILE *__stream) throw () __attribute__ ((__warn_unused_result__)); +extern void funlockfile (FILE *__stream) throw (); +extern __inline __attribute__ ((__gnu_inline__)) int +getchar (void) +{ + return _IO_getc (stdin); +} +extern __inline __attribute__ ((__gnu_inline__)) int +fgetc_unlocked (FILE *__fp) +{ + return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); +} +extern __inline __attribute__ ((__gnu_inline__)) int +getc_unlocked (FILE *__fp) +{ + return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); +} +extern __inline __attribute__ ((__gnu_inline__)) int +getchar_unlocked (void) +{ + return (__builtin_expect (((stdin)->_IO_read_ptr >= (stdin)->_IO_read_end), 0) ? __uflow (stdin) : *(unsigned char *) (stdin)->_IO_read_ptr++); +} +extern __inline __attribute__ ((__gnu_inline__)) int +putchar (int __c) +{ + return _IO_putc (__c, stdout); +} +extern __inline __attribute__ ((__gnu_inline__)) int +fputc_unlocked (int __c, FILE *__stream) +{ + return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); +} +extern __inline __attribute__ ((__gnu_inline__)) int +putc_unlocked (int __c, FILE *__stream) +{ + return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); +} +extern __inline __attribute__ ((__gnu_inline__)) int +putchar_unlocked (int __c) +{ + return (__builtin_expect (((stdout)->_IO_write_ptr >= (stdout)->_IO_write_end), 0) ? __overflow (stdout, (unsigned char) (__c)) : (unsigned char) (*(stdout)->_IO_write_ptr++ = (__c))); +} +extern __inline __attribute__ ((__gnu_inline__)) __ssize_t +getline (char **__lineptr, size_t *__n, FILE *__stream) +{ + return __getdelim (__lineptr, __n, '\n', __stream); +} +extern __inline __attribute__ ((__gnu_inline__)) int +__attribute__ ((__leaf__)) feof_unlocked (FILE *__stream) throw () +{ + return (((__stream)->_flags & 0x10) != 0); +} +extern __inline __attribute__ ((__gnu_inline__)) int +__attribute__ ((__leaf__)) ferror_unlocked (FILE *__stream) throw () +{ + return (((__stream)->_flags & 0x20) != 0); +} +extern int __sprintf_chk (char *__restrict __s, int __flag, size_t __slen, + const char *__restrict __format, ...) throw (); +extern int __vsprintf_chk (char *__restrict __s, int __flag, size_t __slen, + const char *__restrict __format, + __gnuc_va_list __ap) throw (); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) sprintf (char *__restrict __s, const char *__restrict __fmt, ...) throw () +{ + return __builtin___sprintf_chk (__s, 2 - 1, + __builtin_object_size (__s, 2 > 1), __fmt, __builtin_va_arg_pack ()); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) vsprintf (char *__restrict __s, const char *__restrict __fmt, __gnuc_va_list __ap) throw () +{ + return __builtin___vsprintf_chk (__s, 2 - 1, + __builtin_object_size (__s, 2 > 1), __fmt, __ap); +} +extern int __snprintf_chk (char *__restrict __s, size_t __n, int __flag, + size_t __slen, const char *__restrict __format, + ...) throw (); +extern int __vsnprintf_chk (char *__restrict __s, size_t __n, int __flag, + size_t __slen, const char *__restrict __format, + __gnuc_va_list __ap) throw (); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) snprintf (char *__restrict __s, size_t __n, const char *__restrict __fmt, ...) throw () +{ + return __builtin___snprintf_chk (__s, __n, 2 - 1, + __builtin_object_size (__s, 2 > 1), __fmt, __builtin_va_arg_pack ()); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) vsnprintf (char *__restrict __s, size_t __n, const char *__restrict __fmt, __gnuc_va_list __ap) throw () +{ + return __builtin___vsnprintf_chk (__s, __n, 2 - 1, + __builtin_object_size (__s, 2 > 1), __fmt, __ap); +} +extern int __fprintf_chk (FILE *__restrict __stream, int __flag, + const char *__restrict __format, ...); +extern int __printf_chk (int __flag, const char *__restrict __format, ...); +extern int __vfprintf_chk (FILE *__restrict __stream, int __flag, + const char *__restrict __format, __gnuc_va_list __ap); +extern int __vprintf_chk (int __flag, const char *__restrict __format, + __gnuc_va_list __ap); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +fprintf (FILE *__restrict __stream, const char *__restrict __fmt, ...) +{ + return __fprintf_chk (__stream, 2 - 1, __fmt, + __builtin_va_arg_pack ()); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +printf (const char *__restrict __fmt, ...) +{ + return __printf_chk (2 - 1, __fmt, __builtin_va_arg_pack ()); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +vprintf (const char *__restrict __fmt, __gnuc_va_list __ap) +{ + return __vfprintf_chk (stdout, 2 - 1, __fmt, __ap); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +vfprintf (FILE *__restrict __stream, + const char *__restrict __fmt, __gnuc_va_list __ap) +{ + return __vfprintf_chk (__stream, 2 - 1, __fmt, __ap); +} +extern int __dprintf_chk (int __fd, int __flag, const char *__restrict __fmt, + ...) __attribute__ ((__format__ (__printf__, 3, 4))); +extern int __vdprintf_chk (int __fd, int __flag, + const char *__restrict __fmt, __gnuc_va_list __arg) + __attribute__ ((__format__ (__printf__, 3, 0))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +dprintf (int __fd, const char *__restrict __fmt, ...) +{ + return __dprintf_chk (__fd, 2 - 1, __fmt, + __builtin_va_arg_pack ()); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +vdprintf (int __fd, const char *__restrict __fmt, __gnuc_va_list __ap) +{ + return __vdprintf_chk (__fd, 2 - 1, __fmt, __ap); +} +extern int __asprintf_chk (char **__restrict __ptr, int __flag, + const char *__restrict __fmt, ...) + throw () __attribute__ ((__format__ (__printf__, 3, 4))) __attribute__ ((__warn_unused_result__)); +extern int __vasprintf_chk (char **__restrict __ptr, int __flag, + const char *__restrict __fmt, __gnuc_va_list __arg) + throw () __attribute__ ((__format__ (__printf__, 3, 0))) __attribute__ ((__warn_unused_result__)); +extern int __obstack_printf_chk (struct obstack *__restrict __obstack, + int __flag, const char *__restrict __format, + ...) + throw () __attribute__ ((__format__ (__printf__, 3, 4))); +extern int __obstack_vprintf_chk (struct obstack *__restrict __obstack, + int __flag, + const char *__restrict __format, + __gnuc_va_list __args) + throw () __attribute__ ((__format__ (__printf__, 3, 0))); +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...) throw () +{ + return __asprintf_chk (__ptr, 2 - 1, __fmt, + __builtin_va_arg_pack ()); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) __asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...) throw () +{ + return __asprintf_chk (__ptr, 2 - 1, __fmt, + __builtin_va_arg_pack ()); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) obstack_printf (struct obstack *__restrict __obstack, const char *__restrict __fmt, ...) throw () +{ + return __obstack_printf_chk (__obstack, 2 - 1, __fmt, + __builtin_va_arg_pack ()); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) vasprintf (char **__restrict __ptr, const char *__restrict __fmt, __gnuc_va_list __ap) throw () +{ + return __vasprintf_chk (__ptr, 2 - 1, __fmt, __ap); +} +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int +__attribute__ ((__leaf__)) obstack_vprintf (struct obstack *__restrict __obstack, const char *__restrict __fmt, __gnuc_va_list __ap) throw () +{ + return __obstack_vprintf_chk (__obstack, 2 - 1, __fmt, + __ap); +} +extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n, + FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern char *__fgets_alias (char *__restrict __s, int __n, FILE *__restrict __stream) __asm__ ("" "fgets") + __attribute__ ((__warn_unused_result__)); +extern char *__fgets_chk_warn (char *__restrict __s, size_t __size, int __n, FILE *__restrict __stream) __asm__ ("" "__fgets_chk") + __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fgets called with bigger size than length " "of destination buffer"))) + ; +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) char * +fgets (char *__restrict __s, int __n, FILE *__restrict __stream) +{ + if (__builtin_object_size (__s, 2 > 1) != (size_t) -1) + { + if (!__builtin_constant_p (__n) || __n <= 0) + return __fgets_chk (__s, __builtin_object_size (__s, 2 > 1), __n, __stream); + if ((size_t) __n > __builtin_object_size (__s, 2 > 1)) + return __fgets_chk_warn (__s, __builtin_object_size (__s, 2 > 1), __n, __stream); + } + return __fgets_alias (__s, __n, __stream); +} +extern size_t __fread_chk (void *__restrict __ptr, size_t __ptrlen, + size_t __size, size_t __n, + FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern size_t __fread_alias (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "fread") + __attribute__ ((__warn_unused_result__)); +extern size_t __fread_chk_warn (void *__restrict __ptr, size_t __ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "__fread_chk") + __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fread called with bigger size * nmemb than length " "of destination buffer"))) + ; +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) size_t +fread (void *__restrict __ptr, size_t __size, size_t __n, + FILE *__restrict __stream) +{ + if (__builtin_object_size (__ptr, 0) != (size_t) -1) + { + if (!__builtin_constant_p (__size) + || !__builtin_constant_p (__n) + || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2))) + return __fread_chk (__ptr, __builtin_object_size (__ptr, 0), __size, __n, __stream); + if (__size * __n > __builtin_object_size (__ptr, 0)) + return __fread_chk_warn (__ptr, __builtin_object_size (__ptr, 0), __size, __n, __stream); + } + return __fread_alias (__ptr, __size, __n, __stream); +} +extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size, + int __n, FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern char *__fgets_unlocked_alias (char *__restrict __s, int __n, FILE *__restrict __stream) __asm__ ("" "fgets_unlocked") + __attribute__ ((__warn_unused_result__)); +extern char *__fgets_unlocked_chk_warn (char *__restrict __s, size_t __size, int __n, FILE *__restrict __stream) __asm__ ("" "__fgets_unlocked_chk") + __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fgets_unlocked called with bigger size than length " "of destination buffer"))) + ; +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) char * +fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream) +{ + if (__builtin_object_size (__s, 2 > 1) != (size_t) -1) + { + if (!__builtin_constant_p (__n) || __n <= 0) + return __fgets_unlocked_chk (__s, __builtin_object_size (__s, 2 > 1), __n, __stream); + if ((size_t) __n > __builtin_object_size (__s, 2 > 1)) + return __fgets_unlocked_chk_warn (__s, __builtin_object_size (__s, 2 > 1), __n, __stream); + } + return __fgets_unlocked_alias (__s, __n, __stream); +} +extern size_t __fread_unlocked_chk (void *__restrict __ptr, size_t __ptrlen, + size_t __size, size_t __n, + FILE *__restrict __stream) __attribute__ ((__warn_unused_result__)); +extern size_t __fread_unlocked_alias (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "fread_unlocked") + __attribute__ ((__warn_unused_result__)); +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") + __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fread_unlocked called with bigger size * nmemb than " "length of destination buffer"))) + ; +extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) size_t +fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n, + FILE *__restrict __stream) +{ + if (__builtin_object_size (__ptr, 0) != (size_t) -1) + { + if (!__builtin_constant_p (__size) + || !__builtin_constant_p (__n) + || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2))) + return __fread_unlocked_chk (__ptr, __builtin_object_size (__ptr, 0), __size, __n, + __stream); + if (__size * __n > __builtin_object_size (__ptr, 0)) + return __fread_unlocked_chk_warn (__ptr, __builtin_object_size (__ptr, 0), __size, __n, + __stream); + } + if (__builtin_constant_p (__size) + && __builtin_constant_p (__n) + && (__size | __n) < (((size_t) 1) << (8 * sizeof (size_t) / 2)) + && __size * __n <= 8) + { + size_t __cnt = __size * __n; + char *__cptr = (char *) __ptr; + if (__cnt == 0) + return 0; + for (; __cnt > 0; --__cnt) + { + int __c = (__builtin_expect (((__stream)->_IO_read_ptr >= (__stream)->_IO_read_end), 0) ? __uflow (__stream) : *(unsigned char *) (__stream)->_IO_read_ptr++); + if (__c == (-1)) + break; + *__cptr++ = __c; + } + return (__cptr - (char *) __ptr) / __size; + } + return __fread_unlocked_alias (__ptr, __size, __n, __stream); +} +} +extern "C" { +extern __attribute__((visibility ("default"))) JSUint32 JS_snprintf(char *out, JSUint32 outlen, const char *fmt, ...); +extern __attribute__((visibility ("default"))) char* JS_smprintf(const char *fmt, ...); +extern __attribute__((visibility ("default"))) void JS_smprintf_free(char *mem); +extern __attribute__((visibility ("default"))) char* JS_sprintf_append(char *last, const char *fmt, ...); +typedef JSIntn (*JSStuffFunc)(void *arg, const char *s, JSUint32 slen); +extern __attribute__((visibility ("default"))) JSUint32 JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...); +extern __attribute__((visibility ("default"))) JSUint32 JS_vsnprintf(char *out, JSUint32 outlen, const char *fmt, va_list ap); +extern __attribute__((visibility ("default"))) char* JS_vsmprintf(const char *fmt, va_list ap); +extern __attribute__((visibility ("default"))) char* JS_vsprintf_append(char *last, const char *fmt, va_list ap); +extern __attribute__((visibility ("default"))) JSUint32 JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap); +extern __attribute__((visibility ("default"))) JSInt32 JS_sscanf(const char *buf, const char *fmt, ...); +} +extern "C" { +enum JSValueType +{ + JSVAL_TYPE_DOUBLE = 0x00, + JSVAL_TYPE_INT32 = 0x01, + JSVAL_TYPE_UNDEFINED = 0x02, + JSVAL_TYPE_BOOLEAN = 0x03, + JSVAL_TYPE_MAGIC = 0x04, + JSVAL_TYPE_STRING = 0x05, + JSVAL_TYPE_NULL = 0x06, + JSVAL_TYPE_OBJECT = 0x07, + JSVAL_TYPE_NONFUNOBJ = 0x57, + JSVAL_TYPE_FUNOBJ = 0x67, + JSVAL_TYPE_STRORNULL = 0x97, + JSVAL_TYPE_OBJORNULL = 0x98, + JSVAL_TYPE_BOXED = 0x99 +} __attribute__((packed)); +typedef int js_static_assert0[(sizeof(JSValueType) == 1) ? 1 : -1]; +enum JSValueTag +{ + JSVAL_TAG_MAX_DOUBLE = 0x1FFF0, + JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, + JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, + JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, + JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, + JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, + JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, + JSVAL_TAG_OBJECT = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT +} __attribute__((packed)); +typedef int js_static_assert1[(sizeof(JSValueTag) == sizeof(uint32)) ? 1 : -1]; +enum JSValueShiftedTag +{ + JSVAL_SHIFTED_TAG_MAX_DOUBLE = ((((uint64)JSVAL_TAG_MAX_DOUBLE) << 47) | 0xFFFFFFFF), + JSVAL_SHIFTED_TAG_INT32 = (((uint64)JSVAL_TAG_INT32) << 47), + JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64)JSVAL_TAG_UNDEFINED) << 47), + JSVAL_SHIFTED_TAG_STRING = (((uint64)JSVAL_TAG_STRING) << 47), + JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64)JSVAL_TAG_BOOLEAN) << 47), + JSVAL_SHIFTED_TAG_MAGIC = (((uint64)JSVAL_TAG_MAGIC) << 47), + JSVAL_SHIFTED_TAG_NULL = (((uint64)JSVAL_TAG_NULL) << 47), + JSVAL_SHIFTED_TAG_OBJECT = (((uint64)JSVAL_TAG_OBJECT) << 47) +} __attribute__((packed)); +typedef int js_static_assert2[(sizeof(JSValueShiftedTag) == sizeof(uint64)) ? 1 : -1]; +typedef enum JSWhyMagic +{ + JS_ARRAY_HOLE, + JS_ARGS_HOLE, + JS_NATIVE_ENUMERATE, + JS_NO_ITER_VALUE, + JS_GENERATOR_CLOSING, + JS_NO_CONSTANT, + JS_THIS_POISON, + JS_ARG_POISON, + JS_SERIALIZE_NO_NODE, + JS_GENERIC_MAGIC +} JSWhyMagic; +typedef struct JSString JSString; +typedef struct JSFlatString JSFlatString; +typedef struct JSObject JSObject; +typedef union jsval_layout +{ + uint64 asBits; + struct { + uint64 payload47 : 47; + JSValueTag tag : 17; + } debugView; + struct { + union { + int32 i32; + uint32 u32; + JSWhyMagic why; + jsuword word; + } payload; + } s; + double asDouble; + void *asPtr; +} jsval_layout; +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_DOUBLE_IMPL(jsval_layout l) +{ + return l.asBits <= JSVAL_SHIFTED_TAG_MAX_DOUBLE; +} +static __attribute__((always_inline)) inline jsval_layout +DOUBLE_TO_JSVAL_IMPL(double d) +{ + jsval_layout l; + l.asDouble = d; + ((void) 0); + return l; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_INT32_IMPL(jsval_layout l) +{ + return (uint32)(l.asBits >> 47) == JSVAL_TAG_INT32; +} +static __attribute__((always_inline)) inline int32 +JSVAL_TO_INT32_IMPL(jsval_layout l) +{ + return (int32)l.asBits; +} +static __attribute__((always_inline)) inline jsval_layout +INT32_TO_JSVAL_IMPL(int32 i32) +{ + jsval_layout l; + l.asBits = ((uint64)(uint32)i32) | JSVAL_SHIFTED_TAG_INT32; + return l; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_NUMBER_IMPL(jsval_layout l) +{ + return l.asBits < JSVAL_SHIFTED_TAG_UNDEFINED; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_UNDEFINED_IMPL(jsval_layout l) +{ + return l.asBits == JSVAL_SHIFTED_TAG_UNDEFINED; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_STRING_IMPL(jsval_layout l) +{ + return (uint32)(l.asBits >> 47) == JSVAL_TAG_STRING; +} +static __attribute__((always_inline)) inline jsval_layout +STRING_TO_JSVAL_IMPL(JSString *str) +{ + jsval_layout l; + uint64 strBits = (uint64)str; + ((void) 0); + ((void) 0); + l.asBits = strBits | JSVAL_SHIFTED_TAG_STRING; + return l; +} +static __attribute__((always_inline)) inline JSString * +JSVAL_TO_STRING_IMPL(jsval_layout l) +{ + return (JSString *)(l.asBits & 0x00007FFFFFFFFFFFLL); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_BOOLEAN_IMPL(jsval_layout l) +{ + return (uint32)(l.asBits >> 47) == JSVAL_TAG_BOOLEAN; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_TO_BOOLEAN_IMPL(jsval_layout l) +{ + return (JSBool)l.asBits; +} +static __attribute__((always_inline)) inline jsval_layout +BOOLEAN_TO_JSVAL_IMPL(JSBool b) +{ + jsval_layout l; + l.asBits = ((uint64)(uint32)b) | JSVAL_SHIFTED_TAG_BOOLEAN; + return l; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_MAGIC_IMPL(jsval_layout l) +{ + return (l.asBits >> 47) == JSVAL_TAG_MAGIC; +} +static __attribute__((always_inline)) inline JSObject * +MAGIC_JSVAL_TO_OBJECT_OR_NULL_IMPL(jsval_layout l) +{ + uint64 ptrBits = l.asBits & 0x00007FFFFFFFFFFFLL; + ((void) 0); + ((void) 0); + return (JSObject *)ptrBits; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_PRIMITIVE_IMPL(jsval_layout l) +{ + return l.asBits < JSVAL_SHIFTED_TAG_OBJECT; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_OBJECT_IMPL(jsval_layout l) +{ + ((void) 0); + return l.asBits >= JSVAL_SHIFTED_TAG_OBJECT; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_OBJECT_OR_NULL_IMPL(jsval_layout l) +{ + ((void) 0); + return l.asBits >= JSVAL_SHIFTED_TAG_NULL; +} +static __attribute__((always_inline)) inline JSObject * +JSVAL_TO_OBJECT_IMPL(jsval_layout l) +{ + uint64 ptrBits = l.asBits & 0x00007FFFFFFFFFFFLL; + ((void) 0); + return (JSObject *)ptrBits; +} +static __attribute__((always_inline)) inline jsval_layout +OBJECT_TO_JSVAL_IMPL(JSObject *obj) +{ + jsval_layout l; + uint64 objBits = (uint64)obj; + ((void) 0); + ((void) 0); + l.asBits = objBits | JSVAL_SHIFTED_TAG_OBJECT; + return l; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_NULL_IMPL(jsval_layout l) +{ + return l.asBits == JSVAL_SHIFTED_TAG_NULL; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_GCTHING_IMPL(jsval_layout l) +{ + return l.asBits >= JSVAL_SHIFTED_TAG_STRING; +} +static __attribute__((always_inline)) inline void * +JSVAL_TO_GCTHING_IMPL(jsval_layout l) +{ + uint64 ptrBits = l.asBits & 0x00007FFFFFFFFFFFLL; + ((void) 0); + return (void *)ptrBits; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_TRACEABLE_IMPL(jsval_layout l) +{ + return JSVAL_IS_GCTHING_IMPL(l) && !JSVAL_IS_NULL_IMPL(l); +} +static __attribute__((always_inline)) inline uint32 +JSVAL_TRACE_KIND_IMPL(jsval_layout l) +{ + return (uint32)(JSBool)!(JSVAL_IS_OBJECT_IMPL(l)); +} +static __attribute__((always_inline)) inline jsval_layout +PRIVATE_PTR_TO_JSVAL_IMPL(void *ptr) +{ + jsval_layout l; + uint64 ptrBits = (uint64)ptr; + ((void) 0); + l.asBits = ptrBits >> 1; + ((void) 0); + return l; +} +static __attribute__((always_inline)) inline void * +JSVAL_TO_PRIVATE_PTR_IMPL(jsval_layout l) +{ + ((void) 0); + return (void *)(l.asBits << 1); +} +static __attribute__((always_inline)) inline double +JS_CANONICALIZE_NAN(double d) +{ + if ((__builtin_expect((d != d), 0))) { + jsval_layout l; + l.asBits = 0x7FF8000000000000LL; + return l.asDouble; + } + return d; +} +typedef __attribute__((aligned (8))) uint64 jsval; +typedef ptrdiff_t jsid; +} +extern "C" { +typedef JSInt32 jsint; +typedef JSUint32 jsuint; +typedef float64 jsdouble; +typedef JSInt32 jsrefcount; +typedef JSUint16 jschar; +typedef enum JSVersion { + JSVERSION_1_0 = 100, + JSVERSION_1_1 = 110, + JSVERSION_1_2 = 120, + JSVERSION_1_3 = 130, + JSVERSION_1_4 = 140, + JSVERSION_ECMA_3 = 148, + JSVERSION_1_5 = 150, + JSVERSION_1_6 = 160, + JSVERSION_1_7 = 170, + JSVERSION_1_8 = 180, + JSVERSION_ECMA_5 = 185, + JSVERSION_DEFAULT = 0, + JSVERSION_UNKNOWN = -1, + JSVERSION_LATEST = JSVERSION_ECMA_5 +} JSVersion; +typedef enum JSType { + JSTYPE_VOID, + JSTYPE_OBJECT, + JSTYPE_FUNCTION, + JSTYPE_STRING, + JSTYPE_NUMBER, + JSTYPE_BOOLEAN, + JSTYPE_NULL, + JSTYPE_XML, + JSTYPE_LIMIT +} JSType; +typedef enum JSProtoKey { +JSProto_Null = 0, +JSProto_Object = 1, +JSProto_Function = 2, +JSProto_Array = 3, +JSProto_Boolean = 4, +JSProto_JSON = 5, +JSProto_Date = 6, +JSProto_Math = 7, +JSProto_Number = 8, +JSProto_String = 9, +JSProto_RegExp = 10, +JSProto_XML = 11, +JSProto_Namespace = 12, +JSProto_QName = 13, +JSProto_Reflect = 14, +JSProto_ASTNode = 15, +JSProto_Error = 16, +JSProto_InternalError = 17, +JSProto_EvalError = 18, +JSProto_RangeError = 19, +JSProto_ReferenceError = 20, +JSProto_SyntaxError = 21, +JSProto_TypeError = 22, +JSProto_URIError = 23, +JSProto_Generator = 24, +JSProto_Iterator = 25, +JSProto_StopIteration = 26, +JSProto_ArrayBuffer = 27, +JSProto_Int8Array = 28, +JSProto_Uint8Array = 29, +JSProto_Int16Array = 30, +JSProto_Uint16Array = 31, +JSProto_Int32Array = 32, +JSProto_Uint32Array = 33, +JSProto_Float32Array = 34, +JSProto_Float64Array = 35, +JSProto_Uint8ClampedArray = 36, +JSProto_Proxy = 37, +JSProto_AnyName = 38, + JSProto_LIMIT +} JSProtoKey; +typedef enum JSAccessMode { + JSACC_PROTO = 0, + JSACC_PARENT = 1, + JSACC_WATCH = 3, + JSACC_READ = 4, + JSACC_WRITE = 8, + JSACC_LIMIT +} JSAccessMode; +typedef enum JSIterateOp { + JSENUMERATE_INIT, + JSENUMERATE_INIT_ALL, + JSENUMERATE_NEXT, + JSENUMERATE_DESTROY +} JSIterateOp; +typedef struct JSClass JSClass; +typedef struct JSConstDoubleSpec JSConstDoubleSpec; +typedef struct JSContext JSContext; +typedef struct JSErrorReport JSErrorReport; +typedef struct JSFunction JSFunction; +typedef struct JSFunctionSpec JSFunctionSpec; +typedef struct JSTracer JSTracer; +typedef struct JSIdArray JSIdArray; +typedef struct JSPropertyDescriptor JSPropertyDescriptor; +typedef struct JSPropertySpec JSPropertySpec; +typedef struct JSObjectMap JSObjectMap; +typedef struct JSRuntime JSRuntime; +typedef struct JSStackFrame JSStackFrame; +typedef struct JSXDRState JSXDRState; +typedef struct JSExceptionState JSExceptionState; +typedef struct JSLocaleCallbacks JSLocaleCallbacks; +typedef struct JSSecurityCallbacks JSSecurityCallbacks; +typedef struct JSONParser JSONParser; +typedef struct JSCompartment JSCompartment; +typedef struct JSCrossCompartmentCall JSCrossCompartmentCall; +typedef struct JSStructuredCloneWriter JSStructuredCloneWriter; +typedef struct JSStructuredCloneReader JSStructuredCloneReader; +typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks; +typedef class JSWrapper JSWrapper; +typedef class JSCrossCompartmentWrapper JSCrossCompartmentWrapper; +typedef JSBool +(* JSPropertyOp)(JSContext *cx, JSObject *obj, jsid id, jsval *vp); +typedef JSBool +(* JSStrictPropertyOp)(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp); +typedef JSBool +(* JSNewEnumerateOp)(JSContext *cx, JSObject *obj, JSIterateOp enum_op, + jsval *statep, jsid *idp); +typedef JSBool +(* JSEnumerateOp)(JSContext *cx, JSObject *obj); +typedef JSBool +(* JSResolveOp)(JSContext *cx, JSObject *obj, jsid id); +typedef JSBool +(* JSNewResolveOp)(JSContext *cx, JSObject *obj, jsid id, uintN flags, + JSObject **objp); +typedef JSBool +(* JSConvertOp)(JSContext *cx, JSObject *obj, JSType type, jsval *vp); +typedef JSType +(* JSTypeOfOp)(JSContext *cx, JSObject *obj); +typedef void +(* JSFinalizeOp)(JSContext *cx, JSObject *obj); +typedef void +(* JSStringFinalizeOp)(JSContext *cx, JSString *str); +typedef JSBool +(* JSCheckAccessOp)(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, + jsval *vp); +typedef JSBool +(* JSXDRObjectOp)(JSXDRState *xdr, JSObject **objp); +typedef JSBool +(* JSHasInstanceOp)(JSContext *cx, JSObject *obj, const jsval *v, JSBool *bp); +typedef uint32 +(* JSMarkOp)(JSContext *cx, JSObject *obj, void *arg); +typedef void +(* JSTraceOp)(JSTracer *trc, JSObject *obj); +typedef void +(* JSTraceCallback)(JSTracer *trc, void *thing, uint32 kind); +typedef void +(* JSTraceNamePrinter)(JSTracer *trc, char *buf, size_t bufsize); +typedef JSBool +(* JSEqualityOp)(JSContext *cx, JSObject *obj, const jsval *v, JSBool *bp); +typedef JSBool +(* JSNative)(JSContext *cx, uintN argc, jsval *vp); +typedef enum JSContextOp { + JSCONTEXT_NEW, + JSCONTEXT_DESTROY +} JSContextOp; +typedef JSBool +(* JSContextCallback)(JSContext *cx, uintN contextOp); +typedef enum JSGCStatus { + JSGC_BEGIN, + JSGC_END, + JSGC_MARK_END, + JSGC_FINALIZE_END +} JSGCStatus; +typedef JSBool +(* JSGCCallback)(JSContext *cx, JSGCStatus status); +typedef void +(* JSTraceDataOp)(JSTracer *trc, void *data); +typedef JSBool +(* JSOperationCallback)(JSContext *cx); +typedef void +(* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); +typedef enum JSExnType { + JSEXN_NONE = -1, + JSEXN_ERR, + JSEXN_INTERNALERR, + JSEXN_EVALERR, + JSEXN_RANGEERR, + JSEXN_REFERENCEERR, + JSEXN_SYNTAXERR, + JSEXN_TYPEERR, + JSEXN_URIERR, + JSEXN_LIMIT +} JSExnType; +typedef struct JSErrorFormatString { + const char *format; + uint16 argCount; + int16 exnType; +} JSErrorFormatString; +typedef const JSErrorFormatString * +(* JSErrorCallback)(void *userRef, const char *locale, + const uintN errorNumber); +typedef JSBool +(* JSArgumentFormatter)(JSContext *cx, const char *format, JSBool fromJS, + jsval **vpp, va_list *app); +typedef JSBool +(* JSLocaleToUpperCase)(JSContext *cx, JSString *src, jsval *rval); +typedef JSBool +(* JSLocaleToLowerCase)(JSContext *cx, JSString *src, jsval *rval); +typedef JSBool +(* JSLocaleCompare)(JSContext *cx, JSString *src1, JSString *src2, + jsval *rval); +typedef JSBool +(* JSLocaleToUnicode)(JSContext *cx, const char *src, jsval *rval); +typedef struct JSPrincipals JSPrincipals; +typedef JSBool +(* JSPrincipalsTranscoder)(JSXDRState *xdr, JSPrincipals **principalsp); +typedef JSPrincipals * +(* JSObjectPrincipalsFinder)(JSContext *cx, JSObject *obj); +typedef JSBool +(* JSCSPEvalChecker)(JSContext *cx); +typedef JSObject * +(* JSWrapObjectCallback)(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent, + uintN flags); +typedef JSObject * +(* JSPreWrapCallback)(JSContext *cx, JSObject *scope, JSObject *obj, uintN flags); +typedef enum { + JSCOMPARTMENT_NEW, + JSCOMPARTMENT_DESTROY +} JSCompartmentOp; +typedef JSBool +(* JSCompartmentCallback)(JSContext *cx, JSCompartment *compartment, uintN compartmentOp); +typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r, + uint32 tag, uint32 data, void *closure); +typedef JSBool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w, + JSObject *obj, void *closure); +typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32 errorid); +} +extern "C" { +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_NULL(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_NULL_IMPL(l); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_VOID(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_UNDEFINED_IMPL(l); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_INT(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_INT32_IMPL(l); +} +static __attribute__((always_inline)) inline jsint +JSVAL_TO_INT(jsval v) +{ + jsval_layout l; + ((void) 0); + l.asBits = (v); + return JSVAL_TO_INT32_IMPL(l); +} +static __attribute__((always_inline)) inline jsval +INT_TO_JSVAL(int32 i) +{ + return ((INT32_TO_JSVAL_IMPL(i)).asBits); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_DOUBLE(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_DOUBLE_IMPL(l); +} +static __attribute__((always_inline)) inline jsdouble +JSVAL_TO_DOUBLE(jsval v) +{ + jsval_layout l; + ((void) 0); + l.asBits = (v); + return l.asDouble; +} +static __attribute__((always_inline)) inline jsval +DOUBLE_TO_JSVAL(jsdouble d) +{ + d = JS_CANONICALIZE_NAN(d); + return ((DOUBLE_TO_JSVAL_IMPL(d)).asBits); +} +static __attribute__((always_inline)) inline jsval +UINT_TO_JSVAL(uint32 i) +{ + if (i <= ((jsint)0x7fffffff)) + return INT_TO_JSVAL((int32)i); + return DOUBLE_TO_JSVAL((jsdouble)i); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_NUMBER(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_NUMBER_IMPL(l); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_STRING(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_STRING_IMPL(l); +} +static __attribute__((always_inline)) inline JSString * +JSVAL_TO_STRING(jsval v) +{ + jsval_layout l; + ((void) 0); + l.asBits = (v); + return JSVAL_TO_STRING_IMPL(l); +} +static __attribute__((always_inline)) inline jsval +STRING_TO_JSVAL(JSString *str) +{ + return ((STRING_TO_JSVAL_IMPL(str)).asBits); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_OBJECT(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_OBJECT_OR_NULL_IMPL(l); +} +static __attribute__((always_inline)) inline JSObject * +JSVAL_TO_OBJECT(jsval v) +{ + jsval_layout l; + ((void) 0); + l.asBits = (v); + return JSVAL_TO_OBJECT_IMPL(l); +} +static __attribute__((always_inline)) inline jsval +OBJECT_TO_JSVAL(JSObject *obj) +{ + if (obj) + return ((OBJECT_TO_JSVAL_IMPL(obj)).asBits); + return ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_BOOLEAN(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_BOOLEAN_IMPL(l); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_TO_BOOLEAN(jsval v) +{ + jsval_layout l; + ((void) 0); + l.asBits = (v); + return JSVAL_TO_BOOLEAN_IMPL(l); +} +static __attribute__((always_inline)) inline jsval +BOOLEAN_TO_JSVAL(JSBool b) +{ + return ((BOOLEAN_TO_JSVAL_IMPL(b)).asBits); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_PRIMITIVE(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_PRIMITIVE_IMPL(l); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_GCTHING(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_GCTHING_IMPL(l); +} +static __attribute__((always_inline)) inline void * +JSVAL_TO_GCTHING(jsval v) +{ + jsval_layout l; + ((void) 0); + l.asBits = (v); + return JSVAL_TO_GCTHING_IMPL(l); +} +static __attribute__((always_inline)) inline jsval +PRIVATE_TO_JSVAL(void *ptr) +{ + return ((PRIVATE_PTR_TO_JSVAL_IMPL(ptr)).asBits); +} +static __attribute__((always_inline)) inline void * +JSVAL_TO_PRIVATE(jsval v) +{ + jsval_layout l; + ((void) 0); + l.asBits = (v); + return JSVAL_TO_PRIVATE_PTR_IMPL(l); +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_STRING(jsid iden) +{ + return ((iden) & 0x7) == 0; +} +static __attribute__((always_inline)) inline JSString * +JSID_TO_STRING(jsid iden) +{ + ((void) 0); + return (JSString *)((iden)); +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_ZERO(jsid iden) +{ + return (iden) == 0; +} +__attribute__((visibility ("default"))) JSBool +JS_StringHasBeenInterned(JSString *str); +static __attribute__((always_inline)) inline jsid +INTERNED_STRING_TO_JSID(JSString *str) +{ + jsid iden; + ((void) 0); + ((void) 0); + ((void) 0); + (iden) = (size_t)str; + return iden; +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_INT(jsid iden) +{ + return !!((iden) & 0x1); +} +static __attribute__((always_inline)) inline int32 +JSID_TO_INT(jsid iden) +{ + ((void) 0); + return ((int32)(iden)) >> 1; +} +static __attribute__((always_inline)) inline JSBool +INT_FITS_IN_JSID(int32 i) +{ + return ((jsuint)(i) - (jsuint)(-(1 << 30)) <= + (jsuint)(((1 << 30) - 1) - (-(1 << 30)))); +} +static __attribute__((always_inline)) inline jsid +INT_TO_JSID(int32 i) +{ + jsid iden; + ((void) 0); + (iden) = ((i << 1) | 0x1); + return iden; +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_OBJECT(jsid iden) +{ + return ((iden) & 0x7) == 0x4 && + (size_t)(iden) != 0x4; +} +static __attribute__((always_inline)) inline JSObject * +JSID_TO_OBJECT(jsid iden) +{ + ((void) 0); + return (JSObject *)((iden) & ~(size_t)0x7); +} +static __attribute__((always_inline)) inline jsid +OBJECT_TO_JSID(JSObject *obj) +{ + jsid iden; + ((void) 0); + ((void) 0); + (iden) = ((size_t)obj | 0x4); + return iden; +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_GCTHING(jsid iden) +{ + return JSID_IS_STRING(iden) || JSID_IS_OBJECT(iden); +} +static __attribute__((always_inline)) inline void * +JSID_TO_GCTHING(jsid iden) +{ + return (void *)((iden) & ~(size_t)0x7); +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_DEFAULT_XML_NAMESPACE(jsid iden) +{ + ((void) 0) + ; + return ((size_t)(iden) == 0x6); +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_VOID(jsid iden) +{ + ((void) 0) + ; + return ((size_t)(iden) == 0x2); +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_EMPTY(jsid iden) +{ + return ((size_t)(iden) == 0x4); +} +extern __attribute__((visibility ("default"))) int64 +JS_Now(void); +extern __attribute__((visibility ("default"))) jsval +JS_GetNaNValue(JSContext *cx); +extern __attribute__((visibility ("default"))) jsval +JS_GetNegativeInfinityValue(JSContext *cx); +extern __attribute__((visibility ("default"))) jsval +JS_GetPositiveInfinityValue(JSContext *cx); +extern __attribute__((visibility ("default"))) jsval +JS_GetEmptyStringValue(JSContext *cx); +extern __attribute__((visibility ("default"))) JSString * +JS_GetEmptyString(JSRuntime *rt); +extern __attribute__((visibility ("default"))) JSBool +JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format, + ...); +extern __attribute__((visibility ("default"))) JSBool +JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv, + const char *format, va_list ap); +extern __attribute__((visibility ("default"))) JSBool +JS_AddArgumentFormatter(JSContext *cx, const char *format, + JSArgumentFormatter formatter); +extern __attribute__((visibility ("default"))) void +JS_RemoveArgumentFormatter(JSContext *cx, const char *format); +extern __attribute__((visibility ("default"))) JSBool +JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp); +extern __attribute__((visibility ("default"))) JSFunction * +JS_ValueToFunction(JSContext *cx, jsval v); +extern __attribute__((visibility ("default"))) JSFunction * +JS_ValueToConstructor(JSContext *cx, jsval v); +extern __attribute__((visibility ("default"))) JSString * +JS_ValueToString(JSContext *cx, jsval v); +extern __attribute__((visibility ("default"))) JSString * +JS_ValueToSource(JSContext *cx, jsval v); +extern __attribute__((visibility ("default"))) JSBool +JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp); +extern __attribute__((visibility ("default"))) JSBool +JS_DoubleIsInt32(jsdouble d, jsint *ip); +extern __attribute__((visibility ("default"))) JSBool +JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip); +extern __attribute__((visibility ("default"))) JSBool +JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip); +extern __attribute__((visibility ("default"))) JSBool +JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip); +extern __attribute__((visibility ("default"))) JSBool +JS_ValueToUint16(JSContext *cx, jsval v, uint16 *ip); +extern __attribute__((visibility ("default"))) JSBool +JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp); +extern __attribute__((visibility ("default"))) JSType +JS_TypeOfValue(JSContext *cx, jsval v); +extern __attribute__((visibility ("default"))) const char * +JS_GetTypeName(JSContext *cx, JSType type); +extern __attribute__((visibility ("default"))) JSBool +JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, JSBool *equal); +extern __attribute__((visibility ("default"))) JSBool +JS_SameValue(JSContext *cx, jsval v1, jsval v2, JSBool *same); +extern __attribute__((visibility ("default"))) JSRuntime * +JS_Init(uint32 maxbytes); +extern __attribute__((visibility ("default"))) void +JS_Finish(JSRuntime *rt); +extern __attribute__((visibility ("default"))) void +JS_ShutDown(void); +__attribute__((visibility ("default"))) void * +JS_GetRuntimePrivate(JSRuntime *rt); +__attribute__((visibility ("default"))) void +JS_SetRuntimePrivate(JSRuntime *rt, void *data); +extern __attribute__((visibility ("default"))) void +JS_BeginRequest(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_EndRequest(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_YieldRequest(JSContext *cx); +extern __attribute__((visibility ("default"))) jsrefcount +JS_SuspendRequest(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth); +extern __attribute__((visibility ("default"))) JSBool +JS_IsInRequest(JSContext *cx); +} +class JSAutoRequest { + public: + JSAutoRequest(JSContext *cx ) + : mContext(cx), mSaveDepth(0) { + do { } while (0); + JS_BeginRequest(mContext); + } + ~JSAutoRequest() { + JS_EndRequest(mContext); + } + void suspend() { + mSaveDepth = JS_SuspendRequest(mContext); + } + void resume() { + JS_ResumeRequest(mContext, mSaveDepth); + } + protected: + JSContext *mContext; + jsrefcount mSaveDepth; + +}; +class JSAutoSuspendRequest { + public: + JSAutoSuspendRequest(JSContext *cx ) + : mContext(cx), mSaveDepth(0) { + do { } while (0); + if (mContext) { + mSaveDepth = JS_SuspendRequest(mContext); + } + } + ~JSAutoSuspendRequest() { + resume(); + } + void resume() { + if (mContext) { + JS_ResumeRequest(mContext, mSaveDepth); + mContext = 0; + } + } + protected: + JSContext *mContext; + jsrefcount mSaveDepth; + +}; +class JSAutoCheckRequest { + public: + JSAutoCheckRequest(JSContext *cx ) { + do { } while (0); + } + ~JSAutoCheckRequest() { + } + private: + +}; +extern "C" { +extern __attribute__((visibility ("default"))) void +JS_Lock(JSRuntime *rt); +extern __attribute__((visibility ("default"))) void +JS_Unlock(JSRuntime *rt); +extern __attribute__((visibility ("default"))) JSContextCallback +JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback); +extern __attribute__((visibility ("default"))) JSContext * +JS_NewContext(JSRuntime *rt, size_t stackChunkSize); +extern __attribute__((visibility ("default"))) void +JS_DestroyContext(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_DestroyContextNoGC(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_DestroyContextMaybeGC(JSContext *cx); +extern __attribute__((visibility ("default"))) void * +JS_GetContextPrivate(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_SetContextPrivate(JSContext *cx, void *data); +extern __attribute__((visibility ("default"))) JSRuntime * +JS_GetRuntime(JSContext *cx); +extern __attribute__((visibility ("default"))) JSContext * +JS_ContextIterator(JSRuntime *rt, JSContext **iterp); +extern __attribute__((visibility ("default"))) JSVersion +JS_GetVersion(JSContext *cx); +extern __attribute__((visibility ("default"))) JSVersion +JS_SetVersion(JSContext *cx, JSVersion version); +extern __attribute__((visibility ("default"))) const char * +JS_VersionToString(JSVersion version); +extern __attribute__((visibility ("default"))) JSVersion +JS_StringToVersion(const char *string); +extern __attribute__((visibility ("default"))) uint32 +JS_GetOptions(JSContext *cx); +extern __attribute__((visibility ("default"))) uint32 +JS_SetOptions(JSContext *cx, uint32 options); +extern __attribute__((visibility ("default"))) uint32 +JS_ToggleOptions(JSContext *cx, uint32 options); +extern __attribute__((visibility ("default"))) const char * +JS_GetImplementationVersion(void); +extern __attribute__((visibility ("default"))) JSCompartmentCallback +JS_SetCompartmentCallback(JSRuntime *rt, JSCompartmentCallback callback); +extern __attribute__((visibility ("default"))) JSWrapObjectCallback +JS_SetWrapObjectCallbacks(JSRuntime *rt, + JSWrapObjectCallback callback, + JSPreWrapCallback precallback); +extern __attribute__((visibility ("default"))) JSCrossCompartmentCall * +JS_EnterCrossCompartmentCall(JSContext *cx, JSObject *target); +extern __attribute__((visibility ("default"))) void +JS_LeaveCrossCompartmentCall(JSCrossCompartmentCall *call); +extern __attribute__((visibility ("default"))) void * +JS_SetCompartmentPrivate(JSContext *cx, JSCompartment *compartment, void *data); +extern __attribute__((visibility ("default"))) void * +JS_GetCompartmentPrivate(JSContext *cx, JSCompartment *compartment); +extern __attribute__((visibility ("default"))) JSBool +JS_WrapObject(JSContext *cx, JSObject **objp); +extern __attribute__((visibility ("default"))) JSBool +JS_WrapValue(JSContext *cx, jsval *vp); +extern __attribute__((visibility ("default"))) JSObject * +JS_TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target); +extern __attribute__((visibility ("default"))) JSObject * +js_TransplantObjectWithWrapper(JSContext *cx, + JSObject *origobj, + JSObject *origwrapper, + JSObject *targetobj, + JSObject *targetwrapper); +extern __attribute__((visibility ("default"))) JSObject * +js_TransplantObjectWithWrapper(JSContext *cx, + JSObject *origobj, + JSObject *origwrapper, + JSObject *targetobj, + JSObject *targetwrapper); +} +class __attribute__((visibility ("default"))) JSAutoEnterCompartment +{ + JSCrossCompartmentCall *call; + public: + JSAutoEnterCompartment() : call(__null) {} + bool enter(JSContext *cx, JSObject *target); + void enterAndIgnoreErrors(JSContext *cx, JSObject *target); + bool entered() const { return call != __null; } + ~JSAutoEnterCompartment() { + if (call && call != reinterpret_cast(1)) + JS_LeaveCrossCompartmentCall(call); + } + void swap(JSAutoEnterCompartment &other) { + JSCrossCompartmentCall *tmp = call; + call = other.call; + other.call = tmp; + } +}; +extern "C" { +extern __attribute__((visibility ("default"))) JSObject * +JS_GetGlobalObject(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_SetGlobalObject(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_InitStandardClasses(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsid id, + JSBool *resolved); +extern __attribute__((visibility ("default"))) JSBool +JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSIdArray * +JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj, + JSIdArray *ida); +extern __attribute__((visibility ("default"))) JSBool +JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, + JSObject **objp); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetScopeChain(JSContext *cx); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetGlobalForObject(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetGlobalForScopeChain(JSContext *cx); +extern __attribute__((visibility ("default"))) jsval +JS_ComputeThis(JSContext *cx, jsval *vp); +static inline jsval +JS_THIS(JSContext *cx, jsval *vp) +{ + return JSVAL_IS_PRIMITIVE(vp[1]) ? JS_ComputeThis(cx, vp) : vp[1]; +} +extern __attribute__((visibility ("default"))) void * +JS_malloc(JSContext *cx, size_t nbytes); +extern __attribute__((visibility ("default"))) void * +JS_realloc(JSContext *cx, void *p, size_t nbytes); +extern __attribute__((visibility ("default"))) void +JS_free(JSContext *cx, void *p); +extern __attribute__((visibility ("default"))) void +JS_updateMallocCounter(JSContext *cx, size_t nbytes); +extern __attribute__((visibility ("default"))) char * +JS_strdup(JSContext *cx, const char *s); +extern __attribute__((visibility ("default"))) JSBool +JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_AddValueRoot(JSContext *cx, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_AddStringRoot(JSContext *cx, JSString **rp); +extern __attribute__((visibility ("default"))) JSBool +JS_AddObjectRoot(JSContext *cx, JSObject **rp); +extern __attribute__((visibility ("default"))) JSBool +JS_AddGCThingRoot(JSContext *cx, void **rp); +extern __attribute__((visibility ("default"))) JSBool +JS_AddNamedValueRoot(JSContext *cx, jsval *vp, const char *name); +extern __attribute__((visibility ("default"))) JSBool +JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name); +extern __attribute__((visibility ("default"))) JSBool +JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name); +extern __attribute__((visibility ("default"))) JSBool +JS_AddNamedGCThingRoot(JSContext *cx, void **rp, const char *name); +extern __attribute__((visibility ("default"))) JSBool +JS_RemoveValueRoot(JSContext *cx, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_RemoveStringRoot(JSContext *cx, JSString **rp); +extern __attribute__((visibility ("default"))) JSBool +JS_RemoveObjectRoot(JSContext *cx, JSObject **rp); +extern __attribute__((visibility ("default"))) JSBool +JS_RemoveGCThingRoot(JSContext *cx, void **rp); +extern __attribute__((visibility ("default"))) JSBool +js_AddRootRT(JSRuntime *rt, jsval *vp, const char *name); +extern __attribute__((visibility ("default"))) JSBool +js_AddGCThingRootRT(JSRuntime *rt, void **rp, const char *name); +extern __attribute__((visibility ("default"))) JSBool +js_RemoveRoot(JSRuntime *rt, void *rp); +} +namespace JS { +template class AnchorPermitted; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template<> class AnchorPermitted { }; +template +class Anchor: AnchorPermitted { + public: + Anchor() { } + explicit Anchor(T t) { hold = t; } + inline ~Anchor(); + T &get() { return hold; } + void set(const T &t) { hold = t; } + void clear() { hold = 0; } + private: + T hold; + Anchor(const Anchor &); + const Anchor &operator=(const Anchor &); +}; +template +inline Anchor::~Anchor() { + asm volatile("":: "g" (hold) : "memory"); +} +} +extern "C" { +extern __attribute__((noinline)) __attribute__((visibility ("default"))) void +JS_AnchorPtr(void *p); +typedef enum JSGCRootType { + JS_GC_ROOT_VALUE_PTR, + JS_GC_ROOT_GCTHING_PTR +} JSGCRootType; +typedef intN +(* JSGCRootMapFun)(void *rp, JSGCRootType type, const char *name, void *data); +extern __attribute__((visibility ("default"))) uint32 +JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data); +extern __attribute__((visibility ("default"))) JSBool +JS_LockGCThing(JSContext *cx, void *thing); +extern __attribute__((visibility ("default"))) JSBool +JS_LockGCThingRT(JSRuntime *rt, void *thing); +extern __attribute__((visibility ("default"))) JSBool +JS_UnlockGCThing(JSContext *cx, void *thing); +extern __attribute__((visibility ("default"))) JSBool +JS_UnlockGCThingRT(JSRuntime *rt, void *thing); +extern __attribute__((visibility ("default"))) void +JS_SetExtraGCRoots(JSRuntime *rt, JSTraceDataOp traceOp, void *data); +extern __attribute__((visibility ("default"))) void +JS_MarkGCThing(JSContext *cx, jsval v, const char *name, void *arg); +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_TRACEABLE(jsval v) +{ + jsval_layout l; + l.asBits = (v); + return JSVAL_IS_TRACEABLE_IMPL(l); +} +static __attribute__((always_inline)) inline void * +JSVAL_TO_TRACEABLE(jsval v) +{ + return JSVAL_TO_GCTHING(v); +} +static __attribute__((always_inline)) inline uint32 +JSVAL_TRACE_KIND(jsval v) +{ + jsval_layout l; + ((void) 0); + l.asBits = (v); + return JSVAL_TRACE_KIND_IMPL(l); +} +struct JSTracer { + JSContext *context; + JSTraceCallback callback; + JSTraceNamePrinter debugPrinter; + const void *debugPrintArg; + size_t debugPrintIndex; +}; +extern __attribute__((visibility ("default"))) void +JS_CallTracer(JSTracer *trc, void *thing, uint32 kind); +extern __attribute__((visibility ("default"))) void +JS_TraceChildren(JSTracer *trc, void *thing, uint32 kind); +extern __attribute__((visibility ("default"))) void +JS_TraceRuntime(JSTracer *trc); +extern __attribute__((visibility ("default"))) void +JS_GC(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_MaybeGC(JSContext *cx); +extern __attribute__((visibility ("default"))) JSGCCallback +JS_SetGCCallback(JSContext *cx, JSGCCallback cb); +extern __attribute__((visibility ("default"))) JSGCCallback +JS_SetGCCallbackRT(JSRuntime *rt, JSGCCallback cb); +extern __attribute__((visibility ("default"))) JSBool +JS_IsGCMarkingTracer(JSTracer *trc); +extern __attribute__((visibility ("default"))) JSBool +JS_IsAboutToBeFinalized(JSContext *cx, void *thing); +typedef enum JSGCParamKey { + JSGC_MAX_BYTES = 0, + JSGC_MAX_MALLOC_BYTES = 1, + JSGC_STACKPOOL_LIFESPAN = 2, + JSGC_TRIGGER_FACTOR = 3, + JSGC_BYTES = 4, + JSGC_NUMBER = 5, + JSGC_MAX_CODE_CACHE_BYTES = 6, + JSGC_MODE = 7, + JSGC_UNUSED_CHUNKS = 8 +} JSGCParamKey; +typedef enum JSGCMode { + JSGC_MODE_GLOBAL = 0, + JSGC_MODE_COMPARTMENT = 1 +} JSGCMode; +extern __attribute__((visibility ("default"))) void +JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32 value); +extern __attribute__((visibility ("default"))) uint32 +JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key); +extern __attribute__((visibility ("default"))) void +JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32 value); +extern __attribute__((visibility ("default"))) uint32 +JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); +extern __attribute__((visibility ("default"))) void +JS_FlushCaches(JSContext *cx); +extern __attribute__((visibility ("default"))) intN +JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer); +extern __attribute__((visibility ("default"))) intN +JS_RemoveExternalStringFinalizer(JSStringFinalizeOp finalizer); +extern __attribute__((visibility ("default"))) JSString * +JS_NewExternalString(JSContext *cx, jschar *chars, size_t length, intN type); +extern __attribute__((visibility ("default"))) intN +JS_GetExternalStringGCType(JSRuntime *rt, JSString *str); +extern __attribute__((visibility ("default"))) void +JS_SetThreadStackLimit(JSContext *cx, jsuword limitAddr); +extern __attribute__((visibility ("default"))) void +JS_SetNativeStackQuota(JSContext *cx, size_t stackSize); +extern __attribute__((visibility ("default"))) void +JS_SetScriptStackQuota(JSContext *cx, size_t quota); +typedef void (*JSClassInternal)(); +struct JSClass { + const char *name; + uint32 flags; + JSPropertyOp addProperty; + JSPropertyOp delProperty; + JSPropertyOp getProperty; + JSStrictPropertyOp setProperty; + JSEnumerateOp enumerate; + JSResolveOp resolve; + JSConvertOp convert; + JSFinalizeOp finalize; + JSClassInternal reserved0; + JSCheckAccessOp checkAccess; + JSNative call; + JSNative construct; + JSXDRObjectOp xdrObject; + JSHasInstanceOp hasInstance; + JSMarkOp mark; + JSClassInternal reserved1; + void *reserved[19]; +}; +struct JSIdArray { + jsint length; + jsid vector[1]; +}; +extern __attribute__((visibility ("default"))) void +JS_DestroyIdArray(JSContext *cx, JSIdArray *ida); +extern __attribute__((visibility ("default"))) JSBool +JS_ValueToId(JSContext *cx, jsval v, jsid *idp); +extern __attribute__((visibility ("default"))) JSBool +JS_IdToValue(JSContext *cx, jsid id, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_PropertyStub(JSContext *cx, JSObject *obj, jsid id, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_StrictPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_EnumerateStub(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_ResolveStub(JSContext *cx, JSObject *obj, jsid id); +extern __attribute__((visibility ("default"))) JSBool +JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp); +extern __attribute__((visibility ("default"))) void +JS_FinalizeStub(JSContext *cx, JSObject *obj); +struct JSConstDoubleSpec { + jsdouble dval; + const char *name; + uint8 flags; + uint8 spare[3]; +}; +struct JSPropertySpec { + const char *name; + int8 tinyid; + uint8 flags; + JSPropertyOp getter; + JSStrictPropertyOp setter; +}; +struct JSFunctionSpec { + const char *name; + JSNative call; + uint16 nargs; + uint16 flags; +}; +extern __attribute__((visibility ("default"))) JSObject * +JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, + JSClass *clasp, JSNative constructor, uintN nargs, + JSPropertySpec *ps, JSFunctionSpec *fs, + JSPropertySpec *static_ps, JSFunctionSpec *static_fs); +extern __attribute__((visibility ("default"))) JSClass * +JS_GetClass(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv); +extern __attribute__((visibility ("default"))) JSBool +JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp); +extern __attribute__((visibility ("default"))) void * +JS_GetPrivate(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_SetPrivate(JSContext *cx, JSObject *obj, void *data); +extern __attribute__((visibility ("default"))) void * +JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp, + jsval *argv); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetPrototype(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetParent(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetConstructor(JSContext *cx, JSObject *proto); +extern __attribute__((visibility ("default"))) JSBool +JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewGlobalObject(JSContext *cx, JSClass *clasp); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewCompartmentAndGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent); +extern __attribute__((visibility ("default"))) JSBool +JS_IsExtensible(JSObject *obj); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto, + JSObject *parent); +extern __attribute__((visibility ("default"))) JSBool +JS_DeepFreezeObject(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_FreezeObject(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSObject * +JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto, + JSObject *parent); +extern __attribute__((visibility ("default"))) JSObject * +JS_ConstructObjectWithArguments(JSContext *cx, JSClass *clasp, JSObject *proto, + JSObject *parent, uintN argc, jsval *argv); +extern __attribute__((visibility ("default"))) JSObject * +JS_New(JSContext *cx, JSObject *ctor, uintN argc, jsval *argv); +extern __attribute__((visibility ("default"))) JSObject * +JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp, + JSObject *proto, uintN attrs); +extern __attribute__((visibility ("default"))) JSBool +JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds); +extern __attribute__((visibility ("default"))) JSBool +JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps); +extern __attribute__((visibility ("default"))) JSBool +JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, + JSPropertyOp getter, JSStrictPropertyOp setter, uintN attrs); +extern __attribute__((visibility ("default"))) JSBool +JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value, + JSPropertyOp getter, JSStrictPropertyOp setter, uintN attrs); +extern __attribute__((visibility ("default"))) JSBool +JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, JSBool *bp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name, + uintN *attrsp, JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj, + const char *name, + uintN *attrsp, JSBool *foundp, + JSPropertyOp *getterp, + JSStrictPropertyOp *setterp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetPropertyAttrsGetterAndSetterById(JSContext *cx, JSObject *obj, + jsid id, + uintN *attrsp, JSBool *foundp, + JSPropertyOp *getterp, + JSStrictPropertyOp *setterp); +extern __attribute__((visibility ("default"))) JSBool +JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name, + uintN attrs, JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, + int8 tinyid, jsval value, + JSPropertyOp getter, JSStrictPropertyOp setter, + uintN attrs); +extern __attribute__((visibility ("default"))) JSBool +JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name, + const char *alias); +extern __attribute__((visibility ("default"))) JSBool +JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name, + JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id, + JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, + uintN flags, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id, + uintN flags, JSObject **objp, jsval *vp); +struct JSPropertyDescriptor { + JSObject *obj; + uintN attrs; + JSPropertyOp getter; + JSStrictPropertyOp setter; + jsval value; + uintN shortid; +}; +extern __attribute__((visibility ("default"))) JSBool +JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, uintN flags, + JSPropertyDescriptor *desc); +extern __attribute__((visibility ("default"))) JSBool +JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetPropertyDefault(JSContext *cx, JSObject *obj, const char *name, jsval def, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetPropertyByIdDefault(JSContext *cx, JSObject *obj, jsid id, jsval def, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, + jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetMethod(JSContext *cx, JSObject *obj, const char *name, JSObject **objp, + jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name); +extern __attribute__((visibility ("default"))) JSBool +JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name, + jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id); +extern __attribute__((visibility ("default"))) JSBool +JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_DefineUCProperty(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, jsval value, + JSPropertyOp getter, JSStrictPropertyOp setter, + uintN attrs); +extern __attribute__((visibility ("default"))) JSBool +JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + uintN *attrsp, JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + uintN *attrsp, JSBool *foundp, + JSPropertyOp *getterp, + JSStrictPropertyOp *setterp); +extern __attribute__((visibility ("default"))) JSBool +JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + uintN attrs, JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + int8 tinyid, jsval value, + JSPropertyOp getter, JSStrictPropertyOp setter, + uintN attrs); +extern __attribute__((visibility ("default"))) JSBool +JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name, + size_t namelen, JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_HasUCProperty(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + JSBool *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_LookupUCProperty(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetUCProperty(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_SetUCProperty(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_DeleteUCProperty2(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, + jsval *rval); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewArrayObject(JSContext *cx, jsint length, jsval *vector); +extern __attribute__((visibility ("default"))) JSBool +JS_IsArrayObject(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_GetArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp); +extern __attribute__((visibility ("default"))) JSBool +JS_SetArrayLength(JSContext *cx, JSObject *obj, jsuint length); +extern __attribute__((visibility ("default"))) JSBool +JS_HasArrayLength(JSContext *cx, JSObject *obj, jsuint *lengthp); +extern __attribute__((visibility ("default"))) JSBool +JS_DefineElement(JSContext *cx, JSObject *obj, jsint index, jsval value, + JSPropertyOp getter, JSStrictPropertyOp setter, uintN attrs); +extern __attribute__((visibility ("default"))) JSBool +JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias); +extern __attribute__((visibility ("default"))) JSBool +JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, jsint index, + JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_HasElement(JSContext *cx, JSObject *obj, jsint index, JSBool *foundp); +extern __attribute__((visibility ("default"))) JSBool +JS_LookupElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_SetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_DeleteElement(JSContext *cx, JSObject *obj, jsint index); +extern __attribute__((visibility ("default"))) JSBool +JS_DeleteElement2(JSContext *cx, JSObject *obj, jsint index, jsval *rval); +extern __attribute__((visibility ("default"))) void +JS_ClearScope(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSIdArray * +JS_Enumerate(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewPropertyIterator(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp); +extern __attribute__((visibility ("default"))) JSBool +JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, + jsval *vp, uintN *attrsp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval *vp); +extern __attribute__((visibility ("default"))) JSBool +JS_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval v); +struct JSPrincipals { + char *codebase; + void * (* getPrincipalArray)(JSContext *cx, JSPrincipals *); + JSBool (* globalPrivilegesEnabled)(JSContext *cx, JSPrincipals *); + jsrefcount refcount; + void (* destroy)(JSContext *cx, JSPrincipals *); + JSBool (* subsume)(JSPrincipals *, JSPrincipals *); +}; +extern __attribute__((visibility ("default"))) jsrefcount +JS_HoldPrincipals(JSContext *cx, JSPrincipals *principals); +extern __attribute__((visibility ("default"))) jsrefcount +JS_DropPrincipals(JSContext *cx, JSPrincipals *principals); +struct JSSecurityCallbacks { + JSCheckAccessOp checkObjectAccess; + JSPrincipalsTranscoder principalsTranscoder; + JSObjectPrincipalsFinder findObjectPrincipals; + JSCSPEvalChecker contentSecurityPolicyAllows; +}; +extern __attribute__((visibility ("default"))) JSSecurityCallbacks * +JS_SetRuntimeSecurityCallbacks(JSRuntime *rt, JSSecurityCallbacks *callbacks); +extern __attribute__((visibility ("default"))) JSSecurityCallbacks * +JS_GetRuntimeSecurityCallbacks(JSRuntime *rt); +extern __attribute__((visibility ("default"))) JSSecurityCallbacks * +JS_SetContextSecurityCallbacks(JSContext *cx, JSSecurityCallbacks *callbacks); +extern __attribute__((visibility ("default"))) JSSecurityCallbacks * +JS_GetSecurityCallbacks(JSContext *cx); +extern __attribute__((visibility ("default"))) JSFunction * +JS_NewFunction(JSContext *cx, JSNative call, uintN nargs, uintN flags, + JSObject *parent, const char *name); +extern __attribute__((visibility ("default"))) JSFunction * +JS_NewFunctionById(JSContext *cx, JSNative call, uintN nargs, uintN flags, + JSObject *parent, jsid id); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetFunctionObject(JSFunction *fun); +extern __attribute__((visibility ("default"))) JSString * +JS_GetFunctionId(JSFunction *fun); +extern __attribute__((visibility ("default"))) uintN +JS_GetFunctionFlags(JSFunction *fun); +extern __attribute__((visibility ("default"))) uint16 +JS_GetFunctionArity(JSFunction *fun); +extern __attribute__((visibility ("default"))) JSBool +JS_ObjectIsFunction(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_ObjectIsCallable(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs); +extern __attribute__((visibility ("default"))) JSFunction * +JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call, + uintN nargs, uintN attrs); +extern __attribute__((visibility ("default"))) JSFunction * +JS_DefineUCFunction(JSContext *cx, JSObject *obj, + const jschar *name, size_t namelen, JSNative call, + uintN nargs, uintN attrs); +extern __attribute__((visibility ("default"))) JSFunction * +JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call, + uintN nargs, uintN attrs); +extern __attribute__((visibility ("default"))) JSObject * +JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent); +extern __attribute__((visibility ("default"))) JSBool +JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, + const char *bytes, size_t length); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileScript(JSContext *cx, JSObject *obj, + const char *bytes, size_t length, + const char *filename, uintN lineno); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj, + JSPrincipals *principals, + const char *bytes, size_t length, + const char *filename, uintN lineno); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, + JSPrincipals *principals, + const char *bytes, size_t length, + const char *filename, uintN lineno, + JSVersion version); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileUCScript(JSContext *cx, JSObject *obj, + const jschar *chars, size_t length, + const char *filename, uintN lineno); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj, + JSPrincipals *principals, + const jschar *chars, size_t length, + const char *filename, uintN lineno); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, + JSPrincipals *principals, + const jschar *chars, size_t length, + const char *filename, uintN lineno, + JSVersion version); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileFileHandle(JSContext *cx, JSObject *obj, const char *filename, + FILE *fh); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileFileHandleForPrincipals(JSContext *cx, JSObject *obj, + const char *filename, FILE *fh, + JSPrincipals *principals); +extern __attribute__((visibility ("default"))) JSObject * +JS_CompileFileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj, + const char *filename, FILE *fh, + JSPrincipals *principals, + JSVersion version); +extern __attribute__((visibility ("default"))) JSFunction * +JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name, + uintN nargs, const char **argnames, + const char *bytes, size_t length, + const char *filename, uintN lineno); +extern __attribute__((visibility ("default"))) JSFunction * +JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj, + JSPrincipals *principals, const char *name, + uintN nargs, const char **argnames, + const char *bytes, size_t length, + const char *filename, uintN lineno); +extern __attribute__((visibility ("default"))) JSFunction * +JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name, + uintN nargs, const char **argnames, + const jschar *chars, size_t length, + const char *filename, uintN lineno); +extern __attribute__((visibility ("default"))) JSFunction * +JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj, + JSPrincipals *principals, const char *name, + uintN nargs, const char **argnames, + const jschar *chars, size_t length, + const char *filename, uintN lineno); +extern __attribute__((visibility ("default"))) JSFunction * +JS_CompileUCFunctionForPrincipalsVersion(JSContext *cx, JSObject *obj, + JSPrincipals *principals, const char *name, + uintN nargs, const char **argnames, + const jschar *chars, size_t length, + const char *filename, uintN lineno, + JSVersion version); +extern __attribute__((visibility ("default"))) JSString * +JS_DecompileScriptObject(JSContext *cx, JSObject *scriptObj, const char *name, uintN indent); +extern __attribute__((visibility ("default"))) JSString * +JS_DecompileFunction(JSContext *cx, JSFunction *fun, uintN indent); +extern __attribute__((visibility ("default"))) JSString * +JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, uintN indent); +extern __attribute__((visibility ("default"))) JSBool +JS_ExecuteScript(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval, + JSVersion version); +typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart; +extern __attribute__((visibility ("default"))) JSBool +JS_EvaluateScript(JSContext *cx, JSObject *obj, + const char *bytes, uintN length, + const char *filename, uintN lineno, + jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, + JSPrincipals *principals, + const char *bytes, uintN length, + const char *filename, uintN lineno, + jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, + JSPrincipals *principals, + const char *bytes, uintN length, + const char *filename, uintN lineno, + jsval *rval, JSVersion version); +extern __attribute__((visibility ("default"))) JSBool +JS_EvaluateUCScript(JSContext *cx, JSObject *obj, + const jschar *chars, uintN length, + const char *filename, uintN lineno, + jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_EvaluateUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, + JSPrincipals *principals, + const jschar *chars, uintN length, + const char *filename, uintN lineno, + jsval *rval, JSVersion version); +extern __attribute__((visibility ("default"))) JSBool +JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj, + JSPrincipals *principals, + const jschar *chars, uintN length, + const char *filename, uintN lineno, + jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, uintN argc, + jsval *argv, jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, uintN argc, + jsval *argv, jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, uintN argc, + jsval *argv, jsval *rval); +} +namespace JS { +static inline + bool +Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, uintN argc, jsval *argv, jsval *rval) { + return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval); +} +static inline + bool +Call(JSContext *cx, JSObject *thisObj, const char *name, uintN argc, jsval *argv, jsval *rval) { + return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval); +} +static inline + bool +Call(JSContext *cx, JSObject *thisObj, jsval fun, uintN argc, jsval *argv, jsval *rval) { + return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval); +} +extern __attribute__((visibility ("default"))) bool +Call(JSContext *cx, jsval thisv, jsval fun, uintN argc, jsval *argv, jsval *rval); +static inline + bool +Call(JSContext *cx, jsval thisv, JSObject *funObj, uintN argc, jsval *argv, jsval *rval) { + return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval); +} +} +extern "C" { +extern __attribute__((visibility ("default"))) JSOperationCallback +JS_SetOperationCallback(JSContext *cx, JSOperationCallback callback); +extern __attribute__((visibility ("default"))) JSOperationCallback +JS_GetOperationCallback(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_TriggerOperationCallback(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_TriggerAllOperationCallbacks(JSRuntime *rt); +extern __attribute__((visibility ("default"))) JSBool +JS_IsRunning(JSContext *cx); +extern __attribute__((visibility ("default"))) JSStackFrame * +JS_SaveFrameChain(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_RestoreFrameChain(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSString * +JS_NewStringCopyN(JSContext *cx, const char *s, size_t n); +extern __attribute__((visibility ("default"))) JSString * +JS_NewStringCopyZ(JSContext *cx, const char *s); +extern __attribute__((visibility ("default"))) JSString * +JS_InternJSString(JSContext *cx, JSString *str); +extern __attribute__((visibility ("default"))) JSString * +JS_InternString(JSContext *cx, const char *s); +extern __attribute__((visibility ("default"))) JSString * +JS_NewUCString(JSContext *cx, jschar *chars, size_t length); +extern __attribute__((visibility ("default"))) JSString * +JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n); +extern __attribute__((visibility ("default"))) JSString * +JS_NewUCStringCopyZ(JSContext *cx, const jschar *s); +extern __attribute__((visibility ("default"))) JSString * +JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length); +extern __attribute__((visibility ("default"))) JSString * +JS_InternUCString(JSContext *cx, const jschar *s); +extern __attribute__((visibility ("default"))) JSBool +JS_CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32 *result); +extern __attribute__((visibility ("default"))) JSBool +JS_StringEqualsAscii(JSContext *cx, JSString *str, const char *asciiBytes, JSBool *match); +extern __attribute__((visibility ("default"))) size_t +JS_PutEscapedString(JSContext *cx, char *buffer, size_t size, JSString *str, char quote); +extern __attribute__((visibility ("default"))) JSBool +JS_FileEscapedString(FILE *fp, JSString *str, char quote); +extern __attribute__((visibility ("default"))) size_t +JS_GetStringLength(JSString *str); +extern __attribute__((visibility ("default"))) const jschar * +JS_GetStringCharsAndLength(JSContext *cx, JSString *str, size_t *length); +extern __attribute__((visibility ("default"))) const jschar * +JS_GetInternedStringChars(JSString *str); +extern __attribute__((visibility ("default"))) const jschar * +JS_GetInternedStringCharsAndLength(JSString *str, size_t *length); +extern __attribute__((visibility ("default"))) const jschar * +JS_GetStringCharsZ(JSContext *cx, JSString *str); +extern __attribute__((visibility ("default"))) const jschar * +JS_GetStringCharsZAndLength(JSContext *cx, JSString *str, size_t *length); +extern __attribute__((visibility ("default"))) JSFlatString * +JS_FlattenString(JSContext *cx, JSString *str); +extern __attribute__((visibility ("default"))) const jschar * +JS_GetFlatStringChars(JSFlatString *str); +static __attribute__((always_inline)) inline JSFlatString * +JSID_TO_FLAT_STRING(jsid id) +{ + ((void) 0); + return (JSFlatString *)((id)); +} +static __attribute__((always_inline)) inline JSFlatString * +JS_ASSERT_STRING_IS_FLAT(JSString *str) +{ + ((void) 0); + return (JSFlatString *)str; +} +static __attribute__((always_inline)) inline JSString * +JS_FORGET_STRING_FLATNESS(JSFlatString *fstr) +{ + return (JSString *)fstr; +} +extern __attribute__((visibility ("default"))) JSBool +JS_FlatStringEqualsAscii(JSFlatString *str, const char *asciiBytes); +extern __attribute__((visibility ("default"))) size_t +JS_PutEscapedFlatString(char *buffer, size_t size, JSFlatString *str, char quote); +extern __attribute__((visibility ("default"))) JSString * +JS_NewGrowableString(JSContext *cx, jschar *chars, size_t length); +extern __attribute__((visibility ("default"))) JSString * +JS_NewDependentString(JSContext *cx, JSString *str, size_t start, + size_t length); +extern __attribute__((visibility ("default"))) JSString * +JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right); +extern __attribute__((visibility ("default"))) const jschar * +JS_UndependString(JSContext *cx, JSString *str); +extern __attribute__((visibility ("default"))) JSBool +JS_MakeStringImmutable(JSContext *cx, JSString *str); +__attribute__((visibility ("default"))) JSBool +JS_CStringsAreUTF8(void); +__attribute__((visibility ("default"))) void +JS_SetCStringsAreUTF8(void); +__attribute__((visibility ("default"))) JSBool +JS_EncodeCharacters(JSContext *cx, const jschar *src, size_t srclen, char *dst, + size_t *dstlenp); +__attribute__((visibility ("default"))) JSBool +JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst, + size_t *dstlenp); +__attribute__((visibility ("default"))) char * +JS_EncodeString(JSContext *cx, JSString *str); +__attribute__((visibility ("default"))) size_t +JS_GetStringEncodingLength(JSContext *cx, JSString *str); +__attribute__((visibility ("default"))) size_t +JS_EncodeStringToBuffer(JSString *str, char *buffer, size_t length); +class JSAutoByteString { + public: + JSAutoByteString(JSContext *cx, JSString *str ) + : mBytes(JS_EncodeString(cx, str)) { + ((void) 0); + do { } while (0); + } + JSAutoByteString() + : mBytes(__null) { + do { } while (0); + } + ~JSAutoByteString() { + js_free(mBytes); + } + void initBytes(char *bytes) { + ((void) 0); + mBytes = bytes; + } + char *encode(JSContext *cx, JSString *str) { + ((void) 0); + ((void) 0); + mBytes = JS_EncodeString(cx, str); + return mBytes; + } + void clear() { + js_free(mBytes); + mBytes = __null; + } + char *ptr() const { + return mBytes; + } + bool operator!() const { + return !mBytes; + } + private: + char *mBytes; + + JSAutoByteString(const JSAutoByteString &another); + JSAutoByteString &operator=(const JSAutoByteString &another); +}; +typedef JSBool (* JSONWriteCallback)(const jschar *buf, uint32 len, void *data); +__attribute__((visibility ("default"))) JSBool +JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space, + JSONWriteCallback callback, void *data); +__attribute__((visibility ("default"))) JSBool +JS_TryJSON(JSContext *cx, jsval *vp); +__attribute__((visibility ("default"))) JSONParser * +JS_BeginJSONParse(JSContext *cx, jsval *vp); +__attribute__((visibility ("default"))) JSBool +JS_ConsumeJSONText(JSContext *cx, JSONParser *jp, const jschar *data, uint32 len); +__attribute__((visibility ("default"))) JSBool +JS_FinishJSONParse(JSContext *cx, JSONParser *jp, jsval reviver); +struct JSStructuredCloneCallbacks { + ReadStructuredCloneOp read; + WriteStructuredCloneOp write; + StructuredCloneErrorOp reportError; +}; +__attribute__((visibility ("default"))) JSBool +JS_ReadStructuredClone(JSContext *cx, const uint64 *data, size_t nbytes, + uint32 version, jsval *vp, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); +__attribute__((visibility ("default"))) JSBool +JS_WriteStructuredClone(JSContext *cx, jsval v, uint64 **datap, size_t *nbytesp, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); +__attribute__((visibility ("default"))) JSBool +JS_StructuredClone(JSContext *cx, jsval v, jsval *vp, + const JSStructuredCloneCallbacks *optionalCallbacks, + void *closure); +class JSAutoStructuredCloneBuffer { + JSContext *cx_; + uint64 *data_; + size_t nbytes_; + uint32 version_; + public: + JSAutoStructuredCloneBuffer() + : cx_(__null), data_(__null), nbytes_(0), version_(1) {} + ~JSAutoStructuredCloneBuffer() { clear(); } + JSContext *cx() const { return cx_; } + uint64 *data() const { return data_; } + size_t nbytes() const { return nbytes_; } + void clear(JSContext *cx=__null) { + if (data_) { + if (!cx) + cx = cx_; + ((void) 0); + JS_free(cx, data_); + cx_ = __null; + data_ = __null; + nbytes_ = 0; + version_ = 0; + } + } + void adopt(JSContext *cx, uint64 *data, size_t nbytes, + uint32 version=1) { + clear(cx); + cx_ = cx; + data_ = data; + nbytes_ = nbytes; + version_ = version; + } + void steal(uint64 **datap, size_t *nbytesp, JSContext **cxp=__null, + uint32 *versionp=__null) { + *datap = data_; + *nbytesp = nbytes_; + if (cxp) + *cxp = cx_; + if (versionp) + *versionp = version_; + cx_ = __null; + data_ = __null; + nbytes_ = 0; + version_ = 0; + } + bool read(jsval *vp, JSContext *cx=__null, + const JSStructuredCloneCallbacks *optionalCallbacks=__null, + void *closure=__null) const { + if (!cx) + cx = cx_; + ((void) 0); + ((void) 0); + return !!JS_ReadStructuredClone(cx, data_, nbytes_, version_, vp, + optionalCallbacks, closure); + } + bool write(JSContext *cx, jsval v, + const JSStructuredCloneCallbacks *optionalCallbacks=__null, + void *closure=__null) { + clear(cx); + cx_ = cx; + bool ok = !!JS_WriteStructuredClone(cx, v, &data_, &nbytes_, + optionalCallbacks, closure); + if (!ok) { + data_ = __null; + nbytes_ = 0; + version_ = 1; + } + return ok; + } + void swap(JSAutoStructuredCloneBuffer &other) { + JSContext *cx = other.cx_; + uint64 *data = other.data_; + size_t nbytes = other.nbytes_; + uint32 version = other.version_; + other.cx_ = this->cx_; + other.data_ = this->data_; + other.nbytes_ = this->nbytes_; + other.version_ = this->version_; + this->cx_ = cx; + this->data_ = data; + this->nbytes_ = nbytes; + this->version_ = version; + } + private: + JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other); + JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other); +}; +__attribute__((visibility ("default"))) void +JS_SetStructuredCloneCallbacks(JSRuntime *rt, const JSStructuredCloneCallbacks *callbacks); +__attribute__((visibility ("default"))) JSBool +JS_ReadUint32Pair(JSStructuredCloneReader *r, uint32 *p1, uint32 *p2); +__attribute__((visibility ("default"))) JSBool +JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len); +__attribute__((visibility ("default"))) JSBool +JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32 tag, uint32 data); +__attribute__((visibility ("default"))) JSBool +JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); +struct JSLocaleCallbacks { + JSLocaleToUpperCase localeToUpperCase; + JSLocaleToLowerCase localeToLowerCase; + JSLocaleCompare localeCompare; + JSLocaleToUnicode localeToUnicode; + JSErrorCallback localeGetErrorMessage; +}; +extern __attribute__((visibility ("default"))) void +JS_SetLocaleCallbacks(JSContext *cx, JSLocaleCallbacks *callbacks); +extern __attribute__((visibility ("default"))) JSLocaleCallbacks * +JS_GetLocaleCallbacks(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_ReportError(JSContext *cx, const char *format, ...); +extern __attribute__((visibility ("default"))) void +JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const uintN errorNumber, ...); +extern __attribute__((visibility ("default"))) void +JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback, + void *userRef, const uintN errorNumber, ...); +extern __attribute__((visibility ("default"))) JSBool +JS_ReportWarning(JSContext *cx, const char *format, ...); +extern __attribute__((visibility ("default"))) JSBool +JS_ReportErrorFlagsAndNumber(JSContext *cx, uintN flags, + JSErrorCallback errorCallback, void *userRef, + const uintN errorNumber, ...); +extern __attribute__((visibility ("default"))) JSBool +JS_ReportErrorFlagsAndNumberUC(JSContext *cx, uintN flags, + JSErrorCallback errorCallback, void *userRef, + const uintN errorNumber, ...); +extern __attribute__((visibility ("default"))) void +JS_ReportOutOfMemory(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_ReportAllocationOverflow(JSContext *cx); +struct JSErrorReport { + const char *filename; + uintN lineno; + const char *linebuf; + const char *tokenptr; + const jschar *uclinebuf; + const jschar *uctokenptr; + uintN flags; + uintN errorNumber; + const jschar *ucmessage; + const jschar **messageArgs; +}; +extern __attribute__((visibility ("default"))) JSErrorReporter +JS_SetErrorReporter(JSContext *cx, JSErrorReporter er); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewDateObject(JSContext *cx, int year, int mon, int mday, int hour, int min, int sec); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewDateObjectMsec(JSContext *cx, jsdouble msec); +extern __attribute__((visibility ("default"))) JSBool +JS_ObjectIsDate(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewRegExpObject(JSContext *cx, JSObject *obj, char *bytes, size_t length, uintN flags); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewUCRegExpObject(JSContext *cx, JSObject *obj, jschar *chars, size_t length, uintN flags); +extern __attribute__((visibility ("default"))) void +JS_SetRegExpInput(JSContext *cx, JSObject *obj, JSString *input, JSBool multiline); +extern __attribute__((visibility ("default"))) void +JS_ClearRegExpStatics(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_ExecuteRegExp(JSContext *cx, JSObject *obj, JSObject *reobj, jschar *chars, size_t length, + size_t *indexp, JSBool test, jsval *rval); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, uintN flags); +extern __attribute__((visibility ("default"))) JSObject * +JS_NewUCRegExpObjectNoStatics(JSContext *cx, jschar *chars, size_t length, uintN flags); +extern __attribute__((visibility ("default"))) JSBool +JS_ExecuteRegExpNoStatics(JSContext *cx, JSObject *reobj, jschar *chars, size_t length, + size_t *indexp, JSBool test, jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_IsExceptionPending(JSContext *cx); +extern __attribute__((visibility ("default"))) JSBool +JS_GetPendingException(JSContext *cx, jsval *vp); +extern __attribute__((visibility ("default"))) void +JS_SetPendingException(JSContext *cx, jsval v); +extern __attribute__((visibility ("default"))) void +JS_ClearPendingException(JSContext *cx); +extern __attribute__((visibility ("default"))) JSBool +JS_ReportPendingException(JSContext *cx); +extern __attribute__((visibility ("default"))) JSExceptionState * +JS_SaveExceptionState(JSContext *cx); +extern __attribute__((visibility ("default"))) void +JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state); +extern __attribute__((visibility ("default"))) void +JS_DropExceptionState(JSContext *cx, JSExceptionState *state); +extern __attribute__((visibility ("default"))) JSErrorReport * +JS_ErrorFromException(JSContext *cx, jsval v); +extern __attribute__((visibility ("default"))) JSBool +JS_ThrowReportedError(JSContext *cx, const char *message, + JSErrorReport *reportp); +extern __attribute__((visibility ("default"))) JSBool +JS_ThrowStopIteration(JSContext *cx); +extern __attribute__((visibility ("default"))) jsword +JS_GetContextThread(JSContext *cx); +extern __attribute__((visibility ("default"))) jsword +JS_SetContextThread(JSContext *cx); +extern __attribute__((visibility ("default"))) jsword +JS_ClearContextThread(JSContext *cx); +static __attribute__((always_inline)) inline JSBool +JS_IsConstructing(JSContext *cx, const jsval *vp) +{ + jsval_layout l; + l.asBits = (vp[1]); + return JSVAL_IS_MAGIC_IMPL(l); +} +static __attribute__((always_inline)) inline JSBool +JS_IsConstructing_PossiblyWithGivenThisObject(JSContext *cx, const jsval *vp, + JSObject **maybeThis) +{ + jsval_layout l; + JSBool isCtor; + l.asBits = (vp[1]); + isCtor = JSVAL_IS_MAGIC_IMPL(l); + if (isCtor) + *maybeThis = MAGIC_JSVAL_TO_OBJECT_OR_NULL_IMPL(l); + return isCtor; +} +extern __attribute__((visibility ("default"))) JSObject * +JS_NewObjectForConstructor(JSContext *cx, const jsval *vp); +} +extern "C" { +static const uintN JS_GCTHING_ALIGN = 8; +static const uintN JS_GCTHING_ZEROBITS = 3; +typedef uint8 jsbytecode; +typedef uint8 jssrcnote; +typedef uint32 jsatomid; +typedef struct JSArgumentFormatMap JSArgumentFormatMap; +typedef struct JSCodeGenerator JSCodeGenerator; +typedef struct JSGCThing JSGCThing; +typedef struct JSGenerator JSGenerator; +typedef struct JSNativeEnumerator JSNativeEnumerator; +typedef struct JSFunctionBox JSFunctionBox; +typedef struct JSObjectBox JSObjectBox; +typedef struct JSParseNode JSParseNode; +typedef struct JSProperty JSProperty; +typedef struct JSScript JSScript; +typedef struct JSSharpObjectMap JSSharpObjectMap; +typedef struct JSThread JSThread; +typedef struct JSThreadData JSThreadData; +typedef struct JSTreeContext JSTreeContext; +typedef struct JSTryNote JSTryNote; +typedef struct JSLinearString JSLinearString; +typedef struct JSAtom JSAtom; +typedef struct JSAtomList JSAtomList; +typedef struct JSAtomListElement JSAtomListElement; +typedef struct JSAtomMap JSAtomMap; +typedef struct JSAtomState JSAtomState; +typedef struct JSCodeSpec JSCodeSpec; +typedef struct JSPrinter JSPrinter; +typedef struct JSRegExpStatics JSRegExpStatics; +typedef struct JSStackHeader JSStackHeader; +typedef struct JSSubString JSSubString; +typedef struct JSNativeTraceInfo JSNativeTraceInfo; +typedef struct JSSpecializedNative JSSpecializedNative; +typedef struct JSXML JSXML; +typedef struct JSXMLArray JSXMLArray; +typedef struct JSXMLArrayCursor JSXMLArrayCursor; +extern "C++" { +namespace js { +struct ArgumentsData; +class RegExp; +class RegExpStatics; +class AutoStringRooter; +class ExecuteArgsGuard; +class InvokeFrameGuard; +class InvokeArgsGuard; +class InvokeSessionGuard; +class TraceRecorder; +struct TraceMonitor; +class StackSpace; +class StackSegment; +class FrameRegsIter; +class StringBuffer; +struct Compiler; +struct Parser; +class TokenStream; +struct Token; +struct TokenPos; +struct TokenPtr; +class ContextAllocPolicy; +class SystemAllocPolicy; +template +class Vector; +template +struct DefaultHasher; +template , + class AllocPolicy = ContextAllocPolicy> +class HashMap; +template , + class AllocPolicy = ContextAllocPolicy> +class HashSet; +class PropertyCache; +struct PropertyCacheEntry; +struct Shape; +struct EmptyShape; +} +} +typedef enum JSTrapStatus { + JSTRAP_ERROR, + JSTRAP_CONTINUE, + JSTRAP_RETURN, + JSTRAP_THROW, + JSTRAP_LIMIT +} JSTrapStatus; +typedef JSTrapStatus +(* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, + jsval closure); +typedef JSTrapStatus +(* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, + void *closure); +typedef JSTrapStatus +(* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, + void *closure); +typedef JSTrapStatus +(* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, + void *closure); +typedef JSBool +(* JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsid id, jsval old, + jsval *newp, void *closure); +typedef void +(* JSNewScriptHook)(JSContext *cx, + const char *filename, + uintN lineno, + JSScript *script, + JSFunction *fun, + void *callerdata); +typedef void +(* JSDestroyScriptHook)(JSContext *cx, + JSScript *script, + void *callerdata); +typedef void +(* JSSourceHandler)(const char *filename, uintN lineno, jschar *str, + size_t length, void **listenerTSData, void *closure); +typedef void * +(* JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before, + JSBool *ok, void *closure); +typedef JSBool +(* JSDebugErrorHook)(JSContext *cx, const char *message, JSErrorReport *report, + void *closure); +typedef struct JSDebugHooks { + JSInterruptHook interruptHook; + void *interruptHookData; + JSNewScriptHook newScriptHook; + void *newScriptHookData; + JSDestroyScriptHook destroyScriptHook; + void *destroyScriptHookData; + JSDebuggerHandler debuggerHandler; + void *debuggerHandlerData; + JSSourceHandler sourceHandler; + void *sourceHandlerData; + JSInterpreterHook executeHook; + void *executeHookData; + JSInterpreterHook callHook; + void *callHookData; + JSThrowHook throwHook; + void *throwHookData; + JSDebugErrorHook debugErrorHook; + void *debugErrorHookData; +} JSDebugHooks; +typedef JSBool +(* JSLookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, + JSProperty **propp); +typedef JSBool +(* JSAttributesOp)(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp); +typedef JSObject * +(* JSObjectOp)(JSContext *cx, JSObject *obj); +typedef JSObject * +(* JSIteratorOp)(JSContext *cx, JSObject *obj, JSBool keysonly); +extern JSBool js_CStringsAreUTF8; +extern __attribute__((visibility ("default"))) JSObject * +js_ObjectToOuterObject(JSContext *cx, JSObject *obj); +} +extern "C" { +typedef uint32 JSHashNumber; +typedef struct JSHashEntry JSHashEntry; +typedef struct JSHashTable JSHashTable; +typedef JSHashNumber (* JSHashFunction)(const void *key); +typedef intN (* JSHashComparator)(const void *v1, const void *v2); +typedef intN (* JSHashEnumerator)(JSHashEntry *he, intN i, void *arg); +typedef struct JSHashAllocOps { + void * (*allocTable)(void *pool, size_t size); + void (*freeTable)(void *pool, void *item, size_t size); + JSHashEntry * (*allocEntry)(void *pool, const void *key); + void (*freeEntry)(void *pool, JSHashEntry *he, uintN flag); +} JSHashAllocOps; +struct JSHashEntry { + JSHashEntry *next; + JSHashNumber keyHash; + const void *key; + void *value; +}; +struct JSHashTable { + JSHashEntry **buckets; + uint32 nentries; + uint32 shift; + JSHashFunction keyHash; + JSHashComparator keyCompare; + JSHashComparator valueCompare; + JSHashAllocOps *allocOps; + void *allocPriv; +}; +extern __attribute__((visibility ("default"))) JSHashTable * +JS_NewHashTable(uint32 n, JSHashFunction keyHash, + JSHashComparator keyCompare, JSHashComparator valueCompare, + JSHashAllocOps *allocOps, void *allocPriv); +extern __attribute__((visibility ("default"))) void +JS_HashTableDestroy(JSHashTable *ht); +extern __attribute__((visibility ("default"))) JSHashEntry ** +JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key); +extern __attribute__((visibility ("default"))) JSHashEntry * +JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **&hep, JSHashNumber keyHash, + const void *key, void *value); +extern __attribute__((visibility ("default"))) void +JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he); +extern __attribute__((visibility ("default"))) JSHashEntry * +JS_HashTableAdd(JSHashTable *ht, const void *key, void *value); +extern __attribute__((visibility ("default"))) JSBool +JS_HashTableRemove(JSHashTable *ht, const void *key); +extern __attribute__((visibility ("default"))) intN +JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg); +extern __attribute__((visibility ("default"))) void * +JS_HashTableLookup(JSHashTable *ht, const void *key); +extern __attribute__((visibility ("default"))) intN +JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp); +extern __attribute__((visibility ("default"))) JSHashNumber +JS_HashString(const void *key); +extern __attribute__((visibility ("default"))) intN +JS_CompareValues(const void *v1, const void *v2); +} + +namespace std +{ + typedef long unsigned int size_t; + typedef long int ptrdiff_t; +} +namespace std +{ + inline namespace __gnu_cxx_ldbl128 { } +} + + +extern "C++" { +namespace std +{ + class exception + { + public: + exception() throw() { } + virtual ~exception() throw(); + virtual const char* what() const throw(); + }; + class bad_exception : public exception + { + public: + bad_exception() throw() { } + virtual ~bad_exception() throw(); + virtual const char* what() const throw(); + }; + typedef void (*terminate_handler) (); + typedef void (*unexpected_handler) (); + terminate_handler set_terminate(terminate_handler) throw(); + void terminate() throw() __attribute__ ((__noreturn__)); + unexpected_handler set_unexpected(unexpected_handler) throw(); + void unexpected() __attribute__ ((__noreturn__)); + bool uncaught_exception() throw() __attribute__ ((__pure__)); +} +namespace __gnu_cxx +{ + void __verbose_terminate_handler(); +} +} +extern "C++" { +namespace std +{ + class bad_alloc : public exception + { + public: + bad_alloc() throw() { } + virtual ~bad_alloc() throw(); + virtual const char* what() const throw(); + }; + class bad_array_length : public bad_alloc + { + public: + bad_array_length() throw() { }; + virtual ~bad_array_length() throw(); + virtual const char* what() const throw(); + }; + struct nothrow_t { }; + extern const nothrow_t nothrow; + typedef void (*new_handler)(); + new_handler set_new_handler(new_handler) throw(); +} +void* operator new(std::size_t) throw(std::bad_alloc) + __attribute__((__externally_visible__)); +void* operator new[](std::size_t) throw(std::bad_alloc) + __attribute__((__externally_visible__)); +void operator delete(void*) throw() + __attribute__((__externally_visible__)); +void operator delete[](void*) throw() + __attribute__((__externally_visible__)); +void* operator new(std::size_t, const std::nothrow_t&) throw() + __attribute__((__externally_visible__)); +void* operator new[](std::size_t, const std::nothrow_t&) throw() + __attribute__((__externally_visible__)); +void operator delete(void*, const std::nothrow_t&) throw() + __attribute__((__externally_visible__)); +void operator delete[](void*, const std::nothrow_t&) throw() + __attribute__((__externally_visible__)); +inline void* operator new(std::size_t, void* __p) throw() +{ return __p; } +inline void* operator new[](std::size_t, void* __p) throw() +{ return __p; } +inline void operator delete (void*, void*) throw() { } +inline void operator delete[](void*, void*) throw() { } +} +namespace js { +namespace tl { +template struct Min { + static const size_t result = i < j ? i : j; +}; +template struct Max { + static const size_t result = i > j ? i : j; +}; +template struct Clamp { + static const size_t result = i < min ? min : (i > max ? max : i); +}; +template struct Pow { + static const size_t result = x * Pow::result; +}; +template struct Pow { + static const size_t result = 1; +}; +template struct FloorLog2 { + static const size_t result = 1 + FloorLog2::result; +}; +template <> struct FloorLog2<0> { }; +template <> struct FloorLog2<1> { static const size_t result = 0; }; +template struct CeilingLog2 { + static const size_t result = FloorLog2<2 * i - 1>::result; +}; +template struct RoundUpPow2 { + static const size_t result = 1u << CeilingLog2::result; +}; +template <> struct RoundUpPow2<0> { + static const size_t result = 1; +}; +template struct BitSize { + static const size_t result = sizeof(T) * 8; +}; +template struct StaticAssert {}; +template <> struct StaticAssert { typedef int result; }; +template struct IsSameType { + static const bool result = false; +}; +template struct IsSameType { + static const bool result = true; +}; +template struct NBitMask { + typedef typename StaticAssert::result>::result _; + static const size_t result = (size_t(1) << N) - 1; +}; +template <> struct NBitMask::result> { + static const size_t result = size_t(-1); +}; +template struct MulOverflowMask { + static const size_t result = + ~NBitMask::result - CeilingLog2::result>::result; +}; +template <> struct MulOverflowMask<0> { }; +template <> struct MulOverflowMask<1> { static const size_t result = 0; }; +template struct UnsafeRangeSizeMask { + static const size_t result = MulOverflowMask<2 * sizeof(T)>::result; +}; +template struct StripConst { typedef T result; }; +template struct StripConst { typedef T result; }; +template struct IsPodType { static const bool result = false; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template <> struct IsPodType { static const bool result = true; }; +template inline T *ArraySize(T (&)[N]) { return N; } +template inline T *ArrayEnd(T (&arr)[N]) { return arr + N; } +} +class ReentrancyGuard +{ + ReentrancyGuard(const ReentrancyGuard &); + void operator=(const ReentrancyGuard &); + public: + template + ReentrancyGuard(T & ) + { + } + ~ReentrancyGuard() + { + } +}; +__attribute__((always_inline)) inline size_t +RoundUpPow2(size_t x) +{ + size_t log2 = ((x) <= 1 ? 0 : 1 + (((void) 0), ((size_t)((8 * 8) - 1 - __builtin_clzll((x) - 1))))); + ((void) 0); + size_t result = size_t(1) << log2; + return result; +} +template +__attribute__((always_inline)) inline size_t +PointerRangeSize(T *begin, T *end) +{ + return (size_t(end) - size_t(begin)) / sizeof(T); +} +class SystemAllocPolicy +{ + public: + void *malloc(size_t bytes) { return js_malloc(bytes); } + void *realloc(void *p, size_t bytes) { return js_realloc(p, bytes); } + void free(void *p) { js_free(p); } + void reportAllocOverflow() const {} +}; +template +struct AlignedStorage +{ + union U { + char bytes[nbytes]; + uint64 _; + } u; + const void *addr() const { return u.bytes; } + void *addr() { return u.bytes; } +}; +template +struct AlignedStorage2 +{ + union U { + char bytes[sizeof(T)]; + uint64 _; + } u; + const T *addr() const { return (const T *)u.bytes; } + T *addr() { return (T *)u.bytes; } +}; +template +class LazilyConstructed +{ + AlignedStorage2 storage; + bool constructed; + T &asT() { return *storage.addr(); } + public: + LazilyConstructed() { constructed = false; } + ~LazilyConstructed() { if (constructed) asT().~T(); } + bool empty() const { return !constructed; } + void construct() { + ((void) 0); + new(storage.addr()) T(); + constructed = true; + } + template + void construct(const T1 &t1) { + ((void) 0); + new(storage.addr()) T(t1); + constructed = true; + } + template + void construct(const T1 &t1, const T2 &t2) { + ((void) 0); + new(storage.addr()) T(t1, t2); + constructed = true; + } + template + void construct(const T1 &t1, const T2 &t2, const T3 &t3) { + ((void) 0); + new(storage.addr()) T(t1, t2, t3); + constructed = true; + } + template + void construct(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) { + ((void) 0); + new(storage.addr()) T(t1, t2, t3, t4); + constructed = true; + } + T *addr() { + ((void) 0); + return &asT(); + } + T &ref() { + ((void) 0); + return asT(); + } + void destroy() { + ref().~T(); + constructed = false; + } +}; +template +class Conditionally { + LazilyConstructed t; + public: + Conditionally(bool b) { if (b) t.construct(); } + template + Conditionally(bool b, const T1 &t1) { if (b) t.construct(t1); } + template + Conditionally(bool b, const T1 &t1, const T2 &t2) { if (b) t.construct(t1, t2); } +}; +template +class AlignedPtrAndFlag +{ + uintptr_t bits; + public: + AlignedPtrAndFlag(T *t, bool flag) { + ((void) 0); + bits = uintptr_t(t) | uintptr_t(flag); + } + T *ptr() const { + return (T *)(bits & ~uintptr_t(1)); + } + bool flag() const { + return (bits & 1) != 0; + } + void setPtr(T *t) { + ((void) 0); + bits = uintptr_t(t) | uintptr_t(flag()); + } + void setFlag() { + bits |= 1; + } + void unsetFlag() { + bits &= ~uintptr_t(1); + } + void set(T *t, bool flag) { + ((void) 0); + bits = uintptr_t(t) | flag; + } +}; +template +static inline void +Reverse(T *beg, T *end) +{ + while (beg != end) { + if (--end == beg) + return; + T tmp = *beg; + *beg = *end; + *end = tmp; + ++beg; + } +} +template +static inline T * +Find(T *beg, T *end, const T &v) +{ + for (T *p = beg; p != end; ++p) { + if (*p == v) + return p; + } + return end; +} +template +static inline typename Container::ElementType * +Find(Container &c, const typename Container::ElementType &v) +{ + return Find(c.begin(), c.end(), v); +} +template +void +ForEach(InputIterT begin, InputIterT end, CallableT f) +{ + for (; begin != end; ++begin) + f(*begin); +} +template +static inline T +Min(T t1, T t2) +{ + return t1 < t2 ? t1 : t2; +} +template +static inline T +Max(T t1, T t2) +{ + return t1 > t2 ? t1 : t2; +} +template +static T& +InitConst(const T &t) +{ + return const_cast(t); +} +} +namespace js { +typedef uint32 HashNumber; +namespace detail { +template +class HashTable : AllocPolicy +{ + typedef typename tl::StripConst::result NonConstT; + typedef typename HashPolicy::KeyType Key; + typedef typename HashPolicy::Lookup Lookup; + static void assignT(NonConstT &dst, const T &src) { dst = src; } + public: + class Entry { + HashNumber keyHash; + public: + Entry() : keyHash(0), t() {} + void operator=(const Entry &rhs) { keyHash = rhs.keyHash; assignT(t, rhs.t); } + NonConstT t; + bool isFree() const { return keyHash == sFreeKey; } + void setFree() { keyHash = sFreeKey; assignT(t, T()); } + bool isRemoved() const { return keyHash == sRemovedKey; } + void setRemoved() { keyHash = sRemovedKey; assignT(t, T()); } + bool isLive() const { return isLiveHash(keyHash); } + void setLive(HashNumber hn) { ((void) 0); keyHash = hn; } + void setCollision() { ((void) 0); keyHash |= sCollisionBit; } + void setCollision(HashNumber collisionBit) { + ((void) 0); keyHash |= collisionBit; + } + void unsetCollision() { ((void) 0); keyHash &= ~sCollisionBit; } + bool hasCollision() const { ((void) 0); return keyHash & sCollisionBit; } + bool matchHash(HashNumber hn) { return (keyHash & ~sCollisionBit) == hn; } + HashNumber getKeyHash() const { ((void) 0); return keyHash; } + }; + class Ptr + { + friend class HashTable; + typedef void (Ptr::* ConvertibleToBool)(); + void nonNull() {} + Entry *entry; + protected: + Ptr(Entry &entry) : entry(&entry) {} + public: + bool found() const { return entry->isLive(); } + operator ConvertibleToBool() const { return found() ? &Ptr::nonNull : 0; } + bool operator==(const Ptr &rhs) const { ((void) 0); return entry == rhs.entry; } + bool operator!=(const Ptr &rhs) const { return !(*this == rhs); } + T &operator*() const { return entry->t; } + T *operator->() const { return &entry->t; } + }; + class AddPtr : public Ptr + { + friend class HashTable; + HashNumber keyHash; + AddPtr(Entry &entry, HashNumber hn) : Ptr(entry), keyHash(hn) {} + }; + class Range + { + protected: + friend class HashTable; + Range(Entry *c, Entry *e) : cur(c), end(e) { + while (cur != end && !cur->isLive()) + ++cur; + } + Entry *cur, *end; + public: + bool empty() const { + return cur == end; + } + T &front() const { + ((void) 0); + return cur->t; + } + void popFront() { + ((void) 0); + while (++cur != end && !cur->isLive()); + } + }; + class Enum : public Range + { + friend class HashTable; + HashTable &table; + bool removed; + Enum(const Enum &); + void operator=(const Enum &); + public: + template explicit + Enum(Map &map) : Range(map.all()), table(map.impl), removed(false) {} + void removeFront() { + table.remove(*this->cur); + removed = true; + } + ~Enum() { + if (removed) + table.checkUnderloaded(); + } + void endEnumeration() { + if (removed) { + table.checkUnderloaded(); + removed = false; + } + } + }; + private: + uint32 hashShift; + uint32 tableCapacity; + uint32 entryCount; + uint32 gen; + uint32 removedCount; + Entry *table; + void setTableSizeLog2(unsigned sizeLog2) { + hashShift = sHashBits - sizeLog2; + tableCapacity = ((JSUint32)1 << (sizeLog2)); + } + static const unsigned sMinSizeLog2 = 4; + static const unsigned sMinSize = 1 << sMinSizeLog2; + static const unsigned sSizeLimit = ((JSUint32)1 << (24)); + static const unsigned sHashBits = tl::BitSize::result; + static const uint8 sMinAlphaFrac = 64; + static const uint8 sMaxAlphaFrac = 192; + static const uint8 sInvMaxAlpha = 171; + static const HashNumber sGoldenRatio = 0x9E3779B9U; + static const HashNumber sCollisionBit = 1; + static const HashNumber sFreeKey = 0; + static const HashNumber sRemovedKey = 1; + static bool isLiveHash(HashNumber hash) + { + return hash > sRemovedKey; + } + static HashNumber prepareHash(const Lookup& l) + { + HashNumber keyHash = HashPolicy::hash(l); + keyHash *= sGoldenRatio; + if (!isLiveHash(keyHash)) + keyHash -= (sRemovedKey + 1); + return keyHash & ~sCollisionBit; + } + static Entry *createTable(AllocPolicy &alloc, uint32 capacity) + { + Entry *newTable = (Entry *)alloc.malloc(capacity * sizeof(Entry)); + if (!newTable) + return __null; + for (Entry *e = newTable, *end = e + capacity; e != end; ++e) + new(e) Entry(); + return newTable; + } + static void destroyTable(AllocPolicy &alloc, Entry *oldTable, uint32 capacity) + { + for (Entry *e = oldTable, *end = e + capacity; e != end; ++e) + e->~Entry(); + alloc.free(oldTable); + } + public: + HashTable(AllocPolicy ap) + : AllocPolicy(ap), + entryCount(0), + gen(0), + removedCount(0), + table(__null) + {} + bool init(uint32 length) + { + ((void) 0); + ((void) 0); + uint32 capacity = (length * sInvMaxAlpha) >> 7; + if (capacity < sMinSize) + capacity = sMinSize; + uint32 roundUp = sMinSize, roundUpLog2 = sMinSizeLog2; + while (roundUp < capacity) { + roundUp <<= 1; + ++roundUpLog2; + } + capacity = roundUp; + if (capacity >= sSizeLimit) { + this->reportAllocOverflow(); + return false; + } + table = createTable(*this, capacity); + if (!table) + return false; + setTableSizeLog2(roundUpLog2); + ; + return true; + } + bool initialized() const + { + return !!table; + } + ~HashTable() + { + if (table) + destroyTable(*this, table, tableCapacity); + } + private: + static HashNumber hash1(HashNumber hash0, uint32 shift) { + return hash0 >> shift; + } + static HashNumber hash2(HashNumber hash0, uint32 log2, uint32 shift) { + return ((hash0 << log2) >> shift) | 1; + } + bool overloaded() { + return entryCount + removedCount >= ((sMaxAlphaFrac * tableCapacity) >> 8); + } + bool underloaded() { + return tableCapacity > sMinSize && + entryCount <= ((sMinAlphaFrac * tableCapacity) >> 8); + } + static bool match(Entry &e, const Lookup &l) { + return HashPolicy::match(HashPolicy::getKey(e.t), l); + } + Entry &lookup(const Lookup &l, HashNumber keyHash, unsigned collisionBit) const + { + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ; + HashNumber h1 = hash1(keyHash, hashShift); + Entry *entry = &table[h1]; + if (entry->isFree()) { + ; + return *entry; + } + if (entry->matchHash(keyHash) && match(*entry, l)) { + ; + return *entry; + } + unsigned sizeLog2 = sHashBits - hashShift; + HashNumber h2 = hash2(keyHash, sizeLog2, hashShift); + HashNumber sizeMask = (HashNumber(1) << sizeLog2) - 1; + Entry *firstRemoved = __null; + while(true) { + if ((__builtin_expect((entry->isRemoved()), 0))) { + if (!firstRemoved) + firstRemoved = entry; + } else { + entry->setCollision(collisionBit); + } + ; + h1 -= h2; + h1 &= sizeMask; + entry = &table[h1]; + if (entry->isFree()) { + ; + return firstRemoved ? *firstRemoved : *entry; + } + if (entry->matchHash(keyHash) && match(*entry, l)) { + ; + return *entry; + } + } + } + Entry &findFreeEntry(HashNumber keyHash) + { + ; + ((void) 0); + HashNumber h1 = hash1(keyHash, hashShift); + Entry *entry = &table[h1]; + if (entry->isFree()) { + ; + return *entry; + } + unsigned sizeLog2 = sHashBits - hashShift; + HashNumber h2 = hash2(keyHash, sizeLog2, hashShift); + HashNumber sizeMask = (HashNumber(1) << sizeLog2) - 1; + while(true) { + ((void) 0); + entry->setCollision(); + ; + h1 -= h2; + h1 &= sizeMask; + entry = &table[h1]; + if (entry->isFree()) { + ; + return *entry; + } + } + } + bool changeTableSize(int deltaLog2) + { + Entry *oldTable = table; + uint32 oldCap = tableCapacity; + uint32 newLog2 = sHashBits - hashShift + deltaLog2; + uint32 newCapacity = ((JSUint32)1 << (newLog2)); + if (newCapacity >= sSizeLimit) { + this->reportAllocOverflow(); + return false; + } + Entry *newTable = createTable(*this, newCapacity); + if (!newTable) + return false; + setTableSizeLog2(newLog2); + removedCount = 0; + gen++; + table = newTable; + for (Entry *src = oldTable, *end = src + oldCap; src != end; ++src) { + if (src->isLive()) { + src->unsetCollision(); + findFreeEntry(src->getKeyHash()) = *src; + } + } + destroyTable(*this, oldTable, oldCap); + return true; + } + void remove(Entry &e) + { + ; + if (e.hasCollision()) { + e.setRemoved(); + removedCount++; + } else { + ; + e.setFree(); + } + entryCount--; + } + void checkUnderloaded() + { + if (underloaded()) { + ; + (void) changeTableSize(-1); + } + } + public: + void clear() + { + for (Entry *e = table, *end = table + tableCapacity; e != end; ++e) + *e = Entry(); + removedCount = 0; + entryCount = 0; + } + Range all() const { + return Range(table, table + tableCapacity); + } + bool empty() const { + return !entryCount; + } + uint32 count() const{ + return entryCount; + } + uint32 generation() const { + return gen; + } + Ptr lookup(const Lookup &l) const { + ReentrancyGuard g(*this); + HashNumber keyHash = prepareHash(l); + return Ptr(lookup(l, keyHash, 0)); + } + AddPtr lookupForAdd(const Lookup &l) const { + ReentrancyGuard g(*this); + HashNumber keyHash = prepareHash(l); + Entry &entry = lookup(l, keyHash, sCollisionBit); + return AddPtr(entry, keyHash); + } + bool add(AddPtr &p) + { + ReentrancyGuard g(*this); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + if (p.entry->isRemoved()) { + ; + removedCount--; + p.keyHash |= sCollisionBit; + } else { + if (overloaded()) { + int deltaLog2; + if (removedCount >= (tableCapacity >> 2)) { + ; + deltaLog2 = 0; + } else { + ; + deltaLog2 = 1; + } + if (!changeTableSize(deltaLog2)) + return false; + p.entry = &findFreeEntry(p.keyHash); + } + } + p.entry->setLive(p.keyHash); + entryCount++; + return true; + } + bool add(AddPtr &p, T** pentry) + { + if (!add(p)) + return false; + *pentry = &p.entry->t; + return true; + } + bool add(AddPtr &p, const T &t) + { + if (!add(p)) + return false; + p.entry->t = t; + return true; + } + bool relookupOrAdd(AddPtr& p, const Lookup &l, const T& t) + { + { + ReentrancyGuard g(*this); + p.entry = &lookup(l, p.keyHash, sCollisionBit); + } + return p.found() || add(p, t); + } + void remove(Ptr p) + { + ReentrancyGuard g(*this); + ((void) 0); + remove(*p.entry); + checkUnderloaded(); + } +}; +} +template +struct DefaultHasher +{ + typedef Key Lookup; + static HashNumber hash(const Lookup &l) { + return l; + } + static bool match(const Key &k, const Lookup &l) { + return k == l; + } +}; +template +struct DefaultHasher +{ + typedef T *Lookup; + static HashNumber hash(T *l) { + return HashNumber(reinterpret_cast(l) >> + tl::FloorLog2::result); + } + static bool match(T *k, T *l) { + return k == l; + } +}; +template +class HashMap +{ + public: + typedef typename HashPolicy::Lookup Lookup; + class Entry + { + template friend class detail::HashTable; + void operator=(const Entry &rhs) { + const_cast(key) = rhs.key; + value = rhs.value; + } + public: + Entry() : key(), value() {} + Entry(const Key &k, const Value &v) : key(k), value(v) {} + const Key key; + Value value; + }; + private: + struct MapHashPolicy : HashPolicy + { + typedef Key KeyType; + static const Key &getKey(Entry &e) { return e.key; } + }; + typedef detail::HashTable Impl; + friend class Impl::Enum; + HashMap(const HashMap &); + HashMap &operator=(const HashMap &); + Impl impl; + public: + HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + bool init(uint32 len = 0) { return impl.init(len); } + bool initialized() const { return impl.initialized(); } + typedef typename Impl::Ptr Ptr; + Ptr lookup(const Lookup &l) const { return impl.lookup(l); } + void remove(Ptr p) { impl.remove(p); } + typedef typename Impl::AddPtr AddPtr; + AddPtr lookupForAdd(const Lookup &l) const { + return impl.lookupForAdd(l); + } + bool add(AddPtr &p, const Key &k, const Value &v) { + Entry *pentry; + if (!impl.add(p, &pentry)) + return false; + const_cast(pentry->key) = k; + pentry->value = v; + return true; + } + bool add(AddPtr &p, const Key &k) { + Entry *pentry; + if (!impl.add(p, &pentry)) + return false; + const_cast(pentry->key) = k; + return true; + } + bool relookupOrAdd(AddPtr &p, const Key &k, const Value &v) { + return impl.relookupOrAdd(p, k, Entry(k, v)); + } + typedef typename Impl::Range Range; + Range all() const { return impl.all(); } + size_t count() const { return impl.count(); } + typedef typename Impl::Enum Enum; + void clear() { impl.clear(); } + bool empty() const { return impl.empty(); } + unsigned generation() const { return impl.generation(); } + bool has(const Lookup &l) const { + return impl.lookup(l) != __null; + } + Entry *put(const Key &k, const Value &v) { + AddPtr p = lookupForAdd(k); + if (p) { + p->value = v; + return &*p; + } + return add(p, k, v) ? &*p : __null; + } + void remove(const Lookup &l) { + if (Ptr p = lookup(l)) + remove(p); + } +}; +template +class HashSet +{ + typedef typename HashPolicy::Lookup Lookup; + struct SetOps : HashPolicy { + typedef T KeyType; + static const KeyType &getKey(const T &t) { return t; } + }; + typedef detail::HashTable Impl; + friend class Impl::Enum; + HashSet(const HashSet &); + HashSet &operator=(const HashSet &); + Impl impl; + public: + HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + bool init(uint32 len = 0) { return impl.init(len); } + bool initialized() const { return impl.initialized(); } + typedef typename Impl::Ptr Ptr; + Ptr lookup(const Lookup &l) const { return impl.lookup(l); } + void remove(Ptr p) { impl.remove(p); } + typedef typename Impl::AddPtr AddPtr; + AddPtr lookupForAdd(const Lookup &l) const { + return impl.lookupForAdd(l); + } + bool add(AddPtr &p, const T &t) { + return impl.add(p, t); + } + bool relookupOrAdd(AddPtr &p, const Lookup &l, const T &t) { + return impl.relookupOrAdd(p, l, t); + } + typedef typename Impl::Range Range; + Range all() const { return impl.all(); } + size_t count() const { return impl.count(); } + typedef typename Impl::Enum Enum; + void clear() { impl.clear(); } + bool empty() const { return impl.empty(); } + unsigned generation() const { return impl.generation(); } + bool has(const Lookup &l) const { + return impl.lookup(l) != __null; + } + const T *put(const T &t) { + AddPtr p = lookupForAdd(t); + return p ? &*p : (add(p, t) ? &*p : __null); + } + void remove(const Lookup &l) { + if (Ptr p = lookup(l)) + remove(p); + } +}; +} +extern "C" { +enum +{ + _ISupper = (1 << (0)), + _ISlower = (1 << (1)), + _ISalpha = (1 << (2)), + _ISdigit = (1 << (3)), + _ISxdigit = (1 << (4)), + _ISspace = (1 << (5)), + _ISprint = (1 << (6)), + _ISgraph = (1 << (7)), + _ISblank = (1 << (8)), + _IScntrl = (1 << (9)), + _ISpunct = (1 << (10)), + _ISalnum = (1 << (11)) +}; +extern const unsigned short int **__ctype_b_loc (void) + throw () __attribute__ ((__const__)); +extern const __int32_t **__ctype_tolower_loc (void) + throw () __attribute__ ((__const__)); +extern const __int32_t **__ctype_toupper_loc (void) + throw () __attribute__ ((__const__)); +extern int isalnum (int) throw (); +extern int isalpha (int) throw (); +extern int iscntrl (int) throw (); +extern int isdigit (int) throw (); +extern int islower (int) throw (); +extern int isgraph (int) throw (); +extern int isprint (int) throw (); +extern int ispunct (int) throw (); +extern int isspace (int) throw (); +extern int isupper (int) throw (); +extern int isxdigit (int) throw (); +extern int tolower (int __c) throw (); +extern int toupper (int __c) throw (); +extern int isblank (int) throw (); +extern int isctype (int __c, int __mask) throw (); +extern int isascii (int __c) throw (); +extern int toascii (int __c) throw (); +extern int _toupper (int) throw (); +extern int _tolower (int) throw (); +extern int isalnum_l (int, __locale_t) throw (); +extern int isalpha_l (int, __locale_t) throw (); +extern int iscntrl_l (int, __locale_t) throw (); +extern int isdigit_l (int, __locale_t) throw (); +extern int islower_l (int, __locale_t) throw (); +extern int isgraph_l (int, __locale_t) throw (); +extern int isprint_l (int, __locale_t) throw (); +extern int ispunct_l (int, __locale_t) throw (); +extern int isspace_l (int, __locale_t) throw (); +extern int isupper_l (int, __locale_t) throw (); +extern int isxdigit_l (int, __locale_t) throw (); +extern int isblank_l (int, __locale_t) throw (); +extern int __tolower_l (int __c, __locale_t __l) throw (); +extern int tolower_l (int __c, __locale_t __l) throw (); +extern int __toupper_l (int __c, __locale_t __l) throw (); +extern int toupper_l (int __c, __locale_t __l) throw (); +} +extern "C" { +typedef unsigned char PRUint8; +typedef signed char PRInt8; +typedef unsigned short PRUint16; +typedef short PRInt16; +typedef unsigned int PRUint32; +typedef int PRInt32; +typedef long PRInt64; +typedef unsigned long PRUint64; +typedef int PRIntn; +typedef unsigned int PRUintn; +typedef double PRFloat64; +typedef size_t PRSize; +typedef PRInt32 PROffset32; +typedef PRInt64 PROffset64; +typedef ptrdiff_t PRPtrdiff; +typedef unsigned long PRUptrdiff; +typedef PRIntn PRBool; +typedef PRUint8 PRPackedBool; +typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus; +typedef PRUint16 PRUnichar; +typedef long PRWord; +typedef unsigned long PRUword; +} +extern "C" { +typedef struct PRLock PRLock; +extern __attribute__((visibility("default"))) PRLock* PR_NewLock(void); +extern __attribute__((visibility("default"))) void PR_DestroyLock(PRLock *lock); +extern __attribute__((visibility("default"))) void PR_Lock(PRLock *lock); +extern __attribute__((visibility("default"))) PRStatus PR_Unlock(PRLock *lock); +extern __attribute__((visibility("default"))) void PR_AssertCurrentThreadOwnsLock(PRLock *lock); +} +extern "C" { +extern __attribute__((visibility("default"))) PRInt32 PR_AtomicIncrement(PRInt32 *val); +extern __attribute__((visibility("default"))) PRInt32 PR_AtomicDecrement(PRInt32 *val); +extern __attribute__((visibility("default"))) PRInt32 PR_AtomicSet(PRInt32 *val, PRInt32 newval); +extern __attribute__((visibility("default"))) PRInt32 PR_AtomicAdd(PRInt32 *ptr, PRInt32 val); +typedef struct PRStackElemStr PRStackElem; +struct PRStackElemStr { + PRStackElem *prstk_elem_next; +}; +typedef struct PRStackStr PRStack; +extern __attribute__((visibility("default"))) PRStack * PR_CreateStack(const char *stack_name); +extern __attribute__((visibility("default"))) void PR_StackPush(PRStack *stack, PRStackElem *stack_elem); +extern __attribute__((visibility("default"))) PRStackElem * PR_StackPop(PRStack *stack); +extern __attribute__((visibility("default"))) PRStatus PR_DestroyStack(PRStack *stack); +} +extern "C" { +typedef PRUint32 PRIntervalTime; +extern __attribute__((visibility("default"))) PRIntervalTime PR_IntervalNow(void); +extern __attribute__((visibility("default"))) PRUint32 PR_TicksPerSecond(void); +extern __attribute__((visibility("default"))) PRIntervalTime PR_SecondsToInterval(PRUint32 seconds); +extern __attribute__((visibility("default"))) PRIntervalTime PR_MillisecondsToInterval(PRUint32 milli); +extern __attribute__((visibility("default"))) PRIntervalTime PR_MicrosecondsToInterval(PRUint32 micro); +extern __attribute__((visibility("default"))) PRUint32 PR_IntervalToSeconds(PRIntervalTime ticks); +extern __attribute__((visibility("default"))) PRUint32 PR_IntervalToMilliseconds(PRIntervalTime ticks); +extern __attribute__((visibility("default"))) PRUint32 PR_IntervalToMicroseconds(PRIntervalTime ticks); +} +extern "C" { +typedef struct PRCondVar PRCondVar; +extern __attribute__((visibility("default"))) PRCondVar* PR_NewCondVar(PRLock *lock); +extern __attribute__((visibility("default"))) void PR_DestroyCondVar(PRCondVar *cvar); +extern __attribute__((visibility("default"))) PRStatus PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout); +extern __attribute__((visibility("default"))) PRStatus PR_NotifyCondVar(PRCondVar *cvar); +extern __attribute__((visibility("default"))) PRStatus PR_NotifyAllCondVar(PRCondVar *cvar); +} +extern "C" { +typedef struct PRThread PRThread; +typedef struct PRThreadStack PRThreadStack; +typedef enum PRThreadType { + PR_USER_THREAD, + PR_SYSTEM_THREAD +} PRThreadType; +typedef enum PRThreadScope { + PR_LOCAL_THREAD, + PR_GLOBAL_THREAD, + PR_GLOBAL_BOUND_THREAD +} PRThreadScope; +typedef enum PRThreadState { + PR_JOINABLE_THREAD, + PR_UNJOINABLE_THREAD +} PRThreadState; +typedef enum PRThreadPriority +{ + PR_PRIORITY_FIRST = 0, + PR_PRIORITY_LOW = 0, + PR_PRIORITY_NORMAL = 1, + PR_PRIORITY_HIGH = 2, + PR_PRIORITY_URGENT = 3, + PR_PRIORITY_LAST = 3 +} PRThreadPriority; +extern __attribute__((visibility("default"))) PRThread* PR_CreateThread(PRThreadType type, + void ( *start)(void *arg), + void *arg, + PRThreadPriority priority, + PRThreadScope scope, + PRThreadState state, + PRUint32 stackSize); +extern __attribute__((visibility("default"))) PRStatus PR_JoinThread(PRThread *thread); +extern __attribute__((visibility("default"))) PRThread* PR_GetCurrentThread(void); +extern __attribute__((visibility("default"))) PRThreadPriority PR_GetThreadPriority(const PRThread *thread); +extern __attribute__((visibility("default"))) void PR_SetThreadPriority(PRThread *thread, PRThreadPriority priority); +extern __attribute__((visibility("default"))) PRStatus PR_SetCurrentThreadName(const char *name); +extern __attribute__((visibility("default"))) const char * PR_GetThreadName(const PRThread *thread); +typedef void ( *PRThreadPrivateDTOR)(void *priv); +extern __attribute__((visibility("default"))) PRStatus PR_NewThreadPrivateIndex( + PRUintn *newIndex, PRThreadPrivateDTOR destructor); +extern __attribute__((visibility("default"))) PRStatus PR_SetThreadPrivate(PRUintn tpdIndex, void *priv); +extern __attribute__((visibility("default"))) void* PR_GetThreadPrivate(PRUintn tpdIndex); +extern __attribute__((visibility("default"))) PRStatus PR_Interrupt(PRThread *thread); +extern __attribute__((visibility("default"))) void PR_ClearInterrupt(void); +extern __attribute__((visibility("default"))) void PR_BlockInterrupt(void); +extern __attribute__((visibility("default"))) void PR_UnblockInterrupt(void); +extern __attribute__((visibility("default"))) PRStatus PR_Sleep(PRIntervalTime ticks); +extern __attribute__((visibility("default"))) PRThreadScope PR_GetThreadScope(const PRThread *thread); +extern __attribute__((visibility("default"))) PRThreadType PR_GetThreadType(const PRThread *thread); +extern __attribute__((visibility("default"))) PRThreadState PR_GetThreadState(const PRThread *thread); +} +extern "C" { +typedef struct JSFatLock JSFatLock; +typedef struct JSThinLock { + jsword owner; + JSFatLock *fat; +} JSThinLock; +typedef PRLock JSLock; +extern void js_Lock(JSContext *cx, JSThinLock *tl); +extern void js_Unlock(JSContext *cx, JSThinLock *tl); +extern void js_LockRuntime(JSRuntime *rt); +extern void js_UnlockRuntime(JSRuntime *rt); +extern int js_SetupLocks(int,int); +extern void js_CleanupLocks(); +extern void js_InitLock(JSThinLock *); +extern void js_FinishLock(JSThinLock *); +extern JSBool +js_CompareAndSwap(volatile jsword *w, jsword ov, jsword nv); +extern void +js_AtomicSetMask(volatile jsword *w, jsword mask); +extern void +js_AtomicClearMask(volatile jsword *w, jsword mask); +} +namespace js { +class AutoLock { + private: + JSLock *lock; + public: + AutoLock(JSLock *lock) : lock(lock) { PR_Lock(lock); } + ~AutoLock() { PR_Unlock(lock); } +}; +} +static inline int +JSDOUBLE_IS_NEGZERO(jsdouble d) +{ + return (d == 0 && (sizeof (d) == sizeof (float) ? __signbitf (d) : sizeof (d) == sizeof (double) ? __signbit (d) : __signbitl (d))); +} +static inline + bool +JSDOUBLE_IS_INT32(jsdouble d, int32_t* pi) +{ + if (JSDOUBLE_IS_NEGZERO(d)) + return false; + return d == (*pi = int32_t(d)); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_SPECIFIC_INT32_IMPL(jsval_layout l, int32 i32) +{ + return l.asBits == (((uint64)(uint32)i32) | JSVAL_SHIFTED_TAG_INT32); +} +static __attribute__((always_inline)) inline JSBool +JSVAL_IS_SPECIFIC_BOOLEAN(jsval_layout l, JSBool b) +{ + return l.asBits == (((uint64)(uint32)b) | JSVAL_SHIFTED_TAG_BOOLEAN); +} +static __attribute__((always_inline)) inline jsval_layout +MAGIC_TO_JSVAL_IMPL(JSWhyMagic why) +{ + jsval_layout l; + l.asBits = ((uint64)(uint32)why) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} +static __attribute__((always_inline)) inline jsval_layout +MAGIC_TO_JSVAL_IMPL(JSObject *obj) +{ + jsval_layout l; + l.asBits = ((uint64)obj) | JSVAL_SHIFTED_TAG_MAGIC; + return l; +} +static __attribute__((always_inline)) inline JSBool +JSVAL_SAME_TYPE_IMPL(jsval_layout lhs, jsval_layout rhs) +{ + uint64 lbits = lhs.asBits, rbits = rhs.asBits; + return (lbits <= JSVAL_TAG_MAX_DOUBLE && rbits <= JSVAL_TAG_MAX_DOUBLE) || + (((lbits ^ rbits) & 0xFFFF800000000000LL) == 0); +} +static __attribute__((always_inline)) inline jsval_layout +PRIVATE_UINT32_TO_JSVAL_IMPL(uint32 ui) +{ + jsval_layout l; + l.asBits = (uint64)ui; + ((void) 0); + return l; +} +static __attribute__((always_inline)) inline uint32 +JSVAL_TO_PRIVATE_UINT32_IMPL(jsval_layout l) +{ + ((void) 0); + return (uint32)l.asBits; +} +static __attribute__((always_inline)) inline JSValueType +JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval_layout l) +{ + uint64 type = (l.asBits >> 47) & 0xF; + ((void) 0); + return (JSValueType)type; +} +static __attribute__((always_inline)) inline JSValueTag +JSVAL_EXTRACT_NON_DOUBLE_TAG_IMPL(jsval_layout l) +{ + uint64 tag = l.asBits >> 47; + ((void) 0); + return (JSValueTag)tag; +} +typedef int js_static_assert3[(__builtin_offsetof (jsval_layout, s.payload) == 0) ? 1 : -1]; +typedef int js_static_assert4[((JSVAL_TYPE_NONFUNOBJ & 0xF) == JSVAL_TYPE_OBJECT) ? 1 : -1]; +typedef int js_static_assert5[((JSVAL_TYPE_FUNOBJ & 0xF) == JSVAL_TYPE_OBJECT) ? 1 : -1]; +static __attribute__((always_inline)) inline jsval_layout +BOX_NON_DOUBLE_JSVAL(JSValueType type, uint64 *slot) +{ + jsval_layout l; + ((void) 0); + uint32 isI32 = (uint32)(type < JSVAL_TYPE_MAGIC); + uint32 shift = isI32 * 32; + uint64 mask = ((uint64)-1) >> shift; + uint64 payload = *slot & mask; + ((void) 0) + ; + l.asBits = payload | (((uint64)((JSValueTag)(JSVAL_TAG_MAX_DOUBLE | (type & 0xF)))) << 47); + return l; +} +static __attribute__((always_inline)) inline void +UNBOX_NON_DOUBLE_JSVAL(jsval_layout l, uint64 *out) +{ + ((void) 0); + *out = (l.asBits & 0x00007FFFFFFFFFFFLL); +} +namespace js { +class Value +{ + public: + __attribute__((always_inline)) inline + void setNull() { + data.asBits = (((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0))); + } + __attribute__((always_inline)) inline + void setUndefined() { + data.asBits = (((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0))); + } + __attribute__((always_inline)) inline + void setInt32(int32 i) { + data = INT32_TO_JSVAL_IMPL(i); + } + __attribute__((always_inline)) inline + int32 &getInt32Ref() { + ((void) 0); + return data.s.payload.i32; + } + __attribute__((always_inline)) inline + void setDouble(double d) { + data = DOUBLE_TO_JSVAL_IMPL(d); + } + __attribute__((always_inline)) inline + double &getDoubleRef() { + ((void) 0); + return data.asDouble; + } + __attribute__((always_inline)) inline + void setString(JSString *str) { + data = STRING_TO_JSVAL_IMPL(str); + } + __attribute__((always_inline)) inline + void setObject(JSObject &obj) { + data = OBJECT_TO_JSVAL_IMPL(&obj); + } + __attribute__((always_inline)) inline + void setBoolean(bool b) { + data = BOOLEAN_TO_JSVAL_IMPL(b); + } + __attribute__((always_inline)) inline + void setMagic(JSWhyMagic why) { + data = MAGIC_TO_JSVAL_IMPL(why); + } + __attribute__((always_inline)) inline + void setMagicWithObjectOrNullPayload(JSObject *obj) { + data = MAGIC_TO_JSVAL_IMPL(obj); + } + __attribute__((always_inline)) inline + JSObject *getMagicObjectOrNullPayload() const { + return MAGIC_JSVAL_TO_OBJECT_OR_NULL_IMPL(data); + } + __attribute__((always_inline)) inline + void setNumber(uint32 ui) { + if (ui > ((jsint)0x7fffffff)) + setDouble((double)ui); + else + setInt32((int32)ui); + } + __attribute__((always_inline)) inline + void setNumber(double d) { + int32_t i; + if (JSDOUBLE_IS_INT32(d, &i)) + setInt32(i); + else + setDouble(d); + } + __attribute__((always_inline)) inline + void setObjectOrNull(JSObject *arg) { + if (arg) + setObject(*arg); + else + setNull(); + } + __attribute__((always_inline)) inline + void setObjectOrUndefined(JSObject *arg) { + if (arg) + setObject(*arg); + else + setUndefined(); + } + __attribute__((always_inline)) inline + void swap(Value &rhs) { + uint64 tmp = rhs.data.asBits; + rhs.data.asBits = data.asBits; + data.asBits = tmp; + } + __attribute__((always_inline)) inline + bool isUndefined() const { + return JSVAL_IS_UNDEFINED_IMPL(data); + } + __attribute__((always_inline)) inline + bool isNull() const { + return JSVAL_IS_NULL_IMPL(data); + } + __attribute__((always_inline)) inline + bool isNullOrUndefined() const { + return isNull() || isUndefined(); + } + __attribute__((always_inline)) inline + bool isInt32() const { + return JSVAL_IS_INT32_IMPL(data); + } + __attribute__((always_inline)) inline + bool isInt32(int32 i32) const { + return JSVAL_IS_SPECIFIC_INT32_IMPL(data, i32); + } + __attribute__((always_inline)) inline + bool isDouble() const { + return JSVAL_IS_DOUBLE_IMPL(data); + } + __attribute__((always_inline)) inline + bool isNumber() const { + return JSVAL_IS_NUMBER_IMPL(data); + } + __attribute__((always_inline)) inline + bool isString() const { + return JSVAL_IS_STRING_IMPL(data); + } + __attribute__((always_inline)) inline + bool isObject() const { + return JSVAL_IS_OBJECT_IMPL(data); + } + __attribute__((always_inline)) inline + bool isPrimitive() const { + return JSVAL_IS_PRIMITIVE_IMPL(data); + } + __attribute__((always_inline)) inline + bool isObjectOrNull() const { + return JSVAL_IS_OBJECT_OR_NULL_IMPL(data); + } + __attribute__((always_inline)) inline + bool isGCThing() const { + return JSVAL_IS_GCTHING_IMPL(data); + } + __attribute__((always_inline)) inline + bool isBoolean() const { + return JSVAL_IS_BOOLEAN_IMPL(data); + } + __attribute__((always_inline)) inline + bool isTrue() const { + return JSVAL_IS_SPECIFIC_BOOLEAN(data, true); + } + __attribute__((always_inline)) inline + bool isFalse() const { + return JSVAL_IS_SPECIFIC_BOOLEAN(data, false); + } + __attribute__((always_inline)) inline + bool isMagic() const { + return JSVAL_IS_MAGIC_IMPL(data); + } + __attribute__((always_inline)) inline + bool isMagic(JSWhyMagic why) const { + ((void) 0); + return JSVAL_IS_MAGIC_IMPL(data); + } + __attribute__((always_inline)) inline + bool hasPtrPayload() const { + return data.asBits >= JSVAL_SHIFTED_TAG_MAGIC; + } + __attribute__((always_inline)) inline + bool isMarkable() const { + return JSVAL_IS_TRACEABLE_IMPL(data); + } + __attribute__((always_inline)) inline + int32 gcKind() const { + ((void) 0); + return JSVAL_TRACE_KIND_IMPL(data); + } + __attribute__((always_inline)) inline + bool operator==(const Value &rhs) const { + return data.asBits == rhs.data.asBits; + } + __attribute__((always_inline)) inline + bool operator!=(const Value &rhs) const { + return data.asBits != rhs.data.asBits; + } + friend bool SameType(const Value &lhs, const Value &rhs); + __attribute__((always_inline)) inline + int32 toInt32() const { + ((void) 0); + return JSVAL_TO_INT32_IMPL(data); + } + __attribute__((always_inline)) inline + double toDouble() const { + ((void) 0); + return data.asDouble; + } + __attribute__((always_inline)) inline + double toNumber() const { + ((void) 0); + return isDouble() ? toDouble() : double(toInt32()); + } + __attribute__((always_inline)) inline + JSString *toString() const { + ((void) 0); + return JSVAL_TO_STRING_IMPL(data); + } + __attribute__((always_inline)) inline + JSObject &toObject() const { + ((void) 0); + return *JSVAL_TO_OBJECT_IMPL(data); + } + __attribute__((always_inline)) inline + JSObject *toObjectOrNull() const { + ((void) 0); + return JSVAL_TO_OBJECT_IMPL(data); + } + __attribute__((always_inline)) inline + void *toGCThing() const { + ((void) 0); + return JSVAL_TO_GCTHING_IMPL(data); + } + __attribute__((always_inline)) inline + bool toBoolean() const { + ((void) 0); + return JSVAL_TO_BOOLEAN_IMPL(data); + } + __attribute__((always_inline)) inline + uint32 payloadAsRawUint32() const { + ((void) 0); + return data.s.payload.u32; + } + __attribute__((always_inline)) inline + uint64 asRawBits() const { + return data.asBits; + } + __attribute__((always_inline)) inline + JSValueType extractNonDoubleType() const { + return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data); + } + __attribute__((always_inline)) inline + JSValueTag extractNonDoubleTag() const { + return JSVAL_EXTRACT_NON_DOUBLE_TAG_IMPL(data); + } + __attribute__((always_inline)) inline + void unboxNonDoubleTo(uint64 *out) const { + UNBOX_NON_DOUBLE_JSVAL(data, out); + } + __attribute__((always_inline)) inline + void boxNonDoubleFrom(JSValueType type, uint64 *out) { + data = BOX_NON_DOUBLE_JSVAL(type, out); + } + __attribute__((always_inline)) inline + JSValueType extractNonDoubleObjectTraceType() const { + ((void) 0); + return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data); + } + __attribute__((always_inline)) inline + JSValueTag extractNonDoubleObjectTraceTag() const { + ((void) 0); + return JSVAL_EXTRACT_NON_DOUBLE_TAG_IMPL(data); + } + __attribute__((always_inline)) inline + void setPrivate(void *ptr) { + data = PRIVATE_PTR_TO_JSVAL_IMPL(ptr); + } + __attribute__((always_inline)) inline + void *toPrivate() const { + ((void) 0); + return JSVAL_TO_PRIVATE_PTR_IMPL(data); + } + __attribute__((always_inline)) inline + void setPrivateUint32(uint32 ui) { + data = PRIVATE_UINT32_TO_JSVAL_IMPL(ui); + } + __attribute__((always_inline)) inline + uint32 toPrivateUint32() const { + ((void) 0); + return JSVAL_TO_PRIVATE_UINT32_IMPL(data); + } + __attribute__((always_inline)) inline + uint32 &getPrivateUint32Ref() { + ((void) 0); + return data.s.payload.u32; + } + __attribute__((always_inline)) inline + void setUnmarkedPtr(void *ptr) { + data.asPtr = ptr; + } + __attribute__((always_inline)) inline + void *toUnmarkedPtr() const { + return data.asPtr; + } + const jsuword *payloadWord() const { + return &data.s.payload.word; + } + private: + void staticAssertions() { + typedef int js_static_assert6[(sizeof(JSValueType) == 1) ? 1 : -1]; + typedef int js_static_assert7[(sizeof(JSValueTag) == 4) ? 1 : -1]; + typedef int js_static_assert8[(sizeof(JSBool) == 4) ? 1 : -1]; + typedef int js_static_assert9[(sizeof(JSWhyMagic) <= 4) ? 1 : -1]; + typedef int js_static_assert10[(sizeof(jsval) == 8) ? 1 : -1]; + } + jsval_layout data; +} __attribute__((aligned (8))); +__attribute__((always_inline)) inline + bool +SameType(const Value &lhs, const Value &rhs) +{ + return JSVAL_SAME_TYPE_IMPL(lhs.data, rhs.data); +} +static __attribute__((always_inline)) inline Value +NullValue() +{ + Value v; + v.setNull(); + return v; +} +static __attribute__((always_inline)) inline Value +UndefinedValue() +{ + Value v; + v.setUndefined(); + return v; +} +static __attribute__((always_inline)) inline Value +Int32Value(int32 i32) +{ + Value v; + v.setInt32(i32); + return v; +} +static __attribute__((always_inline)) inline Value +DoubleValue(double dbl) +{ + Value v; + v.setDouble(dbl); + return v; +} +static __attribute__((always_inline)) inline Value +StringValue(JSString *str) +{ + Value v; + v.setString(str); + return v; +} +static __attribute__((always_inline)) inline Value +BooleanValue(bool boo) +{ + Value v; + v.setBoolean(boo); + return v; +} +static __attribute__((always_inline)) inline Value +ObjectValue(JSObject &obj) +{ + Value v; + v.setObject(obj); + return v; +} +static __attribute__((always_inline)) inline Value +MagicValue(JSWhyMagic why) +{ + Value v; + v.setMagic(why); + return v; +} +static __attribute__((always_inline)) inline Value +NumberValue(double dbl) +{ + Value v; + v.setNumber(dbl); + return v; +} +static __attribute__((always_inline)) inline Value +ObjectOrNullValue(JSObject *obj) +{ + Value v; + v.setObjectOrNull(obj); + return v; +} +static __attribute__((always_inline)) inline Value +PrivateValue(void *ptr) +{ + Value v; + v.setPrivate(ptr); + return v; +} +static __attribute__((always_inline)) inline void +ClearValueRange(Value *vec, uintN len, bool useHoles) +{ + if (useHoles) { + for (uintN i = 0; i < len; i++) + vec[i].setMagic(JS_ARRAY_HOLE); + } else { + for (uintN i = 0; i < len; i++) + vec[i].setUndefined(); + } +} +static inline jsval * Jsvalify(Value *v) { return (jsval *)v; } +static inline const jsval * Jsvalify(const Value *v) { return (const jsval *)v; } +static inline jsval & Jsvalify(Value &v) { return (jsval &)v; } +static inline const jsval & Jsvalify(const Value &v) { return (const jsval &)v; } +static inline Value * Valueify(jsval *v) { return (Value *)v; } +static inline const Value * Valueify(const jsval *v) { return (const Value *)v; } +static inline Value ** Valueify(jsval **v) { return (Value **)v; } +static inline Value & Valueify(jsval &v) { return (Value &)v; } +static inline const Value & Valueify(const jsval &v) { return (const Value &)v; } +struct Class; +typedef JSBool +(* Native)(JSContext *cx, uintN argc, Value *vp); +typedef JSBool +(* PropertyOp)(JSContext *cx, JSObject *obj, jsid id, Value *vp); +typedef JSBool +(* StrictPropertyOp)(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp); +typedef JSBool +(* ConvertOp)(JSContext *cx, JSObject *obj, JSType type, Value *vp); +typedef JSBool +(* NewEnumerateOp)(JSContext *cx, JSObject *obj, JSIterateOp enum_op, + Value *statep, jsid *idp); +typedef JSBool +(* HasInstanceOp)(JSContext *cx, JSObject *obj, const Value *v, JSBool *bp); +typedef JSBool +(* CheckAccessOp)(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, + Value *vp); +typedef JSBool +(* EqualityOp)(JSContext *cx, JSObject *obj, const Value *v, JSBool *bp); +typedef JSBool +(* DefinePropOp)(JSContext *cx, JSObject *obj, jsid id, const Value *value, + PropertyOp getter, StrictPropertyOp setter, uintN attrs); +typedef JSBool +(* PropertyIdOp)(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, Value *vp); +typedef JSBool +(* StrictPropertyIdOp)(JSContext *cx, JSObject *obj, jsid id, Value *vp, JSBool strict); +typedef JSBool +(* DeleteIdOp)(JSContext *cx, JSObject *obj, jsid id, Value *vp, JSBool strict); +typedef JSBool +(* CallOp)(JSContext *cx, uintN argc, Value *vp); +typedef JSBool +(* LookupPropOp)(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, + JSProperty **propp); +typedef JSBool +(* AttributesOp)(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp); +typedef JSType +(* TypeOfOp)(JSContext *cx, JSObject *obj); +typedef void +(* TraceOp)(JSTracer *trc, JSObject *obj); +typedef JSObject * +(* ObjectOp)(JSContext *cx, JSObject *obj); +typedef void +(* FinalizeOp)(JSContext *cx, JSObject *obj); +class AutoIdVector; +typedef JSBool +(* FixOp)(JSContext *cx, JSObject *obj, bool *fixed, AutoIdVector *props); +static inline Native Valueify(JSNative f) { return (Native)f; } +static inline JSNative Jsvalify(Native f) { return (JSNative)f; } +static inline PropertyOp Valueify(JSPropertyOp f) { return (PropertyOp)f; } +static inline JSPropertyOp Jsvalify(PropertyOp f) { return (JSPropertyOp)f; } +static inline StrictPropertyOp Valueify(JSStrictPropertyOp f) { return (StrictPropertyOp)f; } +static inline JSStrictPropertyOp Jsvalify(StrictPropertyOp f) { return (JSStrictPropertyOp)f; } +static inline ConvertOp Valueify(JSConvertOp f) { return (ConvertOp)f; } +static inline JSConvertOp Jsvalify(ConvertOp f) { return (JSConvertOp)f; } +static inline NewEnumerateOp Valueify(JSNewEnumerateOp f) { return (NewEnumerateOp)f; } +static inline JSNewEnumerateOp Jsvalify(NewEnumerateOp f) { return (JSNewEnumerateOp)f; } +static inline HasInstanceOp Valueify(JSHasInstanceOp f) { return (HasInstanceOp)f; } +static inline JSHasInstanceOp Jsvalify(HasInstanceOp f) { return (JSHasInstanceOp)f; } +static inline CheckAccessOp Valueify(JSCheckAccessOp f) { return (CheckAccessOp)f; } +static inline JSCheckAccessOp Jsvalify(CheckAccessOp f) { return (JSCheckAccessOp)f; } +static inline EqualityOp Valueify(JSEqualityOp f); +static inline JSEqualityOp Jsvalify(EqualityOp f); +static const PropertyOp PropertyStub = (PropertyOp)JS_PropertyStub; +static const StrictPropertyOp StrictPropertyStub = (StrictPropertyOp)JS_StrictPropertyStub; +static const JSEnumerateOp EnumerateStub = JS_EnumerateStub; +static const JSResolveOp ResolveStub = JS_ResolveStub; +static const ConvertOp ConvertStub = (ConvertOp)JS_ConvertStub; +static const JSFinalizeOp FinalizeStub = JS_FinalizeStub; +struct ClassSizeMeasurement { + 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; +}; +struct ClassExtension { + EqualityOp equality; + JSObjectOp outerObject; + JSObjectOp innerObject; + JSIteratorOp iteratorObject; + void *unused; +}; +struct ObjectOps { + js::LookupPropOp lookupProperty; + js::DefinePropOp defineProperty; + js::PropertyIdOp getProperty; + js::StrictPropertyIdOp setProperty; + js::AttributesOp getAttributes; + js::AttributesOp setAttributes; + js::DeleteIdOp deleteProperty; + js::NewEnumerateOp enumerate; + js::TypeOfOp typeOf; + js::TraceOp trace; + js::FixOp fix; + js::ObjectOp thisObject; + js::FinalizeOp clear; +}; +struct Class { + 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; + ClassExtension ext; + ObjectOps ops; + uint8 pad[sizeof(JSClass) - sizeof(ClassSizeMeasurement) - + sizeof(ClassExtension) - sizeof(ObjectOps)]; + static const uint32 NON_NATIVE = (1<<((8 + 8)+4)); + bool isNative() const { + return !(flags & NON_NATIVE); + } +}; +typedef int js_static_assert11[(__builtin_offsetof (JSClass, name) == __builtin_offsetof (Class, name)) ? 1 : -1]; +typedef int js_static_assert12[(__builtin_offsetof (JSClass, flags) == __builtin_offsetof (Class, flags)) ? 1 : -1]; +typedef int js_static_assert13[(__builtin_offsetof (JSClass, addProperty) == __builtin_offsetof (Class, addProperty)) ? 1 : -1]; +typedef int js_static_assert14[(__builtin_offsetof (JSClass, delProperty) == __builtin_offsetof (Class, delProperty)) ? 1 : -1]; +typedef int js_static_assert15[(__builtin_offsetof (JSClass, getProperty) == __builtin_offsetof (Class, getProperty)) ? 1 : -1]; +typedef int js_static_assert16[(__builtin_offsetof (JSClass, setProperty) == __builtin_offsetof (Class, setProperty)) ? 1 : -1]; +typedef int js_static_assert17[(__builtin_offsetof (JSClass, enumerate) == __builtin_offsetof (Class, enumerate)) ? 1 : -1]; +typedef int js_static_assert18[(__builtin_offsetof (JSClass, resolve) == __builtin_offsetof (Class, resolve)) ? 1 : -1]; +typedef int js_static_assert19[(__builtin_offsetof (JSClass, convert) == __builtin_offsetof (Class, convert)) ? 1 : -1]; +typedef int js_static_assert20[(__builtin_offsetof (JSClass, finalize) == __builtin_offsetof (Class, finalize)) ? 1 : -1]; +typedef int js_static_assert21[(__builtin_offsetof (JSClass, reserved0) == __builtin_offsetof (Class, reserved0)) ? 1 : -1]; +typedef int js_static_assert22[(__builtin_offsetof (JSClass, checkAccess) == __builtin_offsetof (Class, checkAccess)) ? 1 : -1]; +typedef int js_static_assert23[(__builtin_offsetof (JSClass, call) == __builtin_offsetof (Class, call)) ? 1 : -1]; +typedef int js_static_assert24[(__builtin_offsetof (JSClass, construct) == __builtin_offsetof (Class, construct)) ? 1 : -1]; +typedef int js_static_assert25[(__builtin_offsetof (JSClass, xdrObject) == __builtin_offsetof (Class, xdrObject)) ? 1 : -1]; +typedef int js_static_assert26[(__builtin_offsetof (JSClass, hasInstance) == __builtin_offsetof (Class, hasInstance)) ? 1 : -1]; +typedef int js_static_assert27[(__builtin_offsetof (JSClass, mark) == __builtin_offsetof (Class, mark)) ? 1 : -1]; +typedef int js_static_assert28[(sizeof(JSClass) == sizeof(Class)) ? 1 : -1]; +struct PropertyDescriptor { + JSObject *obj; + uintN attrs; + PropertyOp getter; + StrictPropertyOp setter; + Value value; + uintN shortid; +}; +typedef int js_static_assert29[(__builtin_offsetof (JSPropertyDescriptor, obj) == __builtin_offsetof (PropertyDescriptor, obj)) ? 1 : -1]; +typedef int js_static_assert30[(__builtin_offsetof (JSPropertyDescriptor, attrs) == __builtin_offsetof (PropertyDescriptor, attrs)) ? 1 : -1]; +typedef int js_static_assert31[(__builtin_offsetof (JSPropertyDescriptor, getter) == __builtin_offsetof (PropertyDescriptor, getter)) ? 1 : -1]; +typedef int js_static_assert32[(__builtin_offsetof (JSPropertyDescriptor, setter) == __builtin_offsetof (PropertyDescriptor, setter)) ? 1 : -1]; +typedef int js_static_assert33[(__builtin_offsetof (JSPropertyDescriptor, value) == __builtin_offsetof (PropertyDescriptor, value)) ? 1 : -1]; +typedef int js_static_assert34[(__builtin_offsetof (JSPropertyDescriptor, shortid) == __builtin_offsetof (PropertyDescriptor, shortid)) ? 1 : -1]; +typedef int js_static_assert35[(sizeof(JSPropertyDescriptor) == sizeof(PropertyDescriptor)) ? 1 : -1]; +static __attribute__((always_inline)) inline JSClass * Jsvalify(Class *c) { return (JSClass *)c; } +static __attribute__((always_inline)) inline Class * Valueify(JSClass *c) { return (Class *)c; } +static __attribute__((always_inline)) inline JSPropertyDescriptor * Jsvalify(PropertyDescriptor *p) { return (JSPropertyDescriptor *) p; } +static __attribute__((always_inline)) inline PropertyDescriptor * Valueify(JSPropertyDescriptor *p) { return (PropertyDescriptor *) p; } +typedef js::Value ValueArgType; +static __attribute__((always_inline)) inline const Value & +ValueArgToConstRef(const Value &v) +{ + return v; +} +static __attribute__((always_inline)) inline void +MakeRangeGCSafe(Value *vec, size_t len) +{ + PodZero(vec, len); +} +static __attribute__((always_inline)) inline void +MakeRangeGCSafe(Value *beg, Value *end) +{ + PodZero(beg, end - beg); +} +static __attribute__((always_inline)) inline void +MakeRangeGCSafe(jsid *beg, jsid *end) +{ + for (jsid *id = beg; id != end; ++id) + *id = INT_TO_JSID(0); +} +static __attribute__((always_inline)) inline void +MakeRangeGCSafe(jsid *vec, size_t len) +{ + MakeRangeGCSafe(vec, vec + len); +} +static __attribute__((always_inline)) inline void +MakeRangeGCSafe(const Shape **beg, const Shape **end) +{ + PodZero(beg, end - beg); +} +static __attribute__((always_inline)) inline void +MakeRangeGCSafe(const Shape **vec, size_t len) +{ + PodZero(vec, len); +} +static __attribute__((always_inline)) inline void +SetValueRangeToUndefined(Value *beg, Value *end) +{ + for (Value *v = beg; v != end; ++v) + v->setUndefined(); +} +static __attribute__((always_inline)) inline void +SetValueRangeToUndefined(Value *vec, size_t len) +{ + SetValueRangeToUndefined(vec, vec + len); +} +static __attribute__((always_inline)) inline void +SetValueRangeToNull(Value *beg, Value *end) +{ + for (Value *v = beg; v != end; ++v) + v->setNull(); +} +static __attribute__((always_inline)) inline void +SetValueRangeToNull(Value *vec, size_t len) +{ + SetValueRangeToNull(vec, vec + len); +} +static __attribute__((always_inline)) inline void +Debug_SetValueRangeToCrashOnTouch(Value *beg, Value *end) +{ +} +static __attribute__((always_inline)) inline void +Debug_SetValueRangeToCrashOnTouch(Value *vec, size_t len) +{ +} +} +namespace js { +template +struct VectorImpl +{ + static inline void destroy(T *begin, T *end) { + for (T *p = begin; p != end; ++p) + p->~T(); + } + static inline void initialize(T *begin, T *end) { + for (T *p = begin; p != end; ++p) + new(p) T(); + } + template + static inline void copyConstruct(T *dst, const U *srcbeg, const U *srcend) { + for (const U *p = srcbeg; p != srcend; ++p, ++dst) + new(dst) T(*p); + } + template + static inline void copyConstructN(T *dst, size_t n, const U &u) { + for (T *end = dst + n; dst != end; ++dst) + new(dst) T(u); + } + static inline bool growTo(Vector &v, size_t newcap) { + ((void) 0); + T *newbuf = reinterpret_cast(v.malloc(newcap * sizeof(T))); + if (!newbuf) + return false; + for (T *dst = newbuf, *src = v.beginNoCheck(); src != v.endNoCheck(); ++dst, ++src) + new(dst) T(*src); + VectorImpl::destroy(v.beginNoCheck(), v.endNoCheck()); + v.free(v.mBegin); + v.mBegin = newbuf; + v.mCapacity = newcap; + return true; + } +}; +template +struct VectorImpl +{ + static inline void destroy(T *, T *) {} + static inline void initialize(T *begin, T *end) { + for (T *p = begin; p != end; ++p) + new(p) T(); + } + template + static inline void copyConstruct(T *dst, const U *srcbeg, const U *srcend) { + for (const U *p = srcbeg; p != srcend; ++p, ++dst) + *dst = *p; + } + static inline void copyConstructN(T *dst, size_t n, const T &t) { + for (T *p = dst, *end = dst + n; p != end; ++p) + *p = t; + } + static inline bool growTo(Vector &v, size_t newcap) { + ((void) 0); + size_t bytes = sizeof(T) * newcap; + T *newbuf = reinterpret_cast(v.realloc(v.mBegin, bytes)); + if (!newbuf) + return false; + v.mBegin = newbuf; + v.mCapacity = newcap; + return true; + } +}; +template +class Vector : AllocPolicy +{ + static const bool sElemIsPod = tl::IsPodType::result; + typedef VectorImpl Impl; + friend struct VectorImpl; + bool calculateNewCapacity(size_t curLength, size_t lengthInc, size_t &newCap); + bool growStorageBy(size_t lengthInc); + bool growHeapStorageBy(size_t lengthInc); + bool convertToHeapStorage(size_t lengthInc); + template inline bool growByImpl(size_t inc); + static const int sMaxInlineBytes = 1024; + static const size_t sInlineCapacity = + tl::Min::result; + static const size_t sInlineBytes = + tl::Max<1, sInlineCapacity * sizeof(T)>::result; + T *mBegin; + size_t mLength; + size_t mCapacity; + AlignedStorage storage; + Vector(const Vector &); + Vector &operator=(const Vector &); + bool usingInlineStorage() const { + return mBegin == (T *)storage.addr(); + } + T *beginNoCheck() const { + return mBegin; + } + T *endNoCheck() { + return mBegin + mLength; + } + const T *endNoCheck() const { + return mBegin + mLength; + } + public: + typedef T ElementType; + Vector(AllocPolicy = AllocPolicy()); + ~Vector(); + const AllocPolicy &allocPolicy() const { + return *this; + } + enum { InlineLength = N }; + size_t length() const { + return mLength; + } + bool empty() const { + return mLength == 0; + } + size_t capacity() const { + return mCapacity; + } + T *begin() const { + ((void) 0); + return mBegin; + } + T *end() { + ((void) 0); + return mBegin + mLength; + } + const T *end() const { + ((void) 0); + return mBegin + mLength; + } + T &operator[](size_t i) { + ((void) 0); + return begin()[i]; + } + const T &operator[](size_t i) const { + ((void) 0); + return begin()[i]; + } + T &back() { + ((void) 0); + return *(end() - 1); + } + const T &back() const { + ((void) 0); + return *(end() - 1); + } + bool reserve(size_t capacity); + void shrinkBy(size_t incr); + bool growBy(size_t incr); + bool resize(size_t newLength); + bool growByUninitialized(size_t incr); + bool resizeUninitialized(size_t newLength); + void clear(); + bool append(const T &t); + bool appendN(const T &t, size_t n); + template bool append(const U *begin, const U *end); + template bool append(const U *begin, size_t length); + template bool append(const Vector &other); + void popBack(); + T popCopy(); + T *extractRawBuffer(); + void replaceRawBuffer(T *p, size_t length); + bool insert(T *p, const T &val); + void erase(T *t); +}; +template +__attribute__((always_inline)) inline +Vector::Vector(AllocPolicy ap) + : AllocPolicy(ap), mBegin((T *)storage.addr()), mLength(0), + mCapacity(sInlineCapacity) +{} +template +__attribute__((always_inline)) inline +Vector::~Vector() +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + Impl::destroy(beginNoCheck(), endNoCheck()); + if (!usingInlineStorage()) + this->free(beginNoCheck()); +} +template +inline + bool +Vector::calculateNewCapacity(size_t curLength, size_t lengthInc, + size_t &newCap) +{ + size_t newMinCap = curLength + lengthInc; + if (newMinCap < curLength || + newMinCap & tl::MulOverflowMask<2 * sizeof(T)>::result) { + this->reportAllocOverflow(); + return false; + } + newCap = RoundUpPow2(newMinCap); + if (newCap & tl::UnsafeRangeSizeMask::result) { + this->reportAllocOverflow(); + return false; + } + return true; +} +template +__attribute__((always_inline)) inline + bool +Vector::growHeapStorageBy(size_t lengthInc) +{ + ((void) 0); + size_t newCap; + return calculateNewCapacity(mLength, lengthInc, newCap) && + Impl::growTo(*this, newCap); +} +template +inline + bool +Vector::convertToHeapStorage(size_t lengthInc) +{ + ((void) 0); + size_t newCap; + if (!calculateNewCapacity(mLength, lengthInc, newCap)) + return false; + T *newBuf = reinterpret_cast(this->malloc(newCap * sizeof(T))); + if (!newBuf) + return false; + Impl::copyConstruct(newBuf, beginNoCheck(), endNoCheck()); + Impl::destroy(beginNoCheck(), endNoCheck()); + mBegin = newBuf; + mCapacity = newCap; + return true; +} +template +__attribute__((noinline)) + bool +Vector::growStorageBy(size_t incr) +{ + ((void) 0); + return usingInlineStorage() + ? convertToHeapStorage(incr) + : growHeapStorageBy(incr); +} +template +inline + bool +Vector::reserve(size_t request) +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + if (request > mCapacity) + return growStorageBy(request - mLength); + return true; +} +template +inline void +Vector::shrinkBy(size_t incr) +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + ((void) 0); + Impl::destroy(endNoCheck() - incr, endNoCheck()); + mLength -= incr; +} +template +template +__attribute__((always_inline)) inline + bool +Vector::growByImpl(size_t incr) +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + if (incr > mCapacity - mLength && !growStorageBy(incr)) + return false; + ((void) 0); + T *newend = endNoCheck() + incr; + if (InitNewElems) + Impl::initialize(endNoCheck(), newend); + mLength += incr; + return true; +} +template +__attribute__((always_inline)) inline + bool +Vector::growBy(size_t incr) +{ + return growByImpl(incr); +} +template +__attribute__((always_inline)) inline + bool +Vector::growByUninitialized(size_t incr) +{ + return growByImpl(incr); +} +template +inline + bool +Vector::resize(size_t newLength) +{ + size_t curLength = mLength; + if (newLength > curLength) + return growBy(newLength - curLength); + shrinkBy(curLength - newLength); + return true; +} +template +__attribute__((always_inline)) inline + bool +Vector::resizeUninitialized(size_t newLength) +{ + size_t curLength = mLength; + if (newLength > curLength) + return growByUninitialized(newLength - curLength); + shrinkBy(curLength - newLength); + return true; +} +template +inline void +Vector::clear() +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + Impl::destroy(beginNoCheck(), endNoCheck()); + mLength = 0; +} +template +__attribute__((always_inline)) inline + bool +Vector::append(const T &t) +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + if (mLength == mCapacity && !growStorageBy(1)) + return false; + ((void) 0); + new(endNoCheck()) T(t); + ++mLength; + return true; +} +template +__attribute__((always_inline)) inline + bool +Vector::appendN(const T &t, size_t needed) +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + if (mLength + needed > mCapacity && !growStorageBy(needed)) + return false; + ((void) 0); + Impl::copyConstructN(endNoCheck(), needed, t); + mLength += needed; + return true; +} +template +inline + bool +Vector::insert(T *p, const T &val) +{ + ((void) 0); + size_t pos = p - begin(); + ((void) 0); + size_t oldLength = mLength; + if (pos == oldLength) + return append(val); + { + T oldBack = back(); + if (!append(oldBack)) + return false; + } + for (size_t i = oldLength; i > pos; --i) + (*this)[i] = (*this)[i - 1]; + (*this)[pos] = val; + return true; +} +template +inline void +Vector::erase(T *it) +{ + ((void) 0); + while (it + 1 != end()) { + *it = *(it + 1); + ++it; + } + popBack(); +} +template +template +__attribute__((always_inline)) inline + bool +Vector::append(const U *insBegin, const U *insEnd) +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + size_t needed = PointerRangeSize(insBegin, insEnd); + if (mLength + needed > mCapacity && !growStorageBy(needed)) + return false; + ((void) 0); + Impl::copyConstruct(endNoCheck(), insBegin, insEnd); + mLength += needed; + return true; +} +template +template +inline + bool +Vector::append(const Vector &other) +{ + return append(other.begin(), other.end()); +} +template +template +__attribute__((always_inline)) inline + bool +Vector::append(const U *insBegin, size_t length) +{ + return this->append(insBegin, insBegin + length); +} +template +__attribute__((always_inline)) inline void +Vector::popBack() +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + ((void) 0); + --mLength; + endNoCheck()->~T(); +} +template +__attribute__((always_inline)) inline T +Vector::popCopy() +{ + T ret = back(); + popBack(); + return ret; +} +template +inline T * +Vector::extractRawBuffer() +{ + T *ret; + if (usingInlineStorage()) { + ret = reinterpret_cast(this->malloc(mLength * sizeof(T))); + if (!ret) + return __null; + Impl::copyConstruct(ret, beginNoCheck(), endNoCheck()); + Impl::destroy(beginNoCheck(), endNoCheck()); + mLength = 0; + } else { + ret = mBegin; + mBegin = (T *)storage.addr(); + mLength = 0; + mCapacity = sInlineCapacity; + } + return ret; +} +template +inline void +Vector::replaceRawBuffer(T *p, size_t length) +{ + ReentrancyGuard g(*this); ((void) 0); ((void) 0); + Impl::destroy(beginNoCheck(), endNoCheck()); + if (!usingInlineStorage()) + this->free(beginNoCheck()); + if (length <= sInlineCapacity) { + mBegin = (T *)storage.addr(); + mLength = length; + mCapacity = sInlineCapacity; + Impl::copyConstruct(mBegin, p, p + length); + Impl::destroy(p, p + length); + this->free(p); + } else { + mBegin = p; + mLength = length; + mCapacity = length; + } +} +} +struct JSCompartment; +namespace js { +namespace gc { +template struct Arena; +struct ArenaBitmap; +struct MarkingDelay; +struct Chunk; +struct FreeCell; +struct Cell { + static const size_t CellShift = 3; + static const size_t CellSize = size_t(1) << CellShift; + static const size_t CellMask = CellSize - 1; + inline Arena *arena() const; + inline Chunk *chunk() const; + inline ArenaBitmap *bitmap() const; + __attribute__((always_inline)) inline size_t cellIndex() const; + __attribute__((always_inline)) inline bool isMarked(uint32 color) const; + __attribute__((always_inline)) inline bool markIfUnmarked(uint32 color) const; + __attribute__((always_inline)) inline void unmark(uint32 color) const; + inline JSCompartment *compartment() const; + __attribute__((always_inline)) inline js::gc::Cell *asCell() { return this; } + __attribute__((always_inline)) inline js::gc::FreeCell *asFreeCell() { + return reinterpret_cast(this); + } +}; +struct FreeCell : Cell { + union { + FreeCell *link; + double data; + }; +}; +typedef int js_static_assert36[(sizeof(FreeCell) == 8) ? 1 : -1]; +} +} +namespace js { +class JSProxyHandler; +class AutoPropDescArrayRooter; +namespace mjit { +class Compiler; +} +static inline PropertyOp +CastAsPropertyOp(JSObject *object) +{ + return (__extension__ (PropertyOp) (size_t) (object)); +} +static inline StrictPropertyOp +CastAsStrictPropertyOp(JSObject *object) +{ + return (__extension__ (StrictPropertyOp) (size_t) (object)); +} +static inline JSPropertyOp +CastAsJSPropertyOp(JSObject *object) +{ + return (__extension__ (JSPropertyOp) (size_t) (object)); +} +static inline JSStrictPropertyOp +CastAsJSStrictPropertyOp(JSObject *object) +{ + return (__extension__ (JSStrictPropertyOp) (size_t) (object)); +} +inline JSObject * +CastAsObject(PropertyOp op) +{ + return (__extension__ (JSObject *) (size_t) (op)); +} +inline JSObject * +CastAsObject(StrictPropertyOp op) +{ + return (__extension__ (JSObject *) (size_t) (op)); +} +inline Value +CastAsObjectJsval(PropertyOp op) +{ + return ObjectOrNullValue(CastAsObject(op)); +} +inline Value +CastAsObjectJsval(StrictPropertyOp op) +{ + return ObjectOrNullValue(CastAsObject(op)); +} +} +struct PropDesc { + friend class js::AutoPropDescArrayRooter; + PropDesc(); + public: + bool initialize(JSContext* cx, jsid id, const js::Value &v); + bool isAccessorDescriptor() const { + return hasGet || hasSet; + } + bool isDataDescriptor() const { + return hasValue || hasWritable; + } + bool isGenericDescriptor() const { + return !isAccessorDescriptor() && !isDataDescriptor(); + } + bool configurable() const { + return (attrs & 0x04) == 0; + } + bool enumerable() const { + return (attrs & 0x01) != 0; + } + bool writable() const { + return (attrs & 0x02) == 0; + } + JSObject* getterObject() const { + return get.isUndefined() ? __null : &get.toObject(); + } + JSObject* setterObject() const { + return set.isUndefined() ? __null : &set.toObject(); + } + const js::Value &getterValue() const { + return get; + } + const js::Value &setterValue() const { + return set; + } + js::PropertyOp getter() const { + return js::CastAsPropertyOp(getterObject()); + } + js::StrictPropertyOp setter() const { + return js::CastAsStrictPropertyOp(setterObject()); + } + js::Value pd; + jsid id; + js::Value value, get, set; + uint8 attrs; + bool hasGet : 1; + bool hasSet : 1; + bool hasValue : 1; + bool hasWritable : 1; + bool hasEnumerable : 1; + bool hasConfigurable : 1; +}; +namespace js { +typedef Vector PropDescArray; +} +struct JSObjectMap { + uint32 shape; + uint32 slotSpan; + static __attribute__((visibility ("default"))) const JSObjectMap sharedNonNative; + explicit JSObjectMap(uint32 shape) : shape(shape), slotSpan(0) {} + JSObjectMap(uint32 shape, uint32 slotSpan) : shape(shape), slotSpan(slotSpan) {} + enum { INVALID_SHAPE = 0x8fffffff, SHAPELESS = 0xffffffff }; + bool isNative() const { return this != &sharedNonNative; } + private: + JSObjectMap(JSObjectMap &); + void operator=(JSObjectMap &); +}; +extern __attribute__((visibility ("default"))) JSBool +js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, + JSProperty **propp); +extern JSBool +js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, const js::Value *value, + js::PropertyOp getter, js::StrictPropertyOp setter, uintN attrs); +extern JSBool +js_GetProperty(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, js::Value *vp); +inline JSBool +js_GetProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *vp) +{ + return js_GetProperty(cx, obj, obj, id, vp); +} +namespace js { +extern JSBool +GetPropertyDefault(JSContext *cx, JSObject *obj, jsid id, const Value &def, Value *vp); +} +extern JSBool +js_SetProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *vp, JSBool strict); +extern JSBool +js_GetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp); +extern JSBool +js_SetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp); +extern JSBool +js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *rval, JSBool strict); +extern __attribute__((visibility ("default"))) JSBool +js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, + js::Value *statep, jsid *idp); +extern JSType +js_TypeOf(JSContext *cx, JSObject *obj); +namespace js { +struct NativeIterator; +} +struct JSFunction; +namespace nanojit { +class ValidateWriter; +} +struct JSObject : js::gc::Cell { + friend class js::TraceRecorder; + friend class nanojit::ValidateWriter; + friend class GetPropCompiler; + union { + js::Shape *lastProp; + JSObjectMap *map; + }; + js::Class *clasp; + private: + inline void setLastProperty(const js::Shape *shape); + inline void removeLastProperty(); + public: + inline const js::Shape *lastProperty() const; + inline js::Shape **nativeSearch(jsid id, bool adding = false); + inline const js::Shape *nativeLookup(jsid id); + inline bool nativeContains(jsid id); + inline bool nativeContains(const js::Shape &shape); + enum { + DELEGATE = 0x01, + SYSTEM = 0x02, + NOT_EXTENSIBLE = 0x04, + BRANDED = 0x08, + GENERIC = 0x10, + METHOD_BARRIER = 0x20, + INDEXED = 0x40, + OWN_SHAPE = 0x80, + BOUND_FUNCTION = 0x100, + HAS_EQUALITY = 0x200, + METHOD_THRASH_COUNT_MASK = 0xc00, + METHOD_THRASH_COUNT_SHIFT = 10, + METHOD_THRASH_COUNT_MAX = METHOD_THRASH_COUNT_MASK >> METHOD_THRASH_COUNT_SHIFT + }; + enum { + NSLOTS_BITS = 29, + NSLOTS_LIMIT = ((JSUint32)1 << (NSLOTS_BITS)) + }; + uint32 flags; + uint32 objShape; + js::EmptyShape **emptyShapes; + JSObject *proto; + JSObject *parent; + void *privateData; + jsuword capacity; + js::Value *slots; + inline bool canProvideEmptyShape(js::Class *clasp); + inline js::EmptyShape *getEmptyShape(JSContext *cx, js::Class *aclasp, + unsigned kind); + bool isNative() const { return map->isNative(); } + js::Class *getClass() const { return clasp; } + JSClass *getJSClass() const { return Jsvalify(clasp); } + bool hasClass(const js::Class *c) const { + return c == clasp; + } + const js::ObjectOps *getOps() const { + return &getClass()->ops; + } + inline void trace(JSTracer *trc); + uint32 shape() const { + ((void) 0); + return objShape; + } + bool isDelegate() const { return !!(flags & DELEGATE); } + void setDelegate() { flags |= DELEGATE; } + void clearDelegate() { flags &= ~DELEGATE; } + bool isBoundFunction() const { return !!(flags & BOUND_FUNCTION); } + static void setDelegateNullSafe(JSObject *obj) { + if (obj) + obj->setDelegate(); + } + bool isSystem() const { return !!(flags & SYSTEM); } + void setSystem() { flags |= SYSTEM; } + bool branded() { return !!(flags & BRANDED); } + bool brand(JSContext *cx); + bool unbrand(JSContext *cx); + bool generic() { return !!(flags & GENERIC); } + void setGeneric() { flags |= GENERIC; } + uintN getMethodThrashCount() const { + return (flags & METHOD_THRASH_COUNT_MASK) >> METHOD_THRASH_COUNT_SHIFT; + } + void setMethodThrashCount(uintN count) { + ((void) 0); + flags = (flags & ~METHOD_THRASH_COUNT_MASK) | (count << METHOD_THRASH_COUNT_SHIFT); + } + bool hasSpecialEquality() const { return !!(flags & HAS_EQUALITY); } + void assertSpecialEqualitySynced() const { + ((void) 0); + } + inline void syncSpecialEquality(); + private: + void generateOwnShape(JSContext *cx); + void setOwnShape(uint32 s) { flags |= OWN_SHAPE; objShape = s; } + void clearOwnShape() { flags &= ~OWN_SHAPE; objShape = map->shape; } + public: + inline bool nativeEmpty() const; + bool hasOwnShape() const { return !!(flags & OWN_SHAPE); } + void setMap(const JSObjectMap *amap) { + ((void) 0); + map = const_cast(amap); + objShape = map->shape; + } + void setSharedNonNativeMap() { + setMap(&JSObjectMap::sharedNonNative); + } + void deletingShapeChange(JSContext *cx, const js::Shape &shape); + const js::Shape *methodShapeChange(JSContext *cx, const js::Shape &shape); + bool methodShapeChange(JSContext *cx, uint32 slot); + void protoShapeChange(JSContext *cx); + void shadowingShapeChange(JSContext *cx, const js::Shape &shape); + bool globalObjectOwnShapeChange(JSContext *cx); + void watchpointOwnShapeChange(JSContext *cx) { generateOwnShape(cx); } + void extensibleShapeChange(JSContext *cx) { + generateOwnShape(cx); + } + bool hasMethodBarrier() { return !!(flags & METHOD_BARRIER); } + void setMethodBarrier() { flags |= METHOD_BARRIER; } + bool brandedOrHasMethodBarrier() { return !!(flags & (BRANDED | METHOD_BARRIER)); } + const js::Shape *methodReadBarrier(JSContext *cx, const js::Shape &shape, js::Value *vp); + const js::Shape *methodWriteBarrier(JSContext *cx, const js::Shape &shape, const js::Value &v); + bool methodWriteBarrier(JSContext *cx, uint32 slot, const js::Value &v); + bool isIndexed() const { return !!(flags & INDEXED); } + void setIndexed() { flags |= INDEXED; } + inline bool inDictionaryMode() const; + inline uint32 propertyCount() const; + inline bool hasPropertyTable() const; + unsigned finalizeKind() const; + uint32 numSlots() const { return capacity; } + size_t slotsAndStructSize(uint32 nslots) const; + size_t slotsAndStructSize() const { return slotsAndStructSize(numSlots()); } + inline js::Value* fixedSlots() const; + inline size_t numFixedSlots() const; + static inline size_t getFixedSlotOffset(size_t slot); + public: + static const uint32 SLOT_CAPACITY_MIN = 8; + bool allocSlots(JSContext *cx, size_t nslots); + bool growSlots(JSContext *cx, size_t nslots); + void shrinkSlots(JSContext *cx, size_t nslots); + bool ensureSlots(JSContext *cx, size_t nslots) { + if (numSlots() < nslots) + return growSlots(cx, nslots); + return true; + } + bool ensureInstanceReservedSlots(JSContext *cx, size_t nreserved); + js::Value *getSlots() const { + return slots; + } + bool ensureClassReservedSlotsForEmptyObject(JSContext *cx); + inline bool ensureClassReservedSlots(JSContext *cx); + uint32 slotSpan() const { return map->slotSpan; } + bool containsSlot(uint32 slot) const { return slot < slotSpan(); } + js::Value& getSlotRef(uintN slot) { + ((void) 0); + return slots[slot]; + } + js::Value &nativeGetSlotRef(uintN slot) { + ((void) 0); + ((void) 0); + return getSlotRef(slot); + } + const js::Value &getSlot(uintN slot) const { + ((void) 0); + return slots[slot]; + } + const js::Value &nativeGetSlot(uintN slot) const { + ((void) 0); + ((void) 0); + return getSlot(slot); + } + void setSlot(uintN slot, const js::Value &value) { + ((void) 0); + slots[slot] = value; + } + void nativeSetSlot(uintN slot, const js::Value &value) { + ((void) 0); + ((void) 0); + return setSlot(slot, value); + } + inline js::Value getReservedSlot(uintN index) const; + inline void updateShape(JSContext *cx); + inline void updateFlags(const js::Shape *shape, bool isDefinitelyAtom = false); + inline void extend(JSContext *cx, const js::Shape *shape, bool isDefinitelyAtom = false); + JSObject *getProto() const { return proto; } + void clearProto() { proto = __null; } + void setProto(JSObject *newProto) { + setDelegateNullSafe(newProto); + proto = newProto; + } + JSObject *getParent() const { + return parent; + } + void clearParent() { + parent = __null; + } + void setParent(JSObject *newParent) { + setDelegateNullSafe(newParent); + parent = newParent; + } + __attribute__((visibility ("default"))) JSObject * getGlobal() const; + bool isGlobal() const { + return !!(getClass()->flags & (1<<((8 + 8)+2))); + } + void *getPrivate() const { + ((void) 0); + return privateData; + } + void setPrivate(void *data) { + ((void) 0); + privateData = data; + } + private: + enum ImmutabilityType { SEAL, FREEZE }; + bool sealOrFreeze(JSContext *cx, ImmutabilityType it); + public: + bool isExtensible() const { return !(flags & NOT_EXTENSIBLE); } + bool preventExtensions(JSContext *cx, js::AutoIdVector *props); + inline bool seal(JSContext *cx) { return sealOrFreeze(cx, SEAL); } + bool freeze(JSContext *cx) { return sealOrFreeze(cx, FREEZE); } + private: + static const uint32 JSSLOT_PRIMITIVE_THIS = 0; + public: + inline const js::Value &getPrimitiveThis() const; + inline void setPrimitiveThis(const js::Value &pthis); + inline uint32 getArrayLength() const; + inline void setArrayLength(uint32 length); + inline uint32 getDenseArrayCapacity(); + inline js::Value* getDenseArrayElements(); + inline const js::Value &getDenseArrayElement(uintN idx); + inline js::Value* addressOfDenseArrayElement(uintN idx); + inline void setDenseArrayElement(uintN idx, const js::Value &val); + inline void shrinkDenseArrayElements(JSContext *cx, uintN cap); + enum EnsureDenseResult { ED_OK, ED_FAILED, ED_SPARSE }; + inline EnsureDenseResult ensureDenseArrayElements(JSContext *cx, uintN index, uintN extra); + bool willBeSparseDenseArray(uintN requiredCapacity, uintN newElementsHint); + JSBool makeDenseArraySlow(JSContext *cx); + private: + static const uint32 JSSLOT_ARGS_DATA = 1; + public: + static const uint32 JSSLOT_ARGS_LENGTH = 0; + static const uint32 ARGS_CLASS_RESERVED_SLOTS = 2; + static const uint32 ARGS_FIRST_FREE_SLOT = ARGS_CLASS_RESERVED_SLOTS + 1; + static const uint32 ARGS_LENGTH_OVERRIDDEN_BIT = 0x1; + static const uint32 ARGS_PACKED_BITS_COUNT = 1; + inline void setArgsLength(uint32 argc); + inline uint32 getArgsInitialLength() const; + inline void setArgsLengthOverridden(); + inline bool isArgsLengthOverridden() const; + inline js::ArgumentsData *getArgsData() const; + inline void setArgsData(js::ArgumentsData *data); + inline const js::Value &getArgsCallee() const; + inline void setArgsCallee(const js::Value &callee); + inline const js::Value &getArgsElement(uint32 i) const; + inline js::Value *getArgsElements() const; + inline js::Value *addressOfArgsElement(uint32 i); + inline void setArgsElement(uint32 i, const js::Value &v); + private: + static const uint32 JSSLOT_CALL_CALLEE = 0; + static const uint32 JSSLOT_CALL_ARGUMENTS = 1; + public: + static const uint32 CALL_RESERVED_SLOTS = 2; + inline bool callIsForEval() const; + inline JSStackFrame *maybeCallObjStackFrame() const; + inline JSObject *getCallObjCallee() const; + inline JSFunction *getCallObjCalleeFunction() const; + inline void setCallObjCallee(JSObject *callee); + inline const js::Value &getCallObjArguments() const; + inline void setCallObjArguments(const js::Value &v); + inline const js::Value &callObjArg(uintN i) const; + inline js::Value &callObjArg(uintN i); + inline const js::Value &callObjVar(uintN i) const; + inline js::Value &callObjVar(uintN i); + static const uint32 JSSLOT_DATE_UTC_TIME = 0; + static const uint32 JSSLOT_DATE_COMPONENTS_START = 1; + static const uint32 JSSLOT_DATE_LOCAL_TIME = 1; + static const uint32 JSSLOT_DATE_LOCAL_YEAR = 2; + static const uint32 JSSLOT_DATE_LOCAL_MONTH = 3; + static const uint32 JSSLOT_DATE_LOCAL_DATE = 4; + static const uint32 JSSLOT_DATE_LOCAL_DAY = 5; + static const uint32 JSSLOT_DATE_LOCAL_HOURS = 6; + static const uint32 JSSLOT_DATE_LOCAL_MINUTES = 7; + static const uint32 JSSLOT_DATE_LOCAL_SECONDS = 8; + static const uint32 DATE_CLASS_RESERVED_SLOTS = 9; + inline const js::Value &getDateUTCTime() const; + inline void setDateUTCTime(const js::Value &pthis); + private: + friend struct JSFunction; + friend class js::mjit::Compiler; + static const uint32 JSSLOT_FLAT_CLOSURE_UPVARS = 0; + static const uint32 JSSLOT_FUN_METHOD_ATOM = 0; + static const uint32 JSSLOT_FUN_METHOD_OBJ = 1; + static const uint32 JSSLOT_BOUND_FUNCTION_THIS = 0; + static const uint32 JSSLOT_BOUND_FUNCTION_ARGS_COUNT = 1; + public: + static const uint32 FUN_CLASS_RESERVED_SLOTS = 2; + inline JSFunction *getFunctionPrivate() const; + inline js::Value *getFlatClosureUpvars() const; + inline js::Value getFlatClosureUpvar(uint32 i) const; + inline js::Value &getFlatClosureUpvar(uint32 i); + inline void setFlatClosureUpvars(js::Value *upvars); + inline bool hasMethodObj(const JSObject& obj) const; + inline void setMethodObj(JSObject& obj); + inline bool initBoundFunction(JSContext *cx, const js::Value &thisArg, + const js::Value *args, uintN argslen); + inline JSObject *getBoundFunctionTarget() const; + inline const js::Value &getBoundFunctionThis() const; + inline const js::Value *getBoundFunctionArguments(uintN &argslen) const; + private: + static const uint32 JSSLOT_REGEXP_LAST_INDEX = 0; + public: + static const uint32 REGEXP_CLASS_RESERVED_SLOTS = 1; + inline const js::Value &getRegExpLastIndex() const; + inline void setRegExpLastIndex(const js::Value &v); + inline void setRegExpLastIndex(jsdouble d); + inline void zeroRegExpLastIndex(); + inline js::NativeIterator *getNativeIterator() const; + inline void setNativeIterator(js::NativeIterator *); + inline JSScript *getScript() const; + private: + static const uint32 JSSLOT_NAME_PREFIX = 0; + static const uint32 JSSLOT_NAME_URI = 1; + static const uint32 JSSLOT_NAMESPACE_DECLARED = 2; + static const uint32 JSSLOT_QNAME_LOCAL_NAME = 2; + public: + static const uint32 NAMESPACE_CLASS_RESERVED_SLOTS = 3; + static const uint32 QNAME_CLASS_RESERVED_SLOTS = 3; + inline JSLinearString *getNamePrefix() const; + inline jsval getNamePrefixVal() const; + inline void setNamePrefix(JSLinearString *prefix); + inline void clearNamePrefix(); + inline JSLinearString *getNameURI() const; + inline jsval getNameURIVal() const; + inline void setNameURI(JSLinearString *uri); + inline jsval getNamespaceDeclared() const; + inline void setNamespaceDeclared(jsval decl); + inline JSLinearString *getQNameLocalName() const; + inline jsval getQNameLocalNameVal() const; + inline void setQNameLocalName(JSLinearString *name); + inline js::JSProxyHandler *getProxyHandler() const; + inline const js::Value &getProxyPrivate() const; + inline void setProxyPrivate(const js::Value &priv); + inline const js::Value &getProxyExtra() const; + inline void setProxyExtra(const js::Value &extra); + inline JSObject *getWithThis() const; + inline void setWithThis(JSObject *thisp); + inline bool isCallable(); + void init(JSContext *cx, js::Class *aclasp, JSObject *proto, JSObject *parent, + void *priv, bool useHoles); + inline void finish(JSContext *cx); + __attribute__((always_inline)) inline void finalize(JSContext *cx); + inline bool initSharingEmptyShape(JSContext *cx, + js::Class *clasp, + JSObject *proto, + JSObject *parent, + void *priv, + unsigned kind); + inline bool hasSlotsArray() const; + inline void freeSlotsArray(JSContext *cx); + inline void revertToFixedSlots(JSContext *cx); + inline bool hasProperty(JSContext *cx, jsid id, bool *foundp, uintN flags = 0); + bool allocSlot(JSContext *cx, uint32 *slotp); + bool freeSlot(JSContext *cx, uint32 slot); + public: + bool reportReadOnly(JSContext* cx, jsid id, uintN report = 0x0); + bool reportNotConfigurable(JSContext* cx, jsid id, uintN report = 0x0); + bool reportNotExtensible(JSContext *cx, uintN report = 0x0); + private: + js::Shape *getChildProperty(JSContext *cx, js::Shape *parent, js::Shape &child); + const js::Shape *addPropertyInternal(JSContext *cx, jsid id, + js::PropertyOp getter, js::StrictPropertyOp setter, + uint32 slot, uintN attrs, + uintN flags, intN shortid, + js::Shape **spp); + bool toDictionaryMode(JSContext *cx); + public: + const js::Shape *addProperty(JSContext *cx, jsid id, + js::PropertyOp getter, js::StrictPropertyOp setter, + uint32 slot, uintN attrs, + uintN flags, intN shortid); + const js::Shape *addDataProperty(JSContext *cx, jsid id, uint32 slot, uintN attrs) { + ((void) 0); + return addProperty(cx, id, __null, __null, slot, attrs, 0, 0); + } + const js::Shape *putProperty(JSContext *cx, jsid id, + js::PropertyOp getter, js::StrictPropertyOp setter, + uint32 slot, uintN attrs, + uintN flags, intN shortid); + const js::Shape *changeProperty(JSContext *cx, const js::Shape *shape, uintN attrs, uintN mask, + js::PropertyOp getter, js::StrictPropertyOp setter); + bool removeProperty(JSContext *cx, jsid id); + void clear(JSContext *cx); + JSBool lookupProperty(JSContext *cx, jsid id, JSObject **objp, JSProperty **propp) { + js::LookupPropOp op = getOps()->lookupProperty; + return (op ? op : js_LookupProperty)(cx, this, id, objp, propp); + } + JSBool defineProperty(JSContext *cx, jsid id, const js::Value &value, + js::PropertyOp getter = js::PropertyStub, + js::StrictPropertyOp setter = js::StrictPropertyStub, + uintN attrs = 0x01) { + js::DefinePropOp op = getOps()->defineProperty; + return (op ? op : js_DefineProperty)(cx, this, id, &value, getter, setter, attrs); + } + JSBool getProperty(JSContext *cx, JSObject *receiver, jsid id, js::Value *vp) { + js::PropertyIdOp op = getOps()->getProperty; + return (op ? op : (js::PropertyIdOp)js_GetProperty)(cx, this, receiver, id, vp); + } + JSBool getProperty(JSContext *cx, jsid id, js::Value *vp) { + return getProperty(cx, this, id, vp); + } + JSBool setProperty(JSContext *cx, jsid id, js::Value *vp, JSBool strict) { + js::StrictPropertyIdOp op = getOps()->setProperty; + return (op ? op : js_SetProperty)(cx, this, id, vp, strict); + } + JSBool getAttributes(JSContext *cx, jsid id, uintN *attrsp) { + js::AttributesOp op = getOps()->getAttributes; + return (op ? op : js_GetAttributes)(cx, this, id, attrsp); + } + JSBool setAttributes(JSContext *cx, jsid id, uintN *attrsp) { + js::AttributesOp op = getOps()->setAttributes; + return (op ? op : js_SetAttributes)(cx, this, id, attrsp); + } + JSBool deleteProperty(JSContext *cx, jsid id, js::Value *rval, JSBool strict) { + js::DeleteIdOp op = getOps()->deleteProperty; + return (op ? op : js_DeleteProperty)(cx, this, id, rval, strict); + } + JSBool enumerate(JSContext *cx, JSIterateOp iterop, js::Value *statep, jsid *idp) { + js::NewEnumerateOp op = getOps()->enumerate; + return (op ? op : js_Enumerate)(cx, this, iterop, statep, idp); + } + JSType typeOf(JSContext *cx) { + js::TypeOfOp op = getOps()->typeOf; + return (op ? op : js_TypeOf)(cx, this); + } + JSObject *thisObject(JSContext *cx) { + JSObjectOp op = getOps()->thisObject; + return op ? op(cx, this) : this; + } + static bool thisObject(JSContext *cx, const js::Value &v, js::Value *vp); + inline JSCompartment *getCompartment() const; + inline JSObject *getThrowTypeError() const; + __attribute__((visibility ("default"))) JSObject * clone(JSContext *cx, JSObject *proto, JSObject *parent); + __attribute__((visibility ("default"))) bool copyPropertiesFrom(JSContext *cx, JSObject *obj); + bool swap(JSContext *cx, JSObject *other); + const js::Shape *defineBlockVariable(JSContext *cx, jsid id, intN index); + inline bool canHaveMethodBarrier() const; + inline bool isArguments() const; + inline bool isNormalArguments() const; + inline bool isStrictArguments() const; + inline bool isArray() const; + inline bool isDenseArray() const; + inline bool isSlowArray() const; + inline bool isNumber() const; + inline bool isBoolean() const; + inline bool isString() const; + inline bool isPrimitive() const; + inline bool isDate() const; + inline bool isFunction() const; + inline bool isObject() const; + inline bool isWith() const; + inline bool isBlock() const; + inline bool isStaticBlock() const; + inline bool isClonedBlock() const; + inline bool isCall() const; + inline bool isRegExp() const; + inline bool isScript() const; + inline bool isXML() const; + inline bool isXMLId() const; + inline bool isNamespace() const; + inline bool isQName() const; + inline bool isProxy() const; + inline bool isObjectProxy() const; + inline bool isFunctionProxy() const; + __attribute__((visibility ("default"))) bool isWrapper() const; + __attribute__((visibility ("default"))) JSObject * unwrap(uintN *flagsp = __null); + inline void initArrayClass(); +}; +typedef int js_static_assert37[(sizeof(JSObject) % sizeof(js::Value) == 0) ? 1 : -1]; +inline js::Value* +JSObject::fixedSlots() const { + return (js::Value*) (jsuword(this) + sizeof(JSObject)); +} +inline + bool +JSObject::hasSlotsArray() const { return this->slots != fixedSlots(); } + inline size_t +JSObject::getFixedSlotOffset(size_t slot) { + return sizeof(JSObject) + (slot * sizeof(js::Value)); +} +struct JSObject_Slots2 : JSObject { js::Value fslots[2]; }; +struct JSObject_Slots4 : JSObject { js::Value fslots[4]; }; +struct JSObject_Slots8 : JSObject { js::Value fslots[8]; }; +struct JSObject_Slots12 : JSObject { js::Value fslots[12]; }; +struct JSObject_Slots16 : JSObject { js::Value fslots[16]; }; +inline void +OBJ_TO_INNER_OBJECT(JSContext *cx, JSObject *&obj) +{ + if (JSObjectOp op = obj->getClass()->ext.innerObject) + obj = op(cx, obj); +} +inline void +OBJ_TO_OUTER_OBJECT(JSContext *cx, JSObject *&obj) +{ + if (JSObjectOp op = obj->getClass()->ext.outerObject) + obj = op(cx, obj); +} +class JSValueArray { + public: + jsval *array; + size_t length; + JSValueArray(jsval *v, size_t c) : array(v), length(c) {} +}; +class ValueArray { + public: + js::Value *array; + size_t length; + ValueArray(js::Value *v, size_t c) : array(v), length(c) {} +}; +extern js::Class js_ObjectClass; +extern js::Class js_WithClass; +extern js::Class js_BlockClass; +inline bool JSObject::isObject() const { return getClass() == &js_ObjectClass; } +inline bool JSObject::isWith() const { return getClass() == &js_WithClass; } +inline bool JSObject::isBlock() const { return getClass() == &js_BlockClass; } +static const uint32 JSSLOT_BLOCK_DEPTH = 0; +static const uint32 JSSLOT_BLOCK_FIRST_FREE_SLOT = JSSLOT_BLOCK_DEPTH + 1; +inline + bool +JSObject::isStaticBlock() const +{ + return isBlock() && !getProto(); +} +inline + bool +JSObject::isClonedBlock() const +{ + return isBlock() && !!getProto(); +} +static const uint32 JSSLOT_WITH_THIS = 1; +extern JSObject * +js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth); +inline JSObject * +js_UnwrapWithObject(JSContext *cx, JSObject *withobj) +{ + ((void) 0); + return withobj->getProto(); +} +extern JSObject * +js_NewBlockObject(JSContext *cx); +extern JSObject * +js_CloneBlockObject(JSContext *cx, JSObject *proto, JSStackFrame *fp); +extern JSBool +js_PutBlockObject(JSContext *cx, JSBool normalUnwind); +JSBool +js_XDRBlockObject(JSXDRState *xdr, JSObject **objp); +struct JSSharpObjectMap { + jsrefcount depth; + jsatomid sharpgen; + JSHashTable *table; +}; +extern JSHashEntry * +js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap, + jschar **sp); +extern void +js_LeaveSharpObject(JSContext *cx, JSIdArray **idap); +extern void +js_TraceSharpMap(JSTracer *trc, JSSharpObjectMap *map); +extern JSBool +js_HasOwnPropertyHelper(JSContext *cx, js::LookupPropOp lookup, uintN argc, + js::Value *vp); +extern JSBool +js_HasOwnProperty(JSContext *cx, js::LookupPropOp lookup, JSObject *obj, jsid id, + JSObject **objp, JSProperty **propp); +extern JSBool +js_NewPropertyDescriptorObject(JSContext *cx, jsid id, uintN attrs, + const js::Value &getter, const js::Value &setter, + const js::Value &value, js::Value *vp); +extern JSBool +js_PropertyIsEnumerable(JSContext *cx, JSObject *obj, jsid id, js::Value *vp); +__attribute__((visibility ("default"))) JSBool js_obj_defineGetter(JSContext *cx, uintN argc, js::Value *vp); +__attribute__((visibility ("default"))) JSBool js_obj_defineSetter(JSContext *cx, uintN argc, js::Value *vp); +extern JSObject * +js_InitObjectClass(JSContext *cx, JSObject *obj); +namespace js { +JSObject * +DefineConstructorAndPrototype(JSContext *cx, JSObject *obj, JSProtoKey key, JSAtom *atom, + JSObject *protoProto, Class *clasp, + Native constructor, uintN nargs, + JSPropertySpec *ps, JSFunctionSpec *fs, + JSPropertySpec *static_ps, JSFunctionSpec *static_fs); +} +extern JSObject * +js_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, + js::Class *clasp, js::Native constructor, uintN nargs, + JSPropertySpec *ps, JSFunctionSpec *fs, + JSPropertySpec *static_ps, JSFunctionSpec *static_fs); +extern const char js_watch_str[]; +extern const char js_unwatch_str[]; +extern const char js_hasOwnProperty_str[]; +extern const char js_isPrototypeOf_str[]; +extern const char js_propertyIsEnumerable_str[]; +extern const char js_defineGetter_str[]; +extern const char js_defineSetter_str[]; +extern const char js_lookupGetter_str[]; +extern const char js_lookupSetter_str[]; +extern JSBool +js_PopulateObject(JSContext *cx, JSObject *newborn, JSObject *props); +extern JSBool +js_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, + JSObject **objp); +extern JSBool +js_SetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, + JSObject *cobj, JSObject *prototype); +extern JSBool +js_FindClassObject(JSContext *cx, JSObject *start, JSProtoKey key, + js::Value *vp, js::Class *clasp = __null); +extern JSObject * +js_ConstructObject(JSContext *cx, js::Class *clasp, JSObject *proto, + JSObject *parent, uintN argc, js::Value *argv); +extern JSObject * +js_CreateThisForFunctionWithProto(JSContext *cx, JSObject *callee, JSObject *proto); +extern JSObject * +js_CreateThisForFunction(JSContext *cx, JSObject *callee); +extern JSObject * +js_CreateThis(JSContext *cx, JSObject *callee); +extern jsid +js_CheckForStringIndex(jsid id); +extern void +js_PurgeScopeChainHelper(JSContext *cx, JSObject *obj, jsid id); +inline void +js_PurgeScopeChain(JSContext *cx, JSObject *obj, jsid id) +{ + if (obj->isDelegate()) + js_PurgeScopeChainHelper(cx, obj, id); +} +extern const js::Shape * +js_AddNativeProperty(JSContext *cx, JSObject *obj, jsid id, + js::PropertyOp getter, js::StrictPropertyOp setter, uint32 slot, + uintN attrs, uintN flags, intN shortid); +extern const js::Shape * +js_ChangeNativePropertyAttrs(JSContext *cx, JSObject *obj, + const js::Shape *shape, uintN attrs, uintN mask, + js::PropertyOp getter, js::StrictPropertyOp setter); +extern JSBool +js_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, + const js::Value &descriptor, JSBool *bp); +const uintN JSDNP_CACHE_RESULT = 1; +const uintN JSDNP_DONT_PURGE = 2; +const uintN JSDNP_SET_METHOD = 4; +const uintN JSDNP_UNQUALIFIED = 8; +extern JSBool +js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, const js::Value &value, + js::PropertyOp getter, js::StrictPropertyOp setter, uintN attrs, + uintN flags, intN shortid, JSProperty **propp, + uintN defineHow = 0); +extern int +js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags, + JSObject **objp, JSProperty **propp); +extern __attribute__((visibility ("default"))) js::Class js_CallClass; +extern __attribute__((visibility ("default"))) js::Class js_DeclEnvClass; +namespace js { +static inline + bool +IsCacheableNonGlobalScope(JSObject *obj) +{ + ((void) 0); + js::Class *clasp = obj->getClass(); + bool cacheable = (clasp == &js_CallClass || + clasp == &js_BlockClass || + clasp == &js_DeclEnvClass); + ((void) 0); + return cacheable; +} +} +extern js::PropertyCacheEntry * +js_FindPropertyHelper(JSContext *cx, jsid id, JSBool cacheResult, + JSObject **objp, JSObject **pobjp, JSProperty **propp); +extern __attribute__((visibility ("default"))) JSBool +js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp, + JSProperty **propp); +extern JSObject * +js_FindIdentifierBase(JSContext *cx, JSObject *scopeChain, jsid id); +extern JSObject * +js_FindVariableScope(JSContext *cx, JSFunction **funp); +const uintN JSGET_CACHE_RESULT = 1; +const uintN JSGET_METHOD_BARRIER = 0; +const uintN JSGET_NO_METHOD_BARRIER = 2; +extern JSBool +js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const js::Shape *shape, uintN getHow, + js::Value *vp); +extern JSBool +js_NativeSet(JSContext *cx, JSObject *obj, const js::Shape *shape, bool added, + bool strict, js::Value *vp); +extern JSBool +js_GetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, uint32 getHow, js::Value *vp); +extern + bool +js_GetPropertyHelperWithShape(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, + uint32 getHow, js::Value *vp, + const js::Shape **shapeOut, JSObject **holderOut); +extern JSBool +js_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, js::Value *vp); +extern JSBool +js_GetMethod(JSContext *cx, JSObject *obj, jsid id, uintN getHow, js::Value *vp); +extern __attribute__((visibility ("default"))) bool +js_CheckUndeclaredVarAssignment(JSContext *cx, JSString *propname); +extern JSBool +js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, uintN defineHow, + js::Value *vp, JSBool strict); +extern JSBool +js_SetNativeAttributes(JSContext *cx, JSObject *obj, js::Shape *shape, + uintN attrs); +namespace js { +extern JSObject * +HasNativeMethod(JSObject *obj, jsid methodid, Native native); +extern + bool +DefaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp); +extern JSBool +CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, + js::Value *vp, uintN *attrsp); +} +extern + bool +js_IsDelegate(JSContext *cx, JSObject *obj, const js::Value &v); +extern __attribute__((visibility ("default"))) JSBool +js_GetClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey, + JSObject **protop, js::Class *clasp = __null); +extern JSBool +js_SetClassPrototype(JSContext *cx, JSObject *ctor, JSObject *proto, + uintN attrs); +extern JSBool +js_PrimitiveToObject(JSContext *cx, js::Value *vp); +extern JSBool +js_ValueToObjectOrNull(JSContext *cx, const js::Value &v, JSObject **objp); +namespace js { +extern JSObject * +ToObjectSlow(JSContext *cx, js::Value *vp); +__attribute__((always_inline)) inline JSObject * +ToObject(JSContext *cx, js::Value *vp) +{ + if (vp->isObject()) + return &vp->toObject(); + return ToObjectSlow(cx, vp); +} +} +extern JSObject * +js_ValueToNonNullObject(JSContext *cx, const js::Value &v); +extern JSBool +js_TryValueOf(JSContext *cx, JSObject *obj, JSType type, js::Value *rval); +extern JSBool +js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom, + uintN argc, js::Value *argv, js::Value *rval); +extern JSBool +js_XDRObject(JSXDRState *xdr, JSObject **objp); +extern void +js_TraceObject(JSTracer *trc, JSObject *obj); +extern void +js_PrintObjectSlotName(JSTracer *trc, char *buf, size_t bufsize); +extern void +js_ClearNative(JSContext *cx, JSObject *obj); +extern + bool +js_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, js::Value *vp); +extern + bool +js_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, const js::Value &v); +extern JSBool +js_CheckPrincipalsAccess(JSContext *cx, JSObject *scopeobj, + JSPrincipals *principals, JSAtom *caller); +extern JSBool +js_CheckContentSecurityPolicy(JSContext *cx, JSObject *scopeObj); +extern const char * +js_ComputeFilename(JSContext *cx, JSStackFrame *caller, + JSPrincipals *principals, uintN *linenop); +extern JSBool +js_ReportGetterOnlyAssignment(JSContext *cx); +extern __attribute__((visibility ("default"))) JSBool +js_GetterOnlyPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp); +extern uintN +js_InferFlags(JSContext *cx, uintN defaultFlags); +JSBool +js_Object(JSContext *cx, uintN argc, js::Value *vp); +namespace js { +extern + bool +SetProto(JSContext *cx, JSObject *obj, JSObject *proto, bool checkForCycles); +extern JSString * +obj_toStringHelper(JSContext *cx, JSObject *obj); +enum EvalType { INDIRECT_EVAL, DIRECT_EVAL }; +extern + bool +EvalKernel(JSContext *cx, uintN argc, js::Value *vp, EvalType evalType, JSStackFrame *caller, + JSObject *scopeobj); +extern __attribute__((visibility ("default"))) bool +IsBuiltinEvalFunction(JSFunction *fun); +} +enum { + UNIT_STRING_LIMIT = 256U, + SMALL_CHAR_LIMIT = 128U, + NUM_SMALL_CHARS = 64U, + INT_STRING_LIMIT = 256U, + NUM_HUNDRED_STRINGS = 156U +}; +extern jschar * +js_GetDependentStringChars(JSString *str); +extern JSString * +js_ConcatStrings(JSContext *cx, JSString *left, JSString *right); +typedef int js_static_assert38[((8 * 8) >= 32) ? 1 : -1]; +struct JSRopeBufferInfo { + size_t capacity; +}; +namespace js { namespace mjit { + class Compiler; +}} +struct JSLinearString; +struct JSString +{ + friend class js::TraceRecorder; + friend class js::mjit::Compiler; + friend JSAtom *js_AtomizeString(JSContext *cx, JSString *str, uintN flags); + size_t lengthAndFlags; + union { + const jschar *chars; + JSString *left; + } u; + union { + jschar inlineStorage[4]; + struct { + union { + JSString *right; + JSString *base; + size_t capacity; + }; + union { + JSString *parent; + size_t reserved; + }; + } s; + size_t externalStringType; + }; + static const size_t TYPE_FLAGS_MASK = (((JSUint32)1 << (4)) - 1); + static const size_t LENGTH_SHIFT = 4; + static const size_t TYPE_MASK = (((JSUint32)1 << (2)) - 1); + static const size_t FLAT = 0x0; + static const size_t DEPENDENT = 0x1; + static const size_t ROPE = 0x2; + static const size_t DEPENDENT_BIT = ((JSUint32)1 << (0)); + static const size_t ROPE_BIT = ((JSUint32)1 << (1)); + static const size_t ATOMIZED = ((JSUint32)1 << (2)); + static const size_t EXTENSIBLE = ((JSUint32)1 << (3)); + size_t buildLengthAndFlags(size_t length, size_t flags) { + return (length << LENGTH_SHIFT) | flags; + } + inline js::gc::Cell *asCell() { + return reinterpret_cast(this); + } + inline js::gc::FreeCell *asFreeCell() { + return reinterpret_cast(this); + } + static const size_t MAX_LENGTH = (1 << 28) - 1; + __attribute__((always_inline)) inline bool isDependent() const { + return lengthAndFlags & DEPENDENT_BIT; + } + __attribute__((always_inline)) inline bool isFlat() const { + return (lengthAndFlags & TYPE_MASK) == FLAT; + } + __attribute__((always_inline)) inline bool isExtensible() const { + ((void) 0); + return lengthAndFlags & EXTENSIBLE; + } + __attribute__((always_inline)) inline bool isAtomized() const { + ((void) 0); + return lengthAndFlags & ATOMIZED; + } + __attribute__((always_inline)) inline bool isRope() const { + return lengthAndFlags & ROPE_BIT; + } + __attribute__((always_inline)) inline size_t length() const { + return lengthAndFlags >> LENGTH_SHIFT; + } + __attribute__((always_inline)) inline bool empty() const { + return lengthAndFlags <= TYPE_FLAGS_MASK; + } + __attribute__((always_inline)) inline const jschar *getChars(JSContext *cx) { + if (isRope()) + return flatten(cx); + return nonRopeChars(); + } + __attribute__((always_inline)) inline const jschar *getCharsZ(JSContext *cx) { + if (!isFlat()) + return undepend(cx); + return flatChars(); + } + __attribute__((always_inline)) inline void initFlatNotTerminated(jschar *chars, size_t length) { + ((void) 0); + ((void) 0); + lengthAndFlags = buildLengthAndFlags(length, FLAT); + u.chars = chars; + } + __attribute__((always_inline)) inline void initFlat(jschar *chars, size_t length) { + initFlatNotTerminated(chars, length); + ((void) 0); + } + __attribute__((always_inline)) inline void initShortString(const jschar *chars, size_t length) { + ((void) 0); + ((void) 0); + ((void) 0); + lengthAndFlags = buildLengthAndFlags(length, FLAT); + u.chars = chars; + } + __attribute__((always_inline)) inline void initFlatExtensible(jschar *chars, size_t length, size_t cap) { + ((void) 0); + ((void) 0); + ((void) 0); + lengthAndFlags = buildLengthAndFlags(length, FLAT | EXTENSIBLE); + u.chars = chars; + s.capacity = cap; + } + __attribute__((always_inline)) inline JSFlatString *assertIsFlat() { + ((void) 0); + return reinterpret_cast(this); + } + __attribute__((always_inline)) inline const jschar *flatChars() const { + ((void) 0); + return u.chars; + } + __attribute__((always_inline)) inline size_t flatLength() const { + ((void) 0); + return length(); + } + inline void flatSetAtomized() { + ((void) 0); + ((void) 0); + lengthAndFlags |= ATOMIZED; + } + inline void flatClearExtensible() { + ((void) 0); + if (lengthAndFlags & EXTENSIBLE) + lengthAndFlags &= ~EXTENSIBLE; + } + inline void initDependent(JSString *base, const jschar *chars, size_t length) { + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + lengthAndFlags = buildLengthAndFlags(length, DEPENDENT); + u.chars = chars; + s.base = base; + } + inline JSLinearString *dependentBase() const { + ((void) 0); + return s.base->assertIsLinear(); + } + __attribute__((always_inline)) inline const jschar *dependentChars() { + ((void) 0); + return u.chars; + } + inline size_t dependentLength() const { + ((void) 0); + return length(); + } + const jschar *undepend(JSContext *cx); + const jschar *nonRopeChars() const { + ((void) 0); + return u.chars; + } + inline void initRopeNode(JSString *left, JSString *right, size_t length) { + ((void) 0); + lengthAndFlags = buildLengthAndFlags(length, ROPE); + u.left = left; + s.right = right; + } + inline JSString *ropeLeft() const { + ((void) 0); + return u.left; + } + inline JSString *ropeRight() const { + ((void) 0); + return s.right; + } + inline void finishTraversalConversion(JSString *base, const jschar *baseBegin, const jschar *end) { + ((void) 0); + lengthAndFlags = buildLengthAndFlags(end - u.chars, DEPENDENT); + s.base = base; + } + const jschar *flatten(JSContext *maybecx); + JSLinearString *ensureLinear(JSContext *cx) { + if (isRope() && !flatten(cx)) + return __null; + return reinterpret_cast(this); + } + bool isLinear() const { + return !isRope(); + } + JSLinearString *assertIsLinear() { + ((void) 0); + return reinterpret_cast(this); + } + typedef uint8 SmallChar; + static inline bool fitsInSmallChar(jschar c) { + return c < SMALL_CHAR_LIMIT && toSmallChar[c] != INVALID_SMALL_CHAR; + } + static inline bool isUnitString(void *ptr) { + jsuword delta = reinterpret_cast(ptr) - + reinterpret_cast(unitStringTable); + if (delta >= UNIT_STRING_LIMIT * sizeof(JSString)) + return false; + ((void) 0); + return true; + } + static inline bool isLength2String(void *ptr) { + jsuword delta = reinterpret_cast(ptr) - + reinterpret_cast(length2StringTable); + if (delta >= NUM_SMALL_CHARS * NUM_SMALL_CHARS * sizeof(JSString)) + return false; + ((void) 0); + return true; + } + static inline bool isHundredString(void *ptr) { + jsuword delta = reinterpret_cast(ptr) - + reinterpret_cast(hundredStringTable); + if (delta >= NUM_HUNDRED_STRINGS * sizeof(JSString)) + return false; + ((void) 0); + return true; + } + static inline bool isStatic(void *ptr) { + return isUnitString(ptr) || isLength2String(ptr) || isHundredString(ptr); + } + static const SmallChar INVALID_SMALL_CHAR = -1; + static const jschar fromSmallChar[]; + static const SmallChar toSmallChar[]; + static const JSString unitStringTable[]; + static const JSString length2StringTable[]; + static const JSString hundredStringTable[]; + static const JSString *const intStringTable[]; + static JSFlatString *unitString(jschar c); + static JSLinearString *getUnitString(JSContext *cx, JSString *str, size_t index); + static JSFlatString *length2String(jschar c1, jschar c2); + static JSFlatString *length2String(uint32 i); + static JSFlatString *intString(jsint i); + static JSFlatString *lookupStaticString(const jschar *chars, size_t length); + __attribute__((always_inline)) inline void finalize(JSContext *cx); + static size_t offsetOfLengthAndFlags() { + return __builtin_offsetof (JSString, lengthAndFlags); + } + static size_t offsetOfChars() { + return __builtin_offsetof (JSString, u.chars); + } + static void staticAsserts() { + typedef int js_static_assert39[(((JSString::MAX_LENGTH << JSString::LENGTH_SHIFT) >> JSString::LENGTH_SHIFT) == JSString::MAX_LENGTH) ? 1 : -1] + ; + } +}; +struct JSLinearString : JSString +{ + const jschar *chars() const { return JSString::nonRopeChars(); } +}; +typedef int js_static_assert40[(sizeof(JSLinearString) == sizeof(JSString)) ? 1 : -1]; +struct JSFlatString : JSLinearString +{ + const jschar *charsZ() const { return chars(); } +}; +typedef int js_static_assert41[(sizeof(JSFlatString) == sizeof(JSString)) ? 1 : -1]; +struct JSAtom : JSFlatString +{ +}; +struct JSExternalString : JSString +{ + static const uintN TYPE_LIMIT = 8; + static JSStringFinalizeOp str_finalizers[TYPE_LIMIT]; + static intN changeFinalizer(JSStringFinalizeOp oldop, + JSStringFinalizeOp newop) { + for (uintN i = 0; i != (sizeof (str_finalizers) / sizeof (str_finalizers)[0]); i++) { + if (str_finalizers[i] == oldop) { + str_finalizers[i] = newop; + return intN(i); + } + } + return -1; + } + void finalize(JSContext *cx); + void finalize(); +}; +typedef int js_static_assert42[(sizeof(JSString) == sizeof(JSExternalString)) ? 1 : -1]; +class JSShortString : public js::gc::Cell +{ + JSString mHeader; + JSString mDummy; + public: + inline jschar *init(size_t length) { + ((void) 0); + mHeader.initShortString(mHeader.inlineStorage, length); + return mHeader.inlineStorage; + } + inline jschar *getInlineStorageBeforeInit() { + return mHeader.inlineStorage; + } + inline void initAtOffsetInBuffer(jschar *p, size_t length) { + ((void) 0); + mHeader.initShortString(p, length); + } + inline void resetLength(size_t length) { + mHeader.initShortString(mHeader.flatChars(), length); + } + inline JSString *header() { + return &mHeader; + } + static const size_t FREE_STRING_WORDS = 2; + static const size_t MAX_SHORT_STRING_LENGTH = + ((sizeof(JSString) + FREE_STRING_WORDS * sizeof(size_t)) / sizeof(jschar)) - 1; + static inline bool fitsIntoShortString(size_t length) { + return length <= MAX_SHORT_STRING_LENGTH; + } + __attribute__((always_inline)) inline void finalize(JSContext *cx); + static void staticAsserts() { + typedef int js_static_assert43[(__builtin_offsetof (JSString, inlineStorage) == sizeof(JSString) - JSShortString::FREE_STRING_WORDS * sizeof(void *)) ? 1 : -1] + ; + typedef int js_static_assert44[(__builtin_offsetof (JSShortString, mDummy) == sizeof(JSString)) ? 1 : -1]; + typedef int js_static_assert45[(__builtin_offsetof (JSString, inlineStorage) + sizeof(jschar) * (JSShortString::MAX_SHORT_STRING_LENGTH + 1) == sizeof(JSShortString)) ? 1 : -1] + ; + } +}; +namespace js { +class StringBuffer; +class StringSegmentRange; +class MutatingRopeSegmentRange; +class RopeBuilder; +} +extern const jschar * +js_GetStringChars(JSContext *cx, JSString *str); +extern const jschar * +js_UndependString(JSContext *cx, JSString *str); +extern JSBool +js_MakeStringImmutable(JSContext *cx, JSString *str); +extern JSString * +js_toLowerCase(JSContext *cx, JSString *str); +extern JSString * +js_toUpperCase(JSContext *cx, JSString *str); +struct JSSubString { + size_t length; + const jschar *chars; +}; +extern jschar js_empty_ucstr[]; +extern JSSubString js_EmptySubString; +extern const uint8 js_X[]; +extern const uint8 js_Y[]; +extern const uint32 js_A[]; +typedef enum JSCharType { + JSCT_UNASSIGNED = 0, + JSCT_UPPERCASE_LETTER = 1, + JSCT_LOWERCASE_LETTER = 2, + JSCT_TITLECASE_LETTER = 3, + JSCT_MODIFIER_LETTER = 4, + JSCT_OTHER_LETTER = 5, + JSCT_NON_SPACING_MARK = 6, + JSCT_ENCLOSING_MARK = 7, + JSCT_COMBINING_SPACING_MARK = 8, + JSCT_DECIMAL_DIGIT_NUMBER = 9, + JSCT_LETTER_NUMBER = 10, + JSCT_OTHER_NUMBER = 11, + JSCT_SPACE_SEPARATOR = 12, + JSCT_LINE_SEPARATOR = 13, + JSCT_PARAGRAPH_SEPARATOR = 14, + JSCT_CONTROL = 15, + JSCT_FORMAT = 16, + JSCT_PRIVATE_USE = 18, + JSCT_SURROGATE = 19, + JSCT_DASH_PUNCTUATION = 20, + JSCT_START_PUNCTUATION = 21, + JSCT_END_PUNCTUATION = 22, + JSCT_CONNECTOR_PUNCTUATION = 23, + JSCT_OTHER_PUNCTUATION = 24, + JSCT_MATH_SYMBOL = 25, + JSCT_CURRENCY_SYMBOL = 26, + JSCT_MODIFIER_SYMBOL = 27, + JSCT_OTHER_SYMBOL = 28 +} JSCharType; +extern const bool js_alnum[]; +const jschar BYTE_ORDER_MARK = 0xFEFF; +const jschar NO_BREAK_SPACE = 0x00A0; +static inline + bool +JS_ISSPACE(jschar c) +{ + unsigned w = c; + if (w < 256) + return (w <= ' ' && (w == ' ' || (9 <= w && w <= 0xD))) || w == NO_BREAK_SPACE; + return w == BYTE_ORDER_MARK || ((js_A[js_Y[(js_X[(uint16)(w)>>6]<<6)|((w)&0x3F)]]) & 0x00070000) == 0x00040000; +} +extern js::Class js_StringClass; +inline + bool +JSObject::isString() const +{ + return getClass() == &js_StringClass; +} +extern JSObject * +js_InitStringClass(JSContext *cx, JSObject *obj); +extern const char js_escape_str[]; +extern const char js_unescape_str[]; +extern const char js_uneval_str[]; +extern const char js_decodeURI_str[]; +extern const char js_encodeURI_str[]; +extern const char js_decodeURIComponent_str[]; +extern const char js_encodeURIComponent_str[]; +extern JSFlatString * +js_NewString(JSContext *cx, jschar *chars, size_t length); +extern JSLinearString * +js_NewDependentString(JSContext *cx, JSString *base, size_t start, + size_t length); +extern JSFlatString * +js_NewStringCopyN(JSContext *cx, const jschar *s, size_t n); +extern JSFlatString * +js_NewStringCopyN(JSContext *cx, const char *s, size_t n); +extern JSFlatString * +js_NewStringCopyZ(JSContext *cx, const jschar *s); +extern JSFlatString * +js_NewStringCopyZ(JSContext *cx, const char *s); +extern const char * +js_ValueToPrintable(JSContext *cx, const js::Value &, + JSAutoByteString *bytes, bool asSource = false); +extern JSString * +js_ValueToString(JSContext *cx, const js::Value &v); +namespace js { +static __attribute__((always_inline)) inline JSString * +ValueToString_TestForStringInline(JSContext *cx, const Value &v) +{ + if (v.isString()) + return v.toString(); + return js_ValueToString(cx, v); +} +extern + bool +ValueToStringBuffer(JSContext *cx, const Value &v, StringBuffer &sb); +} +extern __attribute__((visibility ("default"))) JSString * +js_ValueToSource(JSContext *cx, const js::Value &v); +inline uint32 +js_HashString(JSLinearString *str) +{ + const jschar *s = str->chars(); + size_t n = str->length(); + uint32 h; + for (h = 0; n; s++, n--) + h = (((h) << (4)) | ((h) >> (32 - (4)))) ^ *s; + return h; +} +namespace js { +extern + bool +EqualStrings(JSContext *cx, JSString *str1, JSString *str2, JSBool *result); +extern + bool +EqualStrings(JSLinearString *str1, JSLinearString *str2); +extern + bool +CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32 *result); +extern + bool +StringEqualsAscii(JSLinearString *str, const char *asciiBytes); +} +static const jsuint sBMHCharSetSize = 256; +static const jsuint sBMHPatLenMax = 255; +static const jsint sBMHBadPattern = -2; +extern jsint +js_BoyerMooreHorspool(const jschar *text, jsuint textlen, + const jschar *pat, jsuint patlen); +extern size_t +js_strlen(const jschar *s); +extern jschar * +js_strchr(const jschar *s, jschar c); +extern jschar * +js_strchr_limit(const jschar *s, jschar c, const jschar *limit); +inline void +js_short_strncpy(jschar *dest, const jschar *src, size_t num) +{ + ((void) 0); + for (size_t i = 0; i < num; i++) + dest[i] = src[i]; +} +static inline const jschar * +js_SkipWhiteSpace(const jschar *s, const jschar *end) +{ + ((void) 0); + while (s != end && JS_ISSPACE(*s)) + s++; + return s; +} +extern jschar * +js_InflateString(JSContext *cx, const char *bytes, size_t *length); +extern char * +js_DeflateString(JSContext *cx, const jschar *chars, size_t length); +extern JSBool +js_InflateStringToBuffer(JSContext *cx, const char *bytes, size_t length, + jschar *chars, size_t *charsLength); +extern JSBool +js_InflateUTF8StringToBuffer(JSContext *cx, const char *bytes, size_t length, + jschar *chars, size_t *charsLength); +extern size_t +js_GetDeflatedStringLength(JSContext *cx, const jschar *chars, + size_t charsLength); +extern size_t +js_GetDeflatedUTF8StringLength(JSContext *cx, const jschar *chars, + size_t charsLength); +extern JSBool +js_DeflateStringToBuffer(JSContext *cx, const jschar *chars, + size_t charsLength, char *bytes, size_t *length); +extern JSBool +js_DeflateStringToUTF8Buffer(JSContext *cx, const jschar *chars, + size_t charsLength, char *bytes, size_t *length); +extern JSBool +js_str_escape(JSContext *cx, uintN argc, js::Value *argv, js::Value *rval); +namespace js { +extern JSBool +str_replace(JSContext *cx, uintN argc, js::Value *vp); +} +extern JSBool +js_str_toString(JSContext *cx, uintN argc, js::Value *vp); +extern JSBool +js_str_charAt(JSContext *cx, uintN argc, js::Value *vp); +extern JSBool +js_str_charCodeAt(JSContext *cx, uintN argc, js::Value *vp); +extern int +js_OneUcs4ToUtf8Char(uint8 *utf8Buffer, uint32 ucs4Char); +namespace js { +extern size_t +PutEscapedStringImpl(char *buffer, size_t size, FILE *fp, JSLinearString *str, uint32 quote); +inline size_t +PutEscapedString(char *buffer, size_t size, JSLinearString *str, uint32 quote) +{ + size_t n = PutEscapedStringImpl(buffer, size, __null, str, quote); + ((void) 0); + return n; +} +inline + bool +FileEscapedString(FILE *fp, JSLinearString *str, uint32 quote) +{ + return PutEscapedStringImpl(__null, 0, fp, str, quote) != size_t(-1); +} +} +extern JSBool +js_String(JSContext *cx, uintN argc, js::Value *vp); +static __attribute__((always_inline)) inline jsid +JSID_FROM_BITS(size_t bits) +{ + jsid id; + (id) = bits; + return id; +} +static __attribute__((always_inline)) inline jsid +ATOM_TO_JSID(JSAtom *atom) +{ + ((void) 0); + return JSID_FROM_BITS((size_t)atom); +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_ATOM(jsid id) +{ + return JSID_IS_STRING(id); +} +static __attribute__((always_inline)) inline JSBool +JSID_IS_ATOM(jsid id, JSAtom *atom) +{ + return (id) == (ATOM_TO_JSID(atom)); +} +static __attribute__((always_inline)) inline JSAtom * +JSID_TO_ATOM(jsid id) +{ + return (JSAtom *)JSID_TO_STRING(id); +} +namespace js { +static __attribute__((always_inline)) inline Value +IdToValue(jsid id) +{ + if (JSID_IS_STRING(id)) + return StringValue(JSID_TO_STRING(id)); + if ((__builtin_expect((JSID_IS_INT(id)), 1))) + return Int32Value(JSID_TO_INT(id)); + if ((__builtin_expect((JSID_IS_OBJECT(id)), 1))) + return ObjectValue(*JSID_TO_OBJECT(id)); + ((void) 0); + return UndefinedValue(); +} +static __attribute__((always_inline)) inline jsval +IdToJsval(jsid id) +{ + return Jsvalify(IdToValue(id)); +} +} +extern const char * +js_AtomToPrintableString(JSContext *cx, JSAtom *atom, JSAutoByteString *bytes); +struct JSAtomListElement { + JSHashEntry entry; +}; +struct JSAtomSet { + JSHashEntry *list; + JSHashTable *table; + jsuint count; +}; +struct JSAtomList : public JSAtomSet +{ + JSAtomList() { + list = __null; table = __null; count = 0; + } + JSAtomList(const JSAtomSet& as) { + list = as.list; table = as.table; count = as.count; + } + void clear() { ((void) 0); list = __null; table = __null; count = 0; } + JSAtomListElement *lookup(JSAtom *atom) { + JSHashEntry **hep; + return rawLookup(atom, hep); + } + JSAtomListElement *rawLookup(JSAtom *atom, JSHashEntry **&hep); + enum AddHow { UNIQUE, SHADOW, HOIST }; + JSAtomListElement *add(js::Parser *parser, JSAtom *atom, AddHow how = UNIQUE); + void remove(js::Parser *parser, JSAtom *atom) { + JSHashEntry **hep; + JSAtomListElement *ale = rawLookup(atom, hep); + if (ale) + rawRemove(parser, ale, hep); + } + void rawRemove(js::Parser *parser, JSAtomListElement *ale, JSHashEntry **hep); +}; +struct JSAutoAtomList: public JSAtomList +{ + JSAutoAtomList(js::Parser *p): parser(p) {} + ~JSAutoAtomList(); + private: + js::Parser *parser; +}; +class JSAtomListIterator { + JSAtomList* list; + JSAtomListElement* next; + uint32 index; + public: + JSAtomListIterator(JSAtomList* al) : list(al) { reset(); } + void reset() { + next = (JSAtomListElement *) list->list; + index = 0; + } + JSAtomListElement* operator ()(); +}; +struct JSAtomMap { + JSAtom **vector; + jsatomid length; +}; +namespace js { +typedef int js_static_assert46[(((size_t)(0x1 | 0x2)) < JS_GCTHING_ALIGN) ? 1 : -1]; +typedef uintptr_t AtomEntryType; +static __attribute__((always_inline)) inline JSAtom * +AtomEntryToKey(AtomEntryType entry) +{ + ((void) 0); + return (JSAtom *)(entry & ~((size_t)(0x1 | 0x2))); +} +struct AtomHasher +{ + typedef JSLinearString *Lookup; + static HashNumber hash(JSLinearString *str) { + return js_HashString(str); + } + static bool match(AtomEntryType entry, JSLinearString *lookup) { + return entry ? EqualStrings(AtomEntryToKey(entry), lookup) : false; + } +}; +typedef HashSet AtomSet; +} +struct JSAtomState +{ + js::AtomSet atoms; + JSThinLock lock; + JSAtom *emptyAtom; + JSAtom *booleanAtoms[2]; + JSAtom *typeAtoms[JSTYPE_LIMIT]; + JSAtom *nullAtom; + JSAtom *classAtoms[JSProto_LIMIT]; + JSAtom *anonymousAtom; + JSAtom *applyAtom; + JSAtom *argumentsAtom; + JSAtom *arityAtom; + JSAtom *callAtom; + JSAtom *calleeAtom; + JSAtom *callerAtom; + JSAtom *classPrototypeAtom; + JSAtom *constructorAtom; + JSAtom *eachAtom; + JSAtom *evalAtom; + JSAtom *fileNameAtom; + JSAtom *getAtom; + JSAtom *globalAtom; + JSAtom *ignoreCaseAtom; + JSAtom *indexAtom; + JSAtom *inputAtom; + JSAtom *toISOStringAtom; + JSAtom *iteratorAtom; + JSAtom *joinAtom; + JSAtom *lastIndexAtom; + JSAtom *lengthAtom; + JSAtom *lineNumberAtom; + JSAtom *messageAtom; + JSAtom *multilineAtom; + JSAtom *nameAtom; + JSAtom *nextAtom; + JSAtom *noSuchMethodAtom; + JSAtom *objectNullAtom; + JSAtom *objectUndefinedAtom; + JSAtom *protoAtom; + JSAtom *setAtom; + JSAtom *sourceAtom; + JSAtom *stackAtom; + JSAtom *stickyAtom; + JSAtom *toGMTStringAtom; + JSAtom *toLocaleStringAtom; + JSAtom *toSourceAtom; + JSAtom *toStringAtom; + JSAtom *toUTCStringAtom; + JSAtom *valueOfAtom; + JSAtom *toJSONAtom; + JSAtom *void0Atom; + JSAtom *enumerableAtom; + JSAtom *configurableAtom; + JSAtom *writableAtom; + JSAtom *valueAtom; + JSAtom *testAtom; + JSAtom *useStrictAtom; + JSAtom *locAtom; + JSAtom *lineAtom; + JSAtom *InfinityAtom; + JSAtom *NaNAtom; + JSAtom *builderAtom; + JSAtom *etagoAtom; + JSAtom *namespaceAtom; + JSAtom *ptagcAtom; + JSAtom *qualifierAtom; + JSAtom *spaceAtom; + JSAtom *stagoAtom; + JSAtom *starAtom; + JSAtom *starQualifierAtom; + JSAtom *tagcAtom; + JSAtom *xmlAtom; + JSAtom *functionNamespaceURIAtom; + JSAtom *ProxyAtom; + JSAtom *getOwnPropertyDescriptorAtom; + JSAtom *getPropertyDescriptorAtom; + JSAtom *definePropertyAtom; + JSAtom *deleteAtom; + JSAtom *getOwnPropertyNamesAtom; + JSAtom *enumerateAtom; + JSAtom *fixAtom; + JSAtom *hasAtom; + JSAtom *hasOwnAtom; + JSAtom *keysAtom; + JSAtom *iterateAtom; + struct { + JSAtom *XMLListAtom; + JSAtom *decodeURIAtom; + JSAtom *decodeURIComponentAtom; + JSAtom *defineGetterAtom; + JSAtom *defineSetterAtom; + JSAtom *encodeURIAtom; + JSAtom *encodeURIComponentAtom; + JSAtom *escapeAtom; + JSAtom *hasOwnPropertyAtom; + JSAtom *isFiniteAtom; + JSAtom *isNaNAtom; + JSAtom *isPrototypeOfAtom; + JSAtom *isXMLNameAtom; + JSAtom *lookupGetterAtom; + JSAtom *lookupSetterAtom; + JSAtom *parseFloatAtom; + JSAtom *parseIntAtom; + JSAtom *propertyIsEnumerableAtom; + JSAtom *unescapeAtom; + JSAtom *unevalAtom; + JSAtom *unwatchAtom; + JSAtom *watchAtom; + } lazy; +}; +extern const char *const js_common_atom_names[]; +extern const size_t js_common_atom_count; +extern const char js_Null_str[]; +extern const char js_Object_str[]; +extern const char js_Function_str[]; +extern const char js_Array_str[]; +extern const char js_Boolean_str[]; +extern const char js_JSON_str[]; +extern const char js_Date_str[]; +extern const char js_Math_str[]; +extern const char js_Number_str[]; +extern const char js_String_str[]; +extern const char js_RegExp_str[]; +extern const char js_XML_str[]; +extern const char js_Namespace_str[]; +extern const char js_QName_str[]; +extern const char js_Reflect_str[]; +extern const char js_ASTNode_str[]; +extern const char js_Error_str[]; +extern const char js_InternalError_str[]; +extern const char js_EvalError_str[]; +extern const char js_RangeError_str[]; +extern const char js_ReferenceError_str[]; +extern const char js_SyntaxError_str[]; +extern const char js_TypeError_str[]; +extern const char js_URIError_str[]; +extern const char js_Generator_str[]; +extern const char js_Iterator_str[]; +extern const char js_StopIteration_str[]; +extern const char js_ArrayBuffer_str[]; +extern const char js_Int8Array_str[]; +extern const char js_Uint8Array_str[]; +extern const char js_Int16Array_str[]; +extern const char js_Uint16Array_str[]; +extern const char js_Int32Array_str[]; +extern const char js_Uint32Array_str[]; +extern const char js_Float32Array_str[]; +extern const char js_Float64Array_str[]; +extern const char js_Uint8ClampedArray_str[]; +extern const char js_Proxy_str[]; +extern const char js_AnyName_str[]; +extern const char js_anonymous_str[]; +extern const char js_apply_str[]; +extern const char js_arguments_str[]; +extern const char js_arity_str[]; +extern const char js_call_str[]; +extern const char js_callee_str[]; +extern const char js_caller_str[]; +extern const char js_class_prototype_str[]; +extern const char js_close_str[]; +extern const char js_constructor_str[]; +extern const char js_count_str[]; +extern const char js_etago_str[]; +extern const char js_each_str[]; +extern const char js_eval_str[]; +extern const char js_fileName_str[]; +extern const char js_get_str[]; +extern const char js_getter_str[]; +extern const char js_global_str[]; +extern const char js_ignoreCase_str[]; +extern const char js_index_str[]; +extern const char js_input_str[]; +extern const char js_iterator_str[]; +extern const char js_join_str[]; +extern const char js_lastIndex_str[]; +extern const char js_length_str[]; +extern const char js_lineNumber_str[]; +extern const char js_message_str[]; +extern const char js_multiline_str[]; +extern const char js_name_str[]; +extern const char js_namespace_str[]; +extern const char js_next_str[]; +extern const char js_noSuchMethod_str[]; +extern const char js_object_str[]; +extern const char js_proto_str[]; +extern const char js_ptagc_str[]; +extern const char js_qualifier_str[]; +extern const char js_send_str[]; +extern const char js_setter_str[]; +extern const char js_set_str[]; +extern const char js_source_str[]; +extern const char js_space_str[]; +extern const char js_stack_str[]; +extern const char js_sticky_str[]; +extern const char js_stago_str[]; +extern const char js_star_str[]; +extern const char js_starQualifier_str[]; +extern const char js_tagc_str[]; +extern const char js_toGMTString_str[]; +extern const char js_toLocaleString_str[]; +extern const char js_toSource_str[]; +extern const char js_toString_str[]; +extern const char js_toUTCString_str[]; +extern const char js_undefined_str[]; +extern const char js_valueOf_str[]; +extern const char js_toJSON_str[]; +extern const char js_xml_str[]; +extern const char js_enumerable_str[]; +extern const char js_configurable_str[]; +extern const char js_writable_str[]; +extern const char js_value_str[]; +extern const char js_test_str[]; +extern JSBool +js_InitAtomState(JSRuntime *rt); +extern void +js_FinishAtomState(JSRuntime *rt); +extern void +js_TraceAtomState(JSTracer *trc); +extern void +js_SweepAtomState(JSContext *cx); +extern JSBool +js_InitCommonAtoms(JSContext *cx); +extern void +js_FinishCommonAtoms(JSContext *cx); +extern JSAtom * +js_AtomizeString(JSContext *cx, JSString *str, uintN flags); +extern JSAtom * +js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags); +extern JSAtom * +js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags); +extern JSAtom * +js_GetExistingStringAtom(JSContext *cx, const jschar *chars, size_t length); +inline + bool +js_ValueToAtom(JSContext *cx, const js::Value &v, JSAtom **atomp); +inline + bool +js_ValueToStringId(JSContext *cx, const js::Value &v, jsid *idp); +inline + bool +js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval, + jsid *idp); +inline + bool +js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval, + jsid *idp, js::Value *vp); +extern void +js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al); +const uintN MIN_SPARSE_INDEX = 256; +inline JSObject::EnsureDenseResult +JSObject::ensureDenseArrayElements(JSContext *cx, uintN index, uintN extra) +{ + ((void) 0); + uintN currentCapacity = numSlots(); + uintN requiredCapacity; + if (extra == 1) { + if (index < currentCapacity) + return ED_OK; + requiredCapacity = index + 1; + if (requiredCapacity == 0) { + return ED_SPARSE; + } + } else { + requiredCapacity = index + extra; + if (requiredCapacity < index) { + return ED_SPARSE; + } + if (requiredCapacity <= currentCapacity) + return ED_OK; + } + if (requiredCapacity > MIN_SPARSE_INDEX && + willBeSparseDenseArray(requiredCapacity, extra)) { + return ED_SPARSE; + } + return growSlots(cx, requiredCapacity) ? ED_OK : ED_FAILED; +} +extern + bool +js_StringIsIndex(JSLinearString *str, jsuint *indexp); +inline JSBool +js_IdIsIndex(jsid id, jsuint *indexp) +{ + if (JSID_IS_INT(id)) { + jsint i; + i = JSID_TO_INT(id); + if (i < 0) + return (JSIntn)0; + *indexp = (jsuint)i; + return (JSIntn)1; + } + if ((__builtin_expect((!JSID_IS_STRING(id)), 0))) + return (JSIntn)0; + return js_StringIsIndex(JSID_TO_ATOM(id), indexp); +} +inline + bool +js_IdValIsIndex(JSContext *cx, jsval id, jsuint *indexp, bool *isIndex) +{ + if (JSVAL_IS_INT(id)) { + jsint i; + i = JSVAL_TO_INT(id); + if (i < 0) { + *isIndex = false; + return true; + } + *indexp = (jsuint)i; + *isIndex = true; + return true; + } + if (!JSVAL_IS_STRING(id)) { + *isIndex = false; + return true; + } + JSLinearString *str = JSVAL_TO_STRING(id)->ensureLinear(cx); + if (!str) + return false; + *isIndex = js_StringIsIndex(str, indexp); + return true; +} +extern js::Class js_ArrayClass, js_SlowArrayClass; +inline + bool +JSObject::isDenseArray() const +{ + return getClass() == &js_ArrayClass; +} +inline + bool +JSObject::isSlowArray() const +{ + return getClass() == &js_SlowArrayClass; +} +inline + bool +JSObject::isArray() const +{ + return isDenseArray() || isSlowArray(); +} +static inline JSObject * +js_GetProtoIfDenseArray(JSObject *obj) +{ + return obj->isDenseArray() ? obj->getProto() : obj; +} +extern JSObject * +js_InitArrayClass(JSContext *cx, JSObject *obj); +extern + bool +js_InitContextBusyArrayTable(JSContext *cx); +namespace js +{ +extern JSObject * +NewDenseEmptyArray(JSContext *cx, JSObject *proto=__null); +extern JSObject * +NewDenseAllocatedArray(JSContext *cx, uint length, JSObject *proto=__null); +extern JSObject * +NewDenseUnallocatedArray(JSContext *cx, uint length, JSObject *proto=__null); +extern JSObject * +NewDenseCopiedArray(JSContext *cx, uint length, Value *vp, JSObject *proto=__null); +extern JSObject * +NewSlowEmptyArray(JSContext *cx); +} +extern JSBool +js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp); +extern JSBool +js_SetLengthProperty(JSContext *cx, JSObject *obj, jsdouble length); +extern JSBool +js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp); +extern JSBool +js_IndexToId(JSContext *cx, jsuint index, jsid *idp); +namespace js { +extern + bool +GetElements(JSContext *cx, JSObject *aobj, jsuint length, js::Value *vp); +} +typedef JSBool (*JSComparator)(void *arg, const void *a, const void *b, + int *result); +enum JSMergeSortElemType { + JS_SORTING_VALUES, + JS_SORTING_GENERIC +}; +extern + bool +js_MergeSort(void *vec, size_t nel, size_t elsize, JSComparator cmp, + void *arg, void *tmp, JSMergeSortElemType elemType); +namespace js { +extern JSBool +array_sort(JSContext *cx, uintN argc, js::Value *vp); +} +extern JSBool +js_ArrayCompPush(JSContext *cx, JSObject *obj, const js::Value &vp); +__attribute__((visibility ("default"))) JSBool +js_CoerceArrayToCanvasImageData(JSObject *obj, jsuint offset, jsuint count, + JSUint8 *dest); +JSBool +js_PrototypeHasIndexedProperties(JSContext *cx, JSObject *obj); +JSBool +js_GetDenseArrayElementValue(JSContext *cx, JSObject *obj, jsid id, + js::Value *vp); +JSBool +js_Array(JSContext *cx, uintN argc, js::Value *vp); +__attribute__((visibility ("default"))) JSBool +js_CloneDensePrimitiveArray(JSContext *cx, JSObject *obj, JSObject **clone); +__attribute__((visibility ("default"))) JSBool +js_IsDensePrimitiveArray(JSObject *obj); +extern JSBool +js_EnsureDenseArrayCapacity(JSContext *cx, JSObject *obj, jsint i); +extern js::Class js_BooleanClass; +inline + bool +JSObject::isBoolean() const +{ + return getClass() == &js_BooleanClass; +} +extern JSObject * +js_InitBooleanClass(JSContext *cx, JSObject *obj); +extern JSString * +js_BooleanToString(JSContext *cx, JSBool b); +namespace js { +extern + bool +BooleanToStringBuffer(JSContext *cx, JSBool b, StringBuffer &sb); +} +extern JSBool +js_ValueToBoolean(const js::Value &v); +extern "C" { +typedef struct JSArena JSArena; +typedef struct JSArenaPool JSArenaPool; +struct JSArena { + JSArena *next; + jsuword base; + jsuword limit; + jsuword avail; +}; +struct JSArenaPool { + JSArena first; + JSArena *current; + size_t arenasize; + jsuword mask; + size_t *quotap; +}; +extern __attribute__((visibility ("default"))) void +JS_InitArenaPool(JSArenaPool *pool, const char *name, size_t size, + size_t align, size_t *quotap); +extern __attribute__((visibility ("default"))) void +JS_FreeArenaPool(JSArenaPool *pool); +extern __attribute__((visibility ("default"))) void +JS_FinishArenaPool(JSArenaPool *pool); +extern __attribute__((visibility ("default"))) void +JS_ArenaFinish(void); +extern __attribute__((visibility ("default"))) void +JS_ArenaShutDown(void); +extern __attribute__((visibility ("default"))) void * +JS_ArenaAllocate(JSArenaPool *pool, size_t nb); +extern __attribute__((visibility ("default"))) void * +JS_ArenaRealloc(JSArenaPool *pool, void *p, size_t size, size_t incr); +extern __attribute__((visibility ("default"))) void * +JS_ArenaGrow(JSArenaPool *pool, void *p, size_t size, size_t incr); +extern __attribute__((visibility ("default"))) void +JS_ArenaRelease(JSArenaPool *pool, char *mark); +} +typedef struct JSCListStr { + struct JSCListStr *next; + struct JSCListStr *prev; +} JSCList; +extern "C" { +typedef uint32 JSDHashNumber; +typedef struct JSDHashEntryHdr JSDHashEntryHdr; +typedef struct JSDHashEntryStub JSDHashEntryStub; +typedef struct JSDHashTable JSDHashTable; +typedef struct JSDHashTableOps JSDHashTableOps; +struct JSDHashEntryHdr { + JSDHashNumber keyHash; +}; +struct JSDHashTable { + const JSDHashTableOps *ops; + void *data; + int16 hashShift; + uint8 maxAlphaFrac; + uint8 minAlphaFrac; + uint32 entrySize; + uint32 entryCount; + uint32 removedCount; + uint32 generation; + char *entryStore; +}; +typedef void * +(* JSDHashAllocTable)(JSDHashTable *table, uint32 nbytes); +typedef void +(* JSDHashFreeTable) (JSDHashTable *table, void *ptr); +typedef JSDHashNumber +(* JSDHashHashKey) (JSDHashTable *table, const void *key); +typedef JSBool +(* JSDHashMatchEntry)(JSDHashTable *table, const JSDHashEntryHdr *entry, + const void *key); +typedef void +(* JSDHashMoveEntry)(JSDHashTable *table, const JSDHashEntryHdr *from, + JSDHashEntryHdr *to); +typedef void +(* JSDHashClearEntry)(JSDHashTable *table, JSDHashEntryHdr *entry); +typedef void +(* JSDHashFinalize) (JSDHashTable *table); +typedef JSBool +(* JSDHashInitEntry)(JSDHashTable *table, JSDHashEntryHdr *entry, + const void *key); +struct JSDHashTableOps { + JSDHashAllocTable allocTable; + JSDHashFreeTable freeTable; + JSDHashHashKey hashKey; + JSDHashMatchEntry matchEntry; + JSDHashMoveEntry moveEntry; + JSDHashClearEntry clearEntry; + JSDHashFinalize finalize; + JSDHashInitEntry initEntry; +}; +extern __attribute__((visibility ("default"))) void * +JS_DHashAllocTable(JSDHashTable *table, uint32 nbytes); +extern __attribute__((visibility ("default"))) void +JS_DHashFreeTable(JSDHashTable *table, void *ptr); +extern __attribute__((visibility ("default"))) JSDHashNumber +JS_DHashStringKey(JSDHashTable *table, const void *key); +struct JSDHashEntryStub { + JSDHashEntryHdr hdr; + const void *key; +}; +extern __attribute__((visibility ("default"))) JSDHashNumber +JS_DHashVoidPtrKeyStub(JSDHashTable *table, const void *key); +extern __attribute__((visibility ("default"))) JSBool +JS_DHashMatchEntryStub(JSDHashTable *table, + const JSDHashEntryHdr *entry, + const void *key); +extern __attribute__((visibility ("default"))) JSBool +JS_DHashMatchStringKey(JSDHashTable *table, + const JSDHashEntryHdr *entry, + const void *key); +extern __attribute__((visibility ("default"))) void +JS_DHashMoveEntryStub(JSDHashTable *table, + const JSDHashEntryHdr *from, + JSDHashEntryHdr *to); +extern __attribute__((visibility ("default"))) void +JS_DHashClearEntryStub(JSDHashTable *table, JSDHashEntryHdr *entry); +extern __attribute__((visibility ("default"))) void +JS_DHashFreeStringKey(JSDHashTable *table, JSDHashEntryHdr *entry); +extern __attribute__((visibility ("default"))) void +JS_DHashFinalizeStub(JSDHashTable *table); +extern __attribute__((visibility ("default"))) const JSDHashTableOps * +JS_DHashGetStubOps(void); +extern __attribute__((visibility ("default"))) JSDHashTable * +JS_NewDHashTable(const JSDHashTableOps *ops, void *data, uint32 entrySize, + uint32 capacity); +extern __attribute__((visibility ("default"))) void +JS_DHashTableDestroy(JSDHashTable *table); +extern __attribute__((visibility ("default"))) JSBool +JS_DHashTableInit(JSDHashTable *table, const JSDHashTableOps *ops, void *data, + uint32 entrySize, uint32 capacity); +extern __attribute__((visibility ("default"))) void +JS_DHashTableSetAlphaBounds(JSDHashTable *table, + float maxAlpha, + float minAlpha); +extern __attribute__((visibility ("default"))) void +JS_DHashTableFinish(JSDHashTable *table); +typedef enum JSDHashOperator { + JS_DHASH_LOOKUP = 0, + JS_DHASH_ADD = 1, + JS_DHASH_REMOVE = 2, + JS_DHASH_NEXT = 0, + JS_DHASH_STOP = 1 +} JSDHashOperator; +extern __attribute__((visibility ("default"))) JSDHashEntryHdr * +JS_DHashTableOperate(JSDHashTable *table, const void *key, JSDHashOperator op); +extern __attribute__((visibility ("default"))) void +JS_DHashTableRawRemove(JSDHashTable *table, JSDHashEntryHdr *entry); +typedef JSDHashOperator +(* JSDHashEnumerator)(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 number, + void *arg); +extern __attribute__((visibility ("default"))) uint32 +JS_DHashTableEnumerate(JSDHashTable *table, JSDHashEnumerator etor, void *arg); +} +extern "C" { +struct DtoaState; +DtoaState * +js_NewDtoaState(); +void +js_DestroyDtoaState(DtoaState *state); +double +js_strtod_harder(DtoaState *state, const char *s00, char **se, int *err); +typedef enum JSDToStrMode { + DTOSTR_STANDARD, + DTOSTR_STANDARD_EXPONENTIAL, + DTOSTR_FIXED, + DTOSTR_EXPONENTIAL, + DTOSTR_PRECISION +} JSDToStrMode; +char * +js_dtostr(DtoaState *state, char *buffer, size_t bufferSize, JSDToStrMode mode, int precision, + double dval); +char * +js_dtobasestr(DtoaState *state, int base, double d); +} +extern "C" { +typedef enum JSOp { +JSOP_NOP = 0, +JSOP_PUSH = 1, +JSOP_POPV = 2, +JSOP_ENTERWITH = 3, +JSOP_LEAVEWITH = 4, +JSOP_RETURN = 5, +JSOP_GOTO = 6, +JSOP_IFEQ = 7, +JSOP_IFNE = 8, +JSOP_ARGUMENTS = 9, +JSOP_FORARG = 10, +JSOP_FORLOCAL = 11, +JSOP_DUP = 12, +JSOP_DUP2 = 13, +JSOP_SETCONST = 14, +JSOP_BITOR = 15, +JSOP_BITXOR = 16, +JSOP_BITAND = 17, +JSOP_EQ = 18, +JSOP_NE = 19, +JSOP_LT = 20, +JSOP_LE = 21, +JSOP_GT = 22, +JSOP_GE = 23, +JSOP_LSH = 24, +JSOP_RSH = 25, +JSOP_URSH = 26, +JSOP_ADD = 27, +JSOP_SUB = 28, +JSOP_MUL = 29, +JSOP_DIV = 30, +JSOP_MOD = 31, +JSOP_NOT = 32, +JSOP_BITNOT = 33, +JSOP_NEG = 34, +JSOP_POS = 35, +JSOP_DELNAME = 36, +JSOP_DELPROP = 37, +JSOP_DELELEM = 38, +JSOP_TYPEOF = 39, +JSOP_VOID = 40, +JSOP_INCNAME = 41, +JSOP_INCPROP = 42, +JSOP_INCELEM = 43, +JSOP_DECNAME = 44, +JSOP_DECPROP = 45, +JSOP_DECELEM = 46, +JSOP_NAMEINC = 47, +JSOP_PROPINC = 48, +JSOP_ELEMINC = 49, +JSOP_NAMEDEC = 50, +JSOP_PROPDEC = 51, +JSOP_ELEMDEC = 52, +JSOP_GETPROP = 53, +JSOP_SETPROP = 54, +JSOP_GETELEM = 55, +JSOP_SETELEM = 56, +JSOP_CALLNAME = 57, +JSOP_CALL = 58, +JSOP_NAME = 59, +JSOP_DOUBLE = 60, +JSOP_STRING = 61, +JSOP_ZERO = 62, +JSOP_ONE = 63, +JSOP_NULL = 64, +JSOP_THIS = 65, +JSOP_FALSE = 66, +JSOP_TRUE = 67, +JSOP_OR = 68, +JSOP_AND = 69, +JSOP_TABLESWITCH = 70, +JSOP_LOOKUPSWITCH = 71, +JSOP_STRICTEQ = 72, +JSOP_STRICTNE = 73, +JSOP_SETCALL = 74, +JSOP_ITER = 75, +JSOP_MOREITER = 76, +JSOP_ENDITER = 77, +JSOP_FUNAPPLY = 78, +JSOP_SWAP = 79, +JSOP_OBJECT = 80, +JSOP_POP = 81, +JSOP_NEW = 82, +JSOP_TRAP = 83, +JSOP_GETARG = 84, +JSOP_SETARG = 85, +JSOP_GETLOCAL = 86, +JSOP_SETLOCAL = 87, +JSOP_UINT16 = 88, +JSOP_NEWINIT = 89, +JSOP_NEWARRAY = 90, +JSOP_NEWOBJECT = 91, +JSOP_ENDINIT = 92, +JSOP_INITPROP = 93, +JSOP_INITELEM = 94, +JSOP_DEFSHARP = 95, +JSOP_USESHARP = 96, +JSOP_INCARG = 97, +JSOP_DECARG = 98, +JSOP_ARGINC = 99, +JSOP_ARGDEC = 100, +JSOP_INCLOCAL = 101, +JSOP_DECLOCAL = 102, +JSOP_LOCALINC = 103, +JSOP_LOCALDEC = 104, +JSOP_IMACOP = 105, +JSOP_FORNAME = 106, +JSOP_FORPROP = 107, +JSOP_FORELEM = 108, +JSOP_POPN = 109, +JSOP_BINDNAME = 110, +JSOP_SETNAME = 111, +JSOP_THROW = 112, +JSOP_IN = 113, +JSOP_INSTANCEOF = 114, +JSOP_DEBUGGER = 115, +JSOP_GOSUB = 116, +JSOP_RETSUB = 117, +JSOP_EXCEPTION = 118, +JSOP_LINENO = 119, +JSOP_CONDSWITCH = 120, +JSOP_CASE = 121, +JSOP_DEFAULT = 122, +JSOP_EVAL = 123, +JSOP_ENUMELEM = 124, +JSOP_GETTER = 125, +JSOP_SETTER = 126, +JSOP_DEFFUN = 127, +JSOP_DEFCONST = 128, +JSOP_DEFVAR = 129, +JSOP_LAMBDA = 130, +JSOP_CALLEE = 131, +JSOP_SETLOCALPOP = 132, +JSOP_PICK = 133, +JSOP_TRY = 134, +JSOP_FINALLY = 135, +JSOP_GETFCSLOT = 136, +JSOP_CALLFCSLOT = 137, +JSOP_ARGSUB = 138, +JSOP_ARGCNT = 139, +JSOP_DEFLOCALFUN = 140, +JSOP_GOTOX = 141, +JSOP_IFEQX = 142, +JSOP_IFNEX = 143, +JSOP_ORX = 144, +JSOP_ANDX = 145, +JSOP_GOSUBX = 146, +JSOP_CASEX = 147, +JSOP_DEFAULTX = 148, +JSOP_TABLESWITCHX = 149, +JSOP_LOOKUPSWITCHX = 150, +JSOP_BACKPATCH = 151, +JSOP_BACKPATCH_POP = 152, +JSOP_THROWING = 153, +JSOP_SETRVAL = 154, +JSOP_RETRVAL = 155, +JSOP_GETGNAME = 156, +JSOP_SETGNAME = 157, +JSOP_INCGNAME = 158, +JSOP_DECGNAME = 159, +JSOP_GNAMEINC = 160, +JSOP_GNAMEDEC = 161, +JSOP_REGEXP = 162, +JSOP_DEFXMLNS = 163, +JSOP_ANYNAME = 164, +JSOP_QNAMEPART = 165, +JSOP_QNAMECONST = 166, +JSOP_QNAME = 167, +JSOP_TOATTRNAME = 168, +JSOP_TOATTRVAL = 169, +JSOP_ADDATTRNAME = 170, +JSOP_ADDATTRVAL = 171, +JSOP_BINDXMLNAME = 172, +JSOP_SETXMLNAME = 173, +JSOP_XMLNAME = 174, +JSOP_DESCENDANTS = 175, +JSOP_FILTER = 176, +JSOP_ENDFILTER = 177, +JSOP_TOXML = 178, +JSOP_TOXMLLIST = 179, +JSOP_XMLTAGEXPR = 180, +JSOP_XMLELTEXPR = 181, +JSOP_NOTRACE = 182, +JSOP_XMLCDATA = 183, +JSOP_XMLCOMMENT = 184, +JSOP_XMLPI = 185, +JSOP_DELDESC = 186, +JSOP_CALLPROP = 187, +JSOP_BLOCKCHAIN = 188, +JSOP_NULLBLOCKCHAIN = 189, +JSOP_UINT24 = 190, +JSOP_INDEXBASE = 191, +JSOP_RESETBASE = 192, +JSOP_RESETBASE0 = 193, +JSOP_STARTXML = 194, +JSOP_STARTXMLEXPR = 195, +JSOP_CALLELEM = 196, +JSOP_STOP = 197, +JSOP_GETXPROP = 198, +JSOP_CALLXMLNAME = 199, +JSOP_TYPEOFEXPR = 200, +JSOP_ENTERBLOCK = 201, +JSOP_LEAVEBLOCK = 202, +JSOP_IFPRIMTOP = 203, +JSOP_PRIMTOP = 204, +JSOP_GENERATOR = 205, +JSOP_YIELD = 206, +JSOP_ARRAYPUSH = 207, +JSOP_GETFUNNS = 208, +JSOP_ENUMCONSTELEM = 209, +JSOP_LEAVEBLOCKEXPR = 210, +JSOP_GETTHISPROP = 211, +JSOP_GETARGPROP = 212, +JSOP_GETLOCALPROP = 213, +JSOP_INDEXBASE1 = 214, +JSOP_INDEXBASE2 = 215, +JSOP_INDEXBASE3 = 216, +JSOP_CALLGNAME = 217, +JSOP_CALLLOCAL = 218, +JSOP_CALLARG = 219, +JSOP_BINDGNAME = 220, +JSOP_INT8 = 221, +JSOP_INT32 = 222, +JSOP_LENGTH = 223, +JSOP_HOLE = 224, +JSOP_DEFFUN_FC = 225, +JSOP_DEFLOCALFUN_FC = 226, +JSOP_LAMBDA_FC = 227, +JSOP_OBJTOP = 228, +JSOP_TRACE = 229, +JSOP_GETUPVAR_DBG = 230, +JSOP_CALLUPVAR_DBG = 231, +JSOP_DEFFUN_DBGFC = 232, +JSOP_DEFLOCALFUN_DBGFC = 233, +JSOP_LAMBDA_DBGFC = 234, +JSOP_SETMETHOD = 235, +JSOP_INITMETHOD = 236, +JSOP_UNBRAND = 237, +JSOP_UNBRANDTHIS = 238, +JSOP_SHARPINIT = 239, +JSOP_GETGLOBAL = 240, +JSOP_CALLGLOBAL = 241, +JSOP_FUNCALL = 242, +JSOP_FORGNAME = 243, + JSOP_LIMIT, + JSOP_GETPROP2 = JSOP_LIMIT, + JSOP_GETELEM2 = JSOP_LIMIT + 1, + JSOP_FAKE_LIMIT = JSOP_GETELEM2 +} JSOp; +struct JSCodeSpec { + int8 length; + int8 nuses; + int8 ndefs; + uint8 prec; + uint32 format; + uint32 type() const { return ((format) & 0x001f); } +}; +extern const JSCodeSpec js_CodeSpec[]; +extern uintN js_NumCodeSpecs; +extern const char *js_CodeName[]; +extern const char js_EscapeMap[]; +extern JSString * +js_QuoteString(JSContext *cx, JSString *str, jschar quote); +extern JSPrinter * +js_NewPrinter(JSContext *cx, const char *name, JSFunction *fun, + uintN indent, JSBool pretty, JSBool grouped, JSBool strict); +extern void +js_DestroyPrinter(JSPrinter *jp); +extern JSString * +js_GetPrinterOutput(JSPrinter *jp); +extern int +js_printf(JSPrinter *jp, const char *format, ...); +extern JSBool +js_puts(JSPrinter *jp, const char *s); +uintN +js_GetIndexFromBytecode(JSContext *cx, JSScript *script, jsbytecode *pc, + ptrdiff_t pcoff); +extern uintN +js_GetVariableBytecodeLength(jsbytecode *pc); +extern uintN +js_GetVariableStackUses(JSOp op, jsbytecode *pc); +extern uintN +js_GetEnterBlockStackDefs(JSContext *cx, JSScript *script, jsbytecode *pc); +static inline uintN +js_GetStackUses(const JSCodeSpec *cs, JSOp op, jsbytecode *pc) +{ + ((void) 0); + if (cs->nuses >= 0) + return cs->nuses; + return js_GetVariableStackUses(op, pc); +} +static inline uintN +js_GetStackDefs(JSContext *cx, const JSCodeSpec *cs, JSOp op, JSScript *script, + jsbytecode *pc) +{ + ((void) 0); + if (cs->ndefs >= 0) + return cs->ndefs; + ((void) 0); + return js_GetEnterBlockStackDefs(cx, script, pc); +} +extern JSBool +js_DecompileScript(JSPrinter *jp, JSScript *script); +extern JSBool +js_DecompileFunctionBody(JSPrinter *jp); +extern JSBool +js_DecompileFunction(JSPrinter *jp); +typedef JSBool (* JSDecompilerPtr)(JSPrinter *); +extern JSString * +js_DecompileToString(JSContext *cx, const char *name, JSFunction *fun, + uintN indent, JSBool pretty, JSBool grouped, JSBool strict, + JSDecompilerPtr decompiler); +extern char * +js_DecompileValueGenerator(JSContext *cx, intN spindex, jsval v, + JSString *fallback); +namespace js { +static inline char * +DecompileValueGenerator(JSContext *cx, intN spindex, const Value &v, + JSString *fallback) +{ + return js_DecompileValueGenerator(cx, spindex, Jsvalify(v), fallback); +} +} +extern uintN +js_ReconstructStackDepth(JSContext *cx, JSScript *script, jsbytecode *pc); +} +extern "C" { +extern __attribute__((visibility ("default"))) JSCrossCompartmentCall * +JS_EnterCrossCompartmentCallScript(JSContext *cx, JSScript *target); +} +namespace JS { +class __attribute__((visibility ("default"))) AutoEnterScriptCompartment +{ + JSCrossCompartmentCall *call; + public: + AutoEnterScriptCompartment() : call(__null) {} + bool enter(JSContext *cx, JSScript *target); + bool entered() const { return call != __null; } + ~AutoEnterScriptCompartment() { + if (call && call != reinterpret_cast(1)) + JS_LeaveCrossCompartmentCall(call); + } +}; +} +extern "C" { +extern __attribute__((visibility ("default"))) JSScript * +JS_GetScriptFromObject(JSObject *scriptObject); +extern __attribute__((visibility ("default"))) JSString * +JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, uintN indent); +extern __attribute__((visibility ("default"))) void +JS_SetRuntimeDebugMode(JSRuntime *rt, JSBool debug); +extern __attribute__((visibility ("default"))) JSBool +JS_GetDebugMode(JSContext *cx); +__attribute__((visibility ("default"))) JSBool +JS_SetDebugModeForCompartment(JSContext *cx, JSCompartment *comp, JSBool debug); +__attribute__((visibility ("default"))) JSBool +JS_SetDebugMode(JSContext *cx, JSBool debug); +extern __attribute__((visibility ("default"))) JSBool +js_SetSingleStepMode(JSContext *cx, JSScript *script, JSBool singleStep); +extern __attribute__((visibility ("default"))) JSBool +JS_SetSingleStepMode(JSContext *cx, JSScript *script, JSBool singleStep); +extern jsbytecode * +js_UntrapScriptCode(JSContext *cx, JSScript *script); +extern __attribute__((visibility ("default"))) JSBool +JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc, + JSTrapHandler handler, jsval closure); +extern __attribute__((visibility ("default"))) JSOp +JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc); +extern __attribute__((visibility ("default"))) void +JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, + JSTrapHandler *handlerp, jsval *closurep); +extern __attribute__((visibility ("default"))) void +JS_ClearScriptTraps(JSContext *cx, JSScript *script); +extern __attribute__((visibility ("default"))) void +JS_ClearAllTraps(JSContext *cx); +extern __attribute__((visibility ("default"))) JSTrapStatus +JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure); +extern __attribute__((visibility ("default"))) JSBool +JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep); +extern __attribute__((visibility ("default"))) JSBool +JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id, + JSWatchPointHandler handler, JSObject *closure); +extern __attribute__((visibility ("default"))) JSBool +JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, + JSWatchPointHandler *handlerp, JSObject **closurep); +extern __attribute__((visibility ("default"))) JSBool +JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_ClearAllWatchPoints(JSContext *cx); +extern void +js_TraceWatchPoints(JSTracer *trc, JSObject *obj); +extern void +js_SweepWatchPoints(JSContext *cx); +extern JSBool +js_watch_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp); +namespace js { +bool +IsWatchedProperty(JSContext *cx, const Shape *shape); +} +extern __attribute__((visibility ("default"))) uintN +JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); +extern __attribute__((visibility ("default"))) jsbytecode * +JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno); +extern __attribute__((visibility ("default"))) jsbytecode * +JS_EndPC(JSContext *cx, JSScript *script); +extern __attribute__((visibility ("default"))) uintN +JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun); +extern __attribute__((visibility ("default"))) JSBool +JS_FunctionHasLocalNames(JSContext *cx, JSFunction *fun); +extern __attribute__((visibility ("default"))) jsuword * +JS_GetFunctionLocalNameArray(JSContext *cx, JSFunction *fun, void **markp); +extern __attribute__((visibility ("default"))) JSAtom * +JS_LocalNameToAtom(jsuword w); +extern __attribute__((visibility ("default"))) JSString * +JS_AtomKey(JSAtom *atom); +extern __attribute__((visibility ("default"))) void +JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); +extern __attribute__((visibility ("default"))) JSScript * +JS_GetFunctionScript(JSContext *cx, JSFunction *fun); +extern __attribute__((visibility ("default"))) JSNative +JS_GetFunctionNative(JSContext *cx, JSFunction *fun); +extern __attribute__((visibility ("default"))) JSPrincipals * +JS_GetScriptPrincipals(JSContext *cx, JSScript *script); +extern __attribute__((visibility ("default"))) JSStackFrame * +JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp); +extern __attribute__((visibility ("default"))) JSScript * +JS_GetFrameScript(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) jsbytecode * +JS_GetFramePC(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSStackFrame * +JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp); +extern JSPrincipals * +js_StackFramePrincipals(JSContext *cx, JSStackFrame *fp); +JSPrincipals * +js_EvalFramePrincipals(JSContext *cx, JSObject *callee, JSStackFrame *caller); +extern __attribute__((visibility ("default"))) void * +JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) void +JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation); +extern __attribute__((visibility ("default"))) void * +JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSBool +JS_IsScriptFrame(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetFrameObject(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetFrameThis(JSContext *cx, JSStackFrame *fp, jsval *thisv); +extern __attribute__((visibility ("default"))) JSFunction * +JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSBool +JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSBool +JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) jsval +JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) void +JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval); +extern __attribute__((visibility ("default"))) JSObject * +JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetValidFrameCalleeObject(JSContext *cx, JSStackFrame *fp, jsval *vp); +extern __attribute__((visibility ("default"))) const char * +JS_GetScriptFilename(JSContext *cx, JSScript *script); +extern __attribute__((visibility ("default"))) uintN +JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script); +extern __attribute__((visibility ("default"))) uintN +JS_GetScriptLineExtent(JSContext *cx, JSScript *script); +extern __attribute__((visibility ("default"))) JSVersion +JS_GetScriptVersion(JSContext *cx, JSScript *script); +extern __attribute__((visibility ("default"))) void +JS_SetNewScriptHookProc(JSRuntime *rt, JSNewScriptHook hook, void *callerdata); +extern __attribute__((visibility ("default"))) void +JS_SetDestroyScriptHookProc(JSRuntime *rt, JSDestroyScriptHook hook, + void *callerdata); +extern __attribute__((visibility ("default"))) JSBool +JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp, + const jschar *chars, uintN length, + const char *filename, uintN lineno, + jsval *rval); +extern __attribute__((visibility ("default"))) JSBool +JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp, + const char *bytes, uintN length, + const char *filename, uintN lineno, + jsval *rval); +typedef struct JSPropertyDesc { + jsval id; + jsval value; + uint8 flags; + uint8 spare; + uint16 slot; + jsval alias; +} JSPropertyDesc; +typedef struct JSPropertyDescArray { + uint32 length; + JSPropertyDesc *array; +} JSPropertyDescArray; +typedef struct JSScopeProperty JSScopeProperty; +extern __attribute__((visibility ("default"))) JSScopeProperty * +JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp); +extern __attribute__((visibility ("default"))) JSBool +JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *shape, + JSPropertyDesc *pd); +extern __attribute__((visibility ("default"))) JSBool +JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda); +extern __attribute__((visibility ("default"))) void +JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); +extern __attribute__((visibility ("default"))) JSBool +JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure); +extern __attribute__((visibility ("default"))) JSBool +JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure); +extern __attribute__((visibility ("default"))) JSBool +JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); +extern __attribute__((visibility ("default"))) JSBool +JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure); +extern __attribute__((visibility ("default"))) JSBool +JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure); +extern __attribute__((visibility ("default"))) JSBool +JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure); +extern __attribute__((visibility ("default"))) size_t +JS_GetObjectTotalSize(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) size_t +JS_GetFunctionTotalSize(JSContext *cx, JSFunction *fun); +extern __attribute__((visibility ("default"))) size_t +JS_GetScriptTotalSize(JSContext *cx, JSScript *script); +extern __attribute__((visibility ("default"))) uint32 +JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp); +extern __attribute__((visibility ("default"))) uint32 +JS_GetScriptFilenameFlags(JSScript *script); +extern __attribute__((visibility ("default"))) JSBool +JS_FlagScriptFilenamePrefix(JSRuntime *rt, const char *prefix, uint32 flags); +extern __attribute__((visibility ("default"))) JSBool +JS_IsSystemObject(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSBool +JS_MakeSystemObject(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSObject * +JS_UnwrapObject(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) void +js_RevertVersion(JSContext *cx); +extern __attribute__((visibility ("default"))) const JSDebugHooks * +JS_GetGlobalDebugHooks(JSRuntime *rt); +extern __attribute__((visibility ("default"))) JSDebugHooks * +JS_SetContextDebugHooks(JSContext *cx, const JSDebugHooks *hooks); +extern __attribute__((visibility ("default"))) JSDebugHooks * +JS_ClearContextDebugHooks(JSContext *cx); +extern __attribute__((visibility ("default"))) JSBool +JS_StartProfiling(); +extern __attribute__((visibility ("default"))) void +JS_StopProfiling(); +extern __attribute__((visibility ("default"))) JSBool +JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); +} +typedef enum JSTryNoteKind { + JSTRY_CATCH, + JSTRY_FINALLY, + JSTRY_ITER +} JSTryNoteKind; +namespace js { +class UpvarCookie +{ + uint32 value; + static const uint32 FREE_VALUE = 0xfffffffful; + void checkInvariants() { + typedef int js_static_assert47[(sizeof(UpvarCookie) == sizeof(uint32)) ? 1 : -1]; + typedef int js_static_assert48[(UPVAR_LEVEL_LIMIT < FREE_LEVEL) ? 1 : -1]; + } + public: + static const uint16 FREE_LEVEL = 0x3fff; + static const uint16 UPVAR_LEVEL_LIMIT = 16; + static const uint16 CALLEE_SLOT = 0xffff; + static bool isLevelReserved(uint16 level) { return level >= FREE_LEVEL; } + bool isFree() const { return value == FREE_VALUE; } + uint32 asInteger() const { return value; } + uint16 level() const { ((void) 0); return uint16(value >> 16); } + uint16 slot() const { ((void) 0); return uint16(value); } + void set(const UpvarCookie &other) { set(other.level(), other.slot()); } + void set(uint16 newLevel, uint16 newSlot) { value = (uint32(newLevel) << 16) | newSlot; } + void makeFree() { set(0xffff, 0xffff); ((void) 0); } + void fromInteger(uint32 u32) { value = u32; } +}; +} +struct JSTryNote { + uint8 kind; + uint8 padding; + uint16 stackDepth; + uint32 start; + uint32 length; +}; +typedef struct JSTryNoteArray { + JSTryNote *vector; + uint32 length; +} JSTryNoteArray; +typedef struct JSObjectArray { + JSObject **vector; + uint32 length; +} JSObjectArray; +typedef struct JSUpvarArray { + js::UpvarCookie *vector; + uint32 length; +} JSUpvarArray; +typedef struct JSConstArray { + js::Value *vector; + uint32 length; +} JSConstArray; +struct JSArenaPool; +namespace js { +struct GlobalSlotArray { + struct Entry { + uint32 atomIndex; + uint32 slot; + }; + Entry *vector; + uint32 length; +}; +struct Shape; +enum BindingKind { NONE, ARGUMENT, VARIABLE, CONSTANT, UPVAR }; +class Bindings { + js::Shape *lastBinding; + uint16 nargs; + uint16 nvars; + uint16 nupvars; + public: + inline Bindings(JSContext *cx); + inline void transfer(JSContext *cx, Bindings *bindings); + inline void clone(JSContext *cx, Bindings *bindings); + uint16 countArgs() const { return nargs; } + uint16 countVars() const { return nvars; } + uint16 countUpvars() const { return nupvars; } + uintN countArgsAndVars() const { return nargs + nvars; } + uintN countLocalNames() const { return nargs + nvars + nupvars; } + bool hasUpvars() const { return nupvars > 0; } + bool hasLocalNames() const { return countLocalNames() > 0; } + inline const js::Shape *lastShape() const; + enum { + BINDING_COUNT_LIMIT = 0xFFFF + }; + bool add(JSContext *cx, JSAtom *name, BindingKind kind); + bool addVariable(JSContext *cx, JSAtom *name) { + return add(cx, name, VARIABLE); + } + bool addConstant(JSContext *cx, JSAtom *name) { + return add(cx, name, CONSTANT); + } + bool addUpvar(JSContext *cx, JSAtom *name) { + return add(cx, name, UPVAR); + } + bool addArgument(JSContext *cx, JSAtom *name, uint16 *slotp) { + ((void) 0); + *slotp = nargs; + return add(cx, name, ARGUMENT); + } + bool addDestructuring(JSContext *cx, uint16 *slotp) { + *slotp = nargs; + return add(cx, __null, ARGUMENT); + } + BindingKind lookup(JSContext *cx, JSAtom *name, uintN *indexp) const; + bool hasBinding(JSContext *cx, JSAtom *name) const { + return lookup(cx, name, __null) != NONE; + } + jsuword * + getLocalNameArray(JSContext *cx, JSArenaPool *pool); + int sharpSlotBase(JSContext *cx); + void makeImmutable(); + const js::Shape *lastArgument() const; + const js::Shape *lastVariable() const; + const js::Shape *lastUpvar() const; + void trace(JSTracer *trc); +}; +} +struct JSScript { + static JSScript *NewScript(JSContext *cx, uint32 length, uint32 nsrcnotes, uint32 natoms, + uint32 nobjects, uint32 nupvars, uint32 nregexps, + uint32 ntrynotes, uint32 nconsts, uint32 nglobals, + uint16 nClosedArgs, uint16 nClosedVars, JSVersion version); + static JSScript *NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg); + JSCList links; + jsbytecode *code; + uint32 length; + private: + uint16 version; + size_t callCount_; + public: + uint16 nfixed; + uint8 objectsOffset; + uint8 upvarsOffset; + uint8 regexpsOffset; + uint8 trynotesOffset; + uint8 globalsOffset; + uint8 constOffset; + bool noScriptRval:1; + bool savedCallerFun:1; + bool hasSharps:1; + bool strictModeCode:1; + bool compileAndGo:1; + bool usesEval:1; + bool usesArguments:1; + bool warnedAboutTwoArgumentEval:1; + bool hasSingletons:1; + jsbytecode *main; + JSAtomMap atomMap; + JSCompartment *compartment; + const char *filename; + uint32 lineno; + uint16 nslots; + uint16 staticLevel; + uint16 nClosedArgs; + uint16 nClosedVars; + js::Bindings bindings; + JSPrincipals *principals; + union { + JSObject *object; + JSScript *nextToGC; + } u; + uint32 *closedSlots; + public: + jssrcnote *notes() { return (jssrcnote *)(code + length); } + static const uint8 INVALID_OFFSET = 0xFF; + static bool isValidOffset(uint8 offset) { return offset != INVALID_OFFSET; } + JSObjectArray *objects() { + ((void) 0); + return (JSObjectArray *)((uint8 *) (this + 1) + objectsOffset); + } + JSUpvarArray *upvars() { + ((void) 0); + return (JSUpvarArray *) ((uint8 *) (this + 1) + upvarsOffset); + } + JSObjectArray *regexps() { + ((void) 0); + return (JSObjectArray *) ((uint8 *) (this + 1) + regexpsOffset); + } + JSTryNoteArray *trynotes() { + ((void) 0); + return (JSTryNoteArray *) ((uint8 *) (this + 1) + trynotesOffset); + } + js::GlobalSlotArray *globals() { + ((void) 0); + return (js::GlobalSlotArray *) ((uint8 *) (this + 1) + globalsOffset); + } + JSConstArray *consts() { + ((void) 0); + return (JSConstArray *) ((uint8 *) (this + 1) + constOffset); + } + JSAtom *getAtom(size_t index) { + ((void) 0); + return atomMap.vector[index]; + } + JSObject *getObject(size_t index) { + JSObjectArray *arr = objects(); + ((void) 0); + return arr->vector[index]; + } + uint32 getGlobalSlot(size_t index) { + js::GlobalSlotArray *arr = globals(); + ((void) 0); + return arr->vector[index].slot; + } + JSAtom *getGlobalAtom(size_t index) { + js::GlobalSlotArray *arr = globals(); + ((void) 0); + return getAtom(arr->vector[index].atomIndex); + } + JSVersion getVersion() const { + return JSVersion(version); + } + inline JSFunction *getFunction(size_t index); + inline JSObject *getRegExp(size_t index); + const js::Value &getConst(size_t index) { + JSConstArray *arr = consts(); + ((void) 0); + return arr->vector[index]; + } + inline bool isEmpty() const; + uint32 getClosedArg(uint32 index) { + ((void) 0); + return closedSlots[index]; + } + uint32 getClosedVar(uint32 index) { + ((void) 0); + return closedSlots[nClosedArgs + index]; + } + void copyClosedSlotsTo(JSScript *other); +}; +static inline uintN +StackDepth(JSScript *script) +{ + return script->nslots - script->nfixed; +} +extern __attribute__((visibility ("default"))) js::Class js_ScriptClass; +extern JSObject * +js_InitScriptClass(JSContext *cx, JSObject *obj); +extern JSBool +js_InitRuntimeScriptState(JSRuntime *rt); +extern void +js_FreeRuntimeScriptState(JSRuntime *rt); +extern const char * +js_SaveScriptFilename(JSContext *cx, const char *filename); +extern const char * +js_SaveScriptFilenameRT(JSRuntime *rt, const char *filename, uint32 flags); +extern uint32 +js_GetScriptFilenameFlags(const char *filename); +extern void +js_MarkScriptFilename(const char *filename); +extern void +js_MarkScriptFilenames(JSRuntime *rt); +extern void +js_SweepScriptFilenames(JSRuntime *rt); +extern __attribute__((visibility ("default"))) void +js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun); +extern void +js_CallDestroyScriptHook(JSContext *cx, JSScript *script); +extern void +js_DestroyScript(JSContext *cx, JSScript *script); +extern void +js_DestroyScriptFromGC(JSContext *cx, JSScript *script); +extern void +js_DestroyCachedScript(JSContext *cx, JSScript *script); +extern void +js_TraceScript(JSTracer *trc, JSScript *script); +extern JSObject * +js_NewScriptObject(JSContext *cx, JSScript *script); +extern jssrcnote * +js_GetSrcNoteCached(JSContext *cx, JSScript *script, jsbytecode *pc); +extern uintN +js_FramePCToLineNumber(JSContext *cx, JSStackFrame *fp); +extern uintN +js_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); +extern jsbytecode * +js_LineNumberToPC(JSScript *script, uintN lineno); +extern __attribute__((visibility ("default"))) uintN +js_GetScriptLineExtent(JSScript *script); +static inline JSOp +js_GetOpcode(JSContext *cx, JSScript *script, jsbytecode *pc) +{ + JSOp op = (JSOp) *pc; + if (op == JSOP_TRAP) + op = JS_GetTrapOpcode(cx, script, pc); + return op; +} +extern JSScript * +js_CloneScript(JSContext *cx, JSScript *script); +extern JSBool +js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic); +inline + bool +JSObject::isScript() const +{ + return getClass() == &js_ScriptClass; +} +inline JSScript * +JSObject::getScript() const +{ + ((void) 0); + return static_cast(getPrivate()); +} +struct JSFunction : public JSObject_Slots2 +{ + uint16 nargs; + uint16 flags; + union U { + struct { + js::Native native; + js::Class *clasp; + JSNativeTraceInfo *trcinfo; + } n; + struct Scripted { + JSScript *script; + uint16 skipmin; + JSPackedBool wrapper; + js::Shape *names; + } i; + void *nativeOrScript; + } u; + JSAtom *atom; + bool optimizedClosure() const { return ((this)->flags & 0xc000) > 0x4000; } + bool needsWrapper() const { return (((this)->flags & 0xc000) == 0xc000) && u.i.skipmin != 0; } + bool isInterpreted() const { return (((this)->flags & 0xc000) >= 0x4000); } + bool isNative() const { return !(((this)->flags & 0xc000) >= 0x4000); } + bool isConstructor() const { return flags & 0x0200; } + bool isHeavyweight() const { return ((flags) & 0x80); } + bool isFlatClosure() const { return ((this)->flags & 0xc000) == 0x8000; } + bool isFunctionPrototype() const { return flags & 0x0800; } + inline bool inStrictMode() const; + void setArgCount(uint16 nargs) { + ((void) 0); + this->nargs = nargs; + } + enum { MAX_ARGS_AND_VARS = 2 * ((1U << 16) - 1) }; + bool mightEscape() const { + return isInterpreted() && (isFlatClosure() || !script()->bindings.hasUpvars()); + } + bool joinable() const { + return flags & 0x0001; + } + JSObject &compiledFunObj() { + return *this; + } + private: + enum { + METHOD_ATOM_SLOT = JSSLOT_FUN_METHOD_ATOM + }; + public: + void setJoinable() { + ((void) 0); + getSlotRef(METHOD_ATOM_SLOT).setNull(); + flags |= 0x0001; + } + JSAtom *methodAtom() const { + return (joinable() && getSlot(METHOD_ATOM_SLOT).isString()) + ? (((void) 0), (JSAtom *)getSlot(METHOD_ATOM_SLOT).toString()) + : __null; + } + void setMethodAtom(JSAtom *atom) { + ((void) 0); + getSlotRef(METHOD_ATOM_SLOT).setString((atom)); + } + js::Native maybeNative() const { + return isInterpreted() ? __null : u.n.native; + } + JSScript *script() const { + ((void) 0); + return u.i.script; + } + static uintN offsetOfNativeOrScript() { + typedef int js_static_assert49[(__builtin_offsetof (U, n.native) == __builtin_offsetof (U, i.script)) ? 1 : -1]; + typedef int js_static_assert50[(__builtin_offsetof (U, n.native) == __builtin_offsetof (U, nativeOrScript)) ? 1 : -1]; + return __builtin_offsetof (JSFunction, u.nativeOrScript); + } + static const uint32 CLASS_RESERVED_SLOTS = JSObject::FUN_CLASS_RESERVED_SLOTS; +}; +extern js::Class js_ArgumentsClass; +namespace js { +extern Class StrictArgumentsClass; +struct ArgumentsData { + js::Value callee; + js::Value slots[1]; +}; +} +inline + bool +JSObject::isNormalArguments() const +{ + return getClass() == &js_ArgumentsClass; +} +inline + bool +JSObject::isStrictArguments() const +{ + return getClass() == &js::StrictArgumentsClass; +} +inline + bool +JSObject::isArguments() const +{ + return isNormalArguments() || isStrictArguments(); +} +extern __attribute__((visibility ("default"))) js::Class js_CallClass; +extern __attribute__((visibility ("default"))) js::Class js_FunctionClass; +extern js::Class js_DeclEnvClass; +inline + bool +JSObject::isCall() const +{ + return getClass() == &js_CallClass; +} +inline + bool +JSObject::isFunction() const +{ + return getClass() == &js_FunctionClass; +} +inline JSFunction * +JSObject::getFunctionPrivate() const +{ + ((void) 0); + return reinterpret_cast(getPrivate()); +} +namespace js { +extern JSObject * +NewCallObject(JSContext *cx, js::Bindings *bindings, JSObject &scopeChain, JSObject *callee); +static __attribute__((always_inline)) inline + bool +IsFunctionObject(const js::Value &v) +{ + return v.isObject() && v.toObject().isFunction(); +} +static __attribute__((always_inline)) inline + bool +IsFunctionObject(const js::Value &v, JSObject **funobj) +{ + return v.isObject() && (*funobj = &v.toObject())->isFunction(); +} +static __attribute__((always_inline)) inline + bool +IsFunctionObject(const js::Value &v, JSFunction **fun) +{ + JSObject *funobj; + bool b = IsFunctionObject(v, &funobj); + if (b) + *fun = funobj->getFunctionPrivate(); + return b; +} +extern __attribute__((always_inline)) inline + bool +SameTraceType(const Value &lhs, const Value &rhs) +{ + return SameType(lhs, rhs) && + (lhs.isPrimitive() || + lhs.toObject().isFunction() == rhs.toObject().isFunction()); +} +inline + bool +IsInternalFunctionObject(JSObject *funobj) +{ + ((void) 0); + JSFunction *fun = (JSFunction *) funobj->getPrivate(); + return funobj == fun && (fun->flags & 0x08) && !funobj->getParent(); +} +static __attribute__((always_inline)) inline + bool +IsConstructing(const Value *vp) +{ + return vp[1].isMagic(); +} +static __attribute__((always_inline)) inline + bool +IsConstructing_PossiblyWithGivenThisObject(const Value *vp, JSObject **ctorThis) +{ + bool isCtor = vp[1].isMagic(); + if (isCtor) + *ctorThis = vp[1].getMagicObjectOrNullPayload(); + return isCtor; +} +inline const char * +GetFunctionNameBytes(JSContext *cx, JSFunction *fun, JSAutoByteString *bytes) +{ + if (fun->atom) + return bytes->encode(cx, (fun->atom)); + return js_anonymous_str; +} +extern __attribute__((visibility ("default"))) bool +IsBuiltinFunctionConstructor(JSFunction *fun); +const Shape * +LookupInterpretedFunctionPrototype(JSContext *cx, JSObject *funobj); +} +extern JSString * +fun_toStringHelper(JSContext *cx, JSObject *obj, uintN indent); +extern JSFunction * +js_NewFunction(JSContext *cx, JSObject *funobj, js::Native native, uintN nargs, + uintN flags, JSObject *parent, JSAtom *atom); +extern JSObject * +js_InitFunctionClass(JSContext *cx, JSObject *obj); +extern JSObject * +js_InitArgumentsClass(JSContext *cx, JSObject *obj); +extern void +js_TraceFunction(JSTracer *trc, JSFunction *fun); +extern void +js_FinalizeFunction(JSContext *cx, JSFunction *fun); +extern JSObject * +js_CloneFunctionObject(JSContext *cx, JSFunction *fun, JSObject *parent, + JSObject *proto); +inline JSObject * +CloneFunctionObject(JSContext *cx, JSFunction *fun, JSObject *parent) +{ + ((void) 0); + JSObject *proto; + if (!js_GetClassPrototype(cx, parent, JSProto_Function, &proto)) + return __null; + return js_CloneFunctionObject(cx, fun, parent, proto); +} +extern JSObject * +js_AllocFlatClosure(JSContext *cx, JSFunction *fun, JSObject *scopeChain); +extern JSObject * +js_NewFlatClosure(JSContext *cx, JSFunction *fun, JSOp op, size_t oplen); +extern JSObject * +js_NewDebuggableFlatClosure(JSContext *cx, JSFunction *fun); +extern JSFunction * +js_DefineFunction(JSContext *cx, JSObject *obj, jsid id, js::Native native, + uintN nargs, uintN flags); +extern JSFunction * +js_ValueToFunction(JSContext *cx, const js::Value *vp, uintN flags); +extern JSObject * +js_ValueToFunctionObject(JSContext *cx, js::Value *vp, uintN flags); +extern JSObject * +js_ValueToCallableObject(JSContext *cx, js::Value *vp, uintN flags); +extern void +js_ReportIsNotFunction(JSContext *cx, const js::Value *vp, uintN flags); +extern JSObject * +js_GetCallObject(JSContext *cx, JSStackFrame *fp); +extern JSObject * +js_CreateCallObjectOnTrace(JSContext *cx, JSFunction *fun, JSObject *callee, JSObject *scopeChain); +extern void +js_PutCallObject(JSContext *cx, JSStackFrame *fp); +extern JSBool +js_PutCallObjectOnTrace(JSContext *cx, JSObject *scopeChain, uint32 nargs, + js::Value *argv, uint32 nvars, js::Value *slots); +namespace js { +extern JSBool +GetCallArg(JSContext *cx, JSObject *obj, jsid id, js::Value *vp); +extern JSBool +GetCallVar(JSContext *cx, JSObject *obj, jsid id, js::Value *vp); +extern JSBool +GetCallVarChecked(JSContext *cx, JSObject *obj, jsid id, js::Value *vp); +extern JSBool +GetCallUpvar(JSContext *cx, JSObject *obj, jsid id, js::Value *vp); +extern JSBool +SetCallArg(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp); +extern JSBool +SetCallVar(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp); +extern JSBool +SetCallUpvar(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp); +} +extern JSBool +js_GetArgsValue(JSContext *cx, JSStackFrame *fp, js::Value *vp); +extern JSBool +js_GetArgsProperty(JSContext *cx, JSStackFrame *fp, jsid id, js::Value *vp); +extern JSObject * +js_GetArgsObject(JSContext *cx, JSStackFrame *fp); +extern void +js_PutArgsObject(JSContext *cx, JSStackFrame *fp); +inline + bool +js_IsNamedLambda(JSFunction *fun) { return (fun->flags & 0x08) && fun->atom; } +const uint32 JS_ARGS_LENGTH_MAX = ((JSUint32)1 << (19)) - 1024; +typedef int js_static_assert51[(JS_ARGS_LENGTH_MAX <= ((JSUint32)1 << (30))) ? 1 : -1]; +typedef int js_static_assert52[(((JS_ARGS_LENGTH_MAX << 1) | 1) <= ((jsint)0x7fffffff)) ? 1 : -1]; +extern JSBool +js_XDRFunctionObject(JSXDRState *xdr, JSObject **objp); +extern JSBool +js_fun_apply(JSContext *cx, uintN argc, js::Value *vp); +extern JSBool +js_fun_call(JSContext *cx, uintN argc, js::Value *vp); +extern "C" { +typedef long int __jmp_buf[64] __attribute__ ((__aligned__ (16))); +struct __jmp_buf_tag + { + __jmp_buf __jmpbuf; + int __mask_was_saved; + __sigset_t __saved_mask; + }; +typedef struct __jmp_buf_tag jmp_buf[1]; +extern int setjmp (jmp_buf __env) throw (); +extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) throw (); +extern int _setjmp (struct __jmp_buf_tag __env[1]) throw (); +extern void longjmp (struct __jmp_buf_tag __env[1], int __val) + throw () __attribute__ ((__noreturn__)); +extern void _longjmp (struct __jmp_buf_tag __env[1], int __val) + throw () __attribute__ ((__noreturn__)); +typedef struct __jmp_buf_tag sigjmp_buf[1]; +extern void siglongjmp (sigjmp_buf __env, int __val) + throw () __attribute__ ((__noreturn__)); +extern void longjmp (struct __jmp_buf_tag __env[1], int __val) throw () __asm__ ("" "__longjmp_chk") + __attribute__ ((__noreturn__)); +extern void _longjmp (struct __jmp_buf_tag __env[1], int __val) throw () __asm__ ("" "__longjmp_chk") + __attribute__ ((__noreturn__)); +extern void siglongjmp (struct __jmp_buf_tag __env[1], int __val) throw () __asm__ ("" "__longjmp_chk") + __attribute__ ((__noreturn__)); +} +namespace js { +const size_t GC_CHUNK_SHIFT = 20; +const size_t GC_CHUNK_SIZE = size_t(1) << GC_CHUNK_SHIFT; +const size_t GC_CHUNK_MASK = GC_CHUNK_SIZE - 1; +__attribute__((visibility ("default"))) void * +AllocGCChunk(); +__attribute__((visibility ("default"))) void +FreeGCChunk(void *p); +class GCChunkAllocator { + public: + GCChunkAllocator() {} + void *alloc() { + void *chunk = doAlloc(); + ((void) 0); + return chunk; + } + void free(void *chunk) { + ((void) 0); + ((void) 0); + doFree(chunk); + } + private: + virtual void *doAlloc() { + return AllocGCChunk(); + } + virtual void doFree(void *chunk) { + FreeGCChunk(chunk); + } + GCChunkAllocator(const GCChunkAllocator &); + void operator=(const GCChunkAllocator &); +}; +extern GCChunkAllocator defaultGCChunkAllocator; +} +namespace js { +namespace gc { +enum ConservativeGCTest { + CGCT_VALID, + CGCT_VALIDWITHOFFSET, + CGCT_LOWBITSET, + CGCT_NOTARENA, + CGCT_NOTCHUNK, + CGCT_FREEARENA, + CGCT_WRONGTAG, + CGCT_NOTLIVE, + CGCT_END +}; +struct ConservativeGCStats { + uint32 counter[gc::CGCT_END]; + void add(const ConservativeGCStats &another) { + for (size_t i = 0; i != (sizeof (counter) / sizeof (counter)[0]); ++i) + counter[i] += another.counter[i]; + } + void dump(FILE *fp); +}; +} +} +extern __attribute__((visibility ("default"))) void +js_DumpGCStats(JSRuntime *rt, FILE *fp); +struct JSCompartment; +extern "C" void +js_TraceXML(JSTracer *trc, JSXML* thing); +namespace js { +struct Shape; +namespace gc { +enum FinalizeKind { + FINALIZE_OBJECT0, + FINALIZE_OBJECT2, + FINALIZE_OBJECT4, + FINALIZE_OBJECT8, + FINALIZE_OBJECT12, + FINALIZE_OBJECT16, + FINALIZE_OBJECT_LAST = FINALIZE_OBJECT16, + FINALIZE_FUNCTION, + FINALIZE_XML, + FINALIZE_SHORT_STRING, + FINALIZE_STRING, + FINALIZE_EXTERNAL_STRING, + FINALIZE_LIMIT +}; +const uintN JS_FINALIZE_OBJECT_LIMIT = 6; +struct ArenaHeader { + JSCompartment *compartment; + Arena *next; + FreeCell *freeList; + unsigned thingKind; + bool isUsed; + size_t thingSize; +}; +template +union ThingOrCell { + T t; + FreeCell cell; +}; +template +struct Things { + ThingOrCell things[N]; + char filler[R]; +}; +template +struct Things { + ThingOrCell things[N]; +}; +template +struct Arena { + static const size_t ArenaSize = 4096; + struct AlignedArenaHeader { + T align[(sizeof(ArenaHeader) + sizeof(T) - 1) / sizeof(T)]; + }; + union { + ArenaHeader aheader; + AlignedArenaHeader align; + }; + static const size_t ThingsPerArena = (ArenaSize - sizeof(AlignedArenaHeader)) / sizeof(T); + static const size_t FillerSize = ArenaSize - sizeof(AlignedArenaHeader) - sizeof(T) * ThingsPerArena; + Things t; + inline Chunk *chunk() const; + inline size_t arenaIndex() const; + inline ArenaHeader *header() { return &aheader; }; + inline MarkingDelay *getMarkingDelay() const; + inline ArenaBitmap *bitmap() const; + inline ConservativeGCTest mark(T *thing, JSTracer *trc); + void markDelayedChildren(JSTracer *trc); + inline bool inFreeList(void *thing) const; + inline T *getAlignedThing(void *thing); + void init(JSCompartment *compartment, unsigned thingKind); +}; +typedef int js_static_assert53[(sizeof(Arena) == 4096) ? 1 : -1]; +static const uint32 BLACK = 0; +struct ArenaBitmap { + static const size_t BitCount = Arena::ArenaSize / Cell::CellSize; + static const size_t BitWords = BitCount / (8 * 8); + uintptr_t bitmap[BitWords]; + __attribute__((always_inline)) inline bool isMarked(size_t bit, uint32 color) { + bit += color; + ((void) 0); + uintptr_t *word = &bitmap[bit / (8 * 8)]; + return *word & (uintptr_t(1) << (bit % (8 * 8))); + } + __attribute__((always_inline)) inline bool markIfUnmarked(size_t bit, uint32 color) { + ((void) 0); + uintptr_t *word = &bitmap[bit / (8 * 8)]; + uintptr_t mask = (uintptr_t(1) << (bit % (8 * 8))); + if (*word & mask) + return false; + *word |= mask; + if (color != BLACK) { + bit += color; + word = &bitmap[bit / (8 * 8)]; + mask = (uintptr_t(1) << (bit % (8 * 8))); + if (*word & mask) + return false; + *word |= mask; + } + return true; + } + __attribute__((always_inline)) inline void unmark(size_t bit, uint32 color) { + bit += color; + ((void) 0); + uintptr_t *word = &bitmap[bit / (8 * 8)]; + *word &= ~(uintptr_t(1) << (bit % (8 * 8))); + } +}; +typedef int js_static_assert54[(Arena::ArenaSize % Cell::CellSize == 0) ? 1 : -1]; +typedef int js_static_assert55[(ArenaBitmap::BitCount % (8 * 8) == 0) ? 1 : -1]; +struct MarkingDelay { + Arena *link; + uintptr_t unmarkedChildren; + jsuword start; + void init() + { + link = __null; + unmarkedChildren = 0; + } +}; +struct EmptyArenaLists { + Arena *cellFreeList; + Arena *freeLists[FINALIZE_LIMIT]; + void init() { + PodZero(this); + } + Arena *getOtherArena() { + Arena *arena = cellFreeList; + if (arena) { + cellFreeList = arena->header()->next; + return arena; + } + for (int i = 0; i < FINALIZE_LIMIT; i++) { + if ((arena = (Arena *) freeLists[i])) { + freeLists[i] = freeLists[i]->header()->next; + return arena; + } + } + ; + return __null; + } + template + inline Arena *getTypedFreeList(unsigned thingKind); + template + inline Arena *getNext(JSCompartment *comp, unsigned thingKind); + template + inline void insert(Arena *arena); +}; +template +inline Arena * +EmptyArenaLists::getTypedFreeList(unsigned thingKind) { + ((void) 0); + Arena *arena = (Arena*) freeLists[thingKind]; + if (arena) { + freeLists[thingKind] = freeLists[thingKind]->header()->next; + return arena; + } + return __null; +} +template +inline Arena * +EmptyArenaLists::getNext(JSCompartment *comp, unsigned thingKind) { + Arena *arena = getTypedFreeList(thingKind); + if (arena) { + ((void) 0); + ((void) 0); + arena->header()->isUsed = true; + arena->header()->thingKind = thingKind; + arena->header()->compartment = comp; + return arena; + } + arena = (Arena *)getOtherArena(); + ((void) 0); + arena->init(comp, thingKind); + return arena; +} +template +inline void +EmptyArenaLists::insert(Arena *arena) { + unsigned thingKind = arena->header()->thingKind; + ((void) 0); + arena->header()->next = freeLists[thingKind]; + freeLists[thingKind] = (Arena *) arena; +} +struct ChunkInfo { + Chunk *link; + JSRuntime *runtime; + EmptyArenaLists emptyArenaLists; + size_t age; + size_t numFree; +}; +struct Chunk { + static const size_t BytesPerArena = sizeof(Arena) + + sizeof(ArenaBitmap) + + sizeof(MarkingDelay); + static const size_t ArenasPerChunk = (GC_CHUNK_SIZE - sizeof(ChunkInfo)) / BytesPerArena; + Arena arenas[ArenasPerChunk]; + ArenaBitmap bitmaps[ArenasPerChunk]; + MarkingDelay markingDelay[ArenasPerChunk]; + ChunkInfo info; + void clearMarkBitmap(); + void init(JSRuntime *rt); + bool unused(); + bool hasAvailableArenas(); + bool withinArenasRange(Cell *cell); + template + Arena *allocateArena(JSCompartment *comp, unsigned thingKind); + template + void releaseArena(Arena *a); + JSRuntime *getRuntime(); +}; +typedef int js_static_assert56[(sizeof(Chunk) <= GC_CHUNK_SIZE) ? 1 : -1]; +typedef int js_static_assert57[(sizeof(Chunk) + Chunk::BytesPerArena > GC_CHUNK_SIZE) ? 1 : -1]; +Arena * +Cell::arena() const +{ + uintptr_t addr = uintptr_t(this); + ((void) 0); + addr &= ~(Arena::ArenaSize - 1); + return reinterpret_cast *>(addr); +} +Chunk * +Cell::chunk() const +{ + uintptr_t addr = uintptr_t(this); + ((void) 0); + addr &= ~(GC_CHUNK_SIZE - 1); + return reinterpret_cast(addr); +} +ArenaBitmap * +Cell::bitmap() const +{ + return &chunk()->bitmaps[arena()->arenaIndex()]; +} +size_t +Cell::cellIndex() const +{ + return reinterpret_cast(this) - reinterpret_cast(&arena()->t); +} +template +Chunk * +Arena::chunk() const +{ + uintptr_t addr = uintptr_t(this); + ((void) 0); + addr &= ~(GC_CHUNK_SIZE - 1); + return reinterpret_cast(addr); +} +template +size_t +Arena::arenaIndex() const +{ + return reinterpret_cast *>(this) - chunk()->arenas; +} +template +MarkingDelay * +Arena::getMarkingDelay() const +{ + return &chunk()->markingDelay[arenaIndex()]; +} +template +ArenaBitmap * +Arena::bitmap() const +{ + return &chunk()->bitmaps[arenaIndex()]; +} +template +inline T * +Arena::getAlignedThing(void *thing) +{ + jsuword start = reinterpret_cast(&t.things[0]); + jsuword offset = reinterpret_cast(thing) - start; + offset -= offset % aheader.thingSize; + return reinterpret_cast(start + offset); +} +static void +AssertValidColor(const void *thing, uint32 color) +{ + ((void) 0); +} +inline + bool +Cell::isMarked(uint32 color = BLACK) const +{ + AssertValidColor(this, color); + return bitmap()->isMarked(cellIndex(), color); +} +bool +Cell::markIfUnmarked(uint32 color = BLACK) const +{ + AssertValidColor(this, color); + return bitmap()->markIfUnmarked(cellIndex(), color); +} +void +Cell::unmark(uint32 color) const +{ + ((void) 0); + AssertValidColor(this, color); + bitmap()->unmark(cellIndex(), color); +} +JSCompartment * +Cell::compartment() const +{ + return arena()->header()->compartment; +} +template +static inline +Arena * +GetArena(Cell *cell) +{ + return reinterpret_cast *>(cell->arena()); +} +const size_t GC_ARENA_ALLOCATION_TRIGGER = 30 * js::GC_CHUNK_SIZE; +const float GC_HEAP_GROWTH_FACTOR = 3.0f; +static inline size_t +GetFinalizableTraceKind(size_t thingKind) +{ + typedef int js_static_assert58[(JSExternalString::TYPE_LIMIT == 8) ? 1 : -1]; + static const uint8 map[FINALIZE_LIMIT] = { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 1, + 1, + 1, + }; + ((void) 0); + return map[thingKind]; +} +static inline + bool +IsFinalizableStringKind(unsigned thingKind) +{ + return unsigned(FINALIZE_SHORT_STRING) <= thingKind && + thingKind <= unsigned(FINALIZE_EXTERNAL_STRING); +} +static inline intN +GetExternalStringGCType(JSExternalString *str) +{ + typedef int js_static_assert59[(FINALIZE_STRING + 1 == FINALIZE_EXTERNAL_STRING) ? 1 : -1]; + ((void) 0); + unsigned thingKind = str->externalStringType; + ((void) 0); + return intN(thingKind); +} +static inline uint32 +GetGCThingTraceKind(void *thing) +{ + ((void) 0); + if (JSString::isStatic(thing)) + return 1; + Cell *cell = reinterpret_cast(thing); + return GetFinalizableTraceKind(cell->arena()->header()->thingKind); +} +static inline JSRuntime * +GetGCThingRuntime(void *thing) +{ + return reinterpret_cast(thing)->chunk()->info.runtime; +} +struct ArenaList { + Arena *head; + Arena *cursor; + inline void init() { + head = __null; + cursor = __null; + } + inline Arena *getNextWithFreeList() { + Arena *a; + while (cursor != __null) { + ArenaHeader *aheader = cursor->header(); + a = cursor; + cursor = aheader->next; + if (aheader->freeList) + return a; + } + return __null; + } + inline void insert(Arena *a) { + a->header()->next = head; + head = a; + } + void releaseAll() { + while (head) { + Arena *next = head->header()->next; + head->chunk()->releaseArena(head); + head = next; + } + head = __null; + cursor = __null; + } + inline bool isEmpty() const { + return (head == __null); + } +}; +struct FreeLists { + FreeCell **finalizables[FINALIZE_LIMIT]; + void purge(); + inline FreeCell *getNext(uint32 kind) { + FreeCell *top = __null; + if (finalizables[kind]) { + top = *finalizables[kind]; + if (top) { + *finalizables[kind] = top->link; + } else { + finalizables[kind] = __null; + } + } + return top; + } + template + inline void populate(Arena *a, uint32 thingKind) { + finalizables[thingKind] = &a->header()->freeList; + } +}; +} +typedef Vector GCChunks; +struct GCPtrHasher +{ + typedef void *Lookup; + static HashNumber hash(void *key) { + return HashNumber(uintptr_t(key) >> JS_GCTHING_ZEROBITS); + } + static bool match(void *l, void *k) { return l == k; } +}; +typedef HashMap GCLocks; +struct RootInfo { + RootInfo() {} + RootInfo(const char *name, JSGCRootType type) : name(name), type(type) {} + const char *name; + JSGCRootType type; +}; +typedef js::HashMap, + js::SystemAllocPolicy> RootedValueMap; +typedef int js_static_assert60[(sizeof(HashNumber) == 4) ? 1 : -1]; +struct WrapperHasher +{ + typedef Value Lookup; + static HashNumber hash(Value key) { + uint64 bits = (Jsvalify(key)); + return (uint32)bits ^ (uint32)(bits >> 32); + } + static bool match(const Value &l, const Value &k) { return l == k; } +}; +typedef HashMap WrapperMap; +class AutoValueVector; +class AutoIdVector; +} +static inline void +CheckGCFreeListLink(js::gc::FreeCell *cell) +{ + ((void) 0) + ; + ((void) 0); +} +extern + bool +RefillFinalizableFreeList(JSContext *cx, unsigned thingKind); +extern intN +js_GetExternalStringGCType(JSString *str); +extern __attribute__((visibility ("default"))) uint32 +js_GetGCThingTraceKind(void *thing); +extern JSBool +js_InitGC(JSRuntime *rt, uint32 maxbytes); +extern void +js_FinishGC(JSRuntime *rt); +extern JSBool +js_AddRoot(JSContext *cx, js::Value *vp, const char *name); +extern JSBool +js_AddGCThingRoot(JSContext *cx, void **rp, const char *name); +extern uint32 +js_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data); +typedef struct JSPtrTable { + size_t count; + void **array; +} JSPtrTable; +extern JSBool +js_RegisterCloseableIterator(JSContext *cx, JSObject *obj); +extern JSBool +js_LockGCThingRT(JSRuntime *rt, void *thing); +extern void +js_UnlockGCThingRT(JSRuntime *rt, void *thing); +extern __attribute__((visibility ("default"))) bool +IsAboutToBeFinalized(JSContext *cx, void *thing); +extern __attribute__((visibility ("default"))) bool +js_GCThingIsMarked(void *thing, uintN color); +extern void +js_TraceStackFrame(JSTracer *trc, JSStackFrame *fp); +namespace js { +extern void +MarkRuntime(JSTracer *trc); +extern void +TraceRuntime(JSTracer *trc); +extern __attribute__((visibility ("default"))) void +MarkContext(JSTracer *trc, JSContext *acx); +extern void +TriggerGC(JSRuntime *rt); +extern void +TriggerCompartmentGC(JSCompartment *comp); +extern void +MaybeGC(JSContext *cx); +} +typedef enum JSGCInvocationKind { + GC_NORMAL = 0, + GC_LAST_CONTEXT = 1 +} JSGCInvocationKind; +extern void +js_GC(JSContext *cx, JSCompartment *comp, JSGCInvocationKind gckind); +extern void +js_WaitForGC(JSRuntime *rt); +extern void +js_DestroyScriptsToGC(JSContext *cx, JSCompartment *comp); +namespace js { +class GCHelperThread { + static const size_t FREE_ARRAY_SIZE = size_t(1) << 16; + static const size_t FREE_ARRAY_LENGTH = FREE_ARRAY_SIZE / sizeof(void *); + PRThread* thread; + PRCondVar* wakeup; + PRCondVar* sweepingDone; + bool shutdown; + bool sweeping; + Vector freeVector; + void **freeCursor; + void **freeCursorEnd; + __attribute__((visibility ("default"))) void + replenishAndFreeLater(void *ptr); + static void freeElementsAndArray(void **array, void **end) { + ((void) 0); + for (void **p = array; p != end; ++p) + js_free(*p); + js_free(array); + } + static void threadMain(void* arg); + void threadLoop(JSRuntime *rt); + void doSweep(); + public: + GCHelperThread() + : thread(__null), + wakeup(__null), + sweepingDone(__null), + shutdown(false), + sweeping(false), + freeCursor(__null), + freeCursorEnd(__null) { } + bool init(JSRuntime *rt); + void finish(JSRuntime *rt); + void startBackgroundSweep(JSRuntime *rt); + void waitBackgroundSweepEnd(JSRuntime *rt); + void freeLater(void *ptr) { + ((void) 0); + if (freeCursor != freeCursorEnd) + *freeCursor++ = ptr; + else + replenishAndFreeLater(ptr); + } +}; +struct GCChunkHasher { + typedef gc::Chunk *Lookup; + static HashNumber hash(gc::Chunk *chunk) { + ((void) 0); + return HashNumber(jsuword(chunk) >> GC_CHUNK_SHIFT); + } + static bool match(gc::Chunk *k, gc::Chunk *l) { + ((void) 0); + ((void) 0); + return k == l; + } +}; +typedef HashSet GCChunkSet; +struct ConservativeGCThreadData { + jsuword *nativeStackTop; + union { + jmp_buf jmpbuf; + jsuword words[(((sizeof(jmp_buf))+(sizeof(jsuword))-1)/(sizeof(jsuword)))]; + } registerSnapshot; + unsigned requestThreshold; + __attribute__((noinline)) void recordStackTop(); + void updateForRequestEnd(unsigned suspendCount) { + if (suspendCount) + recordStackTop(); + else + nativeStackTop = __null; + } + bool hasStackToScan() const { + return !!nativeStackTop; + } +}; +struct GCMarker : public JSTracer { + private: + uint32 color; + public: + jsuword stackLimit; + js::gc::Arena *unmarkedArenaStackTop; + public: + explicit GCMarker(JSContext *cx); + ~GCMarker(); + uint32 getMarkColor() const { + return color; + } + void setMarkColor(uint32 newColor) { + markDelayedChildren(); + color = newColor; + } + void delayMarkingChildren(void *thing); + __attribute__((visibility ("default"))) void markDelayedChildren(); +}; +void +MarkStackRangeConservatively(JSTracer *trc, Value *begin, Value *end); +} +extern void +js_FinalizeStringRT(JSRuntime *rt, JSString *str); +extern void +js_MarkTraps(JSTracer *trc); +namespace js { +namespace gc { +extern + bool +SetProtoCheckingForCycles(JSContext *cx, JSObject *obj, JSObject *proto); +JSCompartment * +NewCompartment(JSContext *cx, JSPrincipals *principals); +} +} +inline JSCompartment * +JSObject::getCompartment() const +{ + return compartment(); +} +struct JSFrameRegs +{ + + js::Value *sp; + jsbytecode *pc; + JSStackFrame *fp; +}; +enum JSInterpMode +{ + JSINTERP_NORMAL = 0, + JSINTERP_RECORD = 1, + JSINTERP_SAFEPOINT = 2, + JSINTERP_PROFILE = 3 +}; +enum JSFrameFlags +{ + JSFRAME_GLOBAL = 0x1, + JSFRAME_FUNCTION = 0x2, + JSFRAME_DUMMY = 0x4, + JSFRAME_EVAL = 0x8, + JSFRAME_DEBUGGER = 0x10, + JSFRAME_GENERATOR = 0x20, + JSFRAME_FLOATING_GENERATOR = 0x40, + JSFRAME_CONSTRUCTING = 0x80, + JSFRAME_ASSIGNING = 0x100, + JSFRAME_YIELDING = 0x200, + JSFRAME_FINISHED_IN_INTERPRETER = 0x400, + JSFRAME_OVERRIDE_ARGS = 0x1000, + JSFRAME_OVERFLOW_ARGS = 0x2000, + JSFRAME_UNDERFLOW_ARGS = 0x4000, + JSFRAME_HAS_IMACRO_PC = 0x8000, + JSFRAME_HAS_CALL_OBJ = 0x10000, + JSFRAME_HAS_ARGS_OBJ = 0x20000, + JSFRAME_HAS_HOOK_DATA = 0x40000, + JSFRAME_HAS_ANNOTATION = 0x80000, + JSFRAME_HAS_RVAL = 0x100000, + JSFRAME_HAS_SCOPECHAIN = 0x200000, + JSFRAME_HAS_PREVPC = 0x400000 +}; +namespace js { namespace mjit { struct JITScript; } } +struct JSStackFrame +{ + private: + mutable uint32 flags_; + union { + JSScript *script; + JSFunction *fun; + } exec; + union { + uintN nactual; + JSObject *obj; + JSScript *script; + } args; + mutable JSObject *scopeChain_; + JSStackFrame *prev_; + void *ncode_; + js::Value rval_; + jsbytecode *prevpc_; + jsbytecode *imacropc_; + void *hookData_; + void *annotation_; + friend class js::StackSpace; + friend class js::FrameRegsIter; + friend struct JSContext; + inline void initPrev(JSContext *cx); + public: + bool isFunctionFrame() const { + return !!(flags_ & JSFRAME_FUNCTION); + } + bool isGlobalFrame() const { + return !!(flags_ & JSFRAME_GLOBAL); + } + bool isDummyFrame() const { + return !!(flags_ & JSFRAME_DUMMY); + } + bool isScriptFrame() const { + return !!(flags_ & (JSFRAME_FUNCTION | JSFRAME_GLOBAL)); + } + bool isEvalFrame() const { + ((void) 0); + return flags_ & JSFRAME_EVAL; + } + bool isExecuteFrame() const { + return !!(flags_ & (JSFRAME_GLOBAL | JSFRAME_EVAL)); + } + inline void initCallFrame(JSContext *cx, JSObject &callee, JSFunction *fun, + uint32 nactual, uint32 flags); + inline void resetInvokeCallFrame(); + inline void initCallFrameCallerHalf(JSContext *cx, uint32 flags, void *ncode); + inline void initCallFrameEarlyPrologue(JSFunction *fun, uint32 nactual); + inline void initCallFrameLatePrologue(); + inline void initEvalFrame(JSContext *cx, JSScript *script, JSStackFrame *prev, + uint32 flags); + inline void initGlobalFrame(JSScript *script, JSObject &chain, uint32 flags); + inline void stealFrameAndSlots(js::Value *vp, JSStackFrame *otherfp, + js::Value *othervp, js::Value *othersp); + inline void initDummyFrame(JSContext *cx, JSObject &chain); + JSStackFrame *prev() const { + return prev_; + } + inline void resetGeneratorPrev(JSContext *cx); + js::Value *slots() const { + return (js::Value *)(this + 1); + } + js::Value *base() const { + return slots() + script()->nfixed; + } + js::Value &varSlot(uintN i) { + ((void) 0); + ((void) 0); + return slots()[i]; + } + jsbytecode *pc(JSContext *cx, JSStackFrame *next = __null); + jsbytecode *prevpc() { + ((void) 0); + return prevpc_; + } + JSScript *script() const { + ((void) 0); + return isFunctionFrame() + ? isEvalFrame() ? args.script : fun()->script() + : exec.script; + } + JSScript *functionScript() const { + ((void) 0); + return isEvalFrame() ? args.script : fun()->script(); + } + JSScript *globalScript() const { + ((void) 0); + return exec.script; + } + JSScript *maybeScript() const { + return isScriptFrame() ? script() : __null; + } + size_t numFixed() const { + return script()->nfixed; + } + size_t numSlots() const { + return script()->nslots; + } + size_t numGlobalVars() const { + ((void) 0); + return exec.script->nfixed; + } + JSFunction* fun() const { + ((void) 0); + return exec.fun; + } + JSFunction* maybeFun() const { + return isFunctionFrame() ? fun() : __null; + } + bool hasArgs() const { + return isFunctionFrame() && !isEvalFrame(); + } + uintN numFormalArgs() const { + ((void) 0); + return fun()->nargs; + } + js::Value &formalArg(uintN i) const { + ((void) 0); + return formalArgs()[i]; + } + js::Value *formalArgs() const { + ((void) 0); + return (js::Value *)this - numFormalArgs(); + } + js::Value *formalArgsEnd() const { + ((void) 0); + return (js::Value *)this; + } + js::Value *maybeFormalArgs() const { + return (flags_ & (JSFRAME_FUNCTION | JSFRAME_EVAL)) == JSFRAME_FUNCTION + ? formalArgs() + : __null; + } + inline uintN numActualArgs() const; + inline js::Value *actualArgs() const; + inline js::Value *actualArgsEnd() const; + inline js::Value &canonicalActualArg(uintN i) const; + template inline void forEachCanonicalActualArg(Op op); + template inline void forEachFormalArg(Op op); + inline void clearMissingArgs(); + bool hasArgsObj() const { + return !!(flags_ & JSFRAME_HAS_ARGS_OBJ); + } + JSObject &argsObj() const { + ((void) 0); + ((void) 0); + return *args.obj; + } + JSObject *maybeArgsObj() const { + return hasArgsObj() ? &argsObj() : __null; + } + inline void setArgsObj(JSObject &obj); + inline void clearArgsObj(); + js::Value &functionThis() const { + ((void) 0); + if (isEvalFrame()) + return ((js::Value *)this)[-1]; + return formalArgs()[-1]; + } + JSObject &constructorThis() const { + ((void) 0); + return formalArgs()[-1].toObject(); + } + js::Value &globalThis() const { + ((void) 0); + return ((js::Value *)this)[-1]; + } + js::Value &thisValue() const { + if (flags_ & (JSFRAME_EVAL | JSFRAME_GLOBAL)) + return ((js::Value *)this)[-1]; + return formalArgs()[-1]; + } + inline bool computeThis(JSContext *cx); + js::Value &calleeValue() const { + ((void) 0); + if (isEvalFrame()) + return ((js::Value *)this)[-2]; + return formalArgs()[-2]; + } + JSObject &callee() const { + ((void) 0); + return calleeValue().toObject(); + } + JSObject *maybeCallee() const { + return isFunctionFrame() ? &callee() : __null; + } + bool getValidCalleeObject(JSContext *cx, js::Value *vp); + JSObject &scopeChain() const { + ((void) 0); + if (!(flags_ & JSFRAME_HAS_SCOPECHAIN)) { + scopeChain_ = callee().getParent(); + flags_ |= JSFRAME_HAS_SCOPECHAIN; + } + return *scopeChain_; + } + bool hasCallObj() const { + return !!(flags_ & JSFRAME_HAS_CALL_OBJ); + } + inline JSObject &callObj() const; + inline JSObject *maybeCallObj() const; + inline void setScopeChainNoCallObj(JSObject &obj); + inline void setScopeChainAndCallObj(JSObject &obj); + inline void clearCallObj(); + bool hasImacropc() const { + return flags_ & JSFRAME_HAS_IMACRO_PC; + } + jsbytecode *imacropc() const { + ((void) 0); + return imacropc_; + } + jsbytecode *maybeImacropc() const { + return hasImacropc() ? imacropc() : __null; + } + void clearImacropc() { + flags_ &= ~JSFRAME_HAS_IMACRO_PC; + } + void setImacropc(jsbytecode *pc) { + ((void) 0); + ((void) 0); + imacropc_ = pc; + flags_ |= JSFRAME_HAS_IMACRO_PC; + } + void* annotation() const { + return (flags_ & JSFRAME_HAS_ANNOTATION) ? annotation_ : __null; + } + void setAnnotation(void *annot) { + flags_ |= JSFRAME_HAS_ANNOTATION; + annotation_ = annot; + } + bool hasHookData() const { + return !!(flags_ & JSFRAME_HAS_HOOK_DATA); + } + void* hookData() const { + ((void) 0); + return hookData_; + } + void* maybeHookData() const { + return hasHookData() ? hookData_ : __null; + } + void setHookData(void *v) { + hookData_ = v; + flags_ |= JSFRAME_HAS_HOOK_DATA; + } + const js::Value &returnValue() { + if (!(flags_ & JSFRAME_HAS_RVAL)) + rval_.setUndefined(); + return rval_; + } + void markReturnValue() { + flags_ |= JSFRAME_HAS_RVAL; + } + void setReturnValue(const js::Value &v) { + rval_ = v; + markReturnValue(); + } + void clearReturnValue() { + rval_.setUndefined(); + markReturnValue(); + } + void *nativeReturnAddress() const { + return ncode_; + } + void setNativeReturnAddress(void *addr) { + ncode_ = addr; + } + void **addressOfNativeReturnAddress() { + return &ncode_; + } + bool isGeneratorFrame() const { + return !!(flags_ & JSFRAME_GENERATOR); + } + bool isFloatingGenerator() const { + ((void) 0); + return !!(flags_ & JSFRAME_FLOATING_GENERATOR); + } + void initFloatingGenerator() { + ((void) 0); + flags_ |= (JSFRAME_GENERATOR | JSFRAME_FLOATING_GENERATOR); + } + void unsetFloatingGenerator() { + flags_ &= ~JSFRAME_FLOATING_GENERATOR; + } + void setFloatingGenerator() { + flags_ |= JSFRAME_FLOATING_GENERATOR; + } + bool isConstructing() const { + return !!(flags_ & JSFRAME_CONSTRUCTING); + } + uint32 isConstructingFlag() const { + ((void) 0); + ((void) 0); + return flags_; + } + bool isDebuggerFrame() const { + return !!(flags_ & JSFRAME_DEBUGGER); + } + bool isEvalOrDebuggerFrame() const { + return !!(flags_ & (JSFRAME_EVAL | JSFRAME_DEBUGGER)); + } + bool hasOverriddenArgs() const { + return !!(flags_ & JSFRAME_OVERRIDE_ARGS); + } + bool hasOverflowArgs() const { + return !!(flags_ & JSFRAME_OVERFLOW_ARGS); + } + void setOverriddenArgs() { + flags_ |= JSFRAME_OVERRIDE_ARGS; + } + bool isAssigning() const { + return !!(flags_ & JSFRAME_ASSIGNING); + } + void setAssigning() { + flags_ |= JSFRAME_ASSIGNING; + } + void clearAssigning() { + flags_ &= ~JSFRAME_ASSIGNING; + } + bool isYielding() { + return !!(flags_ & JSFRAME_YIELDING); + } + void setYielding() { + flags_ |= JSFRAME_YIELDING; + } + void clearYielding() { + flags_ &= ~JSFRAME_YIELDING; + } + void setFinishedInInterpreter() { + flags_ |= JSFRAME_FINISHED_IN_INTERPRETER; + } + bool finishedInInterpreter() const { + return !!(flags_ & JSFRAME_FINISHED_IN_INTERPRETER); + } + inline JSObject &varobj(js::StackSegment *seg) const; + inline JSObject &varobj(JSContext *cx) const; + static size_t offsetOfFlags() { + return __builtin_offsetof (JSStackFrame, flags_); + } + static size_t offsetOfExec() { + return __builtin_offsetof (JSStackFrame, exec); + } + void *addressOfArgs() { + return &args; + } + static size_t offsetOfScopeChain() { + return __builtin_offsetof (JSStackFrame, scopeChain_); + } + JSObject **addressOfScopeChain() { + ((void) 0); + return &scopeChain_; + } + static size_t offsetOfPrev() { + return __builtin_offsetof (JSStackFrame, prev_); + } + static size_t offsetOfReturnValue() { + return __builtin_offsetof (JSStackFrame, rval_); + } + static ptrdiff_t offsetOfncode() { + return __builtin_offsetof (JSStackFrame, ncode_); + } + static ptrdiff_t offsetOfCallee(JSFunction *fun) { + ((void) 0); + return -(fun->nargs + 2) * sizeof(js::Value); + } + static ptrdiff_t offsetOfThis(JSFunction *fun) { + return fun == __null + ? -1 * ptrdiff_t(sizeof(js::Value)) + : -(fun->nargs + 1) * ptrdiff_t(sizeof(js::Value)); + } + static ptrdiff_t offsetOfFormalArg(JSFunction *fun, uintN i) { + ((void) 0); + return (-(int)fun->nargs + i) * sizeof(js::Value); + } + static size_t offsetOfFixed(uintN i) { + return sizeof(JSStackFrame) + i * sizeof(js::Value); + } + void staticAsserts() { + typedef int js_static_assert61[(__builtin_offsetof (JSStackFrame, rval_) % sizeof(js::Value) == 0) ? 1 : -1]; + typedef int js_static_assert62[(sizeof(JSStackFrame) % sizeof(js::Value) == 0) ? 1 : -1]; + } + void methodjitStaticAsserts(); +}; +namespace js { +static const size_t VALUES_PER_STACK_FRAME = sizeof(JSStackFrame) / sizeof(Value); +extern JSObject * +GetBlockChain(JSContext *cx, JSStackFrame *fp); +extern JSObject * +GetBlockChainFast(JSContext *cx, JSStackFrame *fp, JSOp op, size_t oplen); +extern JSObject * +GetScopeChain(JSContext *cx); +extern JSObject * +GetScopeChain(JSContext *cx, JSStackFrame *fp); +extern JSObject * +GetScopeChainFast(JSContext *cx, JSStackFrame *fp, JSOp op, size_t oplen); +void +ReportIncompatibleMethod(JSContext *cx, Value *vp, Class *clasp); +template +bool GetPrimitiveThis(JSContext *cx, Value *vp, T *v); +inline void +PutActivationObjects(JSContext *cx, JSStackFrame *fp); +inline void +PutOwnedActivationObjects(JSContext *cx, JSStackFrame *fp); +extern + bool +BoxThisForVp(JSContext *cx, js::Value *vp); +struct CallArgs +{ + Value *argv_; + uintN argc_; + protected: + CallArgs() {} + CallArgs(Value *argv, uintN argc) : argv_(argv), argc_(argc) {} + public: + Value *base() const { return argv_ - 2; } + Value &callee() const { return argv_[-2]; } + Value &thisv() const { return argv_[-1]; } + Value &operator[](unsigned i) const { ((void) 0); return argv_[i]; } + Value *argv() const { return argv_; } + uintN argc() const { return argc_; } + Value &rval() const { return argv_[-2]; } +}; +extern + bool +Invoke(JSContext *cx, const CallArgs &args, uint32 flags); +class InvokeSessionGuard; +extern + bool +ExternalInvoke(JSContext *cx, const Value &thisv, const Value &fval, + uintN argc, Value *argv, Value *rval); +extern + bool +ExternalGetOrSet(JSContext *cx, JSObject *obj, jsid id, const Value &fval, + JSAccessMode mode, uintN argc, Value *argv, Value *rval); +extern + bool +InvokeConstructor(JSContext *cx, const CallArgs &args); +extern + bool +InvokeConstructorWithGivenThis(JSContext *cx, JSObject *thisobj, const Value &fval, + uintN argc, Value *argv, Value *rval); +extern + bool +ExternalInvokeConstructor(JSContext *cx, const Value &fval, uintN argc, Value *argv, + Value *rval); +extern + bool +DirectEval(JSContext *cx, JSFunction *evalfun, uint32 argc, Value *vp); +extern + bool +DirectEval(JSContext *cx, JSFunction *evalfun, uint32 argc, Value *vp); +extern + bool +Execute(JSContext *cx, JSObject *chain, JSScript *script, + JSStackFrame *prev, uintN flags, Value *result); +extern __attribute__((noinline)) + bool +Interpret(JSContext *cx, JSStackFrame *stopFp, uintN inlineCallCount = 0, JSInterpMode mode = JSINTERP_NORMAL); +extern + bool +RunScript(JSContext *cx, JSScript *script, JSStackFrame *fp); +extern + bool +CheckRedeclaration(JSContext *cx, JSObject *obj, jsid id, uintN attrs); +extern + bool +StrictlyEqual(JSContext *cx, const Value &lval, const Value &rval, JSBool *equal); +extern + bool +SameValue(JSContext *cx, const Value &v1, const Value &v2, JSBool *same); +extern JSType +TypeOfValue(JSContext *cx, const Value &v); +inline + bool +InstanceOf(JSContext *cx, JSObject *obj, Class *clasp, Value *argv) +{ + if (obj && obj->getClass() == clasp) + return true; + extern bool InstanceOfSlow(JSContext *, JSObject *, Class *, Value *); + return InstanceOfSlow(cx, obj, clasp, argv); +} +extern JSBool +HasInstance(JSContext *cx, JSObject *obj, const js::Value *v, JSBool *bp); +inline void * +GetInstancePrivate(JSContext *cx, JSObject *obj, Class *clasp, Value *argv) +{ + if (!InstanceOf(cx, obj, clasp, argv)) + return __null; + return obj->getPrivate(); +} +extern + bool +ValueToId(JSContext *cx, const Value &v, jsid *idp); +extern const js::Value & +GetUpvar(JSContext *cx, uintN level, js::UpvarCookie cookie); +} +extern JSBool +js_EnterWith(JSContext *cx, jsint stackIndex, JSOp op, size_t oplen); +extern void +js_LeaveWith(JSContext *cx); +extern JSBool +js_DoIncDec(JSContext *cx, const JSCodeSpec *cs, js::Value *vp, js::Value *vp2); +extern void +js_LogOpcode(JSContext *cx); +extern void +js_MeterOpcodePair(JSOp op1, JSOp op2); +extern void +js_MeterSlotOpcode(JSOp op, uint32 slot); +extern JSBool +js_UnwindScope(JSContext *cx, jsint stackDepth, JSBool normalUnwind); +extern JSBool +js_OnUnknownMethod(JSContext *cx, js::Value *vp); +extern js::Class * +js_IsActiveWithOrBlock(JSContext *cx, JSObject *obj, int stackDepth); +namespace js { +typedef double (*UnaryFunType)(double); +class MathCache +{ + static const unsigned SizeLog2 = 12; + static const unsigned Size = 1 << SizeLog2; + struct Entry { double in; UnaryFunType f; double out; }; + Entry table[Size]; + public: + MathCache(); + uintN hash(double x) { + union { double d; struct { uint32 one, two; } s; } u = { x }; + uint32 hash32 = u.s.one ^ u.s.two; + uint16 hash16 = (uint16)(hash32 ^ (hash32 >> 16)); + return (hash16 & (Size - 1)) ^ (hash16 >> (16 - SizeLog2)); + } + double lookup(UnaryFunType f, double x) { + uintN index = hash(x); + Entry &e = table[index]; + if (e.in == x && e.f == f) + return e.out; + e.in = x; + e.f = f; + return (e.out = f(x)); + } +}; +} +extern js::Class js_MathClass; +extern JSObject * +js_InitMathClass(JSContext *cx, JSObject *obj); +extern + bool +js_IsMathFunction(JSNative native); +extern void +js_InitRandom(JSContext *cx); +extern JSBool +js_math_abs(JSContext *cx, uintN argc, js::Value *vp); +extern JSBool +js_math_ceil(JSContext *cx, uintN argc, js::Value *vp); +extern JSBool +js_math_floor(JSContext *cx, uintN argc, js::Value *vp); +extern JSBool +js_math_max(JSContext *cx, uintN argc, js::Value *vp); +extern JSBool +js_math_min(JSContext *cx, uintN argc, js::Value *vp); +extern JSBool +js_math_round(JSContext *cx, uintN argc, js::Value *vp); +extern jsdouble +js_math_ceil_impl(jsdouble x); +extern jsdouble +js_math_floor_impl(jsdouble x); +extern jsdouble +js_math_round_impl(jsdouble x); +namespace js { +enum { + PCVCAP_PROTOBITS = 4, + PCVCAP_PROTOSIZE = ((JSUint32)1 << (PCVCAP_PROTOBITS)), + PCVCAP_PROTOMASK = (((JSUint32)1 << (PCVCAP_PROTOBITS)) - 1), + PCVCAP_SCOPEBITS = 4, + PCVCAP_SCOPESIZE = ((JSUint32)1 << (PCVCAP_SCOPEBITS)), + PCVCAP_SCOPEMASK = (((JSUint32)1 << (PCVCAP_SCOPEBITS)) - 1), + PCVCAP_TAGBITS = PCVCAP_PROTOBITS + PCVCAP_SCOPEBITS, + PCVCAP_TAGMASK = (((JSUint32)1 << (PCVCAP_TAGBITS)) - 1) +}; +const uint32 SHAPE_OVERFLOW_BIT = ((JSUint32)1 << (32 - PCVCAP_TAGBITS)); +class PCVal +{ + private: + enum { + OBJECT = 0, + SLOT = 1, + SHAPE = 2, + TAG = 3 + }; + jsuword v; + public: + bool isNull() const { return v == 0; } + void setNull() { v = 0; } + bool isFunObj() const { return (v & TAG) == OBJECT; } + JSObject &toFunObj() const { + ((void) 0); + return *reinterpret_cast(v); + } + void setFunObj(JSObject &obj) { + v = reinterpret_cast(&obj); + } + bool isSlot() const { return v & SLOT; } + uint32 toSlot() const { ((void) 0); return uint32(v) >> 1; } + void setSlot(uint32 slot) { v = (jsuword(slot) << 1) | SLOT; } + bool isShape() const { return (v & TAG) == SHAPE; } + const js::Shape *toShape() const { + ((void) 0); + return reinterpret_cast(v & ~TAG); + } + void setShape(const js::Shape *shape) { + ((void) 0); + v = reinterpret_cast(shape) | SHAPE; + } +}; +struct PropertyCacheEntry +{ + jsbytecode *kpc; + jsuword kshape; + jsuword vcap; + PCVal vword; + bool adding() const { return vcapTag() == 0 && kshape != vshape(); } + bool directHit() const { return vcapTag() == 0 && kshape == vshape(); } + jsuword vcapTag() const { return vcap & PCVCAP_TAGMASK; } + uint32 vshape() const { return uint32(vcap >> PCVCAP_TAGBITS); } + jsuword scopeIndex() const { return (vcap >> PCVCAP_PROTOBITS) & PCVCAP_SCOPEMASK; } + jsuword protoIndex() const { return vcap & PCVCAP_PROTOMASK; } + void assign(jsbytecode *kpc, jsuword kshape, jsuword vshape, + uintN scopeIndex, uintN protoIndex, PCVal vword) { + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + this->kpc = kpc; + this->kshape = kshape; + this->vcap = (vshape << PCVCAP_TAGBITS) | (scopeIndex << PCVCAP_PROTOBITS) | protoIndex; + this->vword = vword; + } +}; +class PropertyCache +{ + private: + enum { + SIZE_LOG2 = 12, + SIZE = ((JSUint32)1 << (SIZE_LOG2)), + MASK = (((JSUint32)1 << (SIZE_LOG2)) - 1) + }; + PropertyCacheEntry table[SIZE]; + JSBool empty; + static inline jsuword + hash(jsbytecode *pc, jsuword kshape) + { + return ((((jsuword(pc) >> SIZE_LOG2) ^ jsuword(pc)) + kshape) & MASK); + } + static inline bool matchShape(JSContext *cx, JSObject *obj, uint32 shape); + JSAtom *fullTest(JSContext *cx, jsbytecode *pc, JSObject **objp, + JSObject **pobjp, PropertyCacheEntry *entry); + inline void assertEmpty() {} + public: + __attribute__((always_inline)) inline void test(JSContext *cx, jsbytecode *pc, + JSObject *&obj, JSObject *&pobj, + PropertyCacheEntry *&entry, JSAtom *&atom); + __attribute__((always_inline)) inline bool testForSet(JSContext *cx, jsbytecode *pc, JSObject *obj, + PropertyCacheEntry **entryp, JSObject **obj2p, + JSAtom **atomp); + __attribute__((always_inline)) inline bool testForInit(JSRuntime *rt, jsbytecode *pc, JSObject *obj, + const js::Shape **shapep, PropertyCacheEntry **entryp); + PropertyCacheEntry *fill(JSContext *cx, JSObject *obj, uintN scopeIndex, + uintN protoIndex, JSObject *pobj, + const js::Shape *shape, JSBool adding = false); + void purge(JSContext *cx); + void purgeForScript(JSContext *cx, JSScript *script); +}; +} +namespace js { +struct ShapeHasher { + typedef js::Shape *Key; + typedef const js::Shape *Lookup; + static inline HashNumber hash(const Lookup l); + static inline bool match(Key k, Lookup l); +}; +typedef HashSet KidsHash; +class KidsPointer { + private: + enum { + SHAPE = 0, + HASH = 1, + TAG = 1 + }; + jsuword w; + public: + bool isNull() const { return !w; } + void setNull() { w = 0; } + bool isShape() const { return (w & TAG) == SHAPE && !isNull(); } + js::Shape *toShape() const { + ((void) 0); + return reinterpret_cast(w & ~jsuword(TAG)); + } + void setShape(js::Shape *shape) { + ((void) 0); + ((void) 0); + w = reinterpret_cast(shape) | SHAPE; + } + bool isHash() const { return (w & TAG) == HASH; } + KidsHash *toHash() const { + ((void) 0); + return reinterpret_cast(w & ~jsuword(TAG)); + } + void setHash(KidsHash *hash) { + ((void) 0); + ((void) 0); + w = reinterpret_cast(hash) | HASH; + } +}; +class PropertyTree +{ + friend struct ::JSFunction; + JSCompartment *compartment; + JSArenaPool arenaPool; + js::Shape *freeList; + bool insertChild(JSContext *cx, js::Shape *parent, js::Shape *child); + void removeChild(js::Shape *child); + PropertyTree(); + public: + enum { MAX_HEIGHT = 128 }; + PropertyTree(JSCompartment *comp) + : compartment(comp), freeList(__null) + { + PodZero(&arenaPool); + } + bool init(); + void finish(); + js::Shape *newShapeUnchecked(); + js::Shape *newShape(JSContext *cx); + js::Shape *getChild(JSContext *cx, js::Shape *parent, const js::Shape &child); + void orphanChildren(js::Shape *shape); + void sweepShapes(JSContext *cx); + void unmarkShapes(JSContext *cx); + static void dumpShapes(JSContext *cx); +}; +} +extern "C" { +struct timex +{ + unsigned int modes; + __syscall_slong_t offset; + __syscall_slong_t freq; + __syscall_slong_t maxerror; + __syscall_slong_t esterror; + int status; + __syscall_slong_t constant; + __syscall_slong_t precision; + __syscall_slong_t tolerance; + struct timeval time; + __syscall_slong_t tick; + __syscall_slong_t ppsfreq; + __syscall_slong_t jitter; + int shift; + __syscall_slong_t stabil; + __syscall_slong_t jitcnt; + __syscall_slong_t calcnt; + __syscall_slong_t errcnt; + __syscall_slong_t stbcnt; + int tai; + int :32; int :32; int :32; int :32; + int :32; int :32; int :32; int :32; + int :32; int :32; int :32; +}; +extern "C" { +extern int clock_adjtime (__clockid_t __clock_id, struct timex *__utx) throw (); +} +struct tm +{ + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; + long int tm_gmtoff; + const char *tm_zone; +}; +struct itimerspec + { + struct timespec it_interval; + struct timespec it_value; + }; +struct sigevent; +extern clock_t clock (void) throw (); +extern time_t time (time_t *__timer) throw (); +extern double difftime (time_t __time1, time_t __time0) + throw () __attribute__ ((__const__)); +extern time_t mktime (struct tm *__tp) throw (); +extern size_t strftime (char *__restrict __s, size_t __maxsize, + const char *__restrict __format, + const struct tm *__restrict __tp) throw (); +extern char *strptime (const char *__restrict __s, + const char *__restrict __fmt, struct tm *__tp) + throw (); +extern size_t strftime_l (char *__restrict __s, size_t __maxsize, + const char *__restrict __format, + const struct tm *__restrict __tp, + __locale_t __loc) throw (); +extern char *strptime_l (const char *__restrict __s, + const char *__restrict __fmt, struct tm *__tp, + __locale_t __loc) throw (); +extern struct tm *gmtime (const time_t *__timer) throw (); +extern struct tm *localtime (const time_t *__timer) throw (); +extern struct tm *gmtime_r (const time_t *__restrict __timer, + struct tm *__restrict __tp) throw (); +extern struct tm *localtime_r (const time_t *__restrict __timer, + struct tm *__restrict __tp) throw (); +extern char *asctime (const struct tm *__tp) throw (); +extern char *ctime (const time_t *__timer) throw (); +extern char *asctime_r (const struct tm *__restrict __tp, + char *__restrict __buf) throw (); +extern char *ctime_r (const time_t *__restrict __timer, + char *__restrict __buf) throw (); +extern char *__tzname[2]; +extern int __daylight; +extern long int __timezone; +extern char *tzname[2]; +extern void tzset (void) throw (); +extern int daylight; +extern long int timezone; +extern int stime (const time_t *__when) throw (); +extern time_t timegm (struct tm *__tp) throw (); +extern time_t timelocal (struct tm *__tp) throw (); +extern int dysize (int __year) throw () __attribute__ ((__const__)); +extern int nanosleep (const struct timespec *__requested_time, + struct timespec *__remaining); +extern int clock_getres (clockid_t __clock_id, struct timespec *__res) throw (); +extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) throw (); +extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp) + throw (); +extern int clock_nanosleep (clockid_t __clock_id, int __flags, + const struct timespec *__req, + struct timespec *__rem); +extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) throw (); +extern int timer_create (clockid_t __clock_id, + struct sigevent *__restrict __evp, + timer_t *__restrict __timerid) throw (); +extern int timer_delete (timer_t __timerid) throw (); +extern int timer_settime (timer_t __timerid, int __flags, + const struct itimerspec *__restrict __value, + struct itimerspec *__restrict __ovalue) throw (); +extern int timer_gettime (timer_t __timerid, struct itimerspec *__value) + throw (); +extern int timer_getoverrun (timer_t __timerid) throw (); +extern int timespec_get (struct timespec *__ts, int __base) + throw () __attribute__ ((__nonnull__ (1))); +extern int getdate_err; +extern struct tm *getdate (const char *__string); +extern int getdate_r (const char *__restrict __string, + struct tm *__restrict __resbufp); +} +struct JSContext; +class DSTOffsetCache { + public: + inline DSTOffsetCache(); + JSInt64 getDSTOffsetMilliseconds(int64 localTimeMilliseconds, JSContext *cx); + inline void purge(); + private: + JSInt64 computeDSTOffsetMilliseconds(int64 localTimeSeconds); + JSInt64 offsetMilliseconds; + JSInt64 rangeStartSeconds, rangeEndSeconds; + JSInt64 oldOffsetMilliseconds; + JSInt64 oldRangeStartSeconds, oldRangeEndSeconds; + static const JSInt64 MAX_UNIX_TIMET = 2145859200; + static const JSInt64 MILLISECONDS_PER_SECOND = 1000; + static const JSInt64 SECONDS_PER_MINUTE = 60; + static const JSInt64 SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE; + static const JSInt64 SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR; + static const JSInt64 RANGE_EXPANSION_AMOUNT = 30 * SECONDS_PER_DAY; + private: + void sanityCheck(); + void noteOffsetCalculation() { + ((void)0); + } + void noteCacheHit() { + ((void)0); + } + void noteCacheMissIncrease() { + ((void)0); + } + void noteCacheMissDecrease() { + ((void)0); + } + void noteCacheMissIncreasingOffsetChangeUpper() { + ((void)0); + } + void noteCacheMissIncreasingOffsetChangeExpand() { + ((void)0); + } + void noteCacheMissLargeIncrease() { + ((void)0); + } + void noteCacheMissDecreasingOffsetChangeLower() { + ((void)0); + } + void noteCacheMissDecreasingOffsetChangeExpand() { + ((void)0); + } + void noteCacheMissLargeDecrease() { + ((void)0); + } +}; +extern "C" { +typedef struct PRMJTime PRMJTime; +struct PRMJTime { + JSInt32 tm_usec; + JSInt8 tm_sec; + JSInt8 tm_min; + JSInt8 tm_hour; + JSInt8 tm_mday; + JSInt8 tm_mon; + JSInt8 tm_wday; + JSInt32 tm_year; + JSInt16 tm_yday; + JSInt8 tm_isdst; +}; +extern JSInt64 +PRMJ_Now(void); +extern JSInt32 +PRMJ_LocalGMTDifference(void); +extern size_t +PRMJ_FormatTime(char *buf, int buflen, const char *fmt, PRMJTime *tm); +} +typedef struct JSGSNCache { + jsbytecode *code; + JSDHashTable table; +} JSGSNCache; +extern void +js_PurgeGSNCache(JSGSNCache *cache); +namespace nanojit { +class Assembler; +class CodeAlloc; +class Fragment; +template struct DefaultHash; +template class HashMap; +template class Seq; +} +namespace js { +static const size_t MONITOR_N_GLOBAL_STATES = 4; +static const size_t FRAGMENT_TABLE_SIZE = 512; +static const size_t MAX_NATIVE_STACK_SLOTS = 4096; +static const size_t MAX_CALL_STACK_ENTRIES = 500; +static const size_t MAX_GLOBAL_SLOTS = 4096; +static const size_t GLOBAL_SLOTS_BUFFER_SIZE = MAX_GLOBAL_SLOTS + 1; +static const size_t MAX_SLOW_NATIVE_EXTRA_SLOTS = 16; +class VMAllocator; +class FrameInfoCache; +struct FrameInfo; +struct VMSideExit; +struct TreeFragment; +struct TracerState; +template class Queue; +typedef Queue SlotList; +class TypeMap; +class LoopProfile; +namespace mjit { +class JaegerCompartment; +} +class ContextAllocPolicy +{ + JSContext *cx; + public: + ContextAllocPolicy(JSContext *cx) : cx(cx) {} + JSContext *context() const { return cx; } + void *malloc(size_t bytes); + void free(void *p); + void *realloc(void *p, size_t bytes); + void reportAllocOverflow() const; +}; +class StackSegment +{ + JSContext *cx; + StackSegment *previousInContext; + StackSegment *previousInMemory; + JSStackFrame *initialFrame; + JSFrameRegs *suspendedRegs; + JSObject *initialVarObj; + bool saved; + public: + StackSegment() + : cx(__null), previousInContext(__null), previousInMemory(__null), + initialFrame(__null), suspendedRegs(((JSFrameRegs *)0x1)), + initialVarObj(__null), saved(false) + { + ((void) 0); + } + Value *valueRangeBegin() const { + return (Value *)(this + 1); + } + bool inContext() const { + ((void) 0); + ((void) 0); + return cx; + } + bool isActive() const { + ((void) 0); + ((void) 0); + return !suspendedRegs; + } + bool isSuspended() const { + ((void) 0); + ((void) 0); + return cx && suspendedRegs; + } + bool isSaved() const { + ((void) 0); + return saved; + } + void joinContext(JSContext *cx, JSStackFrame *f) { + ((void) 0); + this->cx = cx; + initialFrame = f; + suspendedRegs = __null; + ((void) 0); + } + void leaveContext() { + ((void) 0); + this->cx = __null; + initialFrame = __null; + suspendedRegs = ((JSFrameRegs *)0x1); + ((void) 0); + } + JSContext *maybeContext() const { + return cx; + } + void suspend(JSFrameRegs *regs) { + ((void) 0); + ((void) 0); + suspendedRegs = regs; + ((void) 0); + } + void resume() { + ((void) 0); + suspendedRegs = __null; + ((void) 0); + } + void save(JSFrameRegs *regs) { + ((void) 0); + suspend(regs); + saved = true; + ((void) 0); + } + void restore() { + ((void) 0); + saved = false; + resume(); + ((void) 0); + } + JSStackFrame *getInitialFrame() const { + ((void) 0); + return initialFrame; + } + inline JSFrameRegs *getCurrentRegs() const; + inline JSStackFrame *getCurrentFrame() const; + JSFrameRegs *getSuspendedRegs() const { + ((void) 0); + return suspendedRegs; + } + JSStackFrame *getSuspendedFrame() const { + return suspendedRegs->fp; + } + void setPreviousInContext(StackSegment *seg) { + previousInContext = seg; + } + StackSegment *getPreviousInContext() const { + return previousInContext; + } + void setPreviousInMemory(StackSegment *seg) { + previousInMemory = seg; + } + StackSegment *getPreviousInMemory() const { + return previousInMemory; + } + void setInitialVarObj(JSObject *obj) { + ((void) 0); + initialVarObj = obj; + } + bool hasInitialVarObj() { + ((void) 0); + return initialVarObj != __null; + } + JSObject &getInitialVarObj() const { + ((void) 0); + return *initialVarObj; + } +}; +static const size_t VALUES_PER_STACK_SEGMENT = sizeof(StackSegment) / sizeof(Value); +typedef int js_static_assert63[(sizeof(StackSegment) % sizeof(Value) == 0) ? 1 : -1]; +class InvokeArgsGuard : public CallArgs +{ + friend class StackSpace; + JSContext *cx; + StackSegment *seg; + Value *prevInvokeArgEnd; + public: + InvokeArgsGuard() : cx(__null), seg(__null) {} + ~InvokeArgsGuard(); + bool pushed() const { return cx != __null; } +}; +struct InvokeArgsAlreadyOnTheStack : CallArgs +{ + InvokeArgsAlreadyOnTheStack(Value *vp, uintN argc) : CallArgs(vp + 2, argc) {} +}; +class InvokeFrameGuard +{ + friend class StackSpace; + JSContext *cx_; + JSFrameRegs regs_; + JSFrameRegs *prevRegs_; + public: + InvokeFrameGuard() : cx_(__null) {} + ~InvokeFrameGuard() { if (pushed()) pop(); } + bool pushed() const { return cx_ != __null; } + JSContext *pushedFrameContext() const { ((void) 0); return cx_; } + void pop(); + JSStackFrame *fp() const { return regs_.fp; } +}; +class FrameGuard +{ + friend class StackSpace; + JSContext *cx_; + StackSegment *seg_; + Value *vp_; + JSStackFrame *fp_; + public: + FrameGuard() : cx_(__null), vp_(__null), fp_(__null) {} + ~FrameGuard(); + bool pushed() const { return cx_ != __null; } + StackSegment *segment() const { return seg_; } + Value *vp() const { return vp_; } + JSStackFrame *fp() const { return fp_; } +}; +class ExecuteFrameGuard : public FrameGuard +{ + friend class StackSpace; + JSFrameRegs regs_; +}; +class DummyFrameGuard : public FrameGuard +{ + friend class StackSpace; + JSFrameRegs regs_; +}; +class GeneratorFrameGuard : public FrameGuard +{}; +class StackSpace +{ + Value *base; + Value *end; + StackSegment *currentSegment; + Value *invokeArgEnd; + friend class InvokeArgsGuard; + friend class InvokeFrameGuard; + friend class FrameGuard; + bool pushSegmentForInvoke(JSContext *cx, uintN argc, InvokeArgsGuard *ag); + void popSegmentForInvoke(const InvokeArgsGuard &ag); + bool pushInvokeFrameSlow(JSContext *cx, const InvokeArgsGuard &ag, + InvokeFrameGuard *fg); + void popInvokeFrameSlow(const CallArgs &args); + bool getSegmentAndFrame(JSContext *cx, uintN vplen, uintN nslots, + FrameGuard *fg) const; + void pushSegmentAndFrame(JSContext *cx, JSFrameRegs *regs, FrameGuard *fg); + void popSegmentAndFrame(JSContext *cx); + struct EnsureSpaceCheck { + inline bool operator()(const StackSpace &, JSContext *, Value *, uintN); + }; + struct LimitCheck { + JSStackFrame *base; + Value **limit; + LimitCheck(JSStackFrame *base, Value **limit) : base(base), limit(limit) {} + inline bool operator()(const StackSpace &, JSContext *, Value *, uintN); + }; + template + inline JSStackFrame *getCallFrame(JSContext *cx, Value *sp, uintN nactual, + JSFunction *fun, JSScript *script, + uint32 *pflags, Check check) const; + inline void popInvokeArgs(const InvokeArgsGuard &args); + inline void popInvokeFrame(const InvokeFrameGuard &ag); + inline Value *firstUnused() const; + inline bool isCurrentAndActive(JSContext *cx) const; + friend class AllFramesIter; + StackSegment *getCurrentSegment() const { return currentSegment; } + public: + static const size_t CAPACITY_VALS = 512 * 1024; + static const size_t CAPACITY_BYTES = CAPACITY_VALS * sizeof(Value); + static const size_t COMMIT_VALS = 16 * 1024; + static const size_t COMMIT_BYTES = COMMIT_VALS * sizeof(Value); + static const size_t STACK_QUOTA = (VALUES_PER_STACK_FRAME + 18) * + 3000; + bool init(); + void finish(); + inline bool ensureEnoughSpaceToEnterTrace(); + static const ptrdiff_t MAX_TRACE_SPACE_VALS = + MAX_NATIVE_STACK_SLOTS + MAX_CALL_STACK_ENTRIES * VALUES_PER_STACK_FRAME + + (VALUES_PER_STACK_SEGMENT + VALUES_PER_STACK_FRAME ); + void mark(JSTracer *trc); + bool pushInvokeArgs(JSContext *cx, uintN argc, InvokeArgsGuard *ag); + bool getInvokeFrame(JSContext *cx, const CallArgs &args, JSFunction *fun, + JSScript *script, uint32 *flags, InvokeFrameGuard *fg) const; + void pushInvokeFrame(JSContext *cx, const CallArgs &args, InvokeFrameGuard *fg); + bool getExecuteFrame(JSContext *cx, JSScript *script, ExecuteFrameGuard *fg) const; + void pushExecuteFrame(JSContext *cx, JSObject *initialVarObj, ExecuteFrameGuard *fg); + inline JSStackFrame *getInlineFrame(JSContext *cx, Value *sp, uintN nactual, + JSFunction *fun, JSScript *script, + uint32 *flags) const; + inline void pushInlineFrame(JSContext *cx, JSScript *script, JSStackFrame *fp, + JSFrameRegs *regs); + inline void popInlineFrame(JSContext *cx, JSStackFrame *prev, js::Value *newsp); + bool getGeneratorFrame(JSContext *cx, uintN vplen, uintN nslots, + GeneratorFrameGuard *fg); + void pushGeneratorFrame(JSContext *cx, JSFrameRegs *regs, GeneratorFrameGuard *fg); + bool pushDummyFrame(JSContext *cx, JSObject &scopeChain, DummyFrameGuard *fg); + inline JSStackFrame *getInlineFrameWithinLimit(JSContext *cx, Value *sp, uintN nactual, + JSFunction *fun, JSScript *script, uint32 *flags, + JSStackFrame *base, Value **limit) const; + inline Value *getStackLimit(JSContext *cx); + bool bumpCommitAndLimit(JSStackFrame *base, Value *from, uintN nvals, Value **limit) const; + inline bool ensureSpace(JSContext *maybecx, Value *from, ptrdiff_t nvals) const; +}; +typedef int js_static_assert64[(StackSpace::CAPACITY_VALS % StackSpace::COMMIT_VALS == 0) ? 1 : -1]; +class FrameRegsIter +{ + JSContext *cx; + StackSegment *curseg; + JSStackFrame *curfp; + Value *cursp; + jsbytecode *curpc; + void initSlow(); + void incSlow(JSStackFrame *fp, JSStackFrame *prev); + public: + inline FrameRegsIter(JSContext *cx); + bool done() const { return curfp == __null; } + inline FrameRegsIter &operator++(); + JSStackFrame *fp() const { return curfp; } + Value *sp() const { return cursp; } + jsbytecode *pc() const { return curpc; } +}; +class AllFramesIter +{ +public: + AllFramesIter(JSContext *cx); + bool done() const { return curfp == __null; } + AllFramesIter& operator++(); + JSStackFrame *fp() const { return curfp; } +private: + StackSegment *curcs; + JSStackFrame *curfp; +}; +} +struct JSPendingProxyOperation { + JSPendingProxyOperation *next; + JSObject *object; +}; +struct JSThreadData { + unsigned requestDepth; + volatile int32 interruptFlags; + js::StackSpace stackSpace; + bool waiveGCQuota; + JSGSNCache gsnCache; + js::PropertyCache propertyCache; + DtoaState *dtoaState; + jsuword *nativeStackBase; + JSPendingProxyOperation *pendingProxyOperation; + js::ConservativeGCThreadData conservativeGC; + bool init(); + void finish(); + void mark(JSTracer *trc); + void purge(JSContext *cx); + inline void triggerOperationCallback(JSRuntime *rt); +}; +struct JSThread { + typedef js::HashMap, + js::SystemAllocPolicy> Map; + JSCList contextList; + void *id; + unsigned suspendCount; + JSThreadData data; +}; +extern JSThread * +js_CurrentThread(JSRuntime *rt); +extern JSBool +js_InitContextThread(JSContext *cx); +extern void +js_ClearContextThread(JSContext *cx); +typedef enum JSDestroyContextMode { + JSDCM_NO_GC, + JSDCM_MAYBE_GC, + JSDCM_FORCE_GC, + JSDCM_NEW_FAILED +} JSDestroyContextMode; +typedef enum JSRuntimeState { + JSRTS_DOWN, + JSRTS_LAUNCHING, + JSRTS_UP, + JSRTS_LANDING +} JSRuntimeState; +typedef struct JSPropertyTreeEntry { + JSDHashEntryHdr hdr; + js::Shape *child; +} JSPropertyTreeEntry; +typedef void +(* JSActivityCallback)(void *arg, JSBool active); +namespace js { +typedef js::Vector WrapperVector; +} +struct JSRuntime { + JSCompartment *atomsCompartment; + bool atomsCompartmentIsLocked; + js::WrapperVector compartments; + JSRuntimeState state; + JSContextCallback cxCallback; + JSCompartmentCallback compartmentCallback; + void setActivityCallback(JSActivityCallback cb, void *arg) { + activityCallback = cb; + activityCallbackArg = arg; + } + JSActivityCallback activityCallback; + void *activityCallbackArg; + uint32 protoHazardShape; + js::GCChunkSet gcChunkSet; + js::RootedValueMap gcRootsHash; + js::GCLocks gcLocksHash; + jsrefcount gcKeepAtoms; + size_t gcBytes; + size_t gcTriggerBytes; + size_t gcLastBytes; + size_t gcMaxBytes; + size_t gcMaxMallocBytes; + size_t gcChunksWaitingToExpire; + uint32 gcEmptyArenaPoolLifespan; + uint32 gcNumber; + js::GCMarker *gcMarkingTracer; + uint32 gcTriggerFactor; + int64 gcJitReleaseTime; + JSGCMode gcMode; + volatile bool gcIsNeeded; + JSCompartment *gcTriggerCompartment; + JSCompartment *gcCurrentCompartment; + bool gcPoke; + bool gcMarkAndSweep; + bool gcRunning; + bool gcRegenShapes; + JSGCCallback gcCallback; + private: + volatile ptrdiff_t gcMallocBytes; + public: + js::GCChunkAllocator *gcChunkAllocator; + void setCustomGCChunkAllocator(js::GCChunkAllocator *allocator) { + ((void) 0); + ((void) 0); + gcChunkAllocator = allocator; + } + JSTraceDataOp gcExtraRootsTraceOp; + void *gcExtraRootsData; + js::Value NaNValue; + js::Value negativeInfinityValue; + js::Value positiveInfinityValue; + JSFlatString *emptyString; + JSCList contextList; + JSDebugHooks globalDebugHooks; + JSBool debugMode; + JSCList trapList; + JSCList watchPointList; + void *data; + PRLock *gcLock; + PRCondVar *gcDone; + PRCondVar *requestDone; + uint32 requestCount; + JSThread *gcThread; + js::GCHelperThread gcHelperThread; + PRLock *rtLock; + PRCondVar *stateChange; + PRLock *debuggerLock; + JSThread::Map threads; + uint32 debuggerMutations; + JSSecurityCallbacks *securityCallbacks; + const JSStructuredCloneCallbacks *structuredCloneCallbacks; + int32 propertyRemovals; + struct JSHashTable *scriptFilenameTable; + JSCList scriptFilenamePrefixes; + PRLock *scriptFilenameTableLock; + const char *thousandsSeparator; + const char *decimalSeparator; + const char *numGrouping; + JSObject *anynameObject; + JSObject *functionNamespaceObject; + volatile int32 interruptCounter; + volatile uint32 shapeGen; + JSAtomState atomState; + JSWrapObjectCallback wrapObjectCallback; + JSPreWrapCallback preWrapObjectCallback; + uint32 stringMemoryUsed; + JSRuntime(); + ~JSRuntime(); + bool init(uint32 maxbytes); + void setGCTriggerFactor(uint32 factor); + void setGCLastBytes(size_t lastBytes); + void* malloc(size_t bytes, JSContext *cx = __null) { + updateMallocCounter(bytes); + void *p = ::js_malloc(bytes); + return (__builtin_expect((!!p), 1)) ? p : onOutOfMemory(__null, bytes, cx); + } + void* calloc(size_t bytes, JSContext *cx = __null) { + updateMallocCounter(bytes); + void *p = ::js_calloc(bytes); + return (__builtin_expect((!!p), 1)) ? p : onOutOfMemory(reinterpret_cast(1), bytes, cx); + } + void* realloc(void* p, size_t oldBytes, size_t newBytes, JSContext *cx = __null) { + ((void) 0); + updateMallocCounter(newBytes - oldBytes); + void *p2 = ::js_realloc(p, newBytes); + return (__builtin_expect((!!p2), 1)) ? p2 : onOutOfMemory(p, newBytes, cx); + } + void* realloc(void* p, size_t bytes, JSContext *cx = __null) { + if (!p) + updateMallocCounter(bytes); + void *p2 = ::js_realloc(p, bytes); + return (__builtin_expect((!!p2), 1)) ? p2 : onOutOfMemory(p, bytes, cx); + } + void free(void* p) { ::js_free(p); } + bool isGCMallocLimitReached() const { return gcMallocBytes <= 0; } + void resetGCMallocBytes() { gcMallocBytes = ptrdiff_t(gcMaxMallocBytes); } + void setGCMaxMallocBytes(size_t value) { + gcMaxMallocBytes = (ptrdiff_t(value) >= 0) ? value : size_t(-1) >> 1; + resetGCMallocBytes(); + } + void updateMallocCounter(size_t nbytes) { + ptrdiff_t newCount = gcMallocBytes - ptrdiff_t(nbytes); + gcMallocBytes = newCount; + if ((__builtin_expect((newCount <= 0), 0))) + onTooMuchMalloc(); + } + private: + __attribute__((visibility ("default"))) void onTooMuchMalloc(); + __attribute__((visibility ("default"))) void * onOutOfMemory(void *p, size_t nbytes, JSContext *cx); +}; +struct JSArgumentFormatMap { + const char *format; + size_t length; + JSArgumentFormatter formatter; + JSArgumentFormatMap *next; +}; +typedef struct JSResolvingKey { + JSObject *obj; + jsid id; +} JSResolvingKey; +typedef struct JSResolvingEntry { + JSDHashEntryHdr hdr; + JSResolvingKey key; + uint32 flags; +} JSResolvingEntry; +extern const JSDebugHooks js_NullDebugHooks; +namespace js { +class AutoGCRooter; +static inline + bool +OptionsHasXML(uint32 options) +{ + return !!(options & ((JSUint32)1 << (6))); +} +static inline + bool +OptionsHasAnonFunFix(uint32 options) +{ + return !!(options & ((JSUint32)1 << (10))); +} +static inline + bool +OptionsSameVersionFlags(uint32 self, uint32 other) +{ + static const uint32 mask = ((JSUint32)1 << (6)) | ((JSUint32)1 << (10)); + return !((self & mask) ^ (other & mask)); +} +namespace VersionFlags { +static const uintN MASK = 0x0FFF; +static const uintN HAS_XML = 0x1000; +static const uintN ANONFUNFIX = 0x2000; +static const uintN FULL_MASK = 0x3FFF; +} +static inline JSVersion +VersionNumber(JSVersion version) +{ + return JSVersion(uint32(version) & VersionFlags::MASK); +} +static inline + bool +VersionHasXML(JSVersion version) +{ + return !!(version & VersionFlags::HAS_XML); +} +static inline + bool +VersionShouldParseXML(JSVersion version) +{ + return VersionHasXML(version) || VersionNumber(version) >= JSVERSION_1_6; +} +static inline + bool +VersionHasAnonFunFix(JSVersion version) +{ + return !!(version & VersionFlags::ANONFUNFIX); +} +static inline void +VersionSetXML(JSVersion *version, bool enable) +{ + if (enable) + *version = JSVersion(uint32(*version) | VersionFlags::HAS_XML); + else + *version = JSVersion(uint32(*version) & ~VersionFlags::HAS_XML); +} +static inline void +VersionSetAnonFunFix(JSVersion *version, bool enable) +{ + if (enable) + *version = JSVersion(uint32(*version) | VersionFlags::ANONFUNFIX); + else + *version = JSVersion(uint32(*version) & ~VersionFlags::ANONFUNFIX); +} +static inline JSVersion +VersionExtractFlags(JSVersion version) +{ + return JSVersion(uint32(version) & ~VersionFlags::MASK); +} +static inline void +VersionCopyFlags(JSVersion *version, JSVersion from) +{ + *version = JSVersion(VersionNumber(*version) | VersionExtractFlags(from)); +} +static inline + bool +VersionHasFlags(JSVersion version) +{ + return !!VersionExtractFlags(version); +} +static inline uintN +VersionFlagsToOptions(JSVersion version) +{ + uintN copts = (VersionHasXML(version) ? ((JSUint32)1 << (6)) : 0) | + (VersionHasAnonFunFix(version) ? ((JSUint32)1 << (10)) : 0); + ((void) 0); + return copts; +} +static inline JSVersion +OptionFlagsToVersion(uintN options, JSVersion version) +{ + VersionSetXML(&version, OptionsHasXML(options)); + VersionSetAnonFunFix(&version, OptionsHasAnonFunFix(options)); + return version; +} +static inline + bool +VersionIsKnown(JSVersion version) +{ + return VersionNumber(version) != JSVERSION_UNKNOWN; +} +typedef js::HashSet, + js::SystemAllocPolicy> BusyArraysMap; +} +struct JSContext +{ + explicit JSContext(JSRuntime *rt); + JSCList link; + private: + JSVersion defaultVersion; + JSVersion versionOverride; + bool hasVersionOverride; + JSBool throwing; + js::Value exception; + uintN runOptions; + public: + JSLocaleCallbacks *localeCallbacks; + JSDHashTable *resolvingTable; + JSPackedBool generatingError; + jsuword stackLimit; + size_t scriptStackQuota; + JSRuntime *const runtime; + JSCompartment *compartment; + + JSFrameRegs *regs; + JSStackFrame* fp() { + ((void) 0); + return regs->fp; + } + JSStackFrame* maybefp() { + ((void) 0); + return regs ? regs->fp : __null; + } + bool hasfp() { + ((void) 0); + return !!regs; + } + public: + friend class js::StackSpace; + friend bool js::Interpret(JSContext *, JSStackFrame *, uintN, JSInterpMode); + void resetCompartment(); + void wrapPendingException(); + void setCurrentRegs(JSFrameRegs *regs) { + ((void) 0); + this->regs = regs; + } + JSArenaPool tempPool; + JSArenaPool regExpPool; + JSObject *globalObject; + JSSharpObjectMap sharpObjectMap; + js::BusyArraysMap busyArrays; + JSArgumentFormatMap *argumentFormatMap; + char *lastMessage; + JSErrorReporter errorReporter; + JSOperationCallback operationCallback; + uintN interpLevel; + void *data; + void *data2; + private: + js::StackSegment *currentSegment; + public: + void assertSegmentsInSync() const { + } + bool hasActiveSegment() const { + assertSegmentsInSync(); + return !!regs; + } + js::StackSegment *activeSegment() const { + ((void) 0); + return currentSegment; + } + js::StackSegment *getCurrentSegment() const { + assertSegmentsInSync(); + return currentSegment; + } + inline js::RegExpStatics *regExpStatics(); + void pushSegmentAndFrame(js::StackSegment *newseg, JSFrameRegs ®s); + void popSegmentAndFrame(); + void saveActiveSegment(); + void restoreSegment(); + inline JSStackFrame *computeNextFrame(JSStackFrame *fp); + js::StackSegment *containingSegment(const JSStackFrame *target); + JSStackFrame *findFrameAtLevel(uintN targetLevel) const { + JSStackFrame *fp = regs->fp; + while (true) { + ((void) 0); + if (fp->script()->staticLevel == targetLevel) + break; + fp = fp->prev(); + } + return fp; + } + public: + bool canSetDefaultVersion() const { + return !regs && !hasVersionOverride; + } + void overrideVersion(JSVersion newVersion) { + ((void) 0); + versionOverride = newVersion; + hasVersionOverride = true; + } + void setDefaultVersion(JSVersion version) { + defaultVersion = version; + } + void clearVersionOverride() { hasVersionOverride = false; } + JSVersion getDefaultVersion() const { return defaultVersion; } + bool isVersionOverridden() const { return hasVersionOverride; } + JSVersion getVersionOverride() const { + ((void) 0); + return versionOverride; + } + bool maybeOverrideVersion(JSVersion newVersion) { + if (canSetDefaultVersion()) { + setDefaultVersion(newVersion); + return false; + } + overrideVersion(newVersion); + return true; + } + private: + void maybeMigrateVersionOverride() { + if ((__builtin_expect((!isVersionOverridden() || currentSegment), 1))) + return; + defaultVersion = versionOverride; + clearVersionOverride(); + } + public: + JSVersion findVersion() const { + if (hasVersionOverride) + return versionOverride; + if (regs) { + JSStackFrame *fp = regs->fp; + while (fp && !fp->isScriptFrame()) + fp = fp->prev(); + if (fp) + return fp->script()->getVersion(); + } + return defaultVersion; + } + void setRunOptions(uintN ropts) { + ((void) 0); + runOptions = ropts; + } + void setCompileOptions(uintN newcopts) { + ((void) 0); + if ((__builtin_expect((getCompileOptions() == newcopts), 1))) + return; + JSVersion version = findVersion(); + JSVersion newVersion = js::OptionFlagsToVersion(newcopts, version); + maybeOverrideVersion(newVersion); + } + uintN getRunOptions() const { return runOptions; } + uintN getCompileOptions() const { return js::VersionFlagsToOptions(findVersion()); } + uintN allOptions() const { return getRunOptions() | getCompileOptions(); } + bool hasRunOption(uintN ropt) const { + ((void) 0); + return !!(runOptions & ropt); + } + bool hasStrictOption() const { return hasRunOption(((JSUint32)1 << (0))); } + bool hasWErrorOption() const { return hasRunOption(((JSUint32)1 << (1))); } + bool hasAtLineOption() const { return hasRunOption(((JSUint32)1 << (5))); } + JSThread *thread; + unsigned outstandingRequests; + JSCList threadLinks; + js::AutoGCRooter *autoGCRooters; + const JSDebugHooks *debugHooks; + JSSecurityCallbacks *securityCallbacks; + uintN resolveFlags; + int64 rngSeed; + js::Value iterValue; + void updateJITEnabled(); + DSTOffsetCache dstOffsetCache; + JSObject *enumerators; + private: + js::Vector genStack; + public: + JSGenerator *generatorFor(JSStackFrame *fp) const; + inline bool ensureGeneratorStackSpace(); + bool enterGenerator(JSGenerator *gen) { + return genStack.append(gen); + } + void leaveGenerator(JSGenerator *gen) { + ((void) 0); + genStack.popBack(); + } + js::GCHelperThread *gcBackgroundFree; + inline void* malloc(size_t bytes) { + return runtime->malloc(bytes, this); + } + inline void* mallocNoReport(size_t bytes) { + ((void) 0); + return runtime->malloc(bytes, __null); + } + inline void* calloc(size_t bytes) { + ((void) 0); + return runtime->calloc(bytes, this); + } + inline void* realloc(void* p, size_t bytes) { + return runtime->realloc(p, bytes, this); + } + inline void* realloc(void* p, size_t oldBytes, size_t newBytes) { + return runtime->realloc(p, oldBytes, newBytes, this); + } + inline void free(void* p) { + if (gcBackgroundFree) { + gcBackgroundFree->freeLater(p); + return; + } + runtime->free(p); + } + template + __attribute__((always_inline)) inline T *create() { + void *memory = this->malloc(sizeof(T)); if (!memory) return __null; return new(memory) T (); + } + template + __attribute__((always_inline)) inline T *create(const P1 &p1) { + void *memory = this->malloc(sizeof(T)); if (!memory) return __null; return new(memory) T (p1); + } + template + __attribute__((always_inline)) inline T *create(const P1 &p1, const P2 &p2) { + void *memory = this->malloc(sizeof(T)); if (!memory) return __null; return new(memory) T (p1, p2); + } + template + __attribute__((always_inline)) inline T *create(const P1 &p1, const P2 &p2, const P3 &p3) { + void *memory = this->malloc(sizeof(T)); if (!memory) return __null; return new(memory) T (p1, p2, p3); + } + template + __attribute__((always_inline)) inline void destroy(T *p) { + p->~T(); + this->free(p); + } + void purge(); + js::StackSpace &stack() const { + return (&(this)->thread->data)->stackSpace; + } + void assertValidStackDepth(uintN ) {} + bool isExceptionPending() { + return throwing; + } + js::Value getPendingException() { + ((void) 0); + return exception; + } + void setPendingException(js::Value v); + void clearPendingException() { + this->throwing = false; + this->exception.setUndefined(); + } + private: + __attribute__((visibility ("default"))) void checkMallocGCPressure(void *p); +}; +static inline uintN +FramePCOffset(JSContext *cx, JSStackFrame* fp) +{ + jsbytecode *pc = fp->hasImacropc() ? fp->imacropc() : fp->pc(cx); + return uintN(pc - fp->script()->code); +} +static inline JSAtom ** +FrameAtomBase(JSContext *cx, JSStackFrame *fp) +{ + return fp->hasImacropc() + ? ((JSAtom **)((uint8 *)(&cx->runtime->atomState) + __builtin_offsetof (JSAtomState, emptyAtom))) + : fp->script()->atomMap.vector; +} +namespace js { +class AutoGCRooter { + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag) + : down(cx->autoGCRooters), tag(tag), context(cx) + { + ((void) 0); + ((void) 0); + cx->autoGCRooters = this; + } + ~AutoGCRooter() { + ((void) 0); + ((void) 0); + context->autoGCRooters = down; + } + inline void trace(JSTracer *trc); + friend __attribute__((visibility ("default"))) void MarkContext(JSTracer *trc, JSContext *acx); + friend void MarkRuntime(JSTracer *trc); + protected: + AutoGCRooter * const down; + ptrdiff_t tag; + JSContext * const context; + enum { + JSVAL = -1, + SHAPE = -2, + PARSER = -3, + SCRIPT = -4, + ENUMERATOR = -5, + IDARRAY = -6, + DESCRIPTORS = -7, + NAMESPACES = -8, + XML = -9, + OBJECT = -10, + ID = -11, + VALVECTOR = -12, + DESCRIPTOR = -13, + STRING = -14, + IDVECTOR = -15, + BINDINGS = -16, + SHAPEVECTOR = -17 + }; + private: + AutoGCRooter(AutoGCRooter &ida); + void operator=(AutoGCRooter &ida); +}; +class AutoValueRooter : private AutoGCRooter +{ + public: + explicit AutoValueRooter(JSContext *cx + ) + : AutoGCRooter(cx, JSVAL), val(js::NullValue()) + { + do { } while (0); + } + AutoValueRooter(JSContext *cx, const Value &v + ) + : AutoGCRooter(cx, JSVAL), val(v) + { + do { } while (0); + } + AutoValueRooter(JSContext *cx, jsval v + ) + : AutoGCRooter(cx, JSVAL), val(js::Valueify(v)) + { + do { } while (0); + } + void set(Value v) { + ((void) 0); + val = v; + } + void set(jsval v) { + ((void) 0); + val = js::Valueify(v); + } + const Value &value() const { + ((void) 0); + return val; + } + Value *addr() { + ((void) 0); + return &val; + } + const jsval &jsval_value() const { + ((void) 0); + return Jsvalify(val); + } + jsval *jsval_addr() { + ((void) 0); + return Jsvalify(&val); + } + friend void AutoGCRooter::trace(JSTracer *trc); + friend void MarkRuntime(JSTracer *trc); + private: + Value val; + +}; +class AutoObjectRooter : private AutoGCRooter { + public: + AutoObjectRooter(JSContext *cx, JSObject *obj = __null + ) + : AutoGCRooter(cx, OBJECT), obj(obj) + { + do { } while (0); + } + void setObject(JSObject *obj) { + this->obj = obj; + } + JSObject * object() const { + return obj; + } + JSObject ** addr() { + return &obj; + } + friend void AutoGCRooter::trace(JSTracer *trc); + friend void MarkRuntime(JSTracer *trc); + private: + JSObject *obj; + +}; +class AutoStringRooter : private AutoGCRooter { + public: + AutoStringRooter(JSContext *cx, JSString *str = __null + ) + : AutoGCRooter(cx, STRING), str(str) + { + do { } while (0); + } + void setString(JSString *str) { + this->str = str; + } + JSString * string() const { + return str; + } + JSString ** addr() { + return &str; + } + friend void AutoGCRooter::trace(JSTracer *trc); + private: + JSString *str; + +}; +class AutoArrayRooter : private AutoGCRooter { + public: + AutoArrayRooter(JSContext *cx, size_t len, Value *vec + ) + : AutoGCRooter(cx, len), array(vec) + { + do { } while (0); + ((void) 0); + } + AutoArrayRooter(JSContext *cx, size_t len, jsval *vec + ) + : AutoGCRooter(cx, len), array(Valueify(vec)) + { + do { } while (0); + ((void) 0); + } + void changeLength(size_t newLength) { + tag = ptrdiff_t(newLength); + ((void) 0); + } + void changeArray(Value *newArray, size_t newLength) { + changeLength(newLength); + array = newArray; + } + Value *array; + friend void AutoGCRooter::trace(JSTracer *trc); + private: + +}; +class AutoShapeRooter : private AutoGCRooter { + public: + AutoShapeRooter(JSContext *cx, const js::Shape *shape + ) + : AutoGCRooter(cx, SHAPE), shape(shape) + { + do { } while (0); + } + friend void AutoGCRooter::trace(JSTracer *trc); + friend void MarkRuntime(JSTracer *trc); + private: + const js::Shape * const shape; + +}; +class AutoScriptRooter : private AutoGCRooter { + public: + AutoScriptRooter(JSContext *cx, JSScript *script + ) + : AutoGCRooter(cx, SCRIPT), script(script) + { + do { } while (0); + } + void setScript(JSScript *script) { + this->script = script; + } + friend void AutoGCRooter::trace(JSTracer *trc); + private: + JSScript *script; + +}; +class AutoIdRooter : private AutoGCRooter +{ + public: + explicit AutoIdRooter(JSContext *cx, jsid id = INT_TO_JSID(0) + ) + : AutoGCRooter(cx, ID), id_(id) + { + do { } while (0); + } + jsid id() { + return id_; + } + jsid * addr() { + return &id_; + } + friend void AutoGCRooter::trace(JSTracer *trc); + friend void MarkRuntime(JSTracer *trc); + private: + jsid id_; + +}; +class AutoIdArray : private AutoGCRooter { + public: + AutoIdArray(JSContext *cx, JSIdArray *ida ) + : AutoGCRooter(cx, IDARRAY), idArray(ida) + { + do { } while (0); + } + ~AutoIdArray() { + if (idArray) + JS_DestroyIdArray(context, idArray); + } + bool operator!() { + return idArray == __null; + } + jsid operator[](size_t i) const { + ((void) 0); + ((void) 0); + return idArray->vector[i]; + } + size_t length() const { + return idArray->length; + } + friend void AutoGCRooter::trace(JSTracer *trc); + JSIdArray *steal() { + JSIdArray *copy = idArray; + idArray = __null; + return copy; + } + protected: + inline void trace(JSTracer *trc); + private: + JSIdArray * idArray; + + AutoIdArray(AutoIdArray &ida); + void operator=(AutoIdArray &ida); +}; +class AutoEnumStateRooter : private AutoGCRooter +{ + public: + AutoEnumStateRooter(JSContext *cx, JSObject *obj + ) + : AutoGCRooter(cx, ENUMERATOR), obj(obj), stateValue() + { + do { } while (0); + ((void) 0); + } + ~AutoEnumStateRooter() { + if (!stateValue.isNull()) { + obj->enumerate(context, JSENUMERATE_DESTROY, &stateValue, 0); + ((void) 0); + } + } + friend void AutoGCRooter::trace(JSTracer *trc); + const Value &state() const { return stateValue; } + Value *addr() { return &stateValue; } + protected: + void trace(JSTracer *trc); + JSObject * const obj; + private: + Value stateValue; + +}; +class AutoXMLRooter : private AutoGCRooter { + public: + AutoXMLRooter(JSContext *cx, JSXML *xml + ) + : AutoGCRooter(cx, XML), xml(xml) + { + do { } while (0); + ((void) 0); + } + friend void AutoGCRooter::trace(JSTracer *trc); + friend void MarkRuntime(JSTracer *trc); + private: + JSXML * const xml; + +}; +class AutoBindingsRooter : private AutoGCRooter { + public: + AutoBindingsRooter(JSContext *cx, Bindings &bindings + ) + : AutoGCRooter(cx, BINDINGS), bindings(bindings) + { + do { } while (0); + } + friend void AutoGCRooter::trace(JSTracer *trc); + private: + Bindings &bindings; + +}; +class AutoLockGC { + public: + explicit AutoLockGC(JSRuntime *rt + ) + : rt(rt) + { + do { } while (0); + PR_Lock((rt)->gcLock); + } + ~AutoLockGC() { PR_Unlock((rt)->gcLock); } + private: + JSRuntime *rt; + +}; +class AutoUnlockGC { + private: + JSRuntime *rt; + + public: + explicit AutoUnlockGC(JSRuntime *rt + ) + : rt(rt) + { + do { } while (0); + PR_Unlock((rt)->gcLock); + } + ~AutoUnlockGC() { PR_Lock((rt)->gcLock); } +}; +class AutoLockAtomsCompartment { + private: + JSContext *cx; + + public: + AutoLockAtomsCompartment(JSContext *cx + ) + : cx(cx) + { + do { } while (0); + js_Lock(cx, &cx->runtime->atomState.lock); + cx->runtime->atomsCompartmentIsLocked = true; + } + ~AutoLockAtomsCompartment() { + cx->runtime->atomsCompartmentIsLocked = false; + js_Unlock(cx, &cx->runtime->atomState.lock); + } +}; +class AutoUnlockAtomsCompartment { + JSContext *cx; + + public: + AutoUnlockAtomsCompartment(JSContext *cx + ) + : cx(cx) + { + do { } while (0); + cx->runtime->atomsCompartmentIsLocked = false; + js_Unlock(cx, &cx->runtime->atomState.lock); + } + ~AutoUnlockAtomsCompartment() { + js_Lock(cx, &cx->runtime->atomState.lock); + cx->runtime->atomsCompartmentIsLocked = true; + } +}; +class AutoKeepAtoms { + JSRuntime *rt; + + public: + explicit AutoKeepAtoms(JSRuntime *rt + ) + : rt(rt) + { + do { } while (0); + PR_AtomicIncrement((PRInt32 *)(&(rt)->gcKeepAtoms));; + } + ~AutoKeepAtoms() { PR_AtomicDecrement((PRInt32 *)(&(rt)->gcKeepAtoms));; } +}; +class AutoArenaAllocator { + JSArenaPool *pool; + void *mark; + + public: + explicit AutoArenaAllocator(JSArenaPool *pool + ) + : pool(pool), mark(((void *) (pool)->current->avail)) + { + do { } while (0); + } + ~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); } + template + T *alloc(size_t elems) { + void *ptr; + 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); + return static_cast(ptr); + } +}; +class AutoReleasePtr { + JSContext *cx; + void *ptr; + + AutoReleasePtr operator=(const AutoReleasePtr &other); + public: + explicit AutoReleasePtr(JSContext *cx, void *ptr + ) + : cx(cx), ptr(ptr) + { + do { } while (0); + } + ~AutoReleasePtr() { cx->free(ptr); } +}; +class AutoReleaseNullablePtr { + JSContext *cx; + void *ptr; + + AutoReleaseNullablePtr operator=(const AutoReleaseNullablePtr &other); + public: + explicit AutoReleaseNullablePtr(JSContext *cx, void *ptr + ) + : cx(cx), ptr(ptr) + { + do { } while (0); + } + void reset(void *ptr2) { + if (ptr) + cx->free(ptr); + ptr = ptr2; + } + ~AutoReleaseNullablePtr() { if (ptr) cx->free(ptr); } +}; +class AutoLocalNameArray { + public: + explicit AutoLocalNameArray(JSContext *cx, JSFunction *fun + ) + : context(cx), + mark(((void *) (&cx->tempPool)->current->avail)), + names(fun->script()->bindings.getLocalNameArray(cx, &cx->tempPool)), + count(fun->script()->bindings.countLocalNames()) + { + do { } while (0); + } + ~AutoLocalNameArray() { + 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); + } + operator bool() const { return !!names; } + uint32 length() const { return count; } + const jsuword &operator [](unsigned i) const { return names[i]; } + private: + JSContext *context; + void *mark; + jsuword *names; + uint32 count; + +}; +template +class AlreadyIncRefed +{ + typedef RefCountable *****ConvertibleToBool; + RefCountable *obj; + public: + explicit AlreadyIncRefed(RefCountable *obj) : obj(obj) {} + bool null() const { return obj == __null; } + operator ConvertibleToBool() const { return (ConvertibleToBool)obj; } + RefCountable *operator->() const { ((void) 0); return obj; } + RefCountable &operator*() const { ((void) 0); return *obj; } + RefCountable *get() const { return obj; } +}; +template +class NeedsIncRef +{ + typedef RefCountable *****ConvertibleToBool; + RefCountable *obj; + public: + explicit NeedsIncRef(RefCountable *obj) : obj(obj) {} + bool null() const { return obj == __null; } + operator ConvertibleToBool() const { return (ConvertibleToBool)obj; } + RefCountable *operator->() const { ((void) 0); return obj; } + RefCountable &operator*() const { ((void) 0); return *obj; } + RefCountable *get() const { return obj; } +}; +template +class AutoRefCount +{ + typedef RefCountable *****ConvertibleToBool; + JSContext *const cx; + RefCountable *obj; + AutoRefCount(const AutoRefCount &); + void operator=(const AutoRefCount &); + public: + explicit AutoRefCount(JSContext *cx) + : cx(cx), obj(__null) + {} + AutoRefCount(JSContext *cx, NeedsIncRef aobj) + : cx(cx), obj(aobj.get()) + { + if (obj) + obj->incref(cx); + } + AutoRefCount(JSContext *cx, AlreadyIncRefed aobj) + : cx(cx), obj(aobj.get()) + {} + ~AutoRefCount() { + if (obj) + obj->decref(cx); + } + void reset(NeedsIncRef aobj) { + if (obj) + obj->decref(cx); + obj = aobj.get(); + if (obj) + obj->incref(cx); + } + void reset(AlreadyIncRefed aobj) { + if (obj) + obj->decref(cx); + obj = aobj.get(); + } + bool null() const { return obj == __null; } + operator ConvertibleToBool() const { return (ConvertibleToBool)obj; } + RefCountable *operator->() const { ((void) 0); return obj; } + RefCountable &operator*() const { ((void) 0); return *obj; } + RefCountable *get() const { return obj; } +}; +} +class JSAutoResolveFlags +{ + public: + JSAutoResolveFlags(JSContext *cx, uintN flags + ) + : mContext(cx), mSaved(cx->resolveFlags) + { + do { } while (0); + cx->resolveFlags = flags; + } + ~JSAutoResolveFlags() { mContext->resolveFlags = mSaved; } + private: + JSContext *mContext; + uintN mSaved; + +}; +extern JSThreadData * +js_CurrentThreadData(JSRuntime *rt); +extern JSBool +js_InitThreads(JSRuntime *rt); +extern void +js_FinishThreads(JSRuntime *rt); +extern void +js_PurgeThreads(JSContext *cx); +namespace js { +class ThreadDataIter : public JSThread::Map::Range +{ + public: + ThreadDataIter(JSRuntime *rt) : JSThread::Map::Range(rt->threads.all()) {} + JSThreadData *threadData() const { + return &front().value->data; + } +}; +} +extern JSContext * +js_NewContext(JSRuntime *rt, size_t stackChunkSize); +extern void +js_DestroyContext(JSContext *cx, JSDestroyContextMode mode); +static inline JSContext * +js_ContextFromLinkField(JSCList *link) +{ + ((void) 0); + return (JSContext *) ((uint8 *) link - __builtin_offsetof (JSContext, link)); +} +extern JSContext * +js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp); +extern __attribute__((visibility ("default"))) JSContext * +js_NextActiveContext(JSRuntime *, JSContext *); +extern JSBool +js_StartResolving(JSContext *cx, JSResolvingKey *key, uint32 flag, + JSResolvingEntry **entryp); +extern void +js_StopResolving(JSContext *cx, JSResolvingKey *key, uint32 flag, + JSResolvingEntry *entry, uint32 generation); +typedef enum JSErrNum { +JSMSG_NOT_AN_ERROR = 0, +JSMSG_NOT_DEFINED = 1, +JSMSG_INACTIVE = 2, +JSMSG_MORE_ARGS_NEEDED = 3, +JSMSG_BAD_CHAR = 4, +JSMSG_BAD_TYPE = 5, +JSMSG_ALLOC_OVERFLOW = 6, +JSMSG_MISSING_HEXDIGITS = 7, +JSMSG_INCOMPATIBLE_PROTO = 8, +JSMSG_NO_CONSTRUCTOR = 9, +JSMSG_CANT_ALIAS = 10, +JSMSG_NOT_SCRIPTED_FUNCTION = 11, +JSMSG_BAD_SORT_ARG = 12, +JSMSG_BAD_ATOMIC_NUMBER = 13, +JSMSG_TOO_MANY_LITERALS = 14, +JSMSG_CANT_WATCH = 15, +JSMSG_STACK_UNDERFLOW = 16, +JSMSG_NEED_DIET = 17, +JSMSG_TOO_MANY_LOCAL_ROOTS = 18, +JSMSG_READ_ONLY = 19, +JSMSG_BAD_FORMAL = 20, +JSMSG_CANT_DELETE = 21, +JSMSG_NOT_FUNCTION = 22, +JSMSG_NOT_CONSTRUCTOR = 23, +JSMSG_SCRIPT_STACK_QUOTA = 24, +JSMSG_TOO_DEEP = 25, +JSMSG_OVER_RECURSED = 26, +JSMSG_IN_NOT_OBJECT = 27, +JSMSG_BAD_NEW_RESULT = 28, +JSMSG_BAD_SHARP_DEF = 29, +JSMSG_BAD_SHARP_USE = 30, +JSMSG_BAD_INSTANCEOF_RHS = 31, +JSMSG_BAD_BYTECODE = 32, +JSMSG_BAD_RADIX = 33, +JSMSG_PAREN_BEFORE_LET = 34, +JSMSG_CANT_CONVERT = 35, +JSMSG_CYCLIC_VALUE = 36, +JSMSG_COMPILE_EXECED_SCRIPT = 37, +JSMSG_CANT_CONVERT_TO = 38, +JSMSG_NO_PROPERTIES = 39, +JSMSG_CANT_FIND_CLASS = 40, +JSMSG_CANT_XDR_CLASS = 41, +JSMSG_BYTECODE_TOO_BIG = 42, +JSMSG_UNKNOWN_FORMAT = 43, +JSMSG_TOO_MANY_CON_ARGS = 44, +JSMSG_TOO_MANY_FUN_ARGS = 45, +JSMSG_BAD_QUANTIFIER = 46, +JSMSG_MIN_TOO_BIG = 47, +JSMSG_MAX_TOO_BIG = 48, +JSMSG_OUT_OF_ORDER = 49, +JSMSG_BAD_DESTRUCT_DECL = 50, +JSMSG_BAD_DESTRUCT_ASS = 51, +JSMSG_PAREN_AFTER_LET = 52, +JSMSG_CURLY_AFTER_LET = 53, +JSMSG_MISSING_PAREN = 54, +JSMSG_UNTERM_CLASS = 55, +JSMSG_TRAILING_SLASH = 56, +JSMSG_BAD_CLASS_RANGE = 57, +JSMSG_BAD_REGEXP_FLAG = 58, +JSMSG_NO_INPUT = 59, +JSMSG_CANT_OPEN = 60, +JSMSG_BAD_STRING_MASK = 61, +JSMSG_UNMATCHED_RIGHT_PAREN = 62, +JSMSG_END_OF_DATA = 63, +JSMSG_SEEK_BEYOND_START = 64, +JSMSG_SEEK_BEYOND_END = 65, +JSMSG_END_SEEK = 66, +JSMSG_WHITHER_WHENCE = 67, +JSMSG_BAD_SCRIPT_MAGIC = 68, +JSMSG_PAREN_BEFORE_FORMAL = 69, +JSMSG_MISSING_FORMAL = 70, +JSMSG_PAREN_AFTER_FORMAL = 71, +JSMSG_CURLY_BEFORE_BODY = 72, +JSMSG_CURLY_AFTER_BODY = 73, +JSMSG_PAREN_BEFORE_COND = 74, +JSMSG_PAREN_AFTER_COND = 75, +JSMSG_DESTRUCT_DUP_ARG = 76, +JSMSG_NAME_AFTER_DOT = 77, +JSMSG_BRACKET_IN_INDEX = 78, +JSMSG_XML_WHOLE_PROGRAM = 79, +JSMSG_PAREN_BEFORE_SWITCH = 80, +JSMSG_PAREN_AFTER_SWITCH = 81, +JSMSG_CURLY_BEFORE_SWITCH = 82, +JSMSG_COLON_AFTER_CASE = 83, +JSMSG_WHILE_AFTER_DO = 84, +JSMSG_PAREN_AFTER_FOR = 85, +JSMSG_SEMI_AFTER_FOR_INIT = 86, +JSMSG_SEMI_AFTER_FOR_COND = 87, +JSMSG_PAREN_AFTER_FOR_CTRL = 88, +JSMSG_CURLY_BEFORE_TRY = 89, +JSMSG_CURLY_AFTER_TRY = 90, +JSMSG_PAREN_BEFORE_CATCH = 91, +JSMSG_CATCH_IDENTIFIER = 92, +JSMSG_PAREN_AFTER_CATCH = 93, +JSMSG_CURLY_BEFORE_CATCH = 94, +JSMSG_CURLY_AFTER_CATCH = 95, +JSMSG_CURLY_BEFORE_FINALLY = 96, +JSMSG_CURLY_AFTER_FINALLY = 97, +JSMSG_CATCH_OR_FINALLY = 98, +JSMSG_PAREN_BEFORE_WITH = 99, +JSMSG_PAREN_AFTER_WITH = 100, +JSMSG_CURLY_IN_COMPOUND = 101, +JSMSG_NO_VARIABLE_NAME = 102, +JSMSG_COLON_IN_COND = 103, +JSMSG_PAREN_AFTER_ARGS = 104, +JSMSG_BRACKET_AFTER_LIST = 105, +JSMSG_COLON_AFTER_ID = 106, +JSMSG_CURLY_AFTER_LIST = 107, +JSMSG_PAREN_IN_PAREN = 108, +JSMSG_SEMI_BEFORE_STMNT = 109, +JSMSG_NO_RETURN_VALUE = 110, +JSMSG_DUPLICATE_FORMAL = 111, +JSMSG_EQUAL_AS_ASSIGN = 112, +JSMSG_OPTIMIZED_CLOSURE_LEAK = 113, +JSMSG_TOO_MANY_DEFAULTS = 114, +JSMSG_TOO_MANY_CASES = 115, +JSMSG_BAD_SWITCH = 116, +JSMSG_BAD_FOR_LEFTSIDE = 117, +JSMSG_CATCH_AFTER_GENERAL = 118, +JSMSG_CATCH_WITHOUT_TRY = 119, +JSMSG_FINALLY_WITHOUT_TRY = 120, +JSMSG_LABEL_NOT_FOUND = 121, +JSMSG_TOUGH_BREAK = 122, +JSMSG_BAD_CONTINUE = 123, +JSMSG_BAD_RETURN_OR_YIELD = 124, +JSMSG_BAD_LABEL = 125, +JSMSG_DUPLICATE_LABEL = 126, +JSMSG_VAR_HIDES_ARG = 127, +JSMSG_BAD_VAR_INIT = 128, +JSMSG_BAD_LEFTSIDE_OF_ASS = 129, +JSMSG_BAD_OPERAND = 130, +JSMSG_BAD_PROP_ID = 131, +JSMSG_RESERVED_ID = 132, +JSMSG_SYNTAX_ERROR = 133, +JSMSG_BAD_SHARP_VAR_DEF = 134, +JSMSG_BAD_PROTOTYPE = 135, +JSMSG_MISSING_EXPONENT = 136, +JSMSG_OUT_OF_MEMORY = 137, +JSMSG_UNTERMINATED_STRING = 138, +JSMSG_TOO_MANY_PARENS = 139, +JSMSG_UNTERMINATED_COMMENT = 140, +JSMSG_UNTERMINATED_REGEXP = 141, +JSMSG_BAD_CLONE_FUNOBJ_SCOPE = 142, +JSMSG_SHARPVAR_TOO_BIG = 143, +JSMSG_ILLEGAL_CHARACTER = 144, +JSMSG_BAD_OCTAL = 145, +JSMSG_BAD_INDIRECT_CALL = 146, +JSMSG_UNCAUGHT_EXCEPTION = 147, +JSMSG_INVALID_BACKREF = 148, +JSMSG_BAD_BACKREF = 149, +JSMSG_PRECISION_RANGE = 150, +JSMSG_BAD_GETTER_OR_SETTER = 151, +JSMSG_BAD_ARRAY_LENGTH = 152, +JSMSG_CANT_DESCRIBE_PROPS = 153, +JSMSG_BAD_APPLY_ARGS = 154, +JSMSG_REDECLARED_VAR = 155, +JSMSG_UNDECLARED_VAR = 156, +JSMSG_ANON_NO_RETURN_VALUE = 157, +JSMSG_DEPRECATED_USAGE = 158, +JSMSG_BAD_URI = 159, +JSMSG_GETTER_ONLY = 160, +JSMSG_IDSTART_AFTER_NUMBER = 161, +JSMSG_UNDEFINED_PROP = 162, +JSMSG_USELESS_EXPR = 163, +JSMSG_REDECLARED_PARAM = 164, +JSMSG_NEWREGEXP_FLAGGED = 165, +JSMSG_RESERVED_SLOT_RANGE = 166, +JSMSG_CANT_DECODE_PRINCIPALS = 167, +JSMSG_CANT_SEAL_OBJECT = 168, +JSMSG_TOO_MANY_CATCH_VARS = 169, +JSMSG_BAD_XML_MARKUP = 170, +JSMSG_BAD_XML_CHARACTER = 171, +JSMSG_BAD_DEFAULT_XML_NAMESPACE = 172, +JSMSG_BAD_XML_NAME_SYNTAX = 173, +JSMSG_BRACKET_AFTER_ATTR_EXPR = 174, +JSMSG_NESTING_GENERATOR = 175, +JSMSG_CURLY_IN_XML_EXPR = 176, +JSMSG_BAD_XML_NAMESPACE = 177, +JSMSG_BAD_XML_ATTR_NAME = 178, +JSMSG_BAD_XML_NAME = 179, +JSMSG_BAD_XML_CONVERSION = 180, +JSMSG_BAD_XMLLIST_CONVERSION = 181, +JSMSG_BAD_GENERATOR_SEND = 182, +JSMSG_NO_ASSIGN_IN_XML_ATTR = 183, +JSMSG_BAD_XML_ATTR_VALUE = 184, +JSMSG_XML_TAG_NAME_MISMATCH = 185, +JSMSG_BAD_XML_TAG_SYNTAX = 186, +JSMSG_BAD_XML_LIST_SYNTAX = 187, +JSMSG_INCOMPATIBLE_METHOD = 188, +JSMSG_CANT_SET_XML_ATTRS = 189, +JSMSG_END_OF_XML_SOURCE = 190, +JSMSG_END_OF_XML_ENTITY = 191, +JSMSG_BAD_XML_QNAME = 192, +JSMSG_BAD_FOR_EACH_LOOP = 193, +JSMSG_BAD_XMLLIST_PUT = 194, +JSMSG_UNKNOWN_XML_ENTITY = 195, +JSMSG_BAD_XML_NCR = 196, +JSMSG_UNDEFINED_XML_NAME = 197, +JSMSG_DUPLICATE_XML_ATTR = 198, +JSMSG_TOO_MANY_LOCALS = 199, +JSMSG_ARRAY_INIT_TOO_BIG = 200, +JSMSG_REGEXP_TOO_COMPLEX = 201, +JSMSG_BUFFER_TOO_SMALL = 202, +JSMSG_BAD_SURROGATE_CHAR = 203, +JSMSG_UTF8_CHAR_TOO_LARGE = 204, +JSMSG_MALFORMED_UTF8_CHAR = 205, +JSMSG_USER_DEFINED_ERROR = 206, +JSMSG_WRONG_CONSTRUCTOR = 207, +JSMSG_BAD_GENERATOR_RETURN = 208, +JSMSG_BAD_ANON_GENERATOR_RETURN = 209, +JSMSG_NAME_AFTER_FOR_PAREN = 210, +JSMSG_IN_AFTER_FOR_NAME = 211, +JSMSG_BAD_TRAP_RETURN_VALUE = 212, +JSMSG_KEYWORD_NOT_NS = 213, +JSMSG_BAD_GENERATOR_YIELD = 214, +JSMSG_BAD_GENERATOR_SYNTAX = 215, +JSMSG_ARRAY_COMP_LEFTSIDE = 216, +JSMSG_NON_XML_FILTER = 217, +JSMSG_EMPTY_ARRAY_REDUCE = 218, +JSMSG_NON_LIST_XML_METHOD = 219, +JSMSG_BAD_DELETE_OPERAND = 220, +JSMSG_BAD_INCOP_OPERAND = 221, +JSMSG_UNEXPECTED_TYPE = 222, +JSMSG_LET_DECL_NOT_IN_BLOCK = 223, +JSMSG_BAD_OBJECT_INIT = 224, +JSMSG_CANT_SET_ARRAY_ATTRS = 225, +JSMSG_EVAL_ARITY = 226, +JSMSG_MISSING_FUN_ARG = 227, +JSMSG_JSON_BAD_PARSE = 228, +JSMSG_JSON_BAD_STRINGIFY = 229, +JSMSG_XDR_CLOSURE_WRAPPER = 230, +JSMSG_NOT_NONNULL_OBJECT = 231, +JSMSG_DEPRECATED_OCTAL = 232, +JSMSG_STRICT_CODE_WITH = 233, +JSMSG_DUPLICATE_PROPERTY = 234, +JSMSG_DEPRECATED_DELETE_OPERAND = 235, +JSMSG_DEPRECATED_ASSIGN = 236, +JSMSG_BAD_BINDING = 237, +JSMSG_INVALID_DESCRIPTOR = 238, +JSMSG_OBJECT_NOT_EXTENSIBLE = 239, +JSMSG_CANT_REDEFINE_PROP = 240, +JSMSG_CANT_APPEND_TO_ARRAY = 241, +JSMSG_CANT_DEFINE_ARRAY_LENGTH = 242, +JSMSG_CANT_DEFINE_ARRAY_INDEX = 243, +JSMSG_TYPED_ARRAY_BAD_INDEX = 244, +JSMSG_TYPED_ARRAY_NEGATIVE_ARG = 245, +JSMSG_TYPED_ARRAY_BAD_ARGS = 246, +JSMSG_CSP_BLOCKED_FUNCTION = 247, +JSMSG_BAD_GET_SET_FIELD = 248, +JSMSG_BAD_PROXY_FIX = 249, +JSMSG_INVALID_EVAL_SCOPE_ARG = 250, +JSMSG_ACCESSOR_WRONG_ARGS = 251, +JSMSG_THROW_TYPE_ERROR = 252, +JSMSG_BAD_TOISOSTRING_PROP = 253, +JSMSG_BAD_PARSE_NODE = 254, +JSMSG_NOT_EXPECTED_TYPE = 255, +JSMSG_CALLER_IS_STRICT = 256, +JSMSG_NEED_DEBUG_MODE = 257, +JSMSG_STRICT_CODE_LET_EXPR_STMT = 258, +JSMSG_CANT_CHANGE_EXTENSIBILITY = 259, +JSMSG_SC_BAD_SERIALIZED_DATA = 260, +JSMSG_SC_UNSUPPORTED_TYPE = 261, +JSMSG_SC_RECURSION = 262, +JSMSG_CANT_WRAP_XML_OBJECT = 263, +JSMSG_BAD_CLONE_VERSION = 264, +JSMSG_CANT_CLONE_OBJECT = 265, +JSMSG_NON_NATIVE_SCOPE = 266, +JSMSG_STRICT_FUNCTION_STATEMENT = 267, +JSMSG_INVALID_FOR_IN_INIT = 268, +JSMSG_CLEARED_SCOPE = 269, + JSErr_Limit +} JSErrNum; +extern __attribute__((visibility ("default"))) const JSErrorFormatString * +js_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber); +extern JSBool +js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap); +extern JSBool +js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback, + void *userRef, const uintN errorNumber, + JSBool charArgs, va_list ap); +extern JSBool +js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback, + void *userRef, const uintN errorNumber, + char **message, JSErrorReport *reportp, + bool charArgs, va_list ap); +extern void +js_ReportOutOfMemory(JSContext *cx); +void +js_ReportOutOfScriptQuota(JSContext *cx); +extern __attribute__((visibility ("default"))) void +js_ReportOverRecursed(JSContext *cx); +extern __attribute__((visibility ("default"))) void +js_ReportAllocationOverflow(JSContext *cx); +extern __attribute__((visibility ("default"))) void +js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report); +extern void +js_ReportIsNotDefined(JSContext *cx, const char *name); +extern JSBool +js_ReportIsNullOrUndefined(JSContext *cx, intN spindex, const js::Value &v, + JSString *fallback); +extern void +js_ReportMissingArg(JSContext *cx, const js::Value &v, uintN arg); +extern JSBool +js_ReportValueErrorFlags(JSContext *cx, uintN flags, const uintN errorNumber, + intN spindex, const js::Value &v, JSString *fallback, + const char *arg1, const char *arg2); +extern JSErrorFormatString js_ErrorFormatString[JSErr_Limit]; +__attribute__((always_inline)) inline void +JSThreadData::triggerOperationCallback(JSRuntime *rt) +{ + if (interruptFlags) + return; + PR_AtomicSet((PRInt32 *)(&interruptFlags), (PRInt32)(1)); + if (requestDepth != 0) + PR_AtomicIncrement((PRInt32 *)(&rt->interruptCounter)); +} +extern JSBool +js_InvokeOperationCallback(JSContext *cx); +extern JSBool +js_HandleExecutionInterrupt(JSContext *cx); +namespace js { +__attribute__((visibility ("default"))) void +TriggerOperationCallback(JSContext *cx); +void +TriggerAllOperationCallbacks(JSRuntime *rt); +} +extern JSStackFrame * +js_GetScriptedCaller(JSContext *cx, JSStackFrame *fp); +extern jsbytecode* +js_GetCurrentBytecodePC(JSContext* cx); +extern + bool +js_CurrentPCIsInImacro(JSContext *cx); +namespace js { +class RegExpStatics; +extern __attribute__((visibility ("default"))) void +LeaveTrace(JSContext *cx); +} +static inline JSStackFrame * +js_GetTopStackFrame(JSContext *cx) +{ + js::LeaveTrace(cx); + return cx->maybefp(); +} +static inline JSBool +js_IsPropertyCacheDisabled(JSContext *cx) +{ + return cx->runtime->shapeGen >= js::SHAPE_OVERFLOW_BIT; +} +static inline uint32 +js_RegenerateShapeForGC(JSRuntime *rt) +{ + ((void) 0); + ((void) 0); + uint32 shape = rt->shapeGen; + shape = (shape + 1) | (shape & js::SHAPE_OVERFLOW_BIT); + rt->shapeGen = shape; + return shape; +} +namespace js { +inline void * +ContextAllocPolicy::malloc(size_t bytes) +{ + return cx->malloc(bytes); +} +inline void +ContextAllocPolicy::free(void *p) +{ + cx->free(p); +} +inline void * +ContextAllocPolicy::realloc(void *p, size_t bytes) +{ + return cx->realloc(p, bytes); +} +inline void +ContextAllocPolicy::reportAllocOverflow() const +{ + js_ReportAllocationOverflow(cx); +} +template +class AutoVectorRooter : protected AutoGCRooter +{ + public: + explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag + ) + : AutoGCRooter(cx, tag), vector(cx) + { + do { } while (0); + } + size_t length() const { return vector.length(); } + bool append(const T &v) { return vector.append(v); } + void popBack() { vector.popBack(); } + bool growBy(size_t inc) { + size_t oldLength = vector.length(); + if (!vector.growByUninitialized(inc)) + return false; + MakeRangeGCSafe(vector.begin() + oldLength, vector.end()); + return true; + } + bool resize(size_t newLength) { + size_t oldLength = vector.length(); + if (newLength <= oldLength) { + vector.shrinkBy(oldLength - newLength); + return true; + } + if (!vector.growByUninitialized(newLength - oldLength)) + return false; + MakeRangeGCSafe(vector.begin() + oldLength, vector.end()); + return true; + } + bool reserve(size_t newLength) { + return vector.reserve(newLength); + } + T &operator[](size_t i) { return vector[i]; } + const T &operator[](size_t i) const { return vector[i]; } + const T *begin() const { return vector.begin(); } + T *begin() { return vector.begin(); } + const T *end() const { return vector.end(); } + T *end() { return vector.end(); } + const T &back() const { return vector.back(); } + friend void AutoGCRooter::trace(JSTracer *trc); + private: + Vector vector; + +}; +class AutoValueVector : public AutoVectorRooter +{ + public: + explicit AutoValueVector(JSContext *cx + ) + : AutoVectorRooter(cx, VALVECTOR) + { + do { } while (0); + } + const jsval *jsval_begin() const { return Jsvalify(begin()); } + jsval *jsval_begin() { return Jsvalify(begin()); } + const jsval *jsval_end() const { return Jsvalify(end()); } + jsval *jsval_end() { return Jsvalify(end()); } + +}; +class AutoIdVector : public AutoVectorRooter +{ + public: + explicit AutoIdVector(JSContext *cx + ) + : AutoVectorRooter(cx, IDVECTOR) + { + do { } while (0); + } + +}; +class AutoShapeVector : public AutoVectorRooter +{ + public: + explicit AutoShapeVector(JSContext *cx + ) + : AutoVectorRooter(cx, SHAPEVECTOR) + { + do { } while (0); + } + +}; +JSIdArray * +NewIdArray(JSContext *cx, jsint length); +} +typedef union jsdpun { + struct { + uint32 hi, lo; + } s; + uint64 u64; + jsdouble d; +} jsdpun; +static inline int +JSDOUBLE_IS_NaN(jsdouble d) +{ + return (sizeof (d) == sizeof (float) ? __isnanf (d) : sizeof (d) == sizeof (double) ? __isnan (d) : __isnanl (d)); +} +static inline int +JSDOUBLE_IS_FINITE(jsdouble d) +{ + return finite(d); +} +static inline int +JSDOUBLE_IS_INFINITE(jsdouble d) +{ + return (sizeof (d) == sizeof (float) ? __isinff (d) : sizeof (d) == sizeof (double) ? __isinf (d) : __isinfl (d)); +} +static inline + bool +JSDOUBLE_IS_NEG(jsdouble d) +{ + return (sizeof (d) == sizeof (float) ? __signbitf (d) : sizeof (d) == sizeof (double) ? __signbit (d) : __signbitl (d)); +} +static inline uint32 +JS_HASH_DOUBLE(jsdouble d) +{ + jsdpun u; + u.d = d; + return u.s.lo ^ u.s.hi; +} +extern jsdouble js_NaN; +extern jsdouble js_PositiveInfinity; +extern jsdouble js_NegativeInfinity; +extern JSBool +js_InitRuntimeNumberState(JSContext *cx); +extern void +js_FinishRuntimeNumberState(JSContext *cx); +extern js::Class js_NumberClass; +inline + bool +JSObject::isNumber() const +{ + return getClass() == &js_NumberClass; +} +extern JSObject * +js_InitNumberClass(JSContext *cx, JSObject *obj); +extern const char js_Infinity_str[]; +extern const char js_NaN_str[]; +extern const char js_isNaN_str[]; +extern const char js_isFinite_str[]; +extern const char js_parseFloat_str[]; +extern const char js_parseInt_str[]; +extern JSString * +js_IntToString(JSContext *cx, jsint i); +extern JSString * +js_NumberToString(JSContext *cx, jsdouble d); +namespace js { +extern bool +NumberValueToStringBuffer(JSContext *cx, const Value &v, StringBuffer &sb); +extern JSFlatString * +NumberToString(JSContext *cx, jsdouble d); +struct ToCStringBuf +{ + static const size_t sbufSize = 34; + char sbuf[sbufSize]; + char *dbuf; + ToCStringBuf(); + ~ToCStringBuf(); +}; +extern char * +NumberToCString(JSContext *cx, ToCStringBuf *cbuf, jsdouble d, jsint base = 10); +const double DOUBLE_INTEGRAL_PRECISION_LIMIT = uint64(1) << 53; +extern + bool +GetPrefixInteger(JSContext *cx, const jschar *start, const jschar *end, int base, + const jschar **endp, jsdouble *dp); +__attribute__((always_inline)) inline + bool +ValueToNumber(JSContext *cx, const js::Value &v, double *out) +{ + if (v.isNumber()) { + *out = v.toNumber(); + return true; + } + extern bool ValueToNumberSlow(JSContext *, js::Value, double *); + return ValueToNumberSlow(cx, v, out); +} +__attribute__((always_inline)) inline + bool +ValueToNumber(JSContext *cx, js::Value *vp) +{ + if (vp->isNumber()) + return true; + double d; + extern bool ValueToNumberSlow(JSContext *, js::Value, double *); + if (!ValueToNumberSlow(cx, *vp, &d)) + return false; + vp->setNumber(d); + return true; +} +__attribute__((always_inline)) inline + bool +ValueToECMAInt32(JSContext *cx, const js::Value &v, int32_t *out) +{ + if (v.isInt32()) { + *out = v.toInt32(); + return true; + } + extern bool ValueToECMAInt32Slow(JSContext *, const js::Value &, int32_t *); + return ValueToECMAInt32Slow(cx, v, out); +} +__attribute__((always_inline)) inline + bool +ValueToECMAUint32(JSContext *cx, const js::Value &v, uint32_t *out) +{ + if (v.isInt32()) { + *out = (uint32_t)v.toInt32(); + return true; + } + extern bool ValueToECMAUint32Slow(JSContext *, const js::Value &, uint32_t *); + return ValueToECMAUint32Slow(cx, v, out); +} +__attribute__((always_inline)) inline + bool +ValueToInt32(JSContext *cx, const js::Value &v, int32_t *out) +{ + if (v.isInt32()) { + *out = v.toInt32(); + return true; + } + extern bool ValueToInt32Slow(JSContext *, const js::Value &, int32_t *); + return ValueToInt32Slow(cx, v, out); +} +__attribute__((always_inline)) inline + bool +ValueToUint16(JSContext *cx, const js::Value &v, uint16_t *out) +{ + if (v.isInt32()) { + *out = (uint16_t)v.toInt32(); + return true; + } + extern bool ValueToUint16Slow(JSContext *, const js::Value &, uint16_t *); + return ValueToUint16Slow(cx, v, out); +} +} +static inline int32 +js_DoubleToECMAInt32(jsdouble d) +{ + int32 i; + jsdouble two32, two31; + if (!JSDOUBLE_IS_FINITE(d)) + return 0; + i = (int32) d; + if ((jsdouble) i == d) + return i; + two32 = 4294967296.0; + two31 = 2147483648.0; + d = fmod(d, two32); + d = (d >= 0) ? floor(d) : ceil(d) + two32; + return (int32) (d >= two31 ? d - two32 : d); +} +uint32 +js_DoubleToECMAUint32(jsdouble d); +static inline jsdouble +js_DoubleToInteger(jsdouble d) +{ + if (d == 0) + return d; + if (!JSDOUBLE_IS_FINITE(d)) { + if (JSDOUBLE_IS_NaN(d)) + return 0; + return d; + } + JSBool neg = (d < 0); + d = floor(neg ? -d : d); + return neg ? -d : d; +} +extern JSBool +js_strtod(JSContext *cx, const jschar *s, const jschar *send, + const jschar **ep, jsdouble *dp); +extern JSBool +js_num_valueOf(JSContext *cx, uintN argc, js::Value *vp); +namespace js { +static __attribute__((always_inline)) inline + bool +ValueFitsInInt32(const Value &v, int32_t *pi) +{ + if (v.isInt32()) { + *pi = v.toInt32(); + return true; + } + return v.isDouble() && JSDOUBLE_IS_INT32(v.toDouble(), pi); +} +template struct NumberTraits { }; +template<> struct NumberTraits { + static __attribute__((always_inline)) inline int32 NaN() { return 0; } + static __attribute__((always_inline)) inline int32 toSelfType(int32 i) { return i; } + static __attribute__((always_inline)) inline int32 toSelfType(jsdouble d) { return js_DoubleToECMAUint32(d); } +}; +template<> struct NumberTraits { + static __attribute__((always_inline)) inline jsdouble NaN() { return js_NaN; } + static __attribute__((always_inline)) inline jsdouble toSelfType(int32 i) { return i; } + static __attribute__((always_inline)) inline jsdouble toSelfType(jsdouble d) { return d; } +}; +template +static __attribute__((always_inline)) inline + bool +StringToNumberType(JSContext *cx, JSString *str, T *result) +{ + size_t length = str->length(); + const jschar *chars = str->getChars(__null); + if (!chars) + return false; + if (length == 1) { + jschar c = chars[0]; + if ('0' <= c && c <= '9') { + *result = NumberTraits::toSelfType(T(c - '0')); + return true; + } + if (JS_ISSPACE(c)) { + *result = NumberTraits::toSelfType(T(0)); + return true; + } + *result = NumberTraits::NaN(); + return true; + } + const jschar *bp = chars; + const jschar *end = chars + length; + bp = js_SkipWhiteSpace(bp, end); + if (end - bp >= 2 && bp[0] == '0' && (bp[1] == 'x' || bp[1] == 'X')) { + const jschar *endptr; + double d; + if (!GetPrefixInteger(cx, bp + 2, end, 16, &endptr, &d) || + js_SkipWhiteSpace(endptr, end) != end) { + *result = NumberTraits::NaN(); + return true; + } + *result = NumberTraits::toSelfType(d); + return true; + } + const jschar *ep; + double d; + if (!js_strtod(cx, bp, end, &ep, &d) || js_SkipWhiteSpace(ep, end) != end) { + *result = NumberTraits::NaN(); + return true; + } + *result = NumberTraits::toSelfType(d); + return true; +} +} +extern const char js_false_str[]; +extern const char js_true_str[]; +extern const char js_null_str[]; +extern const char js_break_str[]; +extern const char js_case_str[]; +extern const char js_catch_str[]; +extern const char js_continue_str[]; +extern const char js_debugger_str[]; +extern const char js_default_str[]; +extern const char js_delete_str[]; +extern const char js_do_str[]; +extern const char js_else_str[]; +extern const char js_finally_str[]; +extern const char js_for_str[]; +extern const char js_function_str[]; +extern const char js_if_str[]; +extern const char js_in_str[]; +extern const char js_instanceof_str[]; +extern const char js_new_str[]; +extern const char js_return_str[]; +extern const char js_switch_str[]; +extern const char js_this_str[]; +extern const char js_throw_str[]; +extern const char js_try_str[]; +extern const char js_typeof_str[]; +extern const char js_var_str[]; +extern const char js_void_str[]; +extern const char js_while_str[]; +extern const char js_with_str[]; +extern const char js_class_str[]; +extern const char js_enum_str[]; +extern const char js_export_str[]; +extern const char js_extends_str[]; +extern const char js_import_str[]; +extern const char js_super_str[]; +extern const char js_const_str[]; +extern const char js_let_str[]; +extern const char js_yield_str[]; +extern const char js_implements_str[]; +extern const char js_interface_str[]; +extern const char js_package_str[]; +extern const char js_private_str[]; +extern const char js_protected_str[]; +extern const char js_public_str[]; +extern const char js_static_str[]; +namespace js { +enum TokenKind { + TOK_ERROR = -1, + TOK_EOF = 0, + TOK_EOL = 1, + TOK_SEMI = 2, + TOK_COMMA = 3, + TOK_ASSIGN = 4, + TOK_HOOK = 5, TOK_COLON = 6, + TOK_OR = 7, + TOK_AND = 8, + TOK_BITOR = 9, + TOK_BITXOR = 10, + TOK_BITAND = 11, + TOK_EQOP = 12, + TOK_RELOP = 13, + TOK_SHOP = 14, + TOK_PLUS = 15, + TOK_MINUS = 16, + TOK_STAR = 17, TOK_DIVOP = 18, + TOK_UNARYOP = 19, + TOK_INC = 20, TOK_DEC = 21, + TOK_DOT = 22, + TOK_LB = 23, TOK_RB = 24, + TOK_LC = 25, TOK_RC = 26, + TOK_LP = 27, TOK_RP = 28, + TOK_NAME = 29, + TOK_NUMBER = 30, + TOK_STRING = 31, + TOK_REGEXP = 32, + TOK_PRIMARY = 33, + TOK_FUNCTION = 34, + TOK_IF = 35, + TOK_ELSE = 36, + TOK_SWITCH = 37, + TOK_CASE = 38, + TOK_DEFAULT = 39, + TOK_WHILE = 40, + TOK_DO = 41, + TOK_FOR = 42, + TOK_BREAK = 43, + TOK_CONTINUE = 44, + TOK_IN = 45, + TOK_VAR = 46, + TOK_WITH = 47, + TOK_RETURN = 48, + TOK_NEW = 49, + TOK_DELETE = 50, + TOK_DEFSHARP = 51, + TOK_USESHARP = 52, + TOK_TRY = 53, + TOK_CATCH = 54, + TOK_FINALLY = 55, + TOK_THROW = 56, + TOK_INSTANCEOF = 57, + TOK_DEBUGGER = 58, + TOK_XMLSTAGO = 59, + TOK_XMLETAGO = 60, + TOK_XMLPTAGC = 61, + TOK_XMLTAGC = 62, + TOK_XMLNAME = 63, + TOK_XMLATTR = 64, + TOK_XMLSPACE = 65, + TOK_XMLTEXT = 66, + TOK_XMLCOMMENT = 67, + TOK_XMLCDATA = 68, + TOK_XMLPI = 69, + TOK_AT = 70, + TOK_DBLCOLON = 71, + TOK_ANYNAME = 72, + TOK_DBLDOT = 73, + TOK_FILTER = 74, + TOK_XMLELEM = 75, + TOK_XMLLIST = 76, + TOK_YIELD = 77, + TOK_ARRAYCOMP = 78, + TOK_ARRAYPUSH = 79, + TOK_LEXICALSCOPE = 80, + TOK_LET = 81, + TOK_SEQ = 82, + TOK_FORHEAD = 83, + TOK_ARGSBODY = 84, + TOK_UPVARS = 85, + TOK_RESERVED, + TOK_STRICT_RESERVED, + TOK_LIMIT +}; +static inline + bool +TokenKindIsXML(TokenKind tt) +{ + return tt == TOK_AT || tt == TOK_DBLCOLON || tt == TOK_ANYNAME; +} +static inline + bool +TreeTypeIsXML(TokenKind tt) +{ + return tt == TOK_XMLCOMMENT || tt == TOK_XMLCDATA || tt == TOK_XMLPI || + tt == TOK_XMLELEM || tt == TOK_XMLLIST; +} +static inline + bool +TokenKindIsDecl(TokenKind tt) +{ + return tt == TOK_VAR || tt == TOK_LET; +} +struct TokenPtr { + uint32 index; + uint32 lineno; + bool operator==(const TokenPtr& bptr) { + return index == bptr.index && lineno == bptr.lineno; + } + bool operator!=(const TokenPtr& bptr) { + return index != bptr.index || lineno != bptr.lineno; + } + bool operator <(const TokenPtr& bptr) { + return lineno < bptr.lineno || + (lineno == bptr.lineno && index < bptr.index); + } + bool operator <=(const TokenPtr& bptr) { + return lineno < bptr.lineno || + (lineno == bptr.lineno && index <= bptr.index); + } + bool operator >(const TokenPtr& bptr) { + return !(*this <= bptr); + } + bool operator >=(const TokenPtr& bptr) { + return !(*this < bptr); + } +}; +struct TokenPos { + TokenPtr begin; + TokenPtr end; + bool operator==(const TokenPos& bpos) { + return begin == bpos.begin && end == bpos.end; + } + bool operator!=(const TokenPos& bpos) { + return begin != bpos.begin || end != bpos.end; + } + bool operator <(const TokenPos& bpos) { + return begin < bpos.begin; + } + bool operator <=(const TokenPos& bpos) { + return begin <= bpos.begin; + } + bool operator >(const TokenPos& bpos) { + return !(*this <= bpos); + } + bool operator >=(const TokenPos& bpos) { + return !(*this < bpos); + } +}; +struct Token { + TokenKind type; + TokenPos pos; + jschar *ptr; + union { + struct { + JSOp op; + JSAtom *atom; + } s; + uintN reflags; + struct { + JSAtom *atom2; + JSAtom *atom; + } p; + jsdouble dval; + } u; +}; +enum TokenStreamFlags +{ + TSF_ERROR = 0x01, + TSF_EOF = 0x02, + TSF_NEWLINES = 0x04, + TSF_OPERAND = 0x08, + TSF_UNEXPECTED_EOF = 0x10, + TSF_KEYWORD_IS_NAME = 0x20, + TSF_STRICT_MODE_CODE = 0x40, + TSF_DIRTYLINE = 0x80, + TSF_OWNFILENAME = 0x100, + TSF_XMLTAGMODE = 0x200, + TSF_XMLTEXTMODE = 0x400, + TSF_XMLONLYMODE = 0x800, + TSF_OCTAL_CHAR = 0x1000, + TSF_IN_HTML_COMMENT = 0x2000 +}; +class TokenStream +{ + static const size_t ntokens = 4; + static const uintN ntokensMask = ntokens - 1; + public: + typedef Vector CharBuffer; + TokenStream(JSContext *); + bool init(const jschar *base, size_t length, const char *filename, uintN lineno, + JSVersion version); + void close(); + ~TokenStream() {} + JSContext *getContext() const { return cx; } + bool onCurrentLine(const TokenPos &pos) const { return lineno == pos.end.lineno; } + const Token ¤tToken() const { return tokens[cursor]; } + const CharBuffer &getTokenbuf() const { return tokenbuf; } + const char *getFilename() const { return filename; } + uintN getLineno() const { return lineno; } + JSVersion versionNumber() const { return VersionNumber(version); } + JSVersion versionWithFlags() const { return version; } + bool hasAnonFunFix() const { return VersionHasAnonFunFix(version); } + bool hasXML() const { return xml || VersionShouldParseXML(versionNumber()); } + void setXML(bool enabled) { xml = enabled; } + void setStrictMode(bool enabled = true) { setFlag(enabled, TSF_STRICT_MODE_CODE); } + void setXMLTagMode(bool enabled = true) { setFlag(enabled, TSF_XMLTAGMODE); } + void setXMLOnlyMode(bool enabled = true) { setFlag(enabled, TSF_XMLONLYMODE); } + void setUnexpectedEOF(bool enabled = true) { setFlag(enabled, TSF_UNEXPECTED_EOF); } + void setOctalCharacterEscape(bool enabled = true) { setFlag(enabled, TSF_OCTAL_CHAR); } + bool isStrictMode() { return !!(flags & TSF_STRICT_MODE_CODE); } + bool isXMLTagMode() { return !!(flags & TSF_XMLTAGMODE); } + bool isXMLOnlyMode() { return !!(flags & TSF_XMLONLYMODE); } + bool isUnexpectedEOF() { return !!(flags & TSF_UNEXPECTED_EOF); } + bool isEOF() const { return !!(flags & TSF_EOF); } + bool isError() const { return !!(flags & TSF_ERROR); } + bool hasOctalCharacterEscape() const { return flags & TSF_OCTAL_CHAR; } + bool reportCompileErrorNumberVA(JSParseNode *pn, uintN flags, uintN errorNumber, va_list ap); + void mungeCurrentToken(TokenKind newKind) { tokens[cursor].type = newKind; } + void mungeCurrentToken(JSOp newOp) { tokens[cursor].u.s.op = newOp; } + void mungeCurrentToken(TokenKind newKind, JSOp newOp) { + mungeCurrentToken(newKind); + mungeCurrentToken(newOp); + } + private: + static JSAtom *atomize(JSContext *cx, CharBuffer &cb); + class Flagger { + TokenStream * const parent; + uintN flags; + public: + Flagger(TokenStream *parent, uintN withFlags) : parent(parent), flags(withFlags) { + parent->flags |= flags; + } + ~Flagger() { parent->flags &= ~flags; } + }; + friend class Flagger; + void setFlag(bool enabled, TokenStreamFlags flag) { + if (enabled) + flags |= flag; + else + flags &= ~flag; + } + public: + TokenKind getToken() { + while (lookahead != 0) { + ((void) 0); + lookahead--; + cursor = (cursor + 1) & ntokensMask; + TokenKind tt = currentToken().type; + ((void) 0); + if (tt != TOK_EOL) + return tt; + } + if (flags & TSF_ERROR) + return TOK_ERROR; + return getTokenInternal(); + } + TokenKind getToken(uintN withFlags) { + Flagger flagger(this, withFlags); + return getToken(); + } + void ungetToken() { + ((void) 0); + lookahead++; + cursor = (cursor - 1) & ntokensMask; + } + TokenKind peekToken(uintN withFlags = 0) { + Flagger flagger(this, withFlags); + if (lookahead != 0) { + ((void) 0); + return tokens[(cursor + lookahead) & ntokensMask].type; + } + TokenKind tt = getToken(); + ungetToken(); + return tt; + } + TokenKind peekTokenSameLine(uintN withFlags = 0) { + Flagger flagger(this, withFlags); + if (!onCurrentLine(currentToken().pos)) + return TOK_EOL; + TokenKind tt = peekToken(TSF_NEWLINES); + return tt; + } + JSBool matchToken(TokenKind tt, uintN withFlags = 0) { + Flagger flagger(this, withFlags); + if (getToken() == tt) + return (JSIntn)1; + ungetToken(); + return (JSIntn)0; + } + private: + typedef struct TokenBuf { + jschar *base; + jschar *limit; + jschar *ptr; + } TokenBuf; + TokenKind getTokenInternal(); + int32 getChar(); + int32 getCharIgnoreEOL(); + void ungetChar(int32 c); + void ungetCharIgnoreEOL(int32 c); + Token *newToken(ptrdiff_t adjust); + bool peekUnicodeEscape(int32 *c); + bool matchUnicodeEscapeIdStart(int32 *c); + bool matchUnicodeEscapeIdent(int32 *c); + JSBool peekChars(intN n, jschar *cp); + JSBool getXMLEntity(); + jschar *findEOL(); + JSBool matchChar(int32 expect) { + int32 c = getChar(); + if (c == expect) + return (JSIntn)1; + ungetChar(c); + return (JSIntn)0; + } + int32 peekChar() { + int32 c = getChar(); + ungetChar(c); + return c; + } + void skipChars(intN n) { + while (--n >= 0) + getChar(); + } + JSContext * const cx; + Token tokens[ntokens]; + uintN cursor; + uintN lookahead; + uintN lineno; + uintN flags; + jschar *linebase; + jschar *prevLinebase; + TokenBuf userbuf; + const char *filename; + JSSourceHandler listener; + void *listenerData; + void *listenerTSData; + CharBuffer tokenbuf; + bool maybeEOL[256]; + bool maybeStrSpecial[256]; + JSVersion version; + bool xml; +}; +} +extern void +js_CloseTokenStream(JSContext *cx, js::TokenStream *ts); +extern __attribute__((visibility ("default"))) int +js_fgets(char *buf, int size, FILE *file); +namespace js { +struct KeywordInfo { + const char *chars; + TokenKind tokentype; + JSOp op; + JSVersion version; +}; +extern const KeywordInfo * +FindKeyword(const jschar *s, size_t length); +} +typedef void (*JSMapKeywordFun)(const char *); +extern JSBool +js_IsIdentifier(JSLinearString *str); +namespace js { +bool +ReportCompileErrorNumber(JSContext *cx, TokenStream *ts, JSParseNode *pn, uintN flags, + uintN errorNumber, ...); +bool +ReportStrictModeError(JSContext *cx, TokenStream *ts, JSTreeContext *tc, JSParseNode *pn, + uintN errorNumber, ...); +} +extern "C" { +typedef enum JSParseNodeArity { + PN_NULLARY, + PN_UNARY, + PN_BINARY, + PN_TERNARY, + PN_FUNC, + PN_LIST, + PN_NAME, + PN_NAMESET +} JSParseNodeArity; +struct JSDefinition; +namespace js { +struct GlobalScope { + GlobalScope(JSContext *cx, JSObject *globalObj, JSCodeGenerator *cg) + : globalObj(globalObj), cg(cg), defs(ContextAllocPolicy(cx)) + { } + struct GlobalDef { + JSAtom *atom; + JSFunctionBox *funbox; + uint32 knownSlot; + GlobalDef() { } + GlobalDef(uint32 knownSlot) + : atom(__null), knownSlot(knownSlot) + { } + GlobalDef(JSAtom *atom, JSFunctionBox *box) : + atom(atom), funbox(box) + { } + }; + JSObject *globalObj; + JSCodeGenerator *cg; + Vector defs; + JSAtomList names; +}; +} +struct JSParseNode { + uint32 pn_type:16, + pn_op:8, + pn_arity:5, + pn_parens:1, + pn_used:1, + pn_defn:1; + js::TokenPos pn_pos; + int32 pn_offset; + JSParseNode *pn_next; + JSParseNode *pn_link; + union { + struct { + JSParseNode *head; + JSParseNode **tail; + uint32 count; + uint32 xflags:12, + blockid:20; + } list; + struct { + JSParseNode *kid1; + JSParseNode *kid2; + JSParseNode *kid3; + } ternary; + struct { + JSParseNode *left; + JSParseNode *right; + js::Value *pval; + uintN iflags; + } binary; + struct { + JSParseNode *kid; + jsint num; + JSBool hidden; + } unary; + struct { + union { + JSAtom *atom; + JSFunctionBox *funbox; + JSObjectBox *objbox; + }; + union { + JSParseNode *expr; + JSDefinition *lexdef; + }; + js::UpvarCookie cookie; + uint32 dflags:12, + blockid:20; + } name; + struct { + JSAtomSet names; + JSParseNode *tree; + } nameset; + struct { + JSAtom *atom; + JSAtom *atom2; + } apair; + jsdouble dval; + } pn_u; +protected: + void inline init(js::TokenKind type, JSOp op, JSParseNodeArity arity) { + pn_type = type; + pn_op = op; + pn_arity = arity; + pn_parens = false; + ((void) 0); + ((void) 0); + pn_next = pn_link = __null; + } + static JSParseNode *create(JSParseNodeArity arity, JSTreeContext *tc); +public: + static JSParseNode *newBinaryOrAppend(js::TokenKind tt, JSOp op, JSParseNode *left, + JSParseNode *right, JSTreeContext *tc); + JSParseNode *expr() const { + ((void) 0); + ((void) 0); + return pn_u.name.expr; + } + JSDefinition *lexdef() const { + ((void) 0); + ((void) 0); + return pn_u.name.lexdef; + } + JSParseNode *maybeExpr() { return pn_used ? __null : expr(); } + JSDefinition *maybeLexDef() { return pn_used ? lexdef() : __null; } + uintN frameLevel() const { + ((void) 0); + return pn_u.name.cookie.level(); + } + uintN frameSlot() const { + ((void) 0); + return pn_u.name.cookie.slot(); + } + inline bool test(uintN flag) const; + bool isLet() const { return test(0x01); } + bool isConst() const { return test(0x02); } + bool isInitialized() const { return test(0x04); } + bool isBlockChild() const { return test(0x20); } + bool isPlaceholder() const { return test(0x80); } + bool isDeoptimized() const { return test(0x400); } + bool isAssigned() const { return test(0x08); } + bool isFunArg() const { return test(0x100); } + bool isClosed() const { return test(0x800); } + bool isTopLevel() const { return test(0x10); } + void setFunArg(); + void become(JSParseNode *pn2); + void clear(); + bool isLiteral() const { + return ((js::TokenKind)(this)->pn_type) == js::TOK_NUMBER || + ((js::TokenKind)(this)->pn_type) == js::TOK_STRING || + (((js::TokenKind)(this)->pn_type) == js::TOK_PRIMARY && ((JSOp)(this)->pn_op) != JSOP_THIS); + } + bool isStringExprStatement() const { + if (((js::TokenKind)(this)->pn_type) == js::TOK_SEMI) { + ((void) 0); + JSParseNode *kid = pn_u.unary.kid; + return kid && ((js::TokenKind)(kid)->pn_type) == js::TOK_STRING && !kid->pn_parens; + } + return false; + } + bool isEscapeFreeStringLiteral() const { + ((void) 0); + JSString *str = (pn_u.name.atom); + return (pn_pos.begin.lineno == pn_pos.end.lineno && + pn_pos.begin.index + str->length() + 2 == pn_pos.end.index); + } + bool isDirectivePrologueMember() const { return pn_u.unary.hidden; } + bool isGeneratorExpr() const { + if (((js::TokenKind)(this)->pn_type) == js::TOK_LP) { + JSParseNode *callee = this->pn_u.list.head; + if (((js::TokenKind)(callee)->pn_type) == js::TOK_FUNCTION) { + JSParseNode *body = (((js::TokenKind)(callee->pn_u.name.expr)->pn_type) == js::TOK_UPVARS) + ? callee->pn_u.name.expr->pn_u.nameset.tree + : callee->pn_u.name.expr; + if (((js::TokenKind)(body)->pn_type) == js::TOK_LEXICALSCOPE) + return true; + } + } + return false; + } + JSParseNode *generatorExpr() const { + ((void) 0); + JSParseNode *callee = this->pn_u.list.head; + JSParseNode *body = ((js::TokenKind)(callee->pn_u.name.expr)->pn_type) == js::TOK_UPVARS + ? callee->pn_u.name.expr->pn_u.nameset.tree + : callee->pn_u.name.expr; + ((void) 0); + return body->pn_u.name.expr; + } + JSParseNode *last() const { + ((void) 0); + ((void) 0); + return (JSParseNode *)((char *)pn_u.list.tail - __builtin_offsetof (JSParseNode, pn_next)); + } + void makeEmpty() { + ((void) 0); + pn_u.list.head = __null; + pn_u.list.tail = &pn_u.list.head; + pn_u.list.count = 0; + pn_u.list.xflags = 0; + pn_u.name.blockid = 0; + } + void initList(JSParseNode *pn) { + ((void) 0); + pn_u.list.head = pn; + pn_u.list.tail = &pn->pn_next; + pn_u.list.count = 1; + pn_u.list.xflags = 0; + pn_u.name.blockid = 0; + } + void append(JSParseNode *pn) { + ((void) 0); + *pn_u.list.tail = pn; + pn_u.list.tail = &pn->pn_next; + pn_u.list.count++; + } + bool getConstantValue(JSContext *cx, bool strictChecks, js::Value *vp); + inline bool isConstant(); +}; +namespace js { +struct NullaryNode : public JSParseNode { + static inline NullaryNode *create(JSTreeContext *tc) { + return (NullaryNode *)JSParseNode::create(PN_NULLARY, tc); + } +}; +struct UnaryNode : public JSParseNode { + static inline UnaryNode *create(JSTreeContext *tc) { + return (UnaryNode *)JSParseNode::create(PN_UNARY, tc); + } +}; +struct BinaryNode : public JSParseNode { + static inline BinaryNode *create(JSTreeContext *tc) { + return (BinaryNode *)JSParseNode::create(PN_BINARY, tc); + } +}; +struct TernaryNode : public JSParseNode { + static inline TernaryNode *create(JSTreeContext *tc) { + return (TernaryNode *)JSParseNode::create(PN_TERNARY, tc); + } +}; +struct ListNode : public JSParseNode { + static inline ListNode *create(JSTreeContext *tc) { + return (ListNode *)JSParseNode::create(PN_LIST, tc); + } +}; +struct FunctionNode : public JSParseNode { + static inline FunctionNode *create(JSTreeContext *tc) { + return (FunctionNode *)JSParseNode::create(PN_FUNC, tc); + } +}; +struct NameNode : public JSParseNode { + static NameNode *create(JSAtom *atom, JSTreeContext *tc); + void inline initCommon(JSTreeContext *tc); +}; +struct NameSetNode : public JSParseNode { + static inline NameSetNode *create(JSTreeContext *tc) { + return (NameSetNode *)JSParseNode::create(PN_NAMESET, tc); + } +}; +struct LexicalScopeNode : public JSParseNode { + static inline LexicalScopeNode *create(JSTreeContext *tc) { + return (LexicalScopeNode *)JSParseNode::create(PN_NAME, tc); + } +}; +} +struct JSDefinition : public JSParseNode +{ + JSDefinition *resolve() { + JSParseNode *pn = this; + while (!pn->pn_defn) { + if (pn->pn_type == js::TOK_ASSIGN) { + pn = pn->pn_u.binary.left; + continue; + } + pn = pn->lexdef(); + } + return (JSDefinition *) pn; + } + bool isFreeVar() const { + ((void) 0); + return pn_u.name.cookie.isFree() || test(0x40); + } + bool isGlobal() const { + ((void) 0); + return test(0x40); + } + enum Kind { VAR, CONST, LET, FUNCTION, ARG, UNKNOWN }; + bool isBindingForm() { return int(kind()) <= int(LET); } + static const char *kindString(Kind kind); + Kind kind() { + if (((js::TokenKind)(this)->pn_type) == js::TOK_FUNCTION) + return FUNCTION; + ((void) 0); + if (((JSOp)(this)->pn_op) == JSOP_NOP) + return UNKNOWN; + if (((JSOp)(this)->pn_op) == JSOP_GETARG) + return ARG; + if (isConst()) + return CONST; + if (isLet()) + return LET; + return VAR; + } +}; +inline + bool +JSParseNode::test(uintN flag) const +{ + ((void) 0); + return !!(pn_u.name.dflags & flag); +} +inline void +JSParseNode::setFunArg() +{ + ((void) 0); + if (pn_used) + pn_u.name.lexdef->pn_u.name.dflags |= 0x100; + pn_u.name.dflags |= 0x100; +} +struct JSObjectBox { + JSObjectBox *traceLink; + JSObjectBox *emitLink; + JSObject *object; + JSObjectBox *parent; + uintN index; + bool isFunctionBox; +}; +struct JSFunctionBox : public JSObjectBox +{ + JSParseNode *node; + JSFunctionBox *siblings; + JSFunctionBox *kids; + JSFunctionBox *parent; + JSParseNode *methods; + js::Bindings bindings; + uint32 queued:1, + inLoop:1, + level:14; + uint32 tcflags; + bool joinable() const; + bool inAnyDynamicScope() const; + bool shouldUnbrand(uintN methods, uintN slowMethods) const; +}; +struct JSFunctionBoxQueue { + JSFunctionBox **vector; + size_t head, tail; + size_t lengthMask; + size_t count() { return head - tail; } + size_t length() { return lengthMask + 1; } + JSFunctionBoxQueue() + : vector(__null), head(0), tail(0), lengthMask(0) { } + bool init(uint32 count) { + lengthMask = (((JSUint32)1 << (JS_CeilingLog2(count))) - 1); + vector = js_array_new(length()); + return !!vector; + } + ~JSFunctionBoxQueue() { js_array_delete(vector); } + void push(JSFunctionBox *funbox) { + if (!funbox->queued) { + ((void) 0); + vector[head++ & lengthMask] = funbox; + funbox->queued = true; + } + } + JSFunctionBox *pull() { + if (tail == head) + return __null; + ((void) 0); + JSFunctionBox *funbox = vector[tail++ & lengthMask]; + funbox->queued = false; + return funbox; + } +}; +typedef struct BindData BindData; +namespace js { +struct Parser : private js::AutoGCRooter +{ + JSContext * const context; + JSAtomListElement *aleFreeList; + void *tempFreeList[6U]; + TokenStream tokenStream; + void *tempPoolMark; + JSPrincipals *principals; + JSStackFrame *const callerFrame; + JSObject *const callerVarObj; + JSParseNode *nodeList; + uint32 functionCount; + JSObjectBox *traceListHead; + JSTreeContext *tc; + js::AutoKeepAtoms keepAtoms; + Parser(JSContext *cx, JSPrincipals *prin = __null, JSStackFrame *cfp = __null); + ~Parser(); + friend void js::AutoGCRooter::trace(JSTracer *trc); + friend struct ::JSTreeContext; + friend struct Compiler; + bool init(const jschar *base, size_t length, const char *filename, uintN lineno, + JSVersion version); + void setPrincipals(JSPrincipals *prin); + const char *getFilename() const { return tokenStream.getFilename(); } + JSVersion versionWithFlags() const { return tokenStream.versionWithFlags(); } + JSVersion versionNumber() const { return tokenStream.versionNumber(); } + bool hasXML() const { return tokenStream.hasXML(); } + bool hasAnonFunFix() const { return tokenStream.hasAnonFunFix(); } + JSParseNode *parse(JSObject *chain); + JSParseNode *parseXMLText(JSObject *chain, bool allowList); + JSObjectBox *newObjectBox(JSObject *obj); + JSFunctionBox *newFunctionBox(JSObject *obj, JSParseNode *fn, JSTreeContext *tc); + JSFunction *newFunction(JSTreeContext *tc, JSAtom *atom, uintN lambda); + bool analyzeFunctions(JSTreeContext *tc); + void cleanFunctionList(JSFunctionBox **funbox); + bool markFunArgs(JSFunctionBox *funbox); + void setFunctionKinds(JSFunctionBox *funbox, uint32 *tcflags); + void trace(JSTracer *trc); + inline bool reportErrorNumber(JSParseNode *pn, uintN flags, uintN errorNumber, ...); +private: + JSParseNode *functionStmt(); + JSParseNode *functionExpr(); + JSParseNode *statements(); + JSParseNode *statement(); + JSParseNode *switchStatement(); + JSParseNode *forStatement(); + JSParseNode *tryStatement(); + JSParseNode *withStatement(); + JSParseNode *letStatement(); + JSParseNode *expressionStatement(); + JSParseNode *variables(bool inLetHead); + JSParseNode *expr(); + JSParseNode *assignExpr(); + JSParseNode *condExpr(); + JSParseNode *orExpr(); + JSParseNode *andExpr(); + JSParseNode *bitOrExpr(); + JSParseNode *bitXorExpr(); + JSParseNode *bitAndExpr(); + JSParseNode *eqExpr(); + JSParseNode *relExpr(); + JSParseNode *shiftExpr(); + JSParseNode *addExpr(); + JSParseNode *mulExpr(); + JSParseNode *unaryExpr(); + JSParseNode *memberExpr(JSBool allowCallSyntax); + JSParseNode *primaryExpr(js::TokenKind tt, JSBool afterDot); + JSParseNode *parenExpr(JSBool *genexp = __null); + bool recognizeDirectivePrologue(JSParseNode *pn, bool *isDirectivePrologueMember); + enum FunctionType { GETTER, SETTER, GENERAL }; + bool functionArguments(JSTreeContext &funtc, JSFunctionBox *funbox, JSParseNode **list); + JSParseNode *functionBody(); + JSParseNode *functionDef(JSAtom *name, FunctionType type, uintN lambda); + JSParseNode *condition(); + JSParseNode *comprehensionTail(JSParseNode *kid, uintN blockid, + js::TokenKind type = js::TOK_SEMI, JSOp op = JSOP_NOP); + JSParseNode *generatorExpr(JSParseNode *kid); + JSBool argumentList(JSParseNode *listNode); + JSParseNode *bracketedExpr(); + JSParseNode *letBlock(JSBool statement); + JSParseNode *returnOrYield(bool useAssignExpr); + JSParseNode *destructuringExpr(BindData *data, js::TokenKind tt); + JSParseNode *endBracketedExpr(); + JSParseNode *propertySelector(); + JSParseNode *qualifiedSuffix(JSParseNode *pn); + JSParseNode *qualifiedIdentifier(); + JSParseNode *attributeIdentifier(); + JSParseNode *xmlExpr(JSBool inTag); + JSParseNode *xmlAtomNode(); + JSParseNode *xmlNameExpr(); + JSParseNode *xmlTagContent(js::TokenKind tagtype, JSAtom **namep); + JSBool xmlElementContent(JSParseNode *pn); + JSParseNode *xmlElementOrList(JSBool allowList); + JSParseNode *xmlElementOrListRoot(JSBool allowList); +}; +inline + bool +Parser::reportErrorNumber(JSParseNode *pn, uintN flags, uintN errorNumber, ...) +{ + va_list args; + __builtin_va_start(args,errorNumber); + bool result = tokenStream.reportCompileErrorNumberVA(pn, flags, errorNumber, args); + __builtin_va_end(args); + return result; +} +struct Compiler +{ + Parser parser; + GlobalScope *globalScope; + Compiler(JSContext *cx, JSPrincipals *prin = __null, JSStackFrame *cfp = __null); + inline + + + bool + init(const jschar *base, size_t length, const char *filename, uintN lineno, JSVersion version) + { + return parser.init(base, length, filename, lineno, version); + } + static + + + bool + compileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *principals, + js::Bindings *bindings, const jschar *chars, size_t length, + const char *filename, uintN lineno, JSVersion version); + static JSScript * + compileScript(JSContext *cx, JSObject *scopeChain, JSStackFrame *callerFrame, + JSPrincipals *principals, uint32 tcflags, + const jschar *chars, size_t length, + const char *filename, uintN lineno, JSVersion version, + JSString *source = __null, uintN staticLevel = 0); + private: + static bool defineGlobals(JSContext *cx, GlobalScope &globalScope, JSScript *script); +}; +} +extern JSBool +js_FoldConstants(JSContext *cx, JSParseNode *pn, JSTreeContext *tc, + bool inCond = false); +} +extern const char js_AnyName_str[]; +extern const char js_AttributeName_str[]; +extern const char js_isXMLName_str[]; +extern const char js_XMLList_str[]; +extern const char js_amp_entity_str[]; +extern const char js_gt_entity_str[]; +extern const char js_lt_entity_str[]; +extern const char js_quot_entity_str[]; +typedef JSBool +(* JSIdentityOp)(const void *a, const void *b); +struct JSXMLArray { + uint32 length; + uint32 capacity; + void **vector; + JSXMLArrayCursor *cursors; + void init() { + length = capacity = 0; + vector = __null; + cursors = __null; + } + void finish(JSContext *cx); + bool setCapacity(JSContext *cx, uint32 capacity); + void trim(); +}; +struct JSXMLArrayCursor +{ + JSXMLArray *array; + uint32 index; + JSXMLArrayCursor *next; + JSXMLArrayCursor **prevp; + void *root; + JSXMLArrayCursor(JSXMLArray *array) + : array(array), index(0), next(array->cursors), prevp(&array->cursors), + root(__null) + { + if (next) + next->prevp = &next; + array->cursors = this; + } + ~JSXMLArrayCursor() { disconnect(); } + void disconnect() { + if (!array) + return; + if (next) + next->prevp = prevp; + *prevp = next; + array = __null; + } + void *getNext() { + if (!array || index >= array->length) + return __null; + return root = array->vector[index++]; + } + void *getCurrent() { + if (!array || index >= array->length) + return __null; + return root = array->vector[index]; + } + void trace(JSTracer *trc); +}; +typedef enum JSXMLClass { + JSXML_CLASS_LIST, + JSXML_CLASS_ELEMENT, + JSXML_CLASS_ATTRIBUTE, + JSXML_CLASS_PROCESSING_INSTRUCTION, + JSXML_CLASS_TEXT, + JSXML_CLASS_COMMENT, + JSXML_CLASS_LIMIT +} JSXMLClass; +typedef struct JSXMLListVar { + JSXMLArray kids; + JSXML *target; + JSObject *targetprop; +} JSXMLListVar; +typedef struct JSXMLElemVar { + JSXMLArray kids; + JSXMLArray namespaces; + JSXMLArray attrs; +} JSXMLElemVar; +struct JSXML : js::gc::Cell { + JSObject *object; + void *domnode; + JSXML *parent; + JSObject *name; + uint32 xml_class; + uint32 xml_flags; + union { + JSXMLListVar list; + JSXMLElemVar elem; + JSString *value; + } u; + void finalize(JSContext *cx) { + if ((((this)->xml_class) < JSXML_CLASS_ATTRIBUTE)) { + u.list.kids.finish(cx); + if (xml_class == JSXML_CLASS_ELEMENT) { + u.elem.namespaces.finish(cx); + u.elem.attrs.finish(cx); + } + } + } +}; +extern JSXML * +js_NewXML(JSContext *cx, JSXMLClass xml_class); +extern void +js_TraceXML(JSTracer *trc, JSXML *xml); +extern JSObject * +js_NewXMLObject(JSContext *cx, JSXMLClass xml_class); +extern JSObject * +js_GetXMLObject(JSContext *cx, JSXML *xml); +extern __attribute__((visibility ("default"))) js::Class js_XMLClass; +extern __attribute__((visibility ("default"))) js::Class js_NamespaceClass; +extern __attribute__((visibility ("default"))) js::Class js_QNameClass; +extern __attribute__((visibility ("default"))) js::Class js_AttributeNameClass; +extern __attribute__((visibility ("default"))) js::Class js_AnyNameClass; +extern js::Class js_XMLFilterClass; +inline + bool +JSObject::isXML() const +{ + return getClass() == &js_XMLClass; +} +inline + bool +JSObject::isXMLId() const +{ + js::Class *clasp = getClass(); + return clasp == &js_QNameClass || + clasp == &js_AttributeNameClass || + clasp == &js_AnyNameClass; +} +inline + bool +JSObject::isNamespace() const +{ + return getClass() == &js_NamespaceClass; +} +inline + bool +JSObject::isQName() const +{ + js::Class* clasp = getClass(); + return clasp == &js_QNameClass || + clasp == &js_AttributeNameClass || + clasp == &js_AnyNameClass; +} +static inline + bool +IsXML(const js::Value &v) +{ + return v.isObject() && v.toObject().isXML(); +} +extern JSObject * +js_InitNamespaceClass(JSContext *cx, JSObject *obj); +extern JSObject * +js_InitQNameClass(JSContext *cx, JSObject *obj); +extern JSObject * +js_InitXMLClass(JSContext *cx, JSObject *obj); +extern JSObject * +js_InitXMLClasses(JSContext *cx, JSObject *obj); +extern JSBool +js_GetFunctionNamespace(JSContext *cx, js::Value *vp); +JSBool +js_IsFunctionQName(JSContext *cx, JSObject *obj, jsid *funidp); +extern JSBool +js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp); +extern JSBool +js_SetDefaultXMLNamespace(JSContext *cx, const js::Value &v); +extern JSBool +js_IsXMLName(JSContext *cx, jsval v); +extern JSBool +js_ToAttributeName(JSContext *cx, js::Value *vp); +extern JSFlatString * +js_EscapeAttributeValue(JSContext *cx, JSString *str, JSBool quote); +extern JSString * +js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str, + JSString *str2); +extern JSFlatString * +js_EscapeElementValue(JSContext *cx, JSString *str); +extern JSString * +js_ValueToXMLString(JSContext *cx, const js::Value &v); +extern JSObject * +js_ConstructXMLQNameObject(JSContext *cx, const js::Value & nsval, + const js::Value & lnval); +extern JSBool +js_GetAnyName(JSContext *cx, jsid *idp); +extern JSBool +js_FindXMLProperty(JSContext *cx, const js::Value &nameval, JSObject **objp, jsid *idp); +extern JSBool +js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, js::Value *vp); +extern JSBool +js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp); +extern JSBool +js_DeleteXMLListElements(JSContext *cx, JSObject *listobj); +extern JSBool +js_StepXMLListFilter(JSContext *cx, JSBool initialized); +extern JSObject * +js_ValueToXMLObject(JSContext *cx, const js::Value &v); +extern JSObject * +js_ValueToXMLListObject(JSContext *cx, const js::Value &v); +extern JSObject * +js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name, + JSString *value); +extern JSString * +js_MakeXMLCDATAString(JSContext *cx, JSString *str); +extern JSString * +js_MakeXMLCommentString(JSContext *cx, JSString *str); +extern JSString * +js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str); +extern JSBool +js_TestXMLEquality(JSContext *cx, const js::Value &v1, const js::Value &v2, + JSBool *bp); +extern JSBool +js_ConcatenateXML(JSContext *cx, JSObject *obj1, JSObject *obj2, js::Value *vp); +namespace JSC { +class ExecutableAllocator; +} +namespace js { +typedef HashMap, + SystemAllocPolicy> RecordAttemptMap; +typedef HashMap, + SystemAllocPolicy> LoopProfileMap; +class Oracle; +typedef HashSet, + SystemAllocPolicy> TracedScriptSet; +typedef HashMap, + SystemAllocPolicy> ToSourceCache; +struct TraceMonitor; +struct TracerState +{ + JSContext* cx; + TraceMonitor* traceMonitor; + double* stackBase; + double* sp; + double* eos; + FrameInfo** callstackBase; + void* sor; + FrameInfo** rp; + void* eor; + VMSideExit* lastTreeExitGuard; + VMSideExit* lastTreeCallGuard; + void* rpAtLastTreeCall; + VMSideExit* outermostTreeExitGuard; + TreeFragment* outermostTree; + uintN* inlineCallCountp; + VMSideExit** innermostNestedGuardp; + VMSideExit* innermost; + uint64 startTime; + TracerState* prev; + uint32 builtinStatus; + double* deepBailSp; + uintN nativeVpLen; + js::Value* nativeVp; + TracerState(JSContext *cx, TraceMonitor *tm, TreeFragment *ti, + uintN &inlineCallCountp, VMSideExit** innermostNestedGuardp); + ~TracerState(); +}; +struct TraceNativeStorage +{ + double stack_global_buf[MAX_NATIVE_STACK_SLOTS + GLOBAL_SLOTS_BUFFER_SIZE]; + FrameInfo *callstack_buf[MAX_CALL_STACK_ENTRIES]; + double *stack() { return stack_global_buf; } + double *global() { return stack_global_buf + MAX_NATIVE_STACK_SLOTS; } + FrameInfo **callstack() { return callstack_buf; } +}; +struct GlobalState { + JSObject* globalObj; + uint32 globalShape; + SlotList* globalSlots; +}; +struct TraceMonitor { + JSContext *tracecx; + js::TracerState *tracerState; + js::VMSideExit *bailExit; + unsigned iterationCounter; + TraceNativeStorage *storage; + VMAllocator* dataAlloc; + VMAllocator* traceAlloc; + VMAllocator* tempAlloc; + nanojit::CodeAlloc* codeAlloc; + nanojit::Assembler* assembler; + FrameInfoCache* frameCache; + uintN flushEpoch; + Oracle* oracle; + TraceRecorder* recorder; + LoopProfile* profile; + GlobalState globalStates[MONITOR_N_GLOBAL_STATES]; + TreeFragment *vmfragments[FRAGMENT_TABLE_SIZE]; + RecordAttemptMap* recordAttempts; + LoopProfileMap* loopProfiles; + uint32 maxCodeCacheBytes; + JSBool needFlush; + TypeMap* cachedTempTypeMap; + TracedScriptSet tracedScripts; + bool ontrace() const { + return !!tracecx; + } + void flush(); + void sweep(JSContext *cx); + void mark(JSTracer *trc); + bool outOfMemory() const; +}; +namespace mjit { +class JaegerCompartment; +} +} +namespace js { +class NativeIterCache { + static const size_t SIZE = size_t(1) << 8; + JSObject *data[SIZE]; + static size_t getIndex(uint32 key) { + return size_t(key) % SIZE; + } + public: + JSObject *last; + NativeIterCache() + : last(__null) { + PodArrayZero(data); + } + void purge() { + PodArrayZero(data); + last = __null; + } + JSObject *get(uint32 key) const { + return data[getIndex(key)]; + } + void set(uint32 key, JSObject *iterobj) { + data[getIndex(key)] = iterobj; + } +}; +class DtoaCache { + double d; + jsint base; + JSString *s; + public: + DtoaCache() : s(__null) {} + void purge() { s = __null; } + JSString *lookup(jsint base, double d) { + return this->s && base == this->base && d == this->d ? this->s : __null; + } + void cache(jsint base, double d, JSString *s) { + this->base = base; + this->d = d; + this->s = s; + } +}; +} +struct __attribute__((visibility ("default"))) JSCompartment { + JSRuntime *rt; + JSPrincipals *principals; + js::gc::Chunk *chunk; + js::gc::ArenaList arenas[js::gc::FINALIZE_LIMIT]; + js::gc::FreeLists freeLists; + size_t gcBytes; + size_t gcTriggerBytes; + size_t gcLastBytes; + JSScript *scriptsToGC[((JSUint32)1 << (6))]; + void *data; + bool active; + js::WrapperMap crossCompartmentWrappers; + js::PropertyTree propertyTree; + js::EmptyShape *emptyArgumentsShape; + js::EmptyShape *emptyBlockShape; + js::EmptyShape *emptyCallShape; + js::EmptyShape *emptyDeclEnvShape; + js::EmptyShape *emptyEnumeratorShape; + js::EmptyShape *emptyWithShape; + typedef js::HashSet, + js::SystemAllocPolicy> EmptyShapeSet; + EmptyShapeSet emptyShapes; + bool debugMode; + JSCList scripts; + JSC::ExecutableAllocator *regExpAllocator; + js::NativeIterCache nativeIterCache; + js::ToSourceCache toSourceCache; + JSCompartment(JSRuntime *rt); + ~JSCompartment(); + bool init(); + void markCrossCompartment(JSTracer *trc); + void mark(JSTracer *trc); + bool wrap(JSContext *cx, js::Value *vp); + bool wrap(JSContext *cx, JSString **strp); + bool wrap(JSContext *cx, JSObject **objp); + bool wrapId(JSContext *cx, jsid *idp); + bool wrap(JSContext *cx, js::PropertyOp *op); + bool wrap(JSContext *cx, js::StrictPropertyOp *op); + bool wrap(JSContext *cx, js::PropertyDescriptor *desc); + bool wrap(JSContext *cx, js::AutoIdVector &props); + void sweep(JSContext *cx, uint32 releaseInterval); + void purge(JSContext *cx); + void finishArenaLists(); + void finalizeObjectArenaLists(JSContext *cx); + void finalizeStringArenaLists(JSContext *cx); + bool arenaListsAreEmpty(); + void setGCLastBytes(size_t lastBytes); + js::DtoaCache dtoaCache; + private: + js::MathCache *mathCache; + js::MathCache *allocMathCache(JSContext *cx); + bool marked; + typedef js::HashMap, + js::SystemAllocPolicy> BackEdgeMap; + BackEdgeMap backEdgeTable; + JSCompartment *thisForCtor() { return this; } + public: + js::MathCache *getMathCache(JSContext *cx) { + return mathCache ? mathCache : allocMathCache(cx); + } + bool isMarked() { return marked; } + void clearMark() { marked = false; } + size_t backEdgeCount(jsbytecode *pc) const; + size_t incBackEdgeCount(jsbytecode *pc); +}; +static inline + bool +JS_ON_TRACE(JSContext *cx) +{ + return false; +} +static inline js::TraceRecorder * +TRACE_RECORDER(JSContext *cx) +{ + return __null; +} +static inline js::LoopProfile * +TRACE_PROFILER(JSContext *cx) +{ + return __null; +} +namespace js { +static inline MathCache * +GetMathCache(JSContext *cx) +{ + return cx->compartment->getMathCache(cx); +} +} +namespace js { +class PreserveCompartment { + protected: + JSContext *cx; + private: + JSCompartment *oldCompartment; + + public: + PreserveCompartment(JSContext *cx ) : cx(cx) { + do { } while (0); + oldCompartment = cx->compartment; + } + ~PreserveCompartment() { + cx->compartment = oldCompartment; + } +}; +class SwitchToCompartment : public PreserveCompartment { + public: + SwitchToCompartment(JSContext *cx, JSCompartment *newCompartment) : PreserveCompartment(cx) { + cx->compartment = newCompartment; + } + SwitchToCompartment(JSContext *cx, JSObject *target) : PreserveCompartment(cx) { + cx->compartment = target->getCompartment(); + } +}; +class AssertCompartmentUnchanged { + protected: + JSContext * const cx; + JSCompartment * const oldCompartment; + + public: + AssertCompartmentUnchanged(JSContext *cx ) + : cx(cx), oldCompartment(cx->compartment) { + do { } while (0); + } + ~AssertCompartmentUnchanged() { + ((void) 0); + } +}; +} +extern js::Class js_RegExpClass; +namespace js { +class RegExpStatics +{ + typedef Vector MatchPairs; + MatchPairs matchPairs; + JSLinearString *matchPairsInput; + JSString *pendingInput; + uintN flags; + RegExpStatics *bufferLink; + bool copied; + bool createDependent(JSContext *cx, size_t start, size_t end, Value *out) const; + void copyTo(RegExpStatics &dst) { + dst.matchPairs.clear(); + ((void) (dst.matchPairs.append(matchPairs))); + dst.matchPairsInput = matchPairsInput; + dst.pendingInput = pendingInput; + dst.flags = flags; + } + void aboutToWrite() { + if (bufferLink && !bufferLink->copied) { + copyTo(*bufferLink); + bufferLink->copied = true; + } + } + bool save(JSContext *cx, RegExpStatics *buffer) { + ((void) 0); + buffer->bufferLink = bufferLink; + bufferLink = buffer; + if (!buffer->matchPairs.reserve(matchPairs.length())) { + js_ReportOutOfMemory(cx); + return false; + } + return true; + } + void restore() { + if (bufferLink->copied) + bufferLink->copyTo(*this); + bufferLink = bufferLink->bufferLink; + } + void checkInvariants() { + } + void checkParenNum(size_t pairNum) const { + ((void) 0); + ((void) 0); + } + bool pairIsPresent(size_t pairNum) const { + return get(pairNum, 0) >= 0; + } + size_t getParenLength(size_t pairNum) const { + checkParenNum(pairNum); + ((void) 0); + return get(pairNum, 1) - get(pairNum, 0); + } + int get(size_t pairNum, bool which) const { + ((void) 0); + return matchPairs[2 * pairNum + which]; + } + bool makeMatch(JSContext *cx, size_t checkValidIndex, size_t pairNum, Value *out) const; + static const uintN allFlags = 0x01 | 0x02 | 0x08 | 0x04; + struct InitBuffer {}; + explicit RegExpStatics(InitBuffer) : bufferLink(__null), copied(false) {} + friend class PreserveRegExpStatics; + public: + RegExpStatics() : bufferLink(__null), copied(false) { clear(); } + static RegExpStatics *extractFrom(JSObject *global); + bool updateFromMatch(JSContext *cx, JSLinearString *input, int *buf, size_t matchItemCount) { + aboutToWrite(); + pendingInput = input; + if (!matchPairs.resizeUninitialized(matchItemCount)) { + js_ReportOutOfMemory(cx); + return false; + } + for (size_t i = 0; i < matchItemCount; ++i) + matchPairs[i] = buf[i]; + matchPairsInput = input; + return true; + } + void setMultiline(bool enabled) { + aboutToWrite(); + if (enabled) + flags = flags | 0x04; + else + flags = flags & ~0x04; + } + void clear() { + aboutToWrite(); + flags = 0; + pendingInput = __null; + matchPairsInput = __null; + matchPairs.clear(); + } + void reset(JSString *newInput, bool newMultiline) { + aboutToWrite(); + clear(); + pendingInput = newInput; + setMultiline(newMultiline); + checkInvariants(); + } + void setPendingInput(JSString *newInput) { + aboutToWrite(); + pendingInput = newInput; + } + private: + size_t pairCount() const { + ((void) 0); + return matchPairs.length() / 2; + } + public: + size_t parenCount() const { + size_t pc = pairCount(); + ((void) 0); + return pc - 1; + } + JSString *getPendingInput() const { return pendingInput; } + uintN getFlags() const { return flags; } + bool multiline() const { return flags & 0x04; } + size_t matchStart() const { + int start = get(0, 0); + ((void) 0); + return size_t(start); + } + size_t matchLimit() const { + int limit = get(0, 1); + ((void) 0); + return size_t(limit); + } + bool matched() const { + ((void) 0); + ((void) 0); + return get(0, 1) - get(0, 0) > 0; + } + void mark(JSTracer *trc) const { + if (pendingInput) + do { JSString *str_ = (pendingInput); ((void) 0); do { do { } while (0); JS_CallTracer(((trc)), (str_), (1)); } while (0); } while (0); + if (matchPairsInput) + do { JSString *str_ = (matchPairsInput); ((void) 0); do { do { } while (0); JS_CallTracer(((trc)), (str_), (1)); } while (0); } while (0); + } + bool createPendingInput(JSContext *cx, Value *out) const; + bool createLastMatch(JSContext *cx, Value *out) const { return makeMatch(cx, 0, 0, out); } + bool createLastParen(JSContext *cx, Value *out) const; + bool createLeftContext(JSContext *cx, Value *out) const; + bool createRightContext(JSContext *cx, Value *out) const; + bool createParen(JSContext *cx, size_t pairNum, Value *out) const { + ((void) 0); + if (pairNum >= pairCount()) { + out->setString(cx->runtime->emptyString); + return true; + } + return makeMatch(cx, pairNum * 2, pairNum, out); + } + void getParen(size_t pairNum, JSSubString *out) const; + void getLastMatch(JSSubString *out) const; + void getLastParen(JSSubString *out) const; + void getLeftContext(JSSubString *out) const; + void getRightContext(JSSubString *out) const; +}; +class PreserveRegExpStatics +{ + RegExpStatics *const original; + RegExpStatics buffer; + public: + explicit PreserveRegExpStatics(RegExpStatics *original) + : original(original), + buffer(RegExpStatics::InitBuffer()) + {} + bool init(JSContext *cx) { + return original->save(cx, &buffer); + } + ~PreserveRegExpStatics() { + original->restore(); + } +}; +} +static inline + bool +VALUE_IS_REGEXP(JSContext *cx, js::Value v) +{ + return !v.isPrimitive() && v.toObject().isRegExp(); +} +inline const js::Value & +JSObject::getRegExpLastIndex() const +{ + ((void) 0); + return getSlot(JSSLOT_REGEXP_LAST_INDEX); +} +inline void +JSObject::setRegExpLastIndex(const js::Value &v) +{ + ((void) 0); + setSlot(JSSLOT_REGEXP_LAST_INDEX, v); +} +inline void +JSObject::setRegExpLastIndex(jsdouble d) +{ + ((void) 0); + setSlot(JSSLOT_REGEXP_LAST_INDEX, js::NumberValue(d)); +} +inline void +JSObject::zeroRegExpLastIndex() +{ + ((void) 0); + getSlotRef(JSSLOT_REGEXP_LAST_INDEX).setInt32(0); +} +namespace js { class AutoStringRooter; } +inline + bool +JSObject::isRegExp() const +{ + return getClass() == &js_RegExpClass; +} +extern __attribute__((visibility ("default"))) JSBool +js_ObjectIsRegExp(JSObject *obj); +extern JSObject * +js_InitRegExpClass(JSContext *cx, JSObject *obj); +extern JSBool +js_regexp_toString(JSContext *cx, JSObject *obj, js::Value *vp); +extern __attribute__((visibility ("default"))) JSObject * +js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *proto); +extern __attribute__((visibility ("default"))) void +js_SaveAndClearRegExpStatics(JSContext *cx, js::RegExpStatics *res, js::AutoStringRooter *tvr); +extern __attribute__((visibility ("default"))) void +js_RestoreRegExpStatics(JSContext *cx, js::RegExpStatics *res); +extern JSBool +js_XDRRegExpObject(JSXDRState *xdr, JSObject **objp); +extern JSBool +js_regexp_exec(JSContext *cx, uintN argc, js::Value *vp); +extern JSBool +js_regexp_test(JSContext *cx, uintN argc, js::Value *vp); +namespace js { +static inline JSObject * +GetGlobalForScopeChain(JSContext *cx) +{ + ((void) 0); + if (cx->hasfp()) + return cx->fp()->scopeChain().getGlobal(); + JSObject *scope = cx->globalObject; + if (!scope) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_INACTIVE); + return __null; + } + OBJ_TO_INNER_OBJECT(cx, scope); + return scope; +} +} +inline + bool +JSContext::ensureGeneratorStackSpace() +{ + bool ok = genStack.reserve(genStack.length() + 1); + if (!ok) + js_ReportOutOfMemory(this); + return ok; +} +JSStackFrame * +JSContext::computeNextFrame(JSStackFrame *fp) +{ + JSStackFrame *next = __null; + for (js::StackSegment *ss = currentSegment; ; ss = ss->getPreviousInContext()) { + JSStackFrame *end = ss->getInitialFrame()->prev(); + for (JSStackFrame *f = ss->getCurrentFrame(); f != end; next = f, f = f->prev()) { + if (f == fp) + return next; + } + if (end != ss->getPreviousInContext()->getCurrentFrame()) + next = __null; + } +} +inline js::RegExpStatics * +JSContext::regExpStatics() +{ + return js::RegExpStatics::extractFrom(js::GetGlobalForScopeChain(this)); +} +namespace js { + __attribute__((always_inline)) inline JSFrameRegs * +StackSegment::getCurrentRegs() const +{ + ((void) 0); + return isActive() ? cx->regs : getSuspendedRegs(); +} + __attribute__((always_inline)) inline JSStackFrame * +StackSegment::getCurrentFrame() const +{ + return getCurrentRegs()->fp; +} + inline Value * +StackSpace::firstUnused() const +{ + StackSegment *seg = currentSegment; + if (!seg) { + ((void) 0); + return base; + } + if (seg->inContext()) { + Value *sp = seg->getCurrentRegs()->sp; + if (invokeArgEnd > sp) { + ((void) 0); + ((void) 0) + ; + return invokeArgEnd; + } + return sp; + } + ((void) 0); + ((void) 0); + return invokeArgEnd; +} +__attribute__((always_inline)) inline + bool +StackSpace::isCurrentAndActive(JSContext *cx) const +{ + return currentSegment && + currentSegment->isActive() && + currentSegment == cx->getCurrentSegment(); +} +__attribute__((always_inline)) inline + bool +StackSpace::ensureSpace(JSContext *maybecx, Value *from, ptrdiff_t nvals) const +{ + ((void) 0); + if (end - from < nvals) { + if (maybecx) + js_ReportOutOfScriptQuota(maybecx); + return false; + } + goto success; + success: + return true; +} +__attribute__((always_inline)) inline + bool +StackSpace::ensureEnoughSpaceToEnterTrace() +{ + return end - firstUnused() > MAX_TRACE_SPACE_VALS; +} +__attribute__((always_inline)) inline + bool +StackSpace::EnsureSpaceCheck::operator()(const StackSpace &stack, JSContext *cx, + Value *from, uintN nvals) +{ + return stack.ensureSpace(cx, from, nvals); +} +__attribute__((always_inline)) inline + bool +StackSpace::LimitCheck::operator()(const StackSpace &stack, JSContext *cx, + Value *from, uintN nvals) +{ + ((void) 0); + ((void) 0); + if (*limit - from >= ptrdiff_t(nvals)) + return true; + if (stack.bumpCommitAndLimit(base, from, nvals, limit)) + return true; + js_ReportOverRecursed(cx); + return false; +} + __attribute__((always_inline)) inline + bool +StackSpace::pushInvokeArgs(JSContext *cx, uintN argc, InvokeArgsGuard *ag) +{ + if ((__builtin_expect((!isCurrentAndActive(cx)), 0))) + return pushSegmentForInvoke(cx, argc, ag); + Value *sp = cx->regs->sp; + Value *start = invokeArgEnd > sp ? invokeArgEnd : sp; + ((void) 0); + uintN nvals = 2 + argc; + if (!ensureSpace(cx, start, nvals)) + return false; + Value *vp = start; + Value *vpend = vp + nvals; + ag->prevInvokeArgEnd = invokeArgEnd; + invokeArgEnd = vpend; + ag->cx = cx; + ag->argv_ = vp + 2; + ag->argc_ = argc; + return true; +} + __attribute__((always_inline)) inline void +StackSpace::popInvokeArgs(const InvokeArgsGuard &ag) +{ + if ((__builtin_expect((ag.seg != __null), 0))) { + popSegmentForInvoke(ag); + return; + } + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + invokeArgEnd = ag.prevInvokeArgEnd; +} +__attribute__((always_inline)) inline +InvokeArgsGuard::~InvokeArgsGuard() +{ + if ((__builtin_expect((!pushed()), 0))) + return; + cx->stack().popInvokeArgs(*this); +} +template + __attribute__((always_inline)) inline JSStackFrame * +StackSpace::getCallFrame(JSContext *cx, Value *firstUnused, uintN nactual, + JSFunction *fun, JSScript *script, uint32 *flags, + Check check) const +{ + ((void) 0); + uintN nvals = VALUES_PER_STACK_FRAME + script->nslots; + uintN nformal = fun->nargs; + if (nactual == nformal) { + if ((__builtin_expect((!check(*this, cx, firstUnused, nvals)), 0))) + return __null; + return reinterpret_cast(firstUnused); + } + if (nactual < nformal) { + *flags |= JSFRAME_UNDERFLOW_ARGS; + uintN nmissing = nformal - nactual; + if ((__builtin_expect((!check(*this, cx, firstUnused, nmissing + nvals)), 0))) + return __null; + SetValueRangeToUndefined(firstUnused, nmissing); + return reinterpret_cast(firstUnused + nmissing); + } + *flags |= JSFRAME_OVERFLOW_ARGS; + uintN ncopy = 2 + nformal; + if ((__builtin_expect((!check(*this, cx, firstUnused, ncopy + nvals)), 0))) + return __null; + Value *dst = firstUnused; + Value *src = firstUnused - (2 + nactual); + PodCopy(dst, src, ncopy); + Debug_SetValueRangeToCrashOnTouch(src, ncopy); + return reinterpret_cast(firstUnused + ncopy); +} + __attribute__((always_inline)) inline + bool +StackSpace::getInvokeFrame(JSContext *cx, const CallArgs &args, + JSFunction *fun, JSScript *script, + uint32 *flags, InvokeFrameGuard *fg) const +{ + ((void) 0); + Value *firstUnused = args.argv() + args.argc(); + fg->regs_.fp = getCallFrame(cx, firstUnused, args.argc(), fun, script, flags, + EnsureSpaceCheck()); + fg->regs_.sp = fg->regs_.fp->slots() + script->nfixed; + fg->regs_.pc = script->code; + return fg->regs_.fp != __null; +} + __attribute__((always_inline)) inline void +StackSpace::pushInvokeFrame(JSContext *cx, const CallArgs &args, + InvokeFrameGuard *fg) +{ + ((void) 0); + if ((__builtin_expect((!currentSegment->inContext()), 0))) { + cx->pushSegmentAndFrame(currentSegment, fg->regs_); + } else { + fg->prevRegs_ = cx->regs; + cx->setCurrentRegs(&fg->regs_); + } + fg->cx_ = cx; + ((void) 0); +} + __attribute__((always_inline)) inline void +StackSpace::popInvokeFrame(const InvokeFrameGuard &fg) +{ + JSContext *cx = fg.cx_; + JSStackFrame *fp = fg.regs_.fp; + ((void) 0); + if ((__builtin_expect((currentSegment->getInitialFrame() == fp), 0))) { + cx->popSegmentAndFrame(); + } else { + ((void) 0); + ((void) 0); + ((void) 0); + cx->setCurrentRegs(fg.prevRegs_); + } +} +__attribute__((always_inline)) inline void +InvokeFrameGuard::pop() +{ + ((void) 0); + cx_->stack().popInvokeFrame(*this); + cx_ = __null; +} + __attribute__((always_inline)) inline JSStackFrame * +StackSpace::getInlineFrame(JSContext *cx, Value *sp, uintN nactual, + JSFunction *fun, JSScript *script, uint32 *flags) const +{ + ((void) 0); + ((void) 0); + ((void) 0); + return getCallFrame(cx, sp, nactual, fun, script, flags, EnsureSpaceCheck()); +} + __attribute__((always_inline)) inline JSStackFrame * +StackSpace::getInlineFrameWithinLimit(JSContext *cx, Value *sp, uintN nactual, + JSFunction *fun, JSScript *script, uint32 *flags, + JSStackFrame *base, Value **limit) const +{ + ((void) 0); + ((void) 0); + ((void) 0); + return getCallFrame(cx, sp, nactual, fun, script, flags, LimitCheck(base, limit)); +} + __attribute__((always_inline)) inline void +StackSpace::pushInlineFrame(JSContext *cx, JSScript *script, JSStackFrame *fp, + JSFrameRegs *regs) +{ + ((void) 0); + ((void) 0); + regs->fp = fp; + regs->pc = script->code; + regs->sp = fp->slots() + script->nfixed; +} + __attribute__((always_inline)) inline void +StackSpace::popInlineFrame(JSContext *cx, JSStackFrame *prev, Value *newsp) +{ + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + JSFrameRegs *regs = cx->regs; + regs->pc = prev->pc(cx, regs->fp); + regs->fp = prev; + regs->sp = newsp; +} +__attribute__((always_inline)) inline Value * +StackSpace::getStackLimit(JSContext *cx) +{ + Value *sp = cx->regs->sp; + ((void) 0); + Value *limit = sp + STACK_QUOTA; + if ((__builtin_expect((limit <= end), 1))) + return limit; + uintN minimum = cx->fp()->numSlots() + VALUES_PER_STACK_FRAME; + return ensureSpace(cx, sp, minimum) ? sp + minimum : __null; +} + inline +FrameRegsIter::FrameRegsIter(JSContext *cx) + : cx(cx) +{ + curseg = cx->getCurrentSegment(); + if ((__builtin_expect((!curseg || !curseg->isActive()), 0))) { + initSlow(); + return; + } + ((void) 0); + curfp = cx->regs->fp; + cursp = cx->regs->sp; + curpc = cx->regs->pc; + return; +} +inline FrameRegsIter & +FrameRegsIter::operator++() +{ + JSStackFrame *fp = curfp; + JSStackFrame *prev = curfp = curfp->prev(); + if (!prev) + return *this; + curpc = curfp->pc(cx, fp); + if ((__builtin_expect((fp == curseg->getInitialFrame()), 0))) { + incSlow(fp, prev); + return *this; + } + cursp = fp->formalArgsEnd(); + return *this; +} +class AutoNamespaceArray : protected AutoGCRooter { + public: + AutoNamespaceArray(JSContext *cx) : AutoGCRooter(cx, NAMESPACES) { + array.init(); + } + ~AutoNamespaceArray() { + array.finish(context); + } + uint32 length() const { return array.length; } + public: + friend void AutoGCRooter::trace(JSTracer *trc); + JSXMLArray array; +}; +template inline void +assertSameCompartment(JSContext *cx, T1 t1) +{ +} +template inline void +assertSameCompartment(JSContext *cx, T1 t1, T2 t2) +{ +} +template inline void +assertSameCompartment(JSContext *cx, T1 t1, T2 t2, T3 t3) +{ +} +template inline void +assertSameCompartment(JSContext *cx, T1 t1, T2 t2, T3 t3, T4 t4) +{ +} +template inline void +assertSameCompartment(JSContext *cx, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) +{ +} +__attribute__((always_inline)) inline + bool +CallJSNative(JSContext *cx, js::Native native, uintN argc, js::Value *vp) +{ + assertSameCompartment(cx, ValueArray(vp, argc + 2)); + JSBool ok = native(cx, argc, vp); + if (ok) { + assertSameCompartment(cx, vp[0]); + ((void) 0); + } + return ok; +} +extern JSBool CallOrConstructBoundFunction(JSContext *, uintN, js::Value *); +__attribute__((always_inline)) inline + bool +CallJSNativeConstructor(JSContext *cx, js::Native native, uintN argc, js::Value *vp) +{ + ((void) 0); + if (!CallJSNative(cx, native, argc, vp)) + return false; + extern JSBool proxy_Construct(JSContext *, uintN, Value *); + ((void) 0) + ; + return true; +} +__attribute__((always_inline)) inline + bool +CallJSPropertyOp(JSContext *cx, js::PropertyOp op, JSObject *obj, jsid id, js::Value *vp) +{ + assertSameCompartment(cx, obj, id, *vp); + JSBool ok = op(cx, obj, id, vp); + if (ok) + assertSameCompartment(cx, obj, *vp); + return ok; +} +__attribute__((always_inline)) inline + bool +CallJSPropertyOpSetter(JSContext *cx, js::StrictPropertyOp op, JSObject *obj, jsid id, + JSBool strict, js::Value *vp) +{ + assertSameCompartment(cx, obj, id, *vp); + return op(cx, obj, id, strict, vp); +} +inline + bool +CallSetter(JSContext *cx, JSObject *obj, jsid id, js::StrictPropertyOp op, uintN attrs, + uintN shortid, JSBool strict, js::Value *vp) +{ + if (attrs & 0x20) + return ExternalGetOrSet(cx, obj, id, CastAsObjectJsval(op), JSACC_WRITE, 1, vp, vp); + if (attrs & 0x10) + return js_ReportGetterOnlyAssignment(cx); + if (attrs & 0x100) + id = INT_TO_JSID(shortid); + return CallJSPropertyOpSetter(cx, op, obj, id, strict, vp); +} +static inline void +LeaveTraceIfGlobalObject(JSContext *cx, JSObject *obj) +{ + if (!obj->parent) + LeaveTrace(cx); +} +static inline void +LeaveTraceIfArgumentsObject(JSContext *cx, JSObject *obj) +{ + if (obj->isArguments()) + LeaveTrace(cx); +} +static inline JSBool +CanLeaveTrace(JSContext *cx) +{ + ((void) 0); + return (JSIntn)0; +} +} +inline void +JSContext::setPendingException(js::Value v) { + this->throwing = true; + this->exception = v; + assertSameCompartment(this, v); +} +namespace js { +static inline + bool +CheckStringLength(JSContext *cx, size_t length) +{ + if ((__builtin_expect((length > JSString::MAX_LENGTH), 0))) { + js_ReportAllocationOverflow(cx); + return false; + } + return true; +} +class StringBuffer +{ + typedef Vector CharBuffer; + CharBuffer cb; + static inline bool checkLength(JSContext *cx, size_t length); + inline bool checkLength(size_t length); + JSContext *context() const { return cb.allocPolicy().context(); } + public: + explicit inline StringBuffer(JSContext *cx); + bool reserve(size_t len); + bool resize(size_t len); + bool append(const jschar c); + bool append(const jschar *chars, size_t len); + bool append(const jschar *begin, const jschar *end); + bool append(JSString *str); + bool append(JSAtom *atom); + bool appendN(const jschar c, size_t n); + bool appendInflated(const char *cstr, size_t len); + JSAtom *atomize(uintN flags = 0); + static JSAtom *atomize(JSContext *cx, const CharBuffer &cb, uintN flags = 0); + static JSAtom *atomize(JSContext *cx, const jschar *begin, size_t length, uintN flags = 0); + void replaceRawBuffer(jschar *chars, size_t len) { cb.replaceRawBuffer(chars, len); } + jschar *begin() { return cb.begin(); } + jschar *end() { return cb.end(); } + const jschar *begin() const { return cb.begin(); } + const jschar *end() const { return cb.end(); } + bool empty() const { return cb.empty(); } + inline jsint length() const; + JSFlatString *finishString(); + template + bool append(const char (&array)[ArrayLength]) { + return cb.append(array, array + ArrayLength - 1); + } +}; +inline +StringBuffer::StringBuffer(JSContext *cx) + : cb(cx) +{} +inline + bool +StringBuffer::reserve(size_t len) +{ + if (!checkLength(len)) + return false; + return cb.reserve(len); +} +inline + bool +StringBuffer::resize(size_t len) +{ + if (!checkLength(len)) + return false; + return cb.resize(len); +} +inline + bool +StringBuffer::append(const jschar c) +{ + if (!checkLength(cb.length() + 1)) + return false; + return cb.append(c); +} +inline + bool +StringBuffer::append(const jschar *chars, size_t len) +{ + if (!checkLength(cb.length() + len)) + return false; + return cb.append(chars, len); +} +inline + bool +StringBuffer::append(const jschar *begin, const jschar *end) +{ + if (!checkLength(cb.length() + (end - begin))) + return false; + return cb.append(begin, end); +} +inline + bool +StringBuffer::append(JSString *str) +{ + JSLinearString *linear = str->ensureLinear(context()); + size_t strLen = linear->length(); + if (!checkLength(cb.length() + strLen)) + return false; + return cb.append(linear->chars(), strLen); +} +inline + bool +StringBuffer::append(JSAtom *atom) +{ + size_t strLen = atom->length(); + if (!checkLength(cb.length() + strLen)) + return false; + return cb.append(atom->chars(), strLen); +} +inline + bool +StringBuffer::appendN(const jschar c, size_t n) +{ + if (!checkLength(cb.length() + n)) + return false; + return cb.appendN(c, n); +} +inline + bool +StringBuffer::appendInflated(const char *cstr, size_t cstrlen) +{ + size_t lengthBefore = length(); + if (!cb.growByUninitialized(cstrlen)) + return false; + js_InflateStringToBuffer(context(), cstr, cstrlen, begin() + lengthBefore, &cstrlen); + ((void) 0); + return true; +} +inline jsint +StringBuffer::length() const +{ + typedef int js_static_assert65[(jsint(JSString::MAX_LENGTH) == JSString::MAX_LENGTH) ? 1 : -1]; + ((void) 0); + return jsint(cb.length()); +} +inline + bool +StringBuffer::checkLength(size_t length) +{ + return CheckStringLength(context(), length); +} +} +inline JSFlatString * +JSString::unitString(jschar c) +{ + ((void) 0); + return const_cast(&unitStringTable[c])->assertIsFlat(); +} +inline JSLinearString * +JSString::getUnitString(JSContext *cx, JSString *str, size_t index) +{ + ((void) 0); + const jschar *chars = str->getChars(cx); + if (!chars) + return __null; + jschar c = chars[index]; + if (c < UNIT_STRING_LIMIT) + return unitString(c); + return js_NewDependentString(cx, str, index, 1); +} +inline JSFlatString * +JSString::length2String(jschar c1, jschar c2) +{ + ((void) 0); + ((void) 0); + return const_cast ( + &length2StringTable[(((size_t)toSmallChar[c1]) << 6) + toSmallChar[c2]] + )->assertIsFlat(); +} +inline JSFlatString * +JSString::length2String(uint32 i) +{ + ((void) 0); + return length2String('0' + i / 10, '0' + i % 10); +} +inline JSFlatString * +JSString::intString(jsint i) +{ + jsuint u = jsuint(i); + ((void) 0); + return const_cast(JSString::intStringTable[u])->assertIsFlat(); +} +inline JSFlatString * +JSString::lookupStaticString(const jschar *chars, size_t length) +{ + if (length == 1) { + if (chars[0] < UNIT_STRING_LIMIT) + return unitString(chars[0]); + } + if (length == 2) { + if (fitsInSmallChar(chars[0]) && fitsInSmallChar(chars[1])) + return length2String(chars[0], chars[1]); + } + typedef int js_static_assert66[(INT_STRING_LIMIT <= 999) ? 1 : -1]; + if (length == 3) { + if ('1' <= chars[0] && chars[0] <= '9' && + '0' <= chars[1] && chars[1] <= '9' && + '0' <= chars[2] && chars[2] <= '9') { + jsint i = (chars[0] - '0') * 100 + + (chars[1] - '0') * 10 + + (chars[2] - '0'); + if (jsuint(i) < INT_STRING_LIMIT) + return intString(i); + } + } + return __null; +} +inline void +JSString::finalize(JSContext *cx) { + ((void) 0); + ; + if (isDependent()) { + ; + } else if (isFlat()) { + cx->runtime->stringMemoryUsed -= length() * 2; + cx->free(const_cast(flatChars())); + } +} +inline void +JSShortString::finalize(JSContext *cx) +{ + ((void) 0); + ((void) 0); + ; +} +inline void +JSExternalString::finalize(JSContext *cx) +{ + ((void) 0); + ((void) 0); + ((void) 0); + ; + jschar *chars = const_cast(flatChars()); + if (!chars) + return; + JSStringFinalizeOp finalizer = str_finalizers[externalStringType]; + if (finalizer) + finalizer(cx, this); +} +inline void +JSExternalString::finalize() +{ + ((void) 0); + JSStringFinalizeOp finalizer = str_finalizers[externalStringType]; + if (finalizer) { + finalizer(__null, this); + } +} +namespace js { +class RopeBuilder { + JSContext *cx; + JSString *res; + public: + RopeBuilder(JSContext *cx) + : cx(cx), res(cx->runtime->emptyString) + {} + inline bool append(JSString *str) { + res = js_ConcatStrings(cx, res, str); + return !!res; + } + inline JSString *result() { + return res; + } +}; +class StringSegmentRange +{ + Vector stack; + JSString *cur; + bool settle(JSString *str) { + while (str->isRope()) { + if (!stack.append(str->ropeRight())) + return false; + str = str->ropeLeft(); + } + cur = str; + return true; + } + public: + StringSegmentRange(JSContext *cx) + : stack(cx), cur(__null) + {} + __attribute__((warn_unused_result)) bool init(JSString *str) { + ((void) 0); + return settle(str); + } + bool empty() const { + return cur == __null; + } + JSString *front() const { + ((void) 0); + return cur; + } + __attribute__((warn_unused_result)) bool popFront() { + ((void) 0); + if (stack.empty()) { + cur = __null; + return true; + } + return settle(stack.popCopy()); + } +}; +} +namespace js { +struct PropertyTable { + static const uint32 MAX_LINEAR_SEARCHES = 7; + static const uint32 MIN_SIZE_LOG2 = 4; + static const uint32 MIN_SIZE = ((JSUint32)1 << (MIN_SIZE_LOG2)); + int hashShift; + uint32 entryCount; + uint32 removedCount; + uint32 freelist; + js::Shape **entries; + PropertyTable(uint32 nentries) + : hashShift(32 - MIN_SIZE_LOG2), + entryCount(nentries), + removedCount(0), + freelist(0xffffffff) + { + } + ~PropertyTable() { + js_free(entries); + } + uint32 capacity() const { return ((JSUint32)1 << (32 - hashShift)); } + bool needsToGrow() const { + uint32 size = capacity(); + return entryCount + removedCount >= size - (size >> 2); + } + bool grow(JSContext *cx); + bool init(JSRuntime *rt, js::Shape *lastProp); + bool change(int log2Delta, JSContext *cx); + js::Shape **search(jsid id, bool adding); +}; +} +struct JSObject; +namespace js { +class PropertyTree; +static inline PropertyOp +CastAsPropertyOp(js::Class *clasp) +{ + return (__extension__ (PropertyOp) (size_t) (clasp)); +} +struct Shape : public JSObjectMap +{ + friend struct ::JSObject; + friend struct ::JSFunction; + friend class js::PropertyTree; + friend class js::Bindings; + friend bool IsShapeAboutToBeFinalized(JSContext *cx, const js::Shape *shape); + union { + mutable size_t numLinearSearches; + mutable js::PropertyTable *table; + }; + public: + inline void freeTable(JSContext *cx); + static bool initEmptyShapes(JSCompartment *comp); + static void finishEmptyShapes(JSCompartment *comp); + jsid id; + protected: + union { + js::PropertyOp rawGetter; + JSObject *getterObj; + js::Class *clasp; + }; + union { + js::StrictPropertyOp rawSetter; + JSObject *setterObj; + }; + public: + uint32 slot; + private: + uint8 attrs; + mutable uint8 flags; + public: + int16 shortid; + protected: + mutable js::Shape *parent; + union { + mutable js::KidsPointer kids; + mutable js::Shape **listp; + }; + static inline js::Shape **search(JSRuntime *rt, js::Shape **startp, jsid id, + bool adding = false); + static js::Shape *newDictionaryShape(JSContext *cx, const js::Shape &child, js::Shape **listp); + static js::Shape *newDictionaryList(JSContext *cx, js::Shape **listp); + inline void removeFromDictionary(JSObject *obj) const; + inline void insertIntoDictionary(js::Shape **dictp); + js::Shape *getChild(JSContext *cx, const js::Shape &child, js::Shape **listp); + bool hashify(JSRuntime *rt); + bool hasTable() const { + return numLinearSearches > PropertyTable::MAX_LINEAR_SEARCHES; + } + js::PropertyTable *getTable() const { + ((void) 0); + return table; + } + void setTable(js::PropertyTable *t) const { + ((void) 0); + table = t; + } + void setParent(js::Shape *p) { + typedef int js_static_assert67[(uint32(0xffffffff) == ~uint32(0)) ? 1 : -1]; + if (p) + slotSpan = ((p->slotSpan)>(slot + 1)?(p->slotSpan):(slot + 1)); + ((void) 0); + parent = p; + } + void insertFree(js::Shape **freep) { + id = ((jsid)0x2); + parent = *freep; + if (parent) + parent->listp = &parent; + listp = freep; + *freep = this; + } + void removeFree() { + ((void) 0); + *listp = parent; + if (parent) + parent->listp = listp; + } + public: + const js::Shape *previous() const { + return parent; + } + class Range { + protected: + friend struct Shape; + const Shape *cursor; + const Shape *end; + public: + Range(const Shape *shape) : cursor(shape) { } + bool empty() const { + ((void) 0); + return !cursor->parent; + } + const Shape &front() const { + ((void) 0); + return *cursor; + } + void popFront() { + ((void) 0); + cursor = cursor->parent; + } + }; + Range all() const { + return Range(this); + } + protected: + enum { + MARK = 0x01, + SHARED_EMPTY = 0x02, + SHAPE_REGEN = 0x04, + IN_DICTIONARY = 0x08, + FROZEN = 0x10 + }; + Shape(jsid id, js::PropertyOp getter, js::StrictPropertyOp setter, uint32 slot, uintN attrs, + uintN flags, intN shortid, uint32 shape = INVALID_SHAPE, uint32 slotSpan = 0); + Shape(JSCompartment *comp, Class *aclasp); + bool marked() const { return (flags & MARK) != 0; } + void mark() const { flags |= MARK; } + void clearMark() { flags &= ~MARK; } + bool hasRegenFlag() const { return (flags & SHAPE_REGEN) != 0; } + void setRegenFlag() { flags |= SHAPE_REGEN; } + void clearRegenFlag() { flags &= ~SHAPE_REGEN; } + bool inDictionary() const { return (flags & IN_DICTIONARY) != 0; } + bool frozen() const { return (flags & FROZEN) != 0; } + void setFrozen() { flags |= FROZEN; } + bool isEmptyShape() const { ((void) 0); return !parent; } + public: + enum { + ALIAS = 0x20, + HAS_SHORTID = 0x40, + METHOD = 0x80, + PUBLIC_FLAGS = ALIAS | HAS_SHORTID | METHOD + }; + uintN getFlags() const { return flags & PUBLIC_FLAGS; } + bool isAlias() const { return (flags & ALIAS) != 0; } + bool hasShortID() const { return (flags & HAS_SHORTID) != 0; } + bool isMethod() const { return (flags & METHOD) != 0; } + JSObject &methodObject() const { ((void) 0); return *getterObj; } + js::PropertyOp getter() const { return rawGetter; } + bool hasDefaultGetter() const { return !rawGetter; } + js::PropertyOp getterOp() const { ((void) 0); return rawGetter; } + JSObject *getterObject() const { ((void) 0); return getterObj; } + js::Value getterValue() const { + ((void) 0); + return getterObj ? js::ObjectValue(*getterObj) : js::UndefinedValue(); + } + js::Value getterOrUndefined() const { + return hasGetterValue() && getterObj ? js::ObjectValue(*getterObj) : js::UndefinedValue(); + } + js::StrictPropertyOp setter() const { return rawSetter; } + bool hasDefaultSetter() const { return !rawSetter; } + js::StrictPropertyOp setterOp() const { ((void) 0); return rawSetter; } + JSObject *setterObject() const { ((void) 0); return setterObj; } + js::Value setterValue() const { + ((void) 0); + return setterObj ? js::ObjectValue(*setterObj) : js::UndefinedValue(); + } + js::Value setterOrUndefined() const { + return hasSetterValue() && setterObj ? js::ObjectValue(*setterObj) : js::UndefinedValue(); + } + inline JSDHashNumber hash() const; + inline bool matches(const js::Shape *p) const; + inline bool matchesParamsAfterId(js::PropertyOp agetter, js::StrictPropertyOp asetter, + uint32 aslot, uintN aattrs, uintN aflags, + intN ashortid) const; + bool get(JSContext* cx, JSObject *receiver, JSObject *obj, JSObject *pobj, js::Value* vp) const; + bool set(JSContext* cx, JSObject *obj, bool strict, js::Value* vp) const; + inline bool isSharedPermanent() const; + void trace(JSTracer *trc) const; + bool hasSlot() const { return (attrs & 0x40) == 0; } + uint8 attributes() const { return attrs; } + bool configurable() const { return (attrs & 0x04) == 0; } + bool enumerable() const { return (attrs & 0x01) != 0; } + bool writable() const { + return (attrs & 0x02) == 0; + } + bool hasGetterValue() const { return attrs & 0x10; } + bool hasSetterValue() const { return attrs & 0x20; } + bool hasDefaultGetterOrIsMethod() const { + return hasDefaultGetter() || isMethod(); + } + bool isDataDescriptor() const { + return (attrs & (0x20 | 0x10)) == 0; + } + bool isAccessorDescriptor() const { + return (attrs & (0x20 | 0x10)) != 0; + } + bool shadowable() const { + ((void) 0); + return hasSlot() || (attrs & 0x80); + } + uint32 entryCount() const { + if (hasTable()) + return getTable()->entryCount; + const js::Shape *shape = this; + uint32 count = 0; + for (js::Shape::Range r = shape->all(); !r.empty(); r.popFront()) + ++count; + return count; + } +}; +struct EmptyShape : public js::Shape +{ + EmptyShape(JSCompartment *comp, js::Class *aclasp); + js::Class *getClass() const { return clasp; }; + static EmptyShape *create(JSCompartment *comp, js::Class *clasp) { + js::Shape *eprop = comp->propertyTree.newShapeUnchecked(); + if (!eprop) + return __null; + return new (eprop) EmptyShape(comp, clasp); + } + static EmptyShape *create(JSContext *cx, js::Class *clasp) { + js::Shape *eprop = ((cx)->compartment->propertyTree).newShape(cx); + if (!eprop) + return __null; + return new (eprop) EmptyShape(cx->compartment, clasp); + } +}; +} +inline js::Shape ** +JSObject::nativeSearch(jsid id, bool adding) +{ + return js::Shape::search(compartment()->rt, &lastProp, id, adding); +} +inline const js::Shape * +JSObject::nativeLookup(jsid id) +{ + ((void) 0); + return ((js::Shape *) (jsuword(*(nativeSearch(id))) & ~(jsuword(1)))); +} +inline + bool +JSObject::nativeContains(jsid id) +{ + return nativeLookup(id) != __null; +} +inline + bool +JSObject::nativeContains(const js::Shape &shape) +{ + return nativeLookup(shape.id) == &shape; +} +inline const js::Shape * +JSObject::lastProperty() const +{ + ((void) 0); + ((void) 0); + return lastProp; +} +inline + bool +JSObject::nativeEmpty() const +{ + return lastProperty()->isEmptyShape(); +} +inline + bool +JSObject::inDictionaryMode() const +{ + return lastProperty()->inDictionary(); +} +inline uint32 +JSObject::propertyCount() const +{ + return lastProperty()->entryCount(); +} +inline + bool +JSObject::hasPropertyTable() const +{ + return lastProperty()->hasTable(); +} +inline void +JSObject::setLastProperty(const js::Shape *shape) +{ + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + lastProp = const_cast(shape); +} +inline void +JSObject::removeLastProperty() +{ + ((void) 0); + ((void) 0); + lastProp = lastProp->parent; +} +namespace js { +inline void +Shape::removeFromDictionary(JSObject *obj) const +{ + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + if (parent) + parent->listp = listp; + *listp = parent; + listp = __null; +} +inline void +Shape::insertIntoDictionary(js::Shape **dictp) +{ + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + setParent(*dictp); + if (parent) + parent->listp = &parent; + listp = dictp; + *dictp = this; +} +} +extern uint32 +js_GenerateShape(JSRuntime *rt); +extern uint32 +js_GenerateShape(JSContext *cx); +namespace js { +__attribute__((always_inline)) inline js::Shape ** +Shape::search(JSRuntime *rt, js::Shape **startp, jsid id, bool adding) +{ + js::Shape *start = *startp; + ; + if (start->hasTable()) + return start->getTable()->search(id, adding); + if (start->numLinearSearches == PropertyTable::MAX_LINEAR_SEARCHES) { + if (start->hashify(rt)) + return start->getTable()->search(id, adding); + ((void) 0); + } else { + ((void) 0); + start->numLinearSearches++; + } + js::Shape **spp; + for (spp = startp; js::Shape *shape = *spp; spp = &shape->parent) { + if (shape->id == id) { + ; + return spp; + } + } + ; + return spp; +} +inline + bool +Shape::isSharedPermanent() const +{ + return (~attrs & (0x40 | 0x04)) == 0; +} +} +inline + bool +js_ValueToAtom(JSContext *cx, const js::Value &v, JSAtom **atomp) +{ + JSString *str; + JSAtom *atom; + if (v.isString()) { + str = v.toString(); + if (str->isAtomized()) { + *atomp = (((void) 0), (JSAtom *)str); + return true; + } + } else { + str = js_ValueToString(cx, v); + if (!str) + return false; + } + atom = js_AtomizeString(cx, str, 0); + if (!atom) + return false; + *atomp = atom; + return true; +} +inline + bool +js_ValueToStringId(JSContext *cx, const js::Value &v, jsid *idp) +{ + JSAtom *atom; + if (js_ValueToAtom(cx, v, &atom)) { + *idp = ATOM_TO_JSID(atom); + return true; + } + return false; +} +inline + bool +js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval, + jsid *idp) +{ + ((void) 0); + extern bool js_InternNonIntElementIdSlow(JSContext *, JSObject *, + const js::Value &, jsid *); + if (idval.isObject()) + return js_InternNonIntElementIdSlow(cx, obj, idval, idp); + return js_ValueToStringId(cx, idval, idp); +} +inline + bool +js_InternNonIntElementId(JSContext *cx, JSObject *obj, const js::Value &idval, + jsid *idp, js::Value *vp) +{ + ((void) 0); + extern bool js_InternNonIntElementIdSlow(JSContext *, JSObject *, + const js::Value &, + jsid *, js::Value *); + if (idval.isObject()) + return js_InternNonIntElementIdSlow(cx, obj, idval, idp, vp); + JSAtom *atom; + if (js_ValueToAtom(cx, idval, &atom)) { + *idp = ATOM_TO_JSID(atom); + vp->setString((atom)); + return true; + } + return false; +} +inline + bool +js_Int32ToId(JSContext* cx, int32 index, jsid* id) +{ + if (INT_FITS_IN_JSID(index)) { + *id = INT_TO_JSID(index); + return true; + } + JSString* str = js_NumberToString(cx, index); + if (!str) + return false; + return js_ValueToStringId(cx, js::StringValue(str), id); +} +namespace js { +class Probes { + static const char nullName[]; + static const char *FunctionClassname(const JSFunction *fun); + static const char *ScriptFilename(JSScript *script); + static int FunctionLineNumber(JSContext *cx, const JSFunction *fun); + static const char *FunctionName(JSContext *cx, const JSFunction *fun, JSAutoByteString *bytes); + static void enterJSFunImpl(JSContext *cx, JSFunction *fun, JSScript *script); + static void handleFunctionReturn(JSContext *cx, JSFunction *fun, JSScript *script); + static void finalizeObjectImpl(JSObject *obj); + public: + static bool callTrackingActive(JSContext *); + static void enterJSFun(JSContext *, JSFunction *, JSScript *, int counter = 1); + static void exitJSFun(JSContext *, JSFunction *, JSScript *, int counter = 0); + static void startExecution(JSContext *cx, JSScript *script); + static void stopExecution(JSContext *cx, JSScript *script); + static void resizeHeap(JSCompartment *compartment, size_t oldSize, size_t newSize); + static void createObject(JSContext *cx, JSObject *obj); + static void resizeObject(JSContext *cx, JSObject *obj, size_t oldSize, size_t newSize); + static void finalizeObject(JSObject *obj); + static void createString(JSContext *cx, JSString *string, size_t length); + static void finalizeString(JSString *string); + static void compileScriptBegin(JSContext *cx, const char *filename, int lineno); + static void compileScriptEnd(JSContext *cx, JSScript *script, const char *filename, int lineno); + static void calloutBegin(JSContext *cx, JSFunction *fun); + static void calloutEnd(JSContext *cx, JSFunction *fun); + static void acquireMemory(JSContext *cx, void *address, size_t nbytes); + static void releaseMemory(JSContext *cx, void *address, size_t nbytes); + static void GCStart(JSCompartment *compartment); + static void GCEnd(JSCompartment *compartment); + static void GCStartMarkPhase(JSCompartment *compartment); + static void GCEndMarkPhase(JSCompartment *compartment); + static void GCStartSweepPhase(JSCompartment *compartment); + static void GCEndSweepPhase(JSCompartment *compartment); + static bool CustomMark(JSString *string); + static bool CustomMark(const char *string); + static bool CustomMark(int marker); + static bool startProfiling(); + static void stopProfiling(); +}; +inline + bool +Probes::callTrackingActive(JSContext *cx) +{ + return false; +} +inline void +Probes::enterJSFun(JSContext *cx, JSFunction *fun, JSScript *script, int counter) +{ +} +inline void +Probes::exitJSFun(JSContext *cx, JSFunction *fun, JSScript *script, int counter) +{ +} +inline void +Probes::createObject(JSContext *cx, JSObject *obj) +{ +} +inline void +Probes::finalizeObject(JSObject *obj) +{ +} +inline void +Probes::startExecution(JSContext *cx, JSScript *script) +{ +} +inline void +Probes::stopExecution(JSContext *cx, JSScript *script) +{ +} +inline void Probes::resizeHeap(JSCompartment *compartment, size_t oldSize, size_t newSize) {} +inline void Probes::resizeObject(JSContext *cx, JSObject *obj, size_t oldSize, size_t newSize) {} +inline void Probes::createString(JSContext *cx, JSString *string, size_t length) {} +inline void Probes::finalizeString(JSString *string) {} +inline void Probes::compileScriptBegin(JSContext *cx, const char *filename, int lineno) {} +inline void Probes::compileScriptEnd(JSContext *cx, JSScript *script, const char *filename, int lineno) {} +inline void Probes::calloutBegin(JSContext *cx, JSFunction *fun) {} +inline void Probes::calloutEnd(JSContext *cx, JSFunction *fun) {} +inline void Probes::acquireMemory(JSContext *cx, void *address, size_t nbytes) {} +inline void Probes::releaseMemory(JSContext *cx, void *address, size_t nbytes) {} +inline void Probes::GCStart(JSCompartment *compartment) {} +inline void Probes::GCEnd(JSCompartment *compartment) {} +inline void Probes::GCStartMarkPhase(JSCompartment *compartment) {} +inline void Probes::GCEndMarkPhase(JSCompartment *compartment) {} +inline void Probes::GCStartSweepPhase(JSCompartment *compartment) {} +inline void Probes::GCEndSweepPhase(JSCompartment *compartment) {} +inline bool Probes::CustomMark(JSString *string) { return (JSIntn)1; } +inline bool Probes::CustomMark(const char *string) { return (JSIntn)1; } +inline bool Probes::CustomMark(int marker) { return (JSIntn)1; } +struct AutoFunctionCallProbe { + JSContext * const cx; + JSFunction *fun; + JSScript *script; + + AutoFunctionCallProbe(JSContext *cx, JSFunction *fun, JSScript *script + ) + : cx(cx), fun(fun), script(script) + { + do { } while (0); + Probes::enterJSFun(cx, fun, script); + } + ~AutoFunctionCallProbe() { + Probes::exitJSFun(cx, fun, script); + } +}; +} +inline + bool +JSFunction::inStrictMode() const +{ + return script()->strictModeCode; +} +inline void +JSStackFrame::initPrev(JSContext *cx) +{ + ((void) 0); + if (JSFrameRegs *regs = cx->regs) { + prev_ = regs->fp; + prevpc_ = regs->pc; + ((void) 0) + ; + } else { + prev_ = __null; + } +} +inline void +JSStackFrame::resetGeneratorPrev(JSContext *cx) +{ + flags_ |= JSFRAME_HAS_PREVPC; + initPrev(cx); +} +inline void +JSStackFrame::initCallFrame(JSContext *cx, JSObject &callee, JSFunction *fun, + uint32 nactual, uint32 flagsArg) +{ + ((void) 0) + ; + ((void) 0); + flags_ = JSFRAME_FUNCTION | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN | flagsArg; + exec.fun = fun; + args.nactual = nactual; + scopeChain_ = callee.getParent(); + initPrev(cx); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); +} +inline void +JSStackFrame::resetInvokeCallFrame() +{ + ((void) 0) + ; + flags_ &= JSFRAME_FUNCTION | + JSFRAME_OVERFLOW_ARGS | + JSFRAME_HAS_PREVPC | + JSFRAME_UNDERFLOW_ARGS; + ((void) 0); + scopeChain_ = callee().getParent(); +} +inline void +JSStackFrame::initCallFrameCallerHalf(JSContext *cx, uint32 flagsArg, + void *ncode) +{ + ((void) 0) + ; + flags_ = JSFRAME_FUNCTION | flagsArg; + prev_ = cx->regs->fp; + ncode_ = ncode; +} +inline void +JSStackFrame::initCallFrameEarlyPrologue(JSFunction *fun, uint32 nactual) +{ + exec.fun = fun; + if (flags_ & (JSFRAME_OVERFLOW_ARGS | JSFRAME_UNDERFLOW_ARGS)) + args.nactual = nactual; +} +inline void +JSStackFrame::initCallFrameLatePrologue() +{ + SetValueRangeToUndefined(slots(), script()->nfixed); +} +inline void +JSStackFrame::initEvalFrame(JSContext *cx, JSScript *script, JSStackFrame *prev, uint32 flagsArg) +{ + ((void) 0); + ((void) 0); + ((void) 0); + js::Value *dstvp = (js::Value *)this - 2; + js::Value *srcvp = prev->flags_ & (JSFRAME_GLOBAL | JSFRAME_EVAL) + ? (js::Value *)prev - 2 + : prev->formalArgs() - 2; + dstvp[0] = srcvp[0]; + dstvp[1] = srcvp[1]; + ((void) 0) + ; + flags_ = flagsArg | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN | + (prev->flags_ & (JSFRAME_FUNCTION | JSFRAME_GLOBAL | JSFRAME_HAS_CALL_OBJ)); + if (isFunctionFrame()) { + exec = prev->exec; + args.script = script; + } else { + exec.script = script; + } + scopeChain_ = &prev->scopeChain(); + ((void) 0); + prev_ = prev; + prevpc_ = prev->pc(cx); + ((void) 0); + ((void) 0); + setAnnotation(prev->annotation()); +} +inline void +JSStackFrame::initGlobalFrame(JSScript *script, JSObject &chain, uint32 flagsArg) +{ + ((void) 0); + js::Value *vp = (js::Value *)this - 2; + vp[0].setUndefined(); + vp[1].setUndefined(); + flags_ = flagsArg | JSFRAME_GLOBAL | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN; + exec.script = script; + args.script = (JSScript *)0xbad; + scopeChain_ = &chain; + prev_ = __null; + ((void) 0); + ((void) 0); + ((void) 0); +} +inline void +JSStackFrame::initDummyFrame(JSContext *cx, JSObject &chain) +{ + js::PodZero(this); + flags_ = JSFRAME_DUMMY | JSFRAME_HAS_PREVPC | JSFRAME_HAS_SCOPECHAIN; + initPrev(cx); + chain.isGlobal(); + setScopeChainNoCallObj(chain); +} +inline void +JSStackFrame::stealFrameAndSlots(js::Value *vp, JSStackFrame *otherfp, + js::Value *othervp, js::Value *othersp) +{ + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + PodCopy(vp, othervp, othersp - othervp); + ((void) 0); + if (otherfp->hasOverflowArgs()) + Debug_SetValueRangeToCrashOnTouch(othervp, othervp + 2 + otherfp->numFormalArgs()); + if (hasCallObj()) { + callObj().setPrivate(this); + otherfp->flags_ &= ~JSFRAME_HAS_CALL_OBJ; + if (js_IsNamedLambda(fun())) { + JSObject *env = callObj().getParent(); + ((void) 0); + env->setPrivate(this); + } + } + if (hasArgsObj()) { + JSObject &args = argsObj(); + ((void) 0); + if (args.isNormalArguments()) + args.setPrivate(this); + else + ((void) 0); + otherfp->flags_ &= ~JSFRAME_HAS_ARGS_OBJ; + } +} +inline js::Value & +JSStackFrame::canonicalActualArg(uintN i) const +{ + if (i < numFormalArgs()) + return formalArg(i); + ((void) 0); + return actualArgs()[i]; +} +template +inline void +JSStackFrame::forEachCanonicalActualArg(Op op) +{ + uintN nformal = fun()->nargs; + js::Value *formals = formalArgsEnd() - nformal; + uintN nactual = numActualArgs(); + if (nactual <= nformal) { + uintN i = 0; + js::Value *actualsEnd = formals + nactual; + for (js::Value *p = formals; p != actualsEnd; ++p, ++i) + op(i, p); + } else { + uintN i = 0; + js::Value *formalsEnd = formalArgsEnd(); + for (js::Value *p = formals; p != formalsEnd; ++p, ++i) + op(i, p); + js::Value *actuals = formalsEnd - (nactual + 2); + js::Value *actualsEnd = formals - 2; + for (js::Value *p = actuals; p != actualsEnd; ++p, ++i) + op(i, p); + } +} +template +inline void +JSStackFrame::forEachFormalArg(Op op) +{ + js::Value *formals = formalArgsEnd() - fun()->nargs; + js::Value *formalsEnd = formalArgsEnd(); + uintN i = 0; + for (js::Value *p = formals; p != formalsEnd; ++p, ++i) + op(i, p); +} +namespace js { +struct CopyNonHoleArgsTo +{ + CopyNonHoleArgsTo(JSObject *aobj, Value *dst) : aobj(aobj), dst(dst) {} + JSObject *aobj; + Value *dst; + void operator()(uintN argi, Value *src) { + if (aobj->getArgsElement(argi).isMagic(JS_ARGS_HOLE)) + dst->setUndefined(); + else + *dst = *src; + ++dst; + } +}; +struct CopyTo +{ + Value *dst; + CopyTo(Value *dst) : dst(dst) {} + void operator()(uintN, Value *src) { + *dst++ = *src; + } +}; +} +__attribute__((always_inline)) inline void +JSStackFrame::clearMissingArgs() +{ + if (flags_ & JSFRAME_UNDERFLOW_ARGS) + SetValueRangeToUndefined(formalArgs() + numActualArgs(), formalArgsEnd()); +} +inline + bool +JSStackFrame::computeThis(JSContext *cx) +{ + js::Value &thisv = thisValue(); + if (thisv.isObject()) + return true; + if (isFunctionFrame()) { + if (fun()->inStrictMode()) + return true; + ((void) 0); + } + if (!js::BoxThisForVp(cx, &thisv - 1)) + return false; + return true; +} +inline JSObject & +JSStackFrame::varobj(js::StackSegment *seg) const +{ + ((void) 0); + return isFunctionFrame() ? callObj() : seg->getInitialVarObj(); +} +inline JSObject & +JSStackFrame::varobj(JSContext *cx) const +{ + ((void) 0); + return isFunctionFrame() ? callObj() : cx->activeSegment()->getInitialVarObj(); +} +inline uintN +JSStackFrame::numActualArgs() const +{ + ((void) 0); + if ((__builtin_expect((flags_ & (JSFRAME_OVERFLOW_ARGS | JSFRAME_UNDERFLOW_ARGS)), 0))) + return hasArgsObj() ? argsObj().getArgsInitialLength() : args.nactual; + return numFormalArgs(); +} +inline js::Value * +JSStackFrame::actualArgs() const +{ + ((void) 0); + js::Value *argv = formalArgs(); + if ((__builtin_expect((flags_ & JSFRAME_OVERFLOW_ARGS), 0))) { + uintN nactual = hasArgsObj() ? argsObj().getArgsInitialLength() : args.nactual; + return argv - (2 + nactual); + } + return argv; +} +inline js::Value * +JSStackFrame::actualArgsEnd() const +{ + ((void) 0); + if ((__builtin_expect((flags_ & JSFRAME_OVERFLOW_ARGS), 0))) + return formalArgs() - 2; + return formalArgs() + numActualArgs(); +} +inline void +JSStackFrame::setArgsObj(JSObject &obj) +{ + ((void) 0); + ((void) 0); + args.obj = &obj; + flags_ |= JSFRAME_HAS_ARGS_OBJ; +} +inline void +JSStackFrame::clearArgsObj() +{ + ((void) 0); + args.nactual = args.obj->getArgsInitialLength(); + flags_ ^= JSFRAME_HAS_ARGS_OBJ; +} +inline void +JSStackFrame::setScopeChainNoCallObj(JSObject &obj) +{ + scopeChain_ = &obj; + flags_ |= JSFRAME_HAS_SCOPECHAIN; + ((void) 0); +} +inline void +JSStackFrame::setScopeChainAndCallObj(JSObject &obj) +{ + ((void) 0); + ((void) 0); + scopeChain_ = &obj; + flags_ |= JSFRAME_HAS_SCOPECHAIN | JSFRAME_HAS_CALL_OBJ; +} +inline void +JSStackFrame::clearCallObj() +{ + ((void) 0); + flags_ ^= JSFRAME_HAS_CALL_OBJ; +} +inline JSObject & +JSStackFrame::callObj() const +{ + ((void) 0); + JSObject *pobj = &scopeChain(); + while ((__builtin_expect((pobj->getClass() != &js_CallClass), 0))) { + ((void) 0); + pobj = pobj->getParent(); + } + return *pobj; +} +inline JSObject * +JSStackFrame::maybeCallObj() const +{ + return hasCallObj() ? &callObj() : __null; +} +namespace js { +class AutoPreserveEnumerators { + JSContext *cx; + JSObject *enumerators; + public: + AutoPreserveEnumerators(JSContext *cx) : cx(cx), enumerators(cx->enumerators) + { + } + ~AutoPreserveEnumerators() + { + cx->enumerators = enumerators; + } +}; +struct AutoInterpPreparer { + JSContext *cx; + JSScript *script; + AutoInterpPreparer(JSContext *cx, JSScript *script) + : cx(cx), script(script) + { + cx->interpLevel++; + } + ~AutoInterpPreparer() + { + --cx->interpLevel; + } +}; +inline void +PutActivationObjects(JSContext *cx, JSStackFrame *fp) +{ + ((void) 0); + ((void) 0); + if (fp->hasCallObj()) { + js_PutCallObject(cx, fp); + } else if (fp->hasArgsObj()) { + js_PutArgsObject(cx, fp); + } +} +inline void +PutOwnedActivationObjects(JSContext *cx, JSStackFrame *fp) +{ + ((void) 0); + if (!fp->isEvalFrame() || fp->script()->strictModeCode) + PutActivationObjects(cx, fp); +} +class InvokeSessionGuard +{ + InvokeArgsGuard args_; + InvokeFrameGuard frame_; + Value savedCallee_, savedThis_; + Value *formals_, *actuals_; + unsigned nformals_; + JSScript *script_; + Value *stackLimit_; + jsbytecode *stop_; + bool optimized() const { return frame_.pushed(); } + public: + InvokeSessionGuard() : args_(), frame_() {} + inline ~InvokeSessionGuard(); + bool start(JSContext *cx, const Value &callee, const Value &thisv, uintN argc); + bool invoke(JSContext *cx) const; + bool started() const { + return args_.pushed(); + } + Value &operator[](unsigned i) const { + ((void) 0); + Value &arg = i < nformals_ ? formals_[i] : actuals_[i]; + ((void) 0); + ((void) 0); + return arg; + } + uintN argc() const { + return args_.argc(); + } + const Value &rval() const { + return optimized() ? frame_.fp()->returnValue() : args_.rval(); + } +}; +inline +InvokeSessionGuard::~InvokeSessionGuard() +{ + if (frame_.pushed()) + PutActivationObjects(frame_.pushedFrameContext(), frame_.fp()); +} +inline + bool +InvokeSessionGuard::invoke(JSContext *cx) const +{ + formals_[-2] = savedCallee_; + formals_[-1] = savedThis_; + if (!optimized()) + return Invoke(cx, args_, 0); + JSStackFrame *fp = frame_.fp(); + fp->clearMissingArgs(); + PutActivationObjects(cx, frame_.fp()); + fp->resetInvokeCallFrame(); + SetValueRangeToUndefined(fp->slots(), script_->nfixed); + JSBool ok; + { + AutoPreserveEnumerators preserve(cx); + Probes::enterJSFun(cx, fp->fun(), script_); + cx->regs->pc = script_->code; + ok = Interpret(cx, cx->fp()); + Probes::exitJSFun(cx, fp->fun(), script_); + } + return ok; +} +namespace detail { +template class PrimitiveBehavior { }; +template<> +class PrimitiveBehavior { + public: + static inline bool isType(const Value &v) { return v.isString(); } + static inline JSString *extract(const Value &v) { return v.toString(); } + static inline Class *getClass() { return &js_StringClass; } +}; +template<> +class PrimitiveBehavior { + public: + static inline bool isType(const Value &v) { return v.isBoolean(); } + static inline bool extract(const Value &v) { return v.toBoolean(); } + static inline Class *getClass() { return &js_BooleanClass; } +}; +template<> +class PrimitiveBehavior { + public: + static inline bool isType(const Value &v) { return v.isNumber(); } + static inline double extract(const Value &v) { return v.toNumber(); } + static inline Class *getClass() { return &js_NumberClass; } +}; +} +inline + bool +ComputeImplicitThis(JSContext *cx, JSObject *obj, const Value &funval, Value *vp) +{ + vp->setUndefined(); + if (!funval.isObject()) + return true; + if (!obj->isGlobal()) { + if (IsCacheableNonGlobalScope(obj)) + return true; + } else { + JSObject *callee = &funval.toObject(); + if (callee->isProxy()) { + callee = callee->unwrap(); + if (!callee->isFunction()) + return true; + } + if (callee->isFunction()) { + JSFunction *fun = callee->getFunctionPrivate(); + if (fun->isInterpreted() && fun->inStrictMode()) + return true; + } + if (callee->getGlobal() == cx->fp()->scopeChain().getGlobal()) + return true;; + } + obj = obj->thisObject(cx); + if (!obj) + return false; + vp->setObject(*obj); + return true; +} +template +bool +GetPrimitiveThis(JSContext *cx, Value *vp, T *v) +{ + typedef detail::PrimitiveBehavior Behavior; + const Value &thisv = vp[1]; + if (Behavior::isType(thisv)) { + *v = Behavior::extract(thisv); + return true; + } + if (thisv.isObject() && thisv.toObject().getClass() == Behavior::getClass()) { + *v = Behavior::extract(thisv.toObject().getPrimitiveThis()); + return true; + } + ReportIncompatibleMethod(cx, vp, Behavior::getClass()); + return false; +} +__attribute__((always_inline)) inline JSObject * +ValuePropertyBearer(JSContext *cx, const Value &v, int spindex) +{ + if (v.isObject()) + return &v.toObject(); + JSProtoKey protoKey; + if (v.isString()) { + protoKey = JSProto_String; + } else if (v.isNumber()) { + protoKey = JSProto_Number; + } else if (v.isBoolean()) { + protoKey = JSProto_Boolean; + } else { + ((void) 0); + js_ReportIsNullOrUndefined(cx, spindex, v, __null); + return __null; + } + JSObject *pobj; + if (!js_GetClassPrototype(cx, __null, protoKey, &pobj)) + return __null; + return pobj; +} +static inline + bool +ScriptEpilogue(JSContext *cx, JSStackFrame *fp, JSBool ok) +{ + if (!fp->isExecuteFrame()) + Probes::exitJSFun(cx, fp->maybeFun(), fp->maybeScript()); + JSInterpreterHook hook = + fp->isExecuteFrame() ? cx->debugHooks->executeHook : cx->debugHooks->callHook; + void* hookData; + if ((__builtin_expect((hook != __null), 0)) && (hookData = fp->maybeHookData())) + hook(cx, fp, (JSIntn)0, &ok, hookData); + if (fp->isEvalFrame()) { + if (fp->script()->strictModeCode) { + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + js_PutCallObject(cx, fp); + } + } else { + if (fp->isFunctionFrame() && !fp->isYielding()) { + ((void) 0); + PutActivationObjects(cx, fp); + } + } + if (fp->isConstructing() && ok) { + if (fp->returnValue().isPrimitive()) + fp->setReturnValue(ObjectValue(fp->constructorThis())); + ; + } + return ok; +} +} +extern js::Class js_DateClass; +inline + bool +JSObject::isDate() const +{ + return getClass() == &js_DateClass; +} +extern JSObject * +js_InitDateClass(JSContext *cx, JSObject *obj); +extern __attribute__((visibility ("default"))) JSObject* +js_NewDateObjectMsec(JSContext* cx, jsdouble msec_time); +extern __attribute__((visibility ("default"))) JSObject* +js_NewDateObject(JSContext* cx, int year, int mon, int mday, + int hour, int min, int sec); +extern __attribute__((visibility ("default"))) JSBool +js_DateIsValid(JSContext *cx, JSObject* obj); +extern __attribute__((visibility ("default"))) int +js_DateGetYear(JSContext *cx, JSObject* obj); +extern __attribute__((visibility ("default"))) int +js_DateGetMonth(JSContext *cx, JSObject* obj); +extern __attribute__((visibility ("default"))) int +js_DateGetDate(JSContext *cx, JSObject* obj); +extern __attribute__((visibility ("default"))) int +js_DateGetHours(JSContext *cx, JSObject* obj); +extern __attribute__((visibility ("default"))) int +js_DateGetMinutes(JSContext *cx, JSObject* obj); +extern __attribute__((visibility ("default"))) int +js_DateGetSeconds(JSContext *cx, JSObject* obj); +extern __attribute__((visibility ("default"))) jsdouble +js_DateGetMsecSinceEpoch(JSContext *cx, JSObject *obj); +typedef uint32 JSIntervalTime; +extern __attribute__((visibility ("default"))) JSIntervalTime +js_IntervalNow(); +JSBool +js_Date(JSContext *cx, uintN argc, js::Value *vp); +namespace js { +struct NativeIterator { + JSObject *obj; + jsid *props_array; + jsid *props_cursor; + jsid *props_end; + uint32 *shapes_array; + uint32 shapes_length; + uint32 shapes_key; + uint32 flags; + JSObject *next; + bool isKeyIter() const { return (flags & 0x2) == 0; } + inline jsid *begin() const { + return props_array; + } + inline jsid *end() const { + return props_end; + } + size_t numKeys() const { + return end() - begin(); + } + jsid *current() const { + ((void) 0); + return props_cursor; + } + void incCursor() { + props_cursor = props_cursor + 1; + } + static NativeIterator *allocateIterator(JSContext *cx, uint32 slength, + const js::AutoIdVector &props); + void init(JSObject *obj, uintN flags, uint32 slength, uint32 key); + void mark(JSTracer *trc); +}; +bool +VectorToIdArray(JSContext *cx, js::AutoIdVector &props, JSIdArray **idap); +__attribute__((visibility ("default"))) bool +GetPropertyNames(JSContext *cx, JSObject *obj, uintN flags, js::AutoIdVector *props); +bool +GetIterator(JSContext *cx, JSObject *obj, uintN flags, js::Value *vp); +bool +VectorToKeyIterator(JSContext *cx, JSObject *obj, uintN flags, js::AutoIdVector &props, js::Value *vp); +bool +VectorToValueIterator(JSContext *cx, JSObject *obj, uintN flags, js::AutoIdVector &props, js::Value *vp); +bool +EnumeratedIdVectorToIterator(JSContext *cx, JSObject *obj, uintN flags, js::AutoIdVector &props, js::Value *vp); +} +extern __attribute__((visibility ("default"))) JSBool +js_ValueToIterator(JSContext *cx, uintN flags, js::Value *vp); +extern __attribute__((visibility ("default"))) JSBool +js_CloseIterator(JSContext *cx, JSObject *iterObj); +bool +js_SuppressDeletedProperty(JSContext *cx, JSObject *obj, jsid id); +bool +js_SuppressDeletedIndexProperties(JSContext *cx, JSObject *obj, jsint begin, jsint end); +extern JSBool +js_IteratorMore(JSContext *cx, JSObject *iterobj, js::Value *rval); +extern JSBool +js_IteratorNext(JSContext *cx, JSObject *iterobj, js::Value *rval); +extern JSBool +js_ThrowStopIteration(JSContext *cx); +typedef enum JSGeneratorState { + JSGEN_NEWBORN, + JSGEN_OPEN, + JSGEN_RUNNING, + JSGEN_CLOSING, + JSGEN_CLOSED +} JSGeneratorState; +struct JSGenerator { + JSObject *obj; + JSGeneratorState state; + JSFrameRegs regs; + JSObject *enumerators; + JSStackFrame *floating; + js::Value floatingStack[1]; + JSStackFrame *floatingFrame() { + return floating; + } + JSStackFrame *liveFrame() { + ((void) 0) + ; + return regs.fp; + } +}; +extern JSObject * +js_NewGenerator(JSContext *cx); +inline JSStackFrame * +js_FloatingFrameIfGenerator(JSContext *cx, JSStackFrame *fp) +{ + ((void) 0); + if ((__builtin_expect((fp->isGeneratorFrame()), 0))) + return cx->generatorFor(fp)->floatingFrame(); + return fp; +} +extern JSGenerator * +js_FloatingFrameToGenerator(JSStackFrame *fp); +inline JSStackFrame * +js_LiveFrameIfGenerator(JSStackFrame *fp) +{ + return fp->isGeneratorFrame() ? js_FloatingFrameToGenerator(fp)->liveFrame() : fp; +} +extern js::Class js_GeneratorClass; +extern js::Class js_IteratorClass; +extern js::Class js_StopIterationClass; +static inline + bool +js_ValueIsStopIteration(const js::Value &v) +{ + return v.isObject() && v.toObject().getClass() == &js_StopIterationClass; +} +extern JSObject * +js_InitIteratorClasses(JSContext *cx, JSObject *obj); +namespace js { +class __attribute__((visibility ("default"))) JSProxyHandler { + void *mFamily; + public: + explicit JSProxyHandler(void *family); + virtual ~JSProxyHandler(); + virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, + PropertyDescriptor *desc) = 0; + virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, + PropertyDescriptor *desc) = 0; + virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, + PropertyDescriptor *desc) = 0; + virtual bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, js::AutoIdVector &props) = 0; + virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) = 0; + virtual bool enumerate(JSContext *cx, JSObject *proxy, js::AutoIdVector &props) = 0; + virtual bool fix(JSContext *cx, JSObject *proxy, Value *vp) = 0; + virtual bool has(JSContext *cx, JSObject *proxy, jsid id, bool *bp); + virtual bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp); + virtual bool get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, js::Value *vp); + virtual bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict, + js::Value *vp); + virtual bool keys(JSContext *cx, JSObject *proxy, js::AutoIdVector &props); + virtual bool iterate(JSContext *cx, JSObject *proxy, uintN flags, js::Value *vp); + virtual bool call(JSContext *cx, JSObject *proxy, uintN argc, js::Value *vp); + virtual bool construct(JSContext *cx, JSObject *proxy, + uintN argc, js::Value *argv, js::Value *rval); + virtual bool hasInstance(JSContext *cx, JSObject *proxy, const js::Value *vp, bool *bp); + virtual JSType typeOf(JSContext *cx, JSObject *proxy); + virtual JSString *obj_toString(JSContext *cx, JSObject *proxy); + virtual JSString *fun_toString(JSContext *cx, JSObject *proxy, uintN indent); + virtual void finalize(JSContext *cx, JSObject *proxy); + virtual void trace(JSTracer *trc, JSObject *proxy); + virtual bool isOuterWindow() { + return false; + } + inline void *family() { + return mFamily; + } +}; +class JSProxy { + public: + static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, + PropertyDescriptor *desc); + static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, Value *vp); + static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, + PropertyDescriptor *desc); + static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, + Value *vp); + static bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc); + static bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, const Value &v); + static bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, js::AutoIdVector &props); + static bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp); + static bool enumerate(JSContext *cx, JSObject *proxy, js::AutoIdVector &props); + static bool fix(JSContext *cx, JSObject *proxy, Value *vp); + static bool has(JSContext *cx, JSObject *proxy, jsid id, bool *bp); + static bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp); + static bool get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, Value *vp); + static bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict, + Value *vp); + static bool keys(JSContext *cx, JSObject *proxy, js::AutoIdVector &props); + static bool iterate(JSContext *cx, JSObject *proxy, uintN flags, Value *vp); + static bool call(JSContext *cx, JSObject *proxy, uintN argc, js::Value *vp); + static bool construct(JSContext *cx, JSObject *proxy, uintN argc, js::Value *argv, js::Value *rval); + static bool hasInstance(JSContext *cx, JSObject *proxy, const js::Value *vp, bool *bp); + static JSType typeOf(JSContext *cx, JSObject *proxy); + static JSString *obj_toString(JSContext *cx, JSObject *proxy); + static JSString *fun_toString(JSContext *cx, JSObject *proxy, uintN indent); +}; +const uint32 JSSLOT_PROXY_HANDLER = 0; +const uint32 JSSLOT_PROXY_PRIVATE = 1; +const uint32 JSSLOT_PROXY_EXTRA = 2; +const uint32 JSSLOT_PROXY_CALL = 3; +const uint32 JSSLOT_PROXY_CONSTRUCT = 4; +extern __attribute__((visibility ("default"))) js::Class ObjectProxyClass; +extern __attribute__((visibility ("default"))) js::Class FunctionProxyClass; +extern __attribute__((visibility ("default"))) js::Class OuterWindowProxyClass; +extern js::Class CallableObjectClass; +} +inline + bool +JSObject::isObjectProxy() const +{ + return getClass() == &js::ObjectProxyClass || + getClass() == &js::OuterWindowProxyClass; +} +inline + bool +JSObject::isFunctionProxy() const +{ + return getClass() == &js::FunctionProxyClass; +} +inline + bool +JSObject::isProxy() const +{ + return isObjectProxy() || isFunctionProxy(); +} +inline js::JSProxyHandler * +JSObject::getProxyHandler() const +{ + ((void) 0); + return (js::JSProxyHandler *) getSlot(js::JSSLOT_PROXY_HANDLER).toPrivate(); +} +inline const js::Value & +JSObject::getProxyPrivate() const +{ + ((void) 0); + return getSlot(js::JSSLOT_PROXY_PRIVATE); +} +inline void +JSObject::setProxyPrivate(const js::Value &priv) +{ + ((void) 0); + setSlot(js::JSSLOT_PROXY_PRIVATE, priv); +} +inline const js::Value & +JSObject::getProxyExtra() const +{ + ((void) 0); + return getSlot(js::JSSLOT_PROXY_EXTRA); +} +inline void +JSObject::setProxyExtra(const js::Value &extra) +{ + ((void) 0); + setSlot(js::JSSLOT_PROXY_EXTRA, extra); +} +namespace js { +__attribute__((visibility ("default"))) JSObject * +NewProxyObject(JSContext *cx, JSProxyHandler *handler, const js::Value &priv, + JSObject *proto, JSObject *parent, + JSObject *call = __null, JSObject *construct = __null); +__attribute__((visibility ("default"))) JSBool +FixProxy(JSContext *cx, JSObject *proxy, JSBool *bp); +} +extern "C" { +extern js::Class js_ProxyClass; +extern __attribute__((visibility ("default"))) JSObject * +js_InitProxyClass(JSContext *cx, JSObject *obj); +} +inline void +js::Shape::freeTable(JSContext *cx) +{ + if (hasTable()) { + cx->destroy(getTable()); + setTable(__null); + } +} +inline js::EmptyShape * +JSObject::getEmptyShape(JSContext *cx, js::Class *aclasp, + unsigned kind) +{ + ((void) 0); + int i = kind - js::gc::FINALIZE_OBJECT0; + if (!emptyShapes) { + emptyShapes = (js::EmptyShape**) + cx->calloc(sizeof(js::EmptyShape*) * js::gc::JS_FINALIZE_OBJECT_LIMIT); + if (!emptyShapes) + return __null; + emptyShapes[0] = js::EmptyShape::create(cx, aclasp); + if (!emptyShapes[0]) { + cx->free(emptyShapes); + emptyShapes = __null; + return __null; + } + } + ((void) 0); + if (!emptyShapes[i]) { + emptyShapes[i] = js::EmptyShape::create(cx, aclasp); + if (!emptyShapes[i]) + return __null; + } + return emptyShapes[i]; +} +inline + bool +JSObject::canProvideEmptyShape(js::Class *aclasp) +{ + return !emptyShapes || emptyShapes[0]->getClass() == aclasp; +} +inline void +JSObject::updateShape(JSContext *cx) +{ + ((void) 0); + js::LeaveTraceIfGlobalObject(cx, this); + if (hasOwnShape()) + setOwnShape(js_GenerateShape(cx)); + else + objShape = lastProp->shape; +} +inline void +JSObject::updateFlags(const js::Shape *shape, bool isDefinitelyAtom) +{ + jsuint index; + if (!isDefinitelyAtom && js_IdIsIndex(shape->id, &index)) + setIndexed(); + if (shape->isMethod()) + setMethodBarrier(); +} +inline void +JSObject::extend(JSContext *cx, const js::Shape *shape, bool isDefinitelyAtom) +{ + setLastProperty(shape); + updateFlags(shape, isDefinitelyAtom); + updateShape(cx); +} +inline void +JSObject::trace(JSTracer *trc) +{ + if (!isNative()) + return; + JSContext *cx = trc->context; + js::Shape *shape = lastProp; + if (((trc)->callback == __null) && cx->runtime->gcRegenShapes) { + if (!shape->hasRegenFlag()) { + shape->shape = js_RegenerateShapeForGC(cx->runtime); + shape->setRegenFlag(); + } + uint32 newShape = shape->shape; + if (hasOwnShape()) { + newShape = js_RegenerateShapeForGC(cx->runtime); + ((void) 0); + } + objShape = newShape; + } + do { + shape->trace(trc); + } while ((shape = shape->parent) != __null); +} +namespace js { +inline +Shape::Shape(jsid id, js::PropertyOp getter, js::StrictPropertyOp setter, uint32 slot, uintN attrs, + uintN flags, intN shortid, uint32 shape, uint32 slotSpan) + : JSObjectMap(shape, slotSpan), + numLinearSearches(0), id(id), rawGetter(getter), rawSetter(setter), slot(slot), + attrs(uint8(attrs)), flags(uint8(flags)), shortid(int16(shortid)), parent(__null) +{ + ((void) 0); + ((void) 0); + ((void) 0); + kids.setNull(); +} +inline +Shape::Shape(JSCompartment *comp, Class *aclasp) + : JSObjectMap(js_GenerateShape(comp->rt), (((aclasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1))), + numLinearSearches(0), + id(((jsid)0x4)), + clasp(aclasp), + rawSetter(__null), + slot(0xffffffff), + attrs(0), + flags(SHARED_EMPTY), + shortid(0), + parent(__null) +{ + kids.setNull(); +} +inline JSDHashNumber +Shape::hash() const +{ + JSDHashNumber hash = 0; + ((void) 0); + if (rawGetter) + hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ jsuword(rawGetter); + if (rawSetter) + hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ jsuword(rawSetter); + hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ (flags & PUBLIC_FLAGS); + hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ attrs; + hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ shortid; + hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ slot; + hash = (((hash) << (4)) | ((hash) >> (32 - (4)))) ^ (id); + return hash; +} +inline + bool +Shape::matches(const js::Shape *other) const +{ + ((void) 0); + ((void) 0); + return id == other->id && + matchesParamsAfterId(other->rawGetter, other->rawSetter, other->slot, other->attrs, + other->flags, other->shortid); +} +inline + bool +Shape::matchesParamsAfterId(js::PropertyOp agetter, js::StrictPropertyOp asetter, uint32 aslot, + uintN aattrs, uintN aflags, intN ashortid) const +{ + ((void) 0); + return rawGetter == agetter && + rawSetter == asetter && + slot == aslot && + attrs == aattrs && + ((flags ^ aflags) & PUBLIC_FLAGS) == 0 && + shortid == ashortid; +} +inline + bool +Shape::get(JSContext* cx, JSObject *receiver, JSObject* obj, JSObject *pobj, js::Value* vp) const +{ + ((void) 0); + ((void) 0); + if (hasGetterValue()) { + ((void) 0); + js::Value fval = getterValue(); + return js::ExternalGetOrSet(cx, receiver, id, fval, JSACC_READ, 0, 0, vp); + } + if (isMethod()) { + vp->setObject(methodObject()); + return pobj->methodReadBarrier(cx, *this, vp); + } + if (obj->getClass() == &js_WithClass) + obj = js_UnwrapWithObject(cx, obj); + return js::CallJSPropertyOp(cx, getterOp(), obj, ((this)->hasShortID() ? INT_TO_JSID((this)->shortid) : (this)->id), vp); +} +inline + bool +Shape::set(JSContext* cx, JSObject* obj, bool strict, js::Value* vp) const +{ + ((void) 0); + if (attrs & 0x20) { + js::Value fval = setterValue(); + return js::ExternalGetOrSet(cx, obj, id, fval, JSACC_WRITE, 1, vp, vp); + } + if (attrs & 0x10) + return js_ReportGetterOnlyAssignment(cx); + if (obj->getClass() == &js_WithClass) + obj = js_UnwrapWithObject(cx, obj); + return js::CallJSPropertyOpSetter(cx, setterOp(), obj, ((this)->hasShortID() ? INT_TO_JSID((this)->shortid) : (this)->id), strict, vp); +} +inline +EmptyShape::EmptyShape(JSCompartment *comp, js::Class *aclasp) + : js::Shape(comp, aclasp) +{ +} +} +namespace js { +namespace gc { +const size_t SLOTS_TO_THING_KIND_LIMIT = 17; +static inline FinalizeKind +GetGCObjectKind(size_t numSlots) +{ + extern FinalizeKind slotsToThingKind[]; + if (numSlots >= SLOTS_TO_THING_KIND_LIMIT) + return FINALIZE_OBJECT0; + return slotsToThingKind[numSlots]; +} +static inline size_t +GetGCKindSlots(FinalizeKind thingKind) +{ + switch (thingKind) { + case FINALIZE_OBJECT0: + return 0; + case FINALIZE_OBJECT2: + return 2; + case FINALIZE_OBJECT4: + return 4; + case FINALIZE_OBJECT8: + return 8; + case FINALIZE_OBJECT12: + return 12; + case FINALIZE_OBJECT16: + return 16; + default: + ; + return 0; + } +} +} +} +template +__attribute__((always_inline)) inline T * +NewFinalizableGCThing(JSContext *cx, unsigned thingKind) +{ + ((void) 0); + ((void) 0) + ; + ((void) 0); + do { + js::gc::FreeCell *cell = cx->compartment->freeLists.getNext(thingKind); + if (cell) { + CheckGCFreeListLink(cell); + return (T *)cell; + } + if (!RefillFinalizableFreeList(cx, thingKind)) + return __null; + } while (true); +} +inline JSObject * +js_NewGCObject(JSContext *cx, js::gc::FinalizeKind kind) +{ + ((void) 0); + JSObject *obj = NewFinalizableGCThing(cx, kind); + if (obj) + obj->capacity = js::gc::GetGCKindSlots(kind); + return obj; +} +inline JSString * +js_NewGCString(JSContext *cx) +{ + return NewFinalizableGCThing(cx, js::gc::FINALIZE_STRING); +} +inline JSShortString * +js_NewGCShortString(JSContext *cx) +{ + return NewFinalizableGCThing(cx, js::gc::FINALIZE_SHORT_STRING); +} +inline JSExternalString * +js_NewGCExternalString(JSContext *cx, uintN type) +{ + ((void) 0); + JSExternalString *str = NewFinalizableGCThing(cx, js::gc::FINALIZE_EXTERNAL_STRING); + return str; +} +inline JSFunction* +js_NewGCFunction(JSContext *cx) +{ + JSFunction *fun = NewFinalizableGCThing(cx, js::gc::FINALIZE_FUNCTION); + if (fun) + fun->capacity = JSObject::FUN_CLASS_RESERVED_SLOTS; + return fun; +} +inline JSXML * +js_NewGCXML(JSContext *cx) +{ + return NewFinalizableGCThing(cx, js::gc::FINALIZE_XML); +} +namespace js { +namespace gc { +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSXML *thing); +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSObject *thing); +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSFunction *thing); +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSShortString *thing); +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSString *thing); +template +static __attribute__((always_inline)) inline void +Mark(JSTracer *trc, T *thing) +{ + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + JSRuntime *rt = trc->context->runtime; + if (rt->gcCurrentCompartment && thing->asCell()->compartment() != rt->gcCurrentCompartment) + goto out; + if (!((trc)->callback == __null)) { + uint32 kind = GetGCThingTraceKind(thing); + trc->callback(trc, thing, kind); + goto out; + } + TypedMarker(trc, thing); + out: + return; +} +static inline void +MarkString(JSTracer *trc, JSString *str) +{ + ((void) 0); + if (JSString::isStatic(str)) + return; + ((void) 0); + Mark(trc, str); +} +static inline void +MarkString(JSTracer *trc, JSString *str, const char *name) +{ + ((void) 0); + do { } while (0); + MarkString(trc, str); +} +static inline void +MarkObject(JSTracer *trc, JSObject &obj, const char *name) +{ + ((void) 0); + ((void) 0); + do { } while (0); + ((void) 0) + ; + Mark(trc, &obj); +} +static inline void +MarkChildren(JSTracer *trc, JSObject *obj) +{ + if (!obj->map) + return; + if (JSObject *proto = obj->getProto()) + MarkObject(trc, *proto, "proto"); + if (JSObject *parent = obj->getParent()) + MarkObject(trc, *parent, "parent"); + if (obj->emptyShapes) { + int count = FINALIZE_OBJECT_LAST - FINALIZE_OBJECT0 + 1; + for (int i = 0; i < count; i++) { + if (obj->emptyShapes[i]) + obj->emptyShapes[i]->trace(trc); + } + } + TraceOp op = obj->getOps()->trace; + (op ? op : js_TraceObject)(trc, obj); +} +static inline void +MarkChildren(JSTracer *trc, JSString *str) +{ + if (str->isDependent()) + MarkString(trc, str->dependentBase(), "base"); + else if (str->isRope()) { + MarkString(trc, str->ropeLeft(), "left child"); + MarkString(trc, str->ropeRight(), "right child"); + } +} +static inline void +MarkChildren(JSTracer *trc, JSXML *xml) +{ + js_TraceXML(trc, xml); +} +static inline + bool +RecursionTooDeep(GCMarker *gcmarker) { + int stackDummy; + return !((jsuword)(&stackDummy) > gcmarker->stackLimit); +} +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSXML *thing) +{ + if (!reinterpret_cast(thing)->markIfUnmarked(reinterpret_cast(trc)->getMarkColor())) + return; + GCMarker *gcmarker = static_cast(trc); + if (RecursionTooDeep(gcmarker)) { + gcmarker->delayMarkingChildren(thing); + } else { + MarkChildren(trc, thing); + } +} +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSObject *thing) +{ + ((void) 0); + ((void) 0); + GCMarker *gcmarker = static_cast(trc); + if (!thing->markIfUnmarked(gcmarker->getMarkColor())) + return; + if (RecursionTooDeep(gcmarker)) { + gcmarker->delayMarkingChildren(thing); + } else { + MarkChildren(trc, thing); + } +} +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSFunction *thing) +{ + ((void) 0); + ((void) 0); + GCMarker *gcmarker = static_cast(trc); + if (!thing->markIfUnmarked(gcmarker->getMarkColor())) + return; + if (RecursionTooDeep(gcmarker)) { + gcmarker->delayMarkingChildren(thing); + } else { + MarkChildren(trc, static_cast(thing)); + } +} +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSShortString *thing) +{ + (void) thing->asCell()->markIfUnmarked(); +} +} +namespace detail { +static __attribute__((always_inline)) inline JSString * +Tag(JSString *str) +{ + ((void) 0); + return (JSString *)(size_t(str) | 1); +} +static __attribute__((always_inline)) inline + bool +Tagged(JSString *str) +{ + return (size_t(str) & 1) != 0; +} +static __attribute__((always_inline)) inline JSString * +Untag(JSString *str) +{ + ((void) 0); + return (JSString *)(size_t(str) & ~size_t(1)); +} +static __attribute__((always_inline)) inline void +NonRopeTypedMarker(JSRuntime *rt, JSString *str) +{ + ((void) 0); + if (rt->gcCurrentCompartment) { + for (;;) { + if (JSString::isStatic(str)) + break; + if (str->asCell()->compartment() != rt->gcCurrentCompartment) { + ((void) 0); + break; + } + if (!str->asCell()->markIfUnmarked()) + break; + if (!str->isDependent()) + break; + str = str->dependentBase(); + } + } else { + while (!JSString::isStatic(str) && + str->asCell()->markIfUnmarked() && + str->isDependent()) { + str = str->dependentBase(); + } + } +} +} +namespace gc { +static __attribute__((always_inline)) inline void +TypedMarker(JSTracer *trc, JSString *str) +{ + using namespace detail; + JSRuntime *rt = trc->context->runtime; + ((void) 0); + if (!str->isRope()) { + NonRopeTypedMarker(rt, str); + return; + } + JSString *parent = __null; + first_visit_node: { + ((void) 0); + ((void) 0); + if (!str->asCell()->markIfUnmarked()) + goto finish_node; + JSString *left = str->ropeLeft(); + if (left->isRope()) { + ((void) 0); + str->u.left = Tag(parent); + parent = str; + str = left; + goto first_visit_node; + } + ((void) 0) + ; + NonRopeTypedMarker(rt, left); + } + visit_right_child: { + JSString *right = str->ropeRight(); + if (right->isRope()) { + ((void) 0); + str->s.right = Tag(parent); + parent = str; + str = right; + goto first_visit_node; + } + ((void) 0) + ; + NonRopeTypedMarker(rt, right); + } + finish_node: { + if (!parent) + return; + if (Tagged(parent->u.left)) { + ((void) 0); + JSString *nextParent = Untag(parent->u.left); + parent->u.left = str; + str = parent; + parent = nextParent; + goto visit_right_child; + } + ((void) 0); + JSString *nextParent = Untag(parent->s.right); + parent->s.right = str; + str = parent; + parent = nextParent; + goto finish_node; + } +} +static inline void +MarkAtomRange(JSTracer *trc, size_t len, JSAtom **vec, const char *name) +{ + for (uint32 i = 0; i < len; i++) { + if (JSAtom *atom = vec[i]) { + do { } while (0); + JSString *str = (atom); + if (!JSString::isStatic(str)) + Mark(trc, str); + } + } +} +static inline void +MarkObjectRange(JSTracer *trc, size_t len, JSObject **vec, const char *name) +{ + for (uint32 i = 0; i < len; i++) { + if (JSObject *obj = vec[i]) { + do { } while (0); + Mark(trc, obj); + } + } +} +static inline void +MarkId(JSTracer *trc, jsid id) +{ + if (JSID_IS_STRING(id)) { + JSString *str = JSID_TO_STRING(id); + if (!JSString::isStatic(str)) + Mark(trc, str); + } + else if ((__builtin_expect((JSID_IS_OBJECT(id)), 0))) + Mark(trc, JSID_TO_OBJECT(id)); +} +static inline void +MarkId(JSTracer *trc, jsid id, const char *name) +{ + do { } while (0); + MarkId(trc, id); +} +static inline void +MarkIdRange(JSTracer *trc, jsid *beg, jsid *end, const char *name) +{ + for (jsid *idp = beg; idp != end; ++idp) { + do { } while (0); + MarkId(trc, *idp); + } +} +static inline void +MarkIdRange(JSTracer *trc, size_t len, jsid *vec, const char *name) +{ + MarkIdRange(trc, vec, vec + len, name); +} +static inline void +MarkKind(JSTracer *trc, void *thing, uint32 kind) +{ + ((void) 0); + ((void) 0); + switch (kind) { + case 0: + Mark(trc, reinterpret_cast(thing)); + break; + case 1: + MarkString(trc, reinterpret_cast(thing)); + break; + case 2: + Mark(trc, reinterpret_cast(thing)); + break; + default: + ((void) 0); + } +} +static inline void +MarkValueRaw(JSTracer *trc, const js::Value &v) +{ + if (v.isMarkable()) { + ((void) 0); + return MarkKind(trc, v.toGCThing(), v.gcKind()); + } +} +static inline void +MarkValue(JSTracer *trc, const js::Value &v, const char *name) +{ + do { } while (0); + MarkValueRaw(trc, v); +} +static inline void +MarkValueRange(JSTracer *trc, Value *beg, Value *end, const char *name) +{ + for (Value *vp = beg; vp < end; ++vp) { + do { } while (0); + MarkValueRaw(trc, *vp); + } +} +static inline void +MarkValueRange(JSTracer *trc, size_t len, Value *vec, const char *name) +{ + MarkValueRange(trc, vec, vec + len, name); +} +static inline void +MarkShapeRange(JSTracer *trc, const Shape **beg, const Shape **end, const char *name) +{ + for (const Shape **sp = beg; sp < end; ++sp) { + do { } while (0); + (*sp)->trace(trc); + } +} +static inline void +MarkShapeRange(JSTracer *trc, size_t len, const Shape **vec, const char *name) +{ + MarkShapeRange(trc, vec, vec + len, name); +} +static inline void +MarkGCThing(JSTracer *trc, void *thing, uint32 kind) +{ + if (!thing) + return; + MarkKind(trc, thing, kind); +} +static inline void +MarkGCThing(JSTracer *trc, void *thing) +{ + if (!thing) + return; + MarkKind(trc, thing, GetGCThingTraceKind(thing)); +} +static inline void +MarkGCThing(JSTracer *trc, void *thing, const char *name) +{ + do { } while (0); + MarkGCThing(trc, thing); +} +static inline void +MarkGCThing(JSTracer *trc, void *thing, const char *name, size_t index) +{ + do { } while (0); + MarkGCThing(trc, thing); +} +static inline void +Mark(JSTracer *trc, void *thing, uint32 kind, const char *name) +{ + ((void) 0); + do { } while (0); + MarkKind(trc, thing, kind); +} +}} +inline + bool +JSObject::preventExtensions(JSContext *cx, js::AutoIdVector *props) +{ + ((void) 0); + if (js::FixOp fix = getOps()->fix) { + bool success; + if (!fix(cx, this, &success, props)) + return false; + if (!success) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_CANT_CHANGE_EXTENSIBILITY); + return false; + } + } else { + if (!GetPropertyNames(cx, this, 0x10 | 0x8, props)) + return false; + } + if (isNative()) + extensibleShapeChange(cx); + flags |= NOT_EXTENSIBLE; + return true; +} +inline + bool +JSObject::brand(JSContext *cx) +{ + ((void) 0); + ((void) 0); + ((void) 0); + generateOwnShape(cx); + if (js_IsPropertyCacheDisabled(cx)) + return false; + flags |= BRANDED; + return true; +} +inline + bool +JSObject::unbrand(JSContext *cx) +{ + ((void) 0); + if (branded()) { + generateOwnShape(cx); + if (js_IsPropertyCacheDisabled(cx)) + return false; + flags &= ~BRANDED; + } + setGeneric(); + return true; +} +inline void +JSObject::syncSpecialEquality() +{ + if (clasp->ext.equality) + flags |= JSObject::HAS_EQUALITY; +} +inline void +JSObject::finalize(JSContext *cx) +{ + if (!map) + return; + js::Class *clasp = getClass(); + if (clasp->finalize) + clasp->finalize(cx, this); + js::Probes::finalizeObject(this); + finish(cx); +} +inline const js::Shape * +JSObject::methodReadBarrier(JSContext *cx, const js::Shape &shape, js::Value *vp) +{ + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + JSObject *funobj = &vp->toObject(); + JSFunction *fun = funobj->getFunctionPrivate(); + ((void) 0); + ((void) 0); + funobj = CloneFunctionObject(cx, fun, funobj->getParent()); + if (!funobj) + return __null; + funobj->setMethodObj(*this); + uint32 slot = shape.slot; + const js::Shape *newshape = methodShapeChange(cx, shape); + if (!newshape) + return __null; + ((void) 0); + ((void) 0); + vp->setObject(*funobj); + nativeSetSlot(slot, *vp); + return newshape; +} +static __attribute__((always_inline)) inline + bool +ChangesMethodValue(const js::Value &prev, const js::Value &v) +{ + JSObject *prevObj; + return prev.isObject() && (prevObj = &prev.toObject())->isFunction() && + (!v.isObject() || &v.toObject() != prevObj); +} +inline const js::Shape * +JSObject::methodWriteBarrier(JSContext *cx, const js::Shape &shape, const js::Value &v) +{ + if (brandedOrHasMethodBarrier() && shape.slot != 0xffffffff) { + const js::Value &prev = nativeGetSlot(shape.slot); + if (ChangesMethodValue(prev, v)) { + ((void)0); + return methodShapeChange(cx, shape); + } + } + return &shape; +} +inline + bool +JSObject::methodWriteBarrier(JSContext *cx, uint32 slot, const js::Value &v) +{ + if (brandedOrHasMethodBarrier()) { + const js::Value &prev = nativeGetSlot(slot); + if (ChangesMethodValue(prev, v)) { + ((void)0); + return methodShapeChange(cx, slot); + } + } + return true; +} +inline + bool +JSObject::ensureClassReservedSlots(JSContext *cx) +{ + return !nativeEmpty() || ensureClassReservedSlotsForEmptyObject(cx); +} +inline js::Value +JSObject::getReservedSlot(uintN index) const +{ + return (index < numSlots()) ? getSlot(index) : js::UndefinedValue(); +} +inline + bool +JSObject::canHaveMethodBarrier() const +{ + return isObject() || isFunction() || isPrimitive() || isDate(); +} +inline + bool +JSObject::isPrimitive() const +{ + return isNumber() || isString() || isBoolean(); +} +inline const js::Value & +JSObject::getPrimitiveThis() const +{ + ((void) 0); + return getSlot(JSSLOT_PRIMITIVE_THIS); +} +inline void +JSObject::setPrimitiveThis(const js::Value &pthis) +{ + ((void) 0); + setSlot(JSSLOT_PRIMITIVE_THIS, pthis); +} +inline unsigned +JSObject::finalizeKind() const +{ + return js::gc::FinalizeKind(arena()->header()->thingKind); +} +inline size_t +JSObject::numFixedSlots() const +{ + if (isFunction()) + return JSObject::FUN_CLASS_RESERVED_SLOTS; + if (!hasSlotsArray()) + return capacity; + return js::gc::GetGCKindSlots(js::gc::FinalizeKind(finalizeKind())); +} +inline size_t +JSObject::slotsAndStructSize(uint32 nslots) const +{ + bool isFun = isFunction() && this == (JSObject*) getPrivate(); + int ndslots = hasSlotsArray() ? nslots : 0; + int nfslots = isFun ? 0 : numFixedSlots(); + return sizeof(js::Value) * (ndslots + nfslots) + + isFun ? sizeof(JSFunction) : sizeof(JSObject); +} +inline uint32 +JSObject::getArrayLength() const +{ + ((void) 0); + return (uint32)(size_t) getPrivate(); +} +inline void +JSObject::setArrayLength(uint32 length) +{ + ((void) 0); + setPrivate((void*) length); +} +inline uint32 +JSObject::getDenseArrayCapacity() +{ + ((void) 0); + return numSlots(); +} +inline js::Value* +JSObject::getDenseArrayElements() +{ + ((void) 0); + return getSlots(); +} +inline const js::Value & +JSObject::getDenseArrayElement(uintN idx) +{ + ((void) 0); + return getSlot(idx); +} +inline js::Value * +JSObject::addressOfDenseArrayElement(uintN idx) +{ + ((void) 0); + return &getSlotRef(idx); +} +inline void +JSObject::setDenseArrayElement(uintN idx, const js::Value &val) +{ + ((void) 0); + setSlot(idx, val); +} +inline void +JSObject::shrinkDenseArrayElements(JSContext *cx, uintN cap) +{ + ((void) 0); + shrinkSlots(cx, cap); +} +inline void +JSObject::setArgsLength(uint32 argc) +{ + ((void) 0); + ((void) 0); + ((void) 0); + getSlotRef(JSSLOT_ARGS_LENGTH).setInt32(argc << ARGS_PACKED_BITS_COUNT); + ((void) 0); +} +inline uint32 +JSObject::getArgsInitialLength() const +{ + ((void) 0); + uint32 argc = uint32(getSlot(JSSLOT_ARGS_LENGTH).toInt32()) >> ARGS_PACKED_BITS_COUNT; + ((void) 0); + return argc; +} +inline void +JSObject::setArgsLengthOverridden() +{ + ((void) 0); + getSlotRef(JSSLOT_ARGS_LENGTH).getInt32Ref() |= ARGS_LENGTH_OVERRIDDEN_BIT; +} +inline + bool +JSObject::isArgsLengthOverridden() const +{ + ((void) 0); + const js::Value &v = getSlot(JSSLOT_ARGS_LENGTH); + return v.toInt32() & ARGS_LENGTH_OVERRIDDEN_BIT; +} +inline js::ArgumentsData * +JSObject::getArgsData() const +{ + ((void) 0); + return (js::ArgumentsData *) getSlot(JSSLOT_ARGS_DATA).toPrivate(); +} +inline void +JSObject::setArgsData(js::ArgumentsData *data) +{ + ((void) 0); + getSlotRef(JSSLOT_ARGS_DATA).setPrivate(data); +} +inline const js::Value & +JSObject::getArgsCallee() const +{ + return getArgsData()->callee; +} +inline void +JSObject::setArgsCallee(const js::Value &callee) +{ + getArgsData()->callee = callee; +} +inline const js::Value & +JSObject::getArgsElement(uint32 i) const +{ + ((void) 0); + ((void) 0); + return getArgsData()->slots[i]; +} +inline js::Value * +JSObject::getArgsElements() const +{ + ((void) 0); + return getArgsData()->slots; +} +inline js::Value * +JSObject::addressOfArgsElement(uint32 i) +{ + ((void) 0); + ((void) 0); + return &getArgsData()->slots[i]; +} +inline void +JSObject::setArgsElement(uint32 i, const js::Value &v) +{ + ((void) 0); + ((void) 0); + getArgsData()->slots[i] = v; +} +inline + bool +JSObject::callIsForEval() const +{ + ((void) 0); + ((void) 0); + ((void) 0) + ; + return getSlot(JSSLOT_CALL_CALLEE).isNull(); +} +inline JSStackFrame * +JSObject::maybeCallObjStackFrame() const +{ + ((void) 0); + return reinterpret_cast(getPrivate()); +} +inline void +JSObject::setCallObjCallee(JSObject *callee) +{ + ((void) 0); + ((void) 0); + return getSlotRef(JSSLOT_CALL_CALLEE).setObjectOrNull(callee); +} +inline JSObject * +JSObject::getCallObjCallee() const +{ + ((void) 0); + return getSlot(JSSLOT_CALL_CALLEE).toObjectOrNull(); +} +inline JSFunction * +JSObject::getCallObjCalleeFunction() const +{ + ((void) 0); + return getSlot(JSSLOT_CALL_CALLEE).toObject().getFunctionPrivate(); +} +inline const js::Value & +JSObject::getCallObjArguments() const +{ + ((void) 0); + ((void) 0); + return getSlot(JSSLOT_CALL_ARGUMENTS); +} +inline void +JSObject::setCallObjArguments(const js::Value &v) +{ + ((void) 0); + ((void) 0); + setSlot(JSSLOT_CALL_ARGUMENTS, v); +} +inline const js::Value & +JSObject::callObjArg(uintN i) const +{ + ((void) 0); + ((void) 0); + return getSlot(JSObject::CALL_RESERVED_SLOTS + i); +} +inline js::Value & +JSObject::callObjArg(uintN i) +{ + ((void) 0); + ((void) 0); + return getSlotRef(JSObject::CALL_RESERVED_SLOTS + i); +} +inline const js::Value & +JSObject::callObjVar(uintN i) const +{ + JSFunction *fun = getCallObjCalleeFunction(); + ((void) 0); + ((void) 0); + return getSlot(JSObject::CALL_RESERVED_SLOTS + fun->nargs + i); +} +inline js::Value & +JSObject::callObjVar(uintN i) +{ + JSFunction *fun = getCallObjCalleeFunction(); + ((void) 0); + ((void) 0); + return getSlotRef(JSObject::CALL_RESERVED_SLOTS + fun->nargs + i); +} +inline const js::Value & +JSObject::getDateUTCTime() const +{ + ((void) 0); + return getSlot(JSSLOT_DATE_UTC_TIME); +} +inline void +JSObject::setDateUTCTime(const js::Value &time) +{ + ((void) 0); + setSlot(JSSLOT_DATE_UTC_TIME, time); +} +inline js::Value * +JSObject::getFlatClosureUpvars() const +{ + return (js::Value *) getSlot(JSSLOT_FLAT_CLOSURE_UPVARS).toPrivate(); +} +inline js::Value +JSObject::getFlatClosureUpvar(uint32 i) const +{ + ((void) 0); + return getFlatClosureUpvars()[i]; +} +inline js::Value & +JSObject::getFlatClosureUpvar(uint32 i) +{ + ((void) 0); + return getFlatClosureUpvars()[i]; +} +inline void +JSObject::setFlatClosureUpvars(js::Value *upvars) +{ + ((void) 0); + ((void) 0); + getSlotRef(JSSLOT_FLAT_CLOSURE_UPVARS).setPrivate(upvars); +} +inline + bool +JSObject::hasMethodObj(const JSObject& obj) const +{ + return JSSLOT_FUN_METHOD_OBJ < numSlots() && + getSlot(JSSLOT_FUN_METHOD_OBJ).isObject() && + &getSlot(JSSLOT_FUN_METHOD_OBJ).toObject() == &obj; +} +inline void +JSObject::setMethodObj(JSObject& obj) +{ + getSlotRef(JSSLOT_FUN_METHOD_OBJ).setObject(obj); +} +inline js::NativeIterator * +JSObject::getNativeIterator() const +{ + return (js::NativeIterator *) getPrivate(); +} +inline void +JSObject::setNativeIterator(js::NativeIterator *ni) +{ + setPrivate(ni); +} +inline JSLinearString * +JSObject::getNamePrefix() const +{ + ((void) 0); + const js::Value &v = getSlot(JSSLOT_NAME_PREFIX); + return !v.isUndefined() ? v.toString()->assertIsLinear() : __null; +} +inline jsval +JSObject::getNamePrefixVal() const +{ + ((void) 0); + return js::Jsvalify(getSlot(JSSLOT_NAME_PREFIX)); +} +inline void +JSObject::setNamePrefix(JSLinearString *prefix) +{ + ((void) 0); + setSlot(JSSLOT_NAME_PREFIX, prefix ? js::StringValue(prefix) : js::UndefinedValue()); +} +inline void +JSObject::clearNamePrefix() +{ + ((void) 0); + setSlot(JSSLOT_NAME_PREFIX, js::UndefinedValue()); +} +inline JSLinearString * +JSObject::getNameURI() const +{ + ((void) 0); + const js::Value &v = getSlot(JSSLOT_NAME_URI); + return !v.isUndefined() ? v.toString()->assertIsLinear() : __null; +} +inline jsval +JSObject::getNameURIVal() const +{ + ((void) 0); + return js::Jsvalify(getSlot(JSSLOT_NAME_URI)); +} +inline void +JSObject::setNameURI(JSLinearString *uri) +{ + ((void) 0); + setSlot(JSSLOT_NAME_URI, uri ? js::StringValue(uri) : js::UndefinedValue()); +} +inline jsval +JSObject::getNamespaceDeclared() const +{ + ((void) 0); + return js::Jsvalify(getSlot(JSSLOT_NAMESPACE_DECLARED)); +} +inline void +JSObject::setNamespaceDeclared(jsval decl) +{ + ((void) 0); + setSlot(JSSLOT_NAMESPACE_DECLARED, js::Valueify(decl)); +} +inline JSLinearString * +JSObject::getQNameLocalName() const +{ + ((void) 0); + const js::Value &v = getSlot(JSSLOT_QNAME_LOCAL_NAME); + return !v.isUndefined() ? v.toString()->assertIsLinear() : __null; +} +inline jsval +JSObject::getQNameLocalNameVal() const +{ + ((void) 0); + return js::Jsvalify(getSlot(JSSLOT_QNAME_LOCAL_NAME)); +} +inline void +JSObject::setQNameLocalName(JSLinearString *name) +{ + ((void) 0); + setSlot(JSSLOT_QNAME_LOCAL_NAME, name ? js::StringValue(name) : js::UndefinedValue()); +} +inline JSObject * +JSObject::getWithThis() const +{ + return &getSlot(JSSLOT_WITH_THIS).toObject(); +} +inline void +JSObject::setWithThis(JSObject *thisp) +{ + getSlotRef(JSSLOT_WITH_THIS).setObject(*thisp); +} +inline void +JSObject::init(JSContext *cx, js::Class *aclasp, JSObject *proto, JSObject *parent, + void *priv, bool useHoles) +{ + clasp = aclasp; + flags = 0; + setProto(proto); + setParent(parent); + privateData = priv; + slots = fixedSlots(); + ((void) 0); + ClearValueRange(slots, capacity, useHoles); + emptyShapes = __null; +} +inline void +JSObject::finish(JSContext *cx) +{ + if (hasSlotsArray()) + freeSlotsArray(cx); + if (emptyShapes) + cx->free(emptyShapes); +} +inline + bool +JSObject::initSharingEmptyShape(JSContext *cx, + js::Class *aclasp, + JSObject *proto, + JSObject *parent, + void *privateValue, + unsigned kind) +{ + init(cx, aclasp, proto, parent, privateValue, false); + ((void) 0); + js::EmptyShape *empty = proto->getEmptyShape(cx, aclasp, kind); + if (!empty) + return false; + setMap(empty); + return true; +} +inline void +JSObject::freeSlotsArray(JSContext *cx) +{ + ((void) 0); + cx->free(slots); +} +inline void +JSObject::revertToFixedSlots(JSContext *cx) +{ + ((void) 0); + size_t fixed = numFixedSlots(); + ((void) 0); + memcpy(fixedSlots(), slots, fixed * sizeof(js::Value)); + freeSlotsArray(cx); + slots = fixedSlots(); + capacity = fixed; +} +inline + bool +JSObject::hasProperty(JSContext *cx, jsid id, bool *foundp, uintN flags) +{ + JSObject *pobj; + JSProperty *prop; + JSAutoResolveFlags rf(cx, flags); + if (!lookupProperty(cx, id, &pobj, &prop)) + return false; + *foundp = !!prop; + return true; +} +inline + bool +JSObject::isCallable() +{ + return isFunction() || getClass()->call; +} +static inline + bool +js_IsCallable(const js::Value &v) +{ + return v.isObject() && v.toObject().isCallable(); +} +namespace js { +class AutoPropDescArrayRooter : private AutoGCRooter +{ + public: + AutoPropDescArrayRooter(JSContext *cx) + : AutoGCRooter(cx, DESCRIPTORS), descriptors(cx) + { } + PropDesc *append() { + if (!descriptors.append(PropDesc())) + return __null; + return &descriptors.back(); + } + PropDesc& operator[](size_t i) { + ((void) 0); + return descriptors[i]; + } + friend void AutoGCRooter::trace(JSTracer *trc); + private: + PropDescArray descriptors; +}; +class AutoPropertyDescriptorRooter : private AutoGCRooter, public PropertyDescriptor +{ + public: + AutoPropertyDescriptorRooter(JSContext *cx) : AutoGCRooter(cx, DESCRIPTOR) { + obj = __null; + attrs = 0; + getter = (PropertyOp) __null; + setter = (StrictPropertyOp) __null; + value.setUndefined(); + } + AutoPropertyDescriptorRooter(JSContext *cx, PropertyDescriptor *desc) + : AutoGCRooter(cx, DESCRIPTOR) + { + obj = desc->obj; + attrs = desc->attrs; + getter = desc->getter; + setter = desc->setter; + value = desc->value; + } + friend void AutoGCRooter::trace(JSTracer *trc); +}; +static inline + bool +InitScopeForObject(JSContext* cx, JSObject* obj, js::Class *clasp, JSObject* proto, + gc::FinalizeKind kind) +{ + ((void) 0); + ((void) 0); + js::EmptyShape *empty = __null; + if (proto) { + if (proto->canProvideEmptyShape(clasp)) { + empty = proto->getEmptyShape(cx, clasp, kind); + if (!empty) + goto bad; + } + } + if (!empty) { + empty = js::EmptyShape::create(cx, clasp); + if (!empty) + goto bad; + uint32 freeslot = (((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1)); + if (freeslot > obj->numSlots() && !obj->allocSlots(cx, freeslot)) + goto bad; + } + obj->setMap(empty); + return true; + bad: + ((void) 0); + return false; +} +static inline JSObject * +NewNativeClassInstance(JSContext *cx, Class *clasp, JSObject *proto, + JSObject *parent, gc::FinalizeKind kind) +{ + ((void) 0); + ((void) 0); + JSObject* obj = js_NewGCObject(cx, kind); + if (obj) { + bool useHoles = (clasp == &js_ArrayClass); + obj->init(cx, clasp, proto, parent, __null, useHoles); + ((void) 0); + js::EmptyShape *empty = proto->getEmptyShape(cx, clasp, kind); + if (empty) + obj->setMap(empty); + else + obj = __null; + } + return obj; +} +static inline JSObject * +NewNativeClassInstance(JSContext *cx, Class *clasp, JSObject *proto, JSObject *parent) +{ + gc::FinalizeKind kind = gc::GetGCObjectKind((((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1))); + return NewNativeClassInstance(cx, clasp, proto, parent, kind); +} +bool +FindClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey, JSObject **protop, + Class *clasp); +static inline JSObject * +NewBuiltinClassInstance(JSContext *cx, Class *clasp, gc::FinalizeKind kind) +{ + ((void) 0); + JSProtoKey protoKey = ((JSProtoKey) (((clasp)->flags >> ((8 + 8) + 8)) & (((JSUint32)1 << (8)) - 1))); + ((void) 0); + JSObject *global; + if (!cx->hasfp()) { + global = cx->globalObject; + OBJ_TO_INNER_OBJECT(cx, global); + if (!global) + return __null; + } else { + global = cx->fp()->scopeChain().getGlobal(); + } + ((void) 0); + const Value &v = global->getReservedSlot(JSProto_LIMIT + protoKey); + JSObject *proto; + if (v.isObject()) { + proto = &v.toObject(); + ((void) 0); + } else { + if (!FindClassPrototype(cx, global, protoKey, &proto, clasp)) + return __null; + } + return NewNativeClassInstance(cx, clasp, proto, global, kind); +} +static inline JSObject * +NewBuiltinClassInstance(JSContext *cx, Class *clasp) +{ + gc::FinalizeKind kind = gc::GetGCObjectKind((((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1))); + return NewBuiltinClassInstance(cx, clasp, kind); +} +static inline JSProtoKey +GetClassProtoKey(js::Class *clasp) +{ + JSProtoKey key = ((JSProtoKey) (((clasp)->flags >> ((8 + 8) + 8)) & (((JSUint32)1 << (8)) - 1))); + if (key != JSProto_Null) + return key; + if (clasp->flags & (1<<((8 + 8)+1))) + return JSProto_Object; + return JSProto_Null; +} +namespace WithProto { + enum e { + Class = 0, + Given = 1 + }; +} +static __attribute__((always_inline)) inline + bool +FindProto(JSContext *cx, js::Class *clasp, JSObject *parent, JSObject ** proto) +{ + JSProtoKey protoKey = GetClassProtoKey(clasp); + if (!js_GetClassPrototype(cx, parent, protoKey, proto, clasp)) + return false; + if (!(*proto) && !js_GetClassPrototype(cx, parent, JSProto_Object, proto)) + return false; + return true; +} +namespace detail +{ +template +static __attribute__((always_inline)) inline JSObject * +NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent, + gc::FinalizeKind kind) +{ + if (withProto == WithProto::Class && !proto) { + if (!FindProto(cx, clasp, parent, &proto)) + return __null; + } + JSObject* obj = isFunction ? js_NewGCFunction(cx) : js_NewGCObject(cx, kind); + if (!obj) + goto out; + ((void) 0); + obj->init(cx, clasp, proto, + (!parent && proto) ? proto->getParent() : parent, + __null, clasp == &js_ArrayClass); + if (clasp->isNative()) { + if (!InitScopeForObject(cx, obj, clasp, proto, kind)) { + obj = __null; + goto out; + } + } else { + obj->setSharedNonNativeMap(); + } +out: + Probes::createObject(cx, obj); + return obj; +} +} +static __attribute__((always_inline)) inline JSObject * +NewFunction(JSContext *cx, JSObject *parent) +{ + return detail::NewObject(cx, &js_FunctionClass, __null, parent, + gc::FINALIZE_OBJECT2); +} +template +static __attribute__((always_inline)) inline JSObject * +NewNonFunction(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent, + gc::FinalizeKind kind) +{ + return detail::NewObject(cx, clasp, proto, parent, kind); +} +template +static __attribute__((always_inline)) inline JSObject * +NewNonFunction(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent) +{ + gc::FinalizeKind kind = gc::GetGCObjectKind((((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1))); + return detail::NewObject(cx, clasp, proto, parent, kind); +} +template +static __attribute__((always_inline)) inline JSObject * +NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent, + gc::FinalizeKind kind) +{ + if (clasp == &js_FunctionClass) + return detail::NewObject(cx, clasp, proto, parent, kind); + return detail::NewObject(cx, clasp, proto, parent, kind); +} +template +static __attribute__((always_inline)) inline JSObject * +NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent) +{ + gc::FinalizeKind kind = gc::GetGCObjectKind((((clasp)->flags >> 8) & (((JSUint32)1 << (8)) - 1))); + return NewObject(cx, clasp, proto, parent, kind); +} +static inline gc::FinalizeKind +GuessObjectGCKind(size_t numSlots, bool isArray) +{ + if (numSlots) + return gc::GetGCObjectKind(numSlots); + return isArray ? gc::FINALIZE_OBJECT8 : gc::FINALIZE_OBJECT4; +} +static inline gc::FinalizeKind +NewObjectGCKind(JSContext *cx, js::Class *clasp) +{ + if (clasp == &js_ArrayClass || clasp == &js_SlowArrayClass) + return gc::FINALIZE_OBJECT8; + if (clasp == &js_FunctionClass) + return gc::FINALIZE_OBJECT2; + return gc::FINALIZE_OBJECT4; +} +static inline JSObject * +CopyInitializerObject(JSContext *cx, JSObject *baseobj) +{ + ((void) 0); + ((void) 0); + gc::FinalizeKind kind = gc::FinalizeKind(baseobj->finalizeKind()); + JSObject *obj = NewBuiltinClassInstance(cx, &js_ObjectClass, kind); + if (!obj || !obj->ensureSlots(cx, baseobj->numSlots())) + return __null; + obj->flags = baseobj->flags; + obj->lastProp = baseobj->lastProp; + obj->objShape = baseobj->objShape; + return obj; +} +static __attribute__((always_inline)) inline + bool +ClassMethodIsNative(JSContext *cx, JSObject *obj, Class *clasp, jsid methodid, + Native native) +{ + ((void) 0); + if (HasNativeMethod(obj, methodid, native)) + return true; + JSObject *pobj = obj->getProto(); + return pobj && pobj->getClass() == clasp && + HasNativeMethod(pobj, methodid, native); +} +} +using namespace js; +using namespace js::gc; +static inline + bool +js_EnterLocalRootScope(JSContext *cx) +{ + return true; +} +static inline void +js_LeaveLocalRootScope(JSContext *cx) +{ +} +static inline void +js_LeaveLocalRootScopeWithResult(JSContext *cx, jsval rval) +{ +} +static inline void +js_LeaveLocalRootScopeWithResult(JSContext *cx, Value rval) +{ +} +static inline void +js_LeaveLocalRootScopeWithResult(JSContext *cx, void *rval) +{ +} +const char js_AttributeName_str[] = "AttributeName"; +const char js_isXMLName_str[] = "isXMLName"; +const char js_XMLList_str[] = "XMLList"; +const char js_localName_str[] = "localName"; +const char js_xml_parent_str[] = "parent"; +const char js_prefix_str[] = "prefix"; +const char js_toXMLString_str[] = "toXMLString"; +const char js_uri_str[] = "uri"; +const char js_amp_entity_str[] = "&"; +const char js_gt_entity_str[] = ">"; +const char js_lt_entity_str[] = "<"; +const char js_quot_entity_str[] = """; +const char js_leftcurly_entity_str[] = "{"; +static JSBool +GetXMLFunction(JSContext *cx, JSObject *obj, jsid id, jsval *vp); +static JSBool +IsDeclared(const JSObject *obj) +{ + jsval v; + ((void) 0); + v = obj->getNamespaceDeclared(); + ((void) 0); + return v == ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1)); +} +static JSBool +xml_isXMLName(JSContext *cx, uintN argc, jsval *vp) +{ + *vp = BOOLEAN_TO_JSVAL(js_IsXMLName(cx, argc ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)))); + return (JSIntn)1; +} +static inline JSObject * +NewBuiltinClassInstanceXML(JSContext *cx, Class *clasp) +{ + JSObject *obj = NewBuiltinClassInstance(cx, clasp); + if (obj) + obj->syncSpecialEquality(); + return obj; +} +static JSBool NamePrefix_getter(JSContext *cx, JSObject *obj, jsid id, jsval *vp) { if (obj->getClass() == &js_NamespaceClass) *vp = obj->getNamePrefixVal(); return true; } +static JSBool NameURI_getter(JSContext *cx, JSObject *obj, jsid id, jsval *vp) { if (obj->getClass() == &js_NamespaceClass) *vp = obj->getNameURIVal(); return true; } +static JSBool +namespace_equality(JSContext *cx, JSObject *obj, const Value *v, JSBool *bp) +{ + JSObject *obj2; + ((void) 0); + obj2 = v->toObjectOrNull(); + *bp = (!obj2 || obj2->getClass() != &js_NamespaceClass) + ? (JSIntn)0 + : EqualStrings(obj->getNameURI(), obj2->getNameURI()); + return (JSIntn)1; +} +__attribute__((visibility ("default"))) Class js_NamespaceClass = { + "Namespace", + (1<<6) | + (((JSObject::NAMESPACE_CLASS_RESERVED_SLOTS) & (((JSUint32)1 << (8)) - 1)) << 8) | + (1<<((8 + 8)+3)) | ((JSProto_Namespace) << ((8 + 8) + 8)), + PropertyStub, + PropertyStub, + PropertyStub, + StrictPropertyStub, + EnumerateStub, + ResolveStub, + ConvertStub, + FinalizeStub, + __null, + __null, + __null, + __null, + __null, + __null, + __null, + { + namespace_equality, + __null, + __null, + __null, + __null, + } +}; +static JSPropertySpec namespace_props[] = { + {js_prefix_str, 0, (0x01 | 0x02 | 0x04 | 0x40), NamePrefix_getter, 0}, + {js_uri_str, 0, (0x01 | 0x02 | 0x04 | 0x40), NameURI_getter, 0}, + {0,0,0,0,0} +}; +static JSBool +namespace_toString(JSContext *cx, uintN argc, Value *vp) +{ + JSObject *obj = ToObject(cx, &vp[1]); + if (!obj) + return (JSIntn)0; + if (!JS_InstanceOf(cx, obj, Jsvalify(&js_NamespaceClass), Jsvalify(vp + 2))) + return (JSIntn)0; + *vp = Valueify(obj->getNameURIVal()); + return (JSIntn)1; +} +static JSFunctionSpec namespace_methods[] = { + {js_toString_str, ((JSNative)(namespace_toString)), 0, (0) | 0x1000}, + {__null, __null, 0, 0} +}; +static JSObject * +NewXMLNamespace(JSContext *cx, JSLinearString *prefix, JSLinearString *uri, JSBool declared) +{ + JSObject *obj; + obj = NewBuiltinClassInstanceXML(cx, &js_NamespaceClass); + if (!obj) + return (JSIntn)0; + ((void) 0); + ((void) 0); + ((void) 0); + if (prefix) + obj->setNamePrefix(prefix); + if (uri) + obj->setNameURI(uri); + if (declared) + obj->setNamespaceDeclared(((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1))); + ; + return obj; +} +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; } +static JSBool QNameLocalName_getter(JSContext *cx, JSObject *obj, jsid id, jsval *vp) { if (obj->getClass() == &js_QNameClass) *vp = obj->getQNameLocalNameVal(); return true; } +static JSBool +qname_identity(JSObject *qna, JSObject *qnb) +{ + JSLinearString *uri1 = qna->getNameURI(); + JSLinearString *uri2 = qnb->getNameURI(); + if (!uri1 ^ !uri2) + return (JSIntn)0; + if (uri1 && !EqualStrings(uri1, uri2)) + return (JSIntn)0; + return EqualStrings(qna->getQNameLocalName(), qnb->getQNameLocalName()); +} +static JSBool +qname_equality(JSContext *cx, JSObject *qn, const Value *v, JSBool *bp) +{ + JSObject *obj2; + obj2 = v->toObjectOrNull(); + *bp = (!obj2 || obj2->getClass() != &js_QNameClass) + ? (JSIntn)0 + : qname_identity(qn, obj2); + return (JSIntn)1; +} +__attribute__((visibility ("default"))) Class js_QNameClass = { + "QName", + (1<<6) | + (((JSObject::QNAME_CLASS_RESERVED_SLOTS) & (((JSUint32)1 << (8)) - 1)) << 8) | + (1<<((8 + 8)+3)) | ((JSProto_QName) << ((8 + 8) + 8)), + PropertyStub, + PropertyStub, + PropertyStub, + StrictPropertyStub, + EnumerateStub, + ResolveStub, + ConvertStub, + FinalizeStub, + __null, + __null, + __null, + __null, + __null, + __null, + __null, + { + qname_equality, + __null, + __null, + __null, + __null, + } +}; +__attribute__((visibility ("default"))) Class js_AttributeNameClass = { + js_AttributeName_str, + (1<<6) | + (((JSObject::QNAME_CLASS_RESERVED_SLOTS) & (((JSUint32)1 << (8)) - 1)) << 8) | + (1<<((8 + 8)+3)) | (1<<((8 + 8)+1)), + PropertyStub, + PropertyStub, + PropertyStub, + StrictPropertyStub, + EnumerateStub, + ResolveStub, + ConvertStub, + FinalizeStub +}; +__attribute__((visibility ("default"))) Class js_AnyNameClass = { + js_AnyName_str, + (1<<6) | + (((JSObject::QNAME_CLASS_RESERVED_SLOTS) & (((JSUint32)1 << (8)) - 1)) << 8) | + (1<<((8 + 8)+3)) | (1<<((8 + 8)+1)), + PropertyStub, + PropertyStub, + PropertyStub, + StrictPropertyStub, + EnumerateStub, + ResolveStub, + ConvertStub, + FinalizeStub +}; +static JSPropertySpec qname_props[] = { + {js_uri_str, 0, (0x01 | 0x02 | 0x04 | 0x40), QNameNameURI_getter, 0}, + {js_localName_str, 0, (0x01 | 0x02 | 0x04 | 0x40), QNameLocalName_getter, 0}, + {0,0,0,0,0} +}; +static JSString * +ConvertQNameToString(JSContext *cx, JSObject *obj) +{ + ((void) 0); + JSString *uri = obj->getNameURI(); + JSString *str; + if (!uri) { + str = (cx->runtime->atomState.starQualifierAtom); + } else if (uri->empty()) { + str = cx->runtime->emptyString; + } else { + JSString *qualstr = (cx->runtime->atomState.qualifierAtom); + str = js_ConcatStrings(cx, uri, qualstr); + if (!str) + return __null; + } + str = js_ConcatStrings(cx, str, obj->getQNameLocalName()); + if (!str) + return __null; + if (obj->getClass() == &js_AttributeNameClass) { + JS::Anchor anchor(str); + size_t length = str->length(); + jschar *chars = (jschar *) cx->malloc((length + 2) * sizeof(jschar)); + if (!chars) + return (JSIntn)0; + *chars = '@'; + const jschar *strChars = str->getChars(cx); + if (!strChars) { + cx->free(chars); + return __null; + } + memcpy((chars + 1), (strChars), (length) * sizeof(jschar)); + chars[++length] = 0; + str = js_NewString(cx, chars, length); + if (!str) { + cx->free(chars); + return __null; + } + } + return str; +} +static JSBool +qname_toString(JSContext *cx, uintN argc, Value *vp) +{ + JSObject *obj = ToObject(cx, &vp[1]); + if (!obj) + return false; + if (!InstanceOf(cx, obj, &js_QNameClass, vp + 2)) + return false; + JSString *str = ConvertQNameToString(cx, obj); + if (!str) + return false; + vp->setString(str); + return true; +} +static JSFunctionSpec qname_methods[] = { + {js_toString_str, ((JSNative)(qname_toString)), 0, (0) | 0x1000}, + {__null, __null, 0, 0} +}; +static void +InitXMLQName(JSObject *obj, JSLinearString *uri, JSLinearString *prefix, + JSLinearString *localName) +{ + ((void) 0); + ((void) 0); + ((void) 0); + ((void) 0); + if (uri) + obj->setNameURI(uri); + if (prefix) + obj->setNamePrefix(prefix); + if (localName) + obj->setQNameLocalName(localName); +} +static JSObject * +NewXMLQName(JSContext *cx, JSLinearString *uri, JSLinearString *prefix, + JSLinearString *localName) +{ + JSObject *obj = NewBuiltinClassInstanceXML(cx, &js_QNameClass); + if (!obj) + return __null; + InitXMLQName(obj, uri, prefix, localName); + ; + return obj; +} +static JSObject * +NewXMLAttributeName(JSContext *cx, JSLinearString *uri, JSLinearString *prefix, + JSLinearString *localName) +{ + JSObject *obj = NewNonFunction(cx, &js_AttributeNameClass, __null, __null); + if (!obj) + return __null; + ((void) 0); + InitXMLQName(obj, uri, prefix, localName); + ; + return obj; +} +JSObject * +js_ConstructXMLQNameObject(JSContext *cx, const Value &nsval, const Value &lnval) +{ + Value argv[2]; + if (nsval.isObject() && + nsval.toObject().getClass() == &js_AnyNameClass) { + argv[0].setNull(); + } else { + argv[0] = nsval; + } + argv[1] = lnval; + return js_ConstructObject(cx, &js_QNameClass, __null, __null, 2, argv); +} +static JSBool +IsXMLName(const jschar *cp, size_t n) +{ + JSBool rv; + jschar c; + rv = (JSIntn)0; + if (n != 0 && (((js_A[js_Y[(js_X[(uint16)(*cp)>>6]<<6)|((*cp)&0x3F)]]) & 0x00000100) || (*cp) == '_')) { + while (--n != 0) { + c = *++cp; + if (!(((js_A[js_Y[(js_X[(uint16)(c)>>6]<<6)|((c)&0x3F)]]) & 0x00000080) || (c) == '.' || (c) == '-' || (c) == '_')) + return rv; + } + rv = (JSIntn)1; + } + return rv; +} +JSBool +js_IsXMLName(JSContext *cx, jsval v) +{ + JSLinearString *name = __null; + JSErrorReporter older; + if (!JSVAL_IS_PRIMITIVE(v) && + JSVAL_TO_OBJECT(v)->isQName()) { + name = JSVAL_TO_OBJECT(v)->getQNameLocalName(); + } else { + older = JS_SetErrorReporter(cx, __null); + JSString *str = js_ValueToString(cx, Valueify(v)); + if (str) + name = str->ensureLinear(cx); + JS_SetErrorReporter(cx, older); + if (!name) { + JS_ClearPendingException(cx); + return (JSIntn)0; + } + } + return IsXMLName(name->chars(), name->length()); +} +static JSBool +NamespaceHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv, + jsval *rval) +{ + jsval urival, prefixval; + JSObject *uriobj; + JSBool isNamespace, isQName; + Class *clasp; + JSLinearString *empty, *prefix, *uri; + isNamespace = isQName = (JSIntn)0; + uriobj = __null; + if (argc <= 0) { + urival = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + } else { + urival = argv[argc > 1]; + if (!JSVAL_IS_PRIMITIVE(urival)) { + uriobj = JSVAL_TO_OBJECT(urival); + clasp = uriobj->getClass(); + isNamespace = (clasp == &js_NamespaceClass); + isQName = (clasp == &js_QNameClass); + } + } + if (!obj) { + if (argc == 1 && isNamespace) { + *rval = urival; + return (JSIntn)1; + } + obj = NewBuiltinClassInstanceXML(cx, &js_NamespaceClass); + if (!obj) + return (JSIntn)0; + } + *rval = OBJECT_TO_JSVAL(obj); + ; + empty = cx->runtime->emptyString; + obj->setNamePrefix(empty); + obj->setNameURI(empty); + if (argc == 1 || argc == -1) { + if (isNamespace) { + obj->setNameURI(uriobj->getNameURI()); + obj->setNamePrefix(uriobj->getNamePrefix()); + } else if (isQName && (uri = uriobj->getNameURI())) { + obj->setNameURI(uri); + obj->setNamePrefix(uriobj->getNamePrefix()); + } else { + JSString *str = js_ValueToString(cx, Valueify(urival)); + if (!str) + return (JSIntn)0; + uri = str->ensureLinear(cx); + if (!uri) + return (JSIntn)0; + obj->setNameURI(uri); + if (!uri->empty()) + obj->clearNamePrefix(); + } + } else if (argc == 2) { + if (!isQName || !(uri = uriobj->getNameURI())) { + JSString *str = js_ValueToString(cx, Valueify(urival)); + if (!str) + return (JSIntn)0; + uri = str->ensureLinear(cx); + if (!uri) + return (JSIntn)0; + } + obj->setNameURI(uri); + prefixval = argv[0]; + if (uri->empty()) { + if (!JSVAL_IS_VOID(prefixval)) { + JSString *str = js_ValueToString(cx, Valueify(prefixval)); + if (!str) + return (JSIntn)0; + if (!str->empty()) { + JSAutoByteString bytes; + if (js_ValueToPrintable(cx, StringValue(str), &bytes)) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, + JSMSG_BAD_XML_NAMESPACE, bytes.ptr()); + } + return (JSIntn)0; + } + } + } else if (JSVAL_IS_VOID(prefixval) || !js_IsXMLName(cx, prefixval)) { + obj->clearNamePrefix(); + } else { + JSString *str = js_ValueToString(cx, Valueify(prefixval)); + if (!str) + return (JSIntn)0; + prefix = str->ensureLinear(cx); + if (!prefix) + return (JSIntn)0; + obj->setNamePrefix(prefix); + } + } + return (JSIntn)1; +} +static JSBool +Namespace(JSContext *cx, uintN argc, Value *vp) +{ + JSObject *thisobj = __null; + (void)IsConstructing_PossiblyWithGivenThisObject(vp, &thisobj); + return NamespaceHelper(cx, thisobj, argc, Jsvalify(vp + 2), Jsvalify(vp)); +} +static JSBool +QNameHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv, jsval *rval) +{ + jsval nameval, nsval; + JSBool isQName, isNamespace; + JSObject *qn; + JSLinearString *uri, *prefix, *name; + JSObject *obj2; + if (argc <= 0) { + nameval = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + isQName = (JSIntn)0; + } else { + nameval = argv[argc > 1]; + isQName = + !JSVAL_IS_PRIMITIVE(nameval) && + JSVAL_TO_OBJECT(nameval)->getClass() == &js_QNameClass; + } + if (!obj) { + if (argc == 1 && isQName) { + *rval = nameval; + return (JSIntn)1; + } + obj = NewBuiltinClassInstanceXML(cx, &js_QNameClass); + if (!obj) + return (JSIntn)0; + } + *rval = OBJECT_TO_JSVAL(obj); + ; + if (isQName) { + qn = JSVAL_TO_OBJECT(nameval); + if (argc == 1) { + uri = qn->getNameURI(); + prefix = qn->getNamePrefix(); + name = qn->getQNameLocalName(); + goto out; + } + nameval = qn->getQNameLocalNameVal(); + } + if (argc == 0) { + name = cx->runtime->emptyString; + } else if (argc < 0) { + name = (cx->runtime->atomState.typeAtoms[JSTYPE_VOID]); + } else { + JSString *str = js_ValueToString(cx, Valueify(nameval)); + if (!str) + return (JSIntn)0; + name = str->ensureLinear(cx); + if (!name) + return (JSIntn)0; + argv[argc > 1] = STRING_TO_JSVAL(name); + } + if (argc > 1 && !JSVAL_IS_VOID(argv[0])) { + nsval = argv[0]; + } else if (((name)->length() == 1 && *(name)->chars() == '*')) { + nsval = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); + } else { + if (!js_GetDefaultXMLNamespace(cx, &nsval)) + return (JSIntn)0; + ((void) 0); + ((void) 0) + ; + } + if (JSVAL_IS_NULL(nsval)) { + prefix = uri = __null; + } else { + isNamespace = isQName = (JSIntn)0; + if (!JSVAL_IS_PRIMITIVE(nsval)) { + obj2 = JSVAL_TO_OBJECT(nsval); + isNamespace = (obj2->getClass() == &js_NamespaceClass); + isQName = (obj2->getClass() == &js_QNameClass); + } + else obj2 = __null; + if (isNamespace) { + uri = obj2->getNameURI(); + prefix = obj2->getNamePrefix(); + } else if (isQName && (uri = obj2->getNameURI())) { + ((void) 0); + prefix = obj2->getNamePrefix(); + } else { + ((void) 0); + JSString *str = js_ValueToString(cx, Valueify(nsval)); + if (!str) + return (JSIntn)0; + uri = str->ensureLinear(cx); + if (!uri) + return (JSIntn)0; + argv[0] = STRING_TO_JSVAL(uri); + prefix = uri->empty() ? cx->runtime->emptyString : __null; + } + } +out: + InitXMLQName(obj, uri, prefix, name); + return (JSIntn)1; +} +static JSBool +QName(JSContext *cx, uintN argc, Value *vp) +{ + JSObject *thisobj = __null; + (void)IsConstructing_PossiblyWithGivenThisObject(vp, &thisobj); + return QNameHelper(cx, thisobj, argc, Jsvalify(vp + 2), Jsvalify(vp)); +} +static JSBool +namespace_identity(const void *a, const void *b) +{ + const JSObject *nsa = (const JSObject *) a; + const JSObject *nsb = (const JSObject *) b; + JSLinearString *prefixa = nsa->getNamePrefix(); + JSLinearString *prefixb = nsb->getNamePrefix(); + if (prefixa && prefixb) { + if (!EqualStrings(prefixa, prefixb)) + return (JSIntn)0; + } else { + if (prefixa || prefixb) + return (JSIntn)0; + } + return EqualStrings(nsa->getNameURI(), nsb->getNameURI()); +} +static JSBool +attr_identity(const void *a, const void *b) +{ + const JSXML *xmla = (const JSXML *) a; + const JSXML *xmlb = (const JSXML *) b; + return qname_identity(xmla->name, xmlb->name); +} +void +JSXMLArrayCursor::trace(JSTracer *trc) { + for (JSXMLArrayCursor *cursor = this; cursor; cursor = cursor->next) + js::gc::MarkGCThing(trc, cursor->root, "cursor_root", index++); +} +static void +XMLArrayCursorTrace(JSTracer *trc, JSXMLArrayCursor *cursor) +{ + cursor->trace(trc); +} +bool +JSXMLArray::setCapacity(JSContext *cx, uint32 newCapacity) +{ + if (newCapacity == 0) { + if (vector) { + if (cx) + cx->free(vector); + else + js_free(vector); + } + vector = __null; + } else { + void **tmp; + if ( + !(tmp = (void **) js_realloc(vector, newCapacity * sizeof(void *)))) { + if (cx) + JS_ReportOutOfMemory(cx); + return false; + } + vector = tmp; + } + capacity = ((JSUint32)1 << (31)) | newCapacity; + return true; +} +void +JSXMLArray::trim() +{ + if (capacity & ((JSUint32)1 << (31))) + return; + if (length < capacity) + setCapacity(__null, length); +} +void +JSXMLArray::finish(JSContext *cx) +{ + cx->free(vector); + while (JSXMLArrayCursor *cursor = cursors) + cursor->disconnect(); +} +static uint32 +XMLArrayFindMember(const JSXMLArray *array, void *elt, JSIdentityOp identity) +{ + void **vector; + uint32 i, n; + vector = array->vector; + if (identity) { + for (i = 0, n = array->length; i < n; i++) { + if (identity(vector[i], elt)) + return i; + } + } else { + for (i = 0, n = array->length; i < n; i++) { + if (vector[i] == elt) + return i; + } + } + return ((uint32) -1); +} +static JSBool +XMLArrayAddMember(JSContext *cx, JSXMLArray *array, uint32 index, void *elt) +{ + uint32 capacity, i; + int log2; + void **vector; + if (index >= array->length) { + if (index >= ((array)->capacity & (((JSUint32)1 << (31)) - 1))) { + capacity = index + 1; + if (index >= 256) { + capacity = ((((capacity)+(32)-1)/(32))*(32)); + } else { + do { unsigned int j_ = (unsigned int)(capacity); (log2) = (j_ <= 1 ? 0 : 32 - __builtin_clz(j_ - 1)); } while (0); + capacity = ((JSUint32)1 << (log2)); + } + if ( + !(vector = (void **) + js_realloc(array->vector, capacity * sizeof(void *)))) { + JS_ReportOutOfMemory(cx); + return (JSIntn)0; + } + array->capacity = capacity; + array->vector = vector; + for (i = array->length; i < index; i++) + vector[i] = __null; + } + array->length = index + 1; + } + array->vector[index] = elt; + return (JSIntn)1; +} +static JSBool +XMLArrayInsert(JSContext *cx, JSXMLArray *array, uint32 i, uint32 n) +{ + uint32 j; + JSXMLArrayCursor *cursor; + j = array->length; + ((void) 0); + if (!array->setCapacity(cx, j + n)) + return (JSIntn)0; + array->length = j + n; + ((void) 0); + while (j != i) { + --j; + array->vector[j + n] = array->vector[j]; + } + for (cursor = array->cursors; cursor; cursor = cursor->next) { + if (cursor->index > i) + cursor->index += n; + } + return (JSIntn)1; +} +static void * +XMLArrayDelete(JSContext *cx, JSXMLArray *array, uint32 index, JSBool compress) +{ + uint32 length; + void **vector, *elt; + JSXMLArrayCursor *cursor; + length = array->length; + if (index >= length) + return __null; + vector = array->vector; + elt = vector[index]; + if (compress) { + while (++index < length) + vector[index-1] = vector[index]; + array->length = length - 1; + array->capacity = ((array)->capacity & (((JSUint32)1 << (31)) - 1)); + } else { + vector[index] = __null; + } + for (cursor = array->cursors; cursor; cursor = cursor->next) { + if (cursor->index > index) + --cursor->index; + } + return elt; +} +static void +XMLArrayTruncate(JSContext *cx, JSXMLArray *array, uint32 length) +{ + void **vector; + ((void) 0); + if (length >= array->length) + return; + if (length == 0) { + if (array->vector) + cx->free(array->vector); + vector = __null; + } else { + vector = (void **) js_realloc(array->vector, length * sizeof(void *)); + if (!vector) + return; + } + if (array->length > length) + array->length = length; + array->capacity = length; + array->vector = vector; +} +static const char js_ignoreComments_str[] = "ignoreComments"; +static const char js_ignoreProcessingInstructions_str[] + = "ignoreProcessingInstructions"; +static const char js_ignoreWhitespace_str[] = "ignoreWhitespace"; +static const char js_prettyPrinting_str[] = "prettyPrinting"; +static const char js_prettyIndent_str[] = "prettyIndent"; +static JSPropertySpec xml_static_props[] = { + {js_ignoreComments_str, 0, 0x04, __null, __null}, + {js_ignoreProcessingInstructions_str, 0, 0x04, __null, __null}, + {js_ignoreWhitespace_str, 0, 0x04, __null, __null}, + {js_prettyPrinting_str, 0, 0x04, __null, __null}, + {js_prettyIndent_str, 0, 0x04, __null, __null}, + {0,0,0,0,0} +}; +static const char xml_namespace_str[] = "http://www.w3.org/XML/1998/namespace"; +static const char xmlns_namespace_str[] = "http://www.w3.org/2000/xmlns/"; +static JSObject * +ParseNodeToQName(Parser *parser, JSParseNode *pn, + JSXMLArray *inScopeNSes, JSBool isAttributeName) +{ + JSContext *cx = parser->context; + JSLinearString *str, *uri, *prefix, *localName; + size_t length, offset; + const jschar *start, *limit, *colon; + uint32 n; + JSObject *ns; + JSLinearString *nsprefix; + ((void) 0); + str = pn->pn_u.name.atom; + start = str->chars(); + length = str->length(); + ((void) 0); + ((void) 0); + uri = cx->runtime->emptyString; + limit = start + length; + colon = js_strchr_limit(start, ':', limit); + if (colon) { + offset = colon - start; + prefix = js_NewDependentString(cx, str, 0, offset); + if (!prefix) + return __null; + 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'))) { + if (offset == 3) { + uri = JS_ASSERT_STRING_IS_FLAT(JS_InternString(cx, xml_namespace_str)); + if (!uri) + return __null; + } 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')) { + uri = JS_ASSERT_STRING_IS_FLAT(JS_InternString(cx, xmlns_namespace_str)); + if (!uri) + return __null; + } else { + uri = __null; + } + } else { + uri = __null; + n = inScopeNSes->length; + while (n != 0) { + --n; + ns = (((n) < (inScopeNSes)->length) ? (JSObject *) (inScopeNSes)->vector[n] : __null); + nsprefix = ns->getNamePrefix(); + if (nsprefix && EqualStrings(nsprefix, prefix)) { + uri = ns->getNameURI(); + break; + } + } + } + if (!uri) { + Value v = StringValue(prefix); + JSAutoByteString bytes; + if (js_ValueToPrintable(parser->context, v, &bytes)) { + ReportCompileErrorNumber(parser->context, &parser->tokenStream, pn, + 0x0, JSMSG_BAD_XML_NAMESPACE, bytes.ptr()); + } + return __null; + } + localName = js_NewStringCopyN(parser->context, colon + 1, length - (offset + 1)); + if (!localName) + return __null; + } else { + if (isAttributeName) { + prefix = uri; + } else { + n = inScopeNSes->length; + while (n != 0) { + --n; + ns = (((n) < (inScopeNSes)->length) ? (JSObject *) (inScopeNSes)->vector[n] : __null); + nsprefix = ns->getNamePrefix(); + if (!nsprefix || nsprefix->empty()) { + uri = ns->getNameURI(); + break; + } + } + prefix = uri->empty() ? parser->context->runtime->emptyString : __null; + } + localName = str; + } + return NewXMLQName(parser->context, uri, prefix, localName); +} +static JSString * +ChompXMLWhitespace(JSContext *cx, JSString *str) +{ + size_t length, newlength, offset; + const jschar *cp, *start, *end; + jschar c; + length = str->length(); + start = str->getChars(cx); + if (!start) + return __null; + for (cp = start, end = cp + length; cp < end; cp++) { + c = *cp; + if (!((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')) + break; + } + while (end > cp) { + c = end[-1]; + if (!((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')) + break; + --end; + } + newlength = end - cp; + if (newlength == length) + return str; + offset = cp - start; + return js_NewDependentString(cx, str, offset, newlength); +} +static JSXML * +ParseNodeToXML(Parser *parser, JSParseNode *pn, + JSXMLArray *inScopeNSes, uintN flags) +{ + JSContext *cx = parser->context; + JSXML *xml, *kid, *attr, *attrj; + JSLinearString *str; + uint32 length, n, i, j; + JSParseNode *pn2, *pn3, *head, **pnp; + JSObject *ns; + JSObject *qn, *attrjqn; + JSXMLClass xml_class; + int stackDummy; + if (!((jsuword)(&stackDummy) > cx->stackLimit)) { + ReportCompileErrorNumber(cx, &parser->tokenStream, pn, 0x0, + JSMSG_OVER_RECURSED); + return __null; + } + xml = __null; + if (!js_EnterLocalRootScope(cx)) + return __null; + switch (pn->pn_type) { + case TOK_XMLELEM: + length = inScopeNSes->length; + pn2 = pn->pn_u.list.head; + xml = ParseNodeToXML(parser, pn2, inScopeNSes, flags); + if (!xml) + goto fail; + n = pn->pn_u.list.count; + ((void) 0); + n -= 2; + if (!xml->u.list.kids.setCapacity(cx, n)) + goto fail; + i = 0; + while ((pn2 = pn2->pn_next) != __null) { + if (!pn2->pn_next) { + ((void) 0); + break; + } + if ((flags & ((JSUint32)1 << (2))) && + n > 1 && pn2->pn_type == TOK_XMLSPACE) { + --n; + continue; + } + kid = ParseNodeToXML(parser, pn2, inScopeNSes, flags); + if (kid == ((JSXML *) 1)) { + --n; + continue; + } + if (!kid) + goto fail; + 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); + kid->parent = xml; + ++i; + if ((flags & ((JSUint32)1 << (2))) && + n > 1 && kid->xml_class == JSXML_CLASS_TEXT) { + JSString *str = ChompXMLWhitespace(cx, kid->u.value); + if (!str) + goto fail; + kid->u.value = str; + } + } + ((void) 0); + if (n < pn->pn_u.list.count - 2) + xml->u.list.kids.trim(); + XMLArrayTruncate(cx, inScopeNSes, length); + break; + case TOK_XMLLIST: + xml = js_NewXML(cx, JSXML_CLASS_LIST); + if (!xml) + goto fail; + n = pn->pn_u.list.count; + if (!xml->u.list.kids.setCapacity(cx, n)) + goto fail; + i = 0; + for (pn2 = pn->pn_u.list.head; pn2; pn2 = pn2->pn_next) { + if (pn2->pn_type == TOK_XMLSPACE) { + --n; + continue; + } + kid = ParseNodeToXML(parser, pn2, inScopeNSes, flags); + if (kid == ((JSXML *) 1)) { + --n; + continue; + } + if (!kid) + goto fail; + 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); + ++i; + } + if (n < pn->pn_u.list.count) + xml->u.list.kids.trim(); + break; + case TOK_XMLSTAGO: + case TOK_XMLPTAGC: + length = inScopeNSes->length; + pn2 = pn->pn_u.list.head; + ((void) 0); + if (pn2->pn_arity == PN_LIST) + goto syntax; + xml = js_NewXML(cx, JSXML_CLASS_ELEMENT); + if (!xml) + goto fail; + ((void) 0); + n = pn->pn_u.list.count - 1; + pnp = &pn2->pn_next; + head = *pnp; + while ((pn2 = *pnp) != __null) { + size_t length; + const jschar *chars; + if (pn2->pn_type != TOK_XMLNAME || pn2->pn_arity != PN_NULLARY) + goto syntax; + for (pn3 = head; pn3 != pn2; pn3 = pn3->pn_next->pn_next) { + if (pn3->pn_u.name.atom == pn2->pn_u.name.atom) { + Value v = StringValue((pn2->pn_u.name.atom)); + JSAutoByteString bytes; + if (js_ValueToPrintable(cx, v, &bytes)) { + ReportCompileErrorNumber(cx, &parser->tokenStream, pn2, + 0x0, JSMSG_DUPLICATE_XML_ATTR, + bytes.ptr()); + } + goto fail; + } + } + JSAtom *atom = pn2->pn_u.name.atom; + pn2 = pn2->pn_next; + ((void) 0); + if (pn2->pn_type != TOK_XMLATTR) + goto syntax; + chars = atom->chars(); + length = atom->length(); + if (length >= 5 && + ((((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')) && + (length == 5 || chars[5] == ':')) { + JSLinearString *uri, *prefix; + uri = (pn2->pn_u.name.atom); + if (length == 5) { + prefix = cx->runtime->emptyString; + } else { + prefix = js_NewStringCopyN(cx, chars + 6, length - 6); + if (!prefix) + goto fail; + } + ns = NewXMLNamespace(cx, prefix, uri, (JSIntn)1); + if (!ns) + goto fail; + if (!(XMLArrayFindMember(inScopeNSes, (void *)(ns), namespace_identity) != ((uint32) -1))) { + if (!XMLArrayAddMember(cx, inScopeNSes, (inScopeNSes)->length, (void *)((ns))) || + !XMLArrayAddMember(cx, &xml->u.elem.namespaces, (&xml->u.elem.namespaces)->length, (void *)((ns)))) { + goto fail; + } + } + ((void) 0); + n -= 2; + *pnp = pn2->pn_next; + continue; + } + pnp = &pn2->pn_next; + } + xml->u.elem.namespaces.trim(); + pn2 = pn->pn_u.list.head; + qn = ParseNodeToQName(parser, pn2, inScopeNSes, (JSIntn)0); + if (!qn) + goto fail; + xml->name = qn; + ((void) 0); + n >>= 1; + if (!xml->u.elem.attrs.setCapacity(cx, n)) + goto fail; + for (i = 0; (pn2 = pn2->pn_next) != __null; i++) { + qn = ParseNodeToQName(parser, pn2, inScopeNSes, (JSIntn)1); + if (!qn) { + xml->u.elem.attrs.length = i; + goto fail; + } + for (j = 0; j < i; j++) { + attrj = (((j) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[j] : __null); + attrjqn = attrj->name; + if (EqualStrings(attrjqn->getNameURI(), qn->getNameURI()) && + EqualStrings(attrjqn->getQNameLocalName(), qn->getQNameLocalName())) { + Value v = StringValue((pn2->pn_u.name.atom)); + JSAutoByteString bytes; + if (js_ValueToPrintable(cx, v, &bytes)) { + ReportCompileErrorNumber(cx, &parser->tokenStream, pn2, + 0x0, JSMSG_DUPLICATE_XML_ATTR, + bytes.ptr()); + } + goto fail; + } + } + pn2 = pn2->pn_next; + ((void) 0); + ((void) 0); + attr = js_NewXML(cx, JSXML_CLASS_ATTRIBUTE); + if (!attr) + goto fail; + 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); + attr->parent = xml; + attr->name = qn; + attr->u.value = (pn2->pn_u.name.atom); + } + if (pn->pn_type == TOK_XMLPTAGC) + XMLArrayTruncate(cx, inScopeNSes, length); + break; + case TOK_XMLSPACE: + case TOK_XMLTEXT: + case TOK_XMLCDATA: + case TOK_XMLCOMMENT: + case TOK_XMLPI: + str = (pn->pn_u.name.atom); + qn = __null; + if (pn->pn_type == TOK_XMLCOMMENT) { + if (flags & ((JSUint32)1 << (0))) + goto skip_child; + xml_class = JSXML_CLASS_COMMENT; + } else if (pn->pn_type == TOK_XMLPI) { + 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'))) { + Value v = StringValue(str); + JSAutoByteString bytes; + if (js_ValueToPrintable(cx, v, &bytes)) { + ReportCompileErrorNumber(cx, &parser->tokenStream, pn, + 0x0, JSMSG_RESERVED_ID, bytes.ptr()); + } + goto fail; + } + if (flags & ((JSUint32)1 << (1))) + goto skip_child; + qn = ParseNodeToQName(parser, pn, inScopeNSes, (JSIntn)0); + if (!qn) + goto fail; + str = pn->pn_u.apair.atom2 + ? (pn->pn_u.apair.atom2) + : cx->runtime->emptyString; + xml_class = JSXML_CLASS_PROCESSING_INSTRUCTION; + } else { + xml_class = JSXML_CLASS_TEXT; + } + xml = js_NewXML(cx, xml_class); + if (!xml) + goto fail; + xml->name = qn; + if (pn->pn_type == TOK_XMLSPACE) + xml->xml_flags |= 0x1; + xml->u.value = str; + break; + default: + goto syntax; + } + js_LeaveLocalRootScopeWithResult(cx, xml); + return xml; +skip_child: + js_LeaveLocalRootScope(cx); + return ((JSXML *) 1); +syntax: + ReportCompileErrorNumber(cx, &parser->tokenStream, pn, 0x0, JSMSG_BAD_XML_MARKUP); +fail: + js_LeaveLocalRootScope(cx); + return __null; +} +static JSBool +GetXMLSetting(JSContext *cx, const char *name, jsval *vp) +{ + jsval v; + if (!js_FindClassObject(cx, __null, JSProto_XML, Valueify(&v))) + return (JSIntn)0; + if (!(!JSVAL_IS_PRIMITIVE(v) && JSVAL_TO_OBJECT(v)->isFunction())) { + *vp = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + return (JSIntn)1; + } + return JS_GetProperty(cx, JSVAL_TO_OBJECT(v), name, vp); +} +static JSBool +GetBooleanXMLSetting(JSContext *cx, const char *name, JSBool *bp) +{ + jsval v; + return GetXMLSetting(cx, name, &v) && JS_ValueToBoolean(cx, v, bp); +} +static JSBool +GetUint32XMLSetting(JSContext *cx, const char *name, uint32 *uip) +{ + jsval v; + return GetXMLSetting(cx, name, &v) && JS_ValueToECMAUint32(cx, v, uip); +} +static JSBool +GetXMLSettingFlags(JSContext *cx, uintN *flagsp) +{ + JSBool flag[4]; + if (!GetBooleanXMLSetting(cx, js_ignoreComments_str, &flag[0]) || + !GetBooleanXMLSetting(cx, js_ignoreProcessingInstructions_str, &flag[1]) || + !GetBooleanXMLSetting(cx, js_ignoreWhitespace_str, &flag[2]) || + !GetBooleanXMLSetting(cx, js_prettyPrinting_str, &flag[3])) { + return false; + } + *flagsp = 0; + for (size_t n = 0; n < 4; ++n) + if (flag[n]) + *flagsp |= ((JSUint32)1 << (n)); + return true; +} +static JSXML * +ParseXMLSource(JSContext *cx, JSString *src) +{ + jsval nsval; + JSLinearString *uri; + size_t urilen, srclen, length, offset, dstlen; + jschar *chars; + const jschar *srcp, *endp; + JSXML *xml; + const char *filename; + uintN lineno; + JSOp op; + static const char prefix[] = ""; + static const char suffix[] = ""; + if (!js_GetDefaultXMLNamespace(cx, &nsval)) + return __null; + uri = JSVAL_TO_OBJECT(nsval)->getNameURI(); + uri = js_EscapeAttributeValue(cx, uri, (JSIntn)0); + if (!uri) + return __null; + urilen = uri->length(); + srclen = src->length(); + length = (sizeof(prefix) - 1) + urilen + (sizeof(middle) - 1) + srclen + + (sizeof(suffix) - 1); + chars = (jschar *) cx->malloc((length + 1) * sizeof(jschar)); + if (!chars) + return __null; + dstlen = length; + js_InflateStringToBuffer(cx, prefix, (sizeof(prefix) - 1), chars, &dstlen); + offset = dstlen; + memcpy((chars + offset), (uri->chars()), (urilen) * sizeof(jschar)); + offset += urilen; + dstlen = length - offset + 1; + js_InflateStringToBuffer(cx, middle, (sizeof(middle) - 1), chars + offset, + &dstlen); + offset += dstlen; + srcp = src->getChars(cx); + if (!srcp) { + cx->free(chars); + return __null; + } + memcpy((chars + offset), (srcp), (srclen) * sizeof(jschar)); + offset += srclen; + dstlen = length - offset + 1; + js_InflateStringToBuffer(cx, suffix, (sizeof(suffix) - 1), chars + offset, + &dstlen); + chars [offset + dstlen] = 0; + LeaveTrace(cx); + xml = __null; + FrameRegsIter i(cx); + for (; !i.done() && !i.pc(); ++i) + ((void) 0); + filename = __null; + lineno = 1; + if (!i.done()) { + JSStackFrame *fp = i.fp(); + op = (JSOp) *i.pc(); + if (op == JSOP_TOXML || op == JSOP_TOXMLLIST) { + filename = fp->script()->filename; + lineno = js_FramePCToLineNumber(cx, fp); + for (endp = srcp + srclen; srcp < endp; srcp++) { + if (*srcp == '\n') + --lineno; + } + } + } + { + Parser parser(cx); + if (parser.init(chars, length, filename, lineno, cx->findVersion())) { + JSObject *scopeChain = GetScopeChain(cx); + if (!scopeChain) { + cx->free(chars); + return __null; + } + JSParseNode *pn = parser.parseXMLText(scopeChain, false); + uintN flags; + if (pn && GetXMLSettingFlags(cx, &flags)) { + AutoNamespaceArray namespaces(cx); + if (namespaces.array.setCapacity(cx, 1)) + xml = ParseNodeToXML(&parser, pn, &namespaces.array, flags); + } + } + } + cx->free(chars); + return xml; +} +static JSXML * +OrphanXMLChild(JSContext *cx, JSXML *xml, uint32 i) +{ + JSObject *ns; + ns = (((0) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[0] : __null); + xml = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (!ns || !xml) + return xml; + if (xml->xml_class == JSXML_CLASS_ELEMENT) { + if (!XMLArrayAddMember(cx, &xml->u.elem.namespaces, (&xml->u.elem.namespaces)->length, (void *)((ns)))) + return __null; + ns->setNamespaceDeclared(((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0))); + } + xml->parent = __null; + return xml; +} +static JSObject * +ToXML(JSContext *cx, jsval v) +{ + JSObject *obj; + JSXML *xml; + Class *clasp; + JSString *str; + uint32 length; + if (JSVAL_IS_PRIMITIVE(v)) { + if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) + goto bad; + } else { + obj = JSVAL_TO_OBJECT(v); + if (obj->isXML()) { + xml = (JSXML *) obj->getPrivate(); + if (xml->xml_class == JSXML_CLASS_LIST) { + if (xml->u.list.kids.length != 1) + goto bad; + xml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null); + if (xml) { + ((void) 0); + return js_GetXMLObject(cx, xml); + } + } + return obj; + } + clasp = obj->getClass(); + if (clasp->flags & (1<<7)) { + ((void) 0); + } + if (clasp != &js_StringClass && + clasp != &js_NumberClass && + clasp != &js_BooleanClass) { + goto bad; + } + } + str = js_ValueToString(cx, Valueify(v)); + if (!str) + return __null; + if (str->empty()) { + length = 0; + xml = __null; + } else { + xml = ParseXMLSource(cx, str); + if (!xml) + return __null; + length = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); + } + if (length == 0) { + obj = js_NewXMLObject(cx, JSXML_CLASS_TEXT); + if (!obj) + return __null; + } else if (length == 1) { + xml = OrphanXMLChild(cx, xml, 0); + if (!xml) + return __null; + obj = js_GetXMLObject(cx, xml); + if (!obj) + return __null; + } else { + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_SYNTAX_ERROR); + return __null; + } + return obj; +bad: + ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_BAD_XML_CONVERSION, 0, Valueify(v), __null, __null, __null)) + ; + return __null; +} +static JSBool +Append(JSContext *cx, JSXML *list, JSXML *kid); +static JSObject * +ToXMLList(JSContext *cx, jsval v) +{ + JSObject *obj, *listobj; + JSXML *xml, *list, *kid; + Class *clasp; + JSString *str; + uint32 i, length; + if (JSVAL_IS_PRIMITIVE(v)) { + if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) + goto bad; + } else { + obj = JSVAL_TO_OBJECT(v); + if (obj->isXML()) { + xml = (JSXML *) obj->getPrivate(); + if (xml->xml_class != JSXML_CLASS_LIST) { + listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST); + if (!listobj) + return __null; + list = (JSXML *) listobj->getPrivate(); + if (!Append(cx, list, xml)) + return __null; + return listobj; + } + return obj; + } + clasp = obj->getClass(); + if (clasp->flags & (1<<7)) { + ((void) 0); + } + if (clasp != &js_StringClass && + clasp != &js_NumberClass && + clasp != &js_BooleanClass) { + goto bad; + } + } + str = js_ValueToString(cx, Valueify(v)); + if (!str) + return __null; + if (str->empty()) { + xml = __null; + length = 0; + } else { + if (!js_EnterLocalRootScope(cx)) + return __null; + xml = ParseXMLSource(cx, str); + if (!xml) { + js_LeaveLocalRootScope(cx); + return __null; + } + length = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); + } + listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST); + if (listobj) { + list = (JSXML *) listobj->getPrivate(); + for (i = 0; i < length; i++) { + kid = OrphanXMLChild(cx, xml, i); + if (!kid || !Append(cx, list, kid)) { + listobj = __null; + break; + } + } + } + if (xml) + js_LeaveLocalRootScopeWithResult(cx, listobj); + return listobj; +bad: + ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_BAD_XMLLIST_CONVERSION, 0, Valueify(v), __null, __null, __null)) + ; + return __null; +} +static JSFlatString * +MakeXMLSpecialString(JSContext *cx, StringBuffer &sb, + JSString *str, JSString *str2, + const jschar *prefix, size_t prefixlength, + const jschar *suffix, size_t suffixlength) +{ + if (!sb.append(prefix, prefixlength) || !sb.append(str)) + return __null; + if (str2 && !str2->empty()) { + if (!sb.append(' ') || !sb.append(str2)) + return __null; + } + if (!sb.append(suffix, suffixlength)) + return __null; + return sb.finishString(); +} +static JSFlatString * +MakeXMLCDATAString(JSContext *cx, StringBuffer &sb, JSString *str) +{ + static const jschar cdata_prefix_ucNstr[] = {'<', '!', '[', + 'C', 'D', 'A', 'T', 'A', + '['}; + static const jschar cdata_suffix_ucNstr[] = {']', ']', '>'}; + return MakeXMLSpecialString(cx, sb, str, __null, + cdata_prefix_ucNstr, 9, + cdata_suffix_ucNstr, 3); +} +static JSFlatString * +MakeXMLCommentString(JSContext *cx, StringBuffer &sb, JSString *str) +{ + static const jschar comment_prefix_ucNstr[] = {'<', '!', '-', '-'}; + static const jschar comment_suffix_ucNstr[] = {'-', '-', '>'}; + return MakeXMLSpecialString(cx, sb, str, __null, + comment_prefix_ucNstr, 4, + comment_suffix_ucNstr, 3); +} +static JSFlatString * +MakeXMLPIString(JSContext *cx, StringBuffer &sb, JSString *name, + JSString *value) +{ + static const jschar pi_prefix_ucNstr[] = {'<', '?'}; + static const jschar pi_suffix_ucNstr[] = {'?', '>'}; + return MakeXMLSpecialString(cx, sb, name, value, + pi_prefix_ucNstr, 2, + pi_suffix_ucNstr, 2); +} +static + bool +AppendAttributeValue(JSContext *cx, StringBuffer &sb, JSString *valstr) +{ + if (!sb.append('=')) + return false; + valstr = js_EscapeAttributeValue(cx, valstr, (JSIntn)1); + return valstr && sb.append(valstr); +} +static JSFlatString * +EscapeElementValue(JSContext *cx, StringBuffer &sb, JSString *str, uint32 toSourceFlag) +{ + size_t length = str->length(); + const jschar *start = str->getChars(cx); + if (!start) + return __null; + for (const jschar *cp = start, *end = start + length; cp != end; ++cp) { + jschar c = *cp; + switch (*cp) { + case '<': + if (!sb.append(js_lt_entity_str)) + return __null; + break; + case '>': + if (!sb.append(js_gt_entity_str)) + return __null; + break; + case '&': + if (!sb.append(js_amp_entity_str)) + return __null; + break; + case '{': + if (toSourceFlag) { + if (!sb.append(js_leftcurly_entity_str)) + return __null; + break; + } + default: + if (!sb.append(c)) + return __null; + } + } + return sb.finishString(); +} +static JSFlatString * +EscapeAttributeValue(JSContext *cx, StringBuffer &sb, JSString *str, JSBool quote) +{ + size_t length = str->length(); + const jschar *start = str->getChars(cx); + if (!start) + return __null; + if (quote && !sb.append('"')) + return __null; + for (const jschar *cp = start, *end = start + length; cp != end; ++cp) { + jschar c = *cp; + switch (c) { + case '"': + if (!sb.append(js_quot_entity_str)) + return __null; + break; + case '<': + if (!sb.append(js_lt_entity_str)) + return __null; + break; + case '&': + if (!sb.append(js_amp_entity_str)) + return __null; + break; + case '\n': + if (!sb.append(" ")) + return __null; + break; + case '\r': + if (!sb.append(" ")) + return __null; + break; + case '\t': + if (!sb.append(" ")) + return __null; + break; + default: + if (!sb.append(c)) + return __null; + } + } + if (quote && !sb.append('"')) + return __null; + return sb.finishString(); +} +static JSObject * +GetNamespace(JSContext *cx, JSObject *qn, const JSXMLArray *inScopeNSes) +{ + JSLinearString *uri, *prefix, *nsprefix; + JSObject *match, *ns; + uint32 i, n; + jsval argv[2]; + uri = qn->getNameURI(); + prefix = qn->getNamePrefix(); + ((void) 0); + if (!uri) { + JSAutoByteString bytes; + const char *s = !prefix ? + js_undefined_str + : js_ValueToPrintable(cx, StringValue(prefix), &bytes); + if (s) + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_BAD_XML_NAMESPACE, s); + return __null; + } + match = __null; + if (inScopeNSes) { + for (i = 0, n = inScopeNSes->length; i < n; i++) { + ns = (((i) < (inScopeNSes)->length) ? (JSObject *) (inScopeNSes)->vector[i] : __null); + if (!ns) + continue; + if (EqualStrings(ns->getNameURI(), uri)) { + nsprefix = ns->getNamePrefix(); + if (nsprefix == prefix || + ((nsprefix && prefix) + ? EqualStrings(nsprefix, prefix) + : (nsprefix ? nsprefix : prefix)->empty())) { + match = ns; + break; + } + } + } + } + if (!match) { + argv[0] = prefix ? STRING_TO_JSVAL(prefix) : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + argv[1] = STRING_TO_JSVAL(uri); + ns = js_ConstructObject(cx, &js_NamespaceClass, __null, __null, + 2, Valueify(argv)); + if (!ns) + return __null; + match = ns; + } + return match; +} +static JSLinearString * +GeneratePrefix(JSContext *cx, JSLinearString *uri, JSXMLArray *decls) +{ + const jschar *cp, *start, *end; + size_t length, newlength, offset; + uint32 i, n, m, serial; + jschar *bp, *dp; + JSBool done; + JSObject *ns; + JSLinearString *nsprefix, *prefix; + ((void) 0); + if (decls->length == 0) + return js_NewStringCopyZ(cx, "a"); + start = uri->chars(); + end = start + uri->length(); + cp = end; + while (--cp > start) { + if (*cp == '.' || *cp == '/' || *cp == ':') { + ++cp; + length = end - cp; + 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'))) + break; + end = --cp; + } + } + length = end - cp; + bp = (jschar *) cp; + newlength = length; + 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)) { + newlength = length + 2 + (size_t) log10((double) decls->length); + bp = (jschar *) + cx->malloc((newlength + 1) * sizeof(jschar)); + if (!bp) + return __null; + bp[newlength] = 0; + for (i = 0; i < newlength; i++) + bp[i] = 'a'; + } + serial = 0; + do { + done = (JSIntn)1; + for (i = 0, n = decls->length; i < n; i++) { + ns = (((i) < (decls)->length) ? (JSObject *) (decls)->vector[i] : __null); + if (ns && (nsprefix = ns->getNamePrefix()) && + nsprefix->length() == newlength && + !memcmp(nsprefix->chars(), bp, + newlength * sizeof(jschar))) { + if (bp == cp) { + newlength = length + 2 + (size_t) log10((double) n); + bp = (jschar *) + cx->malloc((newlength + 1) * sizeof(jschar)); + if (!bp) + return __null; + memcpy((bp), (cp), (length) * sizeof(jschar)); + } + ++serial; + ((void) 0); + dp = bp + length + 2 + (size_t) log10((double) serial); + *dp = 0; + for (m = serial; m != 0; m /= 10) + *--dp = (jschar)('0' + m % 10); + *--dp = '-'; + ((void) 0); + done = (JSIntn)0; + break; + } + } + } while (!done); + if (bp == cp) { + offset = cp - start; + prefix = js_NewDependentString(cx, uri, offset, length); + } else { + prefix = js_NewString(cx, bp, newlength); + if (!prefix) + cx->free(bp); + } + return prefix; +} +static JSBool +namespace_match(const void *a, const void *b) +{ + const JSObject *nsa = (const JSObject *) a; + const JSObject *nsb = (const JSObject *) b; + JSLinearString *prefixa, *prefixb = nsb->getNamePrefix(); + if (prefixb) { + prefixa = nsa->getNamePrefix(); + return prefixa && EqualStrings(prefixa, prefixb); + } + return EqualStrings(nsa->getNameURI(), nsb->getNameURI()); +} +static JSString * +XMLToXMLString(JSContext *cx, JSXML *xml, const JSXMLArray *ancestorNSes, + uint32 indentLevel) +{ + JSBool pretty, indentKids; + StringBuffer sb(cx); + JSString *str; + JSLinearString *prefix, *nsuri; + uint32 i, n, nextIndentLevel; + JSObject *ns, *ns2; + AutoNamespaceArray empty(cx), decls(cx), ancdecls(cx); + if (!GetBooleanXMLSetting(cx, js_prettyPrinting_str, &pretty)) + return __null; + if (pretty) { + if (!sb.appendN(' ', indentLevel & ~0x80000000)) + return __null; + } + str = __null; + switch (xml->xml_class) { + case JSXML_CLASS_TEXT: + if (pretty) { + str = ChompXMLWhitespace(cx, xml->u.value); + if (!str) + return __null; + } else { + str = xml->u.value; + } + return EscapeElementValue(cx, sb, str, indentLevel & 0x80000000); + case JSXML_CLASS_ATTRIBUTE: + return EscapeAttributeValue(cx, sb, xml->u.value, + (indentLevel & 0x80000000) != 0); + case JSXML_CLASS_COMMENT: + return MakeXMLCommentString(cx, sb, xml->u.value); + case JSXML_CLASS_PROCESSING_INSTRUCTION: + return MakeXMLPIString(cx, sb, xml->name->getQNameLocalName(), + xml->u.value); + case JSXML_CLASS_LIST: + { + JSXMLArrayCursor cursor(&xml->u.list.kids); + i = 0; + while (JSXML *kid = (JSXML *) cursor.getNext()) { + if (pretty && i != 0) { + if (!sb.append('\n')) + return __null; + } + JSString *kidstr = XMLToXMLString(cx, kid, ancestorNSes, indentLevel); + if (!kidstr || !sb.append(kidstr)) + return __null; + ++i; + } + } + if (sb.empty()) + return cx->runtime->emptyString; + return sb.finishString(); + default:; + } + if (!js_EnterLocalRootScope(cx)) + return __null; + if (!ancestorNSes) + ancestorNSes = &empty.array; + { + JSXMLArrayCursor cursor(&xml->u.elem.namespaces); + while ((ns = (JSObject *) cursor.getNext()) != __null) { + if (!IsDeclared(ns)) + continue; + if (!(XMLArrayFindMember(ancestorNSes, (void *)(ns), namespace_identity) != ((uint32) -1))) { + ns2 = NewXMLNamespace(cx, ns->getNamePrefix(), ns->getNameURI(), (JSIntn)1); + if (!ns2 || !XMLArrayAddMember(cx, &decls.array, (&decls.array)->length, (void *)((ns2)))) + goto out; + } + } + } + if (!ancdecls.array.setCapacity(cx, ancestorNSes->length + decls.length())) + goto out; + for (i = 0, n = ancestorNSes->length; i < n; i++) { + ns2 = (((i) < (ancestorNSes)->length) ? (JSObject *) (ancestorNSes)->vector[i] : __null); + if (!ns2) + continue; + ((void) 0); + if (!XMLArrayAddMember(cx, &ancdecls.array, (&ancdecls.array)->length, (void *)((ns2)))) + goto out; + } + for (i = 0, n = decls.length(); i < n; i++) { + ns2 = (((i) < (&decls.array)->length) ? (JSObject *) (&decls.array)->vector[i] : __null); + if (!ns2) + continue; + ((void) 0); + if (!XMLArrayAddMember(cx, &ancdecls.array, (&ancdecls.array)->length, (void *)((ns2)))) + goto out; + } + ns = GetNamespace(cx, xml->name, &ancdecls.array); + if (!ns) + goto out; + prefix = ns->getNamePrefix(); + if (!prefix) { + nsuri = ns->getNameURI(); + if (!xml->name->getNamePrefix()) { + prefix = cx->runtime->emptyString; + } else { + prefix = GeneratePrefix(cx, nsuri, &ancdecls.array); + if (!prefix) + goto out; + } + ns = NewXMLNamespace(cx, prefix, nsuri, (JSIntn)1); + if (!ns) + goto out; + if (prefix->empty()) { + i = XMLArrayFindMember(&decls.array, ns, namespace_match); + if (i != ((uint32) -1)) + XMLArrayDelete(cx, &decls.array, i, (JSIntn)1); + } + if (!XMLArrayAddMember(cx, &ancdecls.array, (&ancdecls.array)->length, (void *)((ns))) || + !XMLArrayAddMember(cx, &decls.array, (&decls.array)->length, (void *)((ns)))) { + goto out; + } + } + if (!sb.append('<')) + goto out; + if (!prefix->empty()) { + if (!sb.append(prefix) || !sb.append(':')) + goto out; + } + if (!sb.append(xml->name->getQNameLocalName())) + goto out; + { + JSXMLArrayCursor cursor(&xml->u.elem.attrs); + while (JSXML *attr = (JSXML *) cursor.getNext()) { + if (!sb.append(' ')) + goto out; + ns2 = GetNamespace(cx, attr->name, &ancdecls.array); + if (!ns2) + goto out; + prefix = ns2->getNamePrefix(); + if (!prefix) { + prefix = GeneratePrefix(cx, ns2->getNameURI(), &ancdecls.array); + if (!prefix) + goto out; + ns2 = NewXMLNamespace(cx, prefix, ns2->getNameURI(), (JSIntn)1); + if (!ns2) + goto out; + if (!XMLArrayAddMember(cx, &ancdecls.array, (&ancdecls.array)->length, (void *)((ns2))) || + !XMLArrayAddMember(cx, &decls.array, (&decls.array)->length, (void *)((ns2)))) { + goto out; + } + } + if (!prefix->empty()) { + if (!sb.append(prefix) || !sb.append(':')) + goto out; + } + if (!sb.append(attr->name->getQNameLocalName())) + goto out; + if (!AppendAttributeValue(cx, sb, attr->u.value)) + goto out; + } + } + { + JSXMLArrayCursor cursor(&decls.array); + while (JSObject *ns3 = (JSObject *) cursor.getNext()) { + ((void) 0); + if (!sb.append(" xmlns")) + goto out; + prefix = ns3->getNamePrefix(); + if (!prefix) { + prefix = GeneratePrefix(cx, ns3->getNameURI(), &ancdecls.array); + if (!prefix) + goto out; + ns3->setNamePrefix(prefix); + } + if (!prefix->empty()) { + if (!sb.append(':') || !sb.append(prefix)) + goto out; + } + if (!AppendAttributeValue(cx, sb, ns3->getNameURI())) + goto out; + } + } + n = xml->u.list.kids.length; + if (n == 0) { + if (!sb.append("/>")) + goto out; + } else { + if (!sb.append('>')) + goto out; + { + JSXML *kid; + indentKids = n > 1 || + (n == 1 && + (kid = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null)) && + kid->xml_class != JSXML_CLASS_TEXT); + } + if (pretty && indentKids) { + if (!GetUint32XMLSetting(cx, js_prettyIndent_str, &i)) + goto out; + nextIndentLevel = indentLevel + i; + } else { + nextIndentLevel = indentLevel & 0x80000000; + } + { + JSXMLArrayCursor cursor(&xml->u.list.kids); + while (JSXML *kid = (JSXML *) cursor.getNext()) { + if (pretty && indentKids) { + if (!sb.append('\n')) + goto out; + } + JSString *kidstr = XMLToXMLString(cx, kid, &ancdecls.array, nextIndentLevel); + if (!kidstr) + goto out; + if (!sb.append(kidstr)) + goto out; + } + } + if (pretty && indentKids) { + if (!sb.append('\n') || + !sb.appendN(' ', indentLevel & ~0x80000000)) + goto out; + } + if (!sb.append("getNamePrefix(); + if (prefix && !prefix->empty()) { + if (!sb.append(prefix) || !sb.append(':')) + goto out; + } + if (!sb.append(xml->name->getQNameLocalName()) || !sb.append('>')) + goto out; + } + str = sb.finishString(); +out: + js_LeaveLocalRootScopeWithResult(cx, str); + return str; +} +static JSString * +ToXMLString(JSContext *cx, jsval v, uint32 toSourceFlag) +{ + JSObject *obj; + JSString *str; + JSXML *xml; + if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, + JSMSG_BAD_XML_CONVERSION, + JSVAL_IS_NULL(v) ? js_null_str : js_undefined_str); + return __null; + } + if (JSVAL_IS_BOOLEAN(v) || JSVAL_IS_NUMBER(v)) + return js_ValueToString(cx, Valueify(v)); + if (JSVAL_IS_STRING(v)) { + StringBuffer sb(cx); + return EscapeElementValue(cx, sb, JSVAL_TO_STRING(v), toSourceFlag); + } + obj = JSVAL_TO_OBJECT(v); + if (!obj->isXML()) { + if (!DefaultValue(cx, obj, JSTYPE_STRING, Valueify(&v))) + return __null; + str = js_ValueToString(cx, Valueify(v)); + if (!str) + return __null; + StringBuffer sb(cx); + return EscapeElementValue(cx, sb, str, toSourceFlag); + } + xml = (JSXML *) obj->getPrivate(); + return XMLToXMLString(cx, xml, __null, toSourceFlag | 0); +} +static JSObject * +ToAttributeName(JSContext *cx, jsval v) +{ + JSLinearString *name, *uri, *prefix; + JSObject *obj; + Class *clasp; + JSObject *qn; + if (JSVAL_IS_STRING(v)) { + name = JSVAL_TO_STRING(v)->ensureLinear(cx); + if (!name) + return __null; + uri = prefix = cx->runtime->emptyString; + } else { + if (JSVAL_IS_PRIMITIVE(v)) { + ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_BAD_XML_ATTR_NAME, 0, Valueify(v), __null, __null, __null)) + ; + return __null; + } + obj = JSVAL_TO_OBJECT(v); + clasp = obj->getClass(); + if (clasp == &js_AttributeNameClass) + return obj; + if (clasp == &js_QNameClass) { + qn = obj; + uri = qn->getNameURI(); + prefix = qn->getNamePrefix(); + name = qn->getQNameLocalName(); + } else { + if (clasp == &js_AnyNameClass) { + name = (cx->runtime->atomState.starAtom); + } else { + JSString *str = js_ValueToString(cx, Valueify(v)); + if (!str) + return __null; + name = str->ensureLinear(cx); + if (!name) + return __null; + } + uri = prefix = cx->runtime->emptyString; + } + } + qn = NewXMLAttributeName(cx, uri, prefix, name); + if (!qn) + return __null; + return qn; +} +static void +ReportBadXMLName(JSContext *cx, const Value &idval) +{ + ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_BAD_XML_NAME, 0, idval, __null, __null, __null)); +} +static JSBool +IsFunctionQName(JSContext *cx, JSObject *qn, jsid *funidp) +{ + JSAtom *atom; + JSLinearString *uri; + atom = cx->runtime->atomState.functionNamespaceURIAtom; + uri = qn->getNameURI(); + if (uri && + (uri == (atom) || + EqualStrings(uri, (atom)))) { + return JS_ValueToId(cx, STRING_TO_JSVAL(qn->getQNameLocalName()), funidp); + } + *funidp = ((jsid)0x2); + return (JSIntn)1; +} +JSBool +js_IsFunctionQName(JSContext *cx, JSObject *obj, jsid *funidp) +{ + if (obj->getClass() == &js_QNameClass) + return IsFunctionQName(cx, obj, funidp); + *funidp = ((jsid)0x2); + return (JSIntn)1; +} +static JSObject * +ToXMLName(JSContext *cx, jsval v, jsid *funidp) +{ + JSAtom *atomizedName; + JSString *name; + JSObject *obj; + Class *clasp; + uint32 index; + if (JSVAL_IS_STRING(v)) { + name = JSVAL_TO_STRING(v); + } else { + if (JSVAL_IS_PRIMITIVE(v)) { + ReportBadXMLName(cx, Valueify(v)); + return __null; + } + obj = JSVAL_TO_OBJECT(v); + clasp = obj->getClass(); + if (clasp == &js_AttributeNameClass || clasp == &js_QNameClass) + goto out; + if (clasp == &js_AnyNameClass) { + name = (cx->runtime->atomState.starAtom); + goto construct; + } + name = js_ValueToString(cx, Valueify(v)); + if (!name) + return __null; + } + atomizedName = js_AtomizeString(cx, name, 0); + if (!atomizedName) + return __null; + if (js_IdIsIndex(ATOM_TO_JSID(atomizedName), &index)) + goto bad; + if (*atomizedName->chars() == '@') { + name = js_NewDependentString(cx, name, 1, name->length() - 1); + if (!name) + return __null; + *funidp = ((jsid)0x2); + return ToAttributeName(cx, STRING_TO_JSVAL(name)); + } +construct: + v = STRING_TO_JSVAL(name); + obj = js_ConstructObject(cx, &js_QNameClass, __null, __null, 1, Valueify(&v)); + if (!obj) + return __null; +out: + if (!IsFunctionQName(cx, obj, funidp)) + return __null; + return obj; +bad: + JSAutoByteString bytes; + if (js_ValueToPrintable(cx, StringValue(name), &bytes)) + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_BAD_XML_NAME, bytes.ptr()); + return __null; +} +static JSBool +AddInScopeNamespace(JSContext *cx, JSXML *xml, JSObject *ns) +{ + JSLinearString *prefix, *prefix2; + JSObject *match, *ns2; + uint32 i, n, m; + if (xml->xml_class != JSXML_CLASS_ELEMENT) + return (JSIntn)1; + prefix = ns->getNamePrefix(); + if (!prefix) { + match = __null; + for (i = 0, n = xml->u.elem.namespaces.length; i < n; i++) { + ns2 = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null); + if (ns2 && EqualStrings(ns2->getNameURI(), ns->getNameURI())) { + match = ns2; + break; + } + } + if (!match && !XMLArrayAddMember(cx, &xml->u.elem.namespaces, n, (void *)(ns))) + return (JSIntn)0; + } else { + if (prefix->empty() && xml->name->getNameURI()->empty()) + return (JSIntn)1; + match = __null; + m = ((uint32) -1); + for (i = 0, n = xml->u.elem.namespaces.length; i < n; i++) { + ns2 = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null); + if (ns2 && (prefix2 = ns2->getNamePrefix()) && + EqualStrings(prefix2, prefix)) { + match = ns2; + m = i; + break; + } + } + if (match && !EqualStrings(match->getNameURI(), ns->getNameURI())) { + ns2 = ((JSObject *) XMLArrayDelete(cx, &xml->u.elem.namespaces, m, (JSIntn)1)) + ; + ((void) 0); + match->clearNamePrefix(); + if (!AddInScopeNamespace(cx, xml, match)) + return (JSIntn)0; + } + if (!XMLArrayAddMember(cx, &xml->u.elem.namespaces, (&xml->u.elem.namespaces)->length, (void *)((ns)))) + return (JSIntn)0; + } + return (JSIntn)1; +} +static JSBool +Append(JSContext *cx, JSXML *list, JSXML *xml) +{ + uint32 i, j, k, n; + JSXML *kid; + ((void) 0); + i = list->u.list.kids.length; + n = 1; + if (xml->xml_class == JSXML_CLASS_LIST) { + list->u.list.target = xml->u.list.target; + list->u.list.targetprop = xml->u.list.targetprop; + n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); + k = i + n; + if (!list->u.list.kids.setCapacity(cx, k)) + return (JSIntn)0; + for (j = 0; j < n; j++) { + kid = (((j) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[j] : __null); + if (kid) + 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); + } + return (JSIntn)1; + } + list->u.list.target = xml->parent; + if (xml->xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION) + list->u.list.targetprop = __null; + else + list->u.list.targetprop = xml->name; + if (!XMLArrayAddMember(cx, &list->u.list.kids, i, (void *)(xml))) + return (JSIntn)0; + return (JSIntn)1; +} +static JSXML * +DeepCopyInLRS(JSContext *cx, JSXML *xml, uintN flags); +static JSXML * +DeepCopy(JSContext *cx, JSXML *xml, JSObject *obj, uintN flags) +{ + JSXML *copy; + if (!js_EnterLocalRootScope(cx)) + return __null; + copy = DeepCopyInLRS(cx, xml, flags); + if (copy) { + if (obj) { + obj->setPrivate(copy); + copy->object = obj; + } else if (!js_GetXMLObject(cx, copy)) { + copy = __null; + } + } + js_LeaveLocalRootScopeWithResult(cx, copy); + return copy; +} +static JSBool +DeepCopySetInLRS(JSContext *cx, JSXMLArray *from, JSXMLArray *to, JSXML *parent, + uintN flags) +{ + uint32 j, n; + JSXML *kid2; + JSString *str; + n = from->length; + if (!to->setCapacity(cx, n)) + return (JSIntn)0; + JSXMLArrayCursor cursor(from); + j = 0; + while (JSXML *kid = (JSXML *) cursor.getNext()) { + if ((flags & ((JSUint32)1 << (0))) && + kid->xml_class == JSXML_CLASS_COMMENT) { + continue; + } + if ((flags & ((JSUint32)1 << (1))) && + kid->xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION) { + continue; + } + if ((flags & ((JSUint32)1 << (2))) && + (kid->xml_flags & 0x1)) { + continue; + } + kid2 = DeepCopyInLRS(cx, kid, flags); + if (!kid2) { + to->length = j; + return (JSIntn)0; + } + if ((flags & ((JSUint32)1 << (2))) && + n > 1 && kid2->xml_class == JSXML_CLASS_TEXT) { + str = ChompXMLWhitespace(cx, kid2->u.value); + if (!str) { + to->length = j; + return (JSIntn)0; + } + kid2->u.value = str; + } + do { if ((to)->length <= (j)) (to)->length = (j) + 1; ((to)->vector[j] = (void *)(kid2)); } while (0); + ++j; + if (parent->xml_class != JSXML_CLASS_LIST) + kid2->parent = parent; + } + if (j < n) + to->trim(); + return (JSIntn)1; +} +static JSXML * +DeepCopyInLRS(JSContext *cx, JSXML *xml, uintN flags) +{ + JSXML *copy; + JSObject *qn; + JSBool ok; + uint32 i, n; + JSObject *ns, *ns2; + do { int stackDummy_; if (!((jsuword)(&stackDummy_) > cx->stackLimit)) { js_ReportOverRecursed(cx); return __null; } } while (0); + copy = js_NewXML(cx, JSXMLClass(xml->xml_class)); + if (!copy) + return __null; + qn = xml->name; + if (qn) { + qn = NewXMLQName(cx, qn->getNameURI(), qn->getNamePrefix(), qn->getQNameLocalName()); + if (!qn) { + ok = (JSIntn)0; + goto out; + } + } + copy->name = qn; + copy->xml_flags = xml->xml_flags; + if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) { + copy->u.value = xml->u.value; + ok = (JSIntn)1; + } else { + ok = DeepCopySetInLRS(cx, &xml->u.list.kids, ©->u.list.kids, copy, flags); + if (!ok) + goto out; + if (xml->xml_class == JSXML_CLASS_LIST) { + copy->u.list.target = xml->u.list.target; + copy->u.list.targetprop = xml->u.list.targetprop; + } else { + n = xml->u.elem.namespaces.length; + ok = copy->u.elem.namespaces.setCapacity(cx, n); + if (!ok) + goto out; + for (i = 0; i < n; i++) { + ns = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null); + if (!ns) + continue; + ns2 = NewXMLNamespace(cx, ns->getNamePrefix(), ns->getNameURI(), + IsDeclared(ns)); + if (!ns2) { + copy->u.elem.namespaces.length = i; + ok = (JSIntn)0; + goto out; + } + do { if ((©->u.elem.namespaces)->length <= (i)) (©->u.elem.namespaces)->length = (i) + 1; ((©->u.elem.namespaces)->vector[i] = (void *)(ns2)); } while (0); + } + ok = DeepCopySetInLRS(cx, &xml->u.elem.attrs, ©->u.elem.attrs, copy, + 0); + if (!ok) + goto out; + } + } +out: + if (!ok) + return __null; + return copy; +} +static void +DeleteByIndex(JSContext *cx, JSXML *xml, uint32 index) +{ + JSXML *kid; + if ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) && index < xml->u.list.kids.length) { + kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null); + if (kid) + kid->parent = __null; + XMLArrayDelete(cx, &xml->u.list.kids, index, (JSIntn)1); + } +} +typedef JSBool (*JSXMLNameMatcher)(JSObject *nameqn, JSXML *xml); +static JSBool +MatchAttrName(JSObject *nameqn, JSXML *attr) +{ + JSObject *attrqn = attr->name; + JSLinearString *localName = nameqn->getQNameLocalName(); + JSLinearString *uri; + return (((localName)->length() == 1 && *(localName)->chars() == '*') || + EqualStrings(attrqn->getQNameLocalName(), localName)) && + (!(uri = nameqn->getNameURI()) || + EqualStrings(attrqn->getNameURI(), uri)); +} +static JSBool +MatchElemName(JSObject *nameqn, JSXML *elem) +{ + JSLinearString *localName = nameqn->getQNameLocalName(); + JSLinearString *uri; + return (((localName)->length() == 1 && *(localName)->chars() == '*') || + (elem->xml_class == JSXML_CLASS_ELEMENT && + EqualStrings(elem->name->getQNameLocalName(), localName))) && + (!(uri = nameqn->getNameURI()) || + (elem->xml_class == JSXML_CLASS_ELEMENT && + EqualStrings(elem->name->getNameURI(), uri))); +} +static JSBool +DescendantsHelper(JSContext *cx, JSXML *xml, JSObject *nameqn, JSXML *list) +{ + uint32 i, n; + JSXML *attr, *kid; + do { int stackDummy_; if (!((jsuword)(&stackDummy_) > cx->stackLimit)) { js_ReportOverRecursed(cx); return (JSIntn)0; } } while (0); + if (xml->xml_class == JSXML_CLASS_ELEMENT && + nameqn->getClass() == &js_AttributeNameClass) { + for (i = 0, n = xml->u.elem.attrs.length; i < n; i++) { + attr = (((i) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[i] : __null); + if (attr && MatchAttrName(nameqn, attr)) { + if (!Append(cx, list, attr)) + return (JSIntn)0; + } + } + } + for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (!kid) + continue; + if (nameqn->getClass() != &js_AttributeNameClass && + MatchElemName(nameqn, kid)) { + if (!Append(cx, list, kid)) + return (JSIntn)0; + } + if (!DescendantsHelper(cx, kid, nameqn, list)) + return (JSIntn)0; + } + return (JSIntn)1; +} +static JSXML * +Descendants(JSContext *cx, JSXML *xml, jsval id) +{ + jsid funid; + JSObject *nameqn; + JSObject *listobj; + JSXML *list, *kid; + uint32 i, n; + JSBool ok; + nameqn = ToXMLName(cx, id, &funid); + if (!nameqn) + return __null; + listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST); + if (!listobj) + return __null; + list = (JSXML *) listobj->getPrivate(); + if (!JSID_IS_VOID(funid)) + return list; + list->name = nameqn; + if (!js_EnterLocalRootScope(cx)) + return __null; + if (xml->xml_class == JSXML_CLASS_LIST) { + ok = (JSIntn)1; + for (i = 0, n = xml->u.list.kids.length; i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) { + ok = DescendantsHelper(cx, kid, nameqn, list); + if (!ok) + break; + } + } + } else { + ok = DescendantsHelper(cx, xml, nameqn, list); + } + js_LeaveLocalRootScopeWithResult(cx, list); + if (!ok) + return __null; + list->name = __null; + return list; +} +static JSBool +XMLEquals(JSContext *cx, JSXML *xml, JSXML *vxml, JSBool *bp) +{ + JSObject *qn, *vqn; + uint32 i, j, n; + JSXML *kid, *vkid, *attr, *vattr; + JSObject *xobj, *vobj; +retry: + if (xml->xml_class != vxml->xml_class) { + if (xml->xml_class == JSXML_CLASS_LIST && xml->u.list.kids.length == 1) { + xml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null); + if (xml) + goto retry; + } + if (vxml->xml_class == JSXML_CLASS_LIST && vxml->u.list.kids.length == 1) { + vxml = (((0) < (&vxml->u.list.kids)->length) ? (JSXML *) (&vxml->u.list.kids)->vector[0] : __null); + if (vxml) + goto retry; + } + *bp = (JSIntn)0; + return (JSIntn)1; + } + qn = xml->name; + vqn = vxml->name; + if (qn) { + *bp = vqn && + EqualStrings(qn->getQNameLocalName(), vqn->getQNameLocalName()) && + EqualStrings(qn->getNameURI(), vqn->getNameURI()); + } else { + *bp = vqn == __null; + } + if (!*bp) + return (JSIntn)1; + if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) { + if (!EqualStrings(cx, xml->u.value, vxml->u.value, bp)) + return (JSIntn)0; + } else if (xml->u.list.kids.length != vxml->u.list.kids.length) { + *bp = (JSIntn)0; + } else { + { + JSXMLArrayCursor cursor(&xml->u.list.kids); + JSXMLArrayCursor vcursor(&vxml->u.list.kids); + for (;;) { + kid = (JSXML *) cursor.getNext(); + vkid = (JSXML *) vcursor.getNext(); + if (!kid || !vkid) { + *bp = !kid && !vkid; + break; + } + xobj = js_GetXMLObject(cx, kid); + vobj = js_GetXMLObject(cx, vkid); + if (!xobj || !vobj || + !js_TestXMLEquality(cx, ObjectValue(*xobj), ObjectValue(*vobj), bp)) + return (JSIntn)0; + if (!*bp) + break; + } + } + if (*bp && xml->xml_class == JSXML_CLASS_ELEMENT) { + n = xml->u.elem.attrs.length; + if (n != vxml->u.elem.attrs.length) + *bp = (JSIntn)0; + for (i = 0; *bp && i < n; i++) { + attr = (((i) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[i] : __null); + if (!attr) + continue; + j = XMLArrayFindMember(&vxml->u.elem.attrs, (void *)(attr), attr_identity); + if (j == ((uint32) -1)) { + *bp = (JSIntn)0; + break; + } + vattr = (((j) < (&vxml->u.elem.attrs)->length) ? (JSXML *) (&vxml->u.elem.attrs)->vector[j] : __null); + if (!vattr) + continue; + if (!EqualStrings(cx, attr->u.value, vattr->u.value, bp)) + return (JSIntn)0; + } + } + } + return (JSIntn)1; +} +static JSBool +Equals(JSContext *cx, JSXML *xml, jsval v, JSBool *bp) +{ + JSObject *vobj; + JSXML *vxml; + if (JSVAL_IS_PRIMITIVE(v)) { + *bp = (JSIntn)0; + if (xml->xml_class == JSXML_CLASS_LIST) { + if (xml->u.list.kids.length == 1) { + vxml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null); + if (!vxml) + return (JSIntn)1; + vobj = js_GetXMLObject(cx, vxml); + if (!vobj) + return (JSIntn)0; + return js_TestXMLEquality(cx, ObjectValue(*vobj), Valueify(v), bp); + } + if (JSVAL_IS_VOID(v) && xml->u.list.kids.length == 0) + *bp = (JSIntn)1; + } + } else { + vobj = JSVAL_TO_OBJECT(v); + if (!vobj->isXML()) { + *bp = (JSIntn)0; + } else { + vxml = (JSXML *) vobj->getPrivate(); + if (!XMLEquals(cx, xml, vxml, bp)) + return (JSIntn)0; + } + } + return (JSIntn)1; +} +static JSBool +CheckCycle(JSContext *cx, JSXML *xml, JSXML *kid) +{ + ((void) 0); + do { + if (xml == kid) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, + JSMSG_CYCLIC_VALUE, js_XML_str); + return (JSIntn)0; + } + } while ((xml = xml->parent) != __null); + return (JSIntn)1; +} +static JSBool +Insert(JSContext *cx, JSXML *xml, uint32 i, jsval v) +{ + uint32 j, n; + JSXML *vxml, *kid; + JSObject *vobj; + JSString *str; + if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE)) + return (JSIntn)1; + n = 1; + vxml = __null; + if (!JSVAL_IS_PRIMITIVE(v)) { + vobj = JSVAL_TO_OBJECT(v); + if (vobj->isXML()) { + vxml = (JSXML *) vobj->getPrivate(); + if (vxml->xml_class == JSXML_CLASS_LIST) { + n = vxml->u.list.kids.length; + if (n == 0) + return (JSIntn)1; + for (j = 0; j < n; j++) { + kid = (((j) < (&vxml->u.list.kids)->length) ? (JSXML *) (&vxml->u.list.kids)->vector[j] : __null); + if (!kid) + continue; + if (!CheckCycle(cx, xml, kid)) + return (JSIntn)0; + } + } else if (vxml->xml_class == JSXML_CLASS_ELEMENT) { + if (!CheckCycle(cx, xml, vxml)) + return (JSIntn)0; + } + } + } + if (!vxml) { + str = js_ValueToString(cx, Valueify(v)); + if (!str) + return (JSIntn)0; + vxml = js_NewXML(cx, JSXML_CLASS_TEXT); + if (!vxml) + return (JSIntn)0; + vxml->u.value = str; + } + if (i > xml->u.list.kids.length) + i = xml->u.list.kids.length; + if (!XMLArrayInsert(cx, &xml->u.list.kids, i, n)) + return (JSIntn)0; + if (vxml->xml_class == JSXML_CLASS_LIST) { + for (j = 0; j < n; j++) { + kid = (((j) < (&vxml->u.list.kids)->length) ? (JSXML *) (&vxml->u.list.kids)->vector[j] : __null); + if (!kid) + continue; + kid->parent = xml; + 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); + } + } else { + vxml->parent = xml; + 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); + } + return (JSIntn)1; +} +static JSBool +IndexToId(JSContext *cx, uint32 index, jsid *idp) +{ + JSAtom *atom; + JSString *str; + if (index <= ((1 << 30) - 1)) { + *idp = INT_TO_JSID(index); + } else { + str = js_NumberToString(cx, (jsdouble) index); + if (!str) + return (JSIntn)0; + atom = js_AtomizeString(cx, str, 0); + if (!atom) + return (JSIntn)0; + *idp = ATOM_TO_JSID(atom); + } + return (JSIntn)1; +} +static JSBool +Replace(JSContext *cx, JSXML *xml, uint32 i, jsval v) +{ + uint32 n; + JSXML *vxml, *kid; + JSObject *vobj; + JSString *str; + if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE)) + return (JSIntn)1; + n = xml->u.list.kids.length; + if (i > n) + i = n; + vxml = __null; + if (!JSVAL_IS_PRIMITIVE(v)) { + vobj = JSVAL_TO_OBJECT(v); + if (vobj->isXML()) + vxml = (JSXML *) vobj->getPrivate(); + } + switch (vxml ? JSXMLClass(vxml->xml_class) : JSXML_CLASS_LIMIT) { + case JSXML_CLASS_ELEMENT: + if (!CheckCycle(cx, xml, vxml)) + return (JSIntn)0; + case JSXML_CLASS_COMMENT: + case JSXML_CLASS_PROCESSING_INSTRUCTION: + case JSXML_CLASS_TEXT: + goto do_replace; + case JSXML_CLASS_LIST: + if (i < n) + DeleteByIndex(cx, xml, i); + if (!Insert(cx, xml, i, v)) + return (JSIntn)0; + break; + default: + str = js_ValueToString(cx, Valueify(v)); + if (!str) + return (JSIntn)0; + vxml = js_NewXML(cx, JSXML_CLASS_TEXT); + if (!vxml) + return (JSIntn)0; + vxml->u.value = str; + do_replace: + vxml->parent = xml; + if (i < n) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid) + kid->parent = __null; + } + if (!XMLArrayAddMember(cx, &xml->u.list.kids, i, (void *)(vxml))) + return (JSIntn)0; + break; + } + return (JSIntn)1; +} +static void +DeleteNamedProperty(JSContext *cx, JSXML *xml, JSObject *nameqn, + JSBool attributes) +{ + JSXMLArray *array; + uint32 index, deleteCount; + JSXML *kid; + JSXMLNameMatcher matcher; + if (xml->xml_class == JSXML_CLASS_LIST) { + array = &xml->u.list.kids; + for (index = 0; index < array->length; index++) { + kid = (((index) < (array)->length) ? (JSXML *) (array)->vector[index] : __null); + if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) + DeleteNamedProperty(cx, kid, nameqn, attributes); + } + } else if (xml->xml_class == JSXML_CLASS_ELEMENT) { + if (attributes) { + array = &xml->u.elem.attrs; + matcher = MatchAttrName; + } else { + array = &xml->u.list.kids; + matcher = MatchElemName; + } + deleteCount = 0; + for (index = 0; index < array->length; index++) { + kid = (((index) < (array)->length) ? (JSXML *) (array)->vector[index] : __null); + if (kid && matcher(nameqn, kid)) { + kid->parent = __null; + XMLArrayDelete(cx, array, index, (JSIntn)0); + ++deleteCount; + } else if (deleteCount != 0) { + do { if ((array)->length <= (index - deleteCount)) (array)->length = (index - deleteCount) + 1; ((array)->vector[index - deleteCount] = (void *)(array->vector[index])); } while (0) + ; + } + } + array->length -= deleteCount; + } +} +static void +DeleteListElement(JSContext *cx, JSXML *xml, uint32 index) +{ + JSXML *kid, *parent; + uint32 kidIndex; + ((void) 0); + if (index < xml->u.list.kids.length) { + kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null); + if (kid) { + parent = kid->parent; + if (parent) { + ((void) 0); + ((void) 0); + if (kid->xml_class == JSXML_CLASS_ATTRIBUTE) { + DeleteNamedProperty(cx, parent, kid->name, (JSIntn)1); + } else { + kidIndex = XMLArrayFindMember(&parent->u.list.kids, (void *)(kid), __null) + ; + ((void) 0); + DeleteByIndex(cx, parent, kidIndex); + } + } + XMLArrayDelete(cx, &xml->u.list.kids, index, (JSIntn)1); + } + } +} +static JSBool +SyncInScopeNamespaces(JSContext *cx, JSXML *xml) +{ + JSXMLArray *nsarray; + uint32 i, n; + JSObject *ns; + nsarray = &xml->u.elem.namespaces; + while ((xml = xml->parent) != __null) { + for (i = 0, n = xml->u.elem.namespaces.length; i < n; i++) { + ns = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null); + if (ns && !(XMLArrayFindMember(nsarray, (void *)(ns), namespace_identity) != ((uint32) -1))) { + if (!XMLArrayAddMember(cx, nsarray, (nsarray)->length, (void *)((ns)))) + return (JSIntn)0; + } + } + } + return (JSIntn)1; +} +static JSBool +GetNamedProperty(JSContext *cx, JSXML *xml, JSObject* nameqn, JSXML *list) +{ + JSXMLArray *array; + JSXMLNameMatcher matcher; + JSBool attrs; + if (xml->xml_class == JSXML_CLASS_LIST) { + JSXMLArrayCursor cursor(&xml->u.list.kids); + while (JSXML *kid = (JSXML *) cursor.getNext()) { + if (kid->xml_class == JSXML_CLASS_ELEMENT && + !GetNamedProperty(cx, kid, nameqn, list)) { + return (JSIntn)0; + } + } + } else if (xml->xml_class == JSXML_CLASS_ELEMENT) { + attrs = (nameqn->getClass() == &js_AttributeNameClass); + if (attrs) { + array = &xml->u.elem.attrs; + matcher = MatchAttrName; + } else { + array = &xml->u.list.kids; + matcher = MatchElemName; + } + JSXMLArrayCursor cursor(array); + while (JSXML *kid = (JSXML *) cursor.getNext()) { + if (matcher(nameqn, kid)) { + if (!attrs && + kid->xml_class == JSXML_CLASS_ELEMENT && + !SyncInScopeNamespaces(cx, kid)) { + return (JSIntn)0; + } + if (!Append(cx, list, kid)) + return (JSIntn)0; + } + } + } + return (JSIntn)1; +} +static JSBool +GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp) +{ + JSXML *xml, *list, *kid; + uint32 index; + JSObject *kidobj, *listobj; + JSObject *nameqn; + jsid funid; + xml = (JSXML *) GetInstancePrivate(cx, obj, &js_XMLClass, __null); + if (!xml) + return true; + if (js_IdIsIndex(id, &index)) { + if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE)) { + *vp = (index == 0) ? OBJECT_TO_JSVAL(obj) : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + } else { + if (index < xml->u.list.kids.length) { + kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null); + if (!kid) { + *vp = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + return true; + } + kidobj = js_GetXMLObject(cx, kid); + if (!kidobj) + return false; + *vp = OBJECT_TO_JSVAL(kidobj); + } else { + *vp = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + } + } + return true; + } + nameqn = ToXMLName(cx, IdToJsval(id), &funid); + if (!nameqn) + return false; + if (!JSID_IS_VOID(funid)) + return GetXMLFunction(cx, obj, funid, vp); + jsval roots[2] = { OBJECT_TO_JSVAL(nameqn), ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)) }; + AutoArrayRooter tvr(cx, (sizeof (roots) / sizeof (roots)[0]), Valueify(roots)); + listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST); + if (!listobj) + return false; + roots[1] = OBJECT_TO_JSVAL(listobj); + list = (JSXML *) listobj->getPrivate(); + if (!GetNamedProperty(cx, xml, nameqn, list)) + return false; + list->u.list.target = xml; + list->u.list.targetprop = nameqn; + *vp = OBJECT_TO_JSVAL(listobj); + return true; +} +static JSXML * +CopyOnWrite(JSContext *cx, JSXML *xml, JSObject *obj) +{ + ((void) 0); + xml = DeepCopy(cx, xml, obj, 0); + if (!xml) + return __null; + ((void) 0); + return xml; +} +static JSString * +KidToString(JSContext *cx, JSXML *xml, uint32 index) +{ + JSXML *kid; + JSObject *kidobj; + kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null); + if (!kid) + return cx->runtime->emptyString; + kidobj = js_GetXMLObject(cx, kid); + if (!kidobj) + return __null; + return js_ValueToString(cx, ObjectValue(*kidobj)); +} +static JSBool +ResolveValue(JSContext *cx, JSXML *list, JSXML **result); +static JSBool +PutProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp) +{ + JSBool ok, primitiveAssign; + enum { OBJ_ROOT, ID_ROOT, VAL_ROOT }; + JSXML *xml, *vxml, *rxml, *kid, *attr, *parent, *copy, *kid2, *match; + JSObject *vobj, *nameobj, *attrobj, *parentobj, *kidobj, *copyobj; + JSObject *targetprop, *nameqn, *attrqn; + uint32 index, i, j, k, n, q, matchIndex; + jsval attrval, nsval; + jsid funid; + JSObject *ns; + xml = (JSXML *) GetInstancePrivate(cx, obj, &js_XMLClass, __null); + if (!xml) + return (JSIntn)1; + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + vxml = __null; + if (!JSVAL_IS_PRIMITIVE(*vp)) { + vobj = JSVAL_TO_OBJECT(*vp); + if (vobj->isXML()) + vxml = (JSXML *) vobj->getPrivate(); + } + ok = js_EnterLocalRootScope(cx); + if (!ok) + return (JSIntn)0; + ((void) 0); + jsval roots[3]; + roots[OBJ_ROOT] = OBJECT_TO_JSVAL(obj); + roots[ID_ROOT] = IdToJsval(id); + roots[VAL_ROOT] = *vp; + AutoArrayRooter tvr(cx, (sizeof (roots) / sizeof (roots)[0]), Valueify(roots)); + if (js_IdIsIndex(id, &index)) { + if (xml->xml_class != JSXML_CLASS_LIST) { + ReportBadXMLName(cx, IdToValue(id)); + goto bad; + } + i = index; + if (xml->u.list.target) { + ok = ResolveValue(cx, xml->u.list.target, &rxml); + if (!ok) + goto out; + if (!rxml) + goto out; + ((void) 0); + } else { + rxml = __null; + } + if (index >= xml->u.list.kids.length) { + if (rxml) { + if (rxml->xml_class == JSXML_CLASS_LIST) { + if (rxml->u.list.kids.length != 1) + goto out; + rxml = (((0) < (&rxml->u.list.kids)->length) ? (JSXML *) (&rxml->u.list.kids)->vector[0] : __null); + if (!rxml) + goto out; + ok = js_GetXMLObject(cx, rxml) != __null; + if (!ok) + goto out; + } + if (!(((rxml)->xml_class) < JSXML_CLASS_ATTRIBUTE)) + goto out; + } + targetprop = xml->u.list.targetprop; + if (!targetprop || ((targetprop->getQNameLocalName())->length() == 1 && *(targetprop->getQNameLocalName())->chars() == '*')) { + kid = js_NewXML(cx, JSXML_CLASS_TEXT); + if (!kid) + goto bad; + } else { + nameobj = targetprop; + if (nameobj->getClass() == &js_AttributeNameClass) { + ok = GetProperty(cx, rxml->object, id, &attrval); + if (!ok) + goto out; + if (JSVAL_IS_PRIMITIVE(attrval)) + goto out; + attrobj = JSVAL_TO_OBJECT(attrval); + attr = (JSXML *) attrobj->getPrivate(); + if (((((attr)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (attr)->u.list.kids.length : 0) != 0) + goto out; + kid = js_NewXML(cx, JSXML_CLASS_ATTRIBUTE); + } else { + kid = js_NewXML(cx, JSXML_CLASS_ELEMENT); + } + if (!kid) + goto bad; + kid->name = targetprop; + } + kid->parent = rxml; + i = xml->u.list.kids.length; + if (kid->xml_class != JSXML_CLASS_ATTRIBUTE) { + if (rxml) { + ((void) 0); + n = rxml->u.list.kids.length; + j = n - 1; + if (n != 0 && i != 0) { + for (n = j, j = 0; j < n; j++) { + if (rxml->u.list.kids.vector[j] == + xml->u.list.kids.vector[i-1]) { + break; + } + } + } + kidobj = js_GetXMLObject(cx, kid); + if (!kidobj) + goto bad; + ok = Insert(cx, rxml, j + 1, OBJECT_TO_JSVAL(kidobj)); + if (!ok) + goto out; + } + if (vxml) { + kid->name = (vxml->xml_class == JSXML_CLASS_LIST) + ? vxml->u.list.targetprop + : vxml->name; + } + } + ok = Append(cx, xml, kid); + if (!ok) + goto out; + } + if (!vxml || + vxml->xml_class == JSXML_CLASS_TEXT || + vxml->xml_class == JSXML_CLASS_ATTRIBUTE) { + ok = JS_ConvertValue(cx, *vp, JSTYPE_STRING, vp); + if (!ok) + goto out; + roots[VAL_ROOT] = *vp; + } + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (!kid) + goto out; + parent = kid->parent; + if (kid->xml_class == JSXML_CLASS_ATTRIBUTE) { + nameobj = kid->name; + if (nameobj->getClass() != &js_AttributeNameClass) { + nameobj = NewXMLAttributeName(cx, nameobj->getNameURI(), nameobj->getNamePrefix(), + nameobj->getQNameLocalName()); + if (!nameobj) + goto bad; + } + id = OBJECT_TO_JSID(nameobj); + if (parent) { + parentobj = js_GetXMLObject(cx, parent); + if (!parentobj) + goto bad; + ok = PutProperty(cx, parentobj, id, strict, vp); + if (!ok) + goto out; + ok = GetProperty(cx, parentobj, id, vp); + if (!ok) + goto out; + attr = (JSXML *) JSVAL_TO_OBJECT(*vp)->getPrivate(); + if (attr->u.list.kids.length != 0) + xml->u.list.kids.vector[i] = attr->u.list.kids.vector[0]; + } + } + else if (vxml && vxml->xml_class == JSXML_CLASS_LIST) { + copy = DeepCopyInLRS(cx, vxml, 0); + if (!copy) + goto bad; + copyobj = js_GetXMLObject(cx, copy); + if (!copyobj) + goto bad; + ((void) 0); + if (parent) { + q = XMLArrayFindMember(&parent->u.list.kids, (void *)(kid), __null); + ((void) 0); + ok = Replace(cx, parent, q, OBJECT_TO_JSVAL(copyobj)); + if (!ok) + goto out; + } + n = copy->u.list.kids.length; + if (n == 0) { + XMLArrayDelete(cx, &xml->u.list.kids, i, (JSIntn)1); + } else { + ok = XMLArrayInsert(cx, &xml->u.list.kids, i + 1, n - 1); + if (!ok) + goto out; + for (j = 0; j < n; j++) + xml->u.list.kids.vector[i + j] = copy->u.list.kids.vector[j]; + } + } + else if (vxml || (((kid)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) { + if (parent) { + q = XMLArrayFindMember(&parent->u.list.kids, (void *)(kid), __null); + ((void) 0); + ok = Replace(cx, parent, q, *vp); + if (!ok) + goto out; + vxml = (((q) < (&parent->u.list.kids)->length) ? (JSXML *) (&parent->u.list.kids)->vector[q] : __null); + if (!vxml) + goto out; + roots[VAL_ROOT] = *vp = OBJECT_TO_JSVAL(vxml->object); + } + if (!vxml) { + ((void) 0); + vobj = ToXML(cx, *vp); + if (!vobj) + goto bad; + roots[VAL_ROOT] = *vp = OBJECT_TO_JSVAL(vobj); + vxml = (JSXML *) vobj->getPrivate(); + } + 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); + } + else { + kidobj = js_GetXMLObject(cx, kid); + if (!kidobj) + goto bad; + id = ATOM_TO_JSID(cx->runtime->atomState.starAtom); + ok = PutProperty(cx, kidobj, id, strict, vp); + if (!ok) + goto out; + } + } else { + nameqn = ToXMLName(cx, IdToJsval(id), &funid); + if (!nameqn) + goto bad; + if (!JSID_IS_VOID(funid)) { + ok = js_SetProperty(cx, obj, funid, Valueify(vp), false); + goto out; + } + nameobj = nameqn; + roots[ID_ROOT] = OBJECT_TO_JSVAL(nameobj); + if (xml->xml_class == JSXML_CLASS_LIST) { + n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); + if (n > 1) + goto type_error; + if (n == 0) { + ok = ResolveValue(cx, xml, &rxml); + if (!ok) + goto out; + if (!rxml || ((((rxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (rxml)->u.list.kids.length : 0) != 1) + goto type_error; + ok = Append(cx, xml, rxml); + if (!ok) + goto out; + } + ((void) 0); + xml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null); + if (!xml) + goto out; + ((void) 0); + obj = js_GetXMLObject(cx, xml); + if (!obj) + goto bad; + roots[OBJ_ROOT] = OBJECT_TO_JSVAL(obj); + } + if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) + goto out; + if (!vxml || + vxml->xml_class == JSXML_CLASS_TEXT || + vxml->xml_class == JSXML_CLASS_ATTRIBUTE) { + ok = JS_ConvertValue(cx, *vp, JSTYPE_STRING, vp); + if (!ok) + goto out; + } else { + rxml = DeepCopyInLRS(cx, vxml, 0); + if (!rxml || !js_GetXMLObject(cx, rxml)) + goto bad; + vxml = rxml; + *vp = OBJECT_TO_JSVAL(vxml->object); + } + roots[VAL_ROOT] = *vp; + ok = js_GetDefaultXMLNamespace(cx, &nsval); + if (!ok) + goto out; + if (nameobj->getClass() == &js_AttributeNameClass) { + if (!js_IsXMLName(cx, OBJECT_TO_JSVAL(nameobj))) + goto out; + if (vxml && vxml->xml_class == JSXML_CLASS_LIST) { + n = vxml->u.list.kids.length; + if (n == 0) { + *vp = STRING_TO_JSVAL(cx->runtime->emptyString); + } else { + JSString *left = KidToString(cx, vxml, 0); + if (!left) + goto bad; + JSString *space = cx->runtime->atomState.spaceAtom; + for (i = 1; i < n; i++) { + left = js_ConcatStrings(cx, left, space); + if (!left) + goto bad; + JSString *right = KidToString(cx, vxml, i); + if (!right) + goto bad; + left = js_ConcatStrings(cx, left, right); + if (!left) + goto bad; + } + roots[VAL_ROOT] = *vp = STRING_TO_JSVAL(left); + } + } else { + ok = JS_ConvertValue(cx, *vp, JSTYPE_STRING, vp); + if (!ok) + goto out; + roots[VAL_ROOT] = *vp; + } + match = __null; + for (i = 0, n = xml->u.elem.attrs.length; i < n; i++) { + attr = (((i) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[i] : __null); + if (!attr) + continue; + attrqn = attr->name; + if (EqualStrings(attrqn->getQNameLocalName(), nameqn->getQNameLocalName())) { + JSLinearString *uri = nameqn->getNameURI(); + if (!uri || EqualStrings(attrqn->getNameURI(), uri)) { + if (!match) { + match = attr; + } else { + DeleteNamedProperty(cx, xml, attrqn, (JSIntn)1); + --i; + } + } + } + } + attr = match; + if (!attr) { + JSLinearString *uri = nameqn->getNameURI(); + JSLinearString *left, *right; + if (!uri) { + left = right = cx->runtime->emptyString; + } else { + left = uri; + right = nameqn->getNamePrefix(); + } + nameqn = NewXMLQName(cx, left, right, nameqn->getQNameLocalName()); + if (!nameqn) + goto bad; + attr = js_NewXML(cx, JSXML_CLASS_ATTRIBUTE); + if (!attr) + goto bad; + attr->parent = xml; + attr->name = nameqn; + ok = XMLArrayAddMember(cx, &xml->u.elem.attrs, n, (void *)(attr)); + if (!ok) + goto out; + ns = GetNamespace(cx, nameqn, __null); + if (!ns) + goto bad; + ok = AddInScopeNamespace(cx, xml, ns); + if (!ok) + goto out; + } + attr->u.value = JSVAL_TO_STRING(*vp); + goto out; + } + if (!js_IsXMLName(cx, OBJECT_TO_JSVAL(nameobj)) && + !((nameqn->getQNameLocalName())->length() == 1 && *(nameqn->getQNameLocalName())->chars() == '*')) { + goto out; + } + id = ((jsid)0x2); + primitiveAssign = !vxml && !((nameqn->getQNameLocalName())->length() == 1 && *(nameqn->getQNameLocalName())->chars() == '*'); + k = n = xml->u.list.kids.length; + matchIndex = ((uint32) -1); + kid2 = __null; + while (k != 0) { + --k; + kid = (((k) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[k] : __null); + if (kid && MatchElemName(nameqn, kid)) { + if (matchIndex != ((uint32) -1)) + DeleteByIndex(cx, xml, matchIndex); + matchIndex = k; + kid2 = kid; + } + } + if (kid2) { + ((void) 0); + if (!kid2->parent) + kid2->parent = xml; + } + if (matchIndex == ((uint32) -1)) { + matchIndex = n; + if (primitiveAssign) { + JSLinearString *uri = nameqn->getNameURI(); + JSLinearString *left, *right; + if (!uri) { + ns = JSVAL_TO_OBJECT(nsval); + left = ns->getNameURI(); + right = ns->getNamePrefix(); + } else { + left = uri; + right = nameqn->getNamePrefix(); + } + nameqn = NewXMLQName(cx, left, right, nameqn->getQNameLocalName()); + if (!nameqn) + goto bad; + vobj = js_NewXMLObject(cx, JSXML_CLASS_ELEMENT); + if (!vobj) + goto bad; + vxml = (JSXML *) vobj->getPrivate(); + vxml->parent = xml; + vxml->name = nameqn; + ns = GetNamespace(cx, nameqn, __null); + if (!ns) + goto bad; + ok = Replace(cx, xml, matchIndex, OBJECT_TO_JSVAL(vobj)); + if (!ok) + goto out; + ok = AddInScopeNamespace(cx, vxml, ns); + if (!ok) + goto out; + } + } + if (primitiveAssign) { + JSXMLArrayCursor cursor(&xml->u.list.kids); + cursor.index = matchIndex; + kid = (JSXML *) cursor.getCurrent(); + if ((((kid)->xml_class) < JSXML_CLASS_ATTRIBUTE)) { + kid->u.list.kids.finish(cx); + kid->u.list.kids.init(); + ok = kid->u.list.kids.setCapacity(cx, 1); + } + if (ok) { + ok = JS_ConvertValue(cx, *vp, JSTYPE_STRING, vp); + if (ok && !JSVAL_TO_STRING(*vp)->empty()) { + roots[VAL_ROOT] = *vp; + if ((JSXML *) cursor.getCurrent() == kid) + ok = Replace(cx, kid, 0, *vp); + } + } + } else { + ok = Replace(cx, xml, matchIndex, *vp); + } + } +out: + js_LeaveLocalRootScope(cx); + return ok; +type_error: + { + JSAutoByteString bytes; + if (js_ValueToPrintable(cx, IdToValue(id), &bytes)) + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_BAD_XMLLIST_PUT, bytes.ptr()); + } +bad: + ok = (JSIntn)0; + goto out; +} +static JSBool +ResolveValue(JSContext *cx, JSXML *list, JSXML **result) +{ + JSXML *target, *base; + JSObject *targetprop; + jsid id; + jsval tv; + if (list->xml_class != JSXML_CLASS_LIST || list->u.list.kids.length != 0) { + if (!js_GetXMLObject(cx, list)) + return (JSIntn)0; + *result = list; + return (JSIntn)1; + } + target = list->u.list.target; + targetprop = list->u.list.targetprop; + if (!target || !targetprop || ((targetprop->getQNameLocalName())->length() == 1 && *(targetprop->getQNameLocalName())->chars() == '*')) { + *result = __null; + return (JSIntn)1; + } + if (targetprop->getClass() == &js_AttributeNameClass) { + *result = __null; + return (JSIntn)1; + } + if (!ResolveValue(cx, target, &base)) + return (JSIntn)0; + if (!base) { + *result = __null; + return (JSIntn)1; + } + if (!js_GetXMLObject(cx, base)) + return (JSIntn)0; + id = OBJECT_TO_JSID(targetprop); + if (!GetProperty(cx, base->object, id, &tv)) + return (JSIntn)0; + target = (JSXML *) JSVAL_TO_OBJECT(tv)->getPrivate(); + if (((((target)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (target)->u.list.kids.length : 0) == 0) { + if (base->xml_class == JSXML_CLASS_LIST && ((((base)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (base)->u.list.kids.length : 0) > 1) { + *result = __null; + return (JSIntn)1; + } + tv = STRING_TO_JSVAL(cx->runtime->emptyString); + if (!PutProperty(cx, base->object, id, false, &tv)) + return (JSIntn)0; + if (!GetProperty(cx, base->object, id, &tv)) + return (JSIntn)0; + target = (JSXML *) JSVAL_TO_OBJECT(tv)->getPrivate(); + } + *result = target; + return (JSIntn)1; +} +static JSBool +HasNamedProperty(JSXML *xml, JSObject *nameqn) +{ + JSBool found; + JSXMLArray *array; + JSXMLNameMatcher matcher; + uint32 i, n; + if (xml->xml_class == JSXML_CLASS_LIST) { + found = (JSIntn)0; + JSXMLArrayCursor cursor(&xml->u.list.kids); + while (JSXML *kid = (JSXML *) cursor.getNext()) { + found = HasNamedProperty(kid, nameqn); + if (found) + break; + } + return found; + } + if (xml->xml_class == JSXML_CLASS_ELEMENT) { + if (nameqn->getClass() == &js_AttributeNameClass) { + array = &xml->u.elem.attrs; + matcher = MatchAttrName; + } else { + array = &xml->u.list.kids; + matcher = MatchElemName; + } + for (i = 0, n = array->length; i < n; i++) { + JSXML *kid = (((i) < (array)->length) ? (JSXML *) (array)->vector[i] : __null); + if (kid && matcher(nameqn, kid)) + return (JSIntn)1; + } + } + return (JSIntn)0; +} +static JSBool +HasIndexedProperty(JSXML *xml, uint32 i) +{ + if (xml->xml_class == JSXML_CLASS_LIST) + return i < ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); + if (xml->xml_class == JSXML_CLASS_ELEMENT) + return i == 0; + return (JSIntn)0; +} +static JSBool +HasSimpleContent(JSXML *xml); +static JSBool +HasFunctionProperty(JSContext *cx, JSObject *obj, jsid funid, JSBool *found) +{ + JSObject *pobj; + JSProperty *prop; + JSXML *xml; + ((void) 0); + if (!js_LookupProperty(cx, obj, funid, &pobj, &prop)) + return false; + if (!prop) { + xml = (JSXML *) obj->getPrivate(); + if (HasSimpleContent(xml)) { + AutoObjectRooter tvr(cx); + if (!js_GetClassPrototype(cx, __null, JSProto_String, tvr.addr())) + return false; + ((void) 0); + if (!js_LookupProperty(cx, tvr.object(), funid, &pobj, &prop)) + return false; + } + } + *found = (prop != __null); + return true; +} +static JSBool +HasProperty(JSContext *cx, JSObject *obj, jsval id, JSBool *found) +{ + JSXML *xml; + bool isIndex; + uint32 i; + JSObject *qn; + jsid funid; + xml = (JSXML *) obj->getPrivate(); + if (!js_IdValIsIndex(cx, id, &i, &isIndex)) + return (JSIntn)0; + if (isIndex) { + *found = HasIndexedProperty(xml, i); + } else { + qn = ToXMLName(cx, id, &funid); + if (!qn) + return (JSIntn)0; + if (!JSID_IS_VOID(funid)) { + if (!HasFunctionProperty(cx, obj, funid, found)) + return (JSIntn)0; + } else { + *found = HasNamedProperty(xml, qn); + } + } + return (JSIntn)1; +} +static void +xml_finalize(JSContext *cx, JSObject *obj) +{ + JSXML *xml = (JSXML *) obj->getPrivate(); + if (!xml) + return; + if (xml->object == obj) + xml->object = __null; +} +static void +xml_trace_vector(JSTracer *trc, JSXML **vec, uint32 len) +{ + uint32 i; + JSXML *xml; + for (i = 0; i < len; i++) { + xml = vec[i]; + if (xml) { + do { } while (0); + Mark(trc, xml); + } + } +} +static JSBool +xml_lookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, + JSProperty **propp) +{ + JSBool found; + JSXML *xml; + uint32 i; + JSObject *qn; + jsid funid; + xml = (JSXML *) obj->getPrivate(); + if (js_IdIsIndex(id, &i)) { + found = HasIndexedProperty(xml, i); + } else { + qn = ToXMLName(cx, IdToJsval(id), &funid); + if (!qn) + return (JSIntn)0; + if (!JSID_IS_VOID(funid)) + return js_LookupProperty(cx, obj, funid, objp, propp); + found = HasNamedProperty(xml, qn); + } + if (!found) { + *objp = __null; + *propp = __null; + } else { + const Shape *shape = + js_AddNativeProperty(cx, obj, id, + Valueify(GetProperty), Valueify(PutProperty), + 0xffffffff, 0x01, + 0, 0); + if (!shape) + return (JSIntn)0; + *objp = obj; + *propp = (JSProperty *) shape; + } + return (JSIntn)1; +} +static JSBool +xml_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *v, + PropertyOp getter, StrictPropertyOp setter, uintN attrs) +{ + if (IsFunctionObject(*v) || getter || setter || + (attrs & 0x01) == 0 || + (attrs & (0x02 | 0x04 | 0x40))) { + return js_DefineProperty(cx, obj, id, v, getter, setter, attrs); + } + jsval tmp = Jsvalify(*v); + return PutProperty(cx, obj, id, false, &tmp); +} +static JSBool +xml_getProperty(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, Value *vp) +{ + if (JSID_IS_DEFAULT_XML_NAMESPACE(id)) { + vp->setUndefined(); + return (JSIntn)1; + } + return GetProperty(cx, obj, id, Jsvalify(vp)); +} +static JSBool +xml_setProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp, JSBool strict) +{ + return PutProperty(cx, obj, id, strict, Jsvalify(vp)); +} +static JSBool +xml_getAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp) +{ + JSBool found; + if (!HasProperty(cx, obj, IdToJsval(id), &found)) + return false; + *attrsp = found ? 0x01 : 0; + return (JSIntn)1; +} +static JSBool +xml_setAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp) +{ + JSBool found; + if (!HasProperty(cx, obj, IdToJsval(id), &found)) + return false; + if (found) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, + JSMSG_CANT_SET_XML_ATTRS); + return false; + } + return true; +} +static JSBool +xml_deleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool strict) +{ + JSXML *xml; + jsval idval; + uint32 index; + JSObject *nameqn; + jsid funid; + idval = IdToJsval(id); + xml = (JSXML *) obj->getPrivate(); + if (js_IdIsIndex(id, &index)) { + if (xml->xml_class != JSXML_CLASS_LIST) { + ReportBadXMLName(cx, IdToValue(id)); + return false; + } + DeleteListElement(cx, xml, index); + } else { + nameqn = ToXMLName(cx, idval, &funid); + if (!nameqn) + return false; + if (!JSID_IS_VOID(funid)) + return js_DeleteProperty(cx, obj, funid, rval, false); + DeleteNamedProperty(cx, xml, nameqn, + nameqn->getClass() == &js_AttributeNameClass); + } + if (!obj->nativeEmpty() && !js_DeleteProperty(cx, obj, id, rval, false)) + return false; + rval->setBoolean(true); + return true; +} +JSBool +xml_convert(JSContext *cx, JSObject *obj, JSType type, Value *rval) +{ + return js_TryMethod(cx, obj, cx->runtime->atomState.toStringAtom, 0, __null, rval); +} +static JSBool +xml_enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, Value *statep, jsid *idp) +{ + JSXML *xml; + uint32 length, index; + JSXMLArrayCursor *cursor; + xml = (JSXML *)obj->getPrivate(); + length = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); + switch (enum_op) { + case JSENUMERATE_INIT: + case JSENUMERATE_INIT_ALL: + if (length == 0) { + statep->setInt32(0); + } else { + cursor = cx->create(&xml->u.list.kids); + if (!cursor) + return (JSIntn)0; + statep->setPrivate(cursor); + } + if (idp) + *idp = INT_TO_JSID(length); + break; + case JSENUMERATE_NEXT: + if (statep->isInt32(0)) { + statep->setNull(); + break; + } + cursor = (JSXMLArrayCursor *) statep->toPrivate(); + if (cursor && cursor->array && (index = cursor->index) < length) { + *idp = INT_TO_JSID(index); + cursor->index = index + 1; + break; + } + case JSENUMERATE_DESTROY: + if (!statep->isInt32(0)) { + cursor = (JSXMLArrayCursor *) statep->toPrivate(); + if (cursor) + cx->destroy(cursor); + } + statep->setNull(); + break; + } + return (JSIntn)1; +} +static JSType +xml_typeOf(JSContext *cx, JSObject *obj) +{ + return JSTYPE_XML; +} +static JSBool +xml_hasInstance(JSContext *cx, JSObject *obj, const Value *, JSBool *bp) +{ + return (JSIntn)1; +} +static void +xml_trace(JSTracer *trc, JSObject *obj) +{ + JSXML *xml = (JSXML *) obj->getPrivate(); + if (xml) + do { do { } while (0); JS_CallTracer((trc), (xml), (2)); } while (0); +} +static JSBool +xml_fix(JSContext *cx, JSObject *obj, bool *success, AutoIdVector *props) +{ + ((void) 0); + *success = false; + return true; +} +static void +xml_clear(JSContext *cx, JSObject *obj) +{ +} +static JSBool +HasSimpleContent(JSXML *xml) +{ + JSXML *kid; + JSBool simple; + uint32 i, n; +again: + switch (xml->xml_class) { + case JSXML_CLASS_COMMENT: + case JSXML_CLASS_PROCESSING_INSTRUCTION: + return (JSIntn)0; + case JSXML_CLASS_LIST: + if (xml->u.list.kids.length == 0) + return (JSIntn)1; + if (xml->u.list.kids.length == 1) { + kid = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null); + if (kid) { + xml = kid; + goto again; + } + } + default: + simple = (JSIntn)1; + for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) { + simple = (JSIntn)0; + break; + } + } + return simple; + } +} +JSBool +js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, Value *vp) +{ + ((void) 0); + if (JSID_IS_OBJECT(id)) { + jsid funid; + if (!js_IsFunctionQName(cx, JSID_TO_OBJECT(id), &funid)) + return (JSIntn)0; + if (!JSID_IS_VOID(funid)) + id = funid; + } + AutoValueRooter tvr(cx); + JSBool ok = GetXMLFunction(cx, obj, id, Jsvalify(tvr.addr())); + *vp = tvr.value(); + return ok; +} +JSBool +js_TestXMLEquality(JSContext *cx, const Value &v1, const Value &v2, JSBool *bp) +{ + JSXML *xml, *vxml; + JSObject *vobj; + JSBool ok; + JSString *str, *vstr; + jsdouble d, d2; + JSObject *obj; + jsval v; + if (v1.isObject() && v1.toObject().isXML()) { + obj = &v1.toObject(); + v = Jsvalify(v2); + } else { + v = Jsvalify(v1); + obj = &v2.toObject(); + } + ((void) 0); + xml = (JSXML *) obj->getPrivate(); + vxml = __null; + if (!JSVAL_IS_PRIMITIVE(v)) { + vobj = JSVAL_TO_OBJECT(v); + if (vobj->isXML()) + vxml = (JSXML *) vobj->getPrivate(); + } + if (xml->xml_class == JSXML_CLASS_LIST) { + ok = Equals(cx, xml, v, bp); + } else if (vxml) { + if (vxml->xml_class == JSXML_CLASS_LIST) { + ok = Equals(cx, vxml, OBJECT_TO_JSVAL(obj), bp); + } else { + if (((xml->xml_class == JSXML_CLASS_TEXT || + xml->xml_class == JSXML_CLASS_ATTRIBUTE) && + HasSimpleContent(vxml)) || + ((vxml->xml_class == JSXML_CLASS_TEXT || + vxml->xml_class == JSXML_CLASS_ATTRIBUTE) && + HasSimpleContent(xml))) { + ok = js_EnterLocalRootScope(cx); + if (ok) { + ok = (str = js_ValueToString(cx, ObjectValue(*obj))) && + (vstr = js_ValueToString(cx, Valueify(v))); + if (ok) + ok = EqualStrings(cx, str, vstr, bp); + js_LeaveLocalRootScope(cx); + } + } else { + ok = XMLEquals(cx, xml, vxml, bp); + } + } + } else { + ok = js_EnterLocalRootScope(cx); + if (ok) { + if (HasSimpleContent(xml)) { + ok = (str = js_ValueToString(cx, ObjectValue(*obj))) && + (vstr = js_ValueToString(cx, Valueify(v))); + if (ok) + ok = EqualStrings(cx, str, vstr, bp); + } else if (JSVAL_IS_STRING(v) || JSVAL_IS_NUMBER(v)) { + str = js_ValueToString(cx, ObjectValue(*obj)); + if (!str) { + ok = (JSIntn)0; + } else if (JSVAL_IS_STRING(v)) { + ok = EqualStrings(cx, str, JSVAL_TO_STRING(v), bp); + } else { + ok = JS_ValueToNumber(cx, STRING_TO_JSVAL(str), &d); + if (ok) { + d2 = JSVAL_IS_INT(v) ? JSVAL_TO_INT(v) + : JSVAL_TO_DOUBLE(v); + *bp = ((d) == (d2)); + } + } + } else { + *bp = (JSIntn)0; + } + js_LeaveLocalRootScope(cx); + } + } + return ok; +} +JSBool +js_ConcatenateXML(JSContext *cx, JSObject *obj, JSObject *robj, Value *vp) +{ + JSBool ok; + JSObject *listobj; + JSXML *list, *lxml, *rxml; + ((void) 0); + ok = js_EnterLocalRootScope(cx); + if (!ok) + return (JSIntn)0; + listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST); + if (!listobj) { + ok = (JSIntn)0; + goto out; + } + list = (JSXML *) listobj->getPrivate(); + lxml = (JSXML *) obj->getPrivate(); + ok = Append(cx, list, lxml); + if (!ok) + goto out; + ((void) 0); + rxml = (JSXML *) robj->getPrivate(); + ok = Append(cx, list, rxml); + if (!ok) + goto out; + vp->setObject(*listobj); +out: + js_LeaveLocalRootScopeWithResult(cx, *vp); + return ok; +} +__attribute__((visibility ("default"))) Class js_XMLClass = { + js_XML_str, + (1<<0) | (1<<((8 + 8)+3)) | + ((JSProto_XML) << ((8 + 8) + 8)), + PropertyStub, + PropertyStub, + PropertyStub, + StrictPropertyStub, + EnumerateStub, + ResolveStub, + xml_convert, + xml_finalize, + __null, + __null, + __null, + __null, + __null, + xml_hasInstance, + ((JSMarkOp)(xml_trace)), + {__null,__null,__null,__null,__null}, + { + xml_lookupProperty, + xml_defineProperty, + xml_getProperty, + xml_setProperty, + xml_getAttributes, + xml_setAttributes, + xml_deleteProperty, + xml_enumerate, + xml_typeOf, + __null, + xml_fix, + __null, + xml_clear + } +}; +static JSXML * +StartNonListXMLMethod(JSContext *cx, jsval *vp, JSObject **objp) +{ + JSXML *xml; + JSFunction *fun; + char numBuf[12]; + ((void) 0); + *objp = ToObject(cx, Valueify(&vp[1])); + if (!*objp) + return __null; + xml = (JSXML *) GetInstancePrivate(cx, *objp, &js_XMLClass, Valueify(vp + 2)); + if (!xml || xml->xml_class != JSXML_CLASS_LIST) + return xml; + if (xml->u.list.kids.length == 1) { + xml = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null); + if (xml) { + *objp = js_GetXMLObject(cx, xml); + if (!*objp) + return __null; + vp[1] = OBJECT_TO_JSVAL(*objp); + return xml; + } + } + fun = (((void) 0), (JSFunction *) (JSVAL_TO_OBJECT(*vp))->getPrivate()); + JS_snprintf(numBuf, sizeof numBuf, "%u", xml->u.list.kids.length); + JSAutoByteString funNameBytes; + if (const char *funName = GetFunctionNameBytes(cx, fun, &funNameBytes)) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, JSMSG_NON_LIST_XML_METHOD, + funName, numBuf); + } + return __null; +} +static JSBool +xml_addNamespace(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *ns; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + if (xml->xml_class != JSXML_CLASS_ELEMENT) + goto done; + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + if (!NamespaceHelper(cx, __null, argc == 0 ? -1 : 1, vp + 2, vp)) + return (JSIntn)0; + ((void) 0); + ns = JSVAL_TO_OBJECT(*vp); + if (!AddInScopeNamespace(cx, xml, ns)) + return (JSIntn)0; + ns->setNamespaceDeclared(((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1))); + done: + *vp = OBJECT_TO_JSVAL(obj); + return (JSIntn)1; +} +static JSBool +xml_appendChild(JSContext *cx, uintN argc, jsval *vp) +{ + jsval v; + JSObject *vobj; + JSXML *vxml; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + jsid name; + if (!js_GetAnyName(cx, &name)) + return (JSIntn)0; + if (!GetProperty(cx, obj, name, &v)) + return (JSIntn)0; + ((void) 0); + vobj = JSVAL_TO_OBJECT(v); + ((void) 0); + vxml = (JSXML *) vobj->getPrivate(); + ((void) 0); + if (!IndexToId(cx, vxml->u.list.kids.length, &name)) + return (JSIntn)0; + *vp = (argc != 0) ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + if (!PutProperty(cx, JSVAL_TO_OBJECT(v), name, false, vp)) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(obj); + return (JSIntn)1; +} +static JSBool +xml_attribute(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *qn; + if (argc == 0) { + js_ReportMissingArg(cx, Valueify(*vp), 0); + return (JSIntn)0; + } + qn = ToAttributeName(cx, vp[2]); + if (!qn) + return (JSIntn)0; + vp[2] = OBJECT_TO_JSVAL(qn); + jsid id = OBJECT_TO_JSID(qn); + JSObject *obj = ToObject(cx, Valueify(&vp[1])); + if (!obj) + return (JSIntn)0; + return GetProperty(cx, obj, id, vp); +} +static JSBool +xml_attributes(JSContext *cx, uintN argc, jsval *vp) +{ + jsval name = STRING_TO_JSVAL((cx->runtime->atomState.starAtom)); + JSObject *qn = ToAttributeName(cx, name); + if (!qn) + return (JSIntn)0; + AutoObjectRooter tvr(cx, qn); + jsid id = OBJECT_TO_JSID(qn); + JSObject *obj = ToObject(cx, Valueify(&vp[1])); + if (!obj) + return (JSIntn)0; + return GetProperty(cx, obj, id, vp); +} +static JSXML * +xml_list_helper(JSContext *cx, JSXML *xml, jsval *rval) +{ + JSObject *listobj; + JSXML *list; + listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST); + if (!listobj) + return __null; + *rval = OBJECT_TO_JSVAL(listobj); + list = (JSXML *) listobj->getPrivate(); + list->u.list.target = xml; + return list; +} +static JSBool +ValueToId(JSContext *cx, jsval v, AutoIdRooter *idr) +{ + if (JSVAL_IS_INT(v)) { + jsint i = JSVAL_TO_INT(v); + if (INT_FITS_IN_JSID(i)) + *idr->addr() = INT_TO_JSID(i); + else if (!js_ValueToStringId(cx, Valueify(v), idr->addr())) + return (JSIntn)0; + } else if (JSVAL_IS_STRING(v)) { + JSAtom *atom = js_AtomizeString(cx, JSVAL_TO_STRING(v), 0); + if (!atom) + return (JSIntn)0; + *idr->addr() = ATOM_TO_JSID(atom); + } else if (!JSVAL_IS_PRIMITIVE(v)) { + *idr->addr() = OBJECT_TO_JSID(JSVAL_TO_OBJECT(v)); + } else { + ReportBadXMLName(cx, Valueify(v)); + return (JSIntn)0; + } + return (JSIntn)1; +} +static JSBool +xml_child_helper(JSContext *cx, JSObject *obj, JSXML *xml, jsval name, + jsval *rval) +{ + bool isIndex; + uint32 index; + JSXML *kid; + JSObject *kidobj; + ((void) 0); + if (!js_IdValIsIndex(cx, name, &index, &isIndex)) + return (JSIntn)0; + if (isIndex) { + if (index >= ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0)) { + *rval = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + } else { + kid = (((index) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[index] : __null); + if (!kid) { + *rval = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + } else { + kidobj = js_GetXMLObject(cx, kid); + if (!kidobj) + return (JSIntn)0; + *rval = OBJECT_TO_JSVAL(kidobj); + } + } + return (JSIntn)1; + } + AutoIdRooter idr(cx); + if (!ValueToId(cx, name, &idr)) + return (JSIntn)0; + return GetProperty(cx, obj, idr.id(), rval); +} +static JSBool +xml_child(JSContext *cx, uintN argc, jsval *vp) +{ + jsval v; + JSXML *list, *vxml; + JSObject *kidobj; + 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; + jsval name = argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + if (xml->xml_class == JSXML_CLASS_LIST) { + list = xml_list_helper(cx, xml, vp); + if (!list) + return (JSIntn)0; + JSXMLArrayCursor cursor(&xml->u.list.kids); + while (JSXML *kid = (JSXML *) cursor.getNext()) { + kidobj = js_GetXMLObject(cx, kid); + if (!kidobj) + return (JSIntn)0; + if (!xml_child_helper(cx, kidobj, kid, name, &v)) + return (JSIntn)0; + if (JSVAL_IS_VOID(v)) { + continue; + } + ((void) 0); + vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate(); + if ((!(((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) || vxml->u.list.kids.length != 0) && + !Append(cx, list, vxml)) { + return (JSIntn)0; + } + } + return (JSIntn)1; + } + if (!xml_child_helper(cx, obj, xml, name, vp)) + return (JSIntn)0; + if (JSVAL_IS_VOID(*vp) && !xml_list_helper(cx, xml, vp)) + return (JSIntn)0; + return (JSIntn)1; +} +static JSBool +xml_childIndex(JSContext *cx, uintN argc, jsval *vp) +{ + JSXML *parent; + uint32 i, n; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + parent = xml->parent; + if (!parent || xml->xml_class == JSXML_CLASS_ATTRIBUTE) { + *vp = DOUBLE_TO_JSVAL(js_NaN); + return (JSIntn)1; + } + for (i = 0, n = ((((parent)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (parent)->u.list.kids.length : 0); i < n; i++) { + if ((((i) < (&parent->u.list.kids)->length) ? (JSXML *) (&parent->u.list.kids)->vector[i] : __null) == xml) + break; + } + ((void) 0); + if (i <= ((jsint)0x7fffffff)) + *vp = INT_TO_JSVAL(i); + else + *vp = DOUBLE_TO_JSVAL(i); + return (JSIntn)1; +} +static JSBool +xml_children(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj = ToObject(cx, Valueify(&vp[1])); + if (!obj) + return false; + jsid name = ATOM_TO_JSID(cx->runtime->atomState.starAtom); + return GetProperty(cx, obj, name, vp); +} +static JSBool +xml_comments_helper(JSContext *cx, JSObject *obj, JSXML *xml, jsval *vp) +{ + JSXML *list, *kid, *vxml; + JSBool ok; + uint32 i, n; + JSObject *kidobj; + jsval v; + list = xml_list_helper(cx, xml, vp); + if (!list) + return (JSIntn)0; + ok = (JSIntn)1; + if (xml->xml_class == JSXML_CLASS_LIST) { + for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) { + ok = js_EnterLocalRootScope(cx); + if (!ok) + break; + kidobj = js_GetXMLObject(cx, kid); + if (kidobj) { + ok = xml_comments_helper(cx, kidobj, kid, &v); + } else { + ok = (JSIntn)0; + v = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); + } + js_LeaveLocalRootScopeWithResult(cx, Valueify(v)); + if (!ok) + break; + vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate(); + if (((((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (vxml)->u.list.kids.length : 0) != 0) { + ok = Append(cx, list, vxml); + if (!ok) + break; + } + } + } + } else { + for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_COMMENT) { + ok = Append(cx, list, kid); + if (!ok) + break; + } + } + } + return ok; +} +static JSBool +xml_comments(JSContext *cx, uintN argc, jsval *vp) +{ + 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; + return xml_comments_helper(cx, obj, xml, vp); +} +static JSBool +xml_contains(JSContext *cx, uintN argc, jsval *vp) +{ + jsval value; + JSBool eq; + JSObject *kidobj; + 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; + value = argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + if (xml->xml_class == JSXML_CLASS_LIST) { + eq = (JSIntn)0; + JSXMLArrayCursor cursor(&xml->u.list.kids); + while (JSXML *kid = (JSXML *) cursor.getNext()) { + kidobj = js_GetXMLObject(cx, kid); + if (!kidobj || !js_TestXMLEquality(cx, ObjectValue(*kidobj), Valueify(value), &eq)) + return (JSIntn)0; + if (eq) + break; + } + } else { + if (!js_TestXMLEquality(cx, ObjectValue(*obj), Valueify(value), &eq)) + return (JSIntn)0; + } + *vp = BOOLEAN_TO_JSVAL(eq); + return (JSIntn)1; +} +static JSBool +xml_copy(JSContext *cx, uintN argc, jsval *vp) +{ + JSXML *copy; + 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; + copy = DeepCopy(cx, xml, __null, 0); + if (!copy) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(copy->object); + return (JSIntn)1; +} +static JSBool +xml_descendants(JSContext *cx, uintN argc, jsval *vp) +{ + jsval name; + JSXML *list; + 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; + name = argc == 0 ? STRING_TO_JSVAL((cx->runtime->atomState.starAtom)) : vp[2]; + list = Descendants(cx, xml, name); + if (!list) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(list->object); + return (JSIntn)1; +} +static JSBool +xml_elements_helper(JSContext *cx, JSObject *obj, JSXML *xml, + JSObject *nameqn, jsval *vp) +{ + JSXML *list, *vxml; + jsval v; + JSBool ok; + JSObject *kidobj; + uint32 i, n; + list = xml_list_helper(cx, xml, vp); + if (!list) + return (JSIntn)0; + list->u.list.targetprop = nameqn; + ok = (JSIntn)1; + if (xml->xml_class == JSXML_CLASS_LIST) { + JSXMLArrayCursor cursor(&xml->u.list.kids); + while (JSXML *kid = (JSXML *) cursor.getNext()) { + if (kid->xml_class == JSXML_CLASS_ELEMENT) { + ok = js_EnterLocalRootScope(cx); + if (!ok) + break; + kidobj = js_GetXMLObject(cx, kid); + if (kidobj) { + ok = xml_elements_helper(cx, kidobj, kid, nameqn, &v); + } else { + ok = (JSIntn)0; + v = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); + } + js_LeaveLocalRootScopeWithResult(cx, Valueify(v)); + if (!ok) + break; + vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate(); + if (((((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (vxml)->u.list.kids.length : 0) != 0) { + ok = Append(cx, list, vxml); + if (!ok) + break; + } + } + } + } else { + for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) { + JSXML *kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_ELEMENT && + MatchElemName(nameqn, kid)) { + ok = Append(cx, list, kid); + if (!ok) + break; + } + } + } + return ok; +} +static JSBool +xml_elements(JSContext *cx, uintN argc, jsval *vp) +{ + jsval name; + JSObject *nameqn; + jsid funid; + 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; + name = (argc == 0) ? STRING_TO_JSVAL((cx->runtime->atomState.starAtom)) : vp[2]; + nameqn = ToXMLName(cx, name, &funid); + if (!nameqn) + return (JSIntn)0; + if (!JSID_IS_VOID(funid)) + return xml_list_helper(cx, xml, vp) != __null; + return xml_elements_helper(cx, obj, xml, nameqn, vp); +} +static JSBool +xml_hasOwnProperty(JSContext *cx, uintN argc, jsval *vp) +{ + jsval name; + JSBool found; + JSObject *obj = ToObject(cx, Valueify(&vp[1])); + if (!obj) + return (JSIntn)0; + if (!InstanceOf(cx, obj, &js_XMLClass, Valueify(vp + 2))) + return (JSIntn)0; + name = argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + if (!HasProperty(cx, obj, name, &found)) + return (JSIntn)0; + if (found) { + *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1)); + return (JSIntn)1; + } + return js_HasOwnPropertyHelper(cx, js_LookupProperty, argc, Valueify(vp)); +} +static JSBool +xml_hasComplexContent(JSContext *cx, uintN argc, jsval *vp) +{ + JSXML *kid; + JSObject *kidobj; + uint32 i, n; + 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; +again: + switch (xml->xml_class) { + case JSXML_CLASS_ATTRIBUTE: + case JSXML_CLASS_COMMENT: + case JSXML_CLASS_PROCESSING_INSTRUCTION: + case JSXML_CLASS_TEXT: + *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)0)); + break; + case JSXML_CLASS_LIST: + if (xml->u.list.kids.length == 0) { + *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1)); + } else if (xml->u.list.kids.length == 1) { + kid = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null); + if (kid) { + kidobj = js_GetXMLObject(cx, kid); + if (!kidobj) + return (JSIntn)0; + obj = kidobj; + xml = (JSXML *) obj->getPrivate(); + goto again; + } + } + default: + *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)0)); + for (i = 0, n = xml->u.list.kids.length; i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) { + *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1)); + break; + } + } + break; + } + return (JSIntn)1; +} +static JSBool +xml_hasSimpleContent(JSContext *cx, uintN argc, jsval *vp) +{ + 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; + *vp = BOOLEAN_TO_JSVAL(HasSimpleContent(xml)); + return (JSIntn)1; +} +static JSBool +FindInScopeNamespaces(JSContext *cx, JSXML *xml, JSXMLArray *nsarray) +{ + uint32 length, i, j, n; + JSObject *ns, *ns2; + JSLinearString *prefix, *prefix2; + length = nsarray->length; + do { + if (xml->xml_class != JSXML_CLASS_ELEMENT) + continue; + for (i = 0, n = xml->u.elem.namespaces.length; i < n; i++) { + ns = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null); + if (!ns) + continue; + prefix = ns->getNamePrefix(); + for (j = 0; j < length; j++) { + ns2 = (((j) < (nsarray)->length) ? (JSObject *) (nsarray)->vector[j] : __null); + if (ns2) { + prefix2 = ns2->getNamePrefix(); + if ((prefix2 && prefix) + ? EqualStrings(prefix2, prefix) + : EqualStrings(ns2->getNameURI(), ns->getNameURI())) { + break; + } + } + } + if (j == length) { + if (!XMLArrayAddMember(cx, nsarray, (nsarray)->length, (void *)((ns)))) + return (JSIntn)0; + ++length; + } + } + } while ((xml = xml->parent) != __null); + ((void) 0); + return (JSIntn)1; +} +static + bool +NamespacesToJSArray(JSContext *cx, JSXMLArray *array, jsval *rval) +{ + JSObject *arrayobj = NewDenseEmptyArray(cx); + if (!arrayobj) + return false; + *rval = OBJECT_TO_JSVAL(arrayobj); + AutoValueRooter tvr(cx); + for (uint32 i = 0, n = array->length; i < n; i++) { + JSObject *ns = (((i) < (array)->length) ? (JSObject *) (array)->vector[i] : __null); + if (!ns) + continue; + tvr.set(ObjectValue(*ns)); + if (!arrayobj->setProperty(cx, INT_TO_JSID(i), tvr.addr(), false)) + return false; + } + return true; +} +static JSBool +xml_inScopeNamespaces(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + AutoNamespaceArray namespaces(cx); + return FindInScopeNamespaces(cx, xml, &namespaces.array) && + NamespacesToJSArray(cx, &namespaces.array, vp); +} +static JSBool +xml_insertChildAfter(JSContext *cx, uintN argc, jsval *vp) +{ + jsval arg; + JSXML *kid; + uint32 i; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + *vp = OBJECT_TO_JSVAL(obj); + if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) || argc == 0) + return (JSIntn)1; + arg = vp[2]; + if (JSVAL_IS_NULL(arg)) { + kid = __null; + i = 0; + } else { + if (!(!JSVAL_IS_PRIMITIVE(arg) && JSVAL_TO_OBJECT(arg)->isXML())) + return (JSIntn)1; + kid = (JSXML *) JSVAL_TO_OBJECT(arg)->getPrivate(); + i = XMLArrayFindMember(&xml->u.list.kids, (void *)(kid), __null); + if (i == ((uint32) -1)) + return (JSIntn)1; + ++i; + } + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + return Insert(cx, xml, i, argc >= 2 ? vp[3] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0))); +} +static JSBool +xml_insertChildBefore(JSContext *cx, uintN argc, jsval *vp) +{ + jsval arg; + JSXML *kid; + uint32 i; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + *vp = OBJECT_TO_JSVAL(obj); + if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) || argc == 0) + return (JSIntn)1; + arg = vp[2]; + if (JSVAL_IS_NULL(arg)) { + kid = __null; + i = xml->u.list.kids.length; + } else { + if (!(!JSVAL_IS_PRIMITIVE(arg) && JSVAL_TO_OBJECT(arg)->isXML())) + return (JSIntn)1; + kid = (JSXML *) JSVAL_TO_OBJECT(arg)->getPrivate(); + i = XMLArrayFindMember(&xml->u.list.kids, (void *)(kid), __null); + if (i == ((uint32) -1)) + return (JSIntn)1; + } + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + return Insert(cx, xml, i, argc >= 2 ? vp[3] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0))); +} +static JSBool +xml_length(JSContext *cx, uintN argc, jsval *vp) +{ + 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; + if (xml->xml_class != JSXML_CLASS_LIST) { + *vp = ((((uint64)(uint32)(JSVAL_TAG_INT32)) << 47) | (1)); + } else { + uint32 l = xml->u.list.kids.length; + if (l <= ((jsint)0x7fffffff)) + *vp = INT_TO_JSVAL(l); + else + *vp = DOUBLE_TO_JSVAL(l); + } + return (JSIntn)1; +} +static JSBool +xml_localName(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + *vp = xml->name ? xml->name->getQNameLocalNameVal() : ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); + return (JSIntn)1; +} +static JSBool +xml_name(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + *vp = OBJECT_TO_JSVAL(xml->name); + return (JSIntn)1; +} +static JSBool +xml_namespace(JSContext *cx, uintN argc, jsval *vp) +{ + JSLinearString *prefix, *nsprefix; + jsuint i, length; + JSObject *ns; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + if (argc == 0 && !((uintN)(((xml)->xml_class) - JSXML_CLASS_ELEMENT) <= (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))) { + *vp = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); + return true; + } + if (argc == 0) { + prefix = __null; + } else { + JSString *str = js_ValueToString(cx, Valueify(vp[2])); + if (!str) + return false; + prefix = str->ensureLinear(cx); + if (!prefix) + return false; + vp[2] = STRING_TO_JSVAL(prefix); + } + AutoNamespaceArray inScopeNSes(cx); + if (!FindInScopeNamespaces(cx, xml, &inScopeNSes.array)) + return false; + if (!prefix) { + ns = GetNamespace(cx, xml->name, &inScopeNSes.array); + if (!ns) + return false; + } else { + ns = __null; + for (i = 0, length = inScopeNSes.array.length; i < length; i++) { + ns = (((i) < (&inScopeNSes.array)->length) ? (JSObject *) (&inScopeNSes.array)->vector[i] : __null); + if (ns) { + nsprefix = ns->getNamePrefix(); + if (nsprefix && EqualStrings(nsprefix, prefix)) + break; + ns = __null; + } + } + } + *vp = (!ns) ? ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)) : OBJECT_TO_JSVAL(ns); + return true; +} +static JSBool +xml_namespaceDeclarations(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) + return true; + AutoNamespaceArray ancestors(cx); + AutoNamespaceArray declared(cx); + JSXML *yml = xml; + while ((yml = yml->parent) != __null) { + ((void) 0); + for (uint32 i = 0, n = yml->u.elem.namespaces.length; i < n; i++) { + JSObject *ns = (((i) < (&yml->u.elem.namespaces)->length) ? (JSObject *) (&yml->u.elem.namespaces)->vector[i] : __null); + if (ns && !(XMLArrayFindMember(&ancestors.array, (void *)(ns), namespace_match) != ((uint32) -1))) { + if (!XMLArrayAddMember(cx, &ancestors.array, (&ancestors.array)->length, (void *)((ns)))) + return false; + } + } + } + for (uint32 i = 0, n = xml->u.elem.namespaces.length; i < n; i++) { + JSObject *ns = (((i) < (&xml->u.elem.namespaces)->length) ? (JSObject *) (&xml->u.elem.namespaces)->vector[i] : __null); + if (!ns) + continue; + if (!IsDeclared(ns)) + continue; + if (!(XMLArrayFindMember(&ancestors.array, (void *)(ns), namespace_match) != ((uint32) -1))) { + if (!XMLArrayAddMember(cx, &declared.array, (&declared.array)->length, (void *)((ns)))) + return false; + } + } + return NamespacesToJSArray(cx, &declared.array, vp); +} +static const char js_attribute_str[] = "attribute"; +static const char js_text_str[] = "text"; +const char *js_xml_class_str[] = { + "list", + "element", + js_attribute_str, + "processing-instruction", + js_text_str, + "comment" +}; +static JSBool +xml_nodeKind(JSContext *cx, uintN argc, jsval *vp) +{ + JSString *str; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + str = JS_InternString(cx, js_xml_class_str[xml->xml_class]); + if (!str) + return (JSIntn)0; + *vp = STRING_TO_JSVAL(str); + return (JSIntn)1; +} +static void +NormalizingDelete(JSContext *cx, JSXML *xml, uint32 index) +{ + if (xml->xml_class == JSXML_CLASS_LIST) + DeleteListElement(cx, xml, index); + else + DeleteByIndex(cx, xml, index); +} +static JSBool +xml_normalize_helper(JSContext *cx, JSObject *obj, JSXML *xml) +{ + JSXML *kid, *kid2; + uint32 i, n; + JSObject *kidobj; + JSString *str; + if (!(((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE)) + return (JSIntn)1; + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + for (i = 0, n = xml->u.list.kids.length; i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (!kid) + continue; + if (kid->xml_class == JSXML_CLASS_ELEMENT) { + kidobj = js_GetXMLObject(cx, kid); + if (!kidobj || !xml_normalize_helper(cx, kidobj, kid)) + return (JSIntn)0; + } else if (kid->xml_class == JSXML_CLASS_TEXT) { + while (i + 1 < n && + (kid2 = (((i + 1) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i + 1] : __null)) && + kid2->xml_class == JSXML_CLASS_TEXT) { + str = js_ConcatStrings(cx, kid->u.value, kid2->u.value); + if (!str) + return (JSIntn)0; + NormalizingDelete(cx, xml, i + 1); + n = xml->u.list.kids.length; + kid->u.value = str; + } + if (kid->u.value->empty()) { + NormalizingDelete(cx, xml, i); + n = xml->u.list.kids.length; + --i; + } + } + } + return (JSIntn)1; +} +static JSBool +xml_normalize(JSContext *cx, uintN argc, jsval *vp) +{ + 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; + *vp = OBJECT_TO_JSVAL(obj); + return xml_normalize_helper(cx, obj, xml); +} +static JSBool +xml_parent(JSContext *cx, uintN argc, jsval *vp) +{ + JSXML *parent, *kid; + uint32 i, n; + JSObject *parentobj; + 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; + parent = xml->parent; + if (xml->xml_class == JSXML_CLASS_LIST) { + *vp = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + n = xml->u.list.kids.length; + if (n == 0) + return (JSIntn)1; + kid = (((0) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[0] : __null); + if (!kid) + return (JSIntn)1; + parent = kid->parent; + for (i = 1; i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->parent != parent) + return (JSIntn)1; + } + } + if (!parent) { + *vp = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); + return (JSIntn)1; + } + parentobj = js_GetXMLObject(cx, parent); + if (!parentobj) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(parentobj); + return (JSIntn)1; +} +static JSBool +xml_processingInstructions_helper(JSContext *cx, JSObject *obj, JSXML *xml, + JSObject *nameqn, jsval *vp) +{ + JSXML *list, *vxml; + JSBool ok; + JSObject *kidobj; + jsval v; + uint32 i, n; + list = xml_list_helper(cx, xml, vp); + if (!list) + return (JSIntn)0; + list->u.list.targetprop = nameqn; + ok = (JSIntn)1; + if (xml->xml_class == JSXML_CLASS_LIST) { + JSXMLArrayCursor cursor(&xml->u.list.kids); + while (JSXML *kid = (JSXML *) cursor.getNext()) { + if (kid->xml_class == JSXML_CLASS_ELEMENT) { + ok = js_EnterLocalRootScope(cx); + if (!ok) + break; + kidobj = js_GetXMLObject(cx, kid); + if (kidobj) { + ok = xml_processingInstructions_helper(cx, kidobj, kid, + nameqn, &v); + } else { + ok = (JSIntn)0; + v = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); + } + js_LeaveLocalRootScopeWithResult(cx, Valueify(v)); + if (!ok) + break; + vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate(); + if (((((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (vxml)->u.list.kids.length : 0) != 0) { + ok = Append(cx, list, vxml); + if (!ok) + break; + } + } + } + } else { + for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) { + JSXML *kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION) { + JSLinearString *localName = nameqn->getQNameLocalName(); + if (((localName)->length() == 1 && *(localName)->chars() == '*') || + EqualStrings(localName, kid->name->getQNameLocalName())) { + ok = Append(cx, list, kid); + if (!ok) + break; + } + } + } + } + return ok; +} +static JSBool +xml_processingInstructions(JSContext *cx, uintN argc, jsval *vp) +{ + jsval name; + JSObject *nameqn; + jsid funid; + 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; + name = (argc == 0) ? STRING_TO_JSVAL((cx->runtime->atomState.starAtom)) : vp[2]; + nameqn = ToXMLName(cx, name, &funid); + if (!nameqn) + return (JSIntn)0; + vp[2] = OBJECT_TO_JSVAL(nameqn); + if (!JSID_IS_VOID(funid)) + return xml_list_helper(cx, xml, vp) != __null; + return xml_processingInstructions_helper(cx, obj, xml, nameqn, vp); +} +static JSBool +xml_prependChild(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(obj); + return Insert(cx, xml, 0, argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0))); +} +static JSBool +xml_propertyIsEnumerable(JSContext *cx, uintN argc, jsval *vp) +{ + bool isIndex; + uint32 index; + 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; + *vp = ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)0)); + if (argc != 0) { + if (!js_IdValIsIndex(cx, vp[2], &index, &isIndex)) + return (JSIntn)0; + if (isIndex) { + if (xml->xml_class == JSXML_CLASS_LIST) { + *vp = BOOLEAN_TO_JSVAL(index < xml->u.list.kids.length); + } else { + *vp = BOOLEAN_TO_JSVAL(index == 0); + } + } + } + return (JSIntn)1; +} +static JSBool +namespace_full_match(const void *a, const void *b) +{ + const JSObject *nsa = (const JSObject *) a; + const JSObject *nsb = (const JSObject *) b; + JSLinearString *prefixa = nsa->getNamePrefix(); + JSLinearString *prefixb; + if (prefixa) { + prefixb = nsb->getNamePrefix(); + if (prefixb && !EqualStrings(prefixa, prefixb)) + return (JSIntn)0; + } + return EqualStrings(nsa->getNameURI(), nsb->getNameURI()); +} +static JSBool +xml_removeNamespace_helper(JSContext *cx, JSXML *xml, JSObject *ns) +{ + JSObject *thisns, *attrns; + uint32 i, n; + JSXML *attr, *kid; + thisns = GetNamespace(cx, xml->name, &xml->u.elem.namespaces); + ((void) 0); + if (thisns == ns) + return (JSIntn)1; + for (i = 0, n = xml->u.elem.attrs.length; i < n; i++) { + attr = (((i) < (&xml->u.elem.attrs)->length) ? (JSXML *) (&xml->u.elem.attrs)->vector[i] : __null); + if (!attr) + continue; + attrns = GetNamespace(cx, attr->name, &xml->u.elem.namespaces); + ((void) 0); + if (attrns == ns) + return (JSIntn)1; + } + i = XMLArrayFindMember(&xml->u.elem.namespaces, (void *)(ns), namespace_full_match); + if (i != ((uint32) -1)) + XMLArrayDelete(cx, &xml->u.elem.namespaces, i, (JSIntn)1); + for (i = 0, n = xml->u.list.kids.length; i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) { + if (!xml_removeNamespace_helper(cx, kid, ns)) + return (JSIntn)0; + } + } + return (JSIntn)1; +} +static JSBool +xml_removeNamespace(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *ns; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + if (xml->xml_class != JSXML_CLASS_ELEMENT) + goto done; + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + if (!NamespaceHelper(cx, __null, argc == 0 ? -1 : 1, vp + 2, vp)) + return (JSIntn)0; + ((void) 0); + ns = JSVAL_TO_OBJECT(*vp); + if (!xml_removeNamespace_helper(cx, xml, ns)) + return (JSIntn)0; + done: + *vp = OBJECT_TO_JSVAL(obj); + return (JSIntn)1; +} +static JSBool +xml_replace(JSContext *cx, uintN argc, jsval *vp) +{ + jsval value; + JSXML *vxml, *kid; + uint32 index, i; + JSObject *nameqn; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + if (xml->xml_class != JSXML_CLASS_ELEMENT) + goto done; + if (argc <= 1) { + value = STRING_TO_JSVAL((cx->runtime->atomState.typeAtoms[JSTYPE_VOID])); + } else { + value = vp[3]; + vxml = (!JSVAL_IS_PRIMITIVE(value) && JSVAL_TO_OBJECT(value)->isXML()) + ? (JSXML *) JSVAL_TO_OBJECT(value)->getPrivate() + : __null; + if (!vxml) { + if (!JS_ConvertValue(cx, value, JSTYPE_STRING, &vp[3])) + return (JSIntn)0; + value = vp[3]; + } else { + vxml = DeepCopy(cx, vxml, __null, 0); + if (!vxml) + return (JSIntn)0; + value = vp[3] = OBJECT_TO_JSVAL(vxml->object); + } + } + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + bool haveIndex; + if (argc == 0) { + haveIndex = false; + } else { + if (!js_IdValIsIndex(cx, vp[2], &index, &haveIndex)) + return (JSIntn)0; + } + if (!haveIndex) { + if (!QNameHelper(cx, __null, argc == 0 ? -1 : 1, vp + 2, vp)) + return (JSIntn)0; + ((void) 0); + nameqn = JSVAL_TO_OBJECT(*vp); + i = xml->u.list.kids.length; + index = ((uint32) -1); + while (i != 0) { + --i; + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && MatchElemName(nameqn, kid)) { + if (i != ((uint32) -1)) + DeleteByIndex(cx, xml, i); + index = i; + } + } + if (index == ((uint32) -1)) + goto done; + } + if (!Replace(cx, xml, index, value)) + return (JSIntn)0; + done: + *vp = OBJECT_TO_JSVAL(obj); + return (JSIntn)1; +} +static JSBool +xml_setChildren(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj; + if (!StartNonListXMLMethod(cx, vp, &obj)) + return (JSIntn)0; + *vp = argc != 0 ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + if (!PutProperty(cx, obj, ATOM_TO_JSID(cx->runtime->atomState.starAtom), false, vp)) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(obj); + return (JSIntn)1; +} +static JSBool +xml_setLocalName(JSContext *cx, uintN argc, jsval *vp) +{ + jsval name; + JSObject *nameqn; + JSLinearString *namestr; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + if (!((uintN)(((xml)->xml_class) - JSXML_CLASS_ELEMENT) <= (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))) + return (JSIntn)1; + if (argc == 0) { + namestr = (cx->runtime->atomState.typeAtoms[JSTYPE_VOID]); + } else { + name = vp[2]; + if (!JSVAL_IS_PRIMITIVE(name) && + JSVAL_TO_OBJECT(name)->getClass() == &js_QNameClass) { + nameqn = JSVAL_TO_OBJECT(name); + namestr = nameqn->getQNameLocalName(); + } else { + if (!JS_ConvertValue(cx, name, JSTYPE_STRING, &vp[2])) + return (JSIntn)0; + name = vp[2]; + namestr = JSVAL_TO_STRING(name)->ensureLinear(cx); + if (!namestr) + return (JSIntn)0; + } + } + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + if (namestr) + xml->name->setQNameLocalName(namestr); + return (JSIntn)1; +} +static JSBool +xml_setName(JSContext *cx, uintN argc, jsval *vp) +{ + jsval name; + JSObject *nameqn; + JSXML *nsowner; + JSXMLArray *nsarray; + uint32 i, n; + JSObject *ns; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + if (!((uintN)(((xml)->xml_class) - JSXML_CLASS_ELEMENT) <= (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))) + return (JSIntn)1; + if (argc == 0) { + name = STRING_TO_JSVAL((cx->runtime->atomState.typeAtoms[JSTYPE_VOID])); + } else { + name = vp[2]; + if (!JSVAL_IS_PRIMITIVE(name) && + JSVAL_TO_OBJECT(name)->getClass() == &js_QNameClass && + !(nameqn = JSVAL_TO_OBJECT(name))->getNameURI()) { + name = vp[2] = nameqn->getQNameLocalNameVal(); + } + } + nameqn = js_ConstructObject(cx, &js_QNameClass, __null, __null, 1, Valueify(&name)); + if (!nameqn) + return (JSIntn)0; + if (xml->xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION) + nameqn->setNameURI(cx->runtime->emptyString); + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + xml->name = nameqn; + if (xml->xml_class == JSXML_CLASS_ELEMENT) { + nsowner = xml; + } else { + if (!xml->parent || xml->parent->xml_class != JSXML_CLASS_ELEMENT) + return (JSIntn)1; + nsowner = xml->parent; + } + if (nameqn->getNamePrefix()) { + ns = GetNamespace(cx, nameqn, &nsowner->u.elem.namespaces); + if (!ns) + return (JSIntn)0; + if ((XMLArrayFindMember(&nsowner->u.elem.namespaces, (void *)(ns), __null) != ((uint32) -1))) + return (JSIntn)1; + } else { + ((void) 0); + nsarray = &nsowner->u.elem.namespaces; + for (i = 0, n = nsarray->length; i < n; i++) { + ns = (((i) < (nsarray)->length) ? (JSObject *) (nsarray)->vector[i] : __null); + if (ns && EqualStrings(ns->getNameURI(), nameqn->getNameURI())) { + nameqn->setNamePrefix(ns->getNamePrefix()); + return (JSIntn)1; + } + } + ns = NewXMLNamespace(cx, __null, nameqn->getNameURI(), (JSIntn)1); + if (!ns) + return (JSIntn)0; + } + if (!AddInScopeNamespace(cx, nsowner, ns)) + return (JSIntn)0; + vp[0] = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + return (JSIntn)1; +} +static JSBool +xml_setNamespace(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *qn; + JSObject *ns; + jsval qnargv[2]; + JSXML *nsowner; + JSObject *obj; JSXML *xml = StartNonListXMLMethod(cx, vp, &obj); if (!xml) return (JSIntn)0; ((void) 0); + if (!((uintN)(((xml)->xml_class) - JSXML_CLASS_ELEMENT) <= (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))) + return (JSIntn)1; + xml = (xml->object == obj ? xml : CopyOnWrite(cx, xml, obj)); + if (!xml) + return (JSIntn)0; + ns = js_ConstructObject(cx, &js_NamespaceClass, __null, obj, + argc == 0 ? 0 : 1, Valueify(vp + 2)); + if (!ns) + return (JSIntn)0; + vp[0] = OBJECT_TO_JSVAL(ns); + ns->setNamespaceDeclared(((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1))); + qnargv[0] = OBJECT_TO_JSVAL(ns); + qnargv[1] = OBJECT_TO_JSVAL(xml->name); + qn = js_ConstructObject(cx, &js_QNameClass, __null, __null, 2, Valueify(qnargv)); + if (!qn) + return (JSIntn)0; + xml->name = qn; + if (xml->xml_class == JSXML_CLASS_ELEMENT) { + nsowner = xml; + } else { + if (!xml->parent || xml->parent->xml_class != JSXML_CLASS_ELEMENT) + return (JSIntn)1; + nsowner = xml->parent; + } + if (!AddInScopeNamespace(cx, nsowner, ns)) + return (JSIntn)0; + vp[0] = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + return (JSIntn)1; +} +static JSBool +xml_text_helper(JSContext *cx, JSObject *obj, JSXML *xml, jsval *vp) +{ + JSXML *list, *kid, *vxml; + uint32 i, n; + JSBool ok; + JSObject *kidobj; + jsval v; + list = xml_list_helper(cx, xml, vp); + if (!list) + return (JSIntn)0; + if (xml->xml_class == JSXML_CLASS_LIST) { + ok = (JSIntn)1; + for (i = 0, n = xml->u.list.kids.length; i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) { + ok = js_EnterLocalRootScope(cx); + if (!ok) + break; + kidobj = js_GetXMLObject(cx, kid); + if (kidobj) { + ok = xml_text_helper(cx, kidobj, kid, &v); + } else { + ok = (JSIntn)0; + v = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); + } + js_LeaveLocalRootScopeWithResult(cx, Valueify(v)); + if (!ok) + return (JSIntn)0; + vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate(); + if (((((vxml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (vxml)->u.list.kids.length : 0) != 0 && !Append(cx, list, vxml)) + return (JSIntn)0; + } + } + } else { + for (i = 0, n = ((((xml)->xml_class) < JSXML_CLASS_ATTRIBUTE) ? (xml)->u.list.kids.length : 0); i < n; i++) { + kid = (((i) < (&xml->u.list.kids)->length) ? (JSXML *) (&xml->u.list.kids)->vector[i] : __null); + if (kid && kid->xml_class == JSXML_CLASS_TEXT) { + if (!Append(cx, list, kid)) + return (JSIntn)0; + } + } + } + return (JSIntn)1; +} +static JSBool +xml_text(JSContext *cx, uintN argc, jsval *vp) +{ + 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; + return xml_text_helper(cx, obj, xml, vp); +} +static JSString * +xml_toString_helper(JSContext *cx, JSXML *xml) +{ + JSString *str, *kidstr; + if (xml->xml_class == JSXML_CLASS_ATTRIBUTE || + xml->xml_class == JSXML_CLASS_TEXT) { + return xml->u.value; + } + if (!HasSimpleContent(xml)) + return ToXMLString(cx, OBJECT_TO_JSVAL(xml->object), 0); + str = cx->runtime->emptyString; + if (!js_EnterLocalRootScope(cx)) + return __null; + JSXMLArrayCursor cursor(&xml->u.list.kids); + while (JSXML *kid = (JSXML *) cursor.getNext()) { + if (kid->xml_class != JSXML_CLASS_COMMENT && + kid->xml_class != JSXML_CLASS_PROCESSING_INSTRUCTION) { + kidstr = xml_toString_helper(cx, kid); + if (!kidstr) { + str = __null; + break; + } + str = js_ConcatStrings(cx, str, kidstr); + if (!str) + break; + } + } + js_LeaveLocalRootScopeWithResult(cx, str); + return str; +} +static JSBool +xml_toSource(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj = ToObject(cx, Valueify(&vp[1])); + if (!obj) + return (JSIntn)0; + JSString *str = ToXMLString(cx, OBJECT_TO_JSVAL(obj), 0x80000000); + if (!str) + return (JSIntn)0; + *vp = STRING_TO_JSVAL(str); + return (JSIntn)1; +} +static JSBool +xml_toString(JSContext *cx, uintN argc, jsval *vp) +{ + JSString *str; + 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; + str = xml_toString_helper(cx, xml); + if (!str) + return (JSIntn)0; + *vp = STRING_TO_JSVAL(str); + return (JSIntn)1; +} +static JSBool +xml_toXMLString(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj = ToObject(cx, Valueify(&vp[1])); + if (!obj) + return (JSIntn)0; + JSString *str = ToXMLString(cx, OBJECT_TO_JSVAL(obj), 0); + if (!str) + return (JSIntn)0; + *vp = STRING_TO_JSVAL(str); + return (JSIntn)1; +} +static JSBool +xml_valueOf(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *obj = ToObject(cx, Valueify(&vp[1])); + if (!obj) + return false; + *vp = OBJECT_TO_JSVAL(obj); + return true; +} +static JSFunctionSpec xml_methods[] = { + {"addNamespace", ((JSNative)(xml_addNamespace)), 1, (0) | 0x1000}, + {"appendChild", ((JSNative)(xml_appendChild)), 1, (0) | 0x1000}, + {js_attribute_str, ((JSNative)(xml_attribute)), 1, (0) | 0x1000}, + {"attributes", ((JSNative)(xml_attributes)), 0, (0) | 0x1000}, + {"child", ((JSNative)(xml_child)), 1, (0) | 0x1000}, + {"childIndex", ((JSNative)(xml_childIndex)), 0, (0) | 0x1000}, + {"children", ((JSNative)(xml_children)), 0, (0) | 0x1000}, + {"comments", ((JSNative)(xml_comments)), 0, (0) | 0x1000}, + {"contains", ((JSNative)(xml_contains)), 1, (0) | 0x1000}, + {"copy", ((JSNative)(xml_copy)), 0, (0) | 0x1000}, + {"descendants", ((JSNative)(xml_descendants)), 1, (0) | 0x1000}, + {"elements", ((JSNative)(xml_elements)), 1, (0) | 0x1000}, + {"hasOwnProperty", ((JSNative)(xml_hasOwnProperty)), 1, (0) | 0x1000}, + {"hasComplexContent", ((JSNative)(xml_hasComplexContent)), 1, (0) | 0x1000}, + {"hasSimpleContent", ((JSNative)(xml_hasSimpleContent)), 1, (0) | 0x1000}, + {"inScopeNamespaces", ((JSNative)(xml_inScopeNamespaces)), 0, (0) | 0x1000}, + {"insertChildAfter", ((JSNative)(xml_insertChildAfter)), 2, (0) | 0x1000}, + {"insertChildBefore", ((JSNative)(xml_insertChildBefore)), 2, (0) | 0x1000}, + {js_length_str, ((JSNative)(xml_length)), 0, (0) | 0x1000}, + {js_localName_str, ((JSNative)(xml_localName)), 0, (0) | 0x1000}, + {js_name_str, ((JSNative)(xml_name)), 0, (0) | 0x1000}, + {js_namespace_str, ((JSNative)(xml_namespace)), 1, (0) | 0x1000}, + {"namespaceDeclarations", ((JSNative)(xml_namespaceDeclarations)), 0, (0) | 0x1000}, + {"nodeKind", ((JSNative)(xml_nodeKind)), 0, (0) | 0x1000}, + {"normalize", ((JSNative)(xml_normalize)), 0, (0) | 0x1000}, + {js_xml_parent_str, ((JSNative)(xml_parent)), 0, (0) | 0x1000}, + {"processingInstructions", ((JSNative)(xml_processingInstructions)), 1, (0) | 0x1000}, + {"prependChild", ((JSNative)(xml_prependChild)), 1, (0) | 0x1000}, + {"propertyIsEnumerable", ((JSNative)(xml_propertyIsEnumerable)), 1, (0) | 0x1000}, + {"removeNamespace", ((JSNative)(xml_removeNamespace)), 1, (0) | 0x1000}, + {"replace", ((JSNative)(xml_replace)), 2, (0) | 0x1000}, + {"setChildren", ((JSNative)(xml_setChildren)), 1, (0) | 0x1000}, + {"setLocalName", ((JSNative)(xml_setLocalName)), 1, (0) | 0x1000}, + {"setName", ((JSNative)(xml_setName)), 1, (0) | 0x1000}, + {"setNamespace", ((JSNative)(xml_setNamespace)), 1, (0) | 0x1000}, + {js_text_str, ((JSNative)(xml_text)), 0, (0) | 0x1000}, + {js_toSource_str, ((JSNative)(xml_toSource)), 0, (0) | 0x1000}, + {js_toString_str, ((JSNative)(xml_toString)), 0, (0) | 0x1000}, + {js_toXMLString_str, ((JSNative)(xml_toXMLString)), 0, (0) | 0x1000}, + {js_valueOf_str, ((JSNative)(xml_valueOf)), 0, (0) | 0x1000}, + {__null, __null, 0, 0} +}; +static JSBool +CopyXMLSettings(JSContext *cx, JSObject *from, JSObject *to) +{ + int i; + const char *name; + jsval v; + for (i = 0; xml_static_props[i].name; i++) { + name = xml_static_props[i].name; + if (!JS_GetProperty(cx, from, name, &v)) + return false; + if (name == js_prettyIndent_str) { + if (!JSVAL_IS_NUMBER(v)) + continue; + } else { + if (!JSVAL_IS_BOOLEAN(v)) + continue; + } + if (!JS_SetProperty(cx, to, name, &v)) + return false; + } + return true; +} +static JSBool +SetDefaultXMLSettings(JSContext *cx, JSObject *obj) +{ + int i; + jsval v; + for (i = 0; xml_static_props[i].name; i++) { + v = (xml_static_props[i].name != js_prettyIndent_str) + ? ((((uint64)(uint32)(JSVAL_TAG_BOOLEAN)) << 47) | ((JSIntn)1)) : INT_TO_JSVAL(2); + if (!JS_SetProperty(cx, obj, xml_static_props[i].name, &v)) + return (JSIntn)0; + } + return true; +} +static JSBool +xml_settings(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *settings = JS_NewObject(cx, __null, __null, __null); + if (!settings) + return false; + *vp = OBJECT_TO_JSVAL(settings); + JSObject *obj = ToObject(cx, Valueify(&vp[1])); + if (!obj) + return false; + return CopyXMLSettings(cx, obj, settings); +} +static JSBool +xml_setSettings(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *settings; + jsval v; + JSBool ok; + JSObject *obj = ToObject(cx, Valueify(&vp[1])); + if (!obj) + return (JSIntn)0; + v = (argc == 0) ? ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)) : vp[2]; + if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) { + ok = SetDefaultXMLSettings(cx, obj); + } else { + if (JSVAL_IS_PRIMITIVE(v)) + return (JSIntn)1; + settings = JSVAL_TO_OBJECT(v); + ok = CopyXMLSettings(cx, settings, obj); + } + return ok; +} +static JSBool +xml_defaultSettings(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *settings; + settings = JS_NewObject(cx, __null, __null, __null); + if (!settings) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(settings); + return SetDefaultXMLSettings(cx, settings); +} +static JSFunctionSpec xml_static_methods[] = { + {"settings", ((JSNative)(xml_settings)), 0, (0) | 0x1000}, + {"setSettings", ((JSNative)(xml_setSettings)), 1, (0) | 0x1000}, + {"defaultSettings", ((JSNative)(xml_defaultSettings)), 0, (0) | 0x1000}, + {__null, __null, 0, 0} +}; +static JSBool +XML(JSContext *cx, uintN argc, Value *vp) +{ + JSXML *xml, *copy; + JSObject *xobj, *vobj; + Class *clasp; + jsval v = argc ? Jsvalify(vp[2]) : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) + v = STRING_TO_JSVAL(cx->runtime->emptyString); + xobj = ToXML(cx, v); + if (!xobj) + return (JSIntn)0; + xml = (JSXML *) xobj->getPrivate(); + if (IsConstructing(vp) && !JSVAL_IS_PRIMITIVE(v)) { + vobj = JSVAL_TO_OBJECT(v); + clasp = vobj->getClass(); + if (clasp == &js_XMLClass || + (clasp->flags & (1<<7))) { + copy = DeepCopy(cx, xml, __null, 0); + if (!copy) + return (JSIntn)0; + vp->setObject(*copy->object); + return (JSIntn)1; + } + } + vp->setObject(*xobj); + return (JSIntn)1; +} +static JSBool +XMLList(JSContext *cx, uintN argc, jsval *vp) +{ + JSObject *vobj, *listobj; + JSXML *xml, *list; + jsval v = argc ? vp[2] : ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) + v = STRING_TO_JSVAL(cx->runtime->emptyString); + if (IsConstructing(Valueify(vp)) && !JSVAL_IS_PRIMITIVE(v)) { + vobj = JSVAL_TO_OBJECT(v); + if (vobj->isXML()) { + xml = (JSXML *) vobj->getPrivate(); + if (xml->xml_class == JSXML_CLASS_LIST) { + listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST); + if (!listobj) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(listobj); + list = (JSXML *) listobj->getPrivate(); + if (!Append(cx, list, xml)) + return (JSIntn)0; + return (JSIntn)1; + } + } + } + listobj = ToXMLList(cx, v); + if (!listobj) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(listobj); + return (JSIntn)1; +} +JSXML * +js_NewXML(JSContext *cx, JSXMLClass xml_class) +{ + JSXML *xml = js_NewGCXML(cx); + if (!xml) + return __null; + xml->object = __null; + xml->domnode = __null; + xml->parent = __null; + xml->name = __null; + xml->xml_class = xml_class; + xml->xml_flags = 0; + if (((xml_class) >= JSXML_CLASS_ATTRIBUTE)) { + xml->u.value = cx->runtime->emptyString; + } else { + xml->u.list.kids.init(); + if (xml_class == JSXML_CLASS_LIST) { + xml->u.list.target = __null; + xml->u.list.targetprop = __null; + } else { + xml->u.elem.namespaces.init(); + xml->u.elem.attrs.init(); + } + } + ; + return xml; +} +void +js_TraceXML(JSTracer *trc, JSXML *xml) +{ + if (xml->object) + MarkObject(trc, *xml->object, "object"); + if (xml->name) + MarkObject(trc, *xml->name, "name"); + if (xml->parent) + do { do { } while (0); JS_CallTracer((trc), (xml->parent), (2)); } while (0); + if ((((xml)->xml_class) >= JSXML_CLASS_ATTRIBUTE)) { + if (xml->u.value) + MarkString(trc, xml->u.value, "value"); + return; + } + xml_trace_vector(trc, + (JSXML **) xml->u.list.kids.vector, + xml->u.list.kids.length); + XMLArrayCursorTrace(trc, xml->u.list.kids.cursors); + if (((trc)->callback == __null)) + xml->u.list.kids.trim(); + if (xml->xml_class == JSXML_CLASS_LIST) { + if (xml->u.list.target) + do { do { } while (0); JS_CallTracer((trc), (xml->u.list.target), (2)); } while (0); + if (xml->u.list.targetprop) + MarkObject(trc, *xml->u.list.targetprop, "targetprop"); + } else { + MarkObjectRange(trc, xml->u.elem.namespaces.length, + (JSObject **) xml->u.elem.namespaces.vector, + "xml_namespaces"); + XMLArrayCursorTrace(trc, xml->u.elem.namespaces.cursors); + if (((trc)->callback == __null)) + xml->u.elem.namespaces.trim(); + xml_trace_vector(trc, + (JSXML **) xml->u.elem.attrs.vector, + xml->u.elem.attrs.length); + XMLArrayCursorTrace(trc, xml->u.elem.attrs.cursors); + if (((trc)->callback == __null)) + xml->u.elem.attrs.trim(); + } +} +JSObject * +js_NewXMLObject(JSContext *cx, JSXMLClass xml_class) +{ + JSXML *xml = js_NewXML(cx, xml_class); + if (!xml) + return __null; + AutoXMLRooter root(cx, xml); + return js_GetXMLObject(cx, xml); +} +static JSObject * +NewXMLObject(JSContext *cx, JSXML *xml) +{ + JSObject *obj; + obj = NewNonFunction(cx, &js_XMLClass, __null, __null); + if (!obj) + return __null; + obj->setPrivate(xml); + ; + return obj; +} +JSObject * +js_GetXMLObject(JSContext *cx, JSXML *xml) +{ + JSObject *obj; + obj = xml->object; + if (obj) { + ((void) 0); + return obj; + } + obj = NewXMLObject(cx, xml); + if (!obj) + return __null; + xml->object = obj; + return obj; +} +JSObject * +js_InitNamespaceClass(JSContext *cx, JSObject *obj) +{ + return js_InitClass(cx, obj, __null, &js_NamespaceClass, Namespace, 2, + namespace_props, namespace_methods, __null, __null); +} +JSObject * +js_InitQNameClass(JSContext *cx, JSObject *obj) +{ + return js_InitClass(cx, obj, __null, &js_QNameClass, QName, 2, + qname_props, qname_methods, __null, __null); +} +JSObject * +js_InitXMLClass(JSContext *cx, JSObject *obj) +{ + JSObject *proto, *pobj; + JSFunction *fun; + JSXML *xml; + JSProperty *prop; + Shape *shape; + jsval cval, vp[3]; + if (!JS_DefineFunction(cx, obj, js_isXMLName_str, xml_isXMLName, 1, 0)) + return __null; + proto = js_InitClass(cx, obj, __null, &js_XMLClass, XML, 1, + __null, xml_methods, + xml_static_props, xml_static_methods); + if (!proto) + return __null; + xml = js_NewXML(cx, JSXML_CLASS_TEXT); + if (!xml) + return __null; + proto->setPrivate(xml); + xml->object = proto; + ; + if (!js_LookupProperty(cx, proto, + ATOM_TO_JSID(cx->runtime->atomState.constructorAtom), + &pobj, &prop)) { + return __null; + } + ((void) 0); + shape = (Shape *) prop; + cval = Jsvalify(pobj->nativeGetSlot(shape->slot)); + ((void) 0); + vp[0] = ((((uint64)(uint32)(JSVAL_TAG_NULL)) << 47) | (0)); + vp[1] = cval; + vp[2] = ((((uint64)(uint32)(JSVAL_TAG_UNDEFINED)) << 47) | (0)); + if (!xml_setSettings(cx, 1, vp)) + return __null; + fun = JS_DefineFunction(cx, obj, js_XMLList_str, XMLList, 1, 0x0200); + if (!fun) + return __null; + if (!js_SetClassPrototype(cx, (static_cast(fun)), proto, + 0x02 | 0x04)) { + return __null; + } + return proto; +} +JSObject * +js_InitXMLClasses(JSContext *cx, JSObject *obj) +{ + if (!js_InitNamespaceClass(cx, obj)) + return __null; + if (!js_InitQNameClass(cx, obj)) + return __null; + return js_InitXMLClass(cx, obj); +} +JSBool +js_GetFunctionNamespace(JSContext *cx, Value *vp) +{ + JSObject *global = cx->hasfp() ? cx->fp()->scopeChain().getGlobal() : cx->globalObject; + *vp = global->getReservedSlot(((((JSProto_LIMIT * 3) + 1) + 1) + 1)); + if (vp->isUndefined()) { + JSRuntime *rt = cx->runtime; + JSLinearString *prefix = rt->atomState.typeAtoms[JSTYPE_FUNCTION]; + JSLinearString *uri = rt->atomState.functionNamespaceURIAtom; + JSObject *obj = NewXMLNamespace(cx, prefix, uri, (JSIntn)0); + if (!obj) + return false; + obj->clearProto(); + vp->setObject(*obj); + if (!js_SetReservedSlot(cx, global, ((((JSProto_LIMIT * 3) + 1) + 1) + 1), *vp)) + return false; + } + return true; +} +JSBool +js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp) +{ + JSObject *ns, *obj, *tmp; + jsval v; + JSObject *scopeChain = GetScopeChain(cx); + obj = __null; + for (tmp = scopeChain; tmp; tmp = tmp->getParent()) { + Class *clasp = tmp->getClass(); + if (clasp == &js_BlockClass || clasp == &js_WithClass) + continue; + if (!tmp->getProperty(cx, ((jsid)0x6), Valueify(&v))) + return (JSIntn)0; + if (!JSVAL_IS_PRIMITIVE(v)) { + *vp = v; + return (JSIntn)1; + } + obj = tmp; + } + ns = js_ConstructObject(cx, &js_NamespaceClass, __null, obj, 0, __null); + if (!ns) + return (JSIntn)0; + v = OBJECT_TO_JSVAL(ns); + if (!obj->defineProperty(cx, ((jsid)0x6), Valueify(v), + PropertyStub, StrictPropertyStub, 0x04)) { + return (JSIntn)0; + } + *vp = v; + return (JSIntn)1; +} +JSBool +js_SetDefaultXMLNamespace(JSContext *cx, const Value &v) +{ + Value argv[2]; + argv[0].setString(cx->runtime->emptyString); + argv[1] = v; + JSObject *ns = js_ConstructObject(cx, &js_NamespaceClass, __null, __null, 2, argv); + if (!ns) + return (JSIntn)0; + JSStackFrame *fp = js_GetTopStackFrame(cx); + JSObject &varobj = fp->varobj(cx); + if (!varobj.defineProperty(cx, ((jsid)0x6), ObjectValue(*ns), + PropertyStub, StrictPropertyStub, 0x04)) { + return (JSIntn)0; + } + return (JSIntn)1; +} +JSBool +js_ToAttributeName(JSContext *cx, Value *vp) +{ + JSObject *qn; + qn = ToAttributeName(cx, Jsvalify(*vp)); + if (!qn) + return (JSIntn)0; + vp->setObject(*qn); + return (JSIntn)1; +} +JSFlatString * +js_EscapeAttributeValue(JSContext *cx, JSString *str, JSBool quote) +{ + StringBuffer sb(cx); + return EscapeAttributeValue(cx, sb, str, quote); +} +JSString * +js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str, JSString *str2) +{ + size_t len = str->length(); + const jschar *chars = str->getChars(cx); + if (!chars) + return __null; + size_t len2 = str2->length(); + const jschar *chars2 = str2->getChars(cx); + if (!chars2) + return __null; + size_t newlen = (isName) ? len + 1 + len2 : len + 2 + len2 + 1; + jschar *newchars = (jschar *) cx->malloc((newlen+1) * sizeof(jschar)); + if (!newchars) + return __null; + memcpy((newchars), (chars), (len) * sizeof(jschar)); + newchars += len; + if (isName) { + *newchars++ = ' '; + memcpy((newchars), (chars2), (len2) * sizeof(jschar)); + newchars += len2; + } else { + *newchars++ = '='; + *newchars++ = '"'; + memcpy((newchars), (chars2), (len2) * sizeof(jschar)); + newchars += len2; + *newchars++ = '"'; + } + *newchars = 0; + return js_NewString(cx, newchars - newlen, newlen); +} +JSFlatString * +js_EscapeElementValue(JSContext *cx, JSString *str) +{ + StringBuffer sb(cx); + return EscapeElementValue(cx, sb, str, 0); +} +JSString * +js_ValueToXMLString(JSContext *cx, const Value &v) +{ + return ToXMLString(cx, Jsvalify(v), 0); +} +JSBool +js_GetAnyName(JSContext *cx, jsid *idp) +{ + JSObject *global = cx->hasfp() ? cx->fp()->scopeChain().getGlobal() : cx->globalObject; + Value v = global->getReservedSlot(JSProto_AnyName); + if (v.isUndefined()) { + JSObject *obj = NewNonFunction(cx, &js_AnyNameClass, __null, global); + if (!obj) + return false; + ((void) 0); + JSRuntime *rt = cx->runtime; + InitXMLQName(obj, rt->emptyString, rt->emptyString, + (rt->atomState.starAtom)); + ; + v.setObject(*obj); + if (!js_SetReservedSlot(cx, global, JSProto_AnyName, v)) + return false; + } + *idp = OBJECT_TO_JSID(&v.toObject()); + return true; +} +JSBool +js_FindXMLProperty(JSContext *cx, const Value &nameval, JSObject **objp, jsid *idp) +{ + JSObject *nameobj; + jsval v; + JSObject *qn; + jsid funid; + JSObject *obj, *target, *proto, *pobj; + JSXML *xml; + JSBool found; + JSProperty *prop; + ((void) 0); + nameobj = &nameval.toObject(); + if (nameobj->getClass() == &js_AnyNameClass) { + v = STRING_TO_JSVAL((cx->runtime->atomState.starAtom)); + nameobj = js_ConstructObject(cx, &js_QNameClass, __null, __null, 1, + Valueify(&v)); + if (!nameobj) + return (JSIntn)0; + } else { + ((void) 0) + ; + } + qn = nameobj; + if (!IsFunctionQName(cx, qn, &funid)) + return (JSIntn)0; + obj = &js_GetTopStackFrame(cx)->scopeChain(); + do { + target = obj; + while (target->getClass() == &js_WithClass) { + proto = target->getProto(); + if (!proto) + break; + target = proto; + } + if (target->isXML()) { + if (JSID_IS_VOID(funid)) { + xml = (JSXML *) target->getPrivate(); + found = HasNamedProperty(xml, qn); + } else { + if (!HasFunctionProperty(cx, target, funid, &found)) + return (JSIntn)0; + } + if (found) { + *idp = OBJECT_TO_JSID(nameobj); + *objp = target; + return (JSIntn)1; + } + } else if (!JSID_IS_VOID(funid)) { + if (!target->lookupProperty(cx, funid, &pobj, &prop)) + return (JSIntn)0; + if (prop) { + *idp = funid; + *objp = target; + return (JSIntn)1; + } + } + } while ((obj = obj->getParent()) != __null); + JSAutoByteString printable; + JSString *str = ConvertQNameToString(cx, nameobj); + if (str && js_ValueToPrintable(cx, StringValue(str), &printable)) { + JS_ReportErrorFlagsAndNumber(cx, 0x0, js_GetErrorMessage, __null, + JSMSG_UNDEFINED_XML_NAME, printable.ptr()); + } + return (JSIntn)0; +} +static JSBool +GetXMLFunction(JSContext *cx, JSObject *obj, jsid id, jsval *vp) +{ + ((void) 0); + JSObject *target = obj; + AutoObjectRooter tvr(cx); + for (;;) { + if (!js_GetProperty(cx, target, id, Valueify(vp))) + return false; + if ((!JSVAL_IS_PRIMITIVE(*vp) && JSVAL_TO_OBJECT(*vp)->isFunction())) + return true; + target = target->getProto(); + if (target == __null || !target->isNative()) + break; + tvr.setObject(target); + } + JSXML *xml = (JSXML *) obj->getPrivate(); + if (!HasSimpleContent(xml)) + return true; + if (!js_GetClassPrototype(cx, __null, JSProto_String, tvr.addr())) + return false; + ((void) 0); + return tvr.object()->getProperty(cx, id, Valueify(vp)); +} +static JSXML * +GetPrivate(JSContext *cx, JSObject *obj, const char *method) +{ + JSXML *xml; + xml = (JSXML *) GetInstancePrivate(cx, obj, &js_XMLClass, __null); + if (!xml) { + JS_ReportErrorNumber(cx, js_GetErrorMessage, __null, + JSMSG_INCOMPATIBLE_METHOD, + js_XML_str, method, obj->getClass()->name); + } + return xml; +} +JSBool +js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + JSXML *xml, *list; + xml = GetPrivate(cx, obj, "descendants internal method"); + if (!xml) + return (JSIntn)0; + list = Descendants(cx, xml, id); + if (!list) + return (JSIntn)0; + *vp = OBJECT_TO_JSVAL(list->object); + return (JSIntn)1; +} +JSBool +js_DeleteXMLListElements(JSContext *cx, JSObject *listobj) +{ + JSXML *list; + uint32 n; + list = (JSXML *) listobj->getPrivate(); + for (n = list->u.list.kids.length; n != 0; --n) + DeleteListElement(cx, list, 0); + return (JSIntn)1; +} +struct JSXMLFilter +{ + JSXML *list; + JSXML *result; + JSXML *kid; + JSXMLArrayCursor cursor; + JSXMLFilter(JSXML *list, JSXMLArray *array) + : list(list), result(__null), kid(__null), cursor(array) {} + ~JSXMLFilter() {} +}; +static void +xmlfilter_trace(JSTracer *trc, JSObject *obj) +{ + JSXMLFilter *filter = (JSXMLFilter *) obj->getPrivate(); + if (!filter) + return; + ((void) 0); + do { do { } while (0); JS_CallTracer((trc), (filter->list), (2)); } while (0); + if (filter->result) + do { do { } while (0); JS_CallTracer((trc), (filter->result), (2)); } while (0); + if (filter->kid) + do { do { } while (0); JS_CallTracer((trc), (filter->kid), (2)); } while (0); +} +static void +xmlfilter_finalize(JSContext *cx, JSObject *obj) +{ + JSXMLFilter *filter = (JSXMLFilter *) obj->getPrivate(); + if (!filter) + return; + cx->destroy(filter); +} +Class js_XMLFilterClass = { + "XMLFilter", + (1<<0) | (1<<((8 + 8)+1)) | (1<<((8 + 8)+3)), + PropertyStub, + PropertyStub, + PropertyStub, + StrictPropertyStub, + EnumerateStub, + ResolveStub, + ConvertStub, + xmlfilter_finalize, + __null, + __null, + __null, + __null, + __null, + __null, + ((JSMarkOp)(xmlfilter_trace)) +}; +JSBool +js_StepXMLListFilter(JSContext *cx, JSBool initialized) +{ + jsval *sp; + JSObject *obj, *filterobj, *resobj, *kidobj; + JSXML *xml, *list; + JSXMLFilter *filter; + LeaveTrace(cx); + sp = Jsvalify(cx->regs->sp); + if (!initialized) { + if (!(!JSVAL_IS_PRIMITIVE(sp[-2]) && JSVAL_TO_OBJECT(sp[-2])->isXML())) { + ((void)js_ReportValueErrorFlags(cx, 0x0, JSMSG_NON_XML_FILTER, -2, Valueify(sp[-2]), __null, __null, __null)); + return (JSIntn)0; + } + obj = JSVAL_TO_OBJECT(sp[-2]); + xml = (JSXML *) obj->getPrivate(); + if (xml->xml_class == JSXML_CLASS_LIST) { + list = xml; + } else { + obj = js_NewXMLObject(cx, JSXML_CLASS_LIST); + if (!obj) + return (JSIntn)0; + sp[-1] = OBJECT_TO_JSVAL(obj); + list = (JSXML *) obj->getPrivate(); + if (!Append(cx, list, xml)) + return (JSIntn)0; + } + filterobj = NewNonFunction(cx, &js_XMLFilterClass, __null, __null); + if (!filterobj) + return (JSIntn)0; + filter = cx->create(list, &list->u.list.kids); + if (!filter) + return (JSIntn)0; + filterobj->setPrivate(filter); + sp[-2] = OBJECT_TO_JSVAL(filterobj); + resobj = js_NewXMLObject(cx, JSXML_CLASS_LIST); + if (!resobj) + return (JSIntn)0; + filter->result = (JSXML *) resobj->getPrivate(); + } else { + ((void) 0); + ((void) 0); + filter = (JSXMLFilter *) JSVAL_TO_OBJECT(sp[-2])->getPrivate(); + ((void) 0); + if (js_ValueToBoolean(Valueify(sp[-1])) && + !Append(cx, filter->result, filter->kid)) { + return (JSIntn)0; + } + } + filter->kid = (JSXML *) filter->cursor.getNext(); + if (!filter->kid) { + filter->cursor.disconnect(); + ((void) 0); + sp[-2] = OBJECT_TO_JSVAL(filter->result->object); + kidobj = __null; + } else { + kidobj = js_GetXMLObject(cx, filter->kid); + if (!kidobj) + return (JSIntn)0; + } + sp[-1] = OBJECT_TO_JSVAL(kidobj); + return (JSIntn)1; +} +JSObject * +js_ValueToXMLObject(JSContext *cx, const Value &v) +{ + return ToXML(cx, Jsvalify(v)); +} +JSObject * +js_ValueToXMLListObject(JSContext *cx, const Value &v) +{ + return ToXMLList(cx, Jsvalify(v)); +} +JSObject * +js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name, + JSString *value) +{ + uintN flags; + JSObject *obj; + JSXML *xml; + JSObject *qn; + if (!GetXMLSettingFlags(cx, &flags)) + return __null; + if ((xml_class == JSXML_CLASS_COMMENT && + (flags & ((JSUint32)1 << (0)))) || + (xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION && + (flags & ((JSUint32)1 << (1))))) { + return js_NewXMLObject(cx, JSXML_CLASS_TEXT); + } + obj = js_NewXMLObject(cx, xml_class); + if (!obj) + return __null; + xml = (JSXML *) obj->getPrivate(); + if (name) { + JSLinearString *linearName = name->ensureLinear(cx); + if (!linearName) + return __null; + qn = NewXMLQName(cx, cx->runtime->emptyString, __null, linearName); + if (!qn) + return __null; + xml->name = qn; + } + xml->u.value = value; + return obj; +} +JSString * +js_MakeXMLCDATAString(JSContext *cx, JSString *str) +{ + StringBuffer sb(cx); + return MakeXMLCDATAString(cx, sb, str); +} +JSString * +js_MakeXMLCommentString(JSContext *cx, JSString *str) +{ + StringBuffer sb(cx); + return MakeXMLCommentString(cx, sb, str); +} +JSString * +js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str) +{ + StringBuffer sb(cx); + return MakeXMLPIString(cx, sb, name, str); +}