2003/06/18 07:04:38
[org.ibex.core.git] / src / org / xwt / js / CompiledFunctionImpl.java
index 416cd94..e111040 100644 (file)
@@ -6,7 +6,7 @@ import java.io.*;
 
 // FIXME: could use some cleaning up
 /** a JavaScript function, compiled into bytecode */
-class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
+class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens {
 
     // Fields and Accessors ///////////////////////////////////////////////
 
@@ -17,6 +17,9 @@ class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
     /** the line numbers */
     private int[] line = new int[10];
 
+    /** the first line of this script */
+    private int firstLine = -1;
+
     /** the instructions */
     private int[] op = new int[10];
 
@@ -45,16 +48,12 @@ class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
         this.parentScope = parentScope;
         if (sourceCode == null) return;
         Parser p = new Parser(sourceCode, sourceName, firstLine);
-        try {
-            while(true) {
-                int s = size();
-                p.parseStatement(this, null);
-                if (s == size()) break;
-            }
-            add(-1, Tokens.RETURN);
-        } catch (Exception e) {
-            if (Log.on) Log.log(Parser.class, e);
+        while(true) {
+            int s = size();
+            p.parseStatement(this, null);
+            if (s == size()) break;
         }
+        add(-1, Tokens.RETURN);
     }
     
     public Object call(JS.Array args) throws JS.Exn { return call(args, new FunctionScope(sourceName, parentScope)); }
@@ -105,7 +104,7 @@ class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
         final Vec t = cx.stack;
         OUTER: for(pc=0; pc<size; pc++) {
             String label = null;
-            cx.line = line[op];
+            cx.line = line[pc];
             switch(op[pc]) {
             case LITERAL: t.push(arg[pc]); break;
             case OBJECT: t.push(new JS.Obj()); break;
@@ -348,14 +347,14 @@ class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
 
     // Helpers for Number, String, and Boolean ////////////////////////////////////////
 
-    private Object getFromString(final String o, final Object v) {
+    private static Object getFromString(final String o, final Object v) {
         if (v.equals("length")) return new Integer(((String)o).length());
         else if (v.equals("substring")) return new JS.Callable() {
                 public Object call(JS.Array args) {
                     if (args.length() == 1) return ((String)o).substring(JS.toNumber(args.elementAt(0)).intValue());
                     else if (args.length() == 2) return ((String)o).substring(JS.toNumber(args.elementAt(0)).intValue(),
                                                                               JS.toNumber(args.elementAt(1)).intValue());
-                    else throw je("String.substring() can only take one or two arguments");
+                    else throw new JS.Exn("String.substring() can only take one or two arguments");
                 }
             };
         else if (v.equals("toLowerCase")) return new JS.Callable() {
@@ -380,7 +379,7 @@ class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
                     if (args.length() != 1) return null;
                     return new Integer(((String)o).indexOf(args.elementAt(0).toString()));
                 } };
-        throw je("Not Implemented: propery " + v + " on String objects");
+        throw new JS.Exn("Not Implemented: propery " + v + " on String objects");
     }
 
 
@@ -426,3 +425,6 @@ class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
     }
 
 }
+
+class JSCallable extends JS.Callable {
+}