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

[quickjs] scroll2.html works

This commit is contained in:
Witold Filipczyk 2021-11-12 21:53:31 +01:00
parent 28fba3eab3
commit 38060fea51
6 changed files with 29 additions and 43 deletions

View File

@ -336,10 +336,15 @@ ecmascript_eval(struct ecmascript_interpreter *interpreter,
interpreter->backend_nesting--;
}
#ifdef CONFIG_ECMASCRIPT_SMJS
#ifdef CONFIG_QUICKJS
static void
ecmascript_call_function(struct ecmascript_interpreter *interpreter,
JSValueConst fun, struct string *ret)
#else
static void
ecmascript_call_function(struct ecmascript_interpreter *interpreter,
JS::HandleValue fun, struct string *ret)
#endif
{
if (!get_ecmascript_enable(interpreter))
return;
@ -352,7 +357,6 @@ ecmascript_call_function(struct ecmascript_interpreter *interpreter,
#endif
interpreter->backend_nesting--;
}
#endif
char *
ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter,
@ -556,7 +560,7 @@ ecmascript_timeout_handler(void *i)
check_for_rerender(interpreter, "handler");
}
#ifdef CONFIG_ECMASCRIPT_SMJS
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
/* 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. */
@ -605,17 +609,14 @@ ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleVa
#ifdef CONFIG_QUICKJS
void
ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValue f, int timeout)
ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValueConst fun, int timeout)
{
#if 0
assert(interpreter && interpreter->vs->doc_view->document);
done_string(&interpreter->code);
init_string(&interpreter->code);
kill_timer(&interpreter->vs->doc_view->document->timeout);
JS::RootedValue fun((JSContext *)interpreter->backend_data, f);
interpreter->fun = fun;
install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler2, interpreter);
#endif
}
#endif

View File

@ -82,7 +82,9 @@ struct ecmascript_interpreter {
void *document_obj;
void *location_obj;
#endif
#ifdef CONFIG_ECMASCRIPT_SMJS
#ifdef CONFIG_QUICKJS
JSValueConst fun;
#else
JS::RootedValue fun;
#endif
bool changed;

View File

@ -382,33 +382,26 @@ quickjs_eval(struct ecmascript_interpreter *interpreter,
done_heartbeat(interpreter->heartbeat);
}
#if 0
void
quickjs_call_function(struct ecmascript_interpreter *interpreter,
JS::HandleValue fun, struct string *ret)
JSValueConst fun, struct string *ret)
{
#if 0
JSContext *ctx;
JS::Value rval;
assert(interpreter);
if (!js_module_init_ok) {
return;
}
// if (!js_module_init_ok) {
// return;
// }
ctx = interpreter->backend_data;
JS::Realm *comp = JS::EnterRealm(ctx, interpreter->ac);
// JS::Realm *comp = JS::EnterRealm(ctx, interpreter->ac);
interpreter->heartbeat = add_heartbeat(interpreter);
interpreter->ret = ret;
JS::RootedValue r_val(ctx, rval);
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
JS_CallFunctionValue(ctx, cg, fun, JS::HandleValueArray::empty(), &r_val);
JS_Call(ctx, fun, JS_GetGlobalObject(ctx), 0, nullptr);
done_heartbeat(interpreter->heartbeat);
JS::LeaveRealm(ctx, comp);
#endif
}
#endif
char *
quickjs_eval_stringback(struct ecmascript_interpreter *interpreter,

View File

@ -19,7 +19,7 @@ void quickjs_eval(struct ecmascript_interpreter *interpreter, struct string *cod
char *quickjs_eval_stringback(struct ecmascript_interpreter *interpreter, struct string *code);
int quickjs_eval_boolback(struct ecmascript_interpreter *interpreter, struct string *code);
//void quickjs_call_function(struct ecmascript_interpreter *interpreter, JS::HandleValue fun, struct string *ret);
void quickjs_call_function(struct ecmascript_interpreter *interpreter, JSValueConst fun, struct string *ret);
extern struct module quickjs_module;
#endif

View File

@ -201,34 +201,24 @@ js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
const char *code;
int timeout = 0;
int64_t timeout = 0;
JSValueConst func;
func = argv[0];
if (argc != 2) {
return JS_UNDEFINED;
}
JS_ToInt32(ctx, &timeout, argv[1]);
if (!JS_IsFunction(ctx, func))
return JS_ThrowTypeError(ctx, "not a function");
if (JS_ToInt64(ctx, &timeout, argv[1]))
return JS_EXCEPTION;
if (timeout <= 0) {
return JS_UNDEFINED;
}
if (JS_IsString(argv[0])) {
size_t len;
code = JS_ToCStringLen(ctx, &len, argv[0]);
if (!code) {
return JS_EXCEPTION;
}
ecmascript_set_timeout(interpreter, code, timeout);
return JS_UNDEFINED;
}
ecmascript_set_timeout2q(interpreter, argv[0], timeout);
ecmascript_set_timeout2q(interpreter, func, timeout);
return JS_UNDEFINED;
}
static JSValue
js_window_get_property_closed(JSContext *ctx, JSValueConst this_val)
{

View File

@ -8,7 +8,7 @@ function scrollText() {
}
function scroll() {
document.getElementById('s').innerHTML = scrollText();
setTimeout(scroll, 100);
window.setTimeout(scroll, 100);
}
</script>
</head>