wisemapping-frontend/packages/core-js/lib/Functions.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-07-16 16:41:58 +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
*/
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;
}