jsexn on stack overflow
authorbrian <brian@brianweb.net>
Wed, 2 Jun 2004 02:46:25 +0000 (02:46 +0000)
committerbrian <brian@brianweb.net>
Wed, 2 Jun 2004 02:46:25 +0000 (02:46 +0000)
darcs-hash:20040602024625-24bed-6d8a0fc5f8024e45a7d1896dce6f59be35844c8a.gz

src/org/ibex/js/Interpreter.java

index e89f752..6fc2859 100644 (file)
@@ -6,7 +6,7 @@ import java.util.*;
 
 /** Encapsulates a single JS interpreter (ie call stack) */
 class Interpreter implements ByteCodes, Tokens {
-
+    private static final int MAX_STACK_SIZE = 512;
 
     // Thread-Interpreter Mapping /////////////////////////////////////////////////////////////////////////
 
@@ -236,9 +236,6 @@ class Interpreter implements ByteCodes, Tokens {
                     while (t != null && t.f.numFormalArgs == 0) t = t.next;
                     if (t == null) { target = ts.t.trapee; key = ts.t.name; }
 
-                } else if (target instanceof Trap.TrapScope && key.equals(((Trap.TrapScope)target).t.name)) {
-                    throw je("tried to put to " + key + " inside a trap it owns; use cascade instead"); 
-
                 } else if (target instanceof JS) {
                     if (target instanceof JSScope) {
                         JSScope p = (JSScope)target; // search the scope-path for the trap
@@ -251,6 +248,7 @@ class Interpreter implements ByteCodes, Tokens {
                 }
                 if (t != null) {
                     stack.push(new CallMarker(this));
+                    if(stack.size() > MAX_STACK_SIZE) throw new JSExn("stack overflow");
                     JSArray args = new JSArray();
                     args.addElement(val);
                     stack.push(args);
@@ -302,6 +300,7 @@ class Interpreter implements ByteCodes, Tokens {
                     }
                     if (t != null) {
                         stack.push(new CallMarker(this));
+                        if(stack.size() > MAX_STACK_SIZE) throw new JSExn("stack overflow");
                         JSArray args = new JSArray();
                         stack.push(args);
                         f = t.f;
@@ -352,6 +351,7 @@ class Interpreter implements ByteCodes, Tokens {
                     JSArray arguments = new JSArray();
                     for(int i=0; i<numArgs; i++) arguments.addElement(i==0?a0:i==1?a1:i==2?a2:rest[i-3]);
                     stack.push(new CallMarker(this));
+                    if(stack.size() > MAX_STACK_SIZE) throw new JSExn("stack overflow");
                     stack.push(arguments);
                     f = (JSFunction)object;
                     scope = new JSScope(f.parentScope);