1 #ifndef EL__ECMASCRIPT_SPIDERMONKEY_SHARED_H
2 #define EL__ECMASCRIPT_SPIDERMONKEY_SHARED_H
4 /* For wild SpiderMonkey installations. */
10 #error Out of luck, buddy!
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
{
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
,
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 */
57 undef_to_jsval(JSContext
*ctx
, jsval
*vp
)
62 static inline unsigned char *
63 jsval_to_string(JSContext
*ctx
, jsval
*vp
)
67 if (JS_ConvertValue(ctx
, *vp
, JSTYPE_STRING
, &val
) == JS_FALSE
) {
71 return empty_string_or_(JS_GetStringBytes(JS_ValueToString(ctx
, val
)));