title: AngularJS and D3 - JavaScript RangeError: Maximum call stack size exceeded in recursion
body: <p>SEE EDIT BELOW</p>
  
  <p>I wrote a function to recursively parse solr facet.pivot output and massage it into something I can feed into d3 for a sunburst diagram. Everything works but I am getting one of these and I am not sure how to go about it. </p>
  
  <pre><code>RangeError: Maximum call stack size exceeded
  </code></pre>
  
  <p>Here is the function with some extra statements for readability. </p>
  
  <pre><code>this.get_facet_pivot_sunburst = function(field, data) {
      if (!field) {
          return {};
      } else {
          if (!data) {
              data = response['facet_counts']['facet_pivot'][field];
          }
          var ops = 0;
          var d = parse_facet_pivot(data);    
          console.log("Operations" + ops);
          return d;
      } 
  
      function parse_facet_pivot(data){
        var out = {'name' : 'root', 'children': []};
        for (ob in data) {
          ops++;
          out.children.push(parse_item(data[ob]));
        }
        return out;
      }
  
      function parse_item (doc) {
        ops++;
        var t = {'name' : doc.value, 'size' : doc.count, 'children': []};
        for (piv in doc.pivot) {
          t.children.push(parse_item(doc.pivot[piv]));
        }
        return t;
      }
  }
  </code></pre>
  
  <p>I read online that it may be related to passing a large object to a method or heavy recursion, however I've tried to limit the data to a small subset and I still get this error. In this case, the logger printed 12 as the number of operations, however generally it is between 300-400. </p>
  
  <p>To provide some more background, this runs in an angularjs service, to feed a directive that draws a sunburst using d3. As I mentioned before, the chart gets drawn fine, but I am still getting this.</p>
  
  <p>EDIT:</p>
  
  <p>It looks like the recursion is fine, the problem is somewhere in Angular and D3. Here is a js fiddle that demonstrates the issue (in console log). However, note that in my environment, I am not getting the digest error for some reason. </p>
  
  <p><a href="http://jsfiddle.net/wrdrvr/4c6bju7L/20/" rel="nofollow">http://jsfiddle.net/wrdrvr/4c6bju7L/20/</a></p>