New: throw an exception on nil CPDictionary keys and values.

Previously only a deprecation warning was issued. This warning was scheduled to be removed in Cappuccino 0.9.8, this release.
This commit is contained in:
Alexander Ljungberg committed 2015-03-29 13:02:55 +01:00
1 parent ca2fb81247
commit c7770c37d0
1 file changed
+9 -71
+9 -71
View File
@@ -26,10 +26,7 @@
@import "CPNull.j"
@import "CPObject.j"
//FIXME: After release of 0.9.7 remove below variable
var CPDictionaryShowNilDeprecationMessage = YES,
CPDictionaryMaxDescriptionRecursion = 10;
var CPDictionaryMaxDescriptionRecursion = 10;
/*!
@class CPDictionary
@@ -238,28 +235,10 @@ var CPDictionaryShowNilDeprecationMessage = YES,
key = keyArray[i];
if (value === nil)
{
CPDictionaryShowNilDeprecationMessage = NO;
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: Attempt to insert nil object from objects[%d]", [self className], _cmd, i]);
if (typeof(objj_backtrace_print) === "function")
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change this block to:
// [CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil object from objects[" + i + @"]"];
}
[CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil object from objects[" + i + @"]"];
if (key === nil)
{
CPDictionaryShowNilDeprecationMessage = NO;
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: Attempt to insert nil key from keys[%d]", [self className], _cmd, i]);
if (typeof(objj_backtrace_print) === "function")
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change this block to:
// [CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil key from keys[" + i + @"]"];
}
[CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil key from keys[" + i + @"]"];
[self setObject:value forKey:key];
}
@@ -302,28 +281,10 @@ var CPDictionaryShowNilDeprecationMessage = YES,
key = arguments[index + 1];
if (value === nil)
{
CPDictionaryShowNilDeprecationMessage = NO;
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: Attempt to insert nil object from objects[%d]", [self className], _cmd, (index / 2) - 1]);
if (typeof(objj_backtrace_print) === "function")
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change 3 lines above to this:
// [CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil object from objects[" + ((index / 2) - 1) + @"]"];
}
[CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil object from objects[" + ((index / 2) - 1) + @"]"];
if (key === nil)
{
CPDictionaryShowNilDeprecationMessage = NO;
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: Attempt to insert nil key from keys[%d]", [self className], _cmd, (index / 2) - 1]);
if (typeof(objj_backtrace_print) === "function")
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change 3 lines above to this:
// [CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil key from keys[" + ((index / 2) - 1) + @"]"];
}
[CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil key from keys[" + ((index / 2) - 1) + @"]"];
[self setObject:value forKey:key];
}
@@ -634,34 +595,11 @@ var CPDictionaryShowNilDeprecationMessage = YES,
*/
- (void)setObject:(id)anObject forKey:(id)aKey
{
// FIXME: After release of 0.9.7, remove this test and leave the contents of its block
if (CPDictionaryShowNilDeprecationMessage)
{
if (aKey === nil)
{
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: key cannot be nil", [self className], _cmd]);
if (aKey === nil)
[CPException raise:CPInvalidArgumentException reason:@"key cannot be nil"];
if (typeof(objj_backtrace_print) === "function")
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change this block to:
// [CPException raise:CPInvalidArgumentException reason:@"key cannot be nil"];
}
if (anObject === nil)
{
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: object cannot be nil (key: %s)", [self className], _cmd, aKey]);
if (typeof(objj_backtrace_print) === "function")
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change this block to:
// [CPException raise:CPInvalidArgumentException reason:@"object cannot be nil (key: " + aKey + @")"];
}
}
// FIXME: After release of 0.9.7 remove 2 lines below.
else
CPDictionaryShowNilDeprecationMessage = YES;
if (anObject === nil)
[CPException raise:CPInvalidArgumentException reason:@"object cannot be nil (key: " + aKey + @")"];
self.setValueForKey(aKey, anObject);
}