mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-27 18:38:49 +00:00
Adding self checks in toll free bridged objects so that they are subclassable.
This commit is contained in:
1 parent
e704d42adb
commit
a09878dcb4
6 files changed
+64
No files matched your search
@@ -108,6 +108,7 @@ CPEnumerationReverse = 1 << 1;
|
||||
*/
|
||||
+ (id)alloc
|
||||
{
|
||||
if ([self class] !== CPArray && [self class] !== CPMutableArray) return [super alloc];
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
*/
|
||||
+ (id)alloc
|
||||
{
|
||||
if ([self class] !== CPDictionary && [self class] !== CPMutableDictionary) return [super alloc];
|
||||
return new CFMutableDictionary();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ if (input == nil)
|
||||
*/
|
||||
+ (id)alloc
|
||||
{
|
||||
if ([self class] !== CPException) return [super alloc];
|
||||
return new Error();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ var __placeholder = new Number(),
|
||||
|
||||
+ (id)alloc
|
||||
{
|
||||
if ([self class] !== CPNumber) return [super alloc];
|
||||
return __placeholder;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ var CPStringRegexSpecialCharacters = [
|
||||
*/
|
||||
+ (id)alloc
|
||||
{
|
||||
if ([self class] !== CPString) return [super alloc];
|
||||
return new String;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
@implementation SubclassTollFreeTest : OJTestCase
|
||||
|
||||
- (void)testThatSubclassTollFreeDoesAllowForSubclassing
|
||||
{
|
||||
[OJAssert assert:@"a" equals:[[[MyDict alloc] init] newMessage]];
|
||||
[OJAssert assert:@"a" equals:[[[MyString alloc] init] newMessage]];
|
||||
[OJAssert assert:@"a" equals:[[[MyNum alloc] init] newMessage]];
|
||||
[OJAssert assert:@"a" equals:[[[MyException alloc] init] newMessage]];
|
||||
[OJAssert assert:@"a" equals:[[[MyArray alloc] init] newMessage]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@import <Foundation/CPDictionary.j>
|
||||
|
||||
@implementation MyDict : CPDictionary
|
||||
|
||||
- (id)newMessage
|
||||
{
|
||||
return "a";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MyNum : CPNumber
|
||||
|
||||
- (id)newMessage
|
||||
{
|
||||
return "a";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MyString : CPString
|
||||
|
||||
- (id)newMessage
|
||||
{
|
||||
return "a";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MyException : CPException
|
||||
|
||||
- (id)newMessage
|
||||
{
|
||||
return "a";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MyArray : CPArray
|
||||
|
||||
- (id)newMessage
|
||||
{
|
||||
return "a";
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user