-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientThreads-0.1.1.min.js
1 lines (1 loc) · 2.61 KB
/
ClientThreads-0.1.1.min.js
1
ClientThreads=function(){var _WSTR="",_CONV,_WRKR,CT;return _CONV={is:{object:function(t){return"object"==typeof t},array:function(t){return!!Array.isArray(t)},string:function(t){return"string"==typeof t},function:function(t){return"function"==typeof t},functionInTxt:function(t){return"string"==typeof t&&0==t.search(/^\s*function/i)}},codeToTxt:function(t){function r(t){if(e.is.object(t)){if(e.is.array(t)){for(var n=t.length;n--;)e.is.function(t[n])&&(t[n]=t[n].toString()),e.is.object(t[n])&&(t[n]=r(t[n]));return t}for(var o in t)e.is.function(t[o])&&(t[o]=t[o].toString()),e.is.object(t[o])&&(t[o]=r(t[o]));return t}}var e=this;switch(typeof t){case"function":return t.toString();case"object":return r(t);default:return t}},txtToCode:function(arg,thread){function rcrsvSrch(arg){if(that.is.object(arg)){if(that.is.array(arg)){for(var i=arg.length;i--;)that.is.functionInTxt(arg[i])&&(arg[i]=eval("("+arg[i]+")")),that.is.object(arg[i])&&(arg[i]=rcrsvSrch(arg[i]));return arg}for(var x in arg)that.is.functionInTxt(arg[x])&&(arg[x]=eval("("+arg[x]+")")),that.is.object(arg[x])&&(arg[x]=rcrsvSrch(arg[x]));return arg}}var that=this;switch(typeof arg){case"string":return that.is.functionInTxt(arg)?eval("("+arg+")"):arg;case"object":return rcrsvSrch(arg);default:return arg}}},_WRKR={thread:{},init:function(t){var r=_CONV,e=this,n=!1;addEventListener("message",function(t){if(n){var o=r.txtToCode(t.data);e.thread.onMessage(o,t)}else{e.thread.arguments=r.txtToCode(t.data.args,e.thread),e.thread.is=r.is,e.thread.onMessage=function(t,r){},e.thread.close=function(){close()},e.thread.postMessage=function(t){t&&postMessage(r.codeToTxt(t))};var i=r.txtToCode(t.data.func,e.thread),a=i(t);a&&postMessage(r.codeToTxt(a)),n=!0}},!1)}},CT=function(t,r,e,n){if(!(this instanceof CT))return new CT(t,r,e,n);this.is=_CONV.is,_WSTR||(_WSTR=this.objToTxt(_CONV,"_CONV"),_WSTR+=this.objToTxt(_WRKR,"_WRKR"),_WSTR+="_WRKR.init();");var o=new Blob([_WSTR]),i=window.URL.createObjectURL(o);this.worker=new Worker(i),e&&this.worker.addEventListener("message",function(t){var r=_CONV.txtToCode(t.data);e(r,t)},!1),n||(n=function(t){console.log("ErrorMsg: "+t.message+"\nFile Name: "+t.filename+"\nLine: "+t.lineno)}),this.worker.addEventListener("error",n,!1),this.worker.postMessage({args:_CONV.codeToTxt(t),func:_CONV.codeToTxt(r)})},CT.prototype.objToTxt=function(t,r,e){var n,o=[];for(n in t)t.hasOwnProperty(n)&&(this.is.object(t[n])?o.push(this.objToTxt(t[n],n,":")):o.push(n+":"+t[n]));return e||(e="="),r+e+"{"+o.join(",")+"}\n"},CT.prototype.close=function(){this.worker.terminate()},CT.prototype.postMessage=function(t){this.worker.postMessage(_CONV.codeToTxt(t))},CT}();