2011-08-09 12:45:24 +08: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 10:55:13 +08:00
|
|
|
$defined = function (obj) {
|
2011-08-09 12:45:24 +08:00
|
|
|
return (obj != undefined);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-15 10:55:13 +08:00
|
|
|
$assert = function (assert, message) {
|
2011-08-09 12:45:24 +08:00
|
|
|
if (!$defined(assert) || !assert) {
|
|
|
|
var stack;
|
|
|
|
try {
|
|
|
|
null.eval();
|
2012-08-15 10:55:13 +08:00
|
|
|
} catch (e) {
|
2011-08-09 12:45:24 +08:00
|
|
|
stack = e;
|
|
|
|
}
|
2011-08-24 01:25:49 +08:00
|
|
|
console.log(message + "," + stack);
|
2012-06-24 01:39:50 +08:00
|
|
|
window.errorStack = stackTrace();
|
2011-08-24 07:56:01 +08:00
|
|
|
throw message;
|
2011-08-09 12:45:24 +08:00
|
|
|
}
|
2012-05-28 05:15:46 +08:00
|
|
|
};
|
|
|
|
|
2012-08-15 10:55:13 +08:00
|
|
|
Math.sign = function (value) {
|
2012-05-28 05:15:46 +08:00
|
|
|
return (value >= 0) ? 1 : -1;
|
|
|
|
};
|
|
|
|
|
2012-09-13 07:18:19 +08:00
|
|
|
function stackTrace(exception) {
|
|
|
|
|
|
|
|
if (!$defined(exception)) {
|
|
|
|
try {
|
|
|
|
throw "Dummy Exception"
|
|
|
|
} catch (e) {
|
|
|
|
exception = e;
|
2012-06-24 01:39:50 +08:00
|
|
|
}
|
2012-09-13 07:18:19 +08: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
|
|
|
|
var currentFunction = arguments.callee.caller;
|
|
|
|
while (currentFunction) {
|
|
|
|
var fn = currentFunction.toString();
|
|
|
|
result = result + "\n" + fn;
|
|
|
|
currentFunction = currentFunction.caller;
|
2012-06-24 01:39:50 +08:00
|
|
|
}
|
|
|
|
}
|
2012-09-13 07:18:19 +08:00
|
|
|
|
2012-06-24 01:39:50 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-07-21 20:46:21 +08:00
|
|
|
// Support for Windows ...
|
2012-08-15 10:55:13 +08:00
|
|
|
if (!window.console) {
|
2012-07-21 20:46:21 +08:00
|
|
|
console = {
|
2012-08-15 10:55:13 +08:00
|
|
|
log:function (e) {
|
2012-07-21 20:46:21 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|