X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FInterpreter.java;h=359b844a9c51c1027d5e053b19061f8b98151aa2;hb=163ff4c57ec557bb8615f80e875f045cdfbad696;hp=700462a9cad5b026c69d9c08835e89693761aece;hpb=75b9e1e72f6067e59a1e5312c91d20d05ec8a927;p=org.ibex.core.git diff --git a/src/org/xwt/js/Interpreter.java b/src/org/xwt/js/Interpreter.java index 700462a..359b844 100644 --- a/src/org/xwt/js/Interpreter.java +++ b/src/org/xwt/js/Interpreter.java @@ -44,7 +44,17 @@ class Interpreter implements ByteCodes, Tokens { } } - private static JSExn je(String s) { return new JSExn(JS.getSourceName() + ":" + JS.getLine() + " " + s); } + static int getLine() { + Interpreter c = Interpreter.current(); + return c == null || c.f == null || c.pc < 0 || c.pc >= c.f.size ? -1 : c.f.line[c.pc]; + } + + static String getSourceName() { + Interpreter c = Interpreter.current(); + return c == null || c.f == null ? null : c.f.sourceName; + } + + private static JSExn je(String s) { return new JSExn(getSourceName() + ":" + getLine() + " " + s); } // FIXME: double check the trap logic private Object run() throws JSExn { @@ -87,17 +97,17 @@ class Interpreter implements ByteCodes, Tokens { case ASSERT: if (!JS.toBoolean(stack.pop())) throw je("xwt.assertion.failed" /*FEATURE: line number*/); break; case BITNOT: stack.push(JS.N(~JS.toLong(stack.pop()))); break; case BANG: stack.push(JS.B(!JS.toBoolean(stack.pop()))); break; - case NEWFUNCTION: stack.push(((JSFunction)arg).cloneWithNewParentScope(scope)); break; + case NEWFUNCTION: stack.push(((JSFunction)arg)._cloneWithNewParentScope(scope)); break; case LABEL: break; case TYPEOF: { Object o = stack.pop(); if (o == null) stack.push(null); - else if (o instanceof JS) stack.push(((JS)o).typeName()); + else if (o instanceof JS) stack.push("object"); else if (o instanceof String) stack.push("string"); else if (o instanceof Number) stack.push("number"); else if (o instanceof Boolean) stack.push("boolean"); - else stack.push("unknown"); + else throw new Error("this should not happen"); break; } @@ -139,7 +149,7 @@ class Interpreter implements ByteCodes, Tokens { } } throw new Error("CONTINUE/BREAK invoked but couldn't find LoopMarker at " + - JS.getSourceName() + ":" + JS.getLine()); + getSourceName() + ":" + getLine()); case TRY: { int[] jmps = (int[]) arg;