Browse Source

pastojs: convert TJSFunction(@proc) to proc

git-svn-id: trunk@43079 -
Mattias Gaertner 5 years ago
parent
commit
085602b6e4
2 changed files with 20 additions and 4 deletions
  1. 17 1
      packages/pastojs/src/fppas2js.pp
  2. 3 3
      packages/pastojs/tests/tcmodules.pas

+ 17 - 1
packages/pastojs/src/fppas2js.pp

@@ -9997,6 +9997,22 @@ begin
         ArgName:=TransformArgName(TPasArgument(ParamResolved.IdentEl),AContext);
         ArgName:=TransformArgName(TPasArgument(ParamResolved.IdentEl),AContext);
         Result:=CreatePrimitiveDotExpr(ArgName,El);
         Result:=CreatePrimitiveDotExpr(ArgName,El);
         exit;
         exit;
+        end
+      else if (C=TPasClassType)
+          and aResolver.IsExternalClass_Name(TPasClassType(Decl),'Function') then
+        begin
+        // TJSFunction(param)
+        if (Param is TPasExpr) and (TPasExpr(Param).OpCode=eopAddress) then
+          begin
+          aResolver.ComputeElement(TUnaryExpr(Param).Operand,ValueResolved,[rcNoImplicitProc]);
+          if (ValueResolved.BaseType=btProc)
+              and (ValueResolved.IdentEl is TPasProcedure) then
+            begin
+            // TJSFunction(@procname)  -> procname
+            Result:=CreateReferencePathExpr(TPasProcedure(ValueResolved.IdentEl),AContext);
+            exit;
+            end;
+          end;
         end;
         end;
 
 
       Result:=ConvertExpression(Param,AContext);
       Result:=ConvertExpression(Param,AContext);
@@ -10101,7 +10117,7 @@ begin
       if bsObjectChecks in AContext.ScannerBoolSwitches then
       if bsObjectChecks in AContext.ScannerBoolSwitches then
         begin
         begin
         if (C=TPasClassType)
         if (C=TPasClassType)
-           or (C=TPasClassOfType) then
+            or (C=TPasClassOfType) then
           begin
           begin
           // TObject(param) -> rtl.asExt(param,type,mode)
           // TObject(param) -> rtl.asExt(param,type,mode)
           if C=TPasClassOfType then
           if C=TPasClassOfType then

+ 3 - 3
packages/pastojs/tests/tcmodules.pas

@@ -16920,8 +16920,8 @@ begin
     '    function Sub() {',
     '    function Sub() {',
     '    };',
     '    };',
     '    var f = null;',
     '    var f = null;',
-    '    f = rtl.createCallback($Self, "DoIt");',
-    '    f = rtl.createCallback($Self, "DoIt").bind(null, 13);',
+    '    f = $Self.DoIt;',
+    '    f = $Self.DoIt.bind(null, 13);',
     '    f = Sub;',
     '    f = Sub;',
     '    f = $mod.GetIt;',
     '    f = $mod.GetIt;',
     '  };',
     '  };',
@@ -16937,7 +16937,7 @@ begin
     '  f = $mod.GetIt;',
     '  f = $mod.GetIt;',
     '  f = $mod.GetIt.bind(null, 3);',
     '  f = $mod.GetIt.bind(null, 3);',
     '  f = Sub;',
     '  f = Sub;',
-    '  f = rtl.createCallback(o, "DoIt");',
+    '  f = $mod.TObject.DoIt;',
     '  f = fi.bind(null, 4);',
     '  f = fi.bind(null, 4);',
     '  return Result;',
     '  return Result;',
     '};',
     '};',