fixed bugs 495 and 499
[org.ibex.core.git] / src / org / ibex / js / Interpreter.java
index 1b679ca..92b29a4 100644 (file)
@@ -93,7 +93,9 @@ class Interpreter implements ByteCodes, Tokens {
             case DUP: stack.push(stack.peek()); break;
             case NEWSCOPE: scope = new JSScope(scope); break;
             case OLDSCOPE: scope = scope.getParentScope(); break;
-            case ASSERT: if (!JS.toBoolean(stack.pop())) throw je("ibex.assertion.failed" /*FEATURE: line number*/); break;
+            case ASSERT:
+                if (JS.checkAssertions && !JS.toBoolean(stack.pop()))
+                    throw je("ibex.assertion.failed" /*FEATURE: line number*/); break;
             case BITNOT: stack.push(JS.N(~JS.toLong(stack.pop()))); break;
             case BANG: stack.push(JS.B(!JS.toBoolean(stack.pop()))); break;
             case NEWFUNCTION: stack.push(((JSFunction)arg)._cloneWithNewParentScope(scope)); break;
@@ -243,6 +245,11 @@ class Interpreter implements ByteCodes, Tokens {
                     }
                 }
                 if (t != null) {
+                    stack.pop();
+                    stack.push(new CallMarker(this));
+                    stack.push(target);
+                    JSArray args = new JSArray();
+                    args.addElement(val);
                     f = t.f;
                     scope = new Trap.TrapScope(f.parentScope, t, val);
                     pc = -1;
@@ -287,15 +294,12 @@ class Interpreter implements ByteCodes, Tokens {
                         } else {
                             t = ((JS)o).getTrap(v);
                         }
-
                         while (t != null && t.f.numFormalArgs != 0) t = t.next; // get first read trap
-                        if (t != null) {
-                            stack.push(new CallMarker(this));
-                            JSArray args = new JSArray();
-                            stack.push(args);
-                        }
                     }
                     if (t != null) {
+                        stack.push(new CallMarker(this));
+                        JSArray args = new JSArray();
+                        stack.push(args);
                         f = t.f;
                         scope = new Trap.TrapScope(f.parentScope, t, null);
                         ((Trap.TrapScope)scope).cascadeHappened = true;
@@ -365,7 +369,7 @@ class Interpreter implements ByteCodes, Tokens {
 
             case THROW:
                 throw new JSExn(stack.pop());
-
+                /* FIXME
             case MAKE_GRAMMAR: {
                 final Grammar r = (Grammar)arg;
                 final JSScope final_scope = scope;
@@ -387,7 +391,7 @@ class Interpreter implements ByteCodes, Tokens {
                 stack.push(r2);
                 break;
             }
-
+                */
             case ADD_TRAP: case DEL_TRAP: {
                 Object val = stack.pop();
                 Object key = stack.pop();
@@ -555,7 +559,7 @@ class Interpreter implements ByteCodes, Tokens {
         public CallMarker(Interpreter cx) { pc = cx.pc + 1; scope = cx.scope; f = cx.f; }
     }
     
-    public static class CatchMarker { public CatchMarker() { } }
+    public static class CatchMarker { }
     private static CatchMarker catchMarker = new CatchMarker();
     
     public static class LoopMarker {