Browse Source

pastojs: create intfmap only for first class

git-svn-id: trunk@39548 -
Mattias Gaertner 7 years ago
parent
commit
6211847176
2 changed files with 17 additions and 9 deletions
  1. 16 4
      packages/pastojs/src/fppas2js.pp
  2. 1 5
      packages/pastojs/tests/tcmodules.pas

+ 16 - 4
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]);

+ 1 - 5
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