diff options
author | bptato <nincsnevem662@gmail.com> | 2023-11-21 00:48:38 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-11-21 00:48:38 +0100 |
commit | 42809ced4920e1cf84b6ee61d9ee8131aa96adff (patch) | |
tree | 9a0a8f40f6f0f73529a1d1b885ea2f69828fa5bb | |
parent | e00dfe404a8ff9ad8161d38160edc847526ad06b (diff) | |
download | chawan-42809ced4920e1cf84b6ee61d9ee8131aa96adff.tar.gz |
buffer: call onload function on dispatchLoadEvent
-rw-r--r-- | src/server/buffer.nim | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim index 97acc8e2..681f9bb2 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -35,6 +35,7 @@ import js/fromjs import js/javascript import js/regex import js/timeout +import js/tojs import loader/connecterror import loader/headers import loader/loader @@ -1037,14 +1038,23 @@ proc resolveTask[T](buffer: Buffer, cmd: BufferCommand, res: T) = proc dispatchLoadEvent(buffer: Buffer) = let window = buffer.window - if window == nil: + if window == nil or not buffer.config.scripting: return + let ctx = buffer.window.jsctx + let event = newEvent(ctx, "load", window, window) for el in window.eventListeners: if el.ctype == "load": - let event = newEvent(window.jsctx, "load", window, window) let e = el.callback(event) if e.isErr: - buffer.window.jsctx.writeException(buffer.estream) + ctx.writeException(buffer.estream) + let jsWindow = toJS(ctx, window) + let jsonload = JS_GetPropertyStr(ctx, jsWindow, "onload") + var jsEvent = toJS(ctx, event) + if JS_IsFunction(ctx, jsonload): + JS_FreeValue(ctx, JS_Call(ctx, jsonload, jsWindow, 1, addr jsEvent)) + JS_FreeValue(ctx, jsEvent) + JS_FreeValue(ctx, jsonload) + JS_FreeValue(ctx, jsWindow) proc onload(buffer: Buffer) = var res: LoadResult = (false, buffer.lines.len, -1) |