最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - google script (JS) - maximum recursion depth - Stack Overflow

programmeradmin8浏览0评论

What is the maximum recursion depth in Google Apps Script scripts? I have a function, match_recurse, which looks like the following pseudocode:

function match_recurse(array) {
  for (i=0, i<3, i++) {
    var arr2 = array.copy().push(i);
    if (is_done(arr2)) break;
    match_recurse(arr2);
  }
}

(It also returns its results, but I don't want to bloat the question.)

Now, because the execution errored, the execution transcript and the logs were not saved, so I have no way of knowing whether my is_done function is doing its job wrong. I can do a few cases of the problem on paper and check recursion depth, but I don't know what the maximum is supposed to be.

Looking on the web, I saw an article mentioning that IE has a max call stack of 13 if you go through the Window object, but nothing else.

What is the maximum recursion depth in Google Apps Script scripts? I have a function, match_recurse, which looks like the following pseudocode:

function match_recurse(array) {
  for (i=0, i<3, i++) {
    var arr2 = array.copy().push(i);
    if (is_done(arr2)) break;
    match_recurse(arr2);
  }
}

(It also returns its results, but I don't want to bloat the question.)

Now, because the execution errored, the execution transcript and the logs were not saved, so I have no way of knowing whether my is_done function is doing its job wrong. I can do a few cases of the problem on paper and check recursion depth, but I don't know what the maximum is supposed to be.

Looking on the web, I saw an article mentioning that IE has a max call stack of 13 if you go through the Window object, but nothing else.

Share Improve this question asked Oct 18, 2012 at 1:34 VerdantOzarkVerdantOzark 2,4911 gold badge26 silver badges36 bronze badges 1
  • Thanks, answerers. From the size of the 1000 number, I can see that it was indeed a bug in my stopping condition that I fixed somehow (because the code works now). Thanks – VerdantOzark Commented Oct 20, 2012 at 5:23
Add a ment  | 

2 Answers 2

Reset to default 4

It is 1000, as one can see from here:

function recurse(i) {
  var i = i || 1;
  try {
    recurse(i+1);
  } catch (e) {
    Logger.log(i);
  }
}

The stack depth value is not documented. Executing the following code shows that this value is equal to 1000.

function getStackDepth(curvalue) {
  try {
    curvalue = getStackDepth(curvalue) + 1;
  }
  catch(err) {
  }
  return curvalue;
}

function test() {
  var depth = getStackDepth(2);
  debugger;
}
发布评论

评论列表(0)

  1. 暂无评论