Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

crappy example for now

  • Loading branch information...
commit b4f10db559a16631f6932ba3e231664086def0e8 1 parent 98b565f
@substack authored
Showing with 114 additions and 14 deletions.
  1. +84 −1 README.markdown
  2. +0 −12 example/ex.js
  3. +27 −0 example/giant.js
  4. +3 −1 index.js
View
85 README.markdown
@@ -1,4 +1,87 @@
fritter
=======
-Create node fritters.
+Transform the AST in order to generate stack traces with no stack trace API
+necessary.
+
+examples
+========
+
+``` js
+var src = '(' + function () {
+ (function fee () {
+ [ 'foe', 'fum' ].forEach(fie);
+ })();
+
+ function fie (s) { smell(s) }
+ function smell () { english('blood') }
+}+ ')()'
+
+var fritter = require('fritter');
+var fry = fritter(src);
+fry.on('error', function (err, c) {
+ console.log(String(err));
+ console.log('--------------------');
+ c.stack.forEach(function (s) {
+ console.log(
+ s.callee.id && s.callee.id.name
+ || src.slice(s.range[0], s.range[1] + 1)
+ );
+ });
+ console.log('--------------------');
+});
+
+var vm = require('vm');
+try {
+ vm.runInNewContext(fry.source, fry.context);
+} catch (err) { /* ignore this */ }
+```
+
+methods
+=======
+
+``` js
+var fritter = require('fritter')
+```
+
+var fry = fritter(src, context={})
+--------------------------------
+
+Return a `fry` object given some 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.
+
+attributes
+==========
+
+fry.source
+----------
+
+transformed source to execute with something like `vm.runInNewContext()`
+
+fry.context
+-----------
+
+context to execute `fry.source` with, including randomly-named wrapper
+functions to catch exceptions and track the call stack
+
+fry.names
+---------
+
+names of the randomly-generated wrapper functions
+
+install
+=======
+
+With [npm](http://npmjs.org) do:
+
+```
+npm install fritter
+```
+
+license
+=======
+
+MIT
View
12 example/ex.js
@@ -1,12 +0,0 @@
-var fritter = require('../');
-var vm = require('vm');
-
-var out = fritter('(' + function () {
- console.log('beeeep');
- beep(console.log)('boop');
-
- function beep (fn) { return 4() }
-} + ')()', { console : console });
-
-console.log(out.source);
-vm.runInNewContext(out.source, out.context);
View
27 example/giant.js
@@ -0,0 +1,27 @@
+var src = '(' + function () {
+ (function fee () {
+ [ 'foe', 'fum' ].forEach(fie);
+ })();
+
+ function fie (s) { smell(s) }
+ function smell () { english('blood') }
+}+ ')()'
+
+var fritter = require('../');
+var fry = fritter(src);
+fry.on('error', function (err, c) {
+ console.log(String(err));
+ console.log('--------------------');
+ c.stack.forEach(function (s) {
+ console.log(
+ s.callee.id && s.callee.id.name
+ || src.slice(s.range[0], s.range[1] + 1)
+ );
+ });
+ console.log('--------------------');
+});
+
+var vm = require('vm');
+try {
+ vm.runInNewContext(fry.source, fry.context);
+} catch (err) { /* ignore this */ }
View
4 index.js
@@ -50,7 +50,9 @@ module.exports = function (src, context) {
context[names.catcher] = function (err) {
if (caught.indexOf(err) < 0) {
caught.push(err);
- self.emit('error', err, { stack : self.stack.slice() });
+ self.emit('error', err, {
+ stack : self.stack.slice()
+ });
}
if (!throwing) {
Please sign in to comment.
Something went wrong with that request. Please try again.