2003/06/12 17:57:37
[org.ibex.core.git] / src / org / xwt / js / Context.java
index 4fc5eaa..ee00fc8 100644 (file)
@@ -3,18 +3,38 @@ package org.xwt.js;
 
 import org.xwt.util.*;
 import java.io.*;
+import java.util.*;
 
 /** encapsulates a single JavaScript thread and its state */
 public class Context {
 
-    private static Hash javaThreadToContextMap = new Hash();
+    private static Hashtable javaThreadToContextMap = new Hashtable();
+    static Hashtable currentFunction = new Hashtable();
 
     public Vec stack = new Vec();
 
-    /** at any point in time, one JS Context can be bound to each Java thread; this determines which context any call()s execute in */
+    /**
+     *  at any point in time, one JS Context can be bound to each Java thread;
+     *  this determines which context any call()s execute in
+     */
     public void bindToCurrentThread() { javaThreadToContextMap.put(Thread.currentThread(), this); }
-    public static Context getContextForCurrentThread() {
-       Context ret = (Context)javaThreadToContextMap.get(Thread.currentThread());
+
+    /** returns the current file and line number; intended for displaying to the user */
+    public static String getCurrentSourceNameAndLine() {
+       return getContextForThread(Thread.currentThread()).getCurrentFunction().getSourceName() + ":??";
+    }
+
+    public static String getSourceNameAndLineForThread(Thread t) {
+       CompiledFunction cf = getContextForThread(t).getCurrentFunction();
+       if (cf == null) return "null";
+       return cf.getSourceName() + ":??";
+    }
+
+    /** fetches the currently-executing javascript function */
+    public CompiledFunction getCurrentFunction() { return (CompiledFunction)currentFunction.get(Thread.currentThread()); }
+
+    public static Context getContextForThread(Thread t) {
+       Context ret = (Context)javaThreadToContextMap.get(t);
        if (ret == null) {
            ret = new Context();
            ret.bindToCurrentThread();
@@ -22,7 +42,15 @@ public class Context {
        return ret;
     }
 
+    public static class TryMarker { public int location; public TryMarker(int location) { this.location = location; } }
     public static class CallMarker { public CallMarker() { } }
-    public static class LoopMarker { public int location; public LoopMarker(int location) { this.location = location; } }
+    public static class LoopMarker {
+       public int location;
+       public String label;
+       public LoopMarker(int location, String label) {
+           this.location = location;
+           this.label = label;
+       }
+    }
 
 }