2003/11/05 13:29:00
[org.ibex.core.git] / src / org / xwt / Template.java
index e7e72b5..9e6699b 100644 (file)
@@ -32,7 +32,7 @@ public class Template {
     private Vec children = new Vec();  ///< during XML parsing, this holds the list of currently-parsed children; null otherwise
     private int numunits = -1;         ///< see numUnits(); -1 means that this value has not yet been computed
 
-    private JS.CompiledFunction script = null;       ///< the script on this node
+    private Function script = null;       ///< the script on this node
     private String fileName = "unknown";             ///< the filename this node came from; used only for debugging
     private Vec preapply = new Vec();                ///< templates that should be preapplied (in the order of application)
 
@@ -40,7 +40,7 @@ public class Template {
     // Instance Members that are only meaningful on root Template //////////////////////////////////////
 
     private JS.Scope staticScope = null;             ///< the scope in which the static block is executed
-    private JS.CompiledFunction staticscript = null; ///< the script on the static node of this template, null already performed
+    private Function staticscript = null; ///< the script on the static node of this template, null already performed
 
 
     // Only used during parsing /////////////////////////////////////////////////////////////////
@@ -95,9 +95,9 @@ public class Template {
     JS.Scope getStatic() {
         if (staticScope == null) staticScope = new JS.Scope(null);
         if (staticscript == null) return staticScope;
-        JS.CompiledFunction temp = staticscript;
+        Function temp = staticscript;
         staticscript = null;
-        temp.call(new JS.Array(), staticScope);
+        new JS.Context(temp, staticScope).resume();
         return staticScope;
     }
     
@@ -121,10 +121,12 @@ public class Template {
         for (int i=0; children != null && i<children.size(); i++) {
             Box kid = new Box();
             ((Template)children.elementAt(i)).apply(kid, callback, xwt, pis);
+
+            // FIXME: tailcall?
             b.put(b.numChildren(), kid);
         }
 
-        if (script != null) script.call(new JS.Array(), pis);
+        if (script != null) new JS.Context(script, pis).resume();
 
         for(int i=0; keys != null && i<keys.length; i++)
             if (vals[i] instanceof String && ((String)vals[i]).charAt(0) == '$') b.put(keys[i], pis.get(vals[i]));
@@ -209,6 +211,7 @@ public class Template {
         private void processBodyElement(XML.Element c) {
             Hash h = new Hash(c.len * 2, 3);
             for(int i=0; i<c.len; i++) {
+                if (c.keys[i] == null) continue;
                 if (c.keys[i].endsWith(":image")) {
                     String uri = (String)c.urimap.get(c.keys[i].substring(0, c.keys[i].indexOf(':')));
                     c.keys[i] = c.keys[i].substring(c.keys[i].lastIndexOf(':') + 1);
@@ -276,8 +279,8 @@ public class Template {
             }
         }
 
-        private JS.CompiledFunction parseScript(boolean isstatic) {
-            JS.CompiledFunction thisscript = null;
+        private Function parseScript(boolean isstatic) {
+            Function thisscript = null;
             try {
                 thisscript = JS.parse(t.fileName + (isstatic ? "._" : ""), t.content_start, new StringReader(t.content.toString()));
             } catch (IOException ioe) {
@@ -349,18 +352,15 @@ public class Template {
             this.xwt = xwt;
             this.myStatic = myStatic;
         }
-        public boolean isTransparent() { return true; }
         public Object get(Object key) {
             if (super.has(key)) return super.get(key);
             if (key.equals("xwt")) return xwt;
             if (key.equals("static")) return myStatic;
-            if (Box.SpecialBoxProperty.specialBoxProperties.get(key.toString()) != null) return getParentScope().get(key);
-            throw new JS.Exn("must declare " + key + " before using it!");
+            return super.get(key);
         }
-        public void put(Object key, Object val) {
-            if (super.has(key)) super.put(key, val);
-            else if (Box.SpecialBoxProperty.specialBoxProperties.get(key.toString()) != null) getParentScope().put(key, val);
-            else throw new JS.Exn("must declare " + key + " before using it!");
+        public Object put(Object key, Object val) {
+            if (super.has(key)) return super.put(key, val);
+            return super.put(key, val);
         }
     }