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

[spidermonkey] clearTimeout

This commit is contained in:
Witold Filipczyk 2021-12-01 20:47:25 +01:00
parent adddbf53fb
commit 98d970d606
4 changed files with 56 additions and 10 deletions

View File

@ -585,30 +585,38 @@ ecmascript_timeout_handler2(void *i)
}
#endif
void
timer_id_T
ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, int timeout)
{
assert(interpreter && interpreter->vs->doc_view->document);
if (!code) return;
if (!code) return nullptr;
done_string(&interpreter->code);
init_string(&interpreter->code);
add_to_string(&interpreter->code, code);
mem_free(code);
if (check_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
kill_timer(&interpreter->vs->doc_view->document->timeout);
}
install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler, interpreter);
return interpreter->vs->doc_view->document->timeout;
}
#ifdef CONFIG_ECMASCRIPT_SMJS
void
timer_id_T
ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout)
{
assert(interpreter && interpreter->vs->doc_view->document);
done_string(&interpreter->code);
init_string(&interpreter->code);
if (check_in_map_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;
install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler2, interpreter);
return interpreter->vs->doc_view->document->timeout;
}
#endif

View File

@ -135,10 +135,10 @@ void ecmascript_timeout_dialog(struct terminal *term, int max_exec_time);
void ecmascript_set_action(char **action, char *string);
void ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, int timeout);
timer_id_T ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, int timeout);
#ifdef CONFIG_ECMASCRIPT_SMJS
void ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout);
timer_id_T ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout);
#endif
#ifdef CONFIG_QUICKJS

View File

@ -216,7 +216,6 @@ js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon
return JS_UNDEFINED;
}
timer_id_T id = ecmascript_set_timeout2q(interpreter, func, timeout);
add_to_map_timer(id);
return JS_NewInt64(ctx, reinterpret_cast<int64_t>(id));
}

View File

@ -11,6 +11,7 @@
#include "elinks.h"
#include "ecmascript/spidermonkey/util.h"
#include <js/BigInt.h>
#include <js/Conversions.h>
#include "bfu/dialog.h"
@ -24,6 +25,7 @@
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/window.h"
#include "ecmascript/timer.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
@ -216,11 +218,13 @@ window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
void location_goto(struct document_view *doc_view, char *url);
static bool window_alert(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool window_clearTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool window_open(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval);
const spidermonkeyFunctionSpec window_funcs[] = {
{ "alert", window_alert, 1 },
{ "clearTimeout", window_clearTimeout, 1 },
{ "open", window_open, 3 },
{ "setTimeout", window_setTimeout, 2 },
{ NULL }
@ -443,13 +447,48 @@ window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval)
return true;
}
ecmascript_set_timeout(interpreter, code, timeout);
timer_id_T id = ecmascript_set_timeout(interpreter, code, timeout);
JS::BigInt *bi = JS::NumberToBigInt(ctx, reinterpret_cast<int64_t>(id));
args.rval().setBigInt(bi);
return true;
}
timer_id_T id = ecmascript_set_timeout2(interpreter, args[0], timeout);
JS::BigInt *bi = JS::NumberToBigInt(ctx, reinterpret_cast<int64_t>(id));
args.rval().setBigInt(bi);
return true;
}
ecmascript_set_timeout2(interpreter, args[0], timeout);
/* @window_funcs{"clearTimeout"} */
static bool
window_clearTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::Realm *comp = js::GetContextRealm(ctx);
if (!comp) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
if (argc != 1) {
return true;
}
JS::BigInt *bi = JS::ToBigInt(ctx, args[0]);
int64_t number = JS::ToBigInt64(bi);
timer_id_T id = reinterpret_cast<timer_id_T>(number);
if (check_in_map_timer(id)) {
kill_timer(&id);
}
return true;
}
#if 0
static bool