aboutsummaryrefslogtreecommitdiffstats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-09-14 15:58:52 +0200
committerbptato <nincsnevem662@gmail.com>2024-09-14 16:56:46 +0200
commit5b2a36579e53c69f154288a91ddc3e7c5375d7a6 (patch)
tree6b81b21aa15ef26031ce653ea972f75e00b1df0e /src/html
parentdfa1a4bc5ece3b8c333b9a47bab038ff6a162f5b (diff)
downloadchawan-5b2a36579e53c69f154288a91ddc3e7c5375d7a6.tar.gz
loader: refactor, misc optimizations & fixes
* factor out input/output handle tables; use a seq instead * add possibility to directly open cached items onto stdin (mainly an optimization for reading images, which are always cached) * close used handles on local CGI execution * make clone during load work again
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index b31802bc..146056a9 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -4565,6 +4565,7 @@ proc getContext*(jctx: JSContext; this: HTMLCanvasElement; contextId: string;
# backwards compat, but I don't care.
proc toBlob(ctx: JSContext; this: HTMLCanvasElement; callback: JSValue;
contentType = "image/png"; quality = none(float64)) {.jsfunc.} =
+ let contentType = contentType.toLowerAscii()
if not contentType.startsWith("image/") or this.bitmap.cacheId == 0:
return
let url0 = newURL("img-codec+" & contentType.after('/') & ":encode")
@@ -4582,21 +4583,11 @@ proc toBlob(ctx: JSContext; this: HTMLCanvasElement; callback: JSValue;
let callback = JS_DupValue(ctx, callback)
let window = this.document.window
let loader = window.loader
- let contentType = contentType.toLowerAscii()
- let cacheReq = newRequest(newURL("cache:" & $this.bitmap.cacheId).get)
- loader.fetch(cacheReq).then(proc(res: JSResult[Response]): FetchPromise =
- if res.isNone:
- return newResolvedPromise(res)
- let res = res.get
- let p = loader.fetch(newRequest(
- newURL("img-codec+x-cha-canvas:decode").get,
- httpMethod = hmPost,
- body = RequestBody(t: rbtOutput, outputId: res.outputId)
- ))
- res.resume()
- res.close()
- return p
- ).then(proc(res: JSResult[Response]): FetchPromise =
+ loader.fetch(newRequest(
+ newURL("img-codec+x-cha-canvas:decode").get,
+ httpMethod = hmPost,
+ body = RequestBody(t: rbtCache, cacheId: this.bitmap.cacheId)
+ )).then(proc(res: JSResult[Response]): FetchPromise =
if res.isNone:
return newResolvedPromise(res)
let res = res.get