X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTemplate.java;h=a9ea9b91502a90352a6c92d33b17de5d7435181e;hb=e58686eae8a823ed64ed0ec92c2274c41d90ec93;hp=22c994c2f78586a6640dd2f515392ece4e8acb5c;hpb=bc0d2f2d898adb7b0e207ac4d9ddfde1b408230a;p=org.ibex.core.git diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 22c994c..a9ea9b9 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -5,7 +5,7 @@ import java.io.*; import java.util.zip.*; import java.util.*; import java.lang.*; -import org.mozilla.javascript.*; +import org.xwt.js.*; import org.xwt.util.*; /** @@ -73,10 +73,10 @@ public class Template { private boolean changed = false; /** the script on the static node of this template, null if it has already been executed */ - private Script staticscript = null; + private JS.Script staticscript = null; /** the script on this node */ - private Script script = null; + private JS.Script script = null; /** during XML parsing, this holds the list of currently-parsed children; null otherwise */ private Vec childvect = new Vec(); @@ -165,7 +165,7 @@ public class Template { * @param pboxes a vector of all box parents on which to put $-references * @param ptemplates a vector of the nodeNames to recieve private references on the pboxes */ - void apply(Box b, Vec pboxes, Vec ptemplates, Function callback, int numerator, int denominator) { + void apply(Box b, Vec pboxes, Vec ptemplates, JS.Function callback, int numerator, int denominator) { int original_numerator = numerator; @@ -178,7 +178,7 @@ public class Template { for(int i=0; ichange as needed */ @@ -368,20 +363,25 @@ public class Template { private void link(boolean force) { if (staticscript != null) try { - Scriptable s = Static.createStatic(nodeName, false); + JS.Scope s = Static.createStatic(nodeName, false); if (staticscript != null) { - Script temp = staticscript; - ((InterpretedScript)temp).setParentScope(s); // so we know how to handle Static.get("xwt") + JS.Script temp = staticscript; staticscript = null; - temp.exec(Context.enter(), s); + + // we layer a transparent scope over the Static so that we can catch requests for the xwt object + // yet not screw up paths that include a package called xwt (ie xwt.static.org.xwt.foo) + JS.Scope varScope = new JS.Scope(s) { + public boolean isTransparent() { return true; } + public Object get(Object key) { + if ("xwt".equals(key)) return XWT.singleton; else return super.get(key); + } }; + + JS.Array args = new JS.Array(); + args.addElement(varScope); + temp.call(args); } - } catch (EcmaError e) { - if (Log.on) Log.log(this, "WARNING: uncaught interpreter exception: " + e.getMessage()); - if (Log.on) Log.log(this, " thrown while executing block for " + nodeName + - " at " + e.getSourceName() + ":" + e.getLineNumber()); - } catch (JavaScriptException e) { + } catch (JS.Exn e) { if (Log.on) Log.log(this, "WARNING: uncaught ecmascript exception: " + e.getMessage()); - if (Log.on) Log.log(this, " thrown while executing block for " + nodeName + " at " + e.sourceFile + ":" + e.line); } if (!(force || (preapply != null && _preapply == null) || (postapply != null && _postapply == null))) return; @@ -654,17 +654,11 @@ public class Template { } } - private Script genscript(boolean isstatic) { - Script thisscript = null; - Context cx = Context.enter(); - cx.setOptimizationLevel(-1); - + private JS.Script genscript(boolean isstatic) { + JS.Script thisscript = null; try { - thisscript = cx.compileReader(null, new StringReader(t.content.toString()), t.nodeName + (isstatic ? "._" : ""), t.content_start, null); - } catch (EcmaError ee) { - if (Log.on) Log.log(this, ee.getMessage() + " at " + ee.getSourceName() + ":" + ee.getLineNumber()); - thisscript = null; - } catch (EvaluatorException ee) { + thisscript = JS.Script.parse(new StringReader(t.content.toString()), t.nodeName + (isstatic ? "._" : ""), t.content_start); + } catch (JS.Exn ee) { if (Log.on) Log.log(this, " ERROR: " + ee.getMessage()); thisscript = null; } catch (IOException ioe) {