Fixed: objj_msgSend_reset not resetting with fast objj_msgSend.

Refs #2103.
This commit is contained in:
Alexander Ljungberg
2014-06-22 14:29:40 +01:00
parent 5fafc97bc0
commit ea3adc44fd
2 changed files with 83 additions and 0 deletions
+11
View File
@@ -58,6 +58,17 @@ GLOBAL(objj_msgSend_reset) = function()
objj_msgSendFast1 = objj_msgSendFast1_original;
objj_msgSendFast2 = objj_msgSendFast2_original;
objj_msgSendFast3 = objj_msgSendFast3_original;
objj_enumerateClassesUsingBlock(function(aClass) {
if (aClass.hasOwnProperty("objj_msgSend"))
{
aClass.objj_msgSend = objj_msgSendFast;
aClass.objj_msgSend0 = objj_msgSendFast0;
aClass.objj_msgSend1 = objj_msgSendFast1;
aClass.objj_msgSend2 = objj_msgSendFast2;
aClass.objj_msgSend3 = objj_msgSendFast3;
}
});
}
// decorate both objj_msgSend and objj_msgSendSuper
+72
View File
@@ -0,0 +1,72 @@
var SEEN_MESSAGES = [];
objj_test_decorator = function(msgSend)
{
return function(aReceiverOrSuper, aSelector)
{
if (aSelector === @selector(intify:))
SEEN_MESSAGES.push([aReceiverOrSuper, aSelector]);
return msgSend.apply(this, arguments);
};
}
@implementation TestClass0 : CPObject
- (CPInteger)intify:(CPInteger)anInput
{
return anInput * 2; // now twice as int
}
@end
@implementation TestClass1 : CPObject
- (CPInteger)intify:(CPInteger)anInput
{
return anInput * 2; // now twice as int
}
@end
@implementation DebugTest : OJTestCase
- (void)setUp
{
SEEN_MESSAGES = [];
}
- (void)tearDown
{
objj_msgSend_reset();
}
- (void)test_objj_msgSend_decorate_should_replace_fast_msgSend_for_unitialised_class
{
objj_msgSend_decorate(objj_test_decorator);
var a = [TestClass0 new];
[self assert:[a intify:3] equals:6];
[self assert:SEEN_MESSAGES equals:[[a, @selector(intify:)]]];
}
- (void)test_objj_msgSend_decorate_should_replace_fast_msgSend_for_initialised_class
{
var a = [TestClass1 new];
[a intify:5];
objj_msgSend_decorate(objj_test_decorator);
[self assert:[a intify:3] equals:6];
[self assert:SEEN_MESSAGES equals:[[a, @selector(intify:)]]];
}
- (void)test_objj_msgSend_reset_should_reset
{
objj_msgSend_decorate(objj_test_decorator);
var a = [TestClass1 new];
[self assert:[a intify:3] equals:6];
objj_msgSend_reset();
[self assert:[a intify:3] equals:6];
[self assert:SEEN_MESSAGES equals:[[a, @selector(intify:)]]];
}
@end