diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index 120b284762..98783b773c 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -11220,16 +11220,27 @@ var FinishedGUIDs: TStringList; Intf: TPasType; CurEl: TPasClassType; + NeedIntfMap, HasInterfaces: Boolean; begin + HasInterfaces:=false; + NeedIntfMap:=true; CurEl:=El; - while CurEl.Interfaces.Count=0 do + while CurEl<>nil do begin + if CurEl.Interfaces.Count>0 then + begin + HasInterfaces:=true; + if CurEl<>El then + begin + NeedIntfMap:=false; + break; + end; + end; CurEl:=TPasClassType(AContext.Resolver.GetPasClassAncestor(CurEl,true)); - if CurEl=nil then exit; // class and ancestor has no interfaces end; + if not HasInterfaces then exit; IntfMaps:=nil; - FinishedGUIDs:=TStringList.Create; try ObjLit:=nil; @@ -11241,7 +11252,7 @@ var begin CurEl:=TPasClassType(Scope.Element); if not IsMemberNeeded(TPasElement(CurEl.Interfaces[i])) then continue; - if IntfMaps=nil then + if NeedIntfMap then begin // add "this.$intfmaps = {};" IntfMaps:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El)); @@ -11249,6 +11260,7 @@ var IntfMaps.LHS:=CreatePrimitiveDotExpr('this.'+FBuiltInNames[pbivnIntfMaps],El); MapsObj:=TJSObjectLiteral(CreateElement(TJSObjectLiteral,El)); IntfMaps.Expr:=MapsObj; + NeedIntfMap:=false; end; o:=TObject(Scope.Interfaces[i]); diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas index 9d8db55206..1aff2329a9 100644 --- a/packages/pastojs/tests/tcmodules.pas +++ b/packages/pastojs/tests/tcmodules.pas @@ -14663,7 +14663,6 @@ begin 'rtl.createClass($mod, "TBird", $mod.TObject, function () {', ' this.Fly = function (i) {', ' };', - ' this.$intfmaps = {};', ' rtl.addIntf(this, $mod.IBird);', ' rtl.addIntf(this, $mod.IUnknown);', '});', @@ -14819,7 +14818,6 @@ begin ' rtl.addIntf(this, $mod.IDog);', '});', 'rtl.createClass($mod, "TBird", $mod.TObject, function () {', - ' this.$intfmaps = {};', ' rtl.addIntf(this, $mod.IUnknown);', ' rtl.addIntf(this, $mod.IBird);', ' rtl.addIntf(this, $mod.IDog);', @@ -14871,19 +14869,16 @@ begin 'rtl.createClass($mod, "TBird", $mod.TObject, function () {', ' this.Go = function () {', ' };', - ' this.$intfmaps = {};', ' rtl.addIntf(this, $mod.IUnknown);', '});', 'rtl.createClass($mod, "TCat", $mod.TObject, function () {', ' this.Go = function () {', ' };', - ' this.$intfmaps = {};', ' rtl.addIntf(this, $mod.IUnknown);', '});', 'rtl.createClass($mod, "TDog", $mod.TObject, function () {', ' this.Go = function () {', ' };', - ' this.$intfmaps = {};', ' rtl.addIntf(this, $mod.IUnknown);', '});', '']), @@ -15544,6 +15539,7 @@ begin ' };', ' return Result;', ' };', + ' rtl.addIntf(this, $mod.IUnknown);', '});', '']), LinesToStr([ // $mod.$main