mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[ecmascript] Changed declarations of ecmascript_timeout
Also free functions in quickjs version.
This commit is contained in:
parent
d34ae1371d
commit
937f6b415e
@ -302,6 +302,11 @@ kill_ecmascript_timeouts(struct document *document)
|
||||
foreach(t, document->timeouts) {
|
||||
kill_timer(&t->tid);
|
||||
done_string(&t->code);
|
||||
#ifdef CONFIG_QUICKJS
|
||||
if (!JS_IsNull(t->fun)) {
|
||||
JS_FreeValue(t->ctx, t->fun);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,6 +335,11 @@ ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
foreach (t, interpreter->vs->doc_view->document->timeouts) {
|
||||
kill_timer(&t->tid);
|
||||
done_string(&t->code);
|
||||
#ifdef CONFIG_QUICKJS
|
||||
if (!JS_IsNull(t->fun)) {
|
||||
JS_FreeValue(t->ctx, t->fun);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
free_list(interpreter->vs->doc_view->document->timeouts);
|
||||
}
|
||||
|
@ -491,6 +491,9 @@ ecmascript_timeout_handler2(void *val)
|
||||
/* The expired timer ID has now been erased. */
|
||||
del_from_list(t);
|
||||
done_string(&t->code);
|
||||
#ifdef CONFIG_QUICKJS
|
||||
JS_FreeValue(t->ctx, t->fun);
|
||||
#endif
|
||||
#ifdef CONFIG_MUJS
|
||||
// js_unref(t->ctx, t->fun);
|
||||
#endif
|
||||
@ -502,8 +505,21 @@ ecmascript_timeout_handler2(void *val)
|
||||
#endif
|
||||
|
||||
struct ecmascript_timeout *
|
||||
ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, int timeout, int timeout_next)
|
||||
ecmascript_set_timeout(void *c, char *code, int timeout, int timeout_next)
|
||||
{
|
||||
#ifdef CONFIG_QUICKJS
|
||||
JSContext *ctx = (JSContext *)c;
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
#endif
|
||||
#ifdef CONFIG_ECMASCRIPT_SMJS
|
||||
JSContext *ctx = (JSContext *)c;
|
||||
JS::Realm *comp = js::GetContextRealm((JSContext *)ctx);
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
#endif
|
||||
#ifdef CONFIG_MUJS
|
||||
js_State *ctx = (js_State *)c;
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(ctx);
|
||||
#endif
|
||||
assert(interpreter && interpreter->vs->doc_view->document);
|
||||
if (!code) return NULL;
|
||||
struct ecmascript_timeout *t = (struct ecmascript_timeout *)mem_calloc(1, sizeof(*t));
|
||||
@ -521,7 +537,11 @@ ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, i
|
||||
mem_free(code);
|
||||
|
||||
t->interpreter = interpreter;
|
||||
t->ctx = ctx;
|
||||
t->timeout_next = timeout_next;
|
||||
#ifdef CONFIG_QUICKJS
|
||||
t->fun = JS_NULL;
|
||||
#endif
|
||||
add_to_list(interpreter->vs->doc_view->document->timeouts, t);
|
||||
install_timer(&t->tid, timeout, ecmascript_timeout_handler, t);
|
||||
|
||||
@ -530,8 +550,11 @@ ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, i
|
||||
|
||||
#ifdef CONFIG_ECMASCRIPT_SMJS
|
||||
struct ecmascript_timeout *
|
||||
ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout, int timeout_next)
|
||||
ecmascript_set_timeout2(void *c, JS::HandleValue f, int timeout, int timeout_next)
|
||||
{
|
||||
JSContext *ctx = (JSContext *)c;
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
assert(interpreter && interpreter->vs->doc_view->document);
|
||||
|
||||
struct ecmascript_timeout *t = (struct ecmascript_timeout *)mem_calloc(1, sizeof(*t));
|
||||
@ -544,6 +567,7 @@ ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleVa
|
||||
return NULL;
|
||||
}
|
||||
t->interpreter = interpreter;
|
||||
t->ctx = ctx;
|
||||
t->timeout_next = timeout_next;
|
||||
JS::RootedValue fun((JSContext *)interpreter->backend_data, f);
|
||||
t->fun = fun;
|
||||
@ -556,8 +580,10 @@ ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleVa
|
||||
|
||||
#ifdef CONFIG_QUICKJS
|
||||
struct ecmascript_timeout *
|
||||
ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValueConst fun, int timeout, int timeout_next)
|
||||
ecmascript_set_timeout2q(void *c, JSValueConst fun, int timeout, int timeout_next)
|
||||
{
|
||||
JSContext *ctx = (JSContext *)c;
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
assert(interpreter && interpreter->vs->doc_view->document);
|
||||
struct ecmascript_timeout *t = (struct ecmascript_timeout *)mem_calloc(1, sizeof(*t));
|
||||
|
||||
@ -569,6 +595,7 @@ ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValueCons
|
||||
return NULL;
|
||||
}
|
||||
t->interpreter = interpreter;
|
||||
t->ctx = ctx;
|
||||
t->timeout_next = timeout_next;
|
||||
t->fun = fun;
|
||||
add_to_list(interpreter->vs->doc_view->document->timeouts, t);
|
||||
|
@ -119,9 +119,11 @@ struct ecmascript_timeout {
|
||||
LIST_HEAD_EL(struct ecmascript_timeout);
|
||||
struct string code;
|
||||
#ifdef CONFIG_QUICKJS
|
||||
JSContext *ctx;
|
||||
JSValueConst fun;
|
||||
#endif
|
||||
#ifdef CONFIG_ECMASCRIPT_SMJS
|
||||
JSContext *ctx;
|
||||
JS::RootedValue fun;
|
||||
#endif
|
||||
#ifdef CONFIG_MUJS
|
||||
@ -166,14 +168,14 @@ void ecmascript_timeout_dialog(struct terminal *term, int max_exec_time);
|
||||
|
||||
void ecmascript_set_action(char **action, char *string);
|
||||
|
||||
struct ecmascript_timeout *ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, int timeout, int timeout_next);
|
||||
struct ecmascript_timeout *ecmascript_set_timeout(void *ctx, char *code, int timeout, int timeout_next);
|
||||
|
||||
#ifdef CONFIG_ECMASCRIPT_SMJS
|
||||
struct ecmascript_timeout *ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout, int timeout_next);
|
||||
struct ecmascript_timeout *ecmascript_set_timeout2(void *ctx, JS::HandleValue f, int timeout, int timeout_next);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_QUICKJS
|
||||
struct ecmascript_timeout *ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValue f, int timeout, int timeout_next);
|
||||
struct ecmascript_timeout *ecmascript_set_timeout2q(void *ctx, JSValue f, int timeout, int timeout_next);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MUJS
|
||||
|
@ -467,7 +467,6 @@ mjs_window_setInterval(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
int timeout = js_toint32(J, 2);
|
||||
|
||||
if (timeout <= 0) {
|
||||
@ -485,7 +484,7 @@ mjs_window_setInterval(js_State *J)
|
||||
char *code2 = stracpy(code);
|
||||
|
||||
if (code2) {
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(interpreter, code2, timeout, timeout);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(J, code2, timeout, timeout);
|
||||
char res[32];
|
||||
snprintf(res, 31, "%" PRId64, (int64_t)id);
|
||||
js_pushstring(J, res);
|
||||
@ -511,7 +510,6 @@ mjs_window_setTimeout(js_State *J)
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||
int timeout = js_toint32(J, 2);
|
||||
|
||||
if (timeout <= 0) {
|
||||
@ -529,7 +527,7 @@ mjs_window_setTimeout(js_State *J)
|
||||
char *code2 = stracpy(code);
|
||||
|
||||
if (code2) {
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(interpreter, code2, timeout, -1);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(J, code2, timeout, -1);
|
||||
char res[32];
|
||||
snprintf(res, 31, "%" PRId64, (int64_t)id);
|
||||
js_pushstring(J, res);
|
||||
|
@ -256,8 +256,6 @@ js_window_setInterval(JSContext *ctx, JSValueConst this_val, int argc, JSValueCo
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
int64_t timeout = 0;
|
||||
JSValueConst func;
|
||||
|
||||
@ -276,7 +274,7 @@ js_window_setInterval(JSContext *ctx, JSValueConst this_val, int argc, JSValueCo
|
||||
func = argv[0];
|
||||
|
||||
if (JS_IsFunction(ctx, func)) {
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout2q(interpreter, JS_DupValue(ctx, func), timeout, timeout);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout2q(ctx, JS_DupValue(ctx, func), timeout, timeout);
|
||||
|
||||
return JS_NewInt64(ctx, (int64_t)(id));
|
||||
}
|
||||
@ -291,7 +289,7 @@ js_window_setInterval(JSContext *ctx, JSValueConst this_val, int argc, JSValueCo
|
||||
JS_FreeCString(ctx, code);
|
||||
|
||||
if (code2) {
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(interpreter, code2, timeout, timeout);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(ctx, code2, timeout, timeout);
|
||||
|
||||
return JS_NewInt64(ctx, (int64_t)(id));
|
||||
}
|
||||
@ -309,8 +307,6 @@ js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
REF_JS(this_val);
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
|
||||
int64_t timeout = 0;
|
||||
JSValueConst func;
|
||||
|
||||
@ -329,7 +325,7 @@ js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon
|
||||
func = argv[0];
|
||||
|
||||
if (JS_IsFunction(ctx, func)) {
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout2q(interpreter, JS_DupValue(ctx, func), timeout, -1);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout2q(ctx, JS_DupValue(ctx, func), timeout, -1);
|
||||
|
||||
return JS_NewInt64(ctx, (int64_t)(id));
|
||||
}
|
||||
@ -344,7 +340,7 @@ js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon
|
||||
JS_FreeCString(ctx, code);
|
||||
|
||||
if (code2) {
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(interpreter, code2, timeout, -1);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(ctx, code2, timeout, -1);
|
||||
|
||||
return JS_NewInt64(ctx, (int64_t)(id));
|
||||
}
|
||||
|
@ -584,11 +584,7 @@ window_setInterval(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||
// struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
|
||||
char *code;
|
||||
int timeout;
|
||||
|
||||
@ -608,20 +604,18 @@ window_setInterval(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
return true;
|
||||
}
|
||||
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(interpreter, code, timeout, timeout);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(ctx, code, timeout, timeout);
|
||||
JS::BigInt *bi = JS::NumberToBigInt(ctx, reinterpret_cast<int64_t>(id));
|
||||
args.rval().setBigInt(bi);
|
||||
return true;
|
||||
}
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout2(interpreter, args[0], timeout, timeout);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout2(ctx, args[0], timeout, timeout);
|
||||
JS::BigInt *bi = JS::NumberToBigInt(ctx, reinterpret_cast<int64_t>(id));
|
||||
args.rval().setBigInt(bi);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* @window_funcs{"setTimeout"} */
|
||||
static bool
|
||||
window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
@ -637,11 +631,7 @@ window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||
// struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
|
||||
char *code;
|
||||
int timeout;
|
||||
|
||||
@ -661,12 +651,12 @@ window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
return true;
|
||||
}
|
||||
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(interpreter, code, timeout, -1);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout(ctx, code, timeout, -1);
|
||||
JS::BigInt *bi = JS::NumberToBigInt(ctx, reinterpret_cast<int64_t>(id));
|
||||
args.rval().setBigInt(bi);
|
||||
return true;
|
||||
}
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout2(interpreter, args[0], timeout, -1);
|
||||
struct ecmascript_timeout *id = ecmascript_set_timeout2(ctx, args[0], timeout, -1);
|
||||
JS::BigInt *bi = JS::NumberToBigInt(ctx, reinterpret_cast<int64_t>(id));
|
||||
args.rval().setBigInt(bi);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user