*/
public abstract class JS {
-
// Public Helper Methods //////////////////////////////////////////////////////////////////////
/** parse and compile a function */
public abstract Object get(Object key) throws JS.Exn;
public abstract void put(Object key, Object val) throws JS.Exn;
+ public void put(Object key, Object val, TailCall tail) throws JS.Exn { put(key, val); }
public abstract Object[] keys();
public Object callMethod(Object method, Array args, boolean checkOnly) throws JS.Exn {
if(checkOnly) return Boolean.FALSE;
public Obj() { this(false); }
public Obj(boolean sealed) { this.sealed = sealed; }
public void setSeal(boolean sealed) { this.sealed = sealed; } ///< a sealed object cannot have its properties modified
- public void put(Object key, Object val) { put(key, null, val); }
- protected void put(Object key, Object key2, Object val) {
+ public void put(Object key, Object val) { put2(key, null, val); }
+ protected void put2(Object key, Object key2, Object val) {
if (sealed) return;
if (entries == null) entries = new Hash();
entries.put(key, key2, val); }
}
public static final JS Math = new org.xwt.js.Math();
+
+ public static class TailCall {
+ CompiledFunction func = null;
+ JS.Array args = null;
+ public TailCall() { }
+ public TailCall set(CompiledFunction func) { this.func = func; this.args = new JS.Array(); return this; }
+ public TailCall set(CompiledFunction func, JS.Array args) { this.func = func; this.args = args; return this; }
+ }
/** encapsulates a single JavaScript thread; the JS.Thread->java.lang.Thread mapping is 1:1 */
public static class Thread {
int pc = 0;
boolean paused = false;
- CompiledFunction tailCallFunction = null;
- JS.Array tailCallArgs = null;
-
- public Thread(CompiledFunction function) {
- this(function, new CompiledFunctionImpl.FunctionScope("unknown", function.parentScope));
- }
- public Thread(CompiledFunction function, Scope scope) {
+ public Thread(CompiledFunction function) { this(function, null); }
+ public Thread(CompiledFunction function, Scope scope) { this(function, scope, new JS.Array()); }
+ public Thread(CompiledFunction function, Scope scope, JS.Array args) {
+ if (scope == null) scope = new CompiledFunctionImpl.FunctionScope("unknown", function.parentScope);
stack.push(new CompiledFunctionImpl.CallMarker(this));
- stack.push(new JS.Array());
+ stack.push(args);
this.currentCompiledFunction = function;
this.scope = scope;
}
- public void setTailCall(JS.CompiledFunction f, JS.Array args) { tailCallFunction = f; tailCallArgs = args; }
-
public static JS.Thread current() { return (JS.Thread)javaThreadToJSThread.get(java.lang.Thread.currentThread()); }
-
public Object resume() { bind(); paused = false; Object ret = CompiledFunctionImpl.eval(this); unbind(); return ret; }
public void pause() { paused = true; unbind(); }
public void bind() { javaThreadToJSThread.put(java.lang.Thread.currentThread(), this); }
}
}
- public synchronized void renderGlyph(Res res, Glyph glyph) {
+ public synchronized void renderGlyph(Font.Glyph glyph) {
try {
- if (loadedStream != res) loadFontByteStream(res);
+ if (loadedStream != glyph.font.res) loadFontByteStream(glyph.font.res);
vm.setUserInfo(2, (int)glyph.c);
vm.setUserInfo(3, (int)glyph.c);
- vm.setUserInfo(4, glyph.pointsize);
+ vm.setUserInfo(4, glyph.font.pointsize);
long start = System.currentTimeMillis();
vm.execute();
- glyph.max_ascent = vm.getUserInfo(8);
- glyph.max_descent = vm.getUserInfo(9);
+ glyph.font.max_ascent = vm.getUserInfo(8);
+ glyph.font.max_descent = vm.getUserInfo(9);
glyph.baseline = vm.getUserInfo(10);
glyph.advance = vm.getUserInfo(11);
int height = vm.getUserInfo(7);
if (width == 0 || height == 0) {
Log.log(Freetype.class, "warning glyph has zero width/height");
+ glyph.p = Platform.createAlphaOnlyPicture(new byte[] { }, 0, 0);
} else {
byte[] data = new byte[width * height];
vm.copyin(addr,data,width*height);
glyph.p = Platform.createAlphaOnlyPicture(data, width, height);
}
+
} catch (Exception e) {
Log.log(this, e);
}