commit
This commit is contained in:
parent
a70448a434
commit
a15c733e45
55 changed files with 13236 additions and 1 deletions
63
node_modules/bluebird/js/main/direct_resolve.js
generated
vendored
Normal file
63
node_modules/bluebird/js/main/direct_resolve.js
generated
vendored
Normal file
|
@ -0,0 +1,63 @@
|
|||
"use strict";
|
||||
var util = require("./util.js");
|
||||
var isPrimitive = util.isPrimitive;
|
||||
|
||||
module.exports = function(Promise) {
|
||||
var returner = function () {
|
||||
return this;
|
||||
};
|
||||
var thrower = function () {
|
||||
throw this;
|
||||
};
|
||||
var returnUndefined = function() {};
|
||||
var throwUndefined = function() {
|
||||
throw undefined;
|
||||
};
|
||||
|
||||
var wrapper = function (value, action) {
|
||||
if (action === 1) {
|
||||
return function () {
|
||||
throw value;
|
||||
};
|
||||
} else if (action === 2) {
|
||||
return function () {
|
||||
return value;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Promise.prototype["return"] =
|
||||
Promise.prototype.thenReturn = function (value) {
|
||||
if (value === undefined) return this.then(returnUndefined);
|
||||
|
||||
if (isPrimitive(value)) {
|
||||
return this._then(
|
||||
wrapper(value, 2),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
} else if (value instanceof Promise) {
|
||||
value._ignoreRejections();
|
||||
}
|
||||
return this._then(returner, undefined, undefined, value, undefined);
|
||||
};
|
||||
|
||||
Promise.prototype["throw"] =
|
||||
Promise.prototype.thenThrow = function (reason) {
|
||||
if (reason === undefined) return this.then(throwUndefined);
|
||||
|
||||
if (isPrimitive(reason)) {
|
||||
return this._then(
|
||||
wrapper(reason, 1),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
}
|
||||
return this._then(thrower, undefined, undefined, reason, undefined);
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue