1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[mujs] scroll2 and scroll3

This commit is contained in:
Witold Filipczyk 2022-08-20 20:52:26 +02:00
parent 7c31c7ce25
commit 6e90827d3f
5 changed files with 51 additions and 32 deletions

View File

@ -353,7 +353,7 @@ ecmascript_eval(struct ecmascript_interpreter *interpreter,
#ifdef CONFIG_MUJS
static void
ecmascript_call_function(struct ecmascript_interpreter *interpreter,
void *fun, struct string *ret)
const char *fun, struct string *ret)
#elif defined(CONFIG_QUICKJS)
static void
ecmascript_call_function(struct ecmascript_interpreter *interpreter,
@ -369,7 +369,7 @@ ecmascript_call_function(struct ecmascript_interpreter *interpreter,
assert(interpreter);
interpreter->backend_nesting++;
#ifdef CONFIG_MUJS
;
mujs_call_function(interpreter, fun, ret);
#elif defined(CONFIG_QUICKJS)
quickjs_call_function(interpreter, fun, ret);
#else
@ -587,7 +587,7 @@ ecmascript_timeout_handler(void *i)
check_for_rerender(interpreter, "handler");
}
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
/* Timer callback for @interpreter->vs->doc_view->document->timeout.
* As explained in @install_timer, this function must erase the
* expired timer ID from all variables. */
@ -601,7 +601,6 @@ ecmascript_timeout_handler2(void *i)
interpreter->vs->ecmascript_fragile);
interpreter->vs->doc_view->document->timeout = TIMER_ID_UNDEF;
/* The expired timer ID has now been erased. */
ecmascript_call_function(interpreter, interpreter->fun, NULL);
check_for_rerender(interpreter, "handler2");
}
@ -673,6 +672,28 @@ ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValueCons
}
#endif
#ifdef CONFIG_MUJS
timer_id_T
ecmascript_set_timeout2m(struct ecmascript_interpreter *interpreter, const char *handle, int timeout)
{
assert(interpreter && interpreter->vs->doc_view->document);
if (interpreter->code.source) {
done_string(&interpreter->code);
}
if (!init_string(&interpreter->code)) {
return TIMER_ID_UNDEF;
}
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
kill_timer(&interpreter->vs->doc_view->document->timeout);
}
interpreter->fun = handle;
install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler2, interpreter);
return interpreter->vs->doc_view->document->timeout;
}
#endif
static void
init_ecmascript_module(struct module *module)
{

View File

@ -85,10 +85,12 @@ struct ecmascript_interpreter {
#endif
#ifdef CONFIG_QUICKJS
JSValueConst fun;
#else
#endif
#ifdef CONFIG_ECMASCRIPT_SMJS
JS::RootedValue fun;
#endif
#ifdef CONFIG_MUJS
const char *fun;
#endif
bool changed;
};
@ -147,6 +149,10 @@ timer_id_T ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, J
timer_id_T ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValue f, int timeout);
#endif
#ifdef CONFIG_MUJS
timer_id_T ecmascript_set_timeout2m(struct ecmascript_interpreter *interpreter, const char *handle, int timeout);
#endif
int get_ecmascript_enable(struct ecmascript_interpreter *interpreter);
void check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text);

View File

@ -238,26 +238,14 @@ mujs_eval(struct ecmascript_interpreter *interpreter,
void
mujs_call_function(struct ecmascript_interpreter *interpreter,
void *fun, struct string *ret)
const char *fun, struct string *ret)
{
#if 0
JSContext *ctx;
assert(interpreter);
// if (!js_module_init_ok) {
// return;
// }
ctx = (JSContext *)interpreter->backend_data;
interpreter->heartbeat = add_heartbeat(interpreter);
js_State *J = (js_State *)interpreter->backend_data;
interpreter->ret = ret;
JSValue r = JS_Call(ctx, fun, JS_GetGlobalObject(ctx), 0, nullptr);
done_heartbeat(interpreter->heartbeat);
if (JS_IsException(r)) {
error_reporter(interpreter, ctx);
}
#endif
js_getregistry(J, fun); /* retrieve the js function from the registry */
js_pushnull(J);
js_pcall(J, 0);
js_pop(J, 1);
}
char *

View File

@ -38,8 +38,7 @@ void mujs_put_interpreter(struct ecmascript_interpreter *interpreter);
void mujs_eval(struct ecmascript_interpreter *interpreter, struct string *code, struct string *ret);
char *mujs_eval_stringback(struct ecmascript_interpreter *interpreter, struct string *code);
int mujs_eval_boolback(struct ecmascript_interpreter *interpreter, struct string *code);
//void mujs_call_function(struct ecmascript_interpreter *interpreter, JSValueConst fun, struct string *ret);
void mujs_call_function(struct ecmascript_interpreter *interpreter, const char *fun, struct string *ret);
void addmethod(js_State *J, const char *name, js_CFunction fun, int n);
void addproperty(js_State *J, const char *name, js_CFunction getfun, js_CFunction setfun);

View File

@ -361,6 +361,8 @@ end:
js_pushboolean(J, ret);
}
const char *handle = NULL;
static void
mjs_window_setTimeout(js_State *J)
{
@ -392,13 +394,16 @@ mjs_window_setTimeout(js_State *J)
return;
}
} else {
//func = argv[0];
// if (JS_IsFunction(ctx, func)) {
// timer_id_T id = ecmascript_set_timeout2q(interpreter, JS_DupValue(ctx, func), timeout);
//
// return JS_NewInt64(ctx, reinterpret_cast<int64_t>(id));
// }
if (handle) {
js_unref(J, handle);
}
js_copy(J, 1);
handle = js_ref(J);
timer_id_T id = ecmascript_set_timeout2m(interpreter, handle, timeout);
char res[32];
snprintf(res, 31, "%ld", (int64_t)id);
js_pushstring(J, res);
return;
}
js_pushundefined(J);
return;