• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2module.exports = function(NEXT_FILTER) {
3var util = require("./util");
4var getKeys = require("./es5").keys;
5var tryCatch = util.tryCatch;
6var errorObj = util.errorObj;
7
8function catchFilter(instances, cb, promise) {
9    return function(e) {
10        var boundTo = promise._boundValue();
11        predicateLoop: for (var i = 0; i < instances.length; ++i) {
12            var item = instances[i];
13
14            if (item === Error ||
15                (item != null && item.prototype instanceof Error)) {
16                if (e instanceof item) {
17                    return tryCatch(cb).call(boundTo, e);
18                }
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);
25                }
26            } else if (util.isObject(e)) {
27                var keys = getKeys(item);
28                for (var j = 0; j < keys.length; ++j) {
29                    var key = keys[j];
30                    if (item[key] != e[key]) {
31                        continue predicateLoop;
32                    }
33                }
34                return tryCatch(cb).call(boundTo, e);
35            }
36        }
37        return NEXT_FILTER;
38    };
39}
40
41return catchFilter;
42};
43