Minor correction, due to bad testing on my part: "Using an older JVM with Conext.VERSION_1_2 also fixed null != undefined. Not Good."
... is false. This is purely a language version issue. On Mon, Dec 14, 2009 at 1:23 PM, Mark Storer <[email protected]> wrote: > In the following code, I generate a new context, new scope, and evaluate > some script, which results in Something Bad: > > public boolean createContext( boolean bAllowJavaImports, boolean > bDynamicScope ) // false and false > { > m_context = Context.enter(); > m_context.setErrorReporter( new ErrorHandler() ); > > resetScope( bAllowJavaImports /*false*/); // m_scope = > m_context.initStandardObjects( null ); > > m_context.setLanguageVersion( Context.VERSION_1_2 ); > m_context.setGeneratingDebug( true ); // true or false, same results > > DEBUG_STUFF(); > } > return hasContext() && m_scope != null; > } > > String testScript = "var foo; var msg = (null == foo); throw new Error( > msg, msg )"; > > private void DEBUG_STUFF() { > // evaluate() will catch and log the exception for us. > evaluate( testScript, "test script", 1 ); > } > > public boolean evaluate( java.io.Reader in, java.lang.String name, int > lineno ) throws IOException > { > boolean ret = false; > try { > m_result = m_context.evaluateReader( m_scope, in, name, lineno, null > ); > ret = true; > } catch (JavaScriptException e) { > /* blah */ > } catch (EcmaError e) { > /* blah */ > } > return ret; > } > > The above code results in the following exception log ("false" is the > important part): > > com.cardiff.js.EcmaException: Error: false (test script#1) > at com.cardiff.js.ErrorHandler.error(ErrorHandler.java:52) > at org.mozilla.javascript.Context.reportError(Context.java:897) > at com.cardiff.js.Interpreter.evaluate(Interpreter.java:354) > at com.cardiff.js.Interpreter.evaluate(Interpreter.java:378) > at com.cardiff.js.Interpreter.DEBUG_STUFF(Interpreter.java:97) > at com.cardiff.js.Interpreter.createContext(Interpreter.java:88) > ... > > This is under JRE 1.6.0_17 > > What the heck is going on here? > > Eureka! > > It turns out that setLanguageVersion() was the culprit, though there may be > some interaction with the new embedded JS engine from sun. > setlanguageVersion(Context.VERSION_1_5) remedied the problem. > > Using an older JVM with Conext.VERSION_1_2 also fixed null != undefined. > Not Good. > > -- > --Mark Storer > Professional Geek > -- --Mark Storer Professional Geek _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
