Migrate OGET*
authorDavid Vázquez <davazp@gmail.com>
Mon, 24 Jun 2013 11:57:35 +0000 (13:57 +0200)
committerDavid Vázquez <davazp@gmail.com>
Mon, 24 Jun 2013 11:57:35 +0000 (13:57 +0200)
src/compiler.lisp

index a77d451..a65cd33 100644 (file)
   '(object))
 
 (define-raw-builtin oget* (object key &rest keys)
-  (js!selfcall
-    "var tmp = (" (ls-compile object) ")[xstring(" (ls-compile key) ")];"
-    `(code
-      ,@(mapcar (lambda (key)
-                  `(code "if (tmp === undefined) return " ,(ls-compile nil) ";"
-                         "tmp = tmp[xstring(" ,(ls-compile key) ")];" ))
-                keys))
-    "return tmp === undefined? " (ls-compile nil) " : tmp;" ))
+  (js!selfcall*
+    `(progn
+       (var (tmp (get ,(ls-compile object) (call |xstring| ,(ls-compile key)))))
+       ,@(mapcar (lambda (key)
+                   `(progn
+                      (if (=== tmp undefined) (return ,(ls-compile nil)))
+                      (= tmp (get tmp (call |xstring| ,(ls-compile key))))))
+                 keys))
+    `(return (if (=== tmp undefined) ,(ls-compile nil) tmp))))
 
 (define-raw-builtin oset* (value object key &rest keys)
   (let ((keys (cons key keys)))