source: imaps-frontend/node_modules/stack-generator/stack-generator.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[d565449]1(function(root, factory) {
2 'use strict';
3 // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers.
4
5 /* istanbul ignore next */
6 if (typeof define === 'function' && define.amd) {
7 define('stack-generator', ['stackframe'], factory);
8 } else if (typeof exports === 'object') {
9 module.exports = factory(require('stackframe'));
10 } else {
11 root.StackGenerator = factory(root.StackFrame);
12 }
13}(this, function(StackFrame) {
14 return {
15 backtrace: function StackGenerator$$backtrace(opts) {
16 var stack = [];
17 var maxStackSize = 10;
18
19 if (typeof opts === 'object' && typeof opts.maxStackSize === 'number') {
20 maxStackSize = opts.maxStackSize;
21 }
22
23 var curr = arguments.callee;
24 while (curr && stack.length < maxStackSize && curr['arguments']) {
25 // Allow V8 optimizations
26 var args = new Array(curr['arguments'].length);
27 for (var i = 0; i < args.length; ++i) {
28 args[i] = curr['arguments'][i];
29 }
30 if (/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) {
31 stack.push(new StackFrame({functionName: RegExp.$1 || undefined, args: args}));
32 } else {
33 stack.push(new StackFrame({args: args}));
34 }
35
36 try {
37 curr = curr.caller;
38 } catch (e) {
39 break;
40 }
41 }
42 return stack;
43 }
44 };
45}));
Note: See TracBrowser for help on using the repository browser.