C
Christopher Benson-Manica
All right, since my previous idea (calling functions through a
wrapper) was apparently so awful no one could suggest any
improvements, I'll try a different tack. My end goal is to make
detecting and reporting script errors easy and painless. This could
be accomplished easily if window.onerror were ubiquitous, but it is
not. My new idea is to hack together something superficially
resembling C's assert() macro, perhaps something like
function assert( expr_as_string, cond ) {
var result=eval( expr_as_string );
if( cond == null ) {
cond=true;
}
if( result != cond ) {
alert( 'Assertion failed: '+expr_as_string+'=='+result+', expected
'+cond );
return false;
}
return true;
}
which would be used like
assert( '5 != 3' ); // true
assert( '5*10 == 3' ); // false
Now obviously this is, again, probably unacceptably obfuscatory.
That's why I'm posting and hoping, desperately, for suggested
improvements and/or other ideas. Surely given the amount of script
that's out there someone has conceived a half-reasonable error checking
framework...
wrapper) was apparently so awful no one could suggest any
improvements, I'll try a different tack. My end goal is to make
detecting and reporting script errors easy and painless. This could
be accomplished easily if window.onerror were ubiquitous, but it is
not. My new idea is to hack together something superficially
resembling C's assert() macro, perhaps something like
function assert( expr_as_string, cond ) {
var result=eval( expr_as_string );
if( cond == null ) {
cond=true;
}
if( result != cond ) {
alert( 'Assertion failed: '+expr_as_string+'=='+result+', expected
'+cond );
return false;
}
return true;
}
which would be used like
assert( '5 != 3' ); // true
assert( '5*10 == 3' ); // false
Now obviously this is, again, probably unacceptably obfuscatory.
That's why I'm posting and hoping, desperately, for suggested
improvements and/or other ideas. Surely given the amount of script
that's out there someone has conceived a half-reasonable error checking
framework...