Trouble with eval() and main(_)

44 views
Skip to first unread message

Samuli Kärkkäinen

unread,
Nov 5, 2012, 5:28:22 AM11/5/12
to stream...@googlegroups.com
The following program works as expected, printing "1":

console.log(1);
eval("true");
function main() {}
main();

However if I include _ in the function  call, that is, I run the following:

console.log(1);
eval("true");
function main() {}
main(_);

The output is first

1

about 3500 times, then

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
raw stack unavailable
    at main (.../test._js:4:0)


And then the last line some 3500 times more. If I now rename main as mainx (without removing the _ argument) things still work.

Node.js v0.6.12 on Ubuntu 12.04 64bit, Streamline v0.4.5.

Bruno Jouhier

unread,
Nov 5, 2012, 4:15:29 PM11/5/12
to stream...@googlegroups.com
Wow, this is a vicious one!

The main (!) problem comes from the fact that streamline encapsulates the whole script into a function called "main". It should be an anonymous function instead. This is easy to fix.

What baffles me is the influence of the `eval` call. I tried the following:

(function a() {
    function a() {}
    // eval("true");
    console.log(a.toString())
})();

It prints the empty inner `a` function but if you uncomment the `eval` line, it prints the outer `a` function. A bit beyond my grasp! The explanation must be somewhere in the eval specs.

Bruno

Aseem Kishore

unread,
Nov 5, 2012, 6:56:06 PM11/5/12
to stream...@googlegroups.com
That (the eval effect) is insane. Definitely a candidate for #wtfjs. =)


Bruno, you should have the honor of submitting that. =D

Samuli Kärkkäinen

unread,
Nov 6, 2012, 5:50:15 AM11/6/12
to stream...@googlegroups.com
It seems that only Chrome (and Node) are doing this. With Firefox and IE9 eval() makes no difference. A bug in Chrome?

Bruno Jouhier

unread,
Nov 6, 2012, 6:11:43 AM11/6/12
to stream...@googlegroups.com
I did the test on Firefox, Safari, Opera and Chrome (on Mac OS X) and I got similar results: the eval() call only makes a difference on Chrome. Looks like a V8 bug. I'm going to post to V8 mailing list.

Bruno Jouhier

unread,
Nov 6, 2012, 6:21:05 AM11/6/12
to stream...@googlegroups.com

Bruno Jouhier

unread,
Nov 6, 2012, 2:38:14 PM11/6/12
to stream...@googlegroups.com
Hi Aseem,

Would have been fun if it had been a JS "feature". But it looks like it is a V8 bug. How boring...
Reply all
Reply to author
Forward
0 new messages