diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-24 14:12:27 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-24 14:21:01 +0100 |
commit | fb21b1e4f0ee0e55e9556bf1f399d00d5eae26e4 (patch) | |
tree | c532aa98ee6bedf19b840f4ea0c7360a42407fbf /src/js | |
parent | b27deb7672c53e3ee59f91b7091e83ab28a8318d (diff) | |
download | chawan-fb21b1e4f0ee0e55e9556bf1f399d00d5eae26e4.tar.gz |
io: derive DynStream from RootObj (not Stream)
This way they are no longer compatible, but we no longer need them to be compatible anyway. (This also forces us to throw out the old serialize module, and use packet writers everywhere.)
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/console.nim | 9 | ||||
-rw-r--r-- | src/js/javascript.nim | 8 | ||||
-rw-r--r-- | src/js/timeout.nim | 16 |
3 files changed, 16 insertions, 17 deletions
diff --git a/src/js/console.nim b/src/js/console.nim index e0ac2ae2..d5e074e8 100644 --- a/src/js/console.nim +++ b/src/js/console.nim @@ -1,16 +1,15 @@ -import std/streams - +import io/dynstream import js/javascript type Console* = ref object - err*: Stream + err*: DynStream clearFun: proc() showFun: proc() hideFun: proc() jsDestructor(Console) -proc newConsole*(err: Stream; clearFun: proc() = nil; showFun: proc() = nil; +proc newConsole*(err: DynStream; clearFun: proc() = nil; showFun: proc() = nil; hideFun: proc() = nil): Console = return Console( err: err, @@ -25,7 +24,7 @@ proc log*(console: Console, ss: varargs[string]) {.jsfunc.} = if i != ss.high: console.err.write(' ') console.err.write('\n') - console.err.flush() + console.err.sflush() proc clear(console: Console) {.jsfunc.} = if console.clearFun != nil: diff --git a/src/js/javascript.nim b/src/js/javascript.nim index b4c68729..cbd0b205 100644 --- a/src/js/javascript.nim +++ b/src/js/javascript.nim @@ -44,11 +44,11 @@ import std/macros import std/options import std/sets -import std/streams import std/strutils import std/tables import std/unicode +import io/dynstream import js/error import js/fromjs import js/opaque @@ -208,11 +208,11 @@ proc getExceptionStr*(ctx: JSContext): string = JS_FreeValue(ctx, stack) JS_FreeValue(ctx, ex) -proc writeException*(ctx: JSContext, s: Stream) = +proc writeException*(ctx: JSContext, s: DynStream) = s.write(ctx.getExceptionStr()) - s.flush() + s.sflush() -proc runJSJobs*(rt: JSRuntime, err: Stream) = +proc runJSJobs*(rt: JSRuntime, err: DynStream) = while JS_IsJobPending(rt): var ctx: JSContext let r = JS_ExecutePendingJob(rt, addr ctx) diff --git a/src/js/timeout.nim b/src/js/timeout.nim index 8ef7c114..3c95dada 100644 --- a/src/js/timeout.nim +++ b/src/js/timeout.nim @@ -1,7 +1,7 @@ import std/selectors -import std/streams import std/tables +import io/dynstream import js/javascript type TimeoutState* = object @@ -12,10 +12,10 @@ type TimeoutState* = object interval_fdis: Table[int, int32] selector: Selector[int] #TODO would be better with void... jsctx: JSContext - err: Stream #TODO shouldn't be needed + err: DynStream #TODO shouldn't be needed evalJSFree: proc(src, file: string) #TODO ew -func newTimeoutState*(selector: Selector[int], jsctx: JSContext, err: Stream, +func newTimeoutState*(selector: Selector[int]; jsctx: JSContext; err: DynStream; evalJSFree: proc(src, file: string)): TimeoutState = return TimeoutState( selector: selector, @@ -28,7 +28,7 @@ func empty*(state: TimeoutState): bool = return state.timeouts.len == 0 and state.intervals.len == 0 #TODO varargs -proc setTimeout*[T: JSValue|string](state: var TimeoutState, handler: T, +proc setTimeout*[T: JSValue|string](state: var TimeoutState; handler: T; timeout = 0i32): int32 = let id = state.timeoutid inc state.timeoutid @@ -52,14 +52,14 @@ proc setTimeout*[T: JSValue|string](state: var TimeoutState, handler: T, ), fdi) return id -proc clearTimeout*(state: var TimeoutState, id: int32) = +proc clearTimeout*(state: var TimeoutState; id: int32) = if id in state.timeouts: let timeout = state.timeouts[id] state.selector.unregister(timeout.fdi) state.timeout_fdis.del(timeout.fdi) state.timeouts.del(id) -proc clearInterval*(state: var TimeoutState, id: int32) = +proc clearInterval*(state: var TimeoutState; id: int32) = if id in state.intervals: let interval = state.intervals[id] state.selector.unregister(interval.fdi) @@ -68,7 +68,7 @@ proc clearInterval*(state: var TimeoutState, id: int32) = state.intervals.del(id) #TODO varargs -proc setInterval*[T: JSValue|string](state: var TimeoutState, handler: T, +proc setInterval*[T: JSValue|string](state: var TimeoutState; handler: T; interval = 0i32): int32 = let id = state.timeoutid inc state.timeoutid @@ -91,7 +91,7 @@ proc setInterval*[T: JSValue|string](state: var TimeoutState, handler: T, ), fdi, fun) return id -proc runTimeoutFd*(state: var TimeoutState, fd: int): bool = +proc runTimeoutFd*(state: var TimeoutState; fd: int): bool = if fd in state.interval_fdis: state.intervals[state.interval_fdis[fd]].handler() return true |