wisemapping-open-source/core-js/src/main/javascript/Functions.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

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
*/
$defined = function (obj) {
2011-08-09 06:45:24 +02:00
return (obj != undefined);
};
$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
};
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 {
throw Error("Unexpected Exception");
2012-09-13 01:18:19 +02:00
} catch (e) {
exception = e;
}
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
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-09-23 02:34:43 +02:00
window.errorStack = result;
return result;
}
// Support for Windows ...
if (!window.console) {
console = {
log:function (e) {
}
};
}