On May 15, 2009, at 1:47 PM, Waldemar Horwat wrote:
Did you actually test this? Firefox 2 and up work the same.
js> g = gen()
[object Generator]
js> g.next()
1
js> g.next()
2
js> g.next()
typein:6: ReferenceError: alert is not defined
js> alert=print
function print() {
[native code]
}
js> g = gen(42)
[object Generator]
js> g.next()
1
js> g.next()
2
js> g.next()
Finally called up to three times?!
uncaught exception: [object StopIteration]
Exactly one finally.
That behavior is wrong in the case that g gets forgotten after
calling next just once.
Progress! You're not alleging longjmps or multiple finallys ;-).
You're silently exiting through a finally clause without calling it.
You must mean where I hit that ReferenceError due to alert not being
defined, then reassigned to g without closing it or calling g.next()
and hitting the StopIteration.
(I //totally// so meant to do that in order to provoke this
discussion. :-P)
The alternative, which we prototyped and rejected, but which CPython
implements, is to automate calling the generator's close method from
the garbage collector (close "throws a return" at the generator,
causing finallys to run). But this is a burden on either or both of
content authors and implementators, since it makes finally execution
unpredictably tardy, requires certain kinds of GC, exposes two-phase
finalization, etc.
In browsers, automating close from the GC opens up trivial denial of
service attacks that could prevent pages from being unloaded, which
browsers can and must defeat in ways that again mean "finally does not
always run."
The fact is, in browsers at least, finally does not always run --
ignoring generators. There are good DOS-prevention reasons for
skipping it.
If you want automated close calling in the absence of DOS suppression,
use for-in. This was suggested by Chris Hansen here:
https://mail.mozilla.org/pipermail/es-discuss/2007-January/003743.html
That whole "Immediate closing of iterators" thread is worth a read if
you missed it.
/be
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss