-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d424c0e
commit d046da7
Showing
2 changed files
with
27 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters