You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
938 B
JavaScript

"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;
};