Revision: 3166 http://vexi.svn.sourceforge.net/vexi/?rev=3166&view=rev Author: mkpg2 Date: 2008-11-03 11:22:14 +0000 (Mon, 03 Nov 2008)
Log Message: ----------- Features. <js:object/> vexi.js.proxy Modified Paths: -------------- trunk/core/org.ibex.js/src/org/ibex/js/Constants.java trunk/core/org.ibex.js/src/org/ibex/js/JS.jpp trunk/core/org.ibex.js/src/org/ibex/js/Thread.java trunk/core/org.ibex.js/src_dev/org/ibex/js/JSDynProxy.java trunk/core/org.ibex.js/src_dev/org/ibex/js/RunJS.java trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/TestRangeTraps.java trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/readProxy.js trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/writeProxy.js trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp trunk/core/org.vexi.core/src/org/vexi/core/Constants.java trunk/core/org.vexi.core/src/org/vexi/core/Template.java trunk/core/org.vexi.core/src/org/vexi/core/TemplateBuilder.java trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp Added Paths: ----------- trunk/core/org.vexi.core/src_junit/test/core/jsobj/ trunk/core/org.vexi.core/src_junit/test/core/jsobj/TestJSObj.java trunk/core/org.vexi.core/src_junit/test/core/jsobj/_jstemplate.t trunk/core/org.vexi.core/src_junit/test/core/jsobj/simple.t Modified: trunk/core/org.ibex.js/src/org/ibex/js/Constants.java =================================================================== --- trunk/core/org.ibex.js/src/org/ibex/js/Constants.java 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.ibex.js/src/org/ibex/js/Constants.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -30,6 +30,7 @@ static final JS SC_object = JSU.S("object",true); static final JS SC_remote = JSU.S("remote",true); static final JS SC_progress = JSU.S("progress",true); + static final JS SC_Properties = JSU.S("Properties",true); static final JS SC_some = JSU.S("some",true); static final JS SC_start = JSU.S("start",true); static final JS SC_stream = JSU.S("stream",true); Modified: trunk/core/org.ibex.js/src/org/ibex/js/JS.jpp =================================================================== --- trunk/core/org.ibex.js/src/org/ibex/js/JS.jpp 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.ibex.js/src/org/ibex/js/JS.jpp 2008-11-03 11:22:14 UTC (rev 3166) @@ -186,7 +186,9 @@ } } + public static class Obj extends Basket.Hash implements Cloneable { + Trap propertiesTrap = null; public Obj() { super(3, 4, 0.75F); if(Instr.memory!=null) Instr.memory.register(this); @@ -228,15 +230,15 @@ }; } public JS type() { return SC_object;} - public JS get(JS key) throws JSExn { return (JS)super.get(key, 0); } + public JS get(JS key) throws JSExn { + return (JS)super.get(key, 0); + } - public void put(JS key, JS val) throws JSExn { - // REMARK - putting null does _not_ remove the key - super.put(key, val, 0); + public void put(JS key, JS value) throws JSExn { + super.put(key, value, 0); } public JS getAndTriggerTraps(JS key) throws JSExn { - // FEATURE 'Properties' trap Trap t = (Trap)super.get(key, 1); return t == null || (t = t.read()) == null ? (JS)get(key) : Scheduler.get().runInCurrent(t); @@ -259,33 +261,25 @@ return val; } - public JS putAndTriggerTraps(JS key, JS val) throws JSExn { - Trap t = (Trap)super.get(key, 1); + public JS putAndTriggerTraps(JS key, JS value) throws JSExn { + Trap t = (Trap)super.get(key, 1); if (t != null && (t = t.write()) != null){ JSExn wasException = null; try{ - JS r = Scheduler.get().runBeforePut(t, val); + JS r = Scheduler.get().runBeforePut(t, value); if(r!=Interpreter.CASCADE_PREVENTED) put(key, r); }catch(JSExn e){ wasException = e; throw e; } - /* REMARK can only have JSExns ... TODO remove later - catch(Exception e){ - wasException = true; - if(e instanceof JSExn) - throw (JSExn)e; - else - throw new JSExn(e.getMessage()); - }*/ finally{ Scheduler.get().runAfterPut(wasException); } }else{ - put(key, val); + put(key, value); } - return val; + return value; } public void addTrap(JS key, JS f) throws JSExn { @@ -297,15 +291,26 @@ if (f.getFormalArgs().length > 1 ) throw new JSExn("traps must take either one argument (write) or no arguments (read)"); - for (Trap t = (Trap)super.get(key, 1); t != null; t = t.next()) + + boolean isProperties = SC_Properties.equals(key); + Trap t0 = isProperties?propertiesTrap:(Trap)super.get(key, 1); + for (Trap t=t0; t != null; t = t.next()) if (t.function().equals(f)) return; - super.put(key, new TrapHolder(this, key, f, (Trap)super.get(key, 1)), 1); + Trap newtrap = new TrapHolder(this, key, f, t0); + if (isProperties) propertiesTrap = newtrap; + else super.put(key, newtrap, 1); } public void delTrap(JS key, JS f) throws JSExn { - Trap t = (Trap)super.get(key, 1); + boolean isProperties = SC_Properties.equals(key); + Trap t = isProperties?propertiesTrap:(Trap)super.get(key, 1); + if (t==null) return; - if (t.function().equals(f)) { super.put(key, t.next(), 1); return; } + if (t.function().equals(f)) { + if(isProperties) propertiesTrap = t.next(); + else super.put(key, t.next(), 1); + return; + } for (; t.next() != null; t = t.next()) if (t.next().function().equals(f)) { ((TrapHolder)t).next = t.next().next(); return; } } @@ -342,6 +347,54 @@ } } + public static class Proxy extends Obj { + public JS get(JS key) throws JSExn { + Trap rangeTrap = propertiesTrap==null?null:propertiesTrap.read(); + JSExn rangeTrapException = null; + JS value = null; + try { + if (rangeTrap != null) { + value = Thread.Faction.getCurrent().runBeforeGet(rangeTrap, key); + key = Thread.Faction.getCurrent().cascadedTo; + // if null value returned, avoiding innermost cascade + if (key == null) return value; + } + value = super.get(key); + } catch (JSExn e) { + rangeTrapException = e; + throw e; + } finally { + if (rangeTrap != null) { + // value in: cascaded back to the lowermost read trap + // value out: returned from the outer most read trap + value = Thread.Faction.getCurrent().runAfterGet(value, rangeTrapException); + } + } + return value; + } + + public void put(JS key, JS value) throws JSExn { + Trap rangeTrap = propertiesTrap==null?null:propertiesTrap.write(); + JSExn rangeTrapException = null; + try { + if (rangeTrap != null) { + value = Thread.Faction.getCurrent().runBeforePut(rangeTrap, value, key); + key = Thread.Faction.getCurrent().cascadedTo; + // returned from trap without cascading (cleaned up in finally clause) + if (key==null) return; + } + super.put(key, value); + } catch (JSExn e) { + rangeTrapException = e; + throw e; + } finally { + if (rangeTrap != null) { + Thread.Faction.getCurrent().runAfterPut(rangeTrapException); + } + } + } + } + public interface Trap { public JS key(); public JS target(); Modified: trunk/core/org.ibex.js/src/org/ibex/js/Thread.java =================================================================== --- trunk/core/org.ibex.js/src/org/ibex/js/Thread.java 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.ibex.js/src/org/ibex/js/Thread.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -144,12 +144,14 @@ } /** Execute read traps, part 2 */ - public JS runAfterGet(boolean wereExceptions, JS value) throws JSExn{ + public JS runAfterGet(JS value, JSExn exn) throws JSExn{ try{ - if(!wereExceptions && current.currentInterpreter.f!=null) - return (JS) current.currentInterpreter.run(value); - else - return value; + if(current.currentInterpreter.f!=null) + return (JS) current.currentInterpreter.run(exn!=null?(Object)exn:value); + else{ + if(exn!=null) throw exn; + return value; + } }finally{ if(current.currentInterpreter.old==null) current.destroy(); else current.currentInterpreter = current.currentInterpreter.old; Modified: trunk/core/org.ibex.js/src_dev/org/ibex/js/JSDynProxy.java =================================================================== --- trunk/core/org.ibex.js/src_dev/org/ibex/js/JSDynProxy.java 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.ibex.js/src_dev/org/ibex/js/JSDynProxy.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -18,8 +18,7 @@ public JS get(JS key) throws JSExn { Trap rangeTrap = rtrap(SC_); - boolean rangeTrapException = false; - + JSExn rangeTrapException = null; JS value = null; try { if (rangeTrap != null) { @@ -30,13 +29,13 @@ } value = super.get(key); } catch (JSExn e) { - rangeTrapException = true; + rangeTrapException = e; throw e; } finally { if (rangeTrap != null) { // value in: cascaded back to the lowermost read trap // value out: returned from the outer most read trap - value = Thread.Faction.getCurrent().runAfterGet(rangeTrapException, value); + value = Thread.Faction.getCurrent().runAfterGet(value,rangeTrapException); } } return value; Modified: trunk/core/org.ibex.js/src_dev/org/ibex/js/RunJS.java =================================================================== --- trunk/core/org.ibex.js/src_dev/org/ibex/js/RunJS.java 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.ibex.js/src_dev/org/ibex/js/RunJS.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -281,7 +281,7 @@ if("firethis".equals(key)) return METHOD; if("line".equals(key)) return METHOD; if("import".equals(key)) return METHOD; - if("proxy".equals(key)) return new JSDynProxy(); + if("proxy".equals(key)) return new JS.Proxy(); // INCONSISTENT with vexi obj (tobe changed) Modified: trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/TestRangeTraps.java =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/TestRangeTraps.java 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/TestRangeTraps.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -15,7 +15,7 @@ public static void main(String[] args) throws Throwable { JSTestSuite jts = new JSTestSuite(TestRangeTraps.class); - TestCase t = jts.createTestCase(jts.getResourceDirs(), "writeProxy.js"); + TestCase t = jts.createTestCase(jts.getResourceDirs(), "readProxy.js"); t.runBare(); } } Modified: trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/readProxy.js =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/readProxy.js 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/readProxy.js 2008-11-03 11:22:14 UTC (rev 3166) @@ -3,7 +3,7 @@ var proxy = sys.proxy; proxy.a = 1; proxy.b = 2; -proxy[""] ++= function(){ +proxy.Properties ++= function(){ sys.log.info(trapname); var tn = trapname; if(tn=="a") trapname = "b"; Modified: trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/writeProxy.js =================================================================== --- trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/writeProxy.js 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.ibex.js/src_junit/test/js/exec/traps/range/writeProxy.js 2008-11-03 11:22:14 UTC (rev 3166) @@ -1,7 +1,7 @@ sys.import("shared"); var proxy = sys.proxy; -proxy[""] ++= function(v){ +proxy.Properties ++= function(v){ sys.log.info(trapname); var tn = trapname; if(tn=="a") trapname = "b"; Modified: trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -146,14 +146,14 @@ public JS call(JS method, JS[] args) throws JSExn { if (method != null) return super.call(method, args); - if ((args.length < 1 || !(args[0] instanceof Box)) + if ((args.length < 1 || !(args[0] instanceof JS)) || (args.length == 2 && !(args[1] instanceof JSArray)) || args.length > 2 ) - throw new JSExn("illegal attempt to apply a template; use 'template(box [, array])'"); + throw new JSExn("illegal attempt to apply a template; use 'template(obj [, array])'"); // Ensure template is created by creating the static part. getStatic(); if (t == null) throw new JSExn("no such template " + description()); - t.apply((Box)args[0],args.length==2?((JSArrayLike)args[1]).toArray():null); + t.apply(args[0],args.length==2?((JSArrayLike)args[1]).toArray():null); return args[0]; } Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2008-11-03 11:22:14 UTC (rev 3166) @@ -1690,7 +1690,7 @@ // children private final JS get(int i) throws JSExn { Trap rangeTrap = rtrap(SC_Children); - boolean rangeTrapException = false; + JSExn rangeTrapException = null; JS value = null; try { @@ -1707,13 +1707,13 @@ } else value = getChild(i); } catch (JSExn e) { - rangeTrapException = true; + rangeTrapException = e; throw e; } finally { if (rangeTrap != null) { // value in: cascaded back to the lowermost read trap // value out: returned from the outer most read trap - value = Main.SCHEDULER.runAfterGet(rangeTrapException, value); + value = Main.SCHEDULER.runAfterGet(value, rangeTrapException); } } return value; Modified: trunk/core/org.vexi.core/src/org/vexi/core/Constants.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Constants.java 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.vexi.core/src/org/vexi/core/Constants.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -47,6 +47,7 @@ static final JS SC_shrink = JSU.S("shrink",true); static final JS SC_stringify = JSU.S("stringify",true); static final JS SC_surface = JSU.S("surface",true); + static final JS SC_thisobj = JSU.S("thisobj",true); static final JS SC_titlebar = JSU.S("titlebar",true); static final JS SC_vertical = JSU.S("vertical",true); static final JS SC_visible = JSU.S("visible",true); Modified: trunk/core/org.vexi.core/src/org/vexi/core/Template.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Template.java 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.vexi.core/src/org/vexi/core/Template.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -89,6 +89,15 @@ Template preapply = null; /// Preapplied template (~linked list) in root node only Template principal = null; /// Template to be applied + // HACK - js:obj template hackily implemented. + // also we should consider making use of the this keyword instead of thisobj + Boolean isobj = null; + boolean isObj(){ + if(isobj==null) { + return principal.isObj(); + } + return isobj.booleanValue(); + } ////// // Static part - outer most templates have a static part @@ -144,12 +153,12 @@ */ // @param pboxes a vector of all box parents on which to put $-references // @param ptemplates a vector of the fileNames to recieve private references on the pboxes - public void apply(Box b, JS[] js) throws JSExn { + public void apply(JS b, JS[] js) throws JSExn { apply(b, js, null); } - private static Template preapply(Box b, JS[] args, Template t) throws JSExn{ + private static Template preapply(JS b, JS[] args, Template t) throws JSExn{ if (t != null){ // make sure we have resolved (if were top level) if(t.staticPart!=null && t.staticPart.staticObject==null){ @@ -160,7 +169,7 @@ return t; } - private void apply(Box b, JS[] args, PerInstantiationScope parentPis) throws JSExn { + private void apply(JS b, JS[] args, PerInstantiationScope parentPis) throws JSExn { Main.SCHEDULER.getCurrentInterpreter().enterNonJSCall( this); try{ // REMARK - the preapplies may not have been resolved yet, @@ -179,7 +188,9 @@ if(parentPis!=null) staticPart = parentPis.getStaticPart(); // FEATURE only if necessary (i.e. if there is JS code) PerInstantiationScope pis = new PerInstantiationScope(b, parentPis); - + if(isObj()) pis.put(SC_thisobj, b); + else if(!(b instanceof Box)) throw new JSExn("Tried to apply a ui:box template to a non-box"); + // FIXME needs to obey the new application-ordering rules for (int i=0; children != null && i<children.size(); i++) { Box kid = new Box(); @@ -307,7 +318,7 @@ class PerInstantiationScope extends JS.Obj { PerInstantiationScope parentBoxPis = null; JS box; - void putDollar(String key, Box target) throws JSExn { + void putDollar(String key, JS target) throws JSExn { if (parentBoxPis != null) parentBoxPis.putDollar(key, target); JS jskey = JSU.S("$" + key); sput(jskey, target); Modified: trunk/core/org.vexi.core/src/org/vexi/core/TemplateBuilder.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/TemplateBuilder.java 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.vexi.core/src/org/vexi/core/TemplateBuilder.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -199,12 +199,13 @@ // // FIXME: This is all wrong // Hopefully less wrong now. - if (!(isUiUri && "box".equals(c.getLocalName()))) { + if (!(isUiUri && ("box".equals(c.getLocalName())) || "object".equals(c.getLocalName()))) { String tagname = (c.getUri() == null || "".equals(c.getUri()) ? "" : (c.getUri() + ".")) + c.getLocalName(); t.principal = new Template(t.vexi, tagname); + }else{ + t.isobj = Boolean.valueOf("object".equals(c.getLocalName())); } - // FIXME: 2-value Array Modified: trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp 2008-11-03 10:55:46 UTC (rev 3165) +++ trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp 2008-11-03 11:22:14 UTC (rev 3166) @@ -100,6 +100,7 @@ case "file.tempdir": return VexiJS.fountainForURL("file:" + System.getProperty("java.io.tempdir")); case "js": return getSub(name); case "js.eval": return METHOD; + case "js.proxy": return new JS.Proxy(); case "js.stringify": return METHOD; case "log": return getSub(name); case "log.debug": return METHOD; Added: trunk/core/org.vexi.core/src_junit/test/core/jsobj/TestJSObj.java =================================================================== --- trunk/core/org.vexi.core/src_junit/test/core/jsobj/TestJSObj.java (rev 0) +++ trunk/core/org.vexi.core/src_junit/test/core/jsobj/TestJSObj.java 2008-11-03 11:22:14 UTC (rev 3166) @@ -0,0 +1,43 @@ +package test.core.jsobj; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import test.core.CoreTestSuite; + +/** + * @author mike + */ +public class TestJSObj extends CoreTestSuite{ + + public TestJSObj(Class klass) { + super(klass); + } + + public TestJSObj() { + this(TestJSObj.class); + } + + public String[] getResourceDirs() { + String[] a = super.getResourceDirs(); + String[] b = new String[]{TestJSObj.class.getResource(".").getPath()}; + return append(a,b); + } + + static public Test suite() { + // FEATURE - discover test suites dynamically +// new TestSuite(JSTestSuite.nameFromClass(TestCore.class)); + TestSuite suite = (TestSuite) CoreTestSuite.suite(new TestJSObj()); + return suite; + } + + + + public static void main(String[] args) throws Throwable { + + CoreTestSuite cts = new CoreTestSuite(TestJSObj.class); + TestCase t = cts.createTestCase(cts.getResourceDirs(), "simple.t"); + t.runBare(); + } + +} Property changes on: trunk/core/org.vexi.core/src_junit/test/core/jsobj/TestJSObj.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/core/org.vexi.core/src_junit/test/core/jsobj/_jstemplate.t =================================================================== --- trunk/core/org.vexi.core/src_junit/test/core/jsobj/_jstemplate.t (rev 0) +++ trunk/core/org.vexi.core/src_junit/test/core/jsobj/_jstemplate.t 2008-11-03 11:22:14 UTC (rev 3166) @@ -0,0 +1,7 @@ +<vexi xmlns:js="vexi://js" xmlns=""> + + <js:object y="2"> + thisobj.x = 5; + + </js:object> +</vexi> Added: trunk/core/org.vexi.core/src_junit/test/core/jsobj/simple.t =================================================================== --- trunk/core/org.vexi.core/src_junit/test/core/jsobj/simple.t (rev 0) +++ trunk/core/org.vexi.core/src_junit/test/core/jsobj/simple.t 2008-11-03 11:22:14 UTC (rev 3166) @@ -0,0 +1,9 @@ + +<vexi xmlns:ui="vexi://ui" xmlns="" xmlns:lib="_lib"> + + var obj = ._jstemplate({}); + .util..assertEquals("2",obj.y); + .util..assertEquals(5,obj.x); + + <ui:box/> +</vexi> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn