UNPKG

vox-core

Version:

Runtime de aplicaciones multiplataforma

94 lines (77 loc) 2.08 kB
/** * Scope es una clase que permite manejar los objetos .NET dentro de un scope * para hacer fácil su liberación de memoria * <br>Los objetos obtenidos que son relativos a un scope, se liberan de memoria * al llamar a Scope.end() * @constructor * @param {VW.Clr.Manager} clr * @protected */ var Scope= module.exports= function(manager){ this.id= (++Scope.id) this.manager= manager this.objects= manager.get(this.getNativeTypeScope()).staticMethod(this.getNativeFreeManyMethod()) this.vars=[] } Scope.begin= function(manager){ var scope= new Scope(manager) return scope.func() } Scope.prototype.getNativeTypeScope= function(){ throw new core.System.NotImplementedException("No se ha especificado un tipo nativo. Las clases que hereden de esta deben sobreescribir este método") } Scope.prototype.getNativeFreeManyMethod= function(){ throw new core.System.NotImplementedException("No se ha especificado el nombre del método nativo. Las clases que hereden de esta deben sobreescribir este método") } Scope.prototype.func=function(){ var self= this var func= function(Obj){ Obj.scope= self return Obj } Object.defineProperty(func,"self", { enumerable:false, writable:true }) func.self= self func.end= self.end func.exclude= self.exclude func.remove= self.remove func.include= self.include return func } Scope.prototype.include= function(/* Clr.Type */ obj){ var self= this.self || this var i=obj.CSid; if(i){ if(self.vars.indexOf(i)<0) self.vars.push(i) } return obj } Scope.prototype.exclude= function(/* Clr.Type */ obj){ var self= this.self || this if(obj.scope==self){ obj.scope= null } return obj } Scope.prototype.remove= function(/* Clr.Type */ obj){ var self= this.self || this var i=obj.CSid; if(i){ var y=self.vars.indexOf(i) if(y>=0) self.vars[y]=undefined } return obj } Scope.prototype.end= function(){ /* Borrar todos los elementos agregados */ var self= this.self || this var task= self.objects.FreeMany(self.vars) self.vars=[] self.$disposed= true return task } Scope.id=0