IE8 native JSON.parse bug causes stack overflow

前端 未结 6 1182
生来不讨喜
生来不讨喜 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:22

    A solution is to remove the native JSON.parse on IE8 and replace it with the JSON.parse from the json2.js lib:

    Add:

    
    

    This will trigger json2 to replace the JSON.parse with its own version

    // json2.js
    ...
    if (typeof JSON.parse !== 'function') {
        JSON.parse = function (text, reviver) {
    ...
    

    After that the parse should work again.

    One problem with this approach is that the json2.js parse method is slower than the native one.

提交回复
热议问题