Hello,

I made the move from Rhino 1.6R2 to 1.7R2 - quite late, I know, but I had no 
reason to update js.jar - it just worked well :-)

I've got an issue with existing scripts.
AFAIK, in JavaScript, the last statement of a script is it's return value. But 
what happens, if you put definitions of functions in a script AFTER the last 
statement?
I think this is valid JavaScript, or am I wrong here?

Such scripts run well - but not if Context.setOptimizationLevel(-1) is used - 
I'm using this for some reason, but I'll check if I can change this - so 
there's a work around for me.

To demonstrate the problem, this is a little script which can be executed like 
this   java -jar js.jar   the_script.js


// simple script, (but) with a function a the end
script="3+2;\nfunction foo() {}"

// works well, returns 3+2=5
cx = Packages.org.mozilla.javascript.Context.currentContext
o = cx.evaluateString(this, script, null, 0, null)
java.lang.System.out.println(o)

// setOptimizationLevel(-1), we don't want compiled code, for some reason
// worked well with Rhino 1.6R2 - but 1.7R2 returns the function, not 5
cx = Packages.org.mozilla.javascript.Context.currentContext
cx.setOptimizationLevel(-1)
o = cx.evaluateString(this, script, null, 0, null)
java.lang.System.out.println(o)

// reason is the optimization level ...
cx = Packages.org.mozilla.javascript.Context.currentContext
cx.setOptimizationLevel(0)
o = cx.evaluateString(this, script, null, 0, null)
java.lang.System.out.println(o)

The output is
5
org.mozilla.javascript.interpretedfunct...@1dfafd1
5

I think it should be
5
5
5

:-)

With Rhino 1.6R2, the output is
5
5.0
5

This is okay ;-)

What do you think? Anyone else had such a problem? Is it INCORRECT to place 
function definitions at the end of the script, I mean, after the last statement?

Thank you
   Merten


_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to