Fix for objj_msgSend_reset errors when running debug.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I committed 2010-02-21 13:10:31 -08:00
1 parent 7433c38d92
commit 0805e58a94
1 file changed
+29 -19
+29 -19
View File
@@ -15,28 +15,30 @@ function objj_debug_message_format(aReceiver, aSelector)
var objj_msgSend_original = objj_msgSend,
objj_msgSendSuper_original = objj_msgSendSuper;
// decorator management functions
// reset to default objj_msgSend* implementations
function objj_msgSend_reset()
GLOBAL(objj_msgSend_reset) = function()
{
objj_msgSend = objj_msgSend_original;
objj_msgSendSuper = objj_msgSendSuper_original;
}
// decorate both objj_msgSend and objj_msgSendSuper
function objj_msgSend_decorate()
GLOBAL(objj_msgSend_decorate) = function()
{
for (var i = 0; i < arguments.length; i++)
var index = 0,
count = arguments.length;
for (; index < count; ++index)
{
objj_msgSend = arguments[i](objj_msgSend);
objj_msgSendSuper = arguments[i](objj_msgSendSuper);
objj_msgSend = arguments[index](objj_msgSend);
objj_msgSendSuper = arguments[index](objj_msgSendSuper);
}
}
// reset then decorate both objj_msgSend and objj_msgSendSuper
function objj_msgSend_set_decorators()
GLOBAL(objj_msgSend_set_decorators) = function()
{
objj_msgSend_reset();
objj_msgSend_decorate.apply(NULL, arguments);
@@ -47,12 +49,20 @@ function objj_msgSend_set_decorators()
var objj_backtrace = [];
function objj_backtrace_print(stream) {
for (var i = 0; i < objj_backtrace.length; i++)
objj_fprintf(stream, objj_debug_message_format(objj_backtrace[i].receiver, objj_backtrace[i].selector));
GLOBAL(objj_backtrace_print) = function(/*Callable*/ aStream)
{
var index = 0,
count = objj_backtrace.length;
for (; index < count; ++index)
{
var frame = objj_backtrace[index];
stream(objj_debug_message_format(frame.receiver, frame.selector));
}
}
function objj_backtrace_decorator(msgSend)
GLOBAL(objj_backtrace_decorator) = function(msgSend)
{
return function(aReceiverOrSuper, aSelector)
{
@@ -67,8 +77,8 @@ function objj_backtrace_decorator(msgSend)
catch (anException)
{
// print the exception and backtrace
objj_fprintf(warning_stream, "Exception " + anException + " in " + objj_debug_message_format(aReceiver, aSelector));
objj_backtrace_print(warning_stream);
CPLog.warn("Exception " + anException + " in " + objj_debug_message_format(aReceiver, aSelector));
objj_backtrace_print(CPLog.warn);
}
finally
{
@@ -83,7 +93,7 @@ function objj_backtrace_decorator(msgSend)
var objj_typechecks_reported = {},
objj_typecheck_prints_backtrace = NO;
function objj_typecheck_decorator(msgSend)
GLOBAL(objj_typecheck_decorator) = function(msgSend)
{
return function(aReceiverOrSuper, aSelector)
{
@@ -104,9 +114,9 @@ function objj_typecheck_decorator(msgSend)
var key = [GETMETA(aReceiver).name, aSelector, i, e].join(";");
if (!objj_typechecks_reported[key]) {
objj_typechecks_reported[key] = YES;
objj_fprintf(warning_stream, "Type check failed on argument " + (i-2) + " of " + objj_debug_message_format(aReceiver, aSelector) + ": " + e);
CPLog.warn("Type check failed on argument " + (i-2) + " of " + objj_debug_message_format(aReceiver, aSelector) + ": " + e);
if (objj_typecheck_prints_backtrace)
objj_backtrace_print(warning_stream);
objj_backtrace_print(CPLog.warn);
}
}
}
@@ -122,9 +132,9 @@ function objj_typecheck_decorator(msgSend)
var key = [GETMETA(aReceiver).name, aSelector, "ret", e].join(";");
if (!objj_typechecks_reported[key]) {
objj_typechecks_reported[key] = YES;
objj_fprintf(warning_stream, "Type check failed on return val of " + objj_debug_message_format(aReceiver, aSelector) + ": " + e);
CPLog.warn("Type check failed on return val of " + objj_debug_message_format(aReceiver, aSelector) + ": " + e);
if (objj_typecheck_prints_backtrace)
objj_backtrace_print(warning_stream);
objj_backtrace_print(CPLog.warn);
}
}
@@ -133,7 +143,7 @@ function objj_typecheck_decorator(msgSend)
}
// type checking logic:
function objj_debug_typecheck(expectedType, object)
GLOBAL(objj_debug_typecheck) = function(expectedType, object)
{
var objjClass;