<div dir="auto">Wow, this is a great improvement! Thank you!</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 23, 2018, 6:26 PM Kris Maglione <<a href="mailto:kmaglione@mozilla.com">kmaglione@mozilla.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Oh, and from C++, there's also now a range iterator wrapper with <br>
similar semantics:<br>
<br>
for (auto& docShell : SimpleEnumerator<nsIDocShell>(docShellEnum)) {<br>
...<br>
}<br>
<br>
On Thu, Aug 23, 2018 at 03:19:55PM -0700, Kris Maglione wrote:<br>
>As of bug 1484496, any C++-implemented nsISimpleEnumertor instance can <br>
>be used as a JS iterator. And, when used this way, the iterators now <br>
>have intrinsic type information, and therefore do not require QIing <br>
>their elements.<br>
><br>
>Which is to say, now you can simply do:<br>
><br>
> for (let window of Services.wm.getEnumerator("navigator:browser")) {<br>
> ...;<br>
> }<br>
><br>
> for (let docShell of docShellEnum) {<br>
> ...;<br>
> }<br>
><br>
>rather than:<br>
><br>
> let winEnum = Services.wm.getEnumerator("navigator:browser");<br>
> while (winEnum.hasMoreElements()) {<br>
> let window = winEnum.getNext();<br>
> ...<br>
> }<br>
><br>
> while (docShellEnum.hasMoreElements()) {<br>
> let docShell = winEnum.getNext().QueryInterface(Ci.nsIDocShell);<br>
> ...<br>
> }<br>
><br>
>If you happen to be using an nsIArray from directly from JavaScript, <br>
>you unfortunately still need to specify the expected types, since <br>
>nsIArray has no idea what types it can contain:<br>
><br>
> for (let thing of array.enumerate(Ci.nsIThing)) {<br>
> ...<br>
> }<br>
><br>
>Aside from being easier to maintain, these forms should also be <br>
>somewhat faster than the old protocol, since they only require one <br>
>XPConnect call per iteration rather than 3(+).<br>
><br>
>-Kris<br>
<br>
-- <br>
Kris Maglione<br>
Senior Firefox Add-ons Engineer<br>
Mozilla Corporation<br>
<br>
There is no greater mistake than the hasty conclusion that opinions<br>
are worthless because they are badly argued.<br>
--Thomas Huxley<br>
<br>
_______________________________________________<br>
dev-platform mailing list<br>
<a href="mailto:dev-platform@lists.mozilla.org" target="_blank" rel="noreferrer">dev-platform@lists.mozilla.org</a><br>
<a href="https://lists.mozilla.org/listinfo/dev-platform" rel="noreferrer noreferrer" target="_blank">https://lists.mozilla.org/listinfo/dev-platform</a><br>
</blockquote></div>