update core for recent js changes
authorbrian <brian@brianweb.net>
Tue, 13 Jul 2004 04:29:24 +0000 (04:29 +0000)
committerbrian <brian@brianweb.net>
Tue, 13 Jul 2004 04:29:24 +0000 (04:29 +0000)
darcs-hash:20040713042924-24bed-cc9d2ad4adbae140ea9b441aa9d0a836af8244f7.gz

src/org/ibex/core/Box.java
src/org/ibex/core/Ibex.java
src/org/ibex/core/Template.java
src/org/ibex/net/HTTP.java
src/org/ibex/net/SOAP.java
src/org/ibex/net/XMLRPC.java

index a587a55..96aa0a0 100644 (file)
@@ -38,7 +38,7 @@ import org.ibex.graphics.*;
  *  trigger a Surface.abort; if rendering were done in the same pass,
  *  rendering work done prior to the Surface.abort would be wasted.
  */
-public final class Box extends JSScope implements Task {
+public final class Box extends JS.O implements Task {
 
     // Macros //////////////////////////////////////////////////////////////////////
 
@@ -52,8 +52,6 @@ public final class Box extends JSScope implements Task {
     //#define CHECKSET_BOOLEAN(prop) boolean nu = toBoolean(value); if (nu == prop) break; prop = nu;
     //#define CHECKSET_STRING(prop) if ((value==null&&prop==null)||(value!=null&&JS.toString(value).equals(prop))) break; prop=JS.toString(value);
 
-    public Box() { super(null); }
-
     // FIXME memory leak
     static Hash boxToCursor = new Hash(500, 3);
 
index ccc6afb..447ee1d 100644 (file)
@@ -185,7 +185,7 @@ public final class Ibex extends JS implements JS.Cloneable {
                         throw new JSExn("invalid resource specifier " + url);
                     }
                     case "thread.sleep": sleep(JS.toInt(a)); return null;
-                    case "regexp": return JS.newRegexp(a, null);
+                    case "regexp": return new JSRegexp(a, null);
                     case "net.rpc.xml": return new XMLRPC(JS.toString(a), "");
                     case "crypto.rsa": /* FEATURE */ return null;
                     case "crypto.md5": /* FEATURE */ return null;
@@ -202,7 +202,7 @@ public final class Ibex extends JS implements JS.Cloneable {
                 case 2:
                     //#jswitch(name)
                     case "stream.watch": return new Stream.ProgressWatcher(a, b);
-                    case "regexp": return JS.newRegexp(a, b);
+                    case "regexp": return new JSRegexp(a, b);
                     //#end
                 case 3:
                     //#jswitch(name)
@@ -345,16 +345,16 @@ public final class Ibex extends JS implements JS.Cloneable {
 
     // FEATURE: move this into builtin.xwar
     public Blessing bless(JS b) throws JSExn { return new Ibex.Blessing(b, this, null, null); }
-    // FIXME: Does this really need to extends JS.Clone?
-    // FEATURE: Mandate that Blessings use only String keys?
-    public static class Blessing extends JS.Clone {
+    // JS:FIXME: This doesn't properly handle traps
+    public static class Blessing extends JS.O {
         private Ibex ibex;
         private Template t = null;
         public JS parentkey = null;
         public Blessing parent = null;
+        public JS clonee;
         private Hash cache = new Hash();
         public Blessing(JS clonee, Ibex ibex, Blessing parent, JS parentkey) throws JSExn {
-            super(clonee); this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; }
+            this.clonee = clonee; this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; }
         public JS get(JS key) throws JSExn {
             if (JS.isString(key) && JS.toString(key).equals("")) return getStatic();
             if (cache.get(key) != null) return (JS)cache.get(key);
@@ -381,14 +381,14 @@ public final class Ibex extends JS implements JS.Cloneable {
                 } catch (IOException f) { /* DELIBERATE */ }
             return null;
         }
-        public JSScope getStatic() throws JSExn {
+        public JS getStatic() throws JSExn {
             try {
                 if (t == null) {
                     // FEATURE: Might want to handle the ".t" part better
                     JS res = parent.get(JS.S(JS.toString(parentkey) + ".t"));
                     t = Template.buildTemplate(description(), res, ibex);
                 }
-                return t != null ? t.staticScope : null;
+                return t != null ? t.staticObject : null;
             } catch (Exception e) {
                 Log.error(this, e);
                 return null;
@@ -396,7 +396,7 @@ public final class Ibex extends JS implements JS.Cloneable {
         }
         private String description() {
             String s = JS.debugToString(parentkey);
-            for(Blessing b = parent; b != null; b = b.parent) s = JS.debugToString(parentkey) + "." + s;
+            for(Blessing b = parent; b.parentkey != null; b = b.parent) s = JS.debugToString(b.parentkey) + "." + s;
             return s;
         }
         public JS call(JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn {
@@ -413,6 +413,8 @@ public final class Ibex extends JS implements JS.Cloneable {
             if (t == null) throw new JSExn("No such template " + JS.debugToString(parentkey));
             return t;
         }
+        // JS:FIXME: Blessing shouldn't need to roll its own JS.Clone implementation
+        public InputStream getInputStream() throws IOException { return clonee.getInputStream(); }
     }
 
 }
index efa3bbb..a3d0e4e 100644 (file)
@@ -33,7 +33,6 @@ public class Template {
     private JS script = null;           ///< the script on this node
     Template prev;
     Template prev2;
-    JSScope staticScope = null;         ///< the scope in which the static block is executed
     JS staticObject = null;
 
 
@@ -86,8 +85,9 @@ public class Template {
         for(int i=0; i<urikeys.length; i++) {
             if (urikeys[i] == null) continue;
             // FEATURE: Cache urikeys and resolved resources
-            pis.declare(JS.S(urikeys[i]));
-            pis.put(JS.S(urikeys[i]), ibex.resolveString(urivals[i], true));
+            //pis.declare(JS.S(urikeys[i]));
+            // JS:FIXME: ugly
+            pis.sput(JS.S(urikeys[i]), ibex.resolveString(urivals[i], true));
         }
 
         // FIXME needs to obey the new application-ordering rules
@@ -97,7 +97,7 @@ public class Template {
             b.putAndTriggerTraps(b.get(JS.S("numchildren")), kid);
         }
 
-        if (script != null) JS.cloneWithNewParentScope(script, pis).call(null, null, null, null, 0);
+        if (script != null) JS.cloneWithNewGlobalScope(script, pis).call(null, null, null, null, 0);
 
         for(int i=0; keys != null && i < keys.length; i++) {
             if (keys[i] == null) continue;
@@ -167,8 +167,8 @@ public class Template {
             parse(new InputStreamReader(is));
             JS staticScript = parseScript(static_content, static_content_start);
             t.staticObject = new JS.O();
-            t.staticScope = new PerInstantiationScope(null, ibex, null, t.staticObject);
-            if (staticScript != null) JS.cloneWithNewParentScope(staticScript, t.staticScope).call(null, null, null, null, 0);
+            JS staticScope = new PerInstantiationScope(null, ibex, null, t.staticObject);
+            if (staticScript != null) JS.cloneWithNewGlobalScope(staticScript, staticScope).call(null, null, null, null, 0);
         }
 
         private JS parseScript(StringBuffer content, int content_start) throws IOException {
@@ -211,6 +211,7 @@ public class Template {
                     // t.prev2 = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999);
                     if(t.prev2 != null) throw new Error("FIXME: t.prev2 != null");
                     t.prev2 = ((Ibex.Blessing)t.ibex.resolveString(tagname, false)).getTemplate();
+                    if(t.prev2 == null) throw new Exception("" + tagname + " not found");
                 } catch (Exception e) {
                     Log.error(Template.class, e);
                 }
@@ -326,32 +327,41 @@ public class Template {
         public void whitespace(char[] ch, int start, int length) throws XML.Exn { }
     }
 
-    private static class PerInstantiationScope extends JSScope {
+    private static class PerInstantiationScope extends JS.O {
         Ibex ibex = null;
         PerInstantiationScope parentBoxPis = null;
         JS myStatic = null;
+        JS box;
         void putDollar(String key, Box target) throws JSExn {
             if (parentBoxPis != null) parentBoxPis.putDollar(key, target);
             JS jskey = JS.S("$" + key);
-            declare(jskey);
-            put(jskey, target);
+            //declare(jskey);
+            sput(jskey, target);
         }
-        public PerInstantiationScope(JSScope parentScope, Ibex ibex, PerInstantiationScope parentBoxPis, JS myStatic) {
-            super(parentScope);
+        // JS:FIXME: ugly
+        void sput(JS key, JS val) throws JSExn { super.put(key,val); }
+        public PerInstantiationScope(JS box, Ibex ibex, PerInstantiationScope parentBoxPis, JS myStatic) {
             this.parentBoxPis = parentBoxPis;
             this.ibex = ibex;
             this.myStatic = myStatic;
+            this.box = box;
         }
         public JS get(JS key) throws JSExn {
-            if (super.has(key)) return super.get(key);
             if(JS.isString(key)) {
                 String s = JS.toString(key);
+                // JS:FIXME This is a hack
+                if (super.get(key) != null) return super.get(key);
                 if (s.equals("ibex")) return ibex;
                 if (s.equals("")) return ibex.get(key);
                 if (s.equals("static")) return myStatic;
             }
-            return super.get(key);
+            // JS:FIXME: This won't work with traps that do blocking operations
+            return box.getAndTriggerTraps(key);
         }
+        // JS:FIXME: Everything below here should come from js.scope or something
+        public void put(JS key, JS val) throws JSExn { if(box != null) box.putAndTriggerTraps(key,val); else super.put(key,val); }
+        public void addTrap(JS key, JSFunction f) throws JSExn { box.addTrap(key,f); }
+        public void delTrap(JS key, JSFunction f) throws JSExn { box.delTrap(key,f); }
     }
 
 }
index 5aa3408..da94713 100644 (file)
@@ -718,7 +718,7 @@ public class HTTP {
             return ret;
         }
     
-        public static JSScope proxyAutoConfigRootScope = /*new ProxyAutoConfigRootScope();*/ null; // FIXME: New api
+        public static JS proxyAutoConfigRootScope = /*new ProxyAutoConfigRootScope();*/ null; // JS:FIXME: New api
         public static JS getProxyAutoConfigFunction(String url) {
             try { 
                 BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET()));
@@ -746,7 +746,7 @@ public class HTTP {
                 }
 
                 JS scr = JS.fromReader("PAC script at " + url, 0, new StringReader(script));
-                JS.cloneWithNewParentScope(scr, proxyAutoConfigRootScope).call(null, null, null, null, 0);
+                JS.cloneWithNewGlobalScope(scr, proxyAutoConfigRootScope).call(null, null, null, null, 0);
                 return (JS)proxyAutoConfigRootScope.get(JS.S("FindProxyForURL"));
             } catch (Exception e) {
                 if (Log.on) {
index fbbb9bc..d54ebce 100644 (file)
@@ -67,7 +67,7 @@ public class SOAP extends XMLRPC {
                     objects.addElement(null);
                 } else if (value.endsWith("arrayType") || value.endsWith("JSArray") || key.endsWith("arrayType")) {
                     objects.removeElementAt(objects.size() - 1);
-                    objects.addElement(JS.newArray());
+                    objects.addElement(new JSArray());
                 }
             }
         }
@@ -164,7 +164,7 @@ public class SOAP extends XMLRPC {
 
     /** Appends the SOAP representation of <code>o</code> to <code>sb</code> */
     void appendObject(String name, JS o, StringBuffer sb) throws JSExn {
-        // FIXME: Update for new api
+        // JS:FIXME: Update for new api
         /*
         if (o instanceof Number) {
             if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) {
index e6a3f65..72a2c76 100644 (file)
@@ -141,7 +141,7 @@ public class XMLRPC extends JS {
             case "data":
                 int i;
                 for(i=objects.size() - 1; objects.elementAt(i) != null; i--);
-                JS arr = JS.newArray();
+                JS arr = new JSArray();
                 try {
                     for(int j = i + 1; j<objects.size(); j++) arr.put(JS.N(j - i - 1), (JS)objects.elementAt(j));
                 } catch (JSExn e) {
@@ -187,7 +187,7 @@ public class XMLRPC extends JS {
 
     /** Appends the XML-RPC representation of <code>o</code> to <code>sb</code> */
     void appendObject(JS o, StringBuffer sb) throws JSExn {
-        // FIXME: Update for new api
+        // JS:FIXME: Update for new api
         throw new Error("FIXME");
         /*if (o == null) {
             throw new JSExn("attempted to send a null value via XML-RPC");