diff --git a/Objective-J/Debug.js b/Objective-J/Debug.js index b22493dc0..c0102193d 100644 --- a/Objective-J/Debug.js +++ b/Objective-J/Debug.js @@ -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 diff --git a/Tests/Objective-J/DebugTest.j b/Tests/Objective-J/DebugTest.j new file mode 100644 index 000000000..d48daa5fb --- /dev/null +++ b/Tests/Objective-J/DebugTest.j @@ -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