IE8 native JSON.parse bug causes stack overflow

前端 未结 6 1179
生来不讨喜
生来不讨喜 2020-12-13 00:45

TL;DR: Adding any non-built-in functions to Array.prototype AND Function.prototype will cause the IE8 native JSON parser to get a stack overflow when parsing any JSO

6条回答
  •  春和景丽
    2020-12-13 01:01

    It seems to work okay here:

    
    
    
    Test
    
    
    
    
    

    The problem is either a corrupt Internet Explorer 8 install (are you trying to run multiple copies of Internet Explorer on the same Windows install?) or your input is bad.

    You may also want to read Native JSON in IE8. This particular paragraph may be of interest:

    The optional revive argument is a user defined function used for post parse changes. The resulting object or array is traversed recursively, the reviver function is applied to every member. Each member value is replaced with the value returned by the reviver. If the reviver returns null, the object member is deleted. The traversal and the call on reviver are done in postorder. That’s right; every object is ‘revived´ after all its members are ‘revived´.

    The above paragraph explains why my reviver function looks the way it does. My first attempt at test code was:

    function (key, val) {
        return val + '-reviver!';
    }
    

    Obviously if this reviver function is applied to the address node above after being applied to all its children, I've completely destroyed the address object.

    Of course, if the test of your reviver is as simple as you describe in your question, it is unlikely that some global circular reference is leading to the problem you're seeing. I still think it points to a broken Internet Explorer or bad data.

    Can you edit your question and post a sample of actual data that exhibits the problem so I can try it here?

提交回复
热议问题