Corrected the defaultf psmacro for cases where the rhs value is false in JS.
authorTravis Cross <tc@traviscross.com>
Sat, 15 Nov 2008 05:40:25 +0000 (05:40 +0000)
committerTravis Cross <tc@traviscross.com>
Sat, 15 Nov 2008 05:44:06 +0000 (05:44 +0000)
This affected &optional and &key default parameters in lambda lists.

Thanks to Daniel Gackle for the bug report.

src/special-forms.lisp
t/ps-tests.lisp

index ef9eb01..71d1575 100644 (file)
@@ -265,8 +265,8 @@ Syntax of key spec:
           (when (listp spec) (second spec))))
 
 (defpsmacro defaultf (place value)
-  `(setf ,place (or (and (=== undefined ,place) ,value)
-                 ,place)))
+  `(when (=== ,place undefined)
+     (setf ,place ,value)))
 
 (defun parse-extended-function (lambda-list body &optional name)
   "Returns two values: the effective arguments and body for a function with
index 56f5468..26d8248 100644 (file)
@@ -236,14 +236,18 @@ x = 2 + sideEffect() + x + 5;")
 (test-ps-js defun-optional1
   (defun test-opt (&optional x) (return (if x "yes" "no")))
   "function testOpt(x) {
-  x = undefined === x && null || x;
-  return x ? 'yes' : 'no';
+    if (x === undefined) {
+        x = null;
+    };
+    return x ? 'yes' : 'no';
 }")
 
 (test-ps-js defun-optional2
   (defun foo (x &optional y) (+ x y))
   "function foo(x, y) {
-    y = undefined === y && null || y;
+    if (y === undefined) {
+        y = null;
+    };
     x + y;
 }")
 
@@ -341,7 +345,9 @@ x = 2 + sideEffect() + x + 5;")
 (test-ps-js defun-keyword1
   (defun zoo (foo bar &key baz) (return (+ foo bar baz)))
   "function zoo(foo, bar, _js1) {
-    _js1 = undefined === _js1 && {  } || _js1;
+    if (_js1 === undefined) {
+        _js1 = {  };
+    };
     return foo + bar + _js1.baz;
 }")