diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-05 18:56:45 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-05 18:56:45 +0200 |
commit | 9316348a1fbd73c1b9f696cfdb06ca5e08175922 (patch) | |
tree | ffa638131f28ec081154826ba035b02fa386f67a /src/js/javascript.nim | |
parent | 4981c6f2d365363a78a4eb3cdea3776a19dd41cb (diff) | |
download | chawan-9316348a1fbd73c1b9f696cfdb06ca5e08175922.tar.gz |
js: fix string regression, throw on invalid ctor
Diffstat (limited to 'src/js/javascript.nim')
-rw-r--r-- | src/js/javascript.nim | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim index 0d86bd71..6b83517e 100644 --- a/src/js/javascript.nim +++ b/src/js/javascript.nim @@ -227,9 +227,11 @@ proc setInterruptHandler*(rt: JSRuntime, cb: JSInterruptHandler, opaque: pointer func toString*(ctx: JSContext, val: JSValue): Option[string] = var plen: csize_t let outp = JS_ToCStringLen(ctx, addr plen, val) # cstring - if outp != nil and plen != 0: + if outp != nil: var ret = newString(plen) - copyMem(addr ret[0], outp, plen) + if plen != 0: + prepareMutation(ret) + copyMem(addr ret[0], outp, plen) result = some(ret) JS_FreeCString(ctx, outp) @@ -1413,7 +1415,7 @@ macro jsctor*(fun: typed) = gen.jsCallAndRet = quote do: block `dl`: return ctx.toJS(`jfcl`) - return JS_UNDEFINED + return JS_ThrowTypeError(ctx, "Invalid parameters passed to constructor") discard gen.newJSProc(getJSParams()) gen.registerConstructor() result = newStmtList(fun) |