From b5b84ec73713b8ff40e177d4122dda19bd84bf8e Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 30 Jan 2004 07:02:40 +0000 Subject: [PATCH] 2003/06/29 21:20:38 darcs-hash:20040130070240-aa32f-e13c29c9462f9e27161a8683c2e3a916411a289c.gz --- src/org/xwt/Box.java | 3 +- src/org/xwt/Template.java | 20 +++++++------ src/org/xwt/Trap.java | 8 ++---- src/org/xwt/js/ByteCodes.java | 6 ++++ src/org/xwt/js/CompiledFunctionImpl.java | 46 ++++++++++++++++++++++++++---- src/org/xwt/js/JS.java | 7 +++-- src/org/xwt/js/Math.java | 1 + src/org/xwt/js/Regexp.java | 28 ++++++++++-------- 8 files changed, 84 insertions(+), 35 deletions(-) diff --git a/src/org/xwt/Box.java b/src/org/xwt/Box.java index 501f061..f40a413 100644 --- a/src/org/xwt/Box.java +++ b/src/org/xwt/Box.java @@ -1203,7 +1203,8 @@ public final class Box extends JS.Scope { public void put(Object name, Object value, boolean ignoretraps) { put(name, value, ignoretraps, null); } public void put(Object name_, Object value, boolean ignoretraps, RootProxy rp) { if (name_ instanceof Number) { put(((Number)name_).intValue(), value); return; } - String name = (String)name_; + if (!(name_ instanceof String)) { super.put(name_,value); return; } + String name = name_.toString(); if (name == null) return; // FIXME, shouldn't be necessary if (name.startsWith("xwt_")) { if (Log.on) Log.logJS(this, "attempt to set reserved property " + name); diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 6ee6f0b..2f14040 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -212,15 +212,19 @@ public class Template { } for(int i=0; keys != null && i 0 && !isreadtrap && !tc.putCascadeHappened) cascadeFunction.call(args); return ret; - - } catch (JS.Exn e) { - if (Log.on) Log.log(this, e); - + } finally { // restore the thread-locals tc.putCascadeHappened = save_putCascadeHappened; tc.currentTrap = save_currentTrap; tc.trapDepth--; } - return null; } /** removes this trap */ diff --git a/src/org/xwt/js/ByteCodes.java b/src/org/xwt/js/ByteCodes.java index b23af2d..c74c564 100644 --- a/src/org/xwt/js/ByteCodes.java +++ b/src/org/xwt/js/ByteCodes.java @@ -73,4 +73,10 @@ interface ByteCodes { * and FALSE for all subsequent iterations */ public static final byte LOOP = -22; + + public static final String[] bytecodeToString = new String[] { + "", "", "LITERAL", "ARRAY", "OBJECT", "NEWFUNCTION", "DECLARE", "TOPSCOPE", + "GET", "GET_PRESERVE", "PUT", "JT", "JF", "JMP", "POP", "CALL", "PUSHKEYS", + "SWAP", "NEWSCOPE", "OLDSCOPE", "DUP", "LABEL", "LOOP" + }; } diff --git a/src/org/xwt/js/CompiledFunctionImpl.java b/src/org/xwt/js/CompiledFunctionImpl.java index 9912ab1..5aff71a 100644 --- a/src/org/xwt/js/CompiledFunctionImpl.java +++ b/src/org/xwt/js/CompiledFunctionImpl.java @@ -53,7 +53,8 @@ class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { p.parseStatement(this, null); if (s == size()) break; } - add(-1, Tokens.RETURN); + add(-1, LITERAL, null); + add(-1, RETURN); } public Object call(JS.Array args) throws JS.Exn { return call(args, new FunctionScope(sourceName, parentScope)); } @@ -67,7 +68,10 @@ class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { cx.stack.push(args); eval(scope); Object ret = cx.stack.pop(); - if (cx.stack.size() > size) Log.logJS(this, "warning, stack grew by " + (cx.stack.size() - size) + " elements during call"); + // FIXME: if we catch an exception in Java, JS won't notice and the stack will be messed up + if (cx.stack.size() > size) + // this should never happen + throw new Error("ERROR: stack grew by " + (cx.stack.size() - size) + " elements during call"); return ret; } finally { cx.currentCompiledFunction = saved; @@ -94,17 +98,23 @@ class CompiledFunctionImpl extends JSCallable implements ByteCodes, Tokens { size++; return this; } + + public int getLine(int pc) { + if(pc < 0 || pc >= size) return -1; + return line[pc]; + } // Invoking the Bytecode /////////////////////////////////////////////////////// - int pc = 0; void eval(JS.Scope s) { final JS.Thread cx = JS.Thread.fromJavaThread(java.lang.Thread.currentThread()); final Vec t = cx.stack; + int pc; + int lastPC = -1; OUTER: for(pc=0; pc