X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FTrap.java;h=041e012d8837e03f0f626dca9d1b33198d919f5b;hb=4e8351f507d2e421dab06896b72a58f1a4033094;hp=a0ed711cb1d0ef56be3902158f439bc86dfda6c5;hpb=3d545db9c5a99535462adc62cbf9fc88d3dd619b;p=org.ibex.core.git diff --git a/src/org/xwt/js/Trap.java b/src/org/xwt/js/Trap.java index a0ed711..041e012 100644 --- a/src/org/xwt/js/Trap.java +++ b/src/org/xwt/js/Trap.java @@ -1,4 +1,4 @@ -// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] package org.xwt.js; import java.util.*; @@ -19,31 +19,33 @@ class Trap { JSFunction f = null; ///< the function for this trap Trap next = null; ///< the next trap down the trap stack - Trap(JS b, String n, JSFunction f, Trap nx) { trapee = b; name = n; this.f = f; this.next = nx; } + Trap(JS b, String n, JSFunction f, Trap nx) { + trapee = b; name = n; this.f = f; this.next = nx; + } private static final JSFunction putInvoker = new JSFunction("putInvoker", 0, null); private static final JSFunction getInvoker = new JSFunction("getInvoker", 0, null); + static { - putInvoker.add(-1, ByteCodes.PUT, null); - putInvoker.add(-1, Tokens.RETURN, null); - getInvoker.add(-1, ByteCodes.GET, null); - putInvoker.add(-1, Tokens.RETURN, null); + putInvoker.add(1, ByteCodes.PUT, null); + putInvoker.add(2, Tokens.RETURN, null); + getInvoker.add(1, ByteCodes.GET, null); + getInvoker.add(2, Tokens.RETURN, null); } - void invoke(Object key, Object value) { + void invoke(Object value) throws JSExn { Interpreter i = new Interpreter(putInvoker, false, null); i.stack.push(trapee); - i.stack.push(key); + i.stack.push(name); i.stack.push(value); i.resume(); } - Object invoke(Object key) { + Object invoke() throws JSExn { Interpreter i = new Interpreter(getInvoker, false, null); - i.stack.push(this); - i.stack.push(key); - i.resume(); - return i.stack.pop(); + i.stack.push(trapee); + i.stack.push(name); + return i.resume(); } // FIXME: review; is necessary? @@ -52,8 +54,9 @@ class Trap { Object val = null; boolean cascadeHappened = false; public TrapScope(JSScope parent, Trap t, Object val) { super(parent); this.t = t; this.val = val; } - public Object get(Object key) { + public Object get(Object key) throws JSExn { if (key.equals("trapee")) return t.trapee; + if (key.equals("callee")) return t.f; if (key.equals("trapname")) return t.name; return super.get(key); }