mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-23 10:50:42 +00:00
Fixed: crash in - CPArray/CPDictionary description containing self referential JS object.
Without this fix, certain JS contents could cause `- CPDictionary description` and `- CPArray description` to crash. This change limits how deeply the description code will recurse before returning a default "…" description.
This commit is contained in:
@@ -37,6 +37,8 @@ CPBinarySearchingFirstEqual = 1 << 8;
|
||||
CPBinarySearchingLastEqual = 1 << 9;
|
||||
CPBinarySearchingInsertionIndex = 1 << 10;
|
||||
|
||||
var CPArrayMaxDescriptionRecursion = 10;
|
||||
|
||||
var concat = Array.prototype.concat,
|
||||
join = Array.prototype.join,
|
||||
push = Array.prototype.push;
|
||||
@@ -874,6 +876,11 @@ var concat = Array.prototype.concat,
|
||||
Returns a human readable description of this array and it's elements.
|
||||
*/
|
||||
- (CPString)description
|
||||
{
|
||||
return [self _descriptionWithMaximumDepth:CPArrayMaxDescriptionRecursion];
|
||||
}
|
||||
|
||||
- (CPString)_descriptionWithMaximumDepth:(int)maximumDepth
|
||||
{
|
||||
var index = 0,
|
||||
count = [self count],
|
||||
@@ -887,7 +894,7 @@ var concat = Array.prototype.concat,
|
||||
var object = [self objectAtIndex:index];
|
||||
|
||||
// NOTE: replace(/^/mg, " ") inserts 4 spaces at the beginning of every line
|
||||
description += CPDescriptionOfObject(object).replace(/^/mg, " ");
|
||||
description += CPDescriptionOfObject(object, maximumDepth).replace(/^/mg, " ");
|
||||
|
||||
if (index < count - 1)
|
||||
description += ",\n";
|
||||
|
||||
Reference in New Issue
Block a user