Socket
Socket
Sign inDemoInstall

stack-trace

Package Overview
Dependencies
0
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

74

lib/stack-trace.js
exports.get = function(belowFn) {
var oldLimit = Error.stackTraceLimit;
Error.stackTraceLimit = Infinity;
var dummyObject = {};

@@ -12,2 +15,3 @@ Error.captureStackTrace(dummyObject, belowFn || exports.get);

Error.prepareStackTrace = v8Handler;
Error.stackTraceLimit = oldLimit;

@@ -21,35 +25,49 @@ return v8StackTrace;

return lines.map(function(line) {
var lineMatch = line.match(/at ([^\s]+)\s+\((?:(.+?):(\d+):(\d+)|([^)]+))\)/);
var methodMatch = lineMatch[1].match(/([^\.]+)(?:\.(.+))?/);
var object = methodMatch[1];
var method = methodMatch[2];
return lines
.map(function(line) {
var lineMatch = line.match(/at (?:([^\s]+)\s+)?\(?(?:(.+?):(\d+):(\d+)|([^)]+))\)?/);
if (!lineMatch) {
return;
}
var functionName = lineMatch[1];
var methodName = null;
var typeName = 'Object';
var isNative = (lineMatch[5] === 'native');
var object = null;
var method = null;
var functionName = null;
var typeName = null;
var methodName = null;
var isNative = (lineMatch[5] === 'native');
if (method) {
typeName = object;
methodName = method;
}
if (lineMatch[1]) {
var methodMatch = lineMatch[1].match(/([^\.]+)(?:\.(.+))?/);
object = methodMatch[1];
method = methodMatch[2];
functionName = lineMatch[1];
typeName = 'Object';
}
if (method === '<anonymous>') {
methodName = null;
functionName = '';
}
if (method) {
typeName = object;
methodName = method;
}
var properties = {
fileName: lineMatch[2] || null,
lineNumber: parseInt(lineMatch[3], 10) || null,
functionName: functionName,
typeName: typeName,
methodName: methodName,
columnNumber: parseInt(lineMatch[4], 10) || null,
'native': isNative,
};
if (method === '<anonymous>') {
methodName = null;
functionName = '';
}
return self._createParsedCallSite(properties);
});
var properties = {
fileName: lineMatch[2] || null,
lineNumber: parseInt(lineMatch[3], 10) || null,
functionName: functionName,
typeName: typeName,
methodName: methodName,
columnNumber: parseInt(lineMatch[4], 10) || null,
'native': isNative,
};
return self._createParsedCallSite(properties);
})
.filter(function(callSite) {
return !!callSite;
});
};

@@ -56,0 +74,0 @@

@@ -5,3 +5,3 @@ {

"description": "Get v8 stack traces as an array of CallSite objects.",
"version": "0.0.3",
"version": "0.0.4",
"homepage": "https://github.com/felixge/node-stack-trace",

@@ -8,0 +8,0 @@ "repository": {

@@ -20,1 +20,31 @@ var common = require('../common');

})();
(function deep1() {
(function deep2() {
(function deep3() {
(function deep4() {
(function deep5() {
(function deep6() {
(function deep7() {
(function deep8() {
(function deep9() {
(function deep10() {
(function deep10() {
var trace = stackTrace.get();
var hasFirstCallSite = trace.some(function(callSite) {
return callSite.getFunctionName() === 'deep1';
});
assert.ok(hasFirstCallSite);
})();
})();
})();
})();
})();
})();
})();
})();
})();
})();
})();

@@ -85,1 +85,31 @@ var common = require('../common');

})();
(function testStackWithFileOnly() {
var err = {};
err.stack =
'AssertionError: true == false\n' +
' at /Users/felix/code/node-fast-or-slow/lib/test_case.js:80:10';
var trace = stackTrace.parse(err);
var callSite = trace[0];
assert.strictEqual(callSite.getFileName(), '/Users/felix/code/node-fast-or-slow/lib/test_case.js');
assert.strictEqual(callSite.getFunctionName(), null);
assert.strictEqual(callSite.getTypeName(), null);
assert.strictEqual(callSite.getMethodName(), null);
assert.strictEqual(callSite.getLineNumber(), 80);
assert.strictEqual(callSite.getColumnNumber(), 10);
assert.strictEqual(callSite.isNative(), false);
})();
(function testStackWithMultilineMessage() {
var err = {};
err.stack =
'AssertionError: true == false\nAnd some more shit\n' +
' at /Users/felix/code/node-fast-or-slow/lib/test_case.js:80:10';
var trace = stackTrace.parse(err);
var callSite = trace[0];
assert.strictEqual(callSite.getFileName(), '/Users/felix/code/node-fast-or-slow/lib/test_case.js');
})();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc