title: JavaScript Function eval() throwing an out-of-stack quota exception
body: <p>Recently I ran into a problem: Valid JSON when passed to the <code>eval()</code> function causes it to throw the error -- "script stack space quota is exhausted".</p>
  
  <p>It is consistently reproducible, and through initial examination, it seems that this is a limitation on the number of object attributes/properties that can be defined (and not the size of the content).</p>
  
  <p>Here's the sample code:</p>
  
  <pre><code>function starttest()
  {      
         var d = new Array(50000);
         var i = 0;
  
         for (i = 0; i &lt; d.length; i++) {
              d[i] = new Object();
              d[i].a1 = 1;
              d[i].a2 = 2;
              d[i].a3 = i;
              d[i].a4 = i;
              d[i].a5 = i;
              d[i].a6 = i;
              d[i].a7 = i;
              d[i].a8 = i;
              d[i].a9 = i;
              d[i].a10 = i;
              d[i].a11 = i;
              d[i].a12 = i;
              d[i].a13 = i;
              d[i].a14 = i;
              d[i].a15 = i;
         }       
  
  
  
      var jsonString = JSON.stringify(d);  
      alert(jsonString.length);
  
      var obj = eval(jsonString);
      var count = 0;
      for( var i = 0; i&lt; obj.length; i++) {
  
          for (var k in obj[i]) {
              if (obj[i].hasOwnProperty(k)) {
                 ++count;
              }
          }
      }
  
      alert("Done! || Len: " + obj.length + " || " + "Attrib Count: " + count + " || " + typeof obj)
  }
  </code></pre>
  
  <p>The funny thing is I can define many more objects than seen in the code snippet; the problem arises only when using the <code>eval()</code> function.</p>
  
  <p>Any new insights into this would be greatly helpful. I know using <code>eval()</code> is not safe, and all... and I'm open to suggestions!</p>