summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/promise.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/promise.js')
-rw-r--r--deps/npm/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/promise.js88
1 files changed, 69 insertions, 19 deletions
diff --git a/deps/npm/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/promise.js b/deps/npm/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/promise.js
index f80d247b1..eb081181a 100644
--- a/deps/npm/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/promise.js
+++ b/deps/npm/node_modules/request/node_modules/har-validator/node_modules/bluebird/js/main/promise.js
@@ -9,7 +9,23 @@ var reflect = function() {
var apiRejection = function(msg) {
return Promise.reject(new TypeError(msg));
};
+
var util = require("./util.js");
+
+var getDomain;
+if (util.isNode) {
+ getDomain = function() {
+ var ret = process.domain;
+ if (ret === undefined) ret = null;
+ return ret;
+ };
+} else {
+ getDomain = function() {
+ return null;
+ };
+}
+util.notEnumerableProp(Promise, "_getDomain", getDomain);
+
var async = require("./async.js");
var errors = require("./errors.js");
var TypeError = Promise.TypeError = errors.TypeError;
@@ -208,8 +224,12 @@ Promise.prototype._then = function (
if (!haveInternalData) ret._setIsMigrated();
}
- var callbackIndex =
- target._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
+ var callbackIndex = target._addCallbacks(didFulfill,
+ didReject,
+ didProgress,
+ ret,
+ receiver,
+ getDomain());
if (target._isResolved() && !target._isSettlePromisesQueued()) {
async.invoke(
@@ -291,7 +311,7 @@ Promise.prototype._receiverAt = function (index) {
: this[
index * 5 - 5 + 4];
if (ret === undefined && this._isBound()) {
- return this._boundTo;
+ return this._boundValue();
}
return ret;
};
@@ -314,6 +334,20 @@ Promise.prototype._rejectionHandlerAt = function (index) {
: this[index * 5 - 5 + 1];
};
+Promise.prototype._boundValue = function() {
+ var ret = this._boundTo;
+ if (ret !== undefined) {
+ if (ret instanceof Promise) {
+ if (ret.isFulfilled()) {
+ return ret.value();
+ } else {
+ return undefined;
+ }
+ }
+ }
+ return ret;
+};
+
Promise.prototype._migrateCallbacks = function (follower, index) {
var fulfill = follower._fulfillmentHandlerAt(index);
var reject = follower._rejectionHandlerAt(index);
@@ -321,7 +355,7 @@ Promise.prototype._migrateCallbacks = function (follower, index) {
var promise = follower._promiseAt(index);
var receiver = follower._receiverAt(index);
if (promise instanceof Promise) promise._setIsMigrated();
- this._addCallbacks(fulfill, reject, progress, promise, receiver);
+ this._addCallbacks(fulfill, reject, progress, promise, receiver, null);
};
Promise.prototype._addCallbacks = function (
@@ -329,7 +363,8 @@ Promise.prototype._addCallbacks = function (
reject,
progress,
promise,
- receiver
+ receiver,
+ domain
) {
var index = this._length();
@@ -341,20 +376,34 @@ Promise.prototype._addCallbacks = function (
if (index === 0) {
this._promise0 = promise;
if (receiver !== undefined) this._receiver0 = receiver;
- if (typeof fulfill === "function" && !this._isCarryingStackTrace())
- this._fulfillmentHandler0 = fulfill;
- if (typeof reject === "function") this._rejectionHandler0 = reject;
- if (typeof progress === "function") this._progressHandler0 = progress;
+ if (typeof fulfill === "function" && !this._isCarryingStackTrace()) {
+ this._fulfillmentHandler0 =
+ domain === null ? fulfill : domain.bind(fulfill);
+ }
+ if (typeof reject === "function") {
+ this._rejectionHandler0 =
+ domain === null ? reject : domain.bind(reject);
+ }
+ if (typeof progress === "function") {
+ this._progressHandler0 =
+ domain === null ? progress : domain.bind(progress);
+ }
} else {
var base = index * 5 - 5;
this[base + 3] = promise;
this[base + 4] = receiver;
- if (typeof fulfill === "function")
- this[base + 0] = fulfill;
- if (typeof reject === "function")
- this[base + 1] = reject;
- if (typeof progress === "function")
- this[base + 2] = progress;
+ if (typeof fulfill === "function") {
+ this[base + 0] =
+ domain === null ? fulfill : domain.bind(fulfill);
+ }
+ if (typeof reject === "function") {
+ this[base + 1] =
+ domain === null ? reject : domain.bind(reject);
+ }
+ if (typeof progress === "function") {
+ this[base + 2] =
+ domain === null ? progress : domain.bind(progress);
+ }
}
this._setLength(index + 1);
return index;
@@ -449,7 +498,7 @@ Promise.prototype._settlePromiseFromHandler = function (
promise._pushContext();
var x;
if (receiver === APPLY && !this._isRejected()) {
- x = tryCatch(handler).apply(this._boundTo, value);
+ x = tryCatch(handler).apply(this._boundValue(), value);
} else {
x = tryCatch(handler).call(receiver, value);
}
@@ -519,8 +568,6 @@ Promise.prototype._settlePromiseAt = function (index) {
this._isCarryingStackTrace() ? this._getCarriedStackTrace() : undefined;
var value = this._settledValue;
var receiver = this._receiverAt(index);
-
-
this._clearCallbackDataAtIndex(index);
if (typeof handler === "function") {
@@ -647,7 +694,10 @@ Promise.prototype._settlePromises = function () {
}
};
-Promise._makeSelfResolutionError = makeSelfResolutionError;
+util.notEnumerableProp(Promise,
+ "_makeSelfResolutionError",
+ makeSelfResolutionError);
+
require("./progress.js")(Promise, PromiseArray);
require("./method.js")(Promise, INTERNAL, tryConvertToPromise, apiRejection);
require("./bind.js")(Promise, INTERNAL, tryConvertToPromise);