X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTrap.java;h=bb32ee42501711f414c1e2f8215d35d3762a87d4;hb=1a8dcf7794ae435c5c2811b8d7c2b75832047595;hp=770ad51b35d1d6d032d3034db72fd11138d744ad;hpb=f2eb7d5128e23542ce51973714eeb41ca1d37a6d;p=org.ibex.core.git diff --git a/src/org/xwt/Trap.java b/src/org/xwt/Trap.java index 770ad51..bb32ee4 100644 --- a/src/org/xwt/Trap.java +++ b/src/org/xwt/Trap.java @@ -15,6 +15,22 @@ public class Trap { // Static Data ////////////////////////////////////////////////////////////// + /** the arguments.cascade() function */ + public static final JS.Callable cascadeFunction = new JS.Callable() { + public Object call(JS.Array args) { + Trap currentTrap = TrapContext.get().currentTrap; + if (args.length() != 0) TrapContext.get().putCascadeHappened = true; + Trap t = currentTrap.next; + // if we've hit the end of the trap stack, just do a put(,,,true) + if (t == null) { + if (args.length() == 0) return currentTrap.trapee.get(currentTrap.name, true); + currentTrap.trapee.put(currentTrap.name, args.elementAt(0), true); + return null; + } + return t.perform(args); + } + }; + /** a vector of weak references to all instances of Trap; used for retheming */ private static Hashtable allTraps = new Hashtable(1000); @@ -44,7 +60,7 @@ public class Trap { private JS rp = null; /** the function for this trap */ - JS.Function f = null; + JS.CompiledFunction f = null; /** the name of the property that this trap was placed on */ private String name = null; @@ -72,7 +88,7 @@ public class Trap { * @param isreadtrap true iff this is a read (double-underscore) trap * @param rp if this trap is being placed via a rootproxy, this is that proxy object. */ - static void addTrap(Box trapee, String name, JS.Function f, boolean isreadtrap, JS rp) { + static void addTrap(Box trapee, String name, JS.CompiledFunction f, boolean isreadtrap, JS rp) { if (PROHIBITED.get(name) != null || name.startsWith("xwt_")) { Log.log(Trap.class, "Error: you cannot place traps on special property \"" + name + "\""); @@ -80,7 +96,9 @@ public class Trap { } // find out what script is currently running - String placerNodeName = JS.getCurrentFunctionSourceName(); + JS.CompiledFunction placer = JS.Thread.fromJavaThread(java.lang.Thread.currentThread()).getCurrentCompiledFunction(); + if (placer == null) { Log.log(Trap.class, "placer is null"); return; } + String placerNodeName = placer.getSourceName(); // check if this script has already placed a trap on this property if (trapee.traps == null) trapee.traps = new Hash(10, 3); @@ -108,7 +126,7 @@ public class Trap { public static Trap getTrap(Box b, String name) { if (b.traps == null) return null; - String currentFunctionNodeName = JS.getCurrentFunctionSourceName(); + String currentFunctionNodeName = JS.Thread.fromJavaThread(java.lang.Thread.currentThread()).getCurrentCompiledFunction().getSourceName(); for(Trap cur = (Trap)b.traps.get(name); cur != null; cur = cur.next) if (cur.placerNodeName.equals(currentFunctionNodeName)) return cur; @@ -116,25 +134,6 @@ public class Trap { return null; } - /** Called by Rhino's arguments.cascade. Note: cx will be null if this was invoked from perform() rather than from a script. */ - public static final CascadeFunction cascadeFunction = new CascadeFunction(); - private static class CascadeFunction extends JS.Function { - CascadeFunction() { setSeal(true); } - public Object _call(JS.Array args) { return _call(args, JS.getCurrentFunction()); } - public Object _call(JS.Array args, Function currentFunction) { - Trap currentTrap = TrapContext.get().currentTrap; - if (args.length() != 0) TrapContext.get().putCascadeHappened = true; - Trap t = currentTrap.next; - // if we've hit the end of the trap stack, just do a put(,,,true) - if (t == null) { - if (args.length() == 0) return currentTrap.trapee.get(currentTrap.name, true); - currentTrap.trapee.put(currentTrap.name, args.elementAt(0), true); - return null; - } - return t.perform(args); - } - }; - /** called by Rhino's arguments.trapee hack */ public static Object currentTrapee() { Trap current = TrapContext.get().currentTrap; @@ -168,30 +167,24 @@ public class Trap { // invoke the trap function try { - if (!isreadtrap && args.length() == 0) return cascadeFunction._call(args, f); + if (!isreadtrap && args.length() == 0) return cascadeFunction.call(args); if (f == null) { if (Log.verbose) Log.log(this, "debug: reclaimed a dangling trap on property " + name); - Object ret = cascadeFunction._call(args, f); + Object ret = cascadeFunction.call(args); delete(); return ret; } - System.out.println("calling trap on " + name); - Object ret = null; - try { - ret = f._call(args); - } catch (org.xwt.js.ByteCodeBlock.ReturnException re) { - ret = re.retval; - } - + Object ret = f.call(args); + // autocascade if required - if (args.length() > 0 && !isreadtrap && !tc.putCascadeHappened) cascadeFunction._call(args, f); + if (args.length() > 0 && !isreadtrap && !tc.putCascadeHappened) cascadeFunction.call(args); return ret; } catch (JS.Exn e) { - if (Log.on) Log.log(this, e); + if (Log.on) Log.log(this, e); } finally { // restore the thread-locals @@ -227,7 +220,7 @@ public class Trap { /** returns the TrapContext for the current thread */ static TrapContext get() { - TrapContext ret = (TrapContext)trapContextByThread.get(Thread.currentThread()); + TrapContext ret = (TrapContext)trapContextByThread.get(java.lang.Thread.currentThread()); if (ret == null) { ret = new TrapContext(); trapContextByThread.put(Thread.currentThread(), ret);