aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-28 20:50:51 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-28 21:06:28 +0200
commit9653c35fb9a4398942ecb305835a95fbd87c433a (patch)
tree2db576e71cd89557592715d64ecb4fb4a46f8c66 /src/js
parentdbf2e0e831ebaf8a0e6f375a8f423f87280e7862 (diff)
downloadchawan-9653c35fb9a4398942ecb305835a95fbd87c433a.tar.gz
buffer, pager, config: add meta-refresh + misc fixes
* buffer, pager, config: add meta-refresh value, which makes it possible to follow http-equiv=refresh META tags. * config: clean up redundant format mode parser * timeout: accept varargs for params to pass on to functions * pager: add "options" dict to JS gotoURL * twtstr: remove redundant startsWithNoCase
Diffstat (limited to 'src/js')
-rw-r--r--src/js/timeout.nim20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/js/timeout.nim b/src/js/timeout.nim
index 6c4b157f..f8b8ed8a 100644
--- a/src/js/timeout.nim
+++ b/src/js/timeout.nim
@@ -5,6 +5,7 @@ import io/dynstream
import js/console
import monoucha/fromjs
import monoucha/javascript
+import monoucha/jsutils
import types/opt
type
@@ -16,8 +17,9 @@ type
t: TimeoutType
fd: int
val: JSValue
+ args: seq[JSValue]
- TimeoutState* = object
+ TimeoutState* = ref object
timeoutid: int32
timeouts: Table[int32, TimeoutEntry]
timeoutFds: Table[int, int32]
@@ -43,33 +45,39 @@ proc clearTimeout*(state: var TimeoutState; id: int32) =
let entry = state.timeouts[id]
state.selector.unregister(entry.fd)
JS_FreeValue(state.jsctx, entry.val)
+ for arg in entry.args:
+ JS_FreeValue(state.jsctx, arg)
state.timeoutFds.del(entry.fd)
state.timeouts.del(id)
#TODO varargs
proc setTimeout*(state: var TimeoutState; t: TimeoutType; handler: JSValue;
- timeout = 0i32): int32 =
+ timeout: int32; args: openArray[JSValue]): int32 =
let id = state.timeoutid
inc state.timeoutid
let fd = state.selector.registerTimer(max(timeout, 1), t == ttTimeout, 0)
state.timeoutFds[fd] = id
- state.timeouts[id] = TimeoutEntry(
+ let entry = TimeoutEntry(
t: t,
fd: fd,
val: JS_DupValue(state.jsctx, handler)
)
+ for arg in args:
+ entry.args.add(JS_DupValue(state.jsctx, arg))
+ state.timeouts[id] = entry
return id
proc runEntry(state: var TimeoutState; entry: TimeoutEntry; name: string) =
if JS_IsFunction(state.jsctx, entry.val):
- let ret = JS_Call(state.jsctx, entry.val, JS_UNDEFINED, 0, nil)
+ let ret = JS_Call(state.jsctx, entry.val, JS_UNDEFINED,
+ cint(entry.args.len), entry.args.toJSValueArray())
if JS_IsException(ret):
state.jsctx.writeException(state.err)
JS_FreeValue(state.jsctx, ret)
else:
let s = fromJS[string](state.jsctx, entry.val)
if s.isSome:
- state.evalJSFree(s.get, "setInterval handler")
+ state.evalJSFree(s.get, name)
proc runTimeoutFd*(state: var TimeoutState; fd: int): bool =
if fd notin state.timeoutFds:
@@ -85,5 +93,7 @@ proc clearAll*(state: var TimeoutState) =
for entry in state.timeouts.values:
state.selector.unregister(entry.fd)
JS_FreeValue(state.jsctx, entry.val)
+ for arg in entry.args:
+ JS_FreeValue(state.jsctx, arg)
state.timeouts.clear()
state.timeoutFds.clear()