bugfix slot-value
authorHenrik Hjelte <henrik.hjelte@poboxes.com>
Mon, 19 Dec 2005 13:19:01 +0000 (13:19 +0000)
committerHenrik Hjelte <henrik.hjelte@poboxes.com>
Mon, 19 Dec 2005 13:19:01 +0000 (13:19 +0000)
js.lisp
test.lisp

diff --git a/js.lisp b/js.lisp
index 94a5a2c..afe63a8 100644 (file)
--- a/js.lisp
+++ b/js.lisp
@@ -727,11 +727,13 @@ this macro."
 
 (define-js-compiler-macro slot-value (obj slot)
   (make-instance 'js-slot-value :object (js-compile-to-expression obj)
-                :slot (js-compile-to-symbol slot)))
+                  :slot (js-compile slot)))
 
 (defmethod js-to-strings ((sv js-slot-value) start-pos)
   (append-to-last (js-to-strings (sv-object sv) start-pos)
-                 (format nil ".~A" (symbol-to-js (sv-slot sv)))))
+                  (if (symbolp (sv-slot sv))
+                     (format nil ".~A" (symbol-to-js (sv-slot sv)))
+                      (format nil "[~A]" (first (js-to-strings (sv-slot sv) 0))))))
 
 (defjsmacro with-slots (slots object &rest body)
   `(symbol-macrolet ,(mapcar #'(lambda (slot)
@@ -1372,4 +1374,3 @@ converted to javascript."
   `(concatenate 'string "javascript:"
     (string-join (js-to-statement-strings (js-compile (list 'progn ,@body)) 0) " ")))
 
-
index f6ebcf7..b60f1c6 100644 (file)
--- a/test.lisp
+++ b/test.lisp
  + ('border:1pxsssssssssss;font-size:x-small;height:' + 2 * 200 + ';width:'
  + 2 * 300)
  + '\"></div>')") ;";This line should start with a plus character.
+
+
+(test-ps-js simple-slot-value 
+  (let ((foo (create :a 1)))
+   (alert (slot-value foo 'a)))
+  "{
+    var foo = { a : 1 };
+    alert(foo.a);
+   }")
+
+(test-ps-js buggy-slot-value 
+   (let ((foo (create :a 1))
+        (slot-name "a"))
+    (alert (slot-value foo slot-name)))
+  "{
+    var foo = { a : 1 };
+    var slotName = 'a';
+    alert(foo[slotName]);
+   }"); Last line was alert(foo.slotName) before bug-fix.
+
+(test-ps-js buggy-slot-value-two
+  (slot-value foo (get-slot-name))
+  "foo[getSlotName()]")