-
Notifications
You must be signed in to change notification settings - Fork 10
/
stackjs.min.js
7 lines (7 loc) · 3.41 KB
/
stackjs.min.js
1
2
3
4
5
6
7
(function(){var Defaults={defaultObjectName:"STObject",extendsSeperator:"::",stackSize:50};var _classes={};var _exceptionCallbacks={};var report=function(text){var date=new Date;console.log("STACKJS: "+date.toString()+" : "+text)};var parseClassName=function(classStr){var classNameArray=classStr.split(Defaults.extendsSeperator);var className=classNameArray[0];var extend=classNameArray[1];return{name:className,extend:extend}};var Stack={stack:[],push:function(className,methodName){if(Defaults.stackSize==
this.stack.length)this.stack.shift();this.stack.push({className:className,methodName:methodName})},pop:function(){return this.stack.pop()},clear:function(){this.stack=[]},printStackTrace:function(exceptionObject){var traceStr="";for(var i=0;i<this.stack.length;i++){var stackObect=this.stack[i];traceStr+=stackObect.className+" : "+stackObect.methodName+" -> "}traceStr+=exceptionObject.toString();report(traceStr)}};var Throw=function(exceptionObject){Stack.printStackTrace(exceptionObject);Stack.clear();
if(typeof _exceptionCallbacks[exceptionObject._className]!=="undefined")_exceptionCallbacks[exceptionObject._className](exceptionObject);else;};var Catch=function(exceptionName,callback){_exceptionCallbacks[exceptionName]=callback};var Class=function(name,data){var classNameObject=parseClassName(name);name=classNameObject.name;var extendsClassName=classNameObject.extend;if(typeof extendsClassName==="undefined")extendsClassName=Defaults.defaultObjectName;_classes[name]=function(){if(typeof this[name]!==
"undefined")this[name].apply(this,arguments);else if(typeof this[extendsClassName]!=="undefined")this[extendsClassName].apply(this,arguments)};for(var proto in _classes[extendsClassName].prototype)_classes[name].prototype[proto]=_classes[extendsClassName].prototype[proto];for(var propertyName in data)if(typeof data[propertyName]!=="function"){var getterName="get"+propertyName.charAt(0).toUpperCase()+propertyName.slice(1);if(typeof data[getterName]!=="function"&&propertyName.charAt(0)!=="_")data[getterName]=
function(originalProperty){return function(){Stack.push(name,originalProperty);var retValue=this[originalProperty];Stack.pop();return retValue}}.apply(data,[propertyName]);var setterName="set"+propertyName.charAt(0).toUpperCase()+propertyName.slice(1);if(typeof data[setterName]!=="function"&&propertyName.charAt(0)!=="_")data[setterName]=function(originalProperty){return function(object){Stack.push(name,originalProperty);this[originalProperty]=object;Stack.pop()}}.apply(data,[propertyName])}else data[propertyName]=
function(originalProperty){var myFunction=this[originalProperty];return function(object){Stack.push(name,originalProperty);var retValue=myFunction.apply(this,arguments);Stack.pop();return retValue}}.apply(data,[propertyName]);for(var propertyName in data)_classes[name].prototype[propertyName]=data[propertyName];_classes[name].prototype["_className"]=name;_classes[name].prototype["_sharedInstance"]=new _classes[name];window[name]=_classes[name]};Class(Defaults.defaultObjectName,{_className:Defaults.defaultObjectName,
delegate:null,callDelegate:function(methodName,params){if(this.delegate!==null&&typeof this.delegate[methodName]!=="undefined")this.delegate[methodName].apply(this.delegate,params)}});Class("Exception",{message:null,Exception:function(message){this.message=message},toString:function(){return"Exception: "+this._className+" '"+this.message+"'"}});window.Class=Class;window.Throw=Throw;window.Catch=Catch})();