diff options
author | Kris Maglione <maglione.k@gmail.com> | 2014-02-17 22:03:57 -0800 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2014-02-17 22:03:57 -0800 |
commit | f0a4e746792c41ffa69f8c3516110dfcb4374e69 (patch) | |
tree | c087a88a55a4c6539bba3a1c580762dc87aad3ce /common/modules/base.jsm | |
parent | 1963b49ab01f7acd9053c6a1d2be81c3e1696011 (diff) | |
download | pentadactyl-f0a4e746792c41ffa69f8c3516110dfcb4374e69.tar.gz |
Poke iterator stuff more.
Diffstat (limited to 'common/modules/base.jsm')
-rw-r--r-- | common/modules/base.jsm | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 9f3ec1a0..52ea7d80 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -1405,6 +1405,7 @@ function octal(decimal) parseInt(decimal, 8); * @param {nsIJSIID} iface The interface to which to query all elements. * @returns {Generator} */ +let _iterator = "@@iterator" in [] ? "@@iterator" : "iterator"; function iter(obj, iface) { if (arguments.length == 2 && iface instanceof Ci.nsIJSIID) return iter(obj).map(item => item.QueryInterface(iface)); @@ -1420,20 +1421,10 @@ function iter(obj, iface) { })(); else if (isinstance(obj, ["Iterator", "Generator"])) ; - else if (isinstance(obj, ["Map Iterator"])) - // This is stupid. - res = (function () { - for (;;) { - let { value, done } = obj.next(); - if (done) - return; - - yield value; - } - })(); - else if (isinstance(obj, ["Map"])) - // This is stupid. - res = (r for (r of obj)); + else if (isinstance(obj, [Ci.nsIDOMHTMLCollection, Ci.nsIDOMNodeList])) + res = array.iterItems(obj); + else if (_iterator in obj && callable(obj[_iterator]) && !("__iterator__" in obj)) + res = (x for (x of obj)); else if (ctypes && ctypes.CData && obj instanceof ctypes.CData) { while (obj.constructor instanceof ctypes.PointerType) obj = obj.contents; @@ -1447,8 +1438,6 @@ function iter(obj, iface) { else return iter({}); } - else if (isinstance(obj, [Ci.nsIDOMHTMLCollection, Ci.nsIDOMNodeList])) - res = array.iterItems(obj); else if (Ci.nsIDOMNamedNodeMap && obj instanceof Ci.nsIDOMNamedNodeMap || Ci.nsIDOMMozNamedAttrMap && obj instanceof Ci.nsIDOMMozNamedAttrMap) res = (function () { |