This is great, we should go and see if we can simplify the code, maybe there is an automatic script to clean up as well!
Philipp
Begin forwarded message:
From: Kris Maglione kmaglione@mozilla.com
Date: 24. August 2018 at 12:19:55 AM CEST
To: Firefox Dev firefox-dev@mozilla.org
Subject: PSA: nsISimpleEnumerator now works as a JS iterator
As of bug 1484496, any C++-implemented nsISimpleEnumertor instance can be used as a JS iterator. And, when used this way, the iterators now have intrinsic type information, and therefore do not require QIing their elements.
Which is to say, now you can simply do:
for (let window of Services.wm.getEnumerator("navigator:browser")) {
...;
}
for (let docShell of docShellEnum) {
...;
}
rather than:
let winEnum = Services.wm.getEnumerator("navigator:browser");
while (winEnum.hasMoreElements()) {
let window = winEnum.getNext();
...
}
while (docShellEnum.hasMoreElements()) {
let docShell = winEnum.getNext().QueryInterface(Ci.nsIDocShell);
...
}
If you happen to be using an nsIArray from directly from JavaScript, you unfortunately still need to specify the expected types, since nsIArray has no idea what types it can contain:
for (let thing of array.enumerate(Ci.nsIThing)) {
...
}
Aside from being easier to maintain, these forms should also be somewhat faster than the old protocol, since they only require one XPConnect call per iteration rather than 3(+).
-Kris
firefox-dev mailing list
firefox-dev@mozilla.org
https://mail.mozilla.org/listinfo/firefox-dev
… and much rejoicing was heard in the land of the javascript coders …
On 24/08/18 22:11, Philipp Kewisch wrote:
This is great, we should go and see if we can simplify the code, maybe
there is an automatic script to clean up as well!
Philipp
Begin forwarded message:
From: Kris Maglione <kmaglione@mozilla.com
mailto:kmaglione@mozilla.com>
Date: 24. August 2018 at 12:19:55 AM CEST
To: Firefox Dev <firefox-dev@mozilla.org
mailto:firefox-dev@mozilla.org>
Subject: PSA: nsISimpleEnumerator now works as a JS iterator
As of bug 1484496, any C++-implemented nsISimpleEnumertor instance
can be used as a JS iterator. And, when used this way, the iterators
now have intrinsic type information, and therefore do not require
QIing their elements.
Which is to say, now you can simply do:
for (let window of Services.wm.getEnumerator("navigator:browser")) {
...;
}
for (let docShell of docShellEnum) {
...;
}
rather than:
let winEnum = Services.wm.getEnumerator("navigator:browser");
while (winEnum.hasMoreElements()) {
let window = winEnum.getNext();
...
}
while (docShellEnum.hasMoreElements()) {
let docShell = winEnum.getNext().QueryInterface(Ci.nsIDocShell);
...
}
If you happen to be using an nsIArray from directly from JavaScript,
you unfortunately still need to specify the expected types, since
nsIArray has no idea what types it can contain:
for (let thing of array.enumerate(Ci.nsIThing)) {
...
}
Aside from being easier to maintain, these forms should also be
somewhat faster than the old protocol, since they only require one
XPConnect call per iteration rather than 3(+).
-Kris
firefox-dev mailing list
firefox-dev@mozilla.org mailto:firefox-dev@mozilla.org
https://mail.mozilla.org/listinfo/firefox-dev
On 24/08/2018 12:11, Philipp Kewisch wrote:
This is great, we should go and see if we can simplify the code, maybe
there is an automatic script to clean up as well!
Great yes, sadly this was announced when the bug/feature had already
landed causing big bustage that kept us busy all weekend in
https://bugzilla.mozilla.org/show_bug.cgi?id=1485820 with 109 comments
and 12 patches landed so far :-(
Jörg.