Prototype breaks the IE8 native JSON parser.

79 views
Skip to first unread message

Joel

unread,
Aug 19, 2009, 4:58:09 PM8/19/09
to Prototype & script.aculo.us
See the following URL for all the gory details:

http://stackoverflow.com/questions/1288962/ie8-native-json-parse-prototype-stack-overflow

But to sum up, the following test case will get an "out of stack
space" error in IE8 when it is running in IE8 Standards mode (you can
check the mode by hitting F12 for the Developer Tools). If you comment
out either the Function.prototype line or the Array.prototype line,
you won't get the error.

Because Prototype adds functions to both Array.prototype and
Function.prototype, pages that use Prototype will get the "out of
stack space" error whenever they try to use the native JSON parser to
parse some JSON that contains an array. But only if they pass a
"reviver" function to the JSON.parse() method. Which, unfortunately,
is pretty common in order to handle dates.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">

Function.prototype.test1 = function() { };
Array.prototype.test2 = function() { };

window.onload = function()
{
alert(JSON.parse('{ "foo": [1,2,3] }', function(k,v) { return
v; }));
}

</script>
</head>
<body>

</body>
</html>

T.J. Crowder

unread,
Aug 20, 2009, 4:53:35 AM8/20/09
to Prototype & script.aculo.us
Hi,

Wait! Stop the presses, are you saying IE8 has...a bug in it? ;-)
(Oh, I shouldn't be mean to Microsoft, all browsers have bugs in them,
and they seem to have made quite an effort in IE8.)

Have you reported the bug to Microsoft?

Seriously, though, thank you for doing the research to why it breaks
and posting the info here, very very useful -- I'm sure you just saved
the core team a fair bit of time hunting this down.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 19, 9:58 pm, Joel <joel.muel...@gmail.com> wrote:
> See the following URL for all the gory details:
>
> http://stackoverflow.com/questions/1288962/ie8-native-json-parse-prot...

Tobie Langel

unread,
Aug 20, 2009, 8:04:12 AM8/20/09
to Prototype & script.aculo.us
This is a Prototype bug and will be fixed in version 1.7.

In the meantime, please use Object.toJSON(...) instead.

Best,

Tobie

T.J. Crowder

unread,
Aug 20, 2009, 10:12:57 AM8/20/09
to Prototype & script.aculo.us
Tobie,

What's the issue #? I'm curious how Prototype can work around this
IE8 behavior...

Cheers,

-- T.J.
Reply all
Reply to author
Forward
0 new messages