iconv: Bail out of the loop when an illegal sequence of bytes occurs.
[elinks/elinks-j605.git] / src / ecmascript / spidermonkey / util.h
blobb02bc20b1d8a93bfc8f35455d078a15afa7c54ba
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 */
20 static inline void
21 string_to_jsval(JSContext *ctx, jsval *vp, unsigned char *string)
23 if (!string) {
24 *vp = JSVAL_NULL;
25 } else {
26 *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(ctx, string));
30 static inline void
31 astring_to_jsval(JSContext *ctx, jsval *vp, unsigned char *string)
33 string_to_jsval(ctx, vp, string);
34 mem_free_if(string);
37 static inline void
38 int_to_jsval(JSContext *ctx, jsval *vp, int number)
40 *vp = INT_TO_JSVAL(number);
43 static inline void
44 object_to_jsval(JSContext *ctx, jsval *vp, JSObject *object)
46 *vp = OBJECT_TO_JSVAL(object);
49 static inline void
50 boolean_to_jsval(JSContext *ctx, jsval *vp, int boolean)
52 *vp = BOOLEAN_TO_JSVAL(boolean);
56 static inline int
57 jsval_to_boolean(JSContext *ctx, jsval *vp)
59 jsval val;
61 if (JS_ConvertValue(ctx, *vp, JSTYPE_BOOLEAN, &val) == JS_FALSE) {
62 return JS_FALSE;
65 return JSVAL_TO_BOOLEAN(val);
68 static inline JSObject *
69 jsval_to_object(JSContext *ctx, jsval *vp)
71 jsval val;
73 if (JS_ConvertValue(ctx, *vp, JSTYPE_OBJECT, &val) == JS_FALSE) {
74 return NULL;
77 return JSVAL_TO_OBJECT(val);
80 #endif