• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2module.exports = function(Promise) {
3function returner() {
4    return this.value;
5}
6function thrower() {
7    throw this.reason;
8}
9
10Promise.prototype["return"] =
11Promise.prototype.thenReturn = function (value) {
12    if (value instanceof Promise) value.suppressUnhandledRejections();
13    return this._then(
14        returner, undefined, undefined, {value: value}, undefined);
15};
16
17Promise.prototype["throw"] =
18Promise.prototype.thenThrow = function (reason) {
19    return this._then(
20        thrower, undefined, undefined, {reason: reason}, undefined);
21};
22
23Promise.prototype.catchThrow = function (reason) {
24    if (arguments.length <= 1) {
25        return this._then(
26            undefined, thrower, undefined, {reason: reason}, undefined);
27    } else {
28        var _reason = arguments[1];
29        var handler = function() {throw _reason;};
30        return this.caught(reason, handler);
31    }
32};
33
34Promise.prototype.catchReturn = function (value) {
35    if (arguments.length <= 1) {
36        if (value instanceof Promise) value.suppressUnhandledRejections();
37        return this._then(
38            undefined, returner, undefined, {value: value}, undefined);
39    } else {
40        var _value = arguments[1];
41        if (_value instanceof Promise) _value.suppressUnhandledRejections();
42        var handler = function() {return _value;};
43        return this.caught(value, handler);
44    }
45};
46};
47