diff options
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.js | 68 |
1 files changed, 53 insertions, 15 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 f80d247b14..28dc1f7625 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( @@ -321,7 +341,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 +349,8 @@ Promise.prototype._addCallbacks = function ( reject, progress, promise, - receiver + receiver, + domain ) { var index = this._length(); @@ -341,20 +362,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; @@ -647,7 +682,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); |