1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
8 /** encapsulates a single JavaScript thread and its state */
11 private static Hashtable javaThreadToContextMap = new Hashtable();
12 static Hashtable currentFunction = new Hashtable();
14 public Vec stack = new Vec();
17 * at any point in time, one JS Context can be bound to each Java thread;
18 * this determines which context any call()s execute in
20 public void bindToCurrentThread() { javaThreadToContextMap.put(Thread.currentThread(), this); }
22 /** returns the current file and line number; intended for displaying to the user */
23 public static String getCurrentSourceNameAndLine() {
24 return getContextForThread(Thread.currentThread()).getCurrentFunction().getSourceName() + ":??";
27 public static String getSourceNameAndLineForThread(Thread t) {
28 CompiledFunction cf = getContextForThread(t).getCurrentFunction();
29 if (cf == null) return "null";
30 return cf.getSourceName() + ":??";
33 /** fetches the currently-executing javascript function */
34 public CompiledFunction getCurrentFunction() { return (CompiledFunction)currentFunction.get(Thread.currentThread()); }
36 public static Context getContextForThread(Thread t) {
37 Context ret = (Context)javaThreadToContextMap.get(t);
40 ret.bindToCurrentThread();
45 public static class CallMarker { public CallMarker() { } }
46 public static class LoopMarker {
49 public LoopMarker(int location, String label) {
50 this.location = location;
54 public static class TryMarker {
56 public JS.Scope scope;
57 public TryMarker(int location, JS.Scope scope) {
58 this.location = location;