Browse Source

pastojs: helper inherited

git-svn-id: trunk@41244 -
Mattias Gaertner 6 years ago
parent
commit
fce57c5528

+ 13 - 0
packages/pastojs/src/fppas2js.pp

@@ -376,6 +376,17 @@ Works:
   - pass as argument
   - pass as argument
 - procedure val(const string; var enumtype; out int)
 - procedure val(const string; var enumtype; out int)
 - move all local types to global
 - move all local types to global
+- class helpers:
+  - ancestor
+  - class var,
+  - const
+  - sub type
+  - method, class method, static class method
+  - call methods, @method
+  - constructor
+  - inherited, inherited name
+- record helpers:
+- type helpers:
 
 
 ToDos:
 ToDos:
 - class helpers, type helpers, record helpers, array helpers
 - class helpers, type helpers, record helpers, array helpers
@@ -8054,6 +8065,8 @@ function TPasToJSConverter.ConvertInheritedExpr(El: TInheritedExpr;
       end
       end
     else
     else
       FunName:=CreateReferencePath(AncestorProc,AContext,rpkPathAndName,true);
       FunName:=CreateReferencePath(AncestorProc,AContext,rpkPathAndName,true);
+    if AncestorProc.ProcType.Args.Count=0 then
+      Apply:=false;
     if Apply and (SelfContext=AContext) then
     if Apply and (SelfContext=AContext) then
       // create "ancestor.funcname.apply(this,arguments)"
       // create "ancestor.funcname.apply(this,arguments)"
       FunName:=FunName+'.apply'
       FunName:=FunName+'.apply'

+ 107 - 5
packages/pastojs/tests/tcmodules.pas

@@ -636,7 +636,7 @@ type
     Procedure TestClassHelper_ClassOf;
     Procedure TestClassHelper_ClassOf;
     Procedure TestClassHelper_MethodRefObjFPC;
     Procedure TestClassHelper_MethodRefObjFPC;
     Procedure TestClassHelper_Constructor;
     Procedure TestClassHelper_Constructor;
-    //Procedure TestClassHelper_InheritedObjFPC;
+    Procedure TestClassHelper_InheritedObjFPC;
     //Procedure TestClassHelper_InheritedDelphi;
     //Procedure TestClassHelper_InheritedDelphi;
     // todo: TestClassHelper_Property
     // todo: TestClassHelper_Property
     // todo: TestClassHelper_Property_Array
     // todo: TestClassHelper_Property_Array
@@ -11159,7 +11159,7 @@ begin
     LinesToStr([
     LinesToStr([
     'rtl.createClass($impl, "TIntClass", $mod.TObject, function () {',
     'rtl.createClass($impl, "TIntClass", $mod.TObject, function () {',
     '  this.Create$1 = function () {',
     '  this.Create$1 = function () {',
-    '    $mod.TObject.Create.apply(this, arguments);',
+    '    $mod.TObject.Create.call(this);',
     '    $mod.TObject.Create.call(this);',
     '    $mod.TObject.Create.call(this);',
     '    this.$class.DoGlob();',
     '    this.$class.DoGlob();',
     '    return this;',
     '    return this;',
@@ -11352,7 +11352,7 @@ begin
     '    $mod.TObject.DoVirtual.call(this);',
     '    $mod.TObject.DoVirtual.call(this);',
     '  };',
     '  };',
     '  this.DoVirtual = function () {',
     '  this.DoVirtual = function () {',
-    '    $mod.TObject.DoVirtual.apply(this, arguments);',
+    '    $mod.TObject.DoVirtual.call(this);',
     '    $mod.TObject.DoVirtual.call(this);',
     '    $mod.TObject.DoVirtual.call(this);',
     '    $mod.TObject.DoVirtual.call(this);',
     '    $mod.TObject.DoVirtual.call(this);',
     '    this.DoIt();',
     '    this.DoIt();',
@@ -11529,7 +11529,7 @@ begin
     '});',
     '});',
     'rtl.createClass($mod, "TA", $mod.TObject, function () {',
     'rtl.createClass($mod, "TA", $mod.TObject, function () {',
     '  this.Create = function () {',
     '  this.Create = function () {',
-    '    $mod.TObject.Create.apply(this, arguments);',
+    '    $mod.TObject.Create.call(this);',
     '    $mod.TObject.Create.call(this);',
     '    $mod.TObject.Create.call(this);',
     '    $mod.TObject.CreateWithB.call(this, false);',
     '    $mod.TObject.CreateWithB.call(this, false);',
     '    return this;',
     '    return this;',
@@ -17547,7 +17547,7 @@ begin
     '    var $ir = rtl.createIntfRefs();',
     '    var $ir = rtl.createIntfRefs();',
     '    var $ok = false;',
     '    var $ok = false;',
     '    try {',
     '    try {',
-    '      $ir.ref(1, $mod.TObject.GetIntf.apply(this, arguments));',
+    '      $ir.ref(1, $mod.TObject.GetIntf.call(this));',
     '      $ir.ref(2, $mod.TObject.GetIntf.call(this));',
     '      $ir.ref(2, $mod.TObject.GetIntf.call(this));',
     '      $ir.ref(3, $mod.TObject.GetIntf.call(this));',
     '      $ir.ref(3, $mod.TObject.GetIntf.call(this));',
     '      Result = rtl.setIntfL(Result, $mod.TObject.GetIntf.call(this), true);',
     '      Result = rtl.setIntfL(Result, $mod.TObject.GetIntf.call(this), true);',
@@ -19287,6 +19287,108 @@ begin
     '']));
     '']));
 end;
 end;
 
 
