mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-16 07:31:28 +00:00
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:
@@ -544,6 +544,9 @@ function CPDescriptionOfObject(anObject)
|
||||
if (anObject === undefined)
|
||||
return "undefined";
|
||||
|
||||
if (anObject === window)
|
||||
return "window";
|
||||
|
||||
if (anObject.isa)
|
||||
{
|
||||
if ([anObject isKindOfClass:CPString])
|
||||
|
||||
@@ -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"];
|
||||
|
||||
Reference in New Issue
Block a user