On Jan 8, 8:32 am, Ingmar <[EMAIL PROTECTED]> wrote:
> I tried to evaluate an E4X expression at a child scope:
>
> import org.mozilla.javascript.*;
>
> public class EvaluateXML
> {
> public static void main(String[] args)
> {
> Context cx = Context.enter();
> try {
> ScriptableObject rootscope = cx.initStandardObjects();
> ScriptableObject scope = cx.initStandardObjects();
> scope.setParentScope(rootscope);
>
> //cx.evaluateString(rootscope, "var myxml=<a/>", "",
> 1, null); //
> works
> cx.evaluateString(scope, "var myxml=<a/>", "", 1,
> null); //does not
> work
> System.out.println("done");
> } catch(Exception e) {
> e.printStackTrace();
> } finally {
> Context.exit();
> }
> System.exit(0);
> }
>
> }
>
> and get an exception:
>
> java.lang.IllegalStateException: XML
> at
> org.mozilla.javascript.LazilyLoadedCtor.getValue(LazilyLoadedCtor.java:
> 101)
> at
> org.mozilla.javascript.ScriptableObject.getImpl(ScriptableObject.java:
> 1963)
> at org.mozilla.javascript.ScriptableObject.get(ScriptableObject.java:
> 280)
> at
> org.mozilla.javascript.IdScriptableObject.get(IdScriptableObject.java:
> 385)
> at
> org.mozilla.javascript.LazilyLoadedCtor.buildValue(LazilyLoadedCtor.java:
> 115)
> at org.mozilla.javascript.LazilyLoadedCtor.init(LazilyLoadedCtor.java:
> 89)
> at
> org.mozilla.javascript.ScriptableObject.getImpl(ScriptableObject.java:
> 1961)
> at org.mozilla.javascript.ScriptableObject.get(ScriptableObject.java:
> 280)
> at
> org.mozilla.javascript.IdScriptableObject.get(IdScriptableObject.java:
> 385)
> at
> org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:
> 1544)
> at
> org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:
> 1666)
> at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1617)
> at org.mozilla.javascript.gen.c1._c0(:1)
> at org.mozilla.javascript.gen.c1.call()
> at
> org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:
> 393)
> at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:
> 2834)
> at org.mozilla.javascript.gen.c1.call()
> at org.mozilla.javascript.gen.c1.exec()
> at org.mozilla.javascript.Context.evaluateString(Context.java:1196)
> at EvaluateXML.main(EvaluateXML.java:14)
>
> Should it be possible to evaluate E4X expressions in child scopes?
> What's wrong here?
>
> BTW: I'm using Rhino 1.6R7
>
> Thanks,
> Ingmar.
The problem is that you call initStandardObjects twice and connect
those scopes. initStandardObjects adds all the standard constructors,
etc., to the scope, so your scope chain has *two* copies of these
standard objects, including the "XML" constructor. Try removing the
second initStandardObjects and just create a plain JavaScript object
by calling cx.newObject instead.
--Norris
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino