mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] clearTimeout
This commit is contained in:
parent
adddbf53fb
commit
98d970d606
@ -585,30 +585,38 @@ ecmascript_timeout_handler2(void *i)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
timer_id_T
|
||||||
ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, int timeout)
|
ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, int timeout)
|
||||||
{
|
{
|
||||||
assert(interpreter && interpreter->vs->doc_view->document);
|
assert(interpreter && interpreter->vs->doc_view->document);
|
||||||
if (!code) return;
|
if (!code) return nullptr;
|
||||||
done_string(&interpreter->code);
|
done_string(&interpreter->code);
|
||||||
init_string(&interpreter->code);
|
init_string(&interpreter->code);
|
||||||
add_to_string(&interpreter->code, code);
|
add_to_string(&interpreter->code, code);
|
||||||
mem_free(code);
|
mem_free(code);
|
||||||
kill_timer(&interpreter->vs->doc_view->document->timeout);
|
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);
|
install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler, interpreter);
|
||||||
|
|
||||||
|
return interpreter->vs->doc_view->document->timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_ECMASCRIPT_SMJS
|
#ifdef CONFIG_ECMASCRIPT_SMJS
|
||||||
void
|
timer_id_T
|
||||||
ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout)
|
ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout)
|
||||||
{
|
{
|
||||||
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);
|
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);
|
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);
|
||||||
|
|
||||||
|
return interpreter->vs->doc_view->document->timeout;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -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_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
|
#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
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_QUICKJS
|
#ifdef CONFIG_QUICKJS
|
||||||
|
@ -216,7 +216,6 @@ js_window_setTimeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon
|
|||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
timer_id_T id = ecmascript_set_timeout2q(interpreter, func, timeout);
|
timer_id_T id = ecmascript_set_timeout2q(interpreter, func, timeout);
|
||||||
add_to_map_timer(id);
|
|
||||||
|
|
||||||
return JS_NewInt64(ctx, reinterpret_cast<int64_t>(id));
|
return JS_NewInt64(ctx, reinterpret_cast<int64_t>(id));
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "elinks.h"
|
#include "elinks.h"
|
||||||
|
|
||||||
#include "ecmascript/spidermonkey/util.h"
|
#include "ecmascript/spidermonkey/util.h"
|
||||||
|
#include <js/BigInt.h>
|
||||||
#include <js/Conversions.h>
|
#include <js/Conversions.h>
|
||||||
|
|
||||||
#include "bfu/dialog.h"
|
#include "bfu/dialog.h"
|
||||||
@ -24,6 +25,7 @@
|
|||||||
#include "document/view.h"
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
#include "ecmascript/spidermonkey/window.h"
|
#include "ecmascript/spidermonkey/window.h"
|
||||||
|
#include "ecmascript/timer.h"
|
||||||
#include "intl/libintl.h"
|
#include "intl/libintl.h"
|
||||||
#include "main/select.h"
|
#include "main/select.h"
|
||||||
#include "osdep/newwin.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);
|
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_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_open(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
static bool window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
static bool window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval);
|
||||||
|
|
||||||
const spidermonkeyFunctionSpec window_funcs[] = {
|
const spidermonkeyFunctionSpec window_funcs[] = {
|
||||||
{ "alert", window_alert, 1 },
|
{ "alert", window_alert, 1 },
|
||||||
|
{ "clearTimeout", window_clearTimeout, 1 },
|
||||||
{ "open", window_open, 3 },
|
{ "open", window_open, 3 },
|
||||||
{ "setTimeout", window_setTimeout, 2 },
|
{ "setTimeout", window_setTimeout, 2 },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
@ -443,14 +447,49 @@ window_setTimeout(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
|||||||
return true;
|
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;
|
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);
|
||||||
|
|
||||||
ecmascript_set_timeout2(interpreter, args[0], timeout);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* @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
|
#if 0
|
||||||
static bool
|
static bool
|
||||||
window_get_property_closed(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
window_get_property_closed(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
|
Loading…
Reference in New Issue
Block a user