1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-28 01:35:32 +00: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--; 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 static void
ecmascript_call_function(struct ecmascript_interpreter *interpreter, ecmascript_call_function(struct ecmascript_interpreter *interpreter,
JS::HandleValue fun, struct string *ret) JS::HandleValue fun, struct string *ret)
#endif
{ {
if (!get_ecmascript_enable(interpreter)) if (!get_ecmascript_enable(interpreter))
return; return;
@ -352,7 +357,6 @@ ecmascript_call_function(struct ecmascript_interpreter *interpreter,
#endif #endif
interpreter->backend_nesting--; interpreter->backend_nesting--;
} }
#endif
char * char *
ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter, ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter,
@ -556,7 +560,7 @@ ecmascript_timeout_handler(void *i)
check_for_rerender(interpreter, "handler"); 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. /* Timer callback for @interpreter->vs->doc_view->document->timeout.
* As explained in @install_timer, this function must erase the * As explained in @install_timer, this function must erase the
* expired timer ID from all variables. */ * expired timer ID from all variables. */
@ -605,17 +609,14 @@ ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleVa
#ifdef CONFIG_QUICKJS #ifdef CONFIG_QUICKJS
void 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); assert(interpreter && interpreter->vs->doc_view->document);
done_string(&interpreter->code); done_string(&interpreter->code);
init_string(&interpreter->code); init_string(&interpreter->code);
kill_timer(&interpreter->vs->doc_view->document->timeout); kill_timer(&interpreter->vs->doc_view->document->timeout);
JS::RootedValue fun((JSContext *)interpreter->backend_data, f);
interpreter->fun = fun; interpreter->fun = fun;
install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler2, interpreter); install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler2, interpreter);
#endif
} }
#endif #endif

View File

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

View File

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

View File

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

View File

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