Array.prototype.join with cycles

Brandon Benvie brandon at brandonbenvie.com
Mon Dec 24 08:25:19 PST 2012


Given the following:

var x = [1,2,3];
x.push(x);
x+"";

What should happen? The behavior demonstrated by V8, Spidermonkey, and
Chakra (haven't tested others) is to return the empty string for cycles,
thus returning the result '1,2,3,'. However, unless I'm missing something,
this behavior is unspecified and an equally valid result would be to
infinitely loop or throw a recursion error.

For comparison, JSON.stringify explicitly specifies how to handle recursion.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121224/34e8e9a7/attachment.html>


More information about the es-discuss mailing list