Sorry, missed your reply.  Replies inline.

On Fri, Sep 5, 2014 at 5:37 PM, enormouspenguin <kimkhanh...@gmail.com> wrote:
> Great explanation. Although, It took novice-me quite some time to dig in and
> digest. V8 is really "pretty large and complex" just as you said. The topic
> of V8 deserve full-time dedication in order to catch up. So, for now I am
> happy with the little bit of under the hood knowledge I just obtain. Just
> FYI, your fix for my code to mitigate the V8 bug works flawlessly. Just to
> check if my understanding of the 42 check is correct, I modify it a little
> bit (shorter, less typing):
>
> function printST(x) {
> if(!x) {
> return printST(1);
> }
> var obj = {};
> Error.captureStackTrace(obj, printST);
> log('\tStack length: ' + obj.stack.length);
> }
>
> It also works just like your fix. Any chance the C++ fix (not the JS above)
> going to upstream Node.js, or better V8?

I don't think I have time to work on it myself but if someone wants to
take a stab, I'll be happy to review their work.

> I am interested in call stack (also stack trace API) because I am writing a
> module (for my private project) that organize and execute a arbitrary long
> sequence of functions, using next() callback to signal completion at each
> one, inspired by Connect pipeline. But my module encourage both sync and
> async style of continuation. Therefore, I want to find a way to mitigate
> call stack growth potential problem when doing sync. And also a way to
> correctly test it if I could figure out a solution (It's a work in progress
> though).
>
> I thought of using nextTick() as a fast and reliable built-in trampoline (to
> eliminate tail-call). But what I think I need is a way to insert a function
> to the head of the queue (like stack), not the back as nextTick() does. The
> queue output direction remains the same. The rationale is that I want to
> ensure the next function will always be executed right after the current
> one, but before everything else. Do you have any advice on this?

I'm not quite sure what "before everything else" means here but what I
think you are asking is whether callbacks / continuations should run
in FIFO or LIFO order?  That's up to you, really, but if
process.nextTick()'s FIFO order doesn't work for you, you can always
implement LIFO on top of that.  E.g.:

  var fs = [];
  function cont(f) {
    if (fs.unshift(f) === 1) process.nextTick(function() {
      fs.splice(0, fs.length).forEach(function(f) { f(); });
    });
  }

Aside, ES6 will have proper tail recursion optimization (TCO) but I
don't think that has been implemented in V8 so far.

> Lastly, a tiny problem, any ideas why my code kept not being highlighted
> although I used the "Highlight code syntax" button before entering it? It
> annoys and also embarrasses me to post my code for others to see but have no
> highlight.

I don't know, I don't use the web interface.  I wouldn't worry about it, though.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAHQurc97bddJ90S73%3D%3D3mM1HcRgrkBrLR6wHvnWwJny%3DhZGFQA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to