aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-09-30 21:25:20 +0200
committerbptato <nincsnevem662@gmail.com>2024-09-30 21:25:20 +0200
commitf9433f13765ca6ec6aa5d2c34dd4d3c76d93c08a (patch)
treeb94a661a8821aafe1cc6945ead210abc1349e3de /src
parentbcadca71a694c68263d03da27fcaf3fc897da38f (diff)
downloadchawan-f9433f13765ca6ec6aa5d2c34dd4d3c76d93c08a.tar.gz
timeout: accept err stream as param
gets rid of a todo. (not sure why I thought this was important, but it sure looks nicer)
Diffstat (limited to 'src')
-rw-r--r--src/html/env.nim2
-rw-r--r--src/js/timeout.nim14
-rw-r--r--src/local/client.nim9
-rw-r--r--src/server/buffer.nim2
4 files changed, 11 insertions, 16 deletions
diff --git a/src/html/env.nim b/src/html/env.nim
index 27a12816..2628c09b 100644
--- a/src/html/env.nim
+++ b/src/html/env.nim
@@ -279,7 +279,7 @@ proc addScripting*(window: Window) =
window.jsrt = rt
window.jsctx = ctx
window.importMapsAllowed = true
- window.timeouts = newTimeoutState(ctx, window.console.err, evalJSFree, window)
+ window.timeouts = newTimeoutState(ctx, evalJSFree, window)
ctx.addWindowModule()
ctx.setGlobal(window)
ctx.addDOMExceptionModule()
diff --git a/src/js/timeout.nim b/src/js/timeout.nim
index 72a68dbc..6ff796f2 100644
--- a/src/js/timeout.nim
+++ b/src/js/timeout.nim
@@ -27,16 +27,14 @@ type
timeoutid: int32
timeouts: seq[TimeoutEntry]
jsctx: JSContext
- err: DynStream #TODO shouldn't be needed
evalJSFree: EvalJSFree
opaque: RootRef
sorted: bool
-func newTimeoutState*(jsctx: JSContext; err: DynStream;
- evalJSFree: EvalJSFree; opaque: RootRef): TimeoutState =
+func newTimeoutState*(jsctx: JSContext; evalJSFree: EvalJSFree;
+ opaque: RootRef): TimeoutState =
return TimeoutState(
jsctx: jsctx,
- err: err,
evalJSFree: evalJSFree,
opaque: opaque,
sorted: true
@@ -84,12 +82,12 @@ proc setTimeout*(state: var TimeoutState; t: TimeoutType; handler: JSValue;
state.sorted = false
return id
-proc runEntry(state: var TimeoutState; entry: TimeoutEntry) =
+proc runEntry(state: var TimeoutState; entry: TimeoutEntry; err: DynStream) =
if JS_IsFunction(state.jsctx, entry.val):
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)
+ state.jsctx.writeException(err)
JS_FreeValue(state.jsctx, ret)
else:
var s: string
@@ -107,7 +105,7 @@ proc sortAndGetTimeout*(state: var TimeoutState): cint =
let now = getUnixMillis()
return cint(max(state.timeouts[^1].expires - now, -1))
-proc run*(state: var TimeoutState): bool =
+proc run*(state: var TimeoutState; err: DynStream): bool =
let H = state.timeouts.high
let now = getUnixMillis()
var found = false
@@ -115,7 +113,7 @@ proc run*(state: var TimeoutState): bool =
if state.timeouts[i].expires > now:
break
let entry = state.timeouts[i]
- state.runEntry(entry)
+ state.runEntry(entry, err)
found = true
case entry.t
of ttTimeout: state.clearTimeout0(i)
diff --git a/src/local/client.nim b/src/local/client.nim
index 33bb44e3..6adc4a53 100644
--- a/src/local/client.nim
+++ b/src/local/client.nim
@@ -586,7 +586,7 @@ proc inputLoop(client: Client) =
client.handleWrite(efd)
if (event.revents and POLLERR) != 0 or (event.revents and POLLHUP) != 0:
client.handleError(efd)
- if client.timeouts.run():
+ if client.timeouts.run(client.console.err):
let container = client.consoleWrapper.container
if container != nil:
container.tailOnLoad = true
@@ -634,7 +634,7 @@ proc headlessLoop(client: Client) =
client.handleWrite(efd)
if (event.revents and POLLERR) != 0 or (event.revents and POLLHUP) != 0:
client.handleError(efd)
- discard client.timeouts.run()
+ discard client.timeouts.run(client.console.err)
client.runJSJobs()
client.loader.unregistered.setLen(0)
client.acceptBuffers()
@@ -754,10 +754,7 @@ proc launchClient*(client: Client; pages: seq[string];
client.hideConsole()
client.consoleWrapper = pager.addConsole(interactive = istream != nil,
clearFun, showFun, hideFun)
- #TODO passing console.err here makes it impossible to change it later. maybe
- # better associate it with jsctx
- client.timeouts = newTimeoutState(client.jsctx, client.console.err,
- evalJSFree2, client)
+ client.timeouts = newTimeoutState(client.jsctx, evalJSFree2, client)
client.pager.timeouts = client.timeouts
addExitProc((proc() = client.cleanup()))
if client.config.start.startup_script != "":
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index ba571b82..f858ec16 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -1829,7 +1829,7 @@ proc runBuffer(buffer: Buffer) =
alive = false
break
if buffer.config.scripting:
- if buffer.window.timeouts.run():
+ if buffer.window.timeouts.run(buffer.estream):
buffer.window.runJSJobs()
buffer.maybeReshape()
buffer.loader.unregistered.setLen(0)