X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FJS.java;h=d3da1f1e9d5f87159cc2a2f0a112c0b4161d910f;hp=b0d54e5242ec16674c2d4c282e3179685be4c7e5;hb=2a94571c07db6db966f6bfa32583a72287f4db29;hpb=70fdbe545b400b82aebbd9165607b3599c3e0113 diff --git a/src/org/xwt/js/JS.java b/src/org/xwt/js/JS.java index b0d54e5..d3da1f1 100644 --- a/src/org/xwt/js/JS.java +++ b/src/org/xwt/js/JS.java @@ -104,7 +104,7 @@ public abstract class JS { try { return vec.elementAt(i); } catch (ArrayIndexOutOfBoundsException e) { - throw new JS.Exn(e.getMessage()); + return null; } } public void put(Object key, Object val) { @@ -137,24 +137,28 @@ public abstract class JS { int line; String sourceName; Scope parentScope; - public Function() { this(-1, "unknown", null, null); } public Function(int line, String sourceName, ByteCodeBlock bytecodes, Scope parentScope) { this.sourceName = sourceName; this.line = line; this.bytecodes = bytecodes; this.parentScope = parentScope; } + public Function cloneWithNewParentScope(Scope s) { + if (this.getClass() != Function.class) + throw new Error("org.xwt.js.JS.Function.cloneWithNewParentScope() is not valid for subclasses"); + return new Function(line, sourceName, bytecodes, s); + } public String getSourceName() throws JS.Exn { return sourceName; } public int getLine() throws JS.Exn { return line; } public Object _call(JS.Array args) throws JS.Exn, ByteCodeBlock.ControlTransferException { if (bytecodes == null) throw new Error("tried to call() a JS.Function with bytecodes == null"); Vec stack = new Vec(); stack.push(args); - return bytecodes.eval(new FunctionScope(sourceName, parentScope), stack); + return bytecodes.eval(args == null ? parentScope : new FunctionScope(sourceName, parentScope), stack); } public final Object call(JS.Array args) throws JS.Exn { Function saved = (Function)currentFunction.get(Thread.currentThread()); - currentFunction.put(Thread.currentThread(), this); + if (!getSourceName().equals("java")) currentFunction.put(Thread.currentThread(), this); try { return _call(args); } catch (ByteCodeBlock.ReturnException e) { // ignore @@ -169,29 +173,19 @@ public abstract class JS { } } - public static class Script extends Function { - Vector e = null; - private Script(Vector e) { this.e = e; } - public String getSourceName() throws JS.Exn { return ((ByteCodeBlock)e.elementAt(0)).getSourceName(); } - public Object _call(JS.Array args) throws JS.Exn, ByteCodeBlock.ControlTransferException { - Scope rootScope = (Scope)args.elementAt(0); - for(int i=0; i