I'm trying to implement a custom iterator and want to return different
values depending on the method of iteration (for..in or for each..in).
The problem is that my __iterator__ function receives the "onlyKeys"
parameter as being always true regardless of the for loop used.
So in Rhino 1.7 release 2 2009 03 22 on Windoes XP SP3 with Java
1.6.0_13, I have this test case:
var foo = {
__iterator__ : function(onlyKeys) {
print(keys);
yield [0, "a"];
}
};
for each (let f in foo) {}
for (let f in foo) {}
The above will print true for both cases whereas the following (tested
in Firefox 3.0.10) works as expected.
<script type="application/javascript;version=1.7">
var foo = {
__iterator__ : function(onlyKeys) {
alert(keys);
yield [0, "a"];
}
};
for (let f in foo) {}
for each (let f in foo) {}
</script>
Am I doing something wrong or is it a (known) bug? Hopefully, I'm
doing something wrong.
Cheers
Yes, this is a bug. I've just committed a fix to CVS:
ScriptRuntime.java version 1.312.
--N
Thanks so much for your prompt response and commit Norris. And thanks
for making this project come true.
This fix does not appear to be working. I found out that my array
__iterator__ was broken in Rhino while working on MonkeyScript. I
checked out cvs and testing my code and this code still fails. onlyKeys
is always true even when using for each.
--
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
Sorry the fix didn't work for you. Can you post a shell session that
shows the failure, or even better open a bug?
--N
There's something wrong in your process. I've just updated from CVS,
executed your commands and worked flawlessly. There's one thing that
bothers me. Why the first line outputted by Rhino is: "Rhino 1.7
release 1 2008 11 26"? It should have outputted the date when you
built the sources, which I assume was not November 26th, 2008.
cvs -d :pserver:anon...@cvs-mirror.mozilla.org:/cvsroot update -d -R
./mozilla/js/rhino/
This is the command I'm using for updating from cvs.
I set my JAVA_HOME with
export JAVA_HOME=/usr/lib/jvm/java-6-sun
Run:
ant jar
And to start up the jar built:
java -jar build/rhino1_7R3pre/js.jar -version 170
It feels a little strange myself as well. I see JSON and JS 1.8 code
inside the source code I have, but -version 180 gives me an error.
I'm pretty sure you're being bitten by the OpenJDK Rhino-on-the-
bootclasspath bug.
https://bugs.launchpad.net/ubuntu/+source/openjdk-6/+bug/255149
In a nutshell, OpenJDK uses the unmodified Rhino package to implement
the JS javax.script.ScriptEngine in a way that makes it impossible to
use your own version of Rhino.
You have the following options to work around this bug:
1. Make the Sun Java packages your default using "sudo update-java-
alternatives -s java-6-sun". Setting the JAVA_HOME environment
variable won't do the trick!
2. Start java with the -Xbootclasspath/p:"/path/to/js.jar" to put your
own Rhino on the boot classpath.
3. Remove the symlink named rhino.jar in /usr/lib/jvm/java-6-openjdk/
jre/lib. (This will probably break the javax.script Rhino engine.)
This is really an annoying issue. One way to fix it would be to bundle
the ScriptingEngine implementation with rhino as I proposed in bug
379385 and then get OpenJDK to use that.
https://bugzilla.mozilla.org/show_bug.cgi?id=379385
Hannes