Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81160 views
1
"use strict";
2
module.exports = function(Promise, CapturedTrace, isDebugging) {
3
var contextStack = [];
4
function Context() {
5
this._trace = new CapturedTrace(peekContext());
6
}
7
Context.prototype._pushContext = function () {
8
if (!isDebugging()) return;
9
if (this._trace !== undefined) {
10
contextStack.push(this._trace);
11
}
12
};
13
14
Context.prototype._popContext = function () {
15
if (!isDebugging()) return;
16
if (this._trace !== undefined) {
17
contextStack.pop();
18
}
19
};
20
21
function createContext() {
22
if (isDebugging()) return new Context();
23
}
24
25
function peekContext() {
26
var lastIndex = contextStack.length - 1;
27
if (lastIndex >= 0) {
28
return contextStack[lastIndex];
29
}
30
return undefined;
31
}
32
33
Promise.prototype._peekContext = peekContext;
34
Promise.prototype._pushContext = Context.prototype._pushContext;
35
Promise.prototype._popContext = Context.prototype._popContext;
36
37
return createContext;
38
};
39
40