From 9316348a1fbd73c1b9f696cfdb06ca5e08175922 Mon Sep 17 00:00:00 2001 From: bptato Date: Mon, 5 Jun 2023 18:56:45 +0200 Subject: js: fix string regression, throw on invalid ctor --- src/js/javascript.nim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/js/javascript.nim') 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) -- cgit 1.4.1-2-gfad0 e/README.org?h=v0.6.1&id=dbaf4a34cf15966294d6b2045034537501efaeb2'>blame commit diff stats
path: root/README.org
blob: 3aee07f069c8f87fb6232d62a0bad175adcaa2de (plain) (tree)
1
2
3
4
5
6
7
8
9
10