mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[smjs] Maybe it is not correct, but spidermonkey and smjs work together.
This commit is contained in:
parent
873797935c
commit
477e56eb43
@ -53,7 +53,7 @@ JSObject *spidermonkey_InitClass(JSContext *cx, JSObject *obj,
|
||||
JSPropertySpec *static_ps,
|
||||
const spidermonkeyFunctionSpec *static_fs);
|
||||
|
||||
static unsigned char *jsval_to_string(JSContext *ctx, JS::Value *vp);
|
||||
static unsigned char *jsval_to_string(JSContext *ctx, JS::HandleValue hvp);
|
||||
static unsigned char *jsid_to_string(JSContext *ctx, JS::HandleId hid);
|
||||
|
||||
/* Inline functions */
|
||||
|
@ -43,9 +43,8 @@ heartbeat_callback(JSContext *ctx)
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(comp);
|
||||
// struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
|
||||
|
||||
if (!interpreter->heartbeat || interpreter->heartbeat->ttl > 0) {
|
||||
if (!interpreter || !interpreter->heartbeat || interpreter->heartbeat->ttl > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -29,7 +29,6 @@ JSContext *smjs_ctx;
|
||||
JSObject *smjs_elinks_object;
|
||||
struct session *smjs_ses;
|
||||
|
||||
|
||||
void
|
||||
alert_smjs_error(unsigned char *msg)
|
||||
{
|
||||
@ -184,6 +183,9 @@ smjs_do_file(unsigned char *path)
|
||||
opts.setNoScriptRval(true);
|
||||
JS::RootedValue rval(smjs_ctx);
|
||||
|
||||
JS_BeginRequest(smjs_ctx);
|
||||
JSCompartment *prev = JS_EnterCompartment(smjs_ctx, smjs_elinks_object);
|
||||
|
||||
if (!add_file_to_string(&script, path)
|
||||
|| false == JS::Evaluate(smjs_ctx, opts,
|
||||
script.source, script.length, &rval)) {
|
||||
@ -191,6 +193,8 @@ smjs_do_file(unsigned char *path)
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
JS_LeaveCompartment(smjs_ctx, prev);
|
||||
JS_EndRequest(smjs_ctx);
|
||||
done_string(&script);
|
||||
|
||||
return ret;
|
||||
@ -234,7 +238,7 @@ init_smjs(struct module *module)
|
||||
{
|
||||
if (!spidermonkey_runtime_addref()) return;
|
||||
|
||||
smjs_ctx = JS_NewContext(8L * 1024 * 1024);
|
||||
smjs_ctx = main_ctx; //JS_NewContext(8L * 1024 * 1024);
|
||||
if (!smjs_ctx) {
|
||||
spidermonkey_runtime_release();
|
||||
return;
|
||||
@ -268,7 +272,7 @@ cleanup_smjs(struct module *module)
|
||||
* If the garbage collector were conservative, ELinks would
|
||||
* have to call smjs_detach_cache_entry_object on each cache
|
||||
* entry before it releases the runtime here. */
|
||||
JS_DestroyContext(smjs_ctx);
|
||||
//JS_DestroyContext(smjs_ctx);
|
||||
spidermonkey_runtime_release();
|
||||
}
|
||||
|
||||
|
@ -30,20 +30,18 @@ static JSObject *
|
||||
smjs_get_global_object(void)
|
||||
{
|
||||
assert(smjs_ctx);
|
||||
JSAutoCompartment *acc = NULL;
|
||||
|
||||
JSAutoRequest ar(smjs_ctx);
|
||||
JS::CompartmentOptions opts;
|
||||
|
||||
if (!JS::InitSelfHostedCode(smjs_ctx)) {
|
||||
return NULL;
|
||||
}
|
||||
// if (!JS::InitSelfHostedCode(smjs_ctx)) {
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
JS::RootedObject jsobj(smjs_ctx, JS_NewGlobalObject(smjs_ctx, (JSClass *) &global_class, NULL, JS::DontFireOnNewGlobalHook, opts));
|
||||
|
||||
if (!jsobj) return NULL;
|
||||
|
||||
acc = new JSAutoCompartment(smjs_ctx, jsobj);
|
||||
new JSAutoCompartment(smjs_ctx, jsobj);
|
||||
|
||||
JS_InitStandardClasses(smjs_ctx, jsobj);
|
||||
|
||||
|
@ -27,11 +27,15 @@ script_hook_url(va_list ap, void *data)
|
||||
unsigned char **url = va_arg(ap, unsigned char **);
|
||||
struct session *ses = va_arg(ap, struct session *);
|
||||
enum evhook_status ret = EVENT_HOOK_STATUS_NEXT;
|
||||
|
||||
JS::Value args[3];
|
||||
JS::RootedValue r_rval(smjs_ctx);
|
||||
|
||||
if (*url == NULL) return EVENT_HOOK_STATUS_NEXT;
|
||||
|
||||
JS_BeginRequest(smjs_ctx);
|
||||
JSCompartment *prev = JS_EnterCompartment(smjs_ctx, smjs_elinks_object);
|
||||
|
||||
smjs_ses = ses;
|
||||
args[2].setString(JS_NewStringCopyZ(smjs_ctx, *url));
|
||||
|
||||
@ -48,6 +52,8 @@ script_hook_url(va_list ap, void *data)
|
||||
}
|
||||
|
||||
smjs_ses = NULL;
|
||||
JS_LeaveCompartment(smjs_ctx, prev);
|
||||
JS_EndRequest(smjs_ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -62,6 +68,9 @@ script_hook_pre_format_html(va_list ap, void *data)
|
||||
JS::Value args[4];
|
||||
JS::RootedValue r_rval(smjs_ctx);
|
||||
|
||||
JS_BeginRequest(smjs_ctx);
|
||||
JSCompartment *prev = JS_EnterCompartment(smjs_ctx, smjs_elinks_object);
|
||||
|
||||
evhook_use_params(ses && cached);
|
||||
|
||||
if (!smjs_ctx || !cached->length) {
|
||||
@ -70,6 +79,7 @@ script_hook_pre_format_html(va_list ap, void *data)
|
||||
|
||||
smjs_ses = ses;
|
||||
|
||||
|
||||
if (have_location(ses)) {
|
||||
struct view_state *vs = &cur_loc(ses)->vs;
|
||||
|
||||
@ -88,7 +98,10 @@ script_hook_pre_format_html(va_list ap, void *data)
|
||||
ret = EVENT_HOOK_STATUS_LAST;
|
||||
}
|
||||
|
||||
|
||||
end:
|
||||
JS_LeaveCompartment(smjs_ctx, prev);
|
||||
JS_EndRequest(smjs_ctx);
|
||||
smjs_ses = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
@ -1056,22 +1056,21 @@ static bool
|
||||
session_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||
{
|
||||
ELINKS_CAST_PROP_PARAMS
|
||||
jsid id = hid.get();
|
||||
|
||||
JSObject *tabobj;
|
||||
struct terminal *term = JS_GetPrivate(obj);
|
||||
int index;
|
||||
struct window *tab;
|
||||
|
||||
undef_to_jsval(ctx, vp);
|
||||
hvp.setUndefined();
|
||||
|
||||
if (!JSID_IS_INT(id))
|
||||
if (!JSID_IS_INT(hid))
|
||||
return false;
|
||||
|
||||
assert(term);
|
||||
if_assert_failed return true;
|
||||
|
||||
index = JSID_TO_INT(id);
|
||||
index = JSID_TO_INT(hid);
|
||||
foreach_tab (tab, term->windows) {
|
||||
if (!index) break;
|
||||
--index;
|
||||
@ -1079,7 +1078,9 @@ session_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
|
||||
if ((void *) tab == (void *) &term->windows) return false;
|
||||
|
||||
tabobj = smjs_get_session_object(tab->data);
|
||||
if (tabobj) object_to_jsval(ctx, vp, tabobj);
|
||||
if (tabobj) {
|
||||
hvp.setObject(*tabobj);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user