2008-07-16 05:32:24 -04:00
|
|
|
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_SHARED_H
|
|
|
|
#define EL__ECMASCRIPT_SPIDERMONKEY_SHARED_H
|
|
|
|
|
2011-05-01 16:41:44 -04:00
|
|
|
/* Tell SpiderMonkey headers which operating system will be used.
|
|
|
|
* With standalone SpiderMonkey 1.8.5, "pkg-config --cflags mozjs185"
|
|
|
|
* does not define such a macro, so ELinks must do that here.
|
|
|
|
* With xulrunner 2.0 however, "pkg-config --cflags mozilla-js"
|
|
|
|
* already outputs -DXP_UNIX or similar. To prevent a warning about
|
|
|
|
* macro redefinition, define the macro as 1, like -D does. */
|
2008-07-16 05:32:24 -04:00
|
|
|
#ifdef CONFIG_OS_BEOS
|
2011-05-01 16:41:44 -04:00
|
|
|
#define XP_BEOS 1
|
2008-07-16 05:32:24 -04:00
|
|
|
#elif CONFIG_OS_OS2
|
2011-05-01 16:41:44 -04:00
|
|
|
#define XP_OS2 1
|
2008-07-16 05:32:24 -04:00
|
|
|
#elif CONFIG_OS_RISCOS
|
|
|
|
#error Out of luck, buddy!
|
|
|
|
#elif CONFIG_OS_UNIX
|
2011-05-01 16:41:44 -04:00
|
|
|
#define XP_UNIX 1
|
2008-07-16 05:32:24 -04:00
|
|
|
#elif CONFIG_OS_WIN32
|
2011-05-01 16:41:44 -04:00
|
|
|
#define XP_WIN 1
|
2008-07-16 05:32:24 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <jsapi.h>
|
|
|
|
|
|
|
|
#include "util/string.h"
|
|
|
|
|
2008-07-16 07:23:19 -04:00
|
|
|
extern JSRuntime *spidermonkey_runtime;
|
2020-10-28 17:32:20 -04:00
|
|
|
extern JSContext *main_ctx;
|
2008-07-16 07:23:19 -04:00
|
|
|
int spidermonkey_runtime_addref(void);
|
|
|
|
void spidermonkey_runtime_release(void);
|
|
|
|
|
2008-07-16 05:32:24 -04:00
|
|
|
/** An ELinks-specific replacement for JSFunctionSpec.
|
|
|
|
*
|
|
|
|
* Bug 1016: In SpiderMonkey 1.7 bundled with XULRunner 1.8, jsapi.h
|
|
|
|
* defines JSFunctionSpec in different ways depending on whether
|
|
|
|
* MOZILLA_1_8_BRANCH is defined, and there is no obvious way for
|
|
|
|
* ELinks to check whether MOZILLA_1_8_BRANCH was defined when the
|
|
|
|
* library was built. Avoid the unstable JSFunctionSpec definitions
|
|
|
|
* and use this ELinks-specific structure instead. */
|
|
|
|
typedef struct spidermonkeyFunctionSpec {
|
|
|
|
const char *name;
|
|
|
|
JSNative call;
|
2019-02-10 15:00:37 -05:00
|
|
|
uint8_t nargs;
|
2008-07-16 05:32:24 -04:00
|
|
|
/* ELinks does not use "flags" and "extra" so omit them here. */
|
|
|
|
} spidermonkeyFunctionSpec;
|
|
|
|
|
2020-10-11 09:41:27 -04:00
|
|
|
bool spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj,
|
2008-07-16 05:32:24 -04:00
|
|
|
const spidermonkeyFunctionSpec *fs);
|
|
|
|
JSObject *spidermonkey_InitClass(JSContext *cx, JSObject *obj,
|
|
|
|
JSObject *parent_proto, JSClass *clasp,
|
2019-02-10 15:00:37 -05:00
|
|
|
JSNative constructor, unsigned int nargs,
|
2008-07-16 05:32:24 -04:00
|
|
|
JSPropertySpec *ps,
|
|
|
|
const spidermonkeyFunctionSpec *fs,
|
|
|
|
JSPropertySpec *static_ps,
|
|
|
|
const spidermonkeyFunctionSpec *static_fs);
|
|
|
|
|
2020-10-23 16:34:58 -04:00
|
|
|
static void undef_to_jsval(JSContext *ctx, JS::Value *vp);
|
|
|
|
static unsigned char *jsval_to_string(JSContext *ctx, JS::Value *vp);
|
2011-04-19 16:41:05 -04:00
|
|
|
static unsigned char *jsid_to_string(JSContext *ctx, jsid *id);
|
2008-07-16 05:32:24 -04:00
|
|
|
|
|
|
|
/* Inline functions */
|
|
|
|
|
|
|
|
static inline void
|
2020-10-23 16:34:58 -04:00
|
|
|
undef_to_jsval(JSContext *ctx, JS::Value *vp)
|
2008-07-16 05:32:24 -04:00
|
|
|
{
|
2020-10-23 16:34:58 -04:00
|
|
|
*vp = JS::NullValue();
|
2008-07-16 05:32:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *
|
2020-10-23 16:34:58 -04:00
|
|
|
jsval_to_string(JSContext *ctx, JS::Value *vp)
|
2008-07-16 05:32:24 -04:00
|
|
|
{
|
2020-10-11 09:41:27 -04:00
|
|
|
JS::RootedValue r_vp(ctx, *vp);
|
2020-10-16 13:54:02 -04:00
|
|
|
JSString *str = r_vp.toString();
|
2008-07-16 05:32:24 -04:00
|
|
|
|
2020-10-11 09:41:27 -04:00
|
|
|
return empty_string_or_(JS_EncodeString(ctx, str));
|
2011-04-19 16:41:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char *
|
|
|
|
jsid_to_string(JSContext *ctx, jsid *id)
|
|
|
|
{
|
2020-10-11 09:41:27 -04:00
|
|
|
JS::RootedValue v(ctx);
|
2011-04-19 16:41:05 -04:00
|
|
|
|
|
|
|
/* TODO: check returned value */
|
|
|
|
JS_IdToValue(ctx, *id, &v);
|
2020-10-11 09:41:27 -04:00
|
|
|
return jsval_to_string(ctx, v.address());
|
2008-07-16 05:32:24 -04:00
|
|
|
}
|
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#define ELINKS_CAST_PROP_PARAMS JSObject *obj = (hobj.get()); \
|
2020-10-23 16:34:58 -04:00
|
|
|
JS::Value *vp = (hvp.address());
|
2019-02-10 15:00:37 -05:00
|
|
|
|
2008-07-16 05:32:24 -04:00
|
|
|
#endif
|