summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/bluebird/js/main/context.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/bluebird/js/main/context.js')
-rw-r--r--deps/npm/node_modules/bluebird/js/main/context.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/deps/npm/node_modules/bluebird/js/main/context.js b/deps/npm/node_modules/bluebird/js/main/context.js
new file mode 100644
index 0000000000..ccd7702b7e
--- /dev/null
+++ b/deps/npm/node_modules/bluebird/js/main/context.js
@@ -0,0 +1,38 @@
+"use strict";
+module.exports = function(Promise, CapturedTrace, isDebugging) {
+var contextStack = [];
+function Context() {
+ this._trace = new CapturedTrace(peekContext());
+}
+Context.prototype._pushContext = function () {
+ if (!isDebugging()) return;
+ if (this._trace !== undefined) {
+ contextStack.push(this._trace);
+ }
+};
+
+Context.prototype._popContext = function () {
+ if (!isDebugging()) return;
+ if (this._trace !== undefined) {
+ contextStack.pop();
+ }
+};
+
+function createContext() {
+ if (isDebugging()) return new Context();
+}
+
+function peekContext() {
+ var lastIndex = contextStack.length - 1;
+ if (lastIndex >= 0) {
+ return contextStack[lastIndex];
+ }
+ return undefined;
+}
+
+Promise.prototype._peekContext = peekContext;
+Promise.prototype._pushContext = Context.prototype._pushContext;
+Promise.prototype._popContext = Context.prototype._popContext;
+
+return createContext;
+};