The patch below implements ‘for ... in’ loops in client-side code (in
the js-to-js conversion.)

Before that, the ‘for’ loop in the tilde block in:

--8<---------------cut here---------------start------------->8---
service foo () {
    return <HTML> {
        <BODY> {
            "foo",
            ~{ var y = { a: 1, b: 2 };
               console.log ("hello", y);
               for (var x in y) { alert (y[x]); }
             }
        }
    }
}
--8<---------------cut here---------------end--------------->8---

would be compiled down to just "J2SForIn".

Ludo’.

diff --git a/js2scheme/js.scm b/js2scheme/js.scm
index 760a68f..fc47a38 100644
--- a/js2scheme/js.scm
+++ b/js2scheme/js.scm
@@ -417,5 +417,15 @@
       (append (j2s-js lhs tildec dollarc mode evalp)
 	 (list (symbol->string op)))))
 
-
-
+;*---------------------------------------------------------------------*/
+;*    j2s-js ::J2SForIn ...                                            */
+;*---------------------------------------------------------------------*/
+(define-method (j2s-js this::J2SForIn tildec dollarc mode evalp)
+   (with-access::J2SForIn this (lhs obj body)
+      (cons "for ("
+         (append (j2s-js lhs tildec dollarc mode evalp)
+            (cons " in "
+               (append (j2s-js obj tildec dollarc mode evalp)
+                  (cons "){"
+                     (append (j2s-js body tildec dollarc mode evalp)
+                        '("}")))))))))

Reply via email to