952, 954: Add spidermonkey_empty_context
[elinks.git] / src / ecmascript / spidermonkey-shared.h
blob4cc0eebc87a8c69bdd09f1813f541e401d0e701c
1 #ifndef EL__ECMASCRIPT_SPIDERMONKEY_SHARED_H
2 #define EL__ECMASCRIPT_SPIDERMONKEY_SHARED_H
4 /* For wild SpiderMonkey installations. */
5 #ifdef CONFIG_OS_BEOS
6 #define XP_BEOS
7 #elif CONFIG_OS_OS2
8 #define XP_OS2
9 #elif CONFIG_OS_RISCOS
10 #error Out of luck, buddy!
11 #elif CONFIG_OS_UNIX
12 #define XP_UNIX
13 #elif CONFIG_OS_WIN32
14 #define XP_WIN
15 #endif
17 #include <jsapi.h>
19 #include "util/string.h"
21 extern JSRuntime *spidermonkey_runtime;
22 extern JSContext *spidermonkey_empty_context;
23 int spidermonkey_runtime_addref(void);
24 void spidermonkey_runtime_release(void);
26 /** An ELinks-specific replacement for JSFunctionSpec.
28 * Bug 1016: In SpiderMonkey 1.7 bundled with XULRunner 1.8, jsapi.h
29 * defines JSFunctionSpec in different ways depending on whether
30 * MOZILLA_1_8_BRANCH is defined, and there is no obvious way for
31 * ELinks to check whether MOZILLA_1_8_BRANCH was defined when the
32 * library was built. Avoid the unstable JSFunctionSpec definitions
33 * and use this ELinks-specific structure instead. */
34 typedef struct spidermonkeyFunctionSpec {
35 const char *name;
36 JSNative call;
37 uint8 nargs;
38 /* ELinks does not use "flags" and "extra" so omit them here. */
39 } spidermonkeyFunctionSpec;
41 JSBool spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj,
42 const spidermonkeyFunctionSpec *fs);
43 JSObject *spidermonkey_InitClass(JSContext *cx, JSObject *obj,
44 JSObject *parent_proto, JSClass *clasp,
45 JSNative constructor, uintN nargs,
46 JSPropertySpec *ps,
47 const spidermonkeyFunctionSpec *fs,
48 JSPropertySpec *static_ps,
49 const spidermonkeyFunctionSpec *static_fs);
51 static void undef_to_jsval(JSContext *ctx, jsval *vp);
52 static unsigned char *jsval_to_string(JSContext *ctx, jsval *vp);
54 /* Inline functions */
56 static inline void
57 undef_to_jsval(JSContext *ctx, jsval *vp)
59 *vp = JSVAL_NULL;
62 static inline unsigned char *
63 jsval_to_string(JSContext *ctx, jsval *vp)
65 jsval val;
67 if (JS_ConvertValue(ctx, *vp, JSTYPE_STRING, &val) == JS_FALSE) {
68 return "";
71 return empty_string_or_(JS_GetStringBytes(JS_ValueToString(ctx, val)));
74 #endif