diff --git a/Foundation/CPObject.j b/Foundation/CPObject.j index 5590a2048..d47d522ed 100644 --- a/Foundation/CPObject.j +++ b/Foundation/CPObject.j @@ -532,6 +532,9 @@ CPLog(@"Got some class: %@", inst); function CPDescriptionOfObject(anObject) { + if (!anObject) + return String(anObject); + if (anObject.isa) { if ([anObject isKindOfClass:CPString]) diff --git a/Tests/Foundation/CPObjectTest.j b/Tests/Foundation/CPObjectTest.j index 5b8f487de..926a00238 100644 --- a/Tests/Foundation/CPObjectTest.j +++ b/Tests/Foundation/CPObjectTest.j @@ -50,6 +50,15 @@ [self assertTrue:expectedReturnValue === returnValue]; } +- (void)testCPDescriptionOfObject +{ + var jSON = {"name": "Martin", "access":null}, + d = CPDescriptionOfObject(jSON); + + [self assertTrue:d.indexOf("name:") !== -1 message:"Can't find 'name:' in description of json " + d]; + [self assertTrue:d.indexOf("access:") !== -1 message:"Can't find 'access:' in description of json " + d]; +} + @end @implementation SuperReceiver : CPObject