Transform the AST in order to generate stack traces with no stack trace API necessary.
This module is like stackedy, except that it uses esprima by way of falafel.
giant.js:
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/sources/giant.js', 'utf8');
var fritter = require('fritter');
var fry = fritter(src);
fry.on('error', function (err, c) {
console.log(String(err));
c.stack.forEach(function (s) {
console.log(
' in .' + fry.nameOf(s) + '()'
+ ', line ' + s.start.line
);
});
});
fry.run();
sources/giant.js:
(function fee () {
[ 'foe', 'fum' ].forEach(fie);
})();
function fie (s) { smell(s) }
function smell () { english('blood') }
output:
ReferenceError: english is not defined
in .smell(), line 5
in .forEach(), line 2
in .fee(), line 1
var fritter = require('fritter')
Return a fry
object given some optional javascript source src
and some
context
to execute in and populate.
fry
emits 'error'
events with the error object and the present callstack as
arguments when exceptions in src
are thrown.
If opts.longStacks
is true, turn on longer stack traces for a performance
penalty.
Include and wrap some javascript source src
. Use opts.filename
to associate
nodes in the stack with filenames so custom error handlers know what file an
exception originated form.
Run the fry.source
under fry.context
using Function()
as a nicer form of
eval()
.
Stop execution insofar as that is possible.
If callbacks from external APIs fire, the body of those callbacks won't fire.
transformed source to execute with something like vm.runInNewContext()
context to execute fry.source
with, including randomly-named wrapper
functions to catch exceptions and track the call stack
names of the randomly-generated wrapper functions
With npm do:
npm install fritter
MIT