Version 1
[yaffs-website] / node_modules / bluebird / js / release / direct_resolve.js
1 "use strict";
2 module.exports = function(Promise) {
3 function returner() {
4     return this.value;
5 }
6 function thrower() {
7     throw this.reason;
8 }
9
10 Promise.prototype["return"] =
11 Promise.prototype.thenReturn = function (value) {
12     if (value instanceof Promise) value.suppressUnhandledRejections();
13     return this._then(
14         returner, undefined, undefined, {value: value}, undefined);
15 };
16
17 Promise.prototype["throw"] =
18 Promise.prototype.thenThrow = function (reason) {
19     return this._then(
20         thrower, undefined, undefined, {reason: reason}, undefined);
21 };
22
23 Promise.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
34 Promise.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 };