Fixed: crash on -CPArray/CPDictionary description if a value was the window object.

Without this fix, code like `[@{ "a": window } description]` would crash with a "Maximum call stack size exceeded" exception.

Now`CPDescriptionOfObject()` function simply describes the window object as `window` rather than trying to serialise it into a huge description string.
This commit is contained in:
Alexander Ljungberg
2013-06-13 19:19:22 +01:00
parent d3a44cbc63
commit 22905745f1
2 changed files with 13 additions and 1 deletions
+3
View File
@@ -544,6 +544,9 @@ function CPDescriptionOfObject(anObject)
if (anObject === undefined)
return "undefined";
if (anObject === window)
return "window";
if (anObject.isa)
{
if ([anObject isKindOfClass:CPString])
+10 -1
View File
@@ -389,7 +389,7 @@
- (void)testJSObjectDescription
{
var dict = [[CPDictionary alloc] initWithObjects:[CGRectMake(1, 2, 3, 4), CGPointMake(5, 6)] forKeys:[@"key1", @"key2"]],
var dict = @{ "key1": CGRectMake(1, 2, 3, 4), "key2": CGPointMake(5, 6) },
d = [dict description];
[self assertTrue:d.indexOf("(1, 2)") !== -1 message:"Can't find '(1, 2)' in description of dictionary " + d];
@@ -399,6 +399,15 @@
[self assert:'@{\n @"key1": @[\n @"1",\n @"2",\n @"3"\n ],\n @"key2": @"This is a string",\n @"key3": @{\n @"another": @"object"\n }\n}' equals:[json_dict description]];
}
- (void)testWindowJSObjectDescription
{
var dict = @{ "Key": window };
// 'window' is the global namespace so we should never try to fully describe it. If we do, we're likely
// to get into an infinite loop, and even if we don't it'll be huge.
[self assert:'@{\n @"Key": window\n}' equals:[dict description]];
}
- (void)testInitWithObjectsAndKeys
{
var dict = [[CPDictionary alloc] initWithObjectsAndKeys:@"Value1", @"Key1", nil, @"Key2", @"Value3", @"Key3"];