X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSFunction.java;h=020cb1137b4461cafd72ca274bb561592aafd41a;hb=ce791e4058158295bce9cf7b6698c2b565d571d7;hp=6c0e89a2b763a4fca87537170e0a9bb3dedd9cc0;hpb=3591b88b94a6bb378af3d4abe6eb5233ce583104;p=org.ibex.core.git diff --git a/src/org/ibex/js/JSFunction.java b/src/org/ibex/js/JSFunction.java index 6c0e89a..020cb11 100644 --- a/src/org/ibex/js/JSFunction.java +++ b/src/org/ibex/js/JSFunction.java @@ -2,9 +2,10 @@ package org.ibex.js; import java.io.*; +import org.ibex.util.*; /** A JavaScript function, compiled into bytecode */ -class JSFunction extends JS implements ByteCodes, Tokens, org.ibex.Scheduler.Task { +class JSFunction extends JS implements ByteCodes, Tokens, Task { // Fields and Accessors /////////////////////////////////////////////// @@ -28,7 +29,6 @@ class JSFunction extends JS implements ByteCodes, Tokens, org.ibex.Scheduler.Tas /** if you enqueue a function, it gets invoked in its own pauseable context */ public void perform() throws JSExn { Interpreter i = new Interpreter(this, true, new JSArray()); - int oldpausecount = i.pausecount; i.resume(); } @@ -60,7 +60,7 @@ class JSFunction extends JS implements ByteCodes, Tokens, org.ibex.Scheduler.Tas } /** Note: code gets run in an unpauseable context. */ - public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { + public JS call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn { JSArray args = new JSArray(); if (nargs > 0) args.addElement(a0); if (nargs > 1) args.addElement(a1); @@ -103,24 +103,28 @@ class JSFunction extends JS implements ByteCodes, Tokens, org.ibex.Scheduler.Tas // Debugging ////////////////////////////////////////////////////////////////////// - public String toString() { return "JSFunction [" + sourceName + ":" + firstLine + "]"; } + // FIXME: Put this back in + public String xtoString() { return "JSFunction [" + sourceName + ":" + firstLine + "]"; } - public String dump() { + String dump() { return dump(""); } + private String dump(String prefix) { StringBuffer sb = new StringBuffer(1024); sb.append("\n" + sourceName + ": " + firstLine + "\n"); for (int i=0; i < size; i++) { - sb.append(i); - sb.append(": "); + sb.append(prefix); + sb.append(i).append(" (").append(line[i]).append(") :"); if (op[i] < 0) sb.append(bytecodeToString[-op[i]]); else sb.append(codeToString[op[i]]); sb.append(" "); - sb.append(arg[i] == null ? "(no arg)" : arg[i]); + sb.append(arg[i] == null ? "(no arg)" : arg[i] instanceof JS ? JS.debugToString((JS)arg[i]) : arg[i]); if((op[i] == JF || op[i] == JT || op[i] == JMP) && arg[i] != null && arg[i] instanceof Number) { sb.append(" jump to ").append(i+((Number) arg[i]).intValue()); } else if(op[i] == TRY) { int[] jmps = (int[]) arg[i]; sb.append(" catch: ").append(jmps[0] < 0 ? "No catch block" : ""+(i+jmps[0])); sb.append(" finally: ").append(jmps[1] < 0 ? "No finally block" : ""+(i+jmps[1])); + } else if(op[i] == NEWFUNCTION) { + sb.append(((JSFunction) arg[i]).dump(prefix + " ")); } sb.append("\n"); }