X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTrap.java;h=bb32ee42501711f414c1e2f8215d35d3762a87d4;hb=1a8dcf7794ae435c5c2811b8d7c2b75832047595;hp=d2b39541179a4bb509272828cd2dec64af0c4bf0;hpb=6242c991f365dbd67eba62ecfa5df769a83fcbc6;p=org.ibex.core.git
diff --git a/src/org/xwt/Trap.java b/src/org/xwt/Trap.java
index d2b3954..bb32ee4 100644
--- a/src/org/xwt/Trap.java
+++ b/src/org/xwt/Trap.java
@@ -1,9 +1,9 @@
// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt;
-import org.xwt.util.*;
import java.util.*;
-import org.mozilla.javascript.*;
+import org.xwt.js.*;
+import org.xwt.util.*;
/**
* This class encapsulates a single trap placed on a given node. The
@@ -15,8 +15,24 @@ 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 Vec allTraps = new Vec(1000);
+ private static Hashtable allTraps = new Hashtable(1000);
/** List of properties that cannot be trapped */
private static final Hash PROHIBITED = new Hash(120, 3);
@@ -32,16 +48,19 @@ public class Trap {
for(int i=0; i
b. Used for retheming */
- public static void removeAllTrapsByBox(Box b) {
- for(int i=0; i 0 && !isreadtrap && !tc.putCascadeHappened) cascadeFunction.call(null, null, null, arg);
+ if (args.length() > 0 && !isreadtrap && !tc.putCascadeHappened) cascadeFunction.call(args);
return ret;
- } catch (EcmaError e) {
- if (Log.on) Log.log(this, "WARNING: uncaught interpreter exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown from within trap '" + name + "' at " + e.getSourceName() + ":" + e.getLineNumber());
- } catch (JavaScriptException e) {
- if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage());
- if (Log.on) Log.log(this, " thrown from within trap '" + name + "' at " + e.sourceFile + ":" + e.line);
+ } catch (JS.Exn e) {
+ if (Log.on) Log.log(this, e);
+
} finally {
// restore the thread-locals
tc.putCascadeHappened = save_putCascadeHappened;
@@ -220,11 +205,7 @@ public class Trap {
}
if (trapee.surface != null && !trapee.is_trapped("KeyPressed") && !trapee.is_trapped("KeyReleased"))
trapee.surface.keywatchers.removeElement(trapee);
- if (allTraps.size() == 1) allTraps.setSize(0);
- else {
- allTraps.setElementAt(allTraps.elementAt(allTraps.size() - 1), indexInAllTraps);
- allTraps.setSize(allTraps.size() - 1);
- }
+ allTraps.remove(myWeak);
}
/** per-thread storage for Traps */
@@ -239,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);
@@ -250,3 +231,4 @@ public class Trap {
}
}
+