aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-08-15 19:11:49 +0200
committerbptato <nincsnevem662@gmail.com>2024-08-15 19:23:55 +0200
commit4bf895db711f3d4d229d3f18fbb2145cce2a73af (patch)
tree2e81c7399de03aebb9dfa166eba6ee809a75cd2e /src/js
parent885a3493b6cad4b4247a200928fe61e41883aaba (diff)
downloadchawan-4bf895db711f3d4d229d3f18fbb2145cce2a73af.tar.gz
xhr: more progress
* add responseText, response * add net tests -> currently sync XHR only; should find a way to do async tests... * update monoucha -> simplified & updated some related code that no longer worked properly
Diffstat (limited to 'src/js')
-rw-r--r--src/js/encoding.nim28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/js/encoding.nim b/src/js/encoding.nim
index 7d1bd126..7aae5eb2 100644
--- a/src/js/encoding.nim
+++ b/src/js/encoding.nim
@@ -40,31 +40,29 @@ func newJSTextDecoder(label = "utf-8"; options = TextDecoderOptions()):
func fatal(this: JSTextDecoder): bool {.jsfget.} =
return this.errorMode == demFatal
-proc decode0(this: JSTextDecoder; ctx: JSContext; input: JSArrayBufferView;
- stream: bool): JSResult[JSValue] =
- let H = int(input.abuf.len) - 1
- var oq = ""
- for chunk in this.tdctx.decode(input.abuf.p.toOpenArray(0, H), not stream):
- oq &= chunk
- if this.tdctx.failed:
- this.tdctx.failed = false
- return errTypeError("Failed to decode string")
- return ok(JS_NewStringLen(ctx, cstring(oq), csize_t(oq.len)))
-
type TextDecodeOptions = object of JSDict
stream {.jsdefault.}: bool
#TODO AllowSharedBufferSource
proc decode(ctx: JSContext; this: JSTextDecoder;
- input = none(JSArrayBufferView); options = TextDecodeOptions()):
- JSResult[JSValue] {.jsfunc.} =
+ input = none(JSArrayBufferView); options = TextDecodeOptions()): JSValue
+ {.jsfunc.} =
if not this.stream:
this.tdctx = initTextDecoderContext(this.encoding, this.errorMode)
this.bomSeen = false
this.stream = options.stream
if input.isSome:
- return this.decode0(ctx, input.get, options.stream)
- return ok(JS_NewString(ctx, ""))
+ let input = input.get
+ let H = int(input.abuf.len) - 1
+ var oq = ""
+ let stream = this.stream
+ for chunk in this.tdctx.decode(input.abuf.p.toOpenArray(0, H), not stream):
+ oq &= chunk
+ if this.tdctx.failed:
+ this.tdctx.failed = false
+ return JS_ThrowTypeError(ctx, "failed to decode string")
+ return JS_NewStringLen(ctx, cstring(oq), csize_t(oq.len))
+ return JS_NewString(ctx, "")
func jencoding(this: JSTextDecoder): string {.jsfget: "encoding".} =
return $this.encoding