import java.io.*;
import java.util.*;
-/** encapsulates a single JavaScript thread and its state */
-public class Context {
-
- 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
- */
- public void bindToCurrentThread() { javaThreadToContextMap.put(Thread.currentThread(), this); }
-
- /** 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) {
- JS.CompiledFunction cf = getContextForThread(t).getCurrentFunction();
- if (cf == null) return "null";
- return cf.getSourceName() + ":??";
- }
-
- /** fetches the currently-executing javascript function */
- public JS.CompiledFunction getCurrentFunction() { return (JS.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();
- }
- return ret;
- }
-
- public static class CallMarker { public CallMarker() { } }
- public static class LoopMarker {
- public int location;
- public String label;
- public LoopMarker(int location, String label) {
- this.location = location;
- this.label = label;
- }
- }
- public static class TryMarker {
- public int location;
- public JS.Scope scope;
- public TryMarker(int location, JS.Scope scope) {
- this.location = location;
- this.scope = scope;
- }
- }
-
-}