Re: Feel free to use Iterator() in privileged JS (was: Re: Help with removing __iterator__ from JS)

2015-07-28 Thread Tom Schuster
Please remember that the ES6 iteration protocol can only be used with
for-of.
On Jul 28, 2015 1:20 PM, "Paolo Amadini"  wrote:

> On 7/23/2015 4:16 PM, Boris Zbarsky wrote:
>
>> I might be missing something, but why is __iterator__ and the
>> nonstandard iteration protocol needed for this?
>>
>
> It's not.
>
>  I don't think anyone on the SpiderMonkey end particularly cares whether
>> Iterator or some replacement is used.
>>
>
> Thanks a lot for the clarification. I was in fact replying to Tom's
> aside of "Please also try avoid using Iterator" but it's clear that
> there are use cases for it and we should use it where it makes sense.
>
> Iterator() can even be implemented easily internally using the ES6
> iterator protocol.
>
> Cheers,
> Paolo
> ___
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Feel free to use Iterator() in privileged JS (was: Re: Help with removing __iterator__ from JS)

2015-07-28 Thread Paolo Amadini

On 7/23/2015 4:16 PM, Boris Zbarsky wrote:

I might be missing something, but why is __iterator__ and the
nonstandard iteration protocol needed for this?


It's not.


I don't think anyone on the SpiderMonkey end particularly cares whether
Iterator or some replacement is used.


Thanks a lot for the clarification. I was in fact replying to Tom's
aside of "Please also try avoid using Iterator" but it's clear that
there are use cases for it and we should use it where it makes sense.

Iterator() can even be implemented easily internally using the ES6
iterator protocol.

Cheers,
Paolo
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Help with removing __iterator__ from JS

2015-07-23 Thread Boris Zbarsky

On 7/23/15 7:29 AM, Paolo Amadini wrote:

Well, I was thinking more of something built-in, other than Iterator,
to achieve the same effect over a data structure (for example something
that could be provided from elsewhere as an argument).


Paolo,

I might be missing something, but why is __iterator__ and the 
nonstandard iteration protocol needed for this?



