1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-29 00:02:28 +01:00

Make Minefield not explode, because Minefield exploding is not fun.

This commit is contained in:
Kris Maglione
2012-01-11 19:20:21 -05:00
parent f07015db48
commit 9ef24af485
2 changed files with 47 additions and 13 deletions

View File

@@ -289,7 +289,7 @@ function properties(obj, prototypes, debugger_) {
for (; obj; obj = prototypes && prototype(obj)) {
try {
if (sandbox.Object.getOwnPropertyNames || !debugger_ || !services.debugger.isOn)
var iter = values(Object.getOwnPropertyNames(obj));
var iter = (v for each (v in Object.getOwnPropertyNames(obj)));
}
catch (e) {}
if (!iter)
@@ -1452,17 +1452,7 @@ function iter(obj, iface) {
return iter(obj.enumerator());
return iter(obj.enumerator);
}
res.__noSuchMethod__ = function __noSuchMethod__(meth, args) {
if (meth in iter)
var res = iter[meth].apply(iter, [this].concat(args));
else
res = let (ary = array(this))
ary[meth] ? ary[meth].apply(ary, args) : ary.__noSuchMethod__(meth, args);
if (isinstance(res, ["Iterator", "Generator"]))
return iter(res);
return res;
};
return res;
return Iter(res);
}
update(iter, {
toArray: function toArray(iter) array(iter).array,
@@ -1576,6 +1566,16 @@ update(iter, {
}
});
const Iter = Class("Iter", {
init: function init(iter) {
this.iter = iter;
if ("__iterator__" in iter)
this.iter = iter.__iterator__();
},
__iterator__: function () this.iter
})
/**
* Array utility methods.
*/
@@ -1731,6 +1731,40 @@ var array = Class("array", Array, {
}
});
/* Make Minefield not explode, because Minefield exploding is not fun. */
let iterProto = Iter.prototype;
Object.keys(iter).forEach(function (k) {
iterProto[k] = function () {
let res = iter[k].apply(iter, [this].concat(Array.slice(arguments)));
if (isinstance(res, ["Iterator", "Generator"]))
return Iter(res);
return res;
};
});
Object.keys(array).forEach(function (k) {
if (!(k in iterProto))
iterProto[k] = function () {
let res = array[k].apply(array, [this.toArray()].concat(Array.slice(arguments)));
if (isinstance(res, ["Iterator", "Generator"]))
return Iter(res);
if (isArray(res))
return array(res);
return res;
};
});
Object.getOwnPropertyNames(Array.prototype).forEach(function (k) {
if (!(k in iterProto))
iterProto[k] = function () {
let ary = iter(this).toArray();
let res = ary[k].apply(ary, arguments);
if (isArray(res))
return array(res);
return res;
};
});
endModule();
// catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);}

View File

@@ -101,7 +101,7 @@ var Highlights = Module("Highlight", {
keys: function keys() Object.keys(this.highlight).sort(),
__iterator__: function () values(this.highlight).sort(function (a, b) String.localeCompare(a.class, b.class))
.iterValues(),
.iterValues().__iterator__(),
_create: function _create(agent, args) {
let obj = Highlight.apply(Highlight, args);