Browse Source

pastojs: typecast string(apointer), pointer(astring)

git-svn-id: trunk@39975 -
Mattias Gaertner 6 years ago
parent
commit
481a8bee0c
2 changed files with 20 additions and 2 deletions
  1. 14 2
      packages/pastojs/src/fppas2js.pp
  2. 6 0
      packages/pastojs/tests/tcmodules.pas

+ 14 - 2
packages/pastojs/src/fppas2js.pp

@@ -8764,6 +8764,12 @@ begin
       Result:=ConvertElement(Param,AContext);
       Result:=ConvertElement(Param,AContext);
       exit;
       exit;
       end
       end
+    else if ParamResolved.BaseType=btPointer then
+      begin
+      // string(aPointer) -> value
+      Result:=ConvertElement(Param,AContext);
+      exit;
+      end
     else if IsParamPas2JSBaseType then
     else if IsParamPas2JSBaseType then
       begin
       begin
       if JSBaseType=pbtJSValue then
       if JSBaseType=pbtJSValue then
@@ -8843,14 +8849,20 @@ begin
       begin
       begin
       if JSBaseType=pbtJSValue then
       if JSBaseType=pbtJSValue then
         begin
         begin
-        // convert jsvalue to pointer -> pass through
+        // convert jsvalue to pointer -> value
         Result:=ConvertElement(Param,AContext);
         Result:=ConvertElement(Param,AContext);
         exit;
         exit;
         end;
         end;
       end
       end
+    else if ParamResolved.BaseType in btAllJSStrings then
+      begin
+      // pointer(aString) -> value
+      Result:=ConvertElement(Param,AContext);
+      exit;
+      end
     else if ParamResolved.BaseType=btContext then
     else if ParamResolved.BaseType=btContext then
       begin
       begin
-      // convert user type/value to pointer -> pass through
+      // convert user type/value to pointer -> value
       Result:=ConvertElement(Param,AContext);
       Result:=ConvertElement(Param,AContext);
       exit;
       exit;
       end;
       end;

+ 6 - 0
packages/pastojs/tests/tcmodules.pas

@@ -17938,6 +17938,7 @@ begin
   '  C: tclass;',
   '  C: tclass;',
   '  a: tarrint;',
   '  a: tarrint;',
   '  p: Pointer = nil;',
   '  p: Pointer = nil;',
+  '  s: string;',
   'begin',
   'begin',
   '  p:=p;',
   '  p:=p;',
   '  p:=nil;',
   '  p:=nil;',
@@ -17954,6 +17955,8 @@ begin
   '  a:=TArrInt(p);',
   '  a:=TArrInt(p);',
   '  p:=n;',
   '  p:=n;',
   '  p:=Pointer(a);',
   '  p:=Pointer(a);',
+  '  p:=pointer(s);',
+  '  s:=string(p);',
   '']);
   '']);
   ConvertProgram;
   ConvertProgram;
   CheckSource('TestPointer',
   CheckSource('TestPointer',
@@ -17970,6 +17973,7 @@ begin
     'this.C = null;',
     'this.C = null;',
     'this.a = [];',
     'this.a = [];',
     'this.p = null;',
     'this.p = null;',
+    'this.s = "";',
     '']),
     '']),
     LinesToStr([ // $mod.$main
     LinesToStr([ // $mod.$main
     '$mod.p = $mod.p;',
     '$mod.p = $mod.p;',
@@ -17987,6 +17991,8 @@ begin
     '$mod.a = $mod.p;',
     '$mod.a = $mod.p;',
     '$mod.p = null;',
     '$mod.p = null;',
     '$mod.p = $mod.a;',
     '$mod.p = $mod.a;',
+    '$mod.p = $mod.s;',
+    '$mod.s = $mod.p;',
     '']));
     '']));
 end;
 end;