Description methods in CPArray and CPDictionary will display JavaScript object attributes instead of displaying [Object object]

Don't you hate when your logs of arrays and dictionaries display [Object object] when you have JavaScript objects in them.
Now with this patch all JavaScript objects will be display with all attributes in a nice good looking way. Log CGRect, CGPoint
and other JavaScript objects withour any hassle anymore. For example: console.log([myRect]);
This commit is contained in:
Martin Carlberg
2012-05-11 17:40:11 +02:00
parent c437537749
commit 70182a0ea2
2 changed files with 26 additions and 3 deletions
+12 -1
View File
@@ -807,7 +807,18 @@ var concat = Array.prototype.concat,
description += '\n';
var object = [self objectAtIndex:index],
objectDescription = object && object.isa ? [object description] : String(object);
desc = object;
if (object && typeof(object) === "object" && !object.isa)
{
desc = "JSObject\n{\n";
for (var property in object)
{
if (object.hasOwnProperty(property))
desc += " " + property + ":" + object[property] + "\n";
}
desc += "}";
}
var objectDescription = object && object.isa ? [object description] : String(desc);
description += "\t" + objectDescription.split('\n').join("\n\t");
+14 -2
View File
@@ -142,9 +142,21 @@ CFDictionary.prototype.toString = function()
for (; index < count; ++index)
{
var key = keys[index];
var key = keys[index],
value = this.valueForKey(key),
description = value;
if (value && typeof(value) === "object" && !value.isa)
{
description = "JSObject\n{\n";
for (var property in value)
{
if (value.hasOwnProperty(property))
description += " " + property + ":" + value[property] + "\n";
}
description += "}";
}
string += "\t" + key + " = \"" + String(this.valueForKey(key)).split('\n').join("\n\t") + "\"\n";
string += "\t" + key + " = \"" + String(description).split('\n').join("\n\t") + "\"\n";
}
return string + "}";