<div dir="ltr">This is amazing. Thank you so much for this.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 23, 2018 at 3:20 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">As of bug 1484496, any C++-implemented nsISimpleEnumertor instance can be used <br>
as a JS iterator. And, when used this way, the iterators now have intrinsic <br>
type information, and therefore do not require QIing 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, you <br>
unfortunately still need to specify the expected types, since nsIArray has no <br>
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 somewhat <br>
faster than the old protocol, since they only require one XPConnect call per <br>
iteration rather than 3(+).<br>
<br>
-Kris<br>
_______________________________________________<br>
firefox-dev mailing list<br>
<a href="mailto:firefox-dev@mozilla.org" target="_blank">firefox-dev@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/firefox-dev" rel="noreferrer" target="_blank">https://mail.mozilla.org/listinfo/firefox-dev</a><br>
</blockquote></div>