Closed jdalton closed 13 years ago
This is an interesting one. Input streams in Ringo have an iterator()/__iterator__()
method that iterates over the stream's input as described in CommonJS IO/A. So what that loop does is basically wait for input from stdin (you can try it by typing on the keyboard and hitting return).
Not sure what to think about this. It definitely doesn't obey to the principle of least astonishment. However it's not a bug, so closing.
FWIW I didn't run into this issue in v0.7.0.
Not sure how the behavior of for...in relates to an iterator()
method.
That's a JavaScript 1.7 extension. If you define a method called __iterator__()
it will be called to iterate the object's properties.
(Sorry, underscores in my previous comment were not escaped and thus interpreted as Markdown)
Ok that's for __iterator__()
the CommonJS IO/A proposal doesn't seem to mention that, I only see iterator()
.
The other project currently supporting the IO proposal, Common-Node, allows iterating over the system.stdin
object via for...in
without problems (because it lacks support for the non-standard __iterator__()
method).
I don't see how it's acceptable to break the language or dev expectations by pointing to non-standard functionality and proposed/draft spec by a non-formal standards body.
You're completely right about the breaking dev expectations part. I was myself baffled when I first read your report.
I was going to respond that iteration hooks are planned for Harmony and that you're going to get used to things like that, but I see that the Harmony proposal uses a new for-of
syntax for exactly those reasons.
The intention of the CommonJS proposal obviously was to make text streams iterate over input lines, but it doesn't say so explicitly, and the means to make it work are not available anywhere else than JS 1.7.
I think we went a bit too far here. I'll try to remove the for-in behavrior while keeping everything else working.
@hns Thanks!
To avoid this issue in current versions of RingoJS I detect support for iteratorsand then wrap objects with custom __iterator__
methods as Iterator(object)
to avoid problems.
Doing this..
print('done');
is never called