فهرست منبع

pastojs: fixed Setlength(unicodestring) issue 39208

mattias 3 سال پیش
والد
کامیت
f0f9818824
3فایلهای تغییر یافته به همراه16 افزوده شده و 5 حذف شده
  1. 1 1
      packages/pastojs/src/fppas2js.pp
  2. 1 1
      packages/pastojs/src/pas2jsfilecache.pp
  3. 14 3
      packages/pastojs/tests/tcmodules.pas

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

@@ -13051,7 +13051,7 @@ begin
       StaticDims.Free;
     end;
     end
-  else if ResolvedParam0.BaseType=btString then
+  else if ResolvedParam0.BaseType in btAllJSStrings then
     begin
     // convert "SetLength(astring,NewLen);" to "astring = rtl.strSetLength(astring,NewLen);"
     {$IFDEF VerbosePasResolver}

+ 1 - 1
packages/pastojs/src/pas2jsfilecache.pp

@@ -1043,7 +1043,7 @@ begin
   {$ENDIF}
   ADirectory:=ExtractFilePath(Result);
   if ADirectory=Result then
-    exit; // root directory, e.g. / under Linux or C: under Windows
+    exit; // root directory, e.g. / under Linux or C:\ under Windows
   if SearchCaseInsensitive then
     // search recursively all directory parts
     ADirectory:=IncludeTrailingPathDelimiter(FindDiskFilename(ADirectory,true));

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

@@ -8161,24 +8161,35 @@ procedure TTestModule.TestString_SetLength;
 begin
   StartProgram(false);
   Add([
-  'procedure DoIt(var s: string);',
+  'procedure Fly(var s: string);',
+  'begin',
+  '  SetLength(s,1);',
+  'end;',
+  'procedure Run(var s: unicodestring);',
   'begin',
   '  SetLength(s,2);',
   'end;',
   'var s: string;',
+  '  u: unicodestring;',
   'begin',
   '  SetLength(s,3);',
+  '  SetLength(u,4);',
   '']);
   ConvertProgram;
   CheckSource('TestString_SetLength',
     LinesToStr([ // statements
-    'this.DoIt = function (s) {',
+    'this.Fly = function (s) {',
+    '  s.set(rtl.strSetLength(s.get(), 1));',
+    '};',
+    'this.Run = function (s) {',
     '  s.set(rtl.strSetLength(s.get(), 2));',
     '};',
     'this.s = "";',
+    'this.u = "";',
     '']),
     LinesToStr([ // this.$main
-    '$mod.s = rtl.strSetLength($mod.s, 3);'
+    '$mod.s = rtl.strSetLength($mod.s, 3);',
+    '$mod.u = rtl.strSetLength($mod.u, 4);'
     ]));
 end;