pas2js: fixed calling $final, do not call BeforeDestruction on exception in constructor

git-svn-id: trunk@39966 -
This commit is contained in:
Mattias Gaertner 2018-10-18 10:00:02 +00:00
parent c0c602f76d
commit 91d7658844

View File

@ -235,6 +235,7 @@ var rtl = {
initClass: function(c,parent,name,initfn){ initClass: function(c,parent,name,initfn){
parent[name] = c; parent[name] = c;
c.$class = c; // Note: o.$class === Object.getPrototypeOf(o)
c.$classname = name; c.$classname = name;
if ((parent.$module) && (parent.$module.$impl===parent)) parent=parent.$module; if ((parent.$module) && (parent.$module.$impl===parent)) parent=parent.$module;
c.$parent = parent; c.$parent = parent;
@ -272,21 +273,22 @@ var rtl = {
c.$create = function(fnname,args){ c.$create = function(fnname,args){
if (args == undefined) args = []; if (args == undefined) args = [];
var o = Object.create(this); var o = Object.create(this);
o.$class = this; // Note: o.$class === Object.getPrototypeOf(o)
o.$init(); o.$init();
try{ try{
o[fnname].apply(o,args); o[fnname].apply(o,args);
o.AfterConstruction(); o.AfterConstruction();
} catch($e){ } catch($e){
o.$destroy; // do not call BeforeDestruction
if (this.Destroy) this.Destroy();
this.$final();
throw $e; throw $e;
} }
return o; return o;
}; };
c.$destroy = function(fnname){ c.$destroy = function(fnname){
this.BeforeDestruction(); this.BeforeDestruction();
this[fnname](); if (this[fnname]) this[fnname]();
this.$final; this.$final();
}; };
}; };
rtl.initClass(c,parent,name,initfn); rtl.initClass(c,parent,name,initfn);
@ -306,21 +308,22 @@ var rtl = {
} else { } else {
o = Object.create(this); o = Object.create(this);
} }
o.$class = this; // Note: o.$class === Object.getPrototypeOf(o) if (o.$init) o.$init();
o.$init();
try{ try{
o[fnname].apply(o,args); o[fnname].apply(o,args);
if (o.AfterConstruction) o.AfterConstruction(); if (o.AfterConstruction) o.AfterConstruction();
} catch($e){ } catch($e){
o.$destroy; // do not call BeforeDestruction
if (this.Destroy) this.Destroy();
if (this.$final) this.$final();
throw $e; throw $e;
} }
return o; return o;
}; };
c.$destroy = function(fnname){ c.$destroy = function(fnname){
if (this.BeforeDestruction) this.BeforeDestruction(); if (this.BeforeDestruction) this.BeforeDestruction();
this[fnname](); if (this[fnname]) this[fnname]();
this.$final; if (this.$final) this.$final();
}; };
rtl.initClass(c,parent,name,initfn); rtl.initClass(c,parent,name,initfn);
}, },