diff options
author | bptato <nincsnevem662@gmail.com> | 2025-01-22 20:29:52 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2025-01-22 20:29:52 +0100 |
commit | 9df15b2b3c5a7897d2314c0b68a4faf05b8d7459 (patch) | |
tree | f97cb551b2b75c4bfdafde61c941eb551a33c029 /lib/monoucha0 | |
parent | 52793834ce108631596903f3b6aab44fbd638086 (diff) | |
download | chawan-9df15b2b3c5a7897d2314c0b68a4faf05b8d7459.tar.gz |
javascript: allow sink parameters
Diffstat (limited to 'lib/monoucha0')
-rw-r--r-- | lib/monoucha0/monoucha/javascript.nim | 3 | ||||
-rw-r--r-- | lib/monoucha0/test/etc.nim | 15 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/monoucha0/monoucha/javascript.nim b/lib/monoucha0/monoucha/javascript.nim index 45a79fa7..29fedd80 100644 --- a/lib/monoucha0/monoucha/javascript.nim +++ b/lib/monoucha0/monoucha/javascript.nim @@ -452,6 +452,9 @@ proc getParams(fun: NimNode): seq[FuncParam] = t = t[0] elif t.kind == nnkVarTy: t = newNimNode(nnkPtrTy).add(t[0]) + elif t.kind in {nnkCommand, nnkCall} and t.len == 2 and + t[0].kind == nnkSym and t[0].strVal == "sink": + t = t[1] let val = if it[^1].kind != nnkEmpty: let x = it[^1] some(newPar(x)) diff --git a/lib/monoucha0/test/etc.nim b/lib/monoucha0/test/etc.nim index 47f123a6..ad3fa6bf 100644 --- a/lib/monoucha0/test/etc.nim +++ b/lib/monoucha0/test/etc.nim @@ -148,3 +148,18 @@ test "fromjs-tuple": JS_FreeValue(ctx, jsTest) ctx.free() rt.free() + +type X = ref object + +proc foo(x: X; s: sink string) {.jsfunc.} = + discard + +proc bar(x: X; s: sink(string)) {.jsfunc.} = + discard + +test "sink": + let rt = newJSRuntime() + let ctx = rt.newJSContext() + ctx.registerType(X) + ctx.free() + rt.free() |