Skip to content

Commit

Permalink
Implement simple StackFrame.fromString()
Browse files Browse the repository at this point in the history
Issue: #17
  • Loading branch information
eriwen committed Oct 24, 2018
1 parent ee8d8ba commit 0d7a328
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
24 changes: 24 additions & 0 deletions dist/stackframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@
}
};

StackFrame.fromString = function StackFrame$$fromString(str) {
var argsStartIndex = str.indexOf('(');
var argsEndIndex = str.lastIndexOf(')');

var functionName = str.substring(0, argsStartIndex);
var args = str.substring(argsStartIndex + 1, argsEndIndex).split(',');
var locationString = str.substring(argsEndIndex + 1);

if (locationString.indexOf('@') === 0) {
var parts = /@(.+?)(?::(\d+))?(?::(\d+))?$/.exec(locationString, '');
var fileName = parts[1];
var lineNumber = parts[2];
var columnNumber = parts[3];
}

return new StackFrame({
functionName: functionName,
args: args || undefined,
fileName: fileName,
lineNumber: lineNumber || undefined,
columnNumber: columnNumber || undefined
});
};

for (var i = 0; i < booleanProps.length; i++) {
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]);
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function(p) {
Expand Down
2 changes: 1 addition & 1 deletion dist/stackframe.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/stackframe.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0d7a328

Please sign in to comment.