2003/06/16 08:44:09
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:01:18 +0000 (07:01 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:01:18 +0000 (07:01 +0000)
darcs-hash:20040130070118-2ba56-5788bd32919f8c53c32493abb6d6cff195819664.gz

17 files changed:
src/org/xwt/Box.java
src/org/xwt/MessageQueue.java
src/org/xwt/SpecialBoxProperty.java
src/org/xwt/ThreadMessage.java
src/org/xwt/Trap.java
src/org/xwt/XMLRPC.java
src/org/xwt/XWT.java
src/org/xwt/js/ArrayImpl.java
src/org/xwt/js/CompiledFunctionImpl.java
src/org/xwt/js/Context.java
src/org/xwt/js/Date.java
src/org/xwt/js/JS.java
src/org/xwt/js/Lexer.java
src/org/xwt/js/Math.java
src/org/xwt/js/Regexp.java
src/org/xwt/js/ScopeImpl.java
src/org/xwt/util/Log.java

index d3d51a2..c50ff7b 100644 (file)
@@ -435,14 +435,14 @@ public final class Box extends JS.Scope {
             return null;
             
         } else {
-            Thread thread = Thread.currentThread();
+            java.lang.Thread thread = java.lang.Thread.currentThread();
             if (!(thread instanceof ThreadMessage)) {
                 if (Log.on) Log.log(Box.class, "HTTP images can not be loaded from the foreground thread");
                 return null;
             }
             // FIXME: use primitives here
             ThreadMessage mythread = (ThreadMessage)thread;
-            mythread.setPriority(Thread.MIN_PRIORITY);
+            mythread.setPriority(java.lang.Thread.MIN_PRIORITY);
             mythread.done.release();
             try {
                 HTTP http = new HTTP(str);
@@ -489,7 +489,7 @@ public final class Box extends JS.Scope {
 
             } finally {
                 MessageQueue.add(mythread);
-                mythread.setPriority(Thread.NORM_PRIORITY);
+                mythread.setPriority(java.lang.Thread.NORM_PRIORITY);
                 mythread.go.block();
             }
         }
@@ -518,7 +518,7 @@ public final class Box extends JS.Scope {
         } else {
             image = getPicture(s);
             if (image == null) {
-                if (Log.on) Log.log(Box.class, "unable to load image " + s + " at " + Context.getCurrentSourceNameAndLine());
+                if (Log.on) Log.logJS(Box.class, "unable to load image " + s);
                 return;
             }
             if (sizetoimage) syncSizeToImage();
@@ -539,7 +539,7 @@ public final class Box extends JS.Scope {
             if (border == null) {
                 ImageDecoder id = getImage(s, null);
                 if (id == null) {
-                    if (Log.on) Log.log(this, "unable to load border image " + s + " at " + Context.getCurrentSourceNameAndLine());
+                    if (Log.on) Log.logJS(this, "unable to load border image " + s);
                     return;
                 }
                 int[] data = id.getData();
@@ -740,8 +740,7 @@ public final class Box extends JS.Scope {
 
         if (++surface.sizePosChangesSinceLastRender >= 500) {
             if (surface.sizePosChangesSinceLastRender == 500) {
-                if (Log.on) Log.log(this, "Warning, more than 500 SizeChange/PosChange traps triggered since last complete render");
-                if (Log.on) Log.log(this, "    interpreter is at " + Context.getCurrentSourceNameAndLine());
+                if (Log.on) Log.logJS(this, "Warning, more than 500 SizeChange/PosChange traps triggered since last complete render");
             /*
                 try {
                     Trap t = sizechange ? Trap.getTrap(this, "SizeChange") : Trap.getTrap(this, "PosChange");
@@ -1075,10 +1074,9 @@ public final class Box extends JS.Scope {
         if (i < 0) return;
 
         if (value != null && !(value instanceof Box)) {
-            if (Log.on) Log.log(this, "attempt to set a numerical property on a box to anything other than a box at " + Context.getCurrentSourceNameAndLine());
-
+            if (Log.on) Log.logJS(this, "attempt to set a numerical property on a box to anything other than a box");
         } else if (redirect == null) {
-            if (Log.on) Log.log(this, "attempt to add/remove children to/from a node with a null redirect at " +  Context.getCurrentSourceNameAndLine());
+            if (Log.on) Log.logJS(this, "attempt to add/remove children to/from a node with a null redirect");
         } else if (redirect != this) {
             Box b = value == null ? (Box)redirect.get(i) : (Box)value;
             redirect.put(i, value);
@@ -1092,7 +1090,7 @@ public final class Box extends JS.Scope {
             }
 
         } else if (value instanceof RootProxy) {
-            if (Log.on) Log.log(this, "attempt to reparent a box via its proxy object at " + Context.getCurrentSourceNameAndLine());
+            if (Log.on) Log.logJS(this, "attempt to reparent a box via its proxy object");
 
         } else {
             Box newnode = (Box)value;
@@ -1100,16 +1098,14 @@ public final class Box extends JS.Scope {
             // check if box being moved is currently target of a redirect
             for(Box cur = newnode.getParent(); cur != null; cur = cur.getParent())
                 if (cur.redirect == newnode) {
-                    if (Log.on) Log.log(this, "attempt to move a box that is the target of a redirect at "+
-                                        Context.getCurrentSourceNameAndLine());
+                    if (Log.on) Log.logJS(this, "attempt to move a box that is the target of a redirect");
                     return;
                 }
 
             // check for recursive ancestor violation
             for(Box cur = this; cur != null; cur = cur.getParent())
                 if (cur == newnode) {
-                    if (Log.on) Log.log(this, "attempt to make a node a parent of its own ancestor at " +
-                                        Context.getCurrentSourceNameAndLine());
+                    if (Log.on) Log.logJS(this, "attempt to make a node a parent of its own ancestor");
                     if (Log.on) Log.log(this, "box == " + this + "  ancestor == " + newnode);
                     return;
                 }
@@ -1188,8 +1184,7 @@ public final class Box extends JS.Scope {
 
         Object ret = super.get(name);
         if (name.startsWith("$") && ret == null)
-            if (Log.on) Log.log(this, "WARNING: attempt to access " + name + ", but no child with id=\"" + name.substring(1) + "\" found; " +
-                                Context.getCurrentSourceNameAndLine());
+            if (Log.on) Log.logJS(this, "WARNING: attempt to access " + name + ", but no child with id=\"" + name.substring(1) + "\" found");
         return ret;
     }
 
@@ -1211,7 +1206,7 @@ public final class Box extends JS.Scope {
         String name = (String)name_;
         if (name == null) return;  // FIXME, shouldn't be necessary
         if (name.startsWith("xwt_")) {
-            if (Log.on) Log.log(this, "attempt to set reserved property " + name + " at " + Context.getCurrentSourceNameAndLine());
+            if (Log.on) Log.logJS(this, "attempt to set reserved property " + name);
             return;
         }
 
@@ -1237,11 +1232,9 @@ public final class Box extends JS.Scope {
 
         if (name.charAt(0) == '_') {
             if (value != null && !(value instanceof JS.Callable)) {
-                if (Log.on) Log.log(this, "attempt to put a non function value (" + value + ") to " +
-                                    name + " at " + Context.getCurrentSourceNameAndLine());
+                if (Log.on) Log.logJS(this, "attempt to put a non function value (" + value + ") to " + name);
             } else if (value != null && !(value instanceof JS.CompiledFunction)) {
-                if (Log.on) Log.log(this, "attempt to put a non-compiled function value (" + value + ") to " +
-                                    name + " at " + Context.getCurrentSourceNameAndLine());
+                if (Log.on) Log.logJS(this, "attempt to put a non-compiled function value (" + value + ") to " + name);
             } else if (name.charAt(1) == '_') {
                 name = name.substring(2).intern();
                 Trap t = Trap.getTrap(this, name);
index fbebad4..82934cf 100644 (file)
@@ -117,13 +117,13 @@ public class MessageQueue extends Thread {
                 if ((m != null && m == MessageQueue.currentlyPerforming) || MessageQueue.working) {
                     String what, where;
                     if (m != null && m instanceof ThreadMessage) {
-                        where = org.xwt.js.Context.getSourceNameAndLineForThread((ThreadMessage)m);
+                        where = org.xwt.js.JS.Thread.fromJavaThread((ThreadMessage)m).getSourceName();
                         what = "background thread";
                     } else if (m != null) {
-                        where = org.xwt.js.Context.getSourceNameAndLineForThread(MessageQueue.singleton);
+                        where = org.xwt.js.JS.Thread.fromJavaThread(MessageQueue.singleton).getSourceName();
                         what = "event trap";
                     } else {
-                        where = org.xwt.js.Context.getSourceNameAndLineForThread(MessageQueue.singleton);
+                        where = org.xwt.js.JS.Thread.fromJavaThread(MessageQueue.singleton).getSourceName();
                         what = "script";
                     }
                     long howlong = (System.currentTimeMillis() - t) / 1000;
index e8e92e3..24cc971 100644 (file)
@@ -106,7 +106,7 @@ class SpecialBoxProperty {
                     else if (s.equals("pink")) newcolor = pink;
                     else if (s.equals("yellow")) newcolor = yellow;
                     else if (s.equals("white")) newcolor = white;
-                    else if (Log.on) Log.log(this, "invalid color \"" + s + "\" at " + Context.getCurrentSourceNameAndLine());
+                    else if (Log.on) Log.logJS(this, "invalid color \"" + s + "\"");
                     if (newcolor == b.color) return;
                     b.color = newcolor;
                     b.dirty();
@@ -149,7 +149,7 @@ class SpecialBoxProperty {
                     else if (s.equals("pink")) newtextcolor = pink;
                     else if (s.equals("yellow")) newtextcolor = yellow;
                     else if (s.equals("white")) newtextcolor = white;
-                    else if (Log.on) Log.log(this, "invalid color \"" + s + "\" at " + Context.getCurrentSourceNameAndLine());
+                    else if (Log.on) Log.logJS(this, "invalid color \"" + s + "\"");
                     if (newtextcolor == b.textcolor) return;
                     b.textcolor = newtextcolor;
                     b.dirty();
@@ -219,7 +219,7 @@ class SpecialBoxProperty {
 
         specialBoxProperties.put("static", new SpecialBoxProperty() {
                 public Object get(Box b) {
-                    String cfsn = Context.getContextForThread(Thread.currentThread()).getCurrentFunction().getSourceName();
+                    String cfsn = JS.Thread.fromJavaThread(Thread.currentThread()).getCurrentCompiledFunction().getSourceName();
                     for(int i=0; i<cfsn.length() - 1; i++)
                         if (cfsn.charAt(i) == '.' && (cfsn.charAt(i+1) == '_' || Character.isDigit(cfsn.charAt(i+1)))) {
                             cfsn = cfsn.substring(0, i);
@@ -697,7 +697,7 @@ class SpecialBoxProperty {
                 String templatename = (String)args.elementAt(0);
                 Template t = Template.getTemplate(templatename, null);
                 if (t == null) {
-                    if (Log.on) Log.log(this, "template " + templatename + " not found at " + Context.getCurrentSourceNameAndLine());
+                    if (Log.on) Log.logJS(this, "template " + templatename + " not found");
                 } else {
                     if (ThreadMessage.suspendThread()) try {
                         JS.Callable callback = args.length() < 2 ? null : (Callable)args.elementAt(1);
index 07a47d4..51a4d7a 100644 (file)
@@ -56,7 +56,7 @@ public class ThreadMessage extends Thread implements Message {
         // put ourselves in the background
         Thread thread = Thread.currentThread();
         if (!(thread instanceof ThreadMessage)) {
-            if (Log.on) Log.log(ThreadMessage.class, "attempt to perform background-only operation in a foreground thread at " + Context.getCurrentSourceNameAndLine());
+            if (Log.on) Log.logJS(ThreadMessage.class, "attempt to perform background-only operation in a foreground thread");
             return false;
         }
         ThreadMessage mythread = (ThreadMessage)thread;
index ec47f2d..0d572c7 100644 (file)
@@ -80,7 +80,7 @@ public class Trap {
         }
 
         // find out what script is currently running
-        JS.CompiledFunction placer = Context.getContextForThread(Thread.currentThread()).getCurrentFunction();
+        JS.CompiledFunction placer = JS.Thread.fromJavaThread(java.lang.Thread.currentThread()).getCurrentCompiledFunction();
         if (placer == null) { Log.log(Trap.class, "placer is null"); return; }
         String placerNodeName = placer.getSourceName();
 
@@ -110,7 +110,7 @@ public class Trap {
     public static Trap getTrap(Box b, String name) {
         if (b.traps == null) return null;
 
-        String currentFunctionNodeName = Context.getContextForThread(Thread.currentThread()).getCurrentFunction().getSourceName();
+        String currentFunctionNodeName = JS.Thread.fromJavaThread(java.lang.Thread.currentThread()).getCurrentCompiledFunction().getSourceName();
         for(Trap cur = (Trap)b.traps.get(name); cur != null; cur = cur.next)
             if (cur.placerNodeName.equals(currentFunctionNodeName))
                 return cur;
@@ -122,7 +122,7 @@ public class Trap {
     public static final CascadeFunction cascadeFunction = new CascadeFunction();
     private static class CascadeFunction extends JS.Callable {
         CascadeFunction() { setSeal(true); }
-        public Object call(JS.Array args) { return call(args, Context.getContextForThread(Thread.currentThread()).getCurrentFunction()); }
+        public Object call(JS.Array args) { return call(args, JS.Thread.fromJavaThread(java.lang.Thread.currentThread()).getCurrentCompiledFunction()); }
         public Object call(JS.Array args, JS.CompiledFunction currentFunction) {
             Trap currentTrap = TrapContext.get().currentTrap;
             if (args.length() != 0) TrapContext.get().putCascadeHappened = true;
@@ -223,7 +223,7 @@ public class Trap {
 
         /** returns the TrapContext for the current thread */
         static TrapContext get() {
-            TrapContext ret = (TrapContext)trapContextByThread.get(Thread.currentThread());
+            TrapContext ret = (TrapContext)trapContextByThread.get(java.lang.Thread.currentThread());
             if (ret == null) {
                 ret = new TrapContext();
                 trapContextByThread.put(Thread.currentThread(), ret);
index 64d3fee..282d9ef 100644 (file)
@@ -123,7 +123,7 @@ class XMLRPC extends JS.Callable {
                   if (i > 0) s = s.substring(i);
                   
                   try {
-                  NativeDate nd = (NativeDate)Context.enter().newObject(org.xwt.util.JS.Obj.defaultObjects, "Date");
+                  NativeDate nd = (NativeDate)JS.Thread.enter().newObject(org.xwt.util.JS.Obj.defaultObjects, "Date");
                   double date = NativeDate.date_msecFromDate(Double.valueOf(s.substring(0, 4)).doubleValue(),
                   Double.valueOf(s.substring(4, 6)).doubleValue() - 1,
                   Double.valueOf(s.substring(6, 8)).doubleValue(),
@@ -413,18 +413,18 @@ class XMLRPC extends JS.Callable {
     private static class Filter extends FilterInputStream {
         public Filter(InputStream is) { super(is); }
         public int read() throws IOException {
-            Thread.yield();
-            while(MessageQueue.nonThreadEventsInQueue > 0) try { Thread.sleep(100); } catch (Exception e) { };
+            java.lang.Thread.yield();
+            while(MessageQueue.nonThreadEventsInQueue > 0) try { java.lang.Thread.sleep(100); } catch (Exception e) { };
             return super.read();
         }
         public int read(byte[] b) throws IOException {
-            Thread.yield();
-            while(MessageQueue.nonThreadEventsInQueue > 0) try { Thread.sleep(100); } catch (Exception e) { };
+            java.lang.Thread.yield();
+            while(MessageQueue.nonThreadEventsInQueue > 0) try { java.lang.Thread.sleep(100); } catch (Exception e) { };
             return super.read(b);
         }
         public int read(byte[] b, int i, int j) throws IOException {
-            Thread.yield();
-            while(MessageQueue.nonThreadEventsInQueue > 0) try { Thread.sleep(100); } catch (Exception e) { };
+            java.lang.Thread.yield();
+            while(MessageQueue.nonThreadEventsInQueue > 0) try { java.lang.Thread.sleep(100); } catch (Exception e) { };
             return super.read(b, i, j);
         }
     }
index 7da117e..1b875ad 100644 (file)
@@ -55,7 +55,7 @@ public final class XWT extends JS.Obj {
         put("fileSeparator", File.separator);
         put("homeDir", System.getProperty("user.home"));
         put("tempDir", System.getProperty("java.io.tempdir"));
-        put("math", org.xwt.js.Math.singleton);
+        put("math", org.xwt.js.JS.Math);
 
         put("newBrowserWindow", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
             if (args.length() != 1 || args.elementAt(0) == null) return null;
@@ -98,8 +98,7 @@ public final class XWT extends JS.Obj {
             
         put("println", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
             if (args.length() != 1) return null;
-            if (Log.on) Log.log(this, Context.getCurrentSourceNameAndLine() + " " +
-                                (args.elementAt(0) == null ? "**null**" : args.elementAt(0).toString()));
+            if (Log.on) Log.logJS(this, (args.elementAt(0) == null ? "**null**" : args.elementAt(0).toString()));
             return null;
         }});
 
@@ -322,16 +321,16 @@ public final class XWT extends JS.Obj {
         if (!name.equals("")) name += " : ";
 
         if (o == null) {
-            Log.log(Context.getCurrentSourceNameAndLine() , indent + name + "<null>");
+            Log.logJS(indent + name + "<null>");
 
         } else if (o instanceof JS.Array) {
-            Log.log(Context.getCurrentSourceNameAndLine() , indent + name + "<array>");
+            Log.logJS(indent + name + "<array>");
             JS.Array na = (JS.Array)o;
             for(int i=0; i<na.length(); i++)
                 recurse(indent + "  ", i + "", na.elementAt(i));
 
         } else if (o instanceof JS) {
-            Log.log(Context.getCurrentSourceNameAndLine() , indent + name + "<object>");
+            Log.logJS(indent + name + "<object>");
             JS s = (JS)o;
             Object[] keys = s.keys();
             for(int i=0; i<keys.length; i++)
@@ -340,20 +339,20 @@ public final class XWT extends JS.Obj {
                         s.get(((Integer)keys[i])) : s.get(keys[i].toString()));
 
         } else {
-            Log.log(Context.getCurrentSourceNameAndLine(), indent + name + o);
+            Log.logJS(indent + name + o);
 
         }
     }
 
 
     public static void sleep(int i) {
-        Thread thread = Thread.currentThread();
+        java.lang.Thread thread = java.lang.Thread.currentThread();
         if (!(thread instanceof ThreadMessage)) {
             if (Log.on) Log.log(XWT.class, "cannot sleep() or yield() in the foreground thread");
         } else {
             ThreadMessage mythread = (ThreadMessage)thread;
             mythread.done.release();
-            if (i > 0) try { Thread.sleep(i); } catch (Exception e) { }
+            if (i > 0) try { java.lang.Thread.sleep(i); } catch (Exception e) { }
             MessageQueue.add(mythread);
             mythread.go.block();
         }
index 37403bd..22e9f23 100644 (file)
@@ -5,6 +5,8 @@ import org.xwt.util.*;
 import java.io.*;
 import java.util.*;
 
+// FIXME: could use some cleaning up...
+
 /** A JavaScript Array */
 class ArrayImpl extends JS.Obj {
     private Vec vec = new Vec();
index 692db3f..0755251 100644 (file)
@@ -5,7 +5,7 @@ import org.xwt.util.*;
 import java.io.*;
 
 /** a JavaScript function, compiled into bytecode */
-public class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
+class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
 
     // Fields and Accessors ///////////////////////////////////////////////
 
@@ -62,22 +62,19 @@ public class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Toke
     
     public Object call(JS.Array args) throws JS.Exn { return call(args, new FunctionScope(sourceName, parentScope)); }
     public Object call(JS.Array args, JS.Scope scope) throws JS.Exn {
-        CompiledFunctionImpl saved = (CompiledFunctionImpl)Context.currentFunction.get(Thread.currentThread());
+        JS.Thread cx = JS.Thread.fromJavaThread(java.lang.Thread.currentThread());
+        CompiledFunction saved = cx.currentCompiledFunction;
         try {
-            Context.currentFunction.put(Thread.currentThread(), this);
-            Context cx = Context.getContextForThread(Thread.currentThread());
+            cx.currentCompiledFunction = (CompiledFunction)this;
             int size = cx.stack.size();
-            cx.stack.push(new Context.CallMarker());
+            cx.stack.push(new CallMarker());
             cx.stack.push(args);
             eval(scope);
             Object ret = cx.stack.pop();
-            if (cx.stack.size() > size)
-                Log.log(this, "warning, stack grew by " + (cx.stack.size() - size) +
-                        " elements during call to " + Context.getCurrentSourceNameAndLine());
+            if (cx.stack.size() > size) Log.logJS(this, "warning, stack grew by " + (cx.stack.size() - size) + " elements during call");
             return ret;
         } finally {
-            if (saved == null) Context.currentFunction.remove(Thread.currentThread());
-            else Context.currentFunction.put(Thread.currentThread(), saved);
+            cx.currentCompiledFunction = saved;
         }
     }
 
@@ -107,7 +104,7 @@ public class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Toke
         
     int pc = 0;
     void eval(JS.Scope s) {
-        final Vec t = Context.getContextForThread(Thread.currentThread()).stack;
+        final Vec t = JS.Thread.fromJavaThread(java.lang.Thread.currentThread()).stack;
         OUTER: for(pc=0; pc<size; pc++) {
             String label = null;
             switch(op[pc]) {
@@ -162,7 +159,7 @@ public class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Toke
             case LABEL: break;
             case LOOP: {
                 t.push(s);
-                t.push(new Context.LoopMarker(pc, pc > 0 && op[pc - 1] == LABEL ? (String)arg[pc - 1] : (String)null));
+                t.push(new LoopMarker(pc, pc > 0 && op[pc - 1] == LABEL ? (String)arg[pc - 1] : (String)null));
                 t.push(Boolean.TRUE);
                 break;
             }
@@ -171,10 +168,10 @@ public class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Toke
             case CONTINUE:
                 while(t.size() > 0) {
                     Object o = t.pop();
-                    if (o instanceof Context.CallMarker) ee("break or continue not within a loop");
-                    if (o != null && o instanceof Context.LoopMarker) {
-                        if (arg[pc] == null || arg[pc].equals(((Context.LoopMarker)o).label)) {
-                            int loopInstructionLocation = ((Context.LoopMarker)o).location;
+                    if (o instanceof CallMarker) ee("break or continue not within a loop");
+                    if (o != null && o instanceof LoopMarker) {
+                        if (arg[pc] == null || arg[pc].equals(((LoopMarker)o).label)) {
+                            int loopInstructionLocation = ((LoopMarker)o).location;
                             int endOfLoop = ((Integer)arg[loopInstructionLocation]).intValue() + loopInstructionLocation;
                             s = (JS.Scope)t.pop();
                             if (op[pc] == CONTINUE) { t.push(s); t.push(o); t.push(Boolean.FALSE); }
@@ -186,7 +183,7 @@ public class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Toke
                 throw new Error("CONTINUE/BREAK invoked but couldn't find a LoopMarker at " + sourceName + ":" + line);
 
             case TRY: {
-                t.push(new Context.TryMarker(pc + ((Integer)arg[pc]).intValue(), s));
+                t.push(new TryMarker(pc + ((Integer)arg[pc]).intValue(), s));
                 break;
             }
 
@@ -194,7 +191,7 @@ public class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Toke
                 Object retval = t.pop();
                 while(t.size() > 0) {
                     Object o = t.pop();
-                    if (o != null && o instanceof Context.CallMarker) {
+                    if (o != null && o instanceof CallMarker) {
                         t.push(retval);
                         return;
                     }
@@ -261,10 +258,10 @@ public class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Toke
                 Object exn = t.pop();
                 while(t.size() > 0) {
                     Object o = t.pop();
-                    if (o instanceof Context.TryMarker) {
+                    if (o instanceof TryMarker) {
                         t.push(exn);
-                        pc = ((Context.TryMarker)o).location - 1;
-                        s = ((Context.TryMarker)o).scope;
+                        pc = ((TryMarker)o).location - 1;
+                        s = ((TryMarker)o).scope;
                         continue OUTER;
                     }
                 }
@@ -407,4 +404,26 @@ public class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Toke
             return super.get(key);
         }
     }
+
+
+    // Markers //////////////////////////////////////////////////////////////////////
+
+    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;
+        }
+    }
+
 }
index e8ca96e..000c0f8 100644 (file)
@@ -5,59 +5,3 @@ import org.xwt.util.*;
 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;
-        }
-    }
-
-}
index a3d4b36..f317d31 100644 (file)
@@ -6,6 +6,6 @@ import java.io.*;
 import java.util.*;
 
 /** a JavaScript Date object */
-public class Date extends JS.Obj {
-    
+class Date extends JS.Obj {
+    // FIXME: implement    
 }
index c7c1c54..24f133a 100644 (file)
@@ -15,6 +15,7 @@ import java.util.*;
  */
 public abstract class JS { 
 
+
     // Public Helper Methods //////////////////////////////////////////////////////////////////////
 
     /** parse and compile a function */
@@ -66,6 +67,7 @@ public abstract class JS {
         private boolean sealed = false;
         public Obj() { this(false); }
         public Obj(boolean sealed) { this.sealed = sealed; }
+        /** a sealed object cannot have its properties modified */
         public void setSeal(boolean sealed) { this.sealed = sealed; }
         public Object get(Object key) { return entries.get(key); }
         public void put(Object key, Object val) { if (!sealed) entries.put(key, val); }
@@ -96,7 +98,7 @@ public abstract class JS {
     public static class Scope extends ScopeImpl { 
         public Scope(Scope parentScope) { this(parentScope, false); }
         public Scope(Scope parentScope, boolean sealed) { super(parentScope, sealed); }
-        public Scope getParentScope() { return super.getParentScope(); }
+        /** transparent scopes are not returned by THIS */
         public boolean isTransparent() { return super.isTransparent(); }
         public boolean has(Object key) { return super.has(key); }
         public void declare(String s) { super.declare(s); }
@@ -114,7 +116,44 @@ public abstract class JS {
             super(sourceName, firstLine, sourceCode, scope);
         }
     }
+
+    public static final JS Math = new org.xwt.js.Math();
  
+    /** encapsulates a single JavaScript thread; the JS.Thread->java.lang.Thread mapping is 1:1 */
+    public static class Thread {
+
+        CompiledFunction currentCompiledFunction = null;
+        Vec stack = new Vec();
+        private int line = -1;
+
+        /** binds this thread to the current Java Thread */
+        public void bindToCurrentJavaThread() { javaThreadToJSThread.put(java.lang.Thread.currentThread(), this); }
+
+        /** returns the line of code that is currently executing */
+        public int getLine() { return line; }
+
+        /** returns the name of the source code file which declared the currently executing function */
+        public String getSourceName() { return currentCompiledFunction == null ? null : currentCompiledFunction.getSourceName();  }
+
+        /** fetches the currently-executing javascript function */
+        public JS.CompiledFunction getCurrentCompiledFunction() { return currentCompiledFunction; }
+
+
+        // Statics ///////////////////////////////////////////////////////////////////////
+
+        private static Hashtable javaThreadToJSThread = new Hashtable();
+
+        /** returns the JS thread for a given Java thread, creating one if necessary */
+        public static JS.Thread fromJavaThread(java.lang.Thread t) {
+            JS.Thread ret = (JS.Thread)javaThreadToJSThread.get(t);
+            if (ret == null) {
+                ret = new JS.Thread();
+                ret.bindToCurrentJavaThread();
+            }
+            return ret;
+        }
+        
+    }
 } 
 
 
index 1fa432d..f08ebce 100644 (file)
@@ -17,8 +17,6 @@
  * Contributor(s): Roger Lawrence, Mike McCabe
  */
 
-// FIXME: mark lots of these methods 'final' so they get inlined
-
 package org.xwt.js;
 import java.io.*;
 
@@ -285,7 +283,7 @@ class Lexer implements Tokens {
         return STRING;
     }
 
-    public int _getToken() throws IOException {
+    private int _getToken() throws IOException {
         int c;
         do { c = in.read(); } while (c == '\u0020' || c == '\u0009' || c == '\u000C' || c == '\u000B' || c == '\n' );
         if (c == -1) return -1;
@@ -381,7 +379,7 @@ class Lexer implements Tokens {
     private Object[] pushBackObjects = new Object[10];
 
     /** push back a token */
-    public void pushBackToken(int op, Object obj) {
+    public final void pushBackToken(int op, Object obj) {
         if (pushBackDepth >= pushBackInts.length - 1) {
             int[] newInts = new int[pushBackInts.length * 2];
             System.arraycopy(pushBackInts, 0, newInts, 0, pushBackInts.length);
@@ -396,17 +394,17 @@ class Lexer implements Tokens {
     }
 
     /** push back the most recently read token */
-    public void pushBackToken() { pushBackToken(op, number != null ? (Object)number : (Object)string); }
+    public final void pushBackToken() { pushBackToken(op, number != null ? (Object)number : (Object)string); }
 
     /** read a token but leave it in the stream */
-    public int peekToken() throws IOException {
+    public final int peekToken() throws IOException {
         int ret = getToken();
         pushBackToken();
         return ret;
     }
 
     /** read a token */
-    public int getToken() throws IOException {
+    public final int getToken() throws IOException {
         number = null;
         string = null;
         if (pushBackDepth == 0) {
index 599c4f5..eedfee5 100644 (file)
@@ -6,10 +6,11 @@ import java.io.*;
 import java.util.*;
 
 /** The JavaScript Math object */
-public class Math extends JS.Obj {
+class Math extends JS.Obj {
     public static Math singleton = new Math();
-    private Math() { setSeal(true); }
+    Math() { setSeal(true); }
 
+    // FIXME: clean up, finish implementing
     public Object get(Object name) {
         if ("ceil".equals(name)) return new JS.Callable() { public Object call(JS.Array args)
                 { if (args.elementAt(0) == null) return null;
index 4aa8b2f..9805602 100644 (file)
@@ -6,6 +6,6 @@ import java.io.*;
 import java.util.*;
 
 /** a JavaScript Regexp object */
-public class Regexp extends JS.Obj {
-    
+class Regexp extends JS.Obj {
+    // FIXME: implement    
 }
index ecb9b91..5162c0e 100644 (file)
@@ -5,33 +5,28 @@ import org.xwt.util.*;
 import java.io.*;
 import java.util.*;
 
-/** A JavaScript Scope */
+/** Implementation of a JavaScript Scope */
 class ScopeImpl extends JS.Obj { 
     private JS.Scope parentScope;
     private static Object NULL = new Object();
-    public ScopeImpl(JS.Scope parentScope) { this(parentScope, false); }
     public ScopeImpl(JS.Scope parentScope, boolean sealed) {
         super(sealed);
         if (parentScope == this) throw new Error("can't make a scope its own parent!");
         this.parentScope = parentScope;
     }
-    public JS.Scope getParentScope() { return parentScope; }
-    
-    // transparent scopes are not returned by THIS
-    public boolean isTransparent() { return false; }
-    
+    public Object[] keys() { throw new Error("you can't enumerate the properties of a Scope"); }
     public boolean has(Object key) { return super.get(key) != null; }
     public Object get(Object key) {
-        if (!has(key)) return parentScope == null ? null : getParentScope().get(key);
+        if (!has(key)) return parentScope == null ? null : parentScope.get(key);
         Object ret = super.get(key); return ret == NULL ? null : ret;
     }
     public void put(Object key, Object val) {
-        if (!has(key) && parentScope != null) getParentScope().put(key, val);
+        if (!has(key) && parentScope != null) parentScope.put(key, val);
         else super.put(key, val == null ? NULL : val);
     }
-    public Object[] keys() { throw new Error("you can't enumerate the properties of a Scope"); }
+    public boolean isTransparent() { return false; }
     public void declare(String s) {
-        if (isTransparent()) getParentScope().declare(s);
+        if (isTransparent()) parentScope.declare(s);
         else super.put(s, NULL);
     }
 } 
index 71fb1ed..a367004 100644 (file)
@@ -1,5 +1,6 @@
 // Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL]
 package org.xwt.util;
+import org.xwt.js.*;
 import java.io.*;
 import java.util.*;
 
@@ -14,6 +15,17 @@ public class Log {
     /** true iff nothing has yet been logged */
     public static boolean firstMessage = true;
 
+    /** log a message with the current JavaScript sourceName/line */
+    public static void logJS(Object o, Object message) { logJS(message); }
+    public static void logJS(Object message) {
+        JS.Thread current = org.xwt.js.JS.Thread.fromJavaThread(Thread.currentThread());
+        if (current == null) {
+            log("<none>", message);
+        } else {
+            log(current.getSourceName() + current.getLine(), message);
+        }
+    }
+
     /** message can be a String or a Throwable */
     public static synchronized void log(Object o, Object message) {