Skip to content

Commit bfb00c2

Browse files
committed
chore(logger): getCallInfo module improving performance
1 parent 8fa5f8e commit bfb00c2

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

bin/tsw/util/logger/callInfo.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@
99

1010
this.getCallInfo = function(level) {
1111

12-
const res = {};
12+
const res = {
13+
line: 0,
14+
column: 0,
15+
filename: ''
16+
};
1317

1418
level = level || 0;
1519

1620
const orig = Error.prepareStackTrace;
17-
Error.prepareStackTrace = function(_, stack) {
18-
return stack;
19-
};
21+
const origLimit = Error.stackTraceLimit;
22+
Error.prepareStackTrace = captureStackTrace;
23+
Error.stackTraceLimit = 5;
2024

21-
const err = new Error();
25+
const err = Object.create(null);
2226
Error.captureStackTrace(err, arguments.callee); // eslint-disable-line no-caller
27+
const { stack } = err;
2328

24-
const stack = err.stack;
2529
Error.prepareStackTrace = orig;
30+
Error.stackTraceLimit = origLimit;
2631

2732
if (stack && stack[level] && typeof stack[level].getLineNumber === 'function') {
2833
res.line = stack[level].getLineNumber();
@@ -32,3 +37,8 @@ this.getCallInfo = function(level) {
3237

3338
return res;
3439
};
40+
41+
function captureStackTrace(_, stack) {
42+
return stack;
43+
}
44+

0 commit comments

Comments
 (0)