private Trap() { }
- public Object perform() throws JS.Exn {
- if (f.getNumFormalArgs() > 0) return cascade();
- return f.call(new TrapArgs(this));
+ public Object perform() {
+ try {
+ if (f.getNumFormalArgs() > 0) return cascade();
+ JS.Thread.current().setTailCall(f, new TrapArgs(this));
+ return null;
+ } catch (Exception e) {
+ Log.log(this, "Exception thrown from within trap: " + e);
+ return null;
+ }
}
- public void perform(Object val) throws JS.Exn {
- if (f.getNumFormalArgs() == 0) cascade(val);
- TrapArgs ta = new TrapArgs(this, val);
- Object ret = f.call(ta);
- if (ret != Boolean.FALSE && !ta.cascadeHappened) cascade(val);
+ public void perform(Object val) {
+ try {
+ if (f.getNumFormalArgs() == 0) cascade(val);
+ TrapArgs ta = new TrapArgs(this, val);
+ JS.Thread.current().setTailCall(f, ta);
+ // FIXME: re-add autocascades
+ //if (ret != Boolean.FALSE && !ta.cascadeHappened) cascade(val);
+ } catch (Exception e) {
+ Log.log(this, "Exception thrown from within trap: " + e);
+ }
}
public Object cascade() {
- if (next != null) return next.perform();
+ if (next != null) { next.perform(); return null; }
return trapee.get(name, true);
}
if (key.equals("trapee")) return t.trapee;
if (key.equals("trapname")) return t.name;
if (key.equals("cascade")) return t.cascade();
+ if (key.equals("callee")) return t.f;
return super.get(key);
}
}