Newer
Older
CVSS_3.0_GUI / dist / CVSS_3.0_Calc-1.0.0-linux-x64 / node_modules / nwjs-builder-phoenix / node_modules / bluebird / js / release / catch_filter.js
root on 7 May 2019 1 KB Initial commit
  1. "use strict";
  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;
  7.  
  8. function 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.  
  41. return catchFilter;
  42. };
Buy Me A Coffee