2 #ifndef EL__ECMASCRIPT_SPIDERMONKEY_UTIL_H
3 #define EL__ECMASCRIPT_SPIDERMONKEY_UTIL_H
5 #include "ecmascript/spidermonkey-shared.h"
6 #include "util/memory.h"
8 static void string_to_jsval(JSContext
*ctx
, jsval
*vp
, unsigned char *string
);
9 static void astring_to_jsval(JSContext
*ctx
, jsval
*vp
, unsigned char *string
);
10 static void int_to_jsval(JSContext
*ctx
, jsval
*vp
, int number
);
11 static void object_to_jsval(JSContext
*ctx
, jsval
*vp
, JSObject
*object
);
12 static void boolean_to_jsval(JSContext
*ctx
, jsval
*vp
, int boolean
);
14 static int jsval_to_boolean(JSContext
*ctx
, jsval
*vp
);
18 /** Inline functions */
21 string_to_jsval(JSContext
*ctx
, jsval
*vp
, unsigned char *string
)
26 *vp
= STRING_TO_JSVAL(JS_NewStringCopyZ(ctx
, string
));
31 astring_to_jsval(JSContext
*ctx
, jsval
*vp
, unsigned char *string
)
33 string_to_jsval(ctx
, vp
, string
);
38 int_to_jsval(JSContext
*ctx
, jsval
*vp
, int number
)
40 *vp
= INT_TO_JSVAL(number
);
44 object_to_jsval(JSContext
*ctx
, jsval
*vp
, JSObject
*object
)
46 *vp
= OBJECT_TO_JSVAL(object
);
50 boolean_to_jsval(JSContext
*ctx
, jsval
*vp
, int boolean
)
52 *vp
= BOOLEAN_TO_JSVAL(boolean
);
57 jsval_to_boolean(JSContext
*ctx
, jsval
*vp
)
61 if (JS_ConvertValue(ctx
, *vp
, JSTYPE_BOOLEAN
, &val
) == JS_FALSE
) {
65 return JSVAL_TO_BOOLEAN(val
);
68 static inline JSObject
*
69 jsval_to_object(JSContext
*ctx
, jsval
*vp
)
73 if (JS_ConvertValue(ctx
, *vp
, JSTYPE_OBJECT
, &val
) == JS_FALSE
) {
77 return JSVAL_TO_OBJECT(val
);