But apparently I'm stuck with iterating over keys and reading values 
separately, or
implementing my version of Iterator (at which point I don't see why
I shouldn't simply use Iterator in privileged code


I don't think anyone on the SpiderMonkey end particularly cares whether 
Iterator or some replacement is used.  What the SpiderMonkey team cares 
about is that the old iteration protocol not be used.  Does that make 
sense?  And the reason they would like it to not be used is that it's 
not compatible with the ES6 protocol to such an extent that we can't fix 
some of our spec-compliance bugs without removing it.  As in, there are 
some places in the code where SpiderMonkey ends up having to guess which 
iteration protocol is being used, and it can't always guess correctly...


-Boris
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Help with removing __iterator__ from JS

2015-07-23 Thread Paolo Amadini

On 7/22/2015 1:56 PM, David Bruant wrote:

The ES6 iterator protocol is what you're looking for. See:
Alongside with the computed property syntax, you should be able to
achieve what you want. Something along the lines of:


Well, I was thinking more of something built-in, other than Iterator,
to achieve the same effect over a data structure (for example something
that could be provided from elsewhere as an argument). But apparently
I'm stuck with iterating over keys and reading values separately, or
implementing my version of Iterator (at which point I don't see why
I shouldn't simply use Iterator in privileged code, rather than
implementing MyIterator() everywhere locally or in a MyIterator.jsm).

Cheers,
Paolo
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Help with removing __iterator__ from JS

2015-07-22 Thread David Bruant

Hi Paolo,

The ES6 iterator protocol is what you're looking for. See:
* 
https://hacks.mozilla.org/2015/04/es6-in-depth-iterators-and-the-for-of-loop/
* 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator


Alongside with the computed property syntax, you should be able to 
achieve what you want. Something along the lines of:


function makeIterableEventList(el){
el[Symbol.iterator] = function(){ /* define iterator here*/ }
return el;
}

  events: {
[Symbol.iterator]: function(){ /* define iterator here*/ }
mainview: makeIterableEventList({
  focus(event) {},
}),
filter: makeIterableEventList({
  input(event) {},
}),
  },

  this.boundEventHandlers = [
for ([elementName, events] of this.events)
for ([eventName, handler] of events)
[elementName, eventName, handler.bind(this)]
  ];
---

It should work in Firefox today (at least the Symbol.iterator and 
computed object prop parts. Not 100% sure about the array comprehension 
as I haven't tested)


David

Le 22/07/2015 14:42, Paolo Amadini a écrit :

On 7/21/2015 12:07 PM, Tom Schuster wrote:

Aside: Please also try avoid using Iterator().


What would be the alternative to Iterator() when I need to iterate and
easily assign both keys and values of an object to local variables?

See for example :

  this.boundEventHandlers = [
for ([elementName, events] of Iterator(this.events))
for ([eventName, handler] of Iterator(events))
[elementName, eventName, handler.bind(this)]
  ];

There's more context on the bug for the specific example (the bug is
about supporting destructuring in comprehensions in the first place)
but my concern in general is that I've failed to find an alternative
to Iterator() that is as expressive.

Cheers,
Paolo
___
firefox-dev mailing list
firefox-...@mozilla.org
https://mail.mozilla.org/listinfo/firefox-dev


___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Help with removing __iterator__ from JS

2015-07-22 Thread Paolo Amadini

On 7/21/2015 12:07 PM, Tom Schuster wrote:

Aside: Please also try avoid using Iterator().


What would be the alternative to Iterator() when I need to iterate and
easily assign both keys and values of an object to local variables?

See for example :

  this.boundEventHandlers = [
for ([elementName, events] of Iterator(this.events))
for ([eventName, handler] of Iterator(events))
[elementName, eventName, handler.bind(this)]
  ];

There's more context on the bug for the specific example (the bug is
about supporting destructuring in comprehensions in the first place)
but my concern in general is that I've failed to find an alternative
to Iterator() that is as expressive.

Cheers,
Paolo
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Help with removing __iterator__ from JS

2015-07-21 Thread David Rajchenbach-Teller
If I recall correctly, the difficulty with the OS.File removal is that
some clients of this code were taking advantage of the old API in ways
that do not match the new one. I will try and take another look at it
over the summer.

Cheers,
 David

On 21/07/15 13:07, Tom Schuster wrote:
> Hello!
> 
> We have an old JS extension that allows objects to modify how they
> behave when used with for-in. However this extension will never make it
> into ES6 and is actually incompatible with how iteration is defined
> there. So please don't use __iterator__anymore.
> 
> I would really appreciate your help with removing __iterator__ from the
> OS.File interface, which makes very heavy use of this feature. Bug
> 938704 hasn't seen any serious work since 2013.
> 
> We also need to look into the addon-sdk, where many of the custom
> collection types implement __iterator__ and thus addon authors might
> iterate over them with for-in ...
> 
> Aside: Please also try avoid using Iterator().
> 
> Thank you,
> Tom
> 
> 
> ___
> firefox-dev mailing list
> firefox-...@mozilla.org
> https://mail.mozilla.org/listinfo/firefox-dev
> 


-- 
David Rajchenbach-Teller, PhD
 Performance Team, Mozilla



signature.asc
Description: OpenPGP digital signature
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Help with removing __iterator__ from JS

2015-07-21 Thread Tom Schuster
Hello!

We have an old JS extension that allows objects to modify how they behave
when used with for-in. However this extension will never make it into ES6
and is actually incompatible with how iteration is defined there. So please
don't use __iterator__anymore.

I would really appreciate your help with removing __iterator__ from the
OS.File interface, which makes very heavy use of this feature. Bug 938704
hasn't seen any serious work since 2013.

We also need to look into the addon-sdk, where many of the custom
collection types implement __iterator__ and thus addon authors might
iterate over them with for-in ...

Aside: Please also try avoid using Iterator().

Thank you,
Tom
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform