about summary refs log tree commit diff stats
path: root/src/io/request.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-09 16:48:20 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-09 16:49:24 +0200
commitc20572d3d3dce8bb8ea0fea0d8af9f9d5ea6c80f (patch)
tree5deefeee5697a5ae0176bbdf8d1b0406529dff21 /src/io/request.nim
parente8fa2217df7bacc58e88737f21752bbdf0f5562a (diff)
downloadchawan-c20572d3d3dce8bb8ea0fea0d8af9f9d5ea6c80f.tar.gz
Simplify request.json, remove unused bindings
Diffstat (limited to 'src/io/request.nim')
-rw-r--r--src/io/request.nim17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/io/request.nim b/src/io/request.nim
index 4a123a0b..da3437fb 100644
--- a/src/io/request.nim
+++ b/src/io/request.nim
@@ -310,25 +310,16 @@ proc close*(response: Response) {.jsfunc.} =
   if response.body != nil:
     response.body.close()
 
+#TODO text, json should return promises, not blocking reads
 proc text*(response: Response): string {.jsfunc.} =
   if response.body == nil:
     return ""
   result = response.body.readAll()
   response.close()
 
-#TODO: get rid of this
-proc readAll*(response: Response): string {.jsfunc.} =
-  return response.text()
-
-proc Response_json(ctx: JSContext, this: JSValue, argc: cint, argv: ptr JSValue): JSValue {.cdecl.} =
-  let op = getOpaque0(this)
-  if unlikely(not ctx.isInstanceOf(this, "Response") or op == nil):
-    return JS_ThrowTypeError(ctx, "Value is not an instance of %s", "Response")
-  let response = cast[Response](op)
+proc json(response: Response, ctx: JSContext): JSValue =
   var s = response.text()
-  if s == "":
-    return JS_ThrowSyntaxError("unexpected end of input")
-  return JS_ParseJSON(ctx, addr s[0], cast[csize_t](s.len), cstring"<input>")
+  return JS_ParseJSON(ctx, cstring(s), cast[csize_t](s.len), cstring"<input>")
 
 func credentialsMode*(attribute: CORSAttribute): CredentialsMode =
   case attribute
@@ -342,5 +333,5 @@ proc addRequestModule*(ctx: JSContext) =
     TabGetSet(name: "url", get: Request_url),
     TabGetSet(name: "referrer", get: Request_referrer)
   ])
-  ctx.registerType(Response, extra_funcs = [TabFunc(name: "json", fun: Response_json)])
+  ctx.registerType(Response)
   ctx.registerType(Headers)
ref='#n189'>189