@@ -5,9 +5,35 @@ stacktrace.js
55A JavaScript tool that allows you to debug your JavaScript by giving you a [ stack trace] ( http://en.wikipedia.org/wiki/Stack_trace ) of function calls leading to an error (or any condition you specify)
66
77## Usage
8- stacktrace.js is getting a new API!
8+ ``` js
9+ var callback = function (stackframes ) {
10+ var stringifiedStack = stackframes .map (function (sf ) {
11+ sf .toString ();
12+ }).join (' \n ' );
13+ console .log (stringifiedStack);
14+ };
915
10- Looking for the [ stable version] ( https://github.com/stacktracejs/stacktrace.js/tree/stable ) ?
16+ var errback = function (err ) { console .log (err .message ); };
17+
18+ StackTrace .get ().then (callback, errback)
19+ => Promise (Array [StackFrame](https: // github.com/stacktracejs/stackframe), Error)
20+ => callback ([StackFrame (' func1' , [], ' file.js' , 203 , 9 ), StackFrame (' func2' , [], ' http://localhost:3000/file.min.js' , 1 , 3284 )])
21+
22+ // Somewhere else...
23+ var error = new Error (' BOOM!' );
24+
25+ StackTrace .fromError (error).then (callback, errback)
26+ => Promise (Array [StackFrame](https: // github.com/stacktracejs/stackframe), Error)
27+
28+ StackTrace .generateArtificially ().then (callback, errback)
29+ => Promise (Array [StackFrame](https: // github.com/stacktracejs/stackframe), Error)
30+
31+ StackTrace .instrument (interestingFn, callback, errback)
32+ => Instrumented Function
33+
34+ StackTrace .deinstrument (interestingFn)
35+ => De- instrumented Function
36+ ` ` `
1137
1238## Get stacktrace.js
1339` ` `
@@ -21,10 +47,60 @@ https://cdnjs.com/libraries/stacktrace.js
2147
2248` // cdnjs.cloudflare.com/ajax/libs/stacktrace.js/0.6.4/stacktrace.min.js`
2349
24- ## Contributions
50+ ## API
51+
52+ #### ` StackTrace.get(/*optional*/ options)` => Promise (Array [StackFrame])
53+ Generate a backtrace from invocation point, then parse and enhance it.
54+ options: Object
55+ * ** sourceCache: Object (String URL => String Source)** - Pre- populate source cache to avoid network requests
56+ * ** offline: Boolean (default: false )** - Set to ` true` to prevent all network requests
57+
58+ #### ` StackTrace.fromError(error, /*optional*/ options)` => Promise (Array [StackFrame])
59+ Given an Error object, use [error- stack- parser](https: // github.com/stacktracejs/error-stack-parser)
60+ to parse it and enhance location information with [stacktrace- gps](https: // github.com/stacktracejs/stacktrace-gps).
61+ * ** sourceCache: Object (String URL => String Source)** - Pre- populate source cache to avoid network requests
62+ * ** offline: Boolean (default: false )** - Set to ` true` to prevent all network requests
63+
64+ #### ` StackTrace.generateArtificially(/*optional*/ options)` => Promise (Array [StackFrame])
65+ Use [stack- generator](https: // github.com/stacktracejs/stack-generator) to generate a backtrace by walking the `arguments.callee.caller` chain.
66+ * ** sourceCache: Object (String URL => String Source)** - Pre- populate source cache to avoid network requests
67+ * ** offline: Boolean (default: false )** - Set to ` true` to prevent all network requests
68+
69+ #### ` StackTrace.instrument(fn, callback, /*optional*/ errback)` => Boolean
70+ Call callback with a _stack trace_ anytime ` interestingFn` is called . Returns ` true` if given Function is successfully instrumented
71+ * ** fn** - Function to wrap, call callback on invocation and call- through
72+ * ** callback** - Function to call with stack trace (generated by ` StackTrace.get()` ) when fn is called
73+ * ** errback** - (Optional) Function to call with Error object if there was a problem getting a stack trace.
74+ Fails silently (though ` fn` is still called) if a stack trace couldn' t be generated.
75+
76+ #### `StackTrace.deinstrument(fn)` => Boolean
77+ Remove StackTrace instrumentation on `fn`. Returns `true` if deinstrumentation succeeds.
78+ * **fn** - Previously wrapped Function
79+
80+ ## Browser Support
81+ * Chrome 1+
82+ * Firefox 3+
83+ * Safari 5+
84+ * Opera 9+
85+ * IE 6+
86+ * iOS 7+
87+ * Android 4.0+
88+
89+ _NOTE: You won' t get the benefit of [source maps](http: // www.html5rocks.com/en/tutorials/developertools/sourcemaps/)
90+ in IE9 - or other very old browsers ._
91+
92+ ## Using node .js / io .js only?
93+ I recommend the [stack- trace node package ](https: // www.npmjs.com/package/stack-trace).
94+ It has a very similar API and also supports source maps.
95+
96+ ## Contributing
97+ Want to be listed as a * Contributor* ? Start with the [Contributing Guide](CONTRIBUTING .md )!
2598
2699This project is made possible due to the efforts of these fine people:
27100
28101* [Eric Wendelin](http: // www.eriwen.com)
29102* [Victor Homyakov](https: // github.com/victor-homyakov)
30103* [Many others](https: // github.com/stacktracejs/stacktrace.js/graphs/contributors)
104+
105+ ## License
106+ This project is licensed to the [Public Domain](http: // unlicense.org)
0 commit comments