mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-26 16:14:56 +01:00
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
/*
|
|
Function: $defined
|
|
Returns true if the passed in value/object is defined, that means is not null or undefined.
|
|
|
|
Arguments:
|
|
obj - object to inspect
|
|
*/
|
|
|
|
global.$defined = function (obj) {
|
|
return (obj != undefined);
|
|
};
|
|
|
|
|
|
global.$assert = function (assert, message) {
|
|
if (!$defined(assert) || !assert) {
|
|
logStackTrace();
|
|
console.log(message);
|
|
throw new Error(message);
|
|
}
|
|
};
|
|
|
|
Math.sign = function (value) {
|
|
return (value >= 0) ? 1 : -1;
|
|
};
|
|
|
|
function logStackTrace(exception) {
|
|
|
|
if (!$defined(exception)) {
|
|
try {
|
|
throw Error("Unexpected Exception");
|
|
} catch (e) {
|
|
exception = e;
|
|
}
|
|
}
|
|
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";
|
|
|
|
var currentFunction = arguments.callee.caller;
|
|
while (currentFunction) {
|
|
var fn = currentFunction.toString();
|
|
result = result + "\n" + fn;
|
|
currentFunction = currentFunction.caller;
|
|
}
|
|
}
|
|
window.errorStack = result;
|
|
return result;
|
|
}
|