diff src/jscomp.sml @ 850:1c2f335297b7

Fix a variable capture bug in nested JavaScript; some more list stuff
author Adam Chlipala <adamc@hcoop.net>
date Tue, 16 Jun 2009 17:52:44 -0400
parents 0f7e2cca6d9b
children ae9e22822ec5
line wrap: on
line diff
--- a/src/jscomp.sml	Tue Jun 16 14:38:01 2009 -0400
+++ b/src/jscomp.sml	Tue Jun 16 17:52:44 2009 -0400
@@ -980,12 +980,18 @@
                              jsE inner (e, st))
                           | EJavaScript (_, e) =>
                             let
+                                val locals = List.tabulate
+                                                 (varDepth e,
+                                               fn i => str ("var _" ^ Int.toString (len + inner + i) ^ ";"))
+
                                 val (e, st) = jsE inner (e, st)
                             in
                                 foundJavaScript := true;
-                                (strcat [str "cs(function(){return ",
-                                         compact inner e,
-                                         str "})"],
+                                (strcat (str "cs(function(){"
+                                         :: locals
+                                         @ [str "return ",
+                                            compact inner e,
+                                            str "})"]),
                                  st)
                             end