2008-07-16 12:32:24 +03:00
|
|
|
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_SHARED_H
|
|
|
|
#define EL__ECMASCRIPT_SPIDERMONKEY_SHARED_H
|
|
|
|
|
|
|
|
#include <jsapi.h>
|
|
|
|
|
|
|
|
#include "util/string.h"
|
|
|
|
|
2008-07-16 14:23:19 +03:00
|
|
|
extern JSRuntime *spidermonkey_runtime;
|
2020-10-28 22:32:20 +01:00
|
|
|
extern JSContext *main_ctx;
|
2008-07-16 14:23:19 +03:00
|
|
|
int spidermonkey_runtime_addref(void);
|
|
|
|
void spidermonkey_runtime_release(void);
|
|
|
|
|
2008-07-16 12:32:24 +03: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 21:00:37 +01:00
|
|
|
uint8_t nargs;
|
2008-07-16 12:32:24 +03:00
|
|
|
/* ELinks does not use "flags" and "extra" so omit them here. */
|
|
|
|
} spidermonkeyFunctionSpec;
|
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
bool spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj,
|
2008-07-16 12:32:24 +03:00
|
|
|
const spidermonkeyFunctionSpec *fs);
|
|
|
|
JSObject *spidermonkey_InitClass(JSContext *cx, JSObject *obj,
|
|
|
|
JSObject *parent_proto, JSClass *clasp,
|
2019-02-10 21:00:37 +01:00
|
|
|
JSNative constructor, unsigned int nargs,
|
2008-07-16 12:32:24 +03:00
|
|
|
JSPropertySpec *ps,
|
|
|
|
const spidermonkeyFunctionSpec *fs,
|
|
|
|
JSPropertySpec *static_ps,
|
|
|
|
const spidermonkeyFunctionSpec *static_fs);
|
|
|
|
|
2021-08-21 11:30:09 +02:00
|
|
|
bool spidermonkey_check_if_function_name(const spidermonkeyFunctionSpec funcs[], const char *string);
|
|
|
|
|
2021-01-02 16:20:27 +01:00
|
|
|
static char *jsval_to_string(JSContext *ctx, JS::HandleValue hvp);
|
|
|
|
static char *jsid_to_string(JSContext *ctx, JS::HandleId hid);
|
2008-07-16 12:32:24 +03:00
|
|
|
|
|
|
|
/* Inline functions */
|
|
|
|
|
2021-01-02 16:20:27 +01:00
|
|
|
static inline char *
|
2020-11-15 17:55:58 +01:00
|
|
|
jsval_to_string(JSContext *ctx, JS::HandleValue hvp)
|
2008-07-16 12:32:24 +03:00
|
|
|
{
|
2020-11-15 17:55:58 +01:00
|
|
|
// JS::RootedValue r_vp(ctx, *vp);
|
|
|
|
JSString *str = hvp.toString();
|
|
|
|
//JS::RootedString r_str(ctx, str);
|
2008-07-16 12:32:24 +03:00
|
|
|
|
2020-10-11 15:41:27 +02:00
|
|
|
return empty_string_or_(JS_EncodeString(ctx, str));
|
2011-04-19 22:41:05 +02:00
|
|
|
}
|
|
|
|
|
2021-01-02 16:20:27 +01:00
|
|
|
static inline char *
|
2020-11-15 17:55:58 +01:00
|
|
|
jsid_to_string(JSContext *ctx, JS::HandleId hid)
|
2011-04-19 22:41:05 +02:00
|
|
|
{
|
2020-10-11 15:41:27 +02:00
|
|
|
JS::RootedValue v(ctx);
|
2011-04-19 22:41:05 +02:00
|
|
|
|
|
|
|
/* TODO: check returned value */
|
2020-11-15 17:55:58 +01:00
|
|
|
JS_IdToValue(ctx, hid, &v);
|
|
|
|
return jsval_to_string(ctx, v);
|
2008-07-16 12:32:24 +03:00
|
|
|
}
|
|
|
|
|
2020-10-05 20:14:55 +02:00
|
|
|
#define ELINKS_CAST_PROP_PARAMS JSObject *obj = (hobj.get()); \
|
2020-10-23 22:34:58 +02:00
|
|
|
JS::Value *vp = (hvp.address());
|
2019-02-10 21:00:37 +01:00
|
|
|
|
2008-07-16 12:32:24 +03:00
|
|
|
#endif
|