Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with __iterator__

23 views
Skip to first unread message

Ionut G. Stan

unread,
May 21, 2009, 10:03:43 AM5/21/09
to
Hi,

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

Norris Boyd

unread,
May 21, 2009, 4:34:24 PM5/21/09
to

Yes, this is a bug. I've just committed a fix to CVS:
ScriptRuntime.java version 1.312.

--N

Ionut G. Stan

unread,
May 22, 2009, 3:38:13 PM5/22/09
to
> 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.

Daniel Friesen

unread,
Jul 22, 2009, 3:33:46 AM7/22/09
to

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]

Norris Boyd

unread,
Jul 29, 2009, 3:26:20 PM7/29/09
to

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

Daniel Friesen

unread,
Jul 31, 2009, 3:47:38 AM7/31/09
to
CVS Head is broken right now. I'll try again sometime later and hope the
json errors are gone.
I've got no clue how to use cvs to find an earlier working version and
really don't feel like learning an archaic vcs system.

--
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

Daniel Friesen

unread,
Aug 1, 2009, 5:17:11 PM8/1/09
to
Updated (the issue with Rhino being broken was actually the cvs command
I was using wasn't checking out the new json directory)
$ ant jar
$ java -jar build/rhino1_7R3pre/js.jar -version 170
Rhino 1.7 release 1 2008 11 26
js> var foo = { __iterator__ : function(onlyKeys) { print(onlyKeys);
yield 0; } };
js> for ( let f in foo ) {}
true
js> for each ( let f in foo ) {}
true
js>

Ionut G. Stan

unread,
Aug 2, 2009, 9:19:43 AM8/2/09
to
On Aug 2, 12:17 am, Daniel Friesen <dan...@nadir-seen-fire.com> wrote:
> Updated (the issue with Rhino being broken was actually the cvs command
> I was using wasn't checking out the new json directory)
> $ ant jar
> $ java -jar build/rhino1_7R3pre/js.jar -version 170
> Rhino 1.7 release 1 2008 11 26
> js> var foo = { __iterator__ : function(onlyKeys) { print(onlyKeys);
> yield 0; } };
> js> for ( let f in foo ) {}
> true
> js> for each ( let f in foo ) {}
> true
> js>

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.

Daniel Friesen

unread,
Aug 2, 2009, 7:32:31 PM8/2/09
to

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.

Hannes Wallnoefer

unread,
Aug 5, 2009, 7:02:25 AM8/5/09
to
On Aug 3, 1:32 am, Daniel Friesen <dan...@nadir-seen-fire.com> wrote:
>
> > 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:anonym...@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

Daniel Friesen

unread,
Aug 5, 2009, 12:49:06 PM8/5/09
to
Option two works... That one looks the best, I'll be sure to use that
form of starting up MonkeyScript so that others don't get bitten by the bug.
0 new messages