Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
patinthehat committed May 11, 2023
1 parent d424c0e commit d046da7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
54 changes: 26 additions & 28 deletions src/lib/StackGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
import StackFrame from '@/lib/stackframe';

export function StackGenerator() {
return {
backtrace: function StackGenerator$$backtrace(opts) {
const stack: any[] = [];
let maxStackSize = 10;
export const StackGenerator = {
backtrace: function StackGenerator$$backtrace(opts) {
const stack: any[] = [];
let maxStackSize = 10;

if (typeof opts === 'object' && typeof opts.maxStackSize === 'number') {
maxStackSize = opts.maxStackSize;
}
if (typeof opts === 'object' && typeof opts.maxStackSize === 'number') {
maxStackSize = opts.maxStackSize;
}

let curr = arguments.callee;
while (curr && stack.length < maxStackSize && curr['arguments']) {
const args = new Array(curr['arguments'].length);
for (let i = 0; i < args.length; ++i) {
args[i] = curr['arguments'][i];
}
if (/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) {
stack.push(new StackFrame({ functionName: RegExp.$1 || undefined, args: args }));
} else {
stack.push(new StackFrame({ args: args }));
}
let curr = arguments.callee;
while (curr && stack.length < maxStackSize && curr['arguments']) {
const args = new Array(curr['arguments'].length);
for (let i = 0; i < args.length; ++i) {
args[i] = curr['arguments'][i];
}
if (/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) {
stack.push(new StackFrame({ functionName: RegExp.$1 || undefined, args: args }));
} else {
stack.push(new StackFrame({ args: args }));
}

try {
curr = curr.caller;
} catch (e) {
break;
}
try {
curr = curr.caller;
} catch (e) {
break;
}
return stack;
},
};
}
}
return stack;
},
};

export default StackGenerator;
2 changes: 1 addition & 1 deletion src/lib/stacktrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const StackTrace = {

fromError: function StackTrace$$fromError(error, opts) {
opts = _merge(_options, opts);
const gps = new StackTraceGPS(opts);
const gps = new StackTraceGPS.default(opts);
return new Promise(
function (resolve) {
const stackframes = _filtered(ErrorStackParser.parse(error), opts.filter);
Expand Down

0 comments on commit d046da7

Please sign in to comment.