From 76982fccac3c46ccc47621dd22dc0c96b6b9cd62 Mon Sep 17 00:00:00 2001 From: brian Date: Tue, 6 Jul 2004 00:04:25 +0000 Subject: [PATCH] preliminary core conversion darcs-hash:20040706000425-24bed-2f16fdf8a0fa2cee22210a7a38817d9ac7e91d07.gz --- src/org/ibex/core/Box.java | 144 +++++++++++++++++------------------ src/org/ibex/core/Ibex.java | 121 +++++++++++++++-------------- src/org/ibex/core/Main.java | 2 +- src/org/ibex/core/Template.java | 57 +++++++------- src/org/ibex/graphics/Color.java | 2 +- src/org/ibex/graphics/HTML.java | 21 ++++- src/org/ibex/graphics/Surface.java | 43 ++++++----- src/org/ibex/net/HTTP.java | 19 ++--- src/org/ibex/net/SOAP.java | 12 +-- src/org/ibex/net/XMLRPC.java | 45 +++++------ src/org/ibex/plat/Platform.java | 2 +- src/org/ibex/util/Grammar.java | 6 +- src/org/ibex/util/Log.java | 5 +- src/org/ibex/util/Preprocessor.java | 24 ++++-- 14 files changed, 269 insertions(+), 234 deletions(-) diff --git a/src/org/ibex/core/Box.java b/src/org/ibex/core/Box.java index bb8a27b..29cd9bc 100644 --- a/src/org/ibex/core/Box.java +++ b/src/org/ibex/core/Box.java @@ -57,7 +57,7 @@ public final class Box extends JSScope implements Task { // FIXME memory leak static Hash boxToCursor = new Hash(500, 3); - static final Font DEFAULT_FONT = Font.getFont((Stream)Main.builtin.get("fonts/vera/Vera.ttf"), 10); + static final Font DEFAULT_FONT = Font.getFont((Stream)Main.builtin.get(JS.S("fonts/vera/Vera.ttf")), 10); // Flags ////////////////////////////////////////////////////////////////////// @@ -230,9 +230,11 @@ public final class Box extends JSScope implements Task { set(REPLACE); // FIXME: be smarter / more incremental } + private final static JS SIZECHANGE = JS.S("SizeChange"); + void resize(int x, int y, int width, int height) { if (x == this.x && y == this.y && width == this.width && height == this.height) return; - boolean sizechange = (this.width != width || this.height != height) && hasTrap("SizeChange"); + boolean sizechange = (this.width != width || this.height != height) && hasTrap(SIZECHANGE); int thisx = parent == null ? 0 : this.x; int thisy = parent == null ? 0 : this.y; Box who = (parent == null ? this : parent); @@ -248,7 +250,7 @@ public final class Box extends JSScope implements Task { this.width = width; this.height = height; this.x = x; this.y = y; dirty(); } - if (sizechange) putAndTriggerTrapsAndCatchExceptions("SizeChange", T); + if (sizechange) putAndTriggerTrapsAndCatchExceptions(SIZECHANGE, T); } private float targetColumnSize = (float)0.0; @@ -434,10 +436,10 @@ public final class Box extends JSScope implements Task { // Methods to implement org.ibex.js.JS ////////////////////////////////////// - public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { + public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn { switch (nargs) { case 1: { - //#switch(method) + //#switch(JS.toString(method)) case "indexof": Box b = (Box)a0; if (b.parent != this) @@ -449,8 +451,8 @@ public final class Box extends JSScope implements Task { case "distanceto": Box b = (Box)a0; JS ret = new JS.O(); - ret.put("x", N(b.localToGlobalX(0) - localToGlobalX(0))); - ret.put("y", N(b.localToGlobalY(0) - localToGlobalY(0))); + ret.put(JS.S("x"), N(b.localToGlobalX(0) - localToGlobalX(0))); + ret.put(JS.S("y"), N(b.localToGlobalY(0) - localToGlobalY(0))); return ret; //#end @@ -459,29 +461,30 @@ public final class Box extends JSScope implements Task { return super.callMethod(method, a0, a1, a2, rest, nargs); } - public Object get(Object name) throws JSExn { - if (name instanceof Number) - return redirect == null ? null : redirect == this ? getChild(toInt(name)) : redirect.get(name); + public JS get(JS name) throws JSExn { + if (JS.isInt(name)) + return redirect == null ? null : redirect == this ? getChild(JS.toInt(name)) : redirect.get(name); - //#switch(name) - case "surface": return parent == null ? null : parent.getAndTriggerTraps("surface"); + //#switch(JS.toString(name)) + case "surface": return parent == null ? null : parent.getAndTriggerTraps(name); case "indexof": return METHOD; case "distanceto": return METHOD; - case "text": return text; - case "path": - if (path != null) return path.toString(); + case "text": return JS.S(text); + case "path": { + if (path != null) return JS.S(path.toString()); if (text == null) return null; if (font == null) return null; String ret = ""; for(int i=0; i 0) { CHECKSET_SHORT(rowspan); if (parent != null) parent.REPACK(); } case "visible": CHECKSET_FLAG(VISIBLE); RECONSTRAIN(); dirty(); case "packed": CHECKSET_FLAG(PACKED); if (parent != null) { parent.REPACK(); } else { REPACK(); } - case "align": clear(ALIGNS); setAlign(value == null ? "center" : value); REPLACE(); - case "cursor": setCursor(value); + case "align": clear(ALIGNS); setAlign(value == null ? "center" : JS.toString(value)); REPLACE(); + case "cursor": setCursor(JS.toString(value)); case "fill": setFill(value); case "clip": CHECKSET_FLAG(CLIP); if (parent == null) dirty(); else parent.dirty(); case "rows": CHECKSET_SHORT(rows); if (rows==0){set(FIXED, COLS);if(cols==0)cols=1;} else set(FIXED, ROWS); REPACK(); @@ -577,8 +580,8 @@ public final class Box extends JSScope implements Task { // FIXME: remove case "mouse": - int mousex = toInt(((JS)value).get("x")); - int mousey = toInt(((JS)value).get("y")); + int mousex = toInt(((JS)value).get(JS.S("x"))); + int mousey = toInt(((JS)value).get(JS.S("y"))); getSurface()._mousex = localToGlobalX(mousex); getSurface()._mousey = localToGlobalY(mousey); @@ -592,7 +595,7 @@ public final class Box extends JSScope implements Task { case "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); RECONSTRAIN(); dirty(); case "font": if(!(value instanceof Stream)) throw new JSExn("You can only put streams to the font property"); - if (font == value) return; // FIXME: unclone() + //FIXME: if (font == value) return; // FIXME: unclone() font = value == null ? null : Font.getFont((Stream)value, font == null ? 10 : font.pointsize); RECONSTRAIN(); dirty(); @@ -629,9 +632,9 @@ public final class Box extends JSScope implements Task { case "KeyReleased": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); case "Move": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); case "HScroll": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) - parent.putAndTriggerTraps(name, N(((Number)value).floatValue() * ((float)parent.fontSize()) / ((float)fontSize()))); + parent.putAndTriggerTraps(name, N(JS.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize()))); case "VScroll": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) - parent.putAndTriggerTraps(name, N(((Number)value).floatValue() * ((float)parent.fontSize()) / ((float)fontSize()))); + parent.putAndTriggerTraps(name, N(JS.toFloat(value) * ((float)parent.fontSize()) / ((float)fontSize()))); case "_Move": propagateDownward(name, value, false); case "_Press1": propagateDownward(name, value, false); @@ -675,7 +678,7 @@ public final class Box extends JSScope implements Task { } } - private void setAlign(Object value) { + private void setAlign(String value) { clear(ALIGNS); //#switch(value) case "topleft": set(ALIGN_TOP | ALIGN_LEFT); @@ -690,7 +693,7 @@ public final class Box extends JSScope implements Task { //#end } - private void setCursor(Object value) { + private void setCursor(String value) throws JSExn { if (value == null) { clear(CURSOR); boxToCursor.remove(this); return; } if (value.equals(boxToCursor.get(this))) return; set(CURSOR); @@ -702,24 +705,22 @@ public final class Box extends JSScope implements Task { if (surface.cursor != tempcursor) surface.syncCursor(); } - private void setFill(Object value) throws JSExn { + private void setFill(JS value) throws JSExn { if (value == null) { if (texture == null && fillcolor == 0) return; texture = null; fillcolor = 0; - } else if (value instanceof String) { - int newfillcolor = Color.stringToColor((String)value); + } else if (JS.isString(value)) { + int newfillcolor = Color.stringToColor(JS.toString(value)); if (newfillcolor == fillcolor) return; fillcolor = newfillcolor; texture = null; - } else if (value instanceof JS) { + } else { Picture newtex = Picture.load((JS)value, this); if (texture == newtex) return; texture = newtex; fillcolor = 0; if (texture != null && texture.isLoaded) perform(); - } else { - throw new JSExn("fill must be null, a String, or a stream, not a " + value.getClass()); } dirty(); } @@ -728,9 +729,9 @@ public final class Box extends JSScope implements Task { * Handles events which propagate down the box tree. If obscured * is set, then we merely check for Enter/Leave. */ - private void propagateDownward(Object name_, Object value, boolean obscured) { + private void propagateDownward(JS name_, JS value, boolean obscured) throws JSExn { - String name = (String)name_; + String name = JS.toString(name_); if (getSurface() == null) return; int x = globalToLocalX(getSurface()._mousex); int y = globalToLocalY(getSurface()._mousey); @@ -738,28 +739,28 @@ public final class Box extends JSScope implements Task { boolean isinside = test(VISIBLE) && inside(x, y) && !obscured; if (!wasinside && isinside) { set(MOUSEINSIDE); - putAndTriggerTrapsAndCatchExceptions("Enter", T); + putAndTriggerTrapsAndCatchExceptions(JS.S("Enter"), T); } if (isinside && test(CURSOR)) getSurface().cursor = (String)boxToCursor.get(this); if (wasinside && !isinside) { clear(MOUSEINSIDE); - putAndTriggerTrapsAndCatchExceptions("Leave", T); + putAndTriggerTrapsAndCatchExceptions(JS.S("Leave"), T); } boolean found = false; if (wasinside || isinside) for(Box child = getChild(treeSize() - 1); child != null; child = child.prevSibling()) { boolean save_stop = child.test(STOP_UPWARD_PROPAGATION); - Object value2 = value; + JS value2 = value; if (name.equals("_HScroll") || name.equals("_VScroll")) - value2 = N(((Number)value).floatValue() * ((float)child.fontSize()) / (float)fontSize()); + value2 = N(JS.toFloat(value) * ((float)child.fontSize()) / (float)fontSize()); if (obscured || !child.inside(x - child.x, y - child.y)) { - child.propagateDownward(name, value2, true); + child.propagateDownward(name_, value2, true); } else try { found = true; child.clear(STOP_UPWARD_PROPAGATION); - if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name, value2); - else child.propagateDownward(name, value2, obscured); + if (name != null) child.putAndTriggerTrapsAndCatchExceptions(name_, value2); + else child.propagateDownward(name_, value2, obscured); } finally { if (save_stop) child.set(STOP_UPWARD_PROPAGATION); else child.clear(STOP_UPWARD_PROPAGATION); } @@ -771,7 +772,7 @@ public final class Box extends JSScope implements Task { if (!obscured && !found) if ("_Move".equals(name) || name.startsWith("_Release") || wasinside) if (name != null) - putAndTriggerTrapsAndCatchExceptions(name.substring(1), value); + putAndTriggerTrapsAndCatchExceptions(JS.S(name.substring(1)), value); } /** figures out what box in this subtree of the Box owns the pixel at x,y relitave to the Surface */ @@ -862,10 +863,10 @@ public final class Box extends JSScope implements Task { deleteNode(i); b.parent = null; REPACK(); - putAndTriggerTrapsAndCatchExceptions("ChildChange", b); + putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b); } - public void put(int i, Object value) throws JSExn { + public void put(int i, JS value) throws JSExn { if (i < 0) return; if (value != null && !(value instanceof Box)) { @@ -874,22 +875,22 @@ public final class Box extends JSScope implements Task { } if (redirect == null) { - if (value == null) putAndTriggerTrapsAndCatchExceptions("ChildChange", getChild(i)); + if (value == null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), getChild(i)); else JS.warn("attempt to add/remove children to/from a node with a null redirect"); } else if (redirect != this) { - if (value != null) putAndTriggerTrapsAndCatchExceptions("ChildChange", value); + if (value != null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), value); redirect.put(i, value); if (value == null) { - Box b = (Box)redirect.get(new Integer(i)); - if (b != null) putAndTriggerTrapsAndCatchExceptions("ChildChange", b); + Box b = (Box)redirect.get(JS.N(i)); + if (b != null) putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b); } } else if (value == null) { if (i < 0 || i > treeSize()) return; Box b = getChild(i); removeChild(i); - putAndTriggerTrapsAndCatchExceptions("ChildChange", b); + putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b); } else { Box b = (Box)value; @@ -918,26 +919,19 @@ public final class Box extends JSScope implements Task { REPACK(); b.dirty(); - putAndTriggerTrapsAndCatchExceptions("ChildChange", b); + putAndTriggerTrapsAndCatchExceptions(JS.S("ChildChange"), b); } } - public void putAndTriggerTrapsAndCatchExceptions(Object name, Object val) { + public void putAndTriggerTrapsAndCatchExceptions(JS name, JS val) { try { putAndTriggerTraps(name, val); } catch (JSExn e) { - JS.log("caught js exception while putting to trap \""+name+"\""); + JS.log("caught js exception while putting to trap \""+ JS.debugToString(name)+"\""); JS.log(e); } catch (Exception e) { - JS.log("caught exception while putting to trap \""+name+"\""); + JS.log("caught exception while putting to trap \""+ JS.debugToString(name)+"\""); JS.log(e); } } - } - - - - - - diff --git a/src/org/ibex/core/Ibex.java b/src/org/ibex/core/Ibex.java index b44ba5a..6492ed2 100644 --- a/src/org/ibex/core/Ibex.java +++ b/src/org/ibex/core/Ibex.java @@ -29,9 +29,9 @@ public final class Ibex extends JS implements JS.Cloneable { while(str.indexOf('.') != -1) { String path = str.substring(0, str.indexOf('.')); str = str.substring(str.indexOf('.') + 1); - ret = (JS)ret.get(path); + ret = ret.get(JS.S(path)); } - if (!"".equals(str)) ret = (JS)ret.get(str); + if (!"".equals(str)) ret = ret.get(JS.S(str)); return ret; } @@ -39,13 +39,13 @@ public final class Ibex extends JS implements JS.Cloneable { private class Sub extends JS { String key; Sub(String key) { this.key = key; } - public void put(Object key, Object val) throws JSExn { Ibex.this.put(this.key + "." + key, val); } - public Object get(Object key) throws JSExn { return Ibex.this.get(this.key + "." + key); } - public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { + public void put(JS key, JS val) throws JSExn { Ibex.this.put(this.key + "." + JS.toString(key), val); } + public JS get(JS key) throws JSExn { return Ibex.this.get(this.key + "." + JS.toString(key)); } + public JS call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn { return Ibex.this.callMethod(this.key, a0, a1, a2, rest, nargs); } - public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { - return Ibex.this.callMethod(this.key + "." + method, a0, a1, a2, rest, nargs); + public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn { + return Ibex.this.callMethod(this.key + "." + JS.toString(method), a0, a1, a2, rest, nargs); } } private Cache subCache = new Cache(20); @@ -55,7 +55,8 @@ public final class Ibex extends JS implements JS.Cloneable { return ret; } - public Object get(Object name) throws JSExn { + public JS get(JS key) throws JSExn { return JS.isString(key) ? get(JS.toString(key)) : null; } + JS get(String name) throws JSExn { if (name instanceof String && ((String)name).length() == 0) return rr; //#switch(name) case "math": return ibexMath; @@ -70,9 +71,9 @@ public final class Ibex extends JS implements JS.Cloneable { case "ui.font.wait": return METHOD; case "ui.font.width": return METHOD; case "ui.font.height": return METHOD; - case "ui.font.sansserif": return Main.builtin.get("fonts/vera/Vera.ttf"); - case "ui.font.monospace": return Main.builtin.get("fonts/vera/VeraMono.ttf"); - case "ui.font.serif": return Main.builtin.get("fonts/vera/VeraSe.ttf"); + case "ui.font.sansserif": return Main.builtin.get(JS.S("fonts/vera/Vera.ttf")); + case "ui.font.monospace": return Main.builtin.get(JS.S("fonts/vera/VeraMono.ttf")); + case "ui.font.serif": return Main.builtin.get(JS.S("fonts/vera/VeraSe.ttf")); case "ui.browser": return METHOD; case "ui.mouse": return getSub("ui.mouse"); case "ui.mouse.button": @@ -82,18 +83,18 @@ public final class Ibex extends JS implements JS.Cloneable { else return ZERO; case "ui.key": return getSub("ui.key"); case "ui.key.name": return getSub("ui.key.name"); - case "ui.key.name.alt": return Platform.altKeyName(); + case "ui.key.name.alt": return JS.S(Platform.altKeyName()); case "ui.key.alt": return Surface.alt ? T : F; case "ui.key.control": return Surface.control ? T : F; case "ui.key.shift": return Surface.shift ? T : F; - case "ui.clipboard": return Platform.getClipBoard(); + case "ui.clipboard": return JS.S((String)Platform.getClipBoard()); case "ui.maxdim": return N(Short.MAX_VALUE); case "ui.screen": return getSub("ui.screen"); case "ui.screen.width": return N(Platform.getScreenWidth()); case "ui.screen.height": return N(Platform.getScreenHeight()); case "undocumented": return getSub("undocumented"); - case "undocumented.initialOrigin": return Main.origin; - case "undocumented.initialTemplate": return Main.initialTemplate; + case "undocumented.initialOrigin": return JS.S(Main.origin); + case "undocumented.initialTemplate": return JS.S(Main.initialTemplate); case "thread": return getSub("thread"); case "thread.yield": return METHOD; case "thread.sleep": return METHOD; @@ -123,13 +124,14 @@ public final class Ibex extends JS implements JS.Cloneable { case "crypto.sha1": return METHOD; case "crypto.rc4": return METHOD; //#end - return super.get(name); + return null; } - public void put(Object name, final Object value) throws JSExn { + public void put(JS key, JS value) throws JSExn { if(JS.isString(key)) put(JS.toString(key),value); else super.put(key,value); } + void put(Object name, final JS value) throws JSExn { //#switch(name) case "thread": Scheduler.add((Task)value); return; - case "ui.clipboard": Platform.setClipBoard((String)value); return; + case "ui.clipboard": Platform.setClipBoard(JS.toString(value)); return; case "ui.frame": Platform.createSurface((Box)value, true, true); return; case "ui.window": Platform.createSurface((Box)value, false, true); return; case "undocumented.proxyAuthorization": @@ -140,11 +142,15 @@ public final class Ibex extends JS implements JS.Cloneable { throw new JSExn("attempted to put unknown property: ibex."+name); } - public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn { + public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn { + if(JS.isString(name)) return callMethod(JS.toString(name),a,b,c,rest,nargs); + return super.callMethod(name,a,b,c,rest,nargs); + } + JS callMethod(String name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn { try { //#switch(name) case "date": return new JSDate(a, b, c, rest, nargs); - case "net.rpc.soap": return new SOAP((String)a, "", (String)b, (String)c); + case "net.rpc.soap": return new SOAP(JS.toString(a), "", JS.toString(b), JS.toString(c)); // FIXME support object dumping case "log.debug": JS.debug(a== null ? "**null**" : a.toString()); return null; case "log.info": JS.info(a== null ? "**null**" : a.toString()); return null; @@ -164,14 +170,14 @@ public final class Ibex extends JS implements JS.Cloneable { if(a == null) throw new JSExn("can't clone the null value"); return ((JS)a).jsclone(); case "bless": return bless((JS)a); - case "ui.browser": Platform.newBrowserWindow((String)a); return null; + case "ui.browser": Platform.newBrowserWindow(JS.toString(a)); return null; case "stream.unzip": return new Stream.Zip((Stream)a); case "stream.uncab": return new Stream.Cab((Stream)a); case "stream.cache": try { return new Stream.CachedStream((Stream)a, "resources", true); } catch (Stream.NotCacheableException e) { throw new JSExn("this resource cannot be cached"); } case "stream.url": { - String url = (String)a; + String url = JS.toString(a); if (url.startsWith("http://")) return new Stream.HTTP(url); else if (url.startsWith("https://")) return new Stream.HTTP(url); else if (url.startsWith("data:")) return new Stream.ByteArray(Base64.decode(url.substring(5)), null); @@ -184,7 +190,7 @@ public final class Ibex extends JS implements JS.Cloneable { } case "thread.sleep": sleep(JS.toInt(a)); return null; case "regexp": return new JSRegexp(a, null); - case "net.rpc.xml": return new XMLRPC((String)a, ""); + case "net.rpc.xml": return new XMLRPC(JS.toString(a), ""); case "crypto.rsa": /* FEATURE */ return null; case "crypto.md5": /* FEATURE */ return null; case "crypto.sha1": /* FEATURE */ return null; @@ -192,7 +198,7 @@ public final class Ibex extends JS implements JS.Cloneable { case "stream.parse.html": throw new JSExn("not implemented yet"); //return null; case "stream.parse.xml": new XMLHelper((JS)b).doParse((JS)a); return null; // FIXME backgrounding - case "stream.parse.utf8": try { return new String(InputStreamToByteArray.convert(Stream.getInputStream(a))); } + case "stream.parse.utf8": try { return JS.S(new String(InputStreamToByteArray.convert(Stream.getInputStream(a)))); } catch (Exception e) { Log.warn(this, e); } //#end break; @@ -203,9 +209,9 @@ public final class Ibex extends JS implements JS.Cloneable { //#end case 3: //#switch(name) - case "ui.font.height": return N(Font.getFont((Stream)a, JS.toInt(b)).textheight((String)c)); + case "ui.font.height": return N(Font.getFont((Stream)a, JS.toInt(b)).textheight(JS.toString(c))); case "ui.font.wait": throw new Error("FIXME: ibex.ui.font.wait not implemented"); - case "ui.font.width": return N(Font.getFont((Stream)a, JS.toInt(b)).textwidth((String)c)); + case "ui.font.width": return N(Font.getFont((Stream)a, JS.toInt(b)).textwidth(JS.toString(c))); //#end break; } @@ -242,9 +248,9 @@ public final class Ibex extends JS implements JS.Cloneable { public static final JSMath ibexMath = new JSMath() { // FEATURE: find a cleaner way to do this - private JS gs = new JSScope.Global(); - public Object get(Object key) throws JSExn { - //#switch(key) + private JS gs = /*new JSScope.Global();*/ null; // FIXME: Global scope + public JS get(JS key) throws JSExn { + //#switch(JS.toString(key)) case "isNaN": return METHOD; case "isFinite": return METHOD; case "NaN": return METHOD; @@ -252,8 +258,8 @@ public final class Ibex extends JS implements JS.Cloneable { //#end return super.get(key); } - public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn { - //#switch(name) + public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn { + //#switch(JS.toString(name)) case "isNaN": return gs.callMethod(name,a,b,c,rest,nargs); case "isFinite": return gs.callMethod(name,a,b,c,rest,nargs); case "NaN": return gs.callMethod(name,a,b,c,rest,nargs); @@ -264,9 +270,9 @@ public final class Ibex extends JS implements JS.Cloneable { }; public static final JS ibexString = new JS() { - private JS gs = new JSScope.Global(); - public Object get(Object key) throws JSExn { - //#switch(key) + private JS gs = /*new JSScope.Global();*/ null; // FIXME: Global scope + public JS get(JS key) throws JSExn { + //#switch(JS.toString(key)) case "parseInt": return METHOD; case "parseFloat": return METHOD; case "decodeURI": return METHOD; @@ -279,8 +285,8 @@ public final class Ibex extends JS implements JS.Cloneable { //#end return super.get(key); } - public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn { - //#switch(name) + public JS callMethod(JS name, JS a, JS b, JS c, JS[] rest, int nargs) throws JSExn { + //#switch(JS.toString(name)) case "parseInt": return gs.callMethod(name,a,b,c,rest,nargs); case "parseFloat": return gs.callMethod(name,a,b,c,rest,nargs); case "decodeURI": return gs.callMethod(name,a,b,c,rest,nargs); @@ -300,29 +306,29 @@ public final class Ibex extends JS implements JS.Cloneable { private JS characters, whitespace, endElement, startElement; public XMLHelper(JS b) throws JSExn { super(BUFFER_SIZE); - startElement = (JS)b.getAndTriggerTraps("startElement"); - endElement = (JS)b.getAndTriggerTraps("endElement"); - characters = (JS)b.getAndTriggerTraps("characters"); - whitespace = (JS)b.getAndTriggerTraps("whitespace"); + startElement = b.getAndTriggerTraps(JS.S("startElement")); + endElement = b.getAndTriggerTraps(JS.S("endElement")); + characters = b.getAndTriggerTraps(JS.S("characters")); + whitespace = b.getAndTriggerTraps(JS.S("whitespace")); } public void startElement(XML.Element c) throws XML.Exn { try { JS attrs = new JS.O(); // FIXME attribute URIs? add an additional hash? - for(int i=0; i 0) { - switch (((String)val).charAt(0)) { + if (JS.isString(val) && (JS.toString(val).length() > 0)) { + switch (JS.toString(val).charAt(0)) { case '$': val = pis.get(val); - if (val == null) throw new JSExn("unknown box id '"+vals[i]+"' referenced in XML attribute"); + if (val == null) throw new JSExn("unknown box id '"+JS.toString(vals[i])+"' referenced in XML attribute"); break; case '.': - val = ibex.resolveString(((String)val).substring(1), false); + val = ibex.resolveString(JS.toString(val).substring(1), false); // FIXME: url case // FIXME: should we be resolving all of these in the XML-parsing code? } } - b.putAndTriggerTraps(key, val); + b.putAndTriggerTraps(JS.S(key), val); } } @@ -126,7 +126,7 @@ public class Template { // XML Parsing ///////////////////////////////////////////////////////////////// - public static Template buildTemplate(String sourceName, Object s, Ibex ibex) { + public static Template buildTemplate(String sourceName, JS s, Ibex ibex) { try { return new TemplateHelper(sourceName, s, ibex).t; } catch (Exception e) { @@ -154,7 +154,7 @@ public class Template { String initial_uri = ""; - public TemplateHelper(String sourceName, Object s, Ibex ibex) throws XML.Exn, IOException, JSExn { + public TemplateHelper(String sourceName, JS s, Ibex ibex) throws XML.Exn, IOException, JSExn { this.sourceName = sourceName; this.ibex = ibex; InputStream is = Stream.getInputStream(s); @@ -207,7 +207,8 @@ public class Template { // GROSS hack try { // GROSSER hack - t.prev2 = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999); + // t.prev2 = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999); + throw new Error("FIXME - 9999 thing"); // FIXME:9999 thing } catch (Exception e) { Log.error(Template.class, e); } @@ -253,7 +254,7 @@ public class Template { } }); t.keys = new String[keys.size()]; - t.vals = new Object[vals.size()]; + t.vals = new JS[vals.size()]; keys.copyInto(t.keys); vals.copyInto(t.vals); @@ -263,8 +264,8 @@ public class Template { String valString = t.vals[i].toString(); - if (valString.equals("true")) t.vals[i] = Boolean.TRUE; - else if (valString.equals("false")) t.vals[i] = Boolean.FALSE; + if (valString.equals("true")) t.vals[i] = JS.T; + else if (valString.equals("false")) t.vals[i] = JS.F; else if (valString.equals("null")) t.vals[i] = null; else { boolean hasNonNumeral = false; @@ -277,8 +278,8 @@ public class Template { hasNonNumeral = true; break; } - if (valString.length() > 0 && !hasNonNumeral) t.vals[i] = new Double(valString); - else t.vals[i] = valString.intern(); + if (valString.length() > 0 && !hasNonNumeral) t.vals[i] = JS.N(Double.parseDouble((valString))); + else t.vals[i] = JS.S(valString.intern()); // FEATURE: JS.intern() ? } } } @@ -331,8 +332,9 @@ public class Template { JS myStatic = null; void putDollar(String key, Box target) throws JSExn { if (parentBoxPis != null) parentBoxPis.putDollar(key, target); - declare("$" + key); - put("$" + key, target); + JS jskey = JS.S("$" + key); + declare(jskey); + put(jskey, target); } public PerInstantiationScope(JSScope parentScope, Ibex ibex, PerInstantiationScope parentBoxPis, JS myStatic) { super(parentScope); @@ -340,11 +342,14 @@ public class Template { this.ibex = ibex; this.myStatic = myStatic; } - public Object get(Object key) throws JSExn { + public JS get(JS key) throws JSExn { if (super.has(key)) return super.get(key); - if (key.equals("ibex")) return ibex; - if (key.equals("")) return ibex.get(""); - if (key.equals("static")) return myStatic; + if(JS.isString(key)) { + String s = JS.toString(key); + if (s.equals("ibex")) return ibex; + if (s.equals("")) return ibex.get(key); + if (s.equals("static")) return myStatic; + } return super.get(key); } } diff --git a/src/org/ibex/graphics/Color.java b/src/org/ibex/graphics/Color.java index 210aade..f12e433 100644 --- a/src/org/ibex/graphics/Color.java +++ b/src/org/ibex/graphics/Color.java @@ -8,7 +8,7 @@ public class Color { public static int stringToColor(String s) { // FIXME support three-char strings by doubling digits if (s == null) return 0x00000000; - else if (standard.get(s) != null) return 0xFF000000 | org.ibex.js.JS.toInt(standard.get(s)); + else if (standard.get(s) != null) return 0xFF000000 | ((Integer)standard.get(s)).intValue(); else if (s.length() == 7 && s.charAt(0) == '#') try { // FEATURE alpha return 0xFF000000 | diff --git a/src/org/ibex/graphics/HTML.java b/src/org/ibex/graphics/HTML.java index 8896e6f..e34704e 100644 --- a/src/org/ibex/graphics/HTML.java +++ b/src/org/ibex/graphics/HTML.java @@ -50,9 +50,24 @@ public class HTML { /** true iff we have encountered an LI more recently than the last OL/UL */ private static boolean withinLI = false; + // FEATURE: This is ugly + private static class JS extends org.ibex.js.JS.O { + public void put(String key, Object value) throws JSExn { + if(value instanceof String) put(JS.S(key),JS.S((String)value)); + else if(value instanceof Number) put(JS.S(key), JS.N((Number)value)); + else if(value == null) put(JS.S(key),null); + else throw new Error("FIXME"); + } + public Object _get(String key) throws JSExn { + org.ibex.js.JS js = get(JS.S(key)); + if(JS.isInt(js)) return new Integer(JS.toInt(js)); + return JS.toString(js); + } + } + public static synchronized JS parseReader(Reader r) throws IOException, JSExn { CharStream cs = new CharStream(r); - JS h = new JS.O(); + JS h = new JS(); withinLI = false; h.put("$name", "html"); @@ -137,7 +152,7 @@ public class HTML { */ private static String parseBody(CharStream cs, JS h, String elementName) throws IOException, JSExn { String cdata = ""; - int length = h.get("$numchildren") == null ? 0 : Integer.parseInt(h.get("$numchildren").toString()); + int length = h._get("$numchildren") == null ? 0 : Integer.parseInt(h._get("$numchildren").toString()); while(true) { String closetag = null; @@ -163,7 +178,7 @@ public class HTML { try { // scan subelement if (cs.peek() != '/') { - JS kid = new JS.O(); + JS kid = new JS(); closetag = parseElement(cs, kid); h.put(String.valueOf(length), kid); h.put("$numchildren", new Integer(++length)); diff --git a/src/org/ibex/graphics/Surface.java b/src/org/ibex/graphics/Surface.java index 31ac36e..574cc35 100644 --- a/src/org/ibex/graphics/Surface.java +++ b/src/org/ibex/graphics/Surface.java @@ -17,8 +17,8 @@ public abstract class Surface extends PixelBuffer implements Task { // Static Data //////////////////////////////////////////////////////////////////////////////// - private static Boolean T = Boolean.TRUE; - private static Boolean F = Boolean.FALSE; + private static final JS T = JS.T; + private static final JS F = JS.F; /** all instances of Surface which need to be refreshed by the Scheduler */ public static Vec allSurfaces = new Vec(); @@ -96,7 +96,7 @@ public abstract class Surface extends PixelBuffer implements Task { Scheduler.add(new Task() { public void perform() throws JSExn { Platform.clipboardReadEnabled = true; try { - root.putAndTriggerTraps("_Press3", T); + root.putAndTriggerTraps(JS.S("_Press3"), T); } finally { Platform.clipboardReadEnabled = false; } @@ -130,6 +130,7 @@ public abstract class Surface extends PixelBuffer implements Task { } } + private final static JS MOVE = JS.S("_Move"); /** we enqueue ourselves in the Scheduler when we have a Move message to deal with */ private Task mover = new Task() { public void perform() { @@ -139,7 +140,7 @@ public abstract class Surface extends PixelBuffer implements Task { String oldcursor = cursor; cursor = "default"; // FIXME: Root (ONLY) gets motion events outside itself (if trapped) if (oldmousex != mousex || oldmousey != mousey) - root.putAndTriggerTrapsAndCatchExceptions("_Move", T); + root.putAndTriggerTrapsAndCatchExceptions(MOVE, T); if (!cursor.equals(oldcursor)) syncCursor(); } }; @@ -155,10 +156,10 @@ public abstract class Surface extends PixelBuffer implements Task { Scheduler.add(mover); } - protected final void HScroll(int pixels) { new Message("_HScroll", new Integer(pixels), root); } - protected final void VScroll(int pixels) { new Message("_VScroll", new Integer(pixels), root); } - protected final void HScroll(float lines) { new Message("_HScroll", new Float(lines), root); } - protected final void VScroll(float lines) { new Message("_VScroll", new Float(lines), root); } + protected final void HScroll(int pixels) { new Message("_HScroll", JS.N(pixels), root); } + protected final void VScroll(int pixels) { new Message("_VScroll", JS.N(pixels), root); } + protected final void HScroll(float lines) { new Message("_HScroll", JS.N(lines), root); } + protected final void VScroll(float lines) { new Message("_VScroll", JS.N(lines), root); } /** subclasses should invoke this method when the user resizes the window */ protected final void SizeChange(final int width, final int height) { @@ -175,14 +176,14 @@ public abstract class Surface extends PixelBuffer implements Task { Scheduler.add(new Task() { public void perform() throws JSExn { root.x = x; root.y = y; - root.putAndTriggerTrapsAndCatchExceptions("PosChange", T); + root.putAndTriggerTrapsAndCatchExceptions(JS.S("PosChange"), T); }}); } private final String[] doubleClick = new String[] { null, "_DoubleClick1", "_DoubleClick2", "_DoubleClick3" }; protected final void DoubleClick(int button) { new Message(doubleClick[button], T, root); } - protected final void KeyPressed(String key) { new Message("_KeyPressed", key, root); } - protected final void KeyReleased(String key) { new Message("_KeyReleased", key, root); } + protected final void KeyPressed(String key) { new Message("_KeyPressed", JS.S(key), root); } + protected final void KeyReleased(String key) { new Message("_KeyReleased", JS.S(key), root); } protected final void Close() { new Message("Close", T, root); } protected final void Minimized(boolean b) { minimized = b; new Message("Minimized", b ? T : F, root); } protected final void Maximized(boolean b) { maximized = b; new Message("Maximized", b ? T : F, root); } @@ -304,37 +305,37 @@ public abstract class Surface extends PixelBuffer implements Task { public class Message implements Task { private Box boxContainingMouse; - private Object value; + private JS value; public String name; - Message(String name, Object value, Box boxContainingMouse) { + Message(String name, JS value, Box boxContainingMouse) { this.boxContainingMouse = boxContainingMouse; this.name = name; this.value = value; Scheduler.add(this); } - public void perform() { + public void perform() throws JSExn { if (name.equals("_KeyPressed")) { - String value = (String)this.value; + String value = JS.toString(this.value); if (value.toLowerCase().endsWith("shift")) shift = true; else if (shift) value = value.toUpperCase(); if (value.toLowerCase().equals("alt")) alt = true; else if (alt) value = "A-" + value; if (value.toLowerCase().endsWith("control")) control = true; else if (control) value = "C-" + value; if (value.equals("C-v") || value.equals("A-v")) Platform.clipboardReadEnabled = true; - this.value = value; + this.value = JS.S(value); } else if (name.equals("_KeyReleased")) { - String value = (String)this.value; + String value = JS.toString(this.value); if (value.toLowerCase().equals("alt")) alt = false; else if (value.toLowerCase().equals("control")) control = false; else if (value.toLowerCase().equals("shift")) shift = false; - this.value = value; + this.value = JS.S(value); } else if (name.equals("_HScroll") || name.equals("_VScroll")) { // FIXME: technically points != pixels - if (value instanceof Integer) - value = new Float(((Integer)value).intValue() * root.fontSize()); + if (JS.isInt(value)) + value = JS.N(JS.toInt(value) * root.fontSize()); } try { - boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(name, value); + boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(JS.S(name), value); } finally { Platform.clipboardReadEnabled = false; } diff --git a/src/org/ibex/net/HTTP.java b/src/org/ibex/net/HTTP.java index 5f8a4ed..3c2d970 100644 --- a/src/org/ibex/net/HTTP.java +++ b/src/org/ibex/net/HTTP.java @@ -271,9 +271,9 @@ public class HTTP { if (Log.verbose) Log.info(this, "evaluating PAC script"); String pac = null; try { - Object obj = pacFunc.call(url, host, null, null, 2); - if (Log.verbose) Log.info(this, " PAC script returned \"" + obj + "\""); - pac = obj.toString(); + JS obj = pacFunc.call(JS.S(url), JS.S(host), null, null, 2); + if (Log.verbose) Log.info(this, " PAC script returned \"" + JS.debugToString(obj) + "\""); + pac = JS.toString(obj); } catch (Throwable e) { if (Log.on) Log.info(this, "PAC script threw exception " + e); return null; @@ -718,7 +718,7 @@ public class HTTP { return ret; } - public static JSScope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope(); + public static JSScope proxyAutoConfigRootScope = /*new ProxyAutoConfigRootScope();*/ null; // FIXME: New api public static JS getProxyAutoConfigFunction(String url) { try { BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET())); @@ -747,7 +747,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); - return (JS)proxyAutoConfigRootScope.get("FindProxyForURL"); + return (JS)proxyAutoConfigRootScope.get(JS.S("FindProxyForURL")); } catch (Exception e) { if (Log.on) { Log.info(Platform.class, "WPAD detection failed due to:"); @@ -790,8 +790,8 @@ public class HTTP { // FIXME //Template.buildTemplate("org/ibex/builtin/proxy_authorization.ibex", Stream.getInputStream((JS)Main.builtin.get("org/ibex/builtin/proxy_authorization.ibex")), new Ibex(null)); t.apply(b); - b.put("realm", realm); - b.put("proxyIP", proxyIP); + b.put(JS.S("realm"), JS.S(realm)); + b.put(JS.S("proxyIP"), JS.S(proxyIP)); } }); @@ -803,7 +803,8 @@ public class HTTP { // ProxyAutoConfigRootJSScope //////////////////////////////////////////////////////////////////// - public static class ProxyAutoConfigRootScope extends JSScope.Global { + // FIXME: JS Update for new API + /*public static class ProxyAutoConfigRootScope extends JSScope.Global { public ProxyAutoConfigRootScope() { super(); } @@ -915,7 +916,7 @@ public class HTTP { return false; } public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; - } + }*/ /** diff --git a/src/org/ibex/net/SOAP.java b/src/org/ibex/net/SOAP.java index 55f18f5..3d998d5 100644 --- a/src/org/ibex/net/SOAP.java +++ b/src/org/ibex/net/SOAP.java @@ -136,7 +136,7 @@ public class SOAP extends XMLRPC { } // remove ourselves - Object me = objects.elementAt(objects.size() - 1); + JS me = (JS) objects.elementAt(objects.size() - 1); // find our parent Object parent = objects.size() > 1 ? objects.elementAt(objects.size() - 2) : null; @@ -152,7 +152,7 @@ public class SOAP extends XMLRPC { } else if (parent != null && parent instanceof JS) { objects.removeElementAt(objects.size() - 1); try { - ((JS)parent).put(name, me); + ((JS)parent).put(JS.S(name), me); } catch (JSExn e) { throw new Error("this should never happen"); } @@ -162,7 +162,9 @@ public class SOAP extends XMLRPC { } /** Appends the SOAP representation of o to sb */ - void appendObject(String name, Object o, StringBuffer sb) throws JSExn { + void appendObject(String name, JS o, StringBuffer sb) throws JSExn { + // FIXME: Update for new api + /* if (o instanceof Number) { if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) { sb.append(" <" + name + " xsi:type=\"xsd:int\">"); @@ -239,7 +241,7 @@ public class SOAP extends XMLRPC { } sb.append("\r\n"); - } + }*/ } protected String buildRequest(JSArray args) throws JSExn, IOException { @@ -261,7 +263,7 @@ public class SOAP extends XMLRPC { Enumeration e = ((JS)args.elementAt(0)).keys(); while(e.hasMoreElements()) { Object key = e.nextElement(); - appendObject((String)key, ((JS)args.elementAt(0)).get(key), content); + appendObject((String)key, args.elementAt(0).get((JS)key), content); } } content.append(" \r\n"); diff --git a/src/org/ibex/net/XMLRPC.java b/src/org/ibex/net/XMLRPC.java index 290415f..66908d8 100644 --- a/src/org/ibex/net/XMLRPC.java +++ b/src/org/ibex/net/XMLRPC.java @@ -92,17 +92,17 @@ public class XMLRPC extends JS { public void endElement(XML.Element c) { //#switch(c.getLocalName()) - case "int": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1); - case "i4": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1); - case "boolean": objects.setElementAt(content.getBuf()[0] == '1' ? Boolean.TRUE : Boolean.FALSE, objects.size() - 1); - case "string": objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1); - case "double": objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1); + case "int": objects.setElementAt(JS.N(Integer.parseInt(new String(content.getBuf(), 0, content.size()))), objects.size() - 1); + case "i4": objects.setElementAt(JS.N(Integer.parseInt(new String(content.getBuf(), 0, content.size()))), objects.size() - 1); + case "boolean": objects.setElementAt(content.getBuf()[0] == '1' ? JS.T : JS.F, objects.size() - 1); + case "string": objects.setElementAt(JS.S(new String(content.getBuf(), 0, content.size())), objects.size() - 1); + case "double": objects.setElementAt(JS.N(Double.parseDouble(new String(content.getBuf(), 0, content.size()))), objects.size() - 1); case "base64": objects.setElementAt(new Stream.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())), null), objects.size() - 1); - case "name": objects.addElement(new String(content.getBuf(), 0, content.size())); + case "name": objects.addElement(JS.S(new String(content.getBuf(), 0, content.size()))); case "value": if ("".equals(objects.lastElement())) - objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1); + objects.setElementAt(JS.S(new String(content.getBuf(), 0, content.size())), objects.size() - 1); case "dateTime.iso8601": String s = new String(content.getBuf(), 0, content.size()); @@ -129,11 +129,11 @@ public class XMLRPC extends JS { "the server sent a tag which was malformed: " + s); } case "member": - Object memberValue = objects.elementAt(objects.size() - 1); + JS memberValue = (JS) objects.elementAt(objects.size() - 1); String memberName = (String)objects.elementAt(objects.size() - 2); JS struct = (JS)objects.elementAt(objects.size() - 3); try { - struct.put(memberName, memberValue); + struct.put(JS.S(memberName), memberValue); } catch (JSExn e) { throw new Error("this should never happen"); } @@ -143,7 +143,7 @@ public class XMLRPC extends JS { for(i=objects.size() - 1; objects.elementAt(i) != null; i--); JSArray arr = new JSArray(); try { - for(int j = i + 1; jo to sb */ - void appendObject(Object o, StringBuffer sb) throws JSExn { - - if (o == null) { + void appendObject(JS o, StringBuffer sb) throws JSExn { + // FIXME: Update for new api + throw new Error("FIXME"); + /*if (o == null) { throw new JSExn("attempted to send a null value via XML-RPC"); } else if (o instanceof Number) { @@ -295,19 +296,19 @@ public class XMLRPC extends JS { } else { throw new JSExn("attempt to send object of type " + o.getClass().getName() + " via XML-RPC"); - } + }*/ } // Call Sequence ////////////////////////////////////////////////////////////////////////// - public final Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { + public final JS call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn { JSArray args = new JSArray(); for(int i=0; i