about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-08-28 22:33:31 +0200
committerbptato <nincsnevem662@gmail.com>2023-08-28 22:38:00 +0200
commit1422f3393301cd6105b3939be194c7c119fcf967 (patch)
tree32969f2af8fe5293c13215a84229915a7970e828 /src/io
parentba2a62f6d3a2879c9506ea3fb5aa5552fc4674d9 (diff)
downloadchawan-1422f3393301cd6105b3939be194c7c119fcf967.tar.gz
javascript: refactor
Split out parts of the JS module, because it was starting to confuse
the compiler a little.

(Peakmem is back at 750M. Interesting.)
Diffstat (limited to 'src/io')
-rw-r--r--src/io/loader.nim3
-rw-r--r--src/io/request.nim3
-rw-r--r--src/io/response.nim5
3 files changed, 7 insertions, 4 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim
index 65ce091f..f263e031 100644
--- a/src/io/loader.nim
+++ b/src/io/loader.nim
@@ -34,6 +34,7 @@ import io/urlfilter
 import ips/serialize
 import ips/serversocket
 import ips/socketstream
+import js/error
 import js/javascript
 import types/cookie
 import types/referer
@@ -56,7 +57,7 @@ type
     unregisterFun*: proc(fd: int)
 
   ConnectData = object
-    promise: Promise[Result[Response, JSError]]
+    promise: Promise[JSResult[Response]]
     stream: Stream
     request: Request
 
diff --git a/src/io/request.nim b/src/io/request.nim
index f609360b..6b89eb6b 100644
--- a/src/io/request.nim
+++ b/src/io/request.nim
@@ -5,6 +5,7 @@ import tables
 
 import bindings/quickjs
 import io/headers
+import js/error
 import js/javascript
 import types/formdata
 import types/url
@@ -194,7 +195,7 @@ func createPotentialCORSRequest*(url: URL, destination: RequestDestination, cors
 
 #TODO init as an actual dictionary
 func newRequest*[T: string|Request](ctx: JSContext, resource: T,
-    init = none(JSValue)): Result[Request, JSError] {.jsctor.} =
+    init = none(JSValue)): JSResult[Request] {.jsctor.} =
   when T is string:
     let url = ?newURL(resource)
     if url.username != "" or url.password != "":
diff --git a/src/io/response.nim b/src/io/response.nim
index 38f6b397..75e3d664 100644
--- a/src/io/response.nim
+++ b/src/io/response.nim
@@ -4,6 +4,7 @@ import bindings/quickjs
 import io/headers
 import io/promise
 import io/request
+import js/error
 import js/javascript
 import types/url
 
@@ -50,7 +51,7 @@ proc close*(response: Response) {.jsfunc.} =
   if response.body != nil:
     response.body.close()
 
-proc text*(response: Response): Promise[Result[string, JSError]] {.jsfunc.} =
+proc text*(response: Response): Promise[JSResult[string]] {.jsfunc.} =
   if response.bodyRead == nil:
     let p = newPromise[Result[string, JSError]]()
     let err = Result[string, JSError]
@@ -62,7 +63,7 @@ proc text*(response: Response): Promise[Result[string, JSError]] {.jsfunc.} =
   return bodyRead.then(proc(s: string): Result[string, JSError] =
     ok(s))
 
-proc json(ctx: JSContext, this: Response): Promise[Result[JSValue, JSError]]
+proc json(ctx: JSContext, this: Response): Promise[JSResult[JSValue]]
     {.jsfunc.} =
   return this.text().then(proc(s: Result[string, JSError]):
       Result[JSValue, JSError] =