+procedure TTestModule.TestClassHelper_InheritedObjFPC;
+begin
+  StartProgram(false);
+  Add([
+  'type',
+  '  TObject = class',
+  '    procedure Fly;',
+  '  end;',
+  '  TObjHelper = class helper for TObject',
+  '    procedure Fly;',
+  '  end;',
+  '  TBird = class',
+  '    procedure Fly;',
+  '  end;',
+  '  TBirdHelper = class helper for TBird',
+  '    procedure Fly;',
+  '    procedure Walk;',
+  '  end;',
+  '  TEagleHelper = class helper(TBirdHelper) for TBird',
+  '    procedure Fly;',
+  '    procedure Walk;',
+  '  end;',
+  'procedure Tobject.fly;',
+  'begin',
+  '  inherited;', // ignore
+  'end;',
+  'procedure Tobjhelper.fly;',
+  'begin',
+  '  {@TObject_Fly}inherited;',
+  '  inherited {@TObject_Fly}Fly;',
+  'end;',
+  'procedure Tbird.fly;',
+  'begin',
+  '  {@TObjHelper_Fly}inherited;',
+  '  inherited {@TObjHelper_Fly}Fly;',
+  'end;',
+  'procedure Tbirdhelper.fly;',
+  'begin',
+  '  {@TBird_Fly}inherited;',
+  '  inherited {@TBird_Fly}Fly;',
+  'end;',
+  'procedure Tbirdhelper.walk;',
+  'begin',
+  'end;',
+  'procedure teagleHelper.fly;',
+  'begin',
+  '  {@TBird_Fly}inherited;',
+  '  inherited {@TBird_Fly}Fly;',
+  'end;',
+  'procedure teagleHelper.walk;',
+  'begin',
+  '  {@TBirdHelper_Walk}inherited;',
+  '  inherited {@TBirdHelper_Walk}Walk;',
+  'end;',
+  'begin',
+  '']);
+  ConvertProgram;
+  CheckSource('TestClassHelper_InheritedObjFPC',
+    LinesToStr([ // statements
+    'rtl.createClass($mod, "TObject", null, function () {',
+    '  this.$init = function () {',
+    '  };',
+    '  this.$final = function () {',
+    '  };',
+    '  this.Fly = function () {',
+    '  };',
+    '});',
+    'rtl.createHelper($mod, "TObjHelper", null, function () {',
+    '  this.Fly = function () {',
+    '    $mod.TObject.Fly.call(this);',
+    '    $mod.TObject.Fly.call(this);',
+    '  };',
+    '});',
+    'rtl.createClass($mod, "TBird", $mod.TObject, function () {',
+    '  this.Fly$1 = function () {',
+    '    $mod.TObjHelper.Fly.call(this);',
+    '    $mod.TObjHelper.Fly.call(this);',
+    '  };',
+    '});',
+    'rtl.createHelper($mod, "TBirdHelper", null, function () {',
+    '  this.Fly = function () {',
+    '    $mod.TBird.Fly$1.call(this);',
+    '    $mod.TBird.Fly$1.call(this);',
+    '  };',
+    '  this.Walk = function () {',
+    '  };',
+    '});',
+    'rtl.createHelper($mod, "TEagleHelper", $mod.TBirdHelper, function () {',
+    '  this.Fly$1 = function () {',
+    '    $mod.TBird.Fly$1.call(this);',
+    '    $mod.TBird.Fly$1.call(this);',
+    '  };',
+    '  this.Walk$1 = function () {',
+    '    $mod.TBirdHelper.Walk.call(this);',
+    '    $mod.TBirdHelper.Walk.call(this);',
+    '  };',
+    '});',
+    '']),
+    LinesToStr([ // $mod.$main
+    '']));
+end;
+
 procedure TTestModule.TestProcType;
 procedure TTestModule.TestProcType;
 begin
 begin
   StartProgram(false);
   StartProgram(false);

+ 1 - 1
packages/pastojs/tests/tcoptimizations.pas

@@ -763,7 +763,7 @@ begin
     '});',
     '});',
     ' rtl.createClass($mod, "TMobile", $mod.TObject, function () {',
     ' rtl.createClass($mod, "TMobile", $mod.TObject, function () {',
     '  this.DoA$1 = function () {',
     '  this.DoA$1 = function () {',
-    '    $mod.TObject.DoA.apply(this, arguments);',
+    '    $mod.TObject.DoA.call(this);',
     '  };',
     '  };',
     '  this.DoC = function () {',
     '  this.DoC = function () {',
     '    $mod.TObject.DoB.call(this);',
     '    $mod.TObject.DoB.call(this);',