2011-08-09 06:45:24 +02:00
|
|
|
/*
|
|
|
|
Function: $defined
|
|
|
|
Returns true if the passed in value/object is defined, that means is not null or undefined.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
obj - object to inspect
|
|
|
|
*/
|
|
|
|
|
2012-08-15 04:55:13 +02:00
|
|
|
$defined = function (obj) {
|
2011-08-09 06:45:24 +02:00
|
|
|
return (obj != undefined);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-15 04:55:13 +02:00
|
|
|
$assert = function (assert, message) {
|
2011-08-09 06:45:24 +02:00
|
|
|
if (!$defined(assert) || !assert) {
|
2012-09-23 02:34:43 +02:00
|
|
|
logStackTrace();
|
|
|
|
console.log(message);
|
|
|
|
throw new Error(message);
|
2011-08-09 06:45:24 +02:00
|
|
|
}
|
2012-05-27 23:15:46 +02:00
|
|
|
};
|
|
|
|
|
2012-08-15 04:55:13 +02:00
|
|
|
Math.sign = function (value) {
|
2012-05-27 23:15:46 +02:00
|
|
|
return (value >= 0) ? 1 : -1;
|
|
|
|
};
|
|
|
|
|
2012-09-23 02:34:43 +02:00
|
|
|
function logStackTrace(exception) {
|
2012-09-13 01:18:19 +02:00
|
|
|
|
|
|
|
if (!$defined(exception)) {
|
|
|
|
try {
|
2012-09-20 01:01:22 +02:00
|
|
|
throw Error("Unexpected Exception");
|
2012-09-13 01:18:19 +02:00
|
|
|
} catch (e) {
|
|
|
|
exception = e;
|
2012-06-23 19:39:50 +02:00
|
|
|
}
|
2012-09-13 01:18:19 +02:00
|
|
|
}
|
|
|
|
var result = "";
|
|
|
|
if (exception.stack) { //Firefox and Chrome...
|
|
|
|
result = exception.stack;
|
|
|
|
}
|
|
|
|
else if (window.opera && exception.message) { //Opera
|
|
|
|
result = exception.message;
|
|
|
|
} else { //IE and Safari
|
2012-09-20 01:01:22 +02:00
|
|
|
result = exception.sourceURL + ': ' + exception.line + "\n\n";
|
|
|
|
|
2012-09-13 01:18:19 +02:00
|
|
|
var currentFunction = arguments.callee.caller;
|
|
|
|
while (currentFunction) {
|
|
|
|
var fn = currentFunction.toString();
|
|
|
|
result = result + "\n" + fn;
|
|
|
|
currentFunction = currentFunction.caller;
|
2012-06-23 19:39:50 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-23 02:34:43 +02:00
|
|
|
window.errorStack = result;
|
2012-06-23 19:39:50 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-07-21 14:46:21 +02:00
|
|
|
// Support for Windows ...
|
2012-08-15 04:55:13 +02:00
|
|
|
if (!window.console) {
|
2012-07-21 14:46:21 +02:00
|
|
|
console = {
|
2012-08-15 04:55:13 +02:00
|
|
|
log:function (e) {
|
2012-07-21 14:46:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|