Maximum call stack size exceeded error

后端 未结 30 2574
独厮守ぢ
独厮守ぢ 2020-11-21 23:51

I am using a Direct Web Remoting (DWR) JavaScript library file and am getting an error only in Safari (desktop and iPad)

It says

Maximum call

相关标签:
30条回答
  • 2020-11-22 00:35

    We recently added a field to an admin site we are working on - contact_type... easy right? Well, if you call the select "type" and try to send that through a jquery ajax call it fails with this error buried deep in jquery.js Don't do this:

    $.ajax({
        dataType: "json",
        type: "POST",
        url: "/some_function.php",
        data: { contact_uid:contact_uid, type:type }
    });
    

    The problem is that type:type - I believe it is us naming the argument "type" - having a value variable named type isn't the problem. We changed this to:

    $.ajax({
        dataType: "json",
        type: "POST",
        url: "/some_function.php",
        data: { contact_uid:contact_uid, contact_type:type }
    });
    

    And rewrote some_function.php accordingly - problem solved.

    0 讨论(0)
  • 2020-11-22 00:36

    Check if you have a function that calls itself. For example

    export default class DateUtils {
      static now = (): Date => {
        return DateUtils.now()
      }
    }
    
    0 讨论(0)
  • 2020-11-22 00:38

    I had this error because I had two JS Functions with the same name

    0 讨论(0)
  • 2020-11-22 00:39

    In my case, I was converting a large byte array into a string using the following:

    String.fromCharCode.apply(null, new Uint16Array(bytes))
    

    bytes contained several million entries, which is too big to fit on the stack.

    0 讨论(0)
  • 2020-11-22 00:40

    This can also cause a Maximum call stack size exceeded error:

    var items = [];
    [].push.apply(items, new Array(1000000)); //Bad
    

    Same here:

    items.push(...new Array(1000000)); //Bad
    

    From the Mozilla Docs:

    But beware: in using apply this way, you run the risk of exceeding the JavaScript engine's argument length limit. The consequences of applying a function with too many arguments (think more than tens of thousands of arguments) vary across engines (JavaScriptCore has hard-coded argument limit of 65536), because the limit (indeed even the nature of any excessively-large-stack behavior) is unspecified. Some engines will throw an exception. More perniciously, others will arbitrarily limit the number of arguments actually passed to the applied function. To illustrate this latter case: if such an engine had a limit of four arguments (actual limits are of course significantly higher), it would be as if the arguments 5, 6, 2, 3 had been passed to apply in the examples above, rather than the full array.

    So try:

    var items = [];
    var newItems = new Array(1000000);
    for(var i = 0; i < newItems.length; i++){
      items.push(newItems[i]);
    }
    
    0 讨论(0)
  • 2020-11-22 00:40

    In my case I by mistake i have assigned same variable name , and to val function "class_routine_id"

    var class_routine_id = $("#class_routine_id").val(class_routine_id);
    

    it should be Like :

     var class_routine_id = $("#class_routine_id").val(); 
    
    0 讨论(0)
提交回复
热议问题