Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 90 lines (60 sloc) 2.141 kb
515209b @substack readme stub
authored
1 stackedy
2 ========
3
4 Roll your own stack traces and control program execution through AST
5 manipulation.
996e31f @substack documentation stubs
authored
6
c303903 @substack simple example in the readme, ready for npm publish
authored
7 examples
8 ========
9
10 simple custom stacktrace
11 ------------------------
12
37132d3 @substack examples => example
authored
13 example/simple/run.js:
c303903 @substack simple example in the readme, ready for npm publish
authored
14
15 ````javascript
16 var stackedy = require('stackedy');
17 var fs = require('fs');
18
19 var src = fs.readFileSync(__dirname + '/src.js');
20 var stack = stackedy(src, { filename : 'stax.js' }).run();
21
41ff255 @substack bump and docs about {post,pre}Filter
authored
22 stack.on('error', function (err, c) {
23 stack.stop();
24 console.log('Error: ' + err);
c303903 @substack simple example in the readme, ready for npm publish
authored
25
41ff255 @substack bump and docs about {post,pre}Filter
authored
26 var cur = c.current;
27 console.log(' in ' + cur.filename + ' at line ' + cur.start.line);
c303903 @substack simple example in the readme, ready for npm publish
authored
28
41ff255 @substack bump and docs about {post,pre}Filter
authored
29 c.stack.forEach(function (s) {
c303903 @substack simple example in the readme, ready for npm publish
authored
30 console.log(' in ' + s.filename + ', '
31 + s.functionName + '() at line ' + s.start.line
32 );
33 });
34 });
35 ````
36
37 output:
996e31f @substack documentation stubs
authored
38
c303903 @substack simple example in the readme, ready for npm publish
authored
39 Error: moo
40 in stax.js at line 2
41 in stax.js, h() at line 1
42 in stax.js, g() at line 0
43 in stax.js, f() at line 4
996e31f @substack documentation stubs
authored
44
45 methods
46 =======
47
48 ````javascript
49 var stackedy = require('stackedy');
50 ````
51
52 var stack = stackedy(src='', opts={})
53 -------------------------------------
54
c303903 @substack simple example in the readme, ready for npm publish
authored
55 Create a new stack object.
56
57 stack.include(src, opts={})
58 ---------------------------
59
60 Include a source file body `src` into the current bundle.
61
41ff255 @substack bump and docs about {post,pre}Filter
authored
62 `opts.filename` will augment the stack with filename information.
63
64 `opts.postFilter` transforms the source after transformation.
65
66 `opts.preFilter` transforms the source before transformation.
996e31f @substack documentation stubs
authored
67
c07ebc2 @substack updated docs about runner
authored
68 stack.run(context={}, opts)
69 ---------------------------
c303903 @substack simple example in the readme, ready for npm publish
authored
70
71 Execute the compiled source with the given context using `vm.runInNewContext()`.
72
c07ebc2 @substack updated docs about runner
authored
73 `opts.stoppable` defaults to `true` and controls whether the execution can be
74 stopped with `.stop()`.
75
76 `opts.runner(src, context)` is the function used to run the transformed source.
77 It defaults to `vm.runInNewContext`.
aba461a @substack bump and docs for opts.stoppable
authored
78
cc6ae36 @substack docs for opts.global
authored
79 `opts.global` is the context to use when `this` is `null`, such as `window` in a
80 browser environment.
81
c07ebc2 @substack updated docs about runner
authored
82 stack.compile(context={}, opts)
83 -------------------------------
c303903 @substack simple example in the readme, ready for npm publish
authored
84
85 Compile the sources into a single file with the transformations in place.
86
87 Returns an object with source, augmented context, current and others.
6a5499c @substack bump for .bundle()
authored
88
aba461a @substack bump and docs for opts.stoppable
authored
89 `opts.stoppable` controls whether the execution can be stopped with `.stop()`.
Something went wrong with that request. Please try again.