generators inside DOM events

Brendan Eich brendan at mozilla.com
Fri Jan 10 17:35:50 PST 2014


'yield' in an HTML event attribute value should be a free variable 
reference, since the attribute value is taken as the source of a 
function body, not of a function* body.

/be

> Andrea Giammarchi <mailto:andrea.giammarchi at gmail.com>
> January 8, 2014 1:21 PM
> sorry, actually the right example was with `while (true) yield evt;` 
> but that's the same of async callback, the event is gone.
>
> Well, everything good then ^_^
>
> Thanks again
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> Andrea Giammarchi <mailto:andrea.giammarchi at gmail.com>
> January 8, 2014 1:19 PM
> OK, I have overlooked at this ... so the following code won't have any 
> side effect, correct?
>
> ```javascript
> addEventListener('beforeunload', function (e) {
>   (function*() {
>     while (true) yield null;
>   }());
> });
> ```
>
> Thanks
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> Brandon Benvie <mailto:bbenvie at mozilla.com>
> January 8, 2014 1:12 PM
>
>
> Calling a generator function just creates a paused generator. 
> Generators can't pause callers, just themselves (via yield).
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
> Andrea Giammarchi <mailto:andrea.giammarchi at gmail.com>
> January 8, 2014 1:05 PM
> Sorry, I explained it badly ... let me try again:
>
> what if a DOM event handler uses/creates/invokes inside its function 
> body a generator?
>
> Will the event pause until this will be satisfied?
>
> `a.addEventListener('click', function(e){ 
> if(methodThatInvokesGenerator()) e.stopPropagation(); });`
>
> Is this a concern?
>
> Thanks
>
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> Domenic Denicola <mailto:domenic at domenicdenicola.com>
> January 8, 2014 12:53 PM
> What? That would just cause the event handler function to return a 
> generator object, which the browser would not use or do anything with. 
> It would have no effect.
>
>
> ------------------------------------------------------------------------
> *From:* es-discuss <es-discuss-bounces at mozilla.org> on behalf of 
> Andrea Giammarchi <andrea.giammarchi at gmail.com>
> *Sent:* Wednesday, January 08, 2014 15:50
> *To:* es-discuss at mozilla.org
> *Subject:* generators inside DOM events
> I am not sure this has been discussed already but I wonder what would 
> happen if `yield` is used inside an event such 'beforeunload', 
> 'unload', or even 'click' and others DOM related events.
>
> Main concerns:
>
>  1. it's a UA trap potentially making impossible to leave a page or
>     complete a user meant action
>  2. not even transpilers can solve cases like this (i.e. a still valid
>     event eventually stopped after some generator logic where if
>     simulated the event would be expired at the time the function will
>     be invoked) 
>
> Thanks
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list