Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #839 Iterable Java Object #846

Merged
merged 4 commits into from
Apr 3, 2021
Merged

fix #839 Iterable Java Object #846

merged 4 commits into from
Apr 3, 2021

Conversation

tuchida
Copy link
Contributor

@tuchida tuchida commented Mar 20, 2021

Closes #839
Implemented Symbol.iterator in java.lang.Iterable and java.util.Map.
java.util.Iterator is equivalent to the Iterator object in ECMAScript because it has state, so we did not implement Symbol.iterator.
java.util.Map can iterate over keys and values just like ECMAScript's Map. Nashorn works the same way.

@gbrail
Copy link
Collaborator

gbrail commented Mar 26, 2021

It seems like this is useful. Is it possible to update the commit message or this PR with a short sample of what is possible now that wasn't possible before so that we can put something in the release notes?

Also, how do we ensure that some existing code won't break now that iteration is easier on many types of Java objects?

@tuchida
Copy link
Contributor Author

tuchida commented Mar 26, 2021

It seems like this is useful. Is it possible to update the commit message or this PR with a short sample of what is possible now that wasn't possible before so that we can put something in the release notes?

Can I write the release notes here?
https://github.com/mozilla/rhino/blob/master/RELEASE-NOTES.md

Also, how do we ensure that some existing code won't break now that iteration is easier on many types of Java objects?

Since Symbol.iterator is a Symbol, it does not override Java methods.
Up until now, it was not iterable, which caused a TypeError.

var l = new java.util.ArrayList([1, 2, 3]);
for (var v of l) print(v);
// js: uncaught JavaScript runtime exception: TypeError: [1.0, 2, 3] is not iterable

I don't think there are any side effects from this becoming iterable.

@gbrail
Copy link
Collaborator

gbrail commented Apr 3, 2021

Thanks -- you have given me enough to put in the release notes when it's time. I might ask for help with the PR at that time if it's not obvious. It's cool that we're starting to use lambdas to cut down on code clutter too!

@gbrail gbrail merged commit 52133fc into mozilla:master Apr 3, 2021
@tuchida tuchida mentioned this pull request Apr 4, 2021
@tuchida tuchida deleted the 839/iterable-javaoject branch May 27, 2021 08:14
@tonygermano
Copy link
Contributor

@p-bakker Can this get added to the 1.7.14 milestone and properly linked to 839?

@p-bakker p-bakker added this to the Release 1.7.14 milestone Oct 20, 2021
@p-bakker
Copy link
Collaborator

p-bakker commented Oct 20, 2021

I've linked the PR to the issue. As the issue is already linked to the milestone, i haven't linked the PR, because otherwise both the issue and the PR show up in the milestone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Iterable Java Object
4 participants