about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-26 17:00:26 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-26 17:00:26 +0200
commit32a528939d6f39cefc00bb1742cf75739c64f006 (patch)
tree765a5b72d8b6662f12b1564437363df9c35ec8d8 /src
parent2b47c6f5ac8d41a8025c10d02da4d6090e616a68 (diff)
downloadchawan-32a528939d6f39cefc00bb1742cf75739c64f006.tar.gz
js: improve optional argument handling
If a fallback argument has been specified, treat undefined as if no
argument had been given.

This removes the need for the ?? 1 checks in the config.
Diffstat (limited to 'src')
-rw-r--r--src/js/javascript.nim5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index 87d160ed..0d49cf86 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -507,7 +507,10 @@ proc addParam2(gen: var JSFuncGenerator, s, t, val: NimNode, fallback: NimNode =
     else:
       let j = gen.j
       gen.jsFunCallLists[i].add(newLetStmt(s, quote do:
-        if `j` < argc: `stmt` else: `fallback`))
+        if `j` < argc and not JS_IsUndefined(getJSValue(argv, `j`)):
+          `stmt`
+        else:
+          `fallback`))
 
 proc addValueParam(gen: var JSFuncGenerator, s, t: NimNode, fallback: NimNode = nil) =
   let j = gen.j