Skip to content
Browse files

updated readme example to be more terse

  • Loading branch information...
1 parent 6000c1e commit 982a73def6e59b3e8229284fabd7d935c9ed8ab7 @substack committed May 15, 2012
Showing with 27 additions and 17 deletions.
  1. +26 −16 README.markdown
  2. +1 −1 example/giant.js
View
42 README.markdown
@@ -13,34 +13,44 @@ except that it uses [esprima](http://esprima.org/) by way of
examples
========
+giant.js:
+
``` js
-var src = '(' + function () {
- (function fee () {
- [ 'foe', 'fum' ].forEach(fie);
- })();
-
- function fie (s) { smell(s) }
- function smell () { english('blood') }
-}+ ')()'
+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));
- 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)
+ ' in .' + fry.nameOf(s) + '()'
+ + ', line ' + s.start.line
);
});
- console.log('--------------------');
});
+fry.run();
+```
+
+sources/giant.js:
+
+``` js
+(function fee () {
+ [ 'foe', 'fum' ].forEach(fie);
+})();
-var vm = require('vm');
-try {
- vm.runInNewContext(fry.source, fry.context);
-} catch (err) { /* ignore this */ }
+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
```
methods
View
2 example/giant.js
@@ -7,7 +7,7 @@ fry.on('error', function (err, c) {
console.log(String(err));
c.stack.forEach(function (s) {
console.log(
- ' in .' + fry.nameOf(s) + '()'
+ ' in .' + fry.nameOf(s) + '()'
+ ', line ' + s.start.line
);
});

0 comments on commit 982a73d

Please sign in to comment.
Something went wrong with that request. Please try again.