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);
} finally {
MessageQueue.add(mythread);
- mythread.setPriority(Thread.NORM_PRIORITY);
+ mythread.setPriority(java.lang.Thread.NORM_PRIORITY);
mythread.go.block();
}
}
} 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();
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();
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");
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);
}
} 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;
// 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;
}
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;
}
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;
}
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);
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;
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();
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();
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);
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);
// 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;
}
// 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();
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;
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;
/** 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);
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(),
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);
}
}
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;
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;
}});
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++)
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();
}
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();
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 ///////////////////////////////////////////////
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;
}
}
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]) {
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;
}
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); }
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;
}
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;
}
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;
}
}
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;
+ }
+ }
+
}
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;
- }
- }
-
-}
import java.util.*;
/** a JavaScript Date object */
-public class Date extends JS.Obj {
-
+class Date extends JS.Obj {
+ // FIXME: implement
}
*/
public abstract class JS {
+
// Public Helper Methods //////////////////////////////////////////////////////////////////////
/** parse and compile a function */
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); }
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); }
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;
+ }
+
+ }
}
* Contributor(s): Roger Lawrence, Mike McCabe
*/
-// FIXME: mark lots of these methods 'final' so they get inlined
-
package org.xwt.js;
import java.io.*;
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;
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);
}
/** 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) {
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;
import java.util.*;
/** a JavaScript Regexp object */
-public class Regexp extends JS.Obj {
-
+class Regexp extends JS.Obj {
+ // FIXME: implement
}
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);
}
}
// 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.*;
/** 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) {