mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-01 02:42:03 +00:00
* Move type checking to debug.js.
* Use JSON.stringify for serializing types array. * Print Objective-J objects' names instead of descriptions to prevent inf recursion.
This commit is contained in:
1 parent
9b99457871
commit
d7b679dc78
3 files changed
+82
-82
No files matched your search
@@ -171,3 +171,84 @@ function objj_profileEnd()
|
||||
|
||||
return objj_profile_cleanup();
|
||||
}
|
||||
|
||||
|
||||
// Type checking version of objj_msgSend:
|
||||
|
||||
function objj_msgSendTypeCheck(/*id*/ aReceiver, /*SEL*/ aSelector)
|
||||
{
|
||||
if (aReceiver == nil)
|
||||
return nil;
|
||||
|
||||
CLASS_GET_METHOD_IMPLEMENTATION(var implementation, aReceiver.isa, aSelector);
|
||||
|
||||
var types = method.types;
|
||||
|
||||
for (var i = 2; i < arguments.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
runtimeTypeCheck(types[i-1], arguments[i]);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
objj_fprintf(warning_stream, "Type check failure: "+
|
||||
"aReceiver="+(aReceiver.isa ? "<"+aReceiver.isa.name+">" : String(aReceiver).substring(0,100))+", "+
|
||||
"aSelector="+String(aSelector).substring(0,100)+", "+
|
||||
"argument #"+(i-2)+": " + e);
|
||||
}
|
||||
}
|
||||
|
||||
var result = implementation.apply(aReceiver, arguments);
|
||||
|
||||
try
|
||||
{
|
||||
runtimeTypeCheck(types[0], result);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
objj_fprintf(warning_stream, "Type check failure: "+
|
||||
"aReceiver="+(aReceiver.isa ? "<"+aReceiver.isa.name+">" : String(aReceiver).substring(0,100))+", "+
|
||||
"aSelector="+String(aSelector).substring(0,100)+", "+
|
||||
"return value: " + e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function runtimeTypeCheck(typeName, actual)
|
||||
{
|
||||
var objjClass;
|
||||
|
||||
if (!typeName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (typeName === "id")
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (typeName === "void")
|
||||
{
|
||||
if (actual === undefined)
|
||||
return;
|
||||
}
|
||||
else if (objjClass = objj_getClass(typeName))
|
||||
{
|
||||
if (actual && actual.isa)
|
||||
{
|
||||
var theClass = actual.isa;
|
||||
for(; theClass; theClass = theClass.super_class)
|
||||
if (theClass === objjClass)
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
throw("Expected " + typeName + ", was [" + ((actual && actual.isa) ? "<"+actual.isa.name+">" : actual) +"]");
|
||||
}
|
||||
|
||||
objj_msgSend = objj_msgSendTypeCheck;
|
||||
@@ -655,7 +655,7 @@ objj_preprocessor.prototype.method = function(tokens)
|
||||
|
||||
CONCAT(buffer, ")\n{ with(self)\n{");
|
||||
CONCAT(buffer, this.preprocess(tokens, NULL, TOKEN_CLOSE_BRACE, TOKEN_OPEN_BRACE));
|
||||
CONCAT(buffer, "}\n},"+types.toSource()+")");
|
||||
CONCAT(buffer, "}\n},"+JSON.stringify(types)+")");
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -542,84 +542,3 @@ function sel_registerName(aName)
|
||||
{
|
||||
return aName;
|
||||
}
|
||||
|
||||
|
||||
// Type checking version of objj_msgSend:
|
||||
|
||||
function objj_msgSendTypeCheck(/*id*/ aReceiver, /*SEL*/ aSelector)
|
||||
{
|
||||
if (aReceiver == nil)
|
||||
return nil;
|
||||
|
||||
CLASS_GET_METHOD_IMPLEMENTATION(var implementation, aReceiver.isa, aSelector);
|
||||
|
||||
var types = method.types;
|
||||
|
||||
for (var i = 2; i < arguments.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
runtimeTypeCheck(types[i-1], arguments[i]);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
objj_fprintf(warning_stream, "Type check failure: "+
|
||||
"aReceiver="+String(aReceiver).substring(0,100)+", "+
|
||||
"aSelector="+String(aSelector).substring(0,100)+", "+
|
||||
"argument #"+(i-2)+": " + e);
|
||||
}
|
||||
}
|
||||
|
||||
var result = implementation.apply(aReceiver, arguments);
|
||||
|
||||
try
|
||||
{
|
||||
runtimeTypeCheck(types[0], result);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
objj_fprintf(warning_stream, "Type check failure: "+
|
||||
"aReceiver="+String(aReceiver).substring(0,100)+", "+
|
||||
"aSelector="+String(aSelector).substring(0,100)+", "+
|
||||
"return value: " + e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function runtimeTypeCheck(typeName, actual)
|
||||
{
|
||||
var objjClass;
|
||||
|
||||
if (!typeName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (typeName === "id")
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (typeName === "void")
|
||||
{
|
||||
if (actual === undefined)
|
||||
return;
|
||||
}
|
||||
else if (objjClass = objj_getClass(typeName))
|
||||
{
|
||||
if (actual && actual.isa)
|
||||
{
|
||||
var theClass = actual.isa;
|
||||
for(; theClass; theClass = theClass.super_class)
|
||||
if (theClass === objjClass)
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
throw("Expected " + typeName + ", was [" + actual +"]");
|
||||
}
|
||||
|
||||
objj_msgSend = objj_msgSendTypeCheck;
|
||||
Reference in new issue
Block a user