2 module.exports = function(NEXT_FILTER) {
3 var util = require("./util");
4 var getKeys = require("./es5").keys;
5 var tryCatch = util.tryCatch;
6 var errorObj = util.errorObj;
8 function catchFilter(instances, cb, promise) {
10 var boundTo = promise._boundValue();
11 predicateLoop: for (var i = 0; i < instances.length; ++i) {
12 var item = instances[i];
15 (item != null && item.prototype instanceof Error)) {
16 if (e instanceof item) {
17 return tryCatch(cb).call(boundTo, e);
19 } else if (typeof item === "function") {
20 var matchesPredicate = tryCatch(item).call(boundTo, e);
21 if (matchesPredicate === errorObj) {
22 return matchesPredicate;
23 } else if (matchesPredicate) {
24 return tryCatch(cb).call(boundTo, e);
26 } else if (util.isObject(e)) {
27 var keys = getKeys(item);
28 for (var j = 0; j < keys.length; ++j) {
30 if (item[key] != e[key]) {
31 continue predicateLoop;
34 return tryCatch(cb).call(boundTo, e);