Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array toString recurses infinitely in case of cycle #107

Closed
bvibber opened this issue Jun 14, 2017 · 1 comment
Closed

Array toString recurses infinitely in case of cycle #107

bvibber opened this issue Jun 14, 2017 · 1 comment

Comments

@bvibber
Copy link
Contributor

bvibber commented Jun 14, 2017

This code:

var a = [], b = [];
a.push(b); b.push(a);
alert(a);

hangs or crashes the interpreter with infinite recursion in the Array toString implementation.

In browsers, cycles in array toString() seem to be broken with empty strings:

var a = [ 'AA', 0, 'AZ' ];
var b = ['BA', 0, 'BZ'];
a[1] = b;
b[1] = a;
alert(a);

should give

AA,BA,,BZ,AZ
@bvibber
Copy link
Contributor Author

bvibber commented Jun 14, 2017

Note that the spec for Array.prototype.join does not reflect this behavior of browsers -- see tc39/ecma262#289 -- but not crashing seems like a good thing. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant