I was just playing around with V8 Stack Trace API and came up with the 
following stupid code:
var log = console.log;

log(process.versions);

Error.stackTraceLimit = Infinity;

Error.prepareStackTrace = function(err, stack) {
return stack;
};

function printST() {
var obj = {};
Error.captureStackTrace(obj, printST);
log('\tStack length: ' + obj.stack.length);
}
log('Initiation:');
printST();

function recur(n) {
if(n > 1) {
return recur(--n);
}
log('recur():');
printST();
}

for(var i = 1; i <= 10; i++) {
log(i + '/');
recur(1000);
}
Which prints:

> { http_parser: '2.2',
>
>   node: '0.11.13',
>
>   v8: '3.25.30',
>
>   uv: '0.11.25',
>
>   zlib: '1.2.3',
>
>   modules: '14',
>
>   openssl: '1.0.1g' }
>
> Initiation:
>
>         Stack length: 8
>
> 1/
>
> recur():
>
>         Stack length: 1008
>
> 2/
>
> recur():
>
>         Stack length: 1008
>
> 3/
>
> recur():
>
>         Stack length: 0
>
> 4/
>
> recur():
>
>         Stack length: 1008
>
> 5/
>
> recur():
>
>         Stack length: 0
>
> 6/
>
> recur():
>
>         Stack length: 1008
>
> 7/
>
> recur():
>
>         Stack length: 0
>
> 8/
>
> recur():
>
>         Stack length: 0
>
> 9/
>
> recur():
>
>         Stack length: 0
>
> 10/
>
> recur():
>
>         Stack length: 0
>
> Is that expected behavior? And if so, could anyone please explain it? I 
think it involve some kind of optimization that V8 does because different 
versions of node print different outputs. For example:

> { http_parser: '1.0',
>
>   node: '0.10.29',
>
>   v8: '3.14.5.9',
>
>   ares: '1.9.0-DEV',
>
>   uv: '0.10.27',
>
>   zlib: '1.2.3',
>
>   modules: '11',
>
>   openssl: '1.0.1h' }
>
> Initiation:
>
>         Stack length: 8
>
> 1/
>
> recur():
>
>         Stack length: 1008
>
> 2/
>
> recur():
>
>         Stack length: 0
>
> 3/
>
> recur():
>
>         Stack length: 0
>
> 4/
>
> recur():
>
>         Stack length: 0
>
> 5/
>
> recur():
>
>         Stack length: 0
>
> 6/
>
> recur():
>
>         Stack length: 0
>
> 7/
>
> recur():
>
>         Stack length: 0
>
> 8/
>
> recur():
>
>         Stack length: 0
>
> 9/
>
> recur():
>
>         Stack length: 0
>
> 10/
>
> recur():
>
>         Stack length: 0
>
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/98ca344c-39f4-489c-a619-3cadd81e7d6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to