Преглед на файлове

* synchronized with trunk

git-svn-id: branches/wasm@46993 -
nickysn преди 4 години
родител
ревизия
697bd6d586

+ 2 - 0
.gitattributes

@@ -18341,6 +18341,7 @@ tests/webtbs/tw3444.pp svneol=native#text/plain
 tests/webtbs/tw34442.pp svneol=native#text/plain
 tests/webtbs/tw34496.pp svneol=native#text/pascal
 tests/webtbs/tw34509.pp svneol=native#text/pascal
+tests/webtbs/tw34543.pp svneol=native#text/plain
 tests/webtbs/tw3456.pp svneol=native#text/plain
 tests/webtbs/tw3457.pp svneol=native#text/plain
 tests/webtbs/tw3460.pp svneol=native#text/plain
@@ -18500,6 +18501,7 @@ tests/webtbs/tw37428.pp svneol=native#text/pascal
 tests/webtbs/tw37449.pp svneol=native#text/pascal
 tests/webtbs/tw37465.pp svneol=native#text/plain
 tests/webtbs/tw37468.pp svneol=native#text/pascal
+tests/webtbs/tw37468b.pp svneol=native#text/pascal
 tests/webtbs/tw37477.pp svneol=native#text/pascal
 tests/webtbs/tw37493.pp svneol=native#text/pascal
 tests/webtbs/tw37508.pp svneol=native#text/pascal

+ 3 - 2
compiler/systems/t_zxspectrum.pas

@@ -173,8 +173,9 @@ function TLinkerZXSpectrum.WriteResponseFile_Vlink: Boolean;
         Add('SECTIONS');
         Add('{');
         Add('  . = 0x'+hexstr(FOrigin,4)+';');
-        Add('  .text : { *(.text .text.* ) }');
-        Add('  .data : { *(.data .data.* .rodata .rodata.* .bss .bss.* .fpc.* .stack .stack.* ) }');
+        Add('  .text : { *(.text .text.* _CODE _CODE.* ) }');
+        Add('  .data : { *(.data .data.* .rodata .rodata.* .fpc.* ) }');
+        Add('  .bss  : { *(.bss .bss.* _BSS _BSS.* _BSSEND _BSSEND.* _HEAP _HEAP.* .stack .stack.* _STACK _STACK.* ) }');
         Add('}');
       end;
 

+ 11 - 11
compiler/z80/agz80vasm.pas

@@ -123,7 +123,7 @@ unit agz80vasm;
         eextended: extended;
 {$else}
 {$ifdef FPC_SOFT_FPUX80}
-	eextended: floatx80;
+        eextended: floatx80;
 {$endif}
 {$endif cpuextended}
       begin
@@ -143,13 +143,13 @@ unit agz80vasm;
 {$push}{$warn 6018 off} { Unreachable code due to compile time evaluation }
              aitrealconst_s80bit:
                begin
-     	         if sizeof(tai_realconst(hp).value.s80val) = sizeof(double) then
+                 if sizeof(tai_realconst(hp).value.s80val) = sizeof(double) then
                    writer.AsmWriteLn(asminfo^.comment+'value: '+double2str(tai_realconst(hp).value.s80val))
-     	         else if sizeof(tai_realconst(hp).value.s80val) = sizeof(single) then
+                 else if sizeof(tai_realconst(hp).value.s80val) = sizeof(single) then
                    writer.AsmWriteLn(asminfo^.comment+'value: '+single2str(tai_realconst(hp).value.s80val))
                 else
-     	         internalerror(2017091901);
-       	      end;
+                  internalerror(2017091901);
+              end;
 {$pop}
 {$endif}
 {$endif cpuextended}
@@ -186,12 +186,12 @@ unit agz80vasm;
 {$push}{$warn 6018 off} { Unreachable code due to compile time evaluation }
           aitrealconst_s80bit:
             begin
-	      if sizeof(tai_realconst(hp).value.s80val) = sizeof(double) then
+              if sizeof(tai_realconst(hp).value.s80val) = sizeof(double) then
                 eextended:=float64_to_floatx80(float64(double(tai_realconst(hp).value.s80val)))
-	      else if sizeof(tai_realconst(hp).value.s80val) = sizeof(single) then
-	        eextended:=float32_to_floatx80(float32(single(tai_realconst(hp).value.s80val)))
-	      else
-	        internalerror(2017091901);
+              else if sizeof(tai_realconst(hp).value.s80val) = sizeof(single) then
+                eextended:=float32_to_floatx80(float32(single(tai_realconst(hp).value.s80val)))
+              else
+                internalerror(2017091901);
               pdata:=@eextended;
             end;
 {$pop}
@@ -920,7 +920,7 @@ unit agz80vasm;
             asmbin : 'vasmz80_std';
             asmcmd : '-quiet -Fvobj -o $OBJ $EXTRAOPT $ASM';
             supported_targets : [system_z80_embedded, system_z80_zxspectrum, system_z80_msxdos];
-            flags : [af_needar{,af_smartlink_sections}];
+            flags : [af_needar,af_smartlink_sections];
             labelprefix : '.L';
             labelmaxlen : -1;
             comment : '; ';

+ 4 - 2
packages/fcl-web/src/base/fpjwt.pp

@@ -165,8 +165,10 @@ function TJWT.GetAsString: TJSONStringType;
 begin
   Result:=Base64ToBase64URL(EncodeStringBase64(JOSE.AsString));
   Result:=Result+'.'+Base64ToBase64URL(EncodeStringBase64(Claims.AsString));
-  If (Signature<>'') then
-    Result:=Result+'.'+Signature;
+  // Dot must always be present, even if signature is empty.
+  // https://tools.ietf.org/html/rfc7519#section-6.1
+  // (See also Bug ID 37830)
+  Result:=Result+'.'+Signature;
 end;
 
 

+ 2 - 0
packages/googleapi/src/googledrive.pp

@@ -1213,6 +1213,7 @@ type
     pageToken : String;
     q : String;
     spaces : String;
+    fields: String;
   end;
   
   
@@ -4120,6 +4121,7 @@ begin
   AddToQuery(_Q,'pageToken',AQuery.pageToken);
   AddToQuery(_Q,'q',AQuery.q);
   AddToQuery(_Q,'spaces',AQuery.spaces);
+  AddToQuery(_Q,'fields',AQuery.fields);
   Result:=List(_Q);
 end;
 

+ 114 - 116
packages/openssl/src/openssl.pas

@@ -84,30 +84,27 @@ uses
 {$ENDIF OS2}
   DynLibs, cTypes, SysUtils;
 
-var
-  {$IFDEF WINDOWS}
-  DLLSSLName: string = 'ssleay32.dll';
-  DLLSSLName2: string = 'libssl32.dll';
-  DLLSSLName3: string = {$IFDEF WIN64}'libssl-1_1-x64.dll'{$ELSE}'libssl-1_1.dll'{$ENDIF};
-  DLLUtilName: string = 'libeay32.dll';
-  DLLUtilName2: string = {$IFDEF WIN64}'libcrypto-1_1-x64.dll'{$ELSE}'libcrypto-1_1.dll'{$ENDIF};
-  {$ELSE}
-   {$IFDEF OS2}
-    {$IFDEF OS2GCC}
-  DLLSSLName: string = 'kssl10.dll';
-  DLLUtilName: string = 'kcrypt10.dll';
-  DLLSSLName2: string = 'kssl.dll';
-  DLLUtilName2: string = 'kcrypto.dll';
-    {$ELSE OS2GCC}
-  DLLSSLName: string = 'emssl10.dll';
-  DLLUtilName: string = 'emcrpt10.dll';
-  DLLSSLName2: string = 'ssl.dll';
-  DLLUtilName2: string = 'crypto.dll';
-    {$ENDIF OS2GCC}
-   {$ELSE OS2}
-  DLLSSLName: string = 'libssl';
-  DLLUtilName: string = 'libcrypto';
+Type
+  TLibreSSLSupport = (lssFirst,lssLast,lssDisabled);
 
+const
+// SSL and Crypto DLL arrays must have the same length and contain
+// matched pairs of DLL filenames. Place newer versions at the beginning.
+{$IFDEF WIN64}
+  SSL_DLL_Names:    array[1..3] of string = ('libssl-1_1-x64',    'ssleay32', 'libssl32');
+  Crypto_DLL_Names: array[1..3] of string = ('libcrypto-1_1-x64', 'libeay32', 'libeay32');
+{$ELSEIF DEFINED(WINDOWS)}
+  SSL_DLL_Names:    array[1..3] of string = ('libssl-1_1',    'ssleay32', 'libssl32');
+  Crypto_DLL_Names: array[1..3] of string = ('libcrypto-1_1', 'libeay32', 'libeay32');
+{$ELSEIF DEFINED(OS2GCC)}
+  SSL_DLL_Names:    array[1..2] of string = ('kssl10',   'kssl');
+  Crypto_DLL_Names: array[1..2] of string = ('kcrypt10', 'kcrypto');
+{$ELSEIF DEFINED(OS2)}
+  SSL_DLL_Names:    array[1..2] of string = ('emssl10',  'ssl');
+  Crypto_DLL_Names: array[1..2] of string = ('emcrpt10', 'crypto');
+{$ELSE}
+  BaseSSLName: string = 'libssl';
+  BaseCryptoName: string = 'libcrypto';
   { ADD NEW ONES WHEN THEY APPEAR!
     Always make .so/dylib first, then versions, in descending order!
     Add "." .before the version, first is always just "" }
@@ -115,13 +112,26 @@ var
                                         '.1.0.2', '.1.0.1','.1.0.0','.0.9.8',
                                         '.0.9.7', '.0.9.6', '.0.9.5', '.0.9.4',
                                         '.0.9.3', '.0.9.2', '.0.9.1');
-   {$ENDIF OS2}
-  {$ENDIF WINDOWS}
+  LibreSSLVersions : Array[1..8] of string =
+                     ('', '.48', '.47', '.46', '.45', '.44', '.43', '.35');
+
+  // Mac OS no longer allows you to load the unversioned one. Bug ID 36484.
+  {$IFDEF DARWIN}
+  StartVersionOffset = 1;
+  DefaultLibreSSLSupport = lssFirst;
+  {$ElSE}
+  StartVersionOffset = 0;
+  DefaultLibreSSLSupport = lssLast;
+  {$ENDIF}
+
+Var
+   LibreSSLSupport : TLibreSSLSupport = DefaultLibreSSLSupport;
+{$ENDIF}
 
 const
   // EVP.h Constants
 
-  EVP_MAX_MD_SIZE               = 64; //* longest known is SHA512 */
+  EVP_MAX_MD_SIZE       = 64; //* longest known is SHA512 */
   EVP_MAX_KEY_LENGTH    = 32;
   EVP_MAX_IV_LENGTH     = 16;
   EVP_MAX_BLOCK_LENGTH  = 32;
@@ -4753,42 +4763,6 @@ begin
     _OPENSSLaddallalgorithms;
 end;
 
-{$IFNDEF WINDOWS}
- {$IFNDEF OS2}
-{ Try to load all library versions until you find or run out }
-function LoadLibHack(const Value: String): HModule;
-var
-  i: cInt;
-begin
-  Result := NilHandle;
-
-  for i := Low(DLLVersions) to High(DLLVersions) do begin
-    {$IFDEF DARWIN}
-    Result := LoadLibrary(Value + DLLVersions[i] + '.dylib');
-    {$ELSE}
-    Result := LoadLibrary(Value + '.so' + DLLVersions[i]);
-    {$ENDIF}
-
-    if Result <> NilHandle then
-      Break;
-  end;
-end;
- {$ENDIF OS2}
-{$ENDIF WINDOWS}
-
-function LoadLib(const Value: String): HModule;
-begin
-  {$IFDEF WINDOWS}
-  Result := LoadLibrary(Value);
-  {$ELSE WINDOWS}
-   {$IFDEF OS2}
-  Result := LoadLibrary(Value);
-   {$ELSE OS2}
-  Result := LoadLibHack(Value);
-   {$ENDIF OS2}
-  {$ENDIF WINDOWS}
-end;
-
 Function CheckOK(ProcName : string ) : string;
 
 
@@ -5197,19 +5171,6 @@ begin
   _BN_free:=GetProcAddr(SSLUtilHandle,'BN_free');
 end;
 
-Function LoadUtilLibrary : Boolean;
-
-begin
-  Result:=(SSLUtilHandle<>0);
-  if not Result then
-    begin
-    SSLUtilHandle := LoadLib(DLLUtilName);
-    Result:=(SSLUtilHandle<>0);
-    end;
-end;
-
-
-
 Procedure ClearSSLEntryPoints;
 
 begin
@@ -5368,26 +5329,6 @@ begin
   _BN_free:=nil;
 end;
 
-Procedure UnloadSSLLib;
-
-begin
-  if (SSLLibHandle<>0) then
-    begin
-    FreeLibrary(SSLLibHandle);
-    SSLLibHandle:=0;
-    end;
-end;
-
-Procedure UnloadUtilLib;
-
-begin
-  if (SSLUtilHandle<>0) then
-     begin
-     FreeLibrary(SSLUtilHandle);
-     SSLUtilHandle := 0;
-     end;
-end;
-
 Procedure ClearUtilEntryPoints;
 
 begin
@@ -5613,32 +5554,89 @@ begin
   end;
 end;
 
+function TryLoadLibPair(const SSL_DLL_Name, Crypto_DLL_Name: string):boolean;
+begin
+  Assert((SSLUtilHandle = 0) and (SSLLibHandle = 0),
+    'LoadTryLoadLibPair: Handle is not zero');
+
+  SSLUtilHandle := LoadLibrary(Crypto_DLL_Name);
+  if (SSLUtilHandle <> 0) then
+    SSLLibHandle := LoadLibrary(SSL_DLL_Name);
+
+  Result := (SSLUtilHandle <> 0) and (SSLLibHandle <> 0);
+  if not Result then UnloadLibraries;
+end;
+
+ Function MakeLibName(Const aBase,aVersion : String) : string;
+
+ begin
+   {$IF DEFINED(WINDOWS) OR DEFINED(OS2)}
+   Result:=aBase+aVersion+'.dll';
+   {$ELSE}
+   {$IFNDEF DARWIN}
+   Result:=aBase+'.so'+aVersion;
+   {$ELSE}
+   Result:=aBase+aVersion+'.dylib';
+   {$ENDIF}
+   {$ENDIF}
+ end;
+
+{$IF NOT(DEFINED(WINDOWS) OR DEFINED(OS2))}
+Function LoadOpenSSl : Boolean;
+
+var
+  Idx: Integer;
+begin
+  Result:=False;
+  Idx := Low(DLLVersions)+StartVersionOffset;
+  While (not Result) and (Idx<=High(DLLVersions)) do
+    begin
+    Result := TryLoadLibPair(MakeLibName(BaseSSLName,DLLVersions[Idx]),
+                             MakeLibName(BaseCryptoName,DLLVersions[Idx]));
+    Inc(Idx);
+    end;
+end;
+
+Function LoadLibreSSl : Boolean;
+
+var
+  Idx: Integer;
+begin
+  Result:=False;
+  Idx := Low(LibreSSLVersions)+StartVersionOffset;
+  While (not Result) and (Idx<=High(LibreSSLVersions)) do
+    begin
+    Result := TryLoadLibPair(MakeLibName(BaseSSLName,LibreSSLVersions[Idx]),
+                             MakeLibName(BaseCryptoName,LibreSSLVersions[Idx]));
+    Inc(Idx);
+    end;
+end;
+{$ENDIF}
+
 Function LoadLibraries : Boolean;
 
+var
+  Idx: Integer;
+
 begin
   Result:=False;
-{$IFDEF DARWIN}  
-  // Mac OS no longer allows you to load the unversioned one. Bug ID 36484.
-  DLLVERSIONS[1]:=DLLVERSIONS[2];
+{$IF DEFINED(WINDOWS) OR DEFINED(OS2)}
+  Assert(Low(SSL_DLL_Names) = Low(Crypto_DLL_Names));
+  Assert(High(SSL_DLL_Names) = High(Crypto_DLL_Names));
+  Idx:=Low(SSL_DLL_Names);
+  While (not Result) and (Idx<=High(SSL_DLL_Names)) do
+    begin
+    Result := TryLoadLibPair(MakeLibName(SSL_DLL_Names[Idx],''), MakeLibName(Crypto_DLL_Names[Idx],''));
+    Inc(Idx);
+    end;
+{$ELSE}
+  if LibreSSLSupport=lssFirst then
+    Result:=LoadLibreSSL;
+  if not Result then
+    Result:=LoadOpenSSL;
+  if (Not Result) and (LibreSSLSupport=lssFirst) then
+    Result:=LoadLibreSSL;
 {$ENDIF}
-  SSLUtilHandle := LoadLib(DLLUtilName);
-  SSLLibHandle := LoadLib(DLLSSLName);
-  {$IFDEF MSWINDOWS}
-  if (SSLUtilHandle = 0) then
-    SSLUtilHandle := LoadLib(DLLUtilName2);
-  if (SSLLibHandle = 0) then
-    SSLLibHandle := LoadLib(DLLSSLName2);
-  if (SSLLibHandle = 0) then
-    SSLLibHandle := LoadLib(DLLSSLName3);
-  {$ELSE MSWINDOWS}
-   {$IFDEF OS2}
-  if (SSLUtilHandle = 0) then
-    SSLUtilHandle := LoadLib(DLLUtilName2);
-  if (SSLLibHandle = 0) then
-    SSLLibHandle := LoadLib(DLLSSLName2);
-   {$ENDIF OS2}
-  {$ENDIF MSWINDOWS}
-  Result:=(SSLLibHandle<>0) and (SSLUtilHandle<>0);
 end;
 
 function InitSSLInterface: Boolean;

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

@@ -15177,7 +15177,8 @@ begin
       end;// end of init function
 
     // for specialization: add RTTI name
-    if (Scope.JSName<>'') and (Scope.JSName<>El.Name) and HasTypeInfo(El,AContext) then
+    if ((Scope.JSName<>'') and (Scope.JSName<>El.Name))
+        or (El.Parent is TPasMembersType) then
       begin
       Call.AddArg(CreateLiteralString(El,GetTypeInfoName(El,AContext,El)));
       end;

+ 138 - 70
packages/pastojs/tests/tcgenerics.pas

@@ -27,7 +27,7 @@ type
     Procedure TestGen_ClassEmpty;
     Procedure TestGen_Class_EmptyMethod;
     Procedure TestGen_Class_TList;
-    Procedure TestGen_Class_TCustomList;
+    Procedure TestGen_Class_TCustomList; // ToDo: with Self do Result:=Method()
     Procedure TestGen_ClassAncestor;
     Procedure TestGen_Class_TypeInfo;
     Procedure TestGen_Class_TypeOverload; // ToDo TBird, TBird<T>, TBird<S,T>
@@ -37,12 +37,13 @@ type
     Procedure TestGen_Class_ClassConstructor;
     Procedure TestGen_Class_TypeCastSpecializesWarn;
     Procedure TestGen_Class_TypeCastSpecializesJSValueNoWarn;
-    procedure TestGen_Class_VarArgsOfType;
     procedure TestGen_Class_OverloadsInUnit;
     procedure TestGen_ClassForward_CircleRTTI;
+    procedure TestGen_Class_Nested_RTTI;
     Procedure TestGen_Class_ClassVarRecord_UnitImpl;
 
     // generic external class
+    procedure TestGen_ExtClass_VarArgsOfType;
     procedure TestGen_ExtClass_Array;
     procedure TestGen_ExtClass_GenJSValueAssign;
     procedure TestGen_ExtClass_AliasMemberType;
@@ -365,7 +366,7 @@ begin
     '  };',
     '});',
     'rtl.createClass(this, "TBird$G1", this.TObject, function () {',
-    '});',
+    '}, "TBird<System.Word>");',
     'this.a = null;',
     'this.b = null;',
     '']),
@@ -403,7 +404,7 @@ begin
     '    var Result = 0;',
     '    return Result;',
     '  };',
-    '});',
+    '}, "TBird<System.Word>");',
     'this.a = null;',
     '']),
     LinesToStr([ // $mod.$main
@@ -479,7 +480,7 @@ begin
     '    this.FItems.splice(2, 0, w);',
     '    this.FItems.splice(2, 3);',
     '  };',
-    '});',
+    '}, "TList<System.Word>");',
     'this.l = null;',
     'this.w = 0;',
     '']),
@@ -511,7 +512,7 @@ begin
   'function TList<T>.Add: word;',
   'begin',
   '  Result:=PrepareAddingItem;',
-  //'  Result:=Self.PrepareAddingItem;',
+  '  Result:=Self.PrepareAddingItem;',
   //'  with Self do Result:=PrepareAddingItem;',
   'end;',
   'var l: TWordList;',
@@ -531,14 +532,15 @@ begin
     '    var Result = 0;',
     '    return Result;',
     '  };',
-    '});',
+    '}, "TCustomList<System.Word>");',
     'rtl.createClass(this, "TList$G1", this.TCustomList$G2, function () {',
     '  this.Add = function () {',
     '    var Result = 0;',
     '    Result = this.PrepareAddingItem();',
+    '    Result = this.PrepareAddingItem();',
     '    return Result;',
     '  };',
-    '});',
+    '}, "TList<System.Word>");',
     'this.l = null;',
     '']),
     LinesToStr([ // $mod.$main
@@ -568,9 +570,9 @@ begin
     '  };',
     '});',
     'rtl.createClass(this, "TBird$G2", this.TObject, function () {',
-    '});',
+    '}, "TBird<System.Word>");',
     'rtl.createClass(this, "TEagle$G1", this.TBird$G2, function () {',
-    '});',
+    '}, "TEagle<System.Word>");',
     'this.a = null;',
     '']),
     LinesToStr([ // $mod.$main
@@ -684,7 +686,7 @@ begin
     '});',
     'rtl.createClass(this, "TBird$G1", this.TObject, function () {',
     '  this.fSize = 0;',
-    '});',
+    '}, "TBird<System.Word>");',
     '']),
     LinesToStr([ // $mod.$main
     '$mod.TBird$G1.fSize = 3 + $mod.TBird$G1.fSize;',
@@ -750,7 +752,7 @@ begin
     '    this.Run();',
     '    $mod.TPoint$G1.Run();',
     '  };',
-    '});',
+    '}, "TPoint<System.Word>");',
     'this.p = null;',
     '']),
     LinesToStr([ // $mod.$main
@@ -800,13 +802,13 @@ begin
     '  this.x = 0;',
     '  this.Fly = function () {',
     '  };',
-    '});',
+    '}, "TPoint<System.Word>");',
     'this.r = null;',
     'rtl.createClass(this, "TPoint$G2", this.TObject, function () {',
     '  this.x = 0;',
     '  this.Fly = function () {',
     '  };',
-    '});',
+    '}, "TPoint<System.SmallInt>");',
     'this.s = null;',
     '']),
     LinesToStr([ // $mod.$main
@@ -858,13 +860,13 @@ begin
     '    $mod.TObject.$init.call(this);',
     '    this.F = 0;',
     '  };',
-    '});',
+    '}, "TBird<System.Word>");',
     'rtl.createClass(this, "TBird$G2", this.TObject, function () {',
     '  this.$init = function () {',
     '    $mod.TObject.$init.call(this);',
     '    this.F = "";',
     '  };',
-    '});',
+    '}, "TBird<System.Char>");',
     'this.w = null;',
     'this.c = null;',
     '']),
@@ -906,13 +908,13 @@ begin
     '    $mod.TObject.$init.call(this);',
     '    this.F = 0;',
     '  };',
-    '});',
+    '}, "TBird<System.Word>");',
     'rtl.createClass(this, "TBird$G2", this.TObject, function () {',
     '  this.$init = function () {',
     '    $mod.TObject.$init.call(this);',
     '    this.F = undefined;',
     '  };',
-    '});',
+    '}, "TBird<System.JSValue>");',
     'this.w = null;',
     'this.a = null;',
     '']),
@@ -923,45 +925,6 @@ begin
   CheckResolverUnexpectedHints();
 end;
 
-procedure TTestGenerics.TestGen_Class_VarArgsOfType;
-begin
-  StartProgram(false);
-  Add([
-  '{$mode objfpc}',
-  '{$modeswitch externalclass}',
-  'type',
-  '  TJSObject = class external name ''Object''',
-  '  end;',
-  '  generic TGJSSet<T> = class external name ''Set''',
-  '    constructor new(aElement1: T); varargs of T; overload;',
-  '    function bind(thisArg: TJSObject): T; varargs of T;',
-  '  end;',
-  '  TJSWordSet = specialize TGJSSet<word>;',
-  'var',
-  '  s: TJSWordSet;',
-  '  w: word;',
-  'begin',
-  '  s:=TJSWordSet.new(3);',
-  '  s:=TJSWordSet.new(3,5);',
-  '  w:=s.bind(nil);',
-  '  w:=s.bind(nil,6);',
-  '  w:=s.bind(nil,7,8);',
-  '']);
-  ConvertProgram;
-  CheckSource('TestGen_Class_VarArgsOfType',
-    LinesToStr([ // statements
-    'this.s = null;',
-    'this.w = 0;',
-    '']),
-    LinesToStr([ // $mod.$main
-    '$mod.s = new Set(3);',
-    '$mod.s = new Set(3, 5);',
-    '$mod.w = $mod.s.bind(null);',
-    '$mod.w = $mod.s.bind(null, 6);',
-    '$mod.w = $mod.s.bind(null, 7, 8);',
-    '']));
-end;
-
 procedure TTestGenerics.TestGen_Class_OverloadsInUnit;
 begin
   StartProgram(true,[supTObject]);
@@ -1013,7 +976,7 @@ begin
     '    this.Create$2 = function (b) {',
     '      return this;',
     '    };',
-    '  });',
+    '  }, "TBird<System.Word>");',
     '  rtl.createClass(this, "TBird$G2", pas.system.TObject, function () {',
     '    this.c = 13;',
     '    var c$1 = 14;',
@@ -1024,7 +987,7 @@ begin
     '    this.Create$2 = function (b) {',
     '      return this;',
     '    };',
-    '  });',
+    '  }, "TBird<System.Double>");',
     '});',
     '']));
   CheckSource('TestGen_Class_OverloadsInUnit',
@@ -1115,6 +1078,57 @@ begin
     '']));
 end;
 
+procedure TTestGenerics.TestGen_Class_Nested_RTTI;
+begin
+  WithTypeInfo:=true;
+  StartProgram(true,[supTObject]);
+  AddModuleWithIntfImplSrc('UnitA.pas',
+  LinesToStr([
+  'type',
+  '  generic TAnt<T> = class',
+  '  type',
+  '    TLeg = class',
+  '    published',
+  '      Size: T;',
+  '    end;',
+  '  end;',
+  '  TBoolAnt = specialize TAnt<boolean>;',
+  '']),
+  LinesToStr([
+  '']));
+  Add([
+  'uses UnitA;',
+  'var',
+  '  BoolLeg: TBoolAnt.TLeg;',
+  'begin',
+  '  if typeinfo(TBoolAnt.TLeg)=nil then ;',
+  '']);
+  ConvertProgram;
+  CheckUnit('UnitA.pas',
+    LinesToStr([ // statements
+    'rtl.module("UnitA", ["system"], function () {',
+    '  var $mod = this;',
+    '  $mod.$rtti.$Class("TAnt<System.Boolean>");',
+    '  rtl.createClass(this, "TAnt$G1", pas.system.TObject, function () {',
+    '    rtl.createClass(this, "TLeg", pas.system.TObject, function () {',
+    '      this.$init = function () {',
+    '        pas.system.TObject.$init.call(this);',
+    '        this.Size = false;',
+    '      };',
+    '      var $r = this.$rtti;',
+    '      $r.addField("Size", rtl.boolean);',
+    '    }, "TAnt<System.Boolean>.TLeg");',
+    '  }, "TAnt<System.Boolean>");',
+    '});']));
+  CheckSource('TestGen_Class_Nested_RTTI',
+    LinesToStr([ // statements
+    'this.BoolLeg = null;',
+    '']),
+    LinesToStr([ // $mod.$main
+    'if (pas.UnitA.$rtti["TAnt<System.Boolean>.TLeg"] === null) ;',
+    '']));
+end;
+
 procedure TTestGenerics.TestGen_Class_ClassVarRecord_UnitImpl;
 begin
   StartProgram(true,[supTObject]);
@@ -1151,7 +1165,7 @@ begin
     '      this.x = $impl.TBird.$new();',
     '      this.a = rtl.arraySetLength(null, $impl.TBird, 2);',
     '    };',
-    '  });',
+    '  }, "TAnt<UnitA.TBird>");',
     '  $mod.$implcode = function () {',
     '    rtl.recNewT($impl, "TBird", function () {',
     '      this.b = 0;',
@@ -1168,7 +1182,8 @@ begin
     '  $mod.$init = function () {',
     '    $impl.f.x.b = $impl.f.x.b + 10;',
     '  };',
-    '}, []);']));
+    '}, []);',
+    '']));
   CheckSource('TestGen_Class_ClassVarRecord_UnitImpl',
     LinesToStr([ // statements
     'pas.UnitA.TAnt$G1.$initSpec();',
@@ -1177,6 +1192,45 @@ begin
     '']));
 end;
 
+procedure TTestGenerics.TestGen_ExtClass_VarArgsOfType;
+begin
+  StartProgram(false);
+  Add([
+  '{$mode objfpc}',
+  '{$modeswitch externalclass}',
+  'type',
+  '  TJSObject = class external name ''Object''',
+  '  end;',
+  '  generic TGJSSet<T> = class external name ''Set''',
+  '    constructor new(aElement1: T); varargs of T; overload;',
+  '    function bind(thisArg: TJSObject): T; varargs of T;',
+  '  end;',
+  '  TJSWordSet = specialize TGJSSet<word>;',
+  'var',
+  '  s: TJSWordSet;',
+  '  w: word;',
+  'begin',
+  '  s:=TJSWordSet.new(3);',
+  '  s:=TJSWordSet.new(3,5);',
+  '  w:=s.bind(nil);',
+  '  w:=s.bind(nil,6);',
+  '  w:=s.bind(nil,7,8);',
+  '']);
+  ConvertProgram;
+  CheckSource('TestGen_ExtClass_VarArgsOfType',
+    LinesToStr([ // statements
+    'this.s = null;',
+    'this.w = 0;',
+    '']),
+    LinesToStr([ // $mod.$main
+    '$mod.s = new Set(3);',
+    '$mod.s = new Set(3, 5);',
+    '$mod.w = $mod.s.bind(null);',
+    '$mod.w = $mod.s.bind(null, 6);',
+    '$mod.w = $mod.s.bind(null, 7, 8);',
+    '']));
+end;
+
 procedure TTestGenerics.TestGen_ExtClass_Array;
 begin
   StartProgram(false);
@@ -1431,10 +1485,17 @@ begin
     '  this.$final = function () {',
     '  };',
     '});',
-    'rtl.createInterface(this, "IBird$G2", "{33AB51C6-6240-3BDF-B4B0-D48A593EAB0A}", ["GetSize", "SetSize", "DoIt"], this.IUnknown);',
+    'rtl.createInterface(',
+    '  this,',
+    '  "IBird$G2",',
+    '  "{33AB51C6-6240-3BDF-B4B0-D48A593EAB0A}",',
+    '  ["GetSize", "SetSize", "DoIt"],',
+    '  this.IUnknown,',
+    '  "IBird<System.Word>"',
+    ');',
     'rtl.createClass(this, "TBird$G1", this.TObject, function () {',
     '  rtl.addIntf(this, $mod.IBird$G2);',
-    '});',
+    '}, "TBird<System.Word>");',
     'this.BirdIntf = null;',
     '']),
     LinesToStr([ // $mod.$main
@@ -1463,7 +1524,14 @@ begin
   ConvertProgram;
   CheckSource('TestGen_ClassInterface_InterfacedObject',
     LinesToStr([ // statements
-    'rtl.createInterface(this, "IComparer$G2", "{505778ED-F783-4456-9691-32F419CC5E18}", ["Compare"], pas.system.IUnknown);',
+    'rtl.createInterface(',
+    '  this,',
+    '  "IComparer$G2",',
+    '  "{505778ED-F783-4456-9691-32F419CC5E18}",',
+    '  ["Compare"],',
+    '  pas.system.IUnknown,',
+    '  "IComparer<System.Longint>"',
+    ');',
     'this.aComparer = null;',
     'rtl.createClass(this, "TComparer$G1", pas.system.TInterfacedObject, function () {',
     '  this.Compare = function (Left, Right) {',
@@ -1472,7 +1540,7 @@ begin
     '  };',
     '  rtl.addIntf(this, $mod.IComparer$G2);',
     '  rtl.addIntf(this, pas.system.IUnknown);',
-    '});',
+    '}, "TComparer<System.Longint>");',
     '']),
     LinesToStr([ // $mod.$main
     'rtl.setIntfP($mod, "aComparer", rtl.queryIntfT($mod.TComparer$G1.$create("Create"), $mod.IComparer$G2), true);',
@@ -1549,7 +1617,7 @@ begin
     '  };',
     '});',
     'rtl.createClass(this, "TBird$G1", this.TObject, function () {',
-    '});',
+    '}, "TBird<System.Word>");',
     'this.b = null;',
     '']),
     LinesToStr([ // $mod.$main
@@ -1592,13 +1660,13 @@ begin
     '    this.Fly = function () {',
     '      $impl.DoIt();',
     '    };',
-    '  });',
+    '  }, "TBird<System.Boolean>");',
     '  this.b = null;',
     '  rtl.createClass(this, "TBird$G2", pas.system.TObject, function () {',
     '    this.Fly = function () {',
     '      $impl.DoIt();',
     '    };',
-    '  });',
+    '  }, "TBird<System.Word>");',
     '  $mod.$implcode = function () {',
     '    $impl.DoIt = function () {',
     '      var b = null;',
@@ -1646,7 +1714,7 @@ begin
     '    var i = 0;',
     '    i = this.m;',
     '  };',
-    '});',
+    '}, "TBird<System.Word>");',
     'this.b = null;',
     '']),
     LinesToStr([ // $mod.$main
@@ -1694,7 +1762,7 @@ begin
     '    $mod.o.Field = 3;',
     '    if (4 === $mod.o.Field) ;',
     '  };',
-    '});',
+    '}, "TBird<System.Word>");',
     'this.b = null;',
     '']),
     LinesToStr([ // $mod.$main

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

@@ -11964,7 +11964,7 @@ begin
     '      this.Glob();',
     '      this.Glob();',
     '    };',
-    '  });',
+    '  }, "TPoint.TBird");',
     '  this.$eq = function (b) {',
     '    return true;',
     '  };',
@@ -16395,7 +16395,7 @@ begin
     '      this.FId = i;',
     '      return Result;',
     '    };',
-    '  });',
+    '  }, "TBird.TLeg");',
     '  this.DoIt = function (b) {',
     '    var Result = null;',
     '    Result.Create();',

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

@@ -634,7 +634,7 @@ begin
     '  $lt = this;',
     '  rtl.createClass(this, "TLeg", $lt4, function () {',
     '    $lt1 = this;',
-    '  });',
+    '  }, "TAnt.TLeg");',
     '  this.$init = function () {',
     '    $lt4.$init.call(this);',
     '    this.Bird = null;',

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

@@ -16,7 +16,7 @@
  Examples:
     ./testpas2js --suite=TTestSrcMap.TestEmptyProgram
 }
-unit tcsrcmap;
+unit TCSrcMap;
 
 {$mode objfpc}{$H+}
 

+ 1 - 0
packages/pastojs/tests/testpas2js.lpi

@@ -64,6 +64,7 @@
       <Unit5>
         <Filename Value="tcsrcmap.pas"/>
         <IsPartOfProject Value="True"/>
+        <UnitName Value="TCSrcMap"/>
       </Unit5>
       <Unit6>
         <Filename Value="../src/fppjssrcmap.pp"/>

+ 2 - 2
packages/pastojs/tests/testpas2js.pp

@@ -20,8 +20,8 @@ uses
   {$IFDEF EnableMemCheck}
   MemCheck,
   {$ENDIF}
-  Classes, consoletestrunner, tcconverter, TCModules, tcoptimizations, tcsrcmap,
-  tcfiler, tcunitsearch, tcprecompile, TCGenerics;
+  Classes, consoletestrunner, tcconverter, TCModules, TCSrcMap,
+  TCFiler, TCUnitSearch, TCOptimizations, TCGenerics, TCPrecompile;
 
 type
 

+ 3 - 3
rtl/darwin/Makefile

@@ -3278,7 +3278,7 @@ dos$(PPUEXT) : $(UNIXINC)/dos.pp $(SYSTEMUNIT)$(PPUEXT) strings$(PPUEXT) unix$(P
 	       unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
 sysutils$(PPUEXT) : objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT) $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
-		    objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT)
+		    unixtype$(PPUEXT)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $(UNIXINC)/sysutils.pp
 classes$(PPUEXT) : sysutils$(PPUEXT) rtlconsts$(PPUEXT) types$(PPUEXT) typinfo$(PPUEXT) unix$(PPUEXT) $(UNIXINC)/classes.pp $(wildcard $(OBJPASDIR)/classes/*.inc) \
 		   sysutils$(PPUEXT) typinfo$(PPUEXT) rtlconsts$(PPUEXT) types$(PPUEXT) fgl$(PPUEXT) sortbase$(PPUEXT)
@@ -3329,13 +3329,13 @@ termio$(PPUEXT) : termio.pp baseunix$(PPUEXT)
 	$(COMPILER) $<
 dl$(PPUEXT) : $(UNIXINC)/dl.pp $(SYSTEMUNIT)$(PPUEXT) unixtype$(PPUEXT) ctypes$(PPUEXT)
 	$(COMPILER) $<
-errors$(PPUEXT) : $(UNIXINC)/errors.pp strings$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) strings$(PPUEXT)
+errors$(PPUEXT) : $(UNIXINC)/errors.pp unixtype$(PPUEXT) strings$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) strings$(PPUEXT)
 	$(COMPILER) $<
 cmem$(PPUEXT) : $(INC)/cmem.pp $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
 sysctl$(PPUEXT) : $(BSDINC)/sysctl.pp $(SYSTEMUNIT)$(PPUEXT) unixtype$(PPUEXT)
 	$(COMPILER) $<
-cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp unix$(PPUEXT) sysutils$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp unix$(PPUEXT) unixtype$(PPUEXT) sysutils$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
 initc$(PPUEXT) : $(UNIXINC)/initc.pp $(SYSTEMUNIT)$(PPUEXT) ctypes$(PPUEXT)
 	$(COMPILER) $<

+ 3 - 3
rtl/darwin/Makefile.fpc

@@ -209,7 +209,7 @@ dos$(PPUEXT) : $(UNIXINC)/dos.pp $(SYSTEMUNIT)$(PPUEXT) strings$(PPUEXT) unix$(P
 #
 
 sysutils$(PPUEXT) : objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT) $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
-                    objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT)
+                    unixtype$(PPUEXT)
         $(COMPILER) -Fi$(OBJPASDIR)/sysutils $(UNIXINC)/sysutils.pp
 
 classes$(PPUEXT) : sysutils$(PPUEXT) rtlconsts$(PPUEXT) types$(PPUEXT) typinfo$(PPUEXT) unix$(PPUEXT) $(UNIXINC)/classes.pp $(wildcard $(OBJPASDIR)/classes/*.inc) \
@@ -295,7 +295,7 @@ termio$(PPUEXT) : termio.pp baseunix$(PPUEXT)
 dl$(PPUEXT) : $(UNIXINC)/dl.pp $(SYSTEMUNIT)$(PPUEXT) unixtype$(PPUEXT) ctypes$(PPUEXT)
 	$(COMPILER) $<
 
-errors$(PPUEXT) : $(UNIXINC)/errors.pp strings$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) strings$(PPUEXT)
+errors$(PPUEXT) : $(UNIXINC)/errors.pp unixtype$(PPUEXT) strings$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) strings$(PPUEXT)
 	$(COMPILER) $<
 
 cmem$(PPUEXT) : $(INC)/cmem.pp $(SYSTEMUNIT)$(PPUEXT)
@@ -304,7 +304,7 @@ cmem$(PPUEXT) : $(INC)/cmem.pp $(SYSTEMUNIT)$(PPUEXT)
 sysctl$(PPUEXT) : $(BSDINC)/sysctl.pp $(SYSTEMUNIT)$(PPUEXT) unixtype$(PPUEXT)
 	$(COMPILER) $<
 
-cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp unix$(PPUEXT) sysutils$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp unix$(PPUEXT) unixtype$(PPUEXT) sysutils$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
 
 initc$(PPUEXT) : $(UNIXINC)/initc.pp $(SYSTEMUNIT)$(PPUEXT) ctypes$(PPUEXT)

+ 4 - 4
rtl/linux/Makefile

@@ -4375,7 +4375,7 @@ dos$(PPUEXT) : $(UNIXINC)/dos.pp $(INC)/filerec.inc $(INC)/textrec.inc strings$(
 	$(COMPILER) $(UNIXINC)/dos.pp
 sysutils$(PPUEXT) : $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
 		    objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT) unixtype$(PPUEXT) \
-		    linux$(PPUEXT) syscall$(PPUEXT) baseunix$(PPUEXT) unixutil$(PPUEXT) initc$(PPUEXT)
+		    linux$(PPUEXT) syscall$(PPUEXT) baseunix$(PPUEXT) unixtype$(PPUEXT) unixutil$(PPUEXT) initc$(PPUEXT)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $(UNIXINC)/sysutils.pp
 classes$(PPUEXT) : $(UNIXINC)/classes.pp $(wildcard $(OBJPASDIR)/classes/*.inc) \
 		   sysutils$(PPUEXT) typinfo$(PPUEXT) rtlconsts$(PPUEXT) fgl$(PPUEXT) types$(PPUEXT) unix$(PPUEXT) sortbase$(PPUEXT)
@@ -4429,15 +4429,15 @@ fpwidestring$(PPUEXT): $(OBJPASDIR)/fpwidestring.pp character$(PPUEXT) unixcp$(P
 	$(COMPILER) $(OBJPASDIR)/fpwidestring.pp
 sortbase$(PPUEXT) : $(INC)/sortbase.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
-errors$(PPUEXT) : $(UNIXINC)/errors.pp strings$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+errors$(PPUEXT) : $(UNIXINC)/errors.pp strings$(PPUEXT) unixtype$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $(UNIXINC)/errors.pp
 callspec$(PPUEXT) : $(INC)/callspec.pp $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $(INC)/callspec.pp
 cmem$(PPUEXT) : $(INC)/cmem.pp $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $(INC)/cmem.pp
-cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp $(SYSTEMUNIT)$(PPUEXT) unix$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) initc$(PPUEXT) dl$(PPUEXT)
+cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp $(SYSTEMUNIT)$(PPUEXT) unixtype$(PPUEXT) unix$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) initc$(PPUEXT) dl$(PPUEXT)
 	$(COMPILER) $(UNIXINC)/cthreads.pp
-cwstring$(PPUEXT) : $(UNIXINC)/cwstring.pp $(SYSTEMUNIT)$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) unix$(PPUEXT) unixtype$(PPUEXT) ctypes$(PPUEXT) dynlibs$(PPUEXT) unixcp$(PPUEXT)
+cwstring$(PPUEXT) : $(UNIXINC)/cwstring.pp $(SYSTEMUNIT)$(PPUEXT) unixtype$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) unix$(PPUEXT) unixtype$(PPUEXT) ctypes$(PPUEXT) dynlibs$(PPUEXT) unixcp$(PPUEXT)
 	$(COMPILER) $(UNIXINC)/cwstring.pp
 ctypes$(PPUEXT) :  $(INC)/ctypes.pp unixtype$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $(INC)/ctypes.pp

+ 4 - 4
rtl/linux/Makefile.fpc

@@ -391,7 +391,7 @@ dos$(PPUEXT) : $(UNIXINC)/dos.pp $(INC)/filerec.inc $(INC)/textrec.inc strings$(
 
 sysutils$(PPUEXT) : $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
                     objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT) unixtype$(PPUEXT) \
-                    linux$(PPUEXT) syscall$(PPUEXT) baseunix$(PPUEXT) unixutil$(PPUEXT) initc$(PPUEXT)
+                    linux$(PPUEXT) syscall$(PPUEXT) baseunix$(PPUEXT) unixtype$(PPUEXT) unixutil$(PPUEXT) initc$(PPUEXT)
         $(COMPILER) -Fi$(OBJPASDIR)/sysutils $(UNIXINC)/sysutils.pp
 
 classes$(PPUEXT) : $(UNIXINC)/classes.pp $(wildcard $(OBJPASDIR)/classes/*.inc) \
@@ -482,7 +482,7 @@ sortbase$(PPUEXT) : $(INC)/sortbase.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 # Other $(SYSTEMUNIT)-dependent RTL Units
 #
 
-errors$(PPUEXT) : $(UNIXINC)/errors.pp strings$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+errors$(PPUEXT) : $(UNIXINC)/errors.pp strings$(PPUEXT) unixtype$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $(UNIXINC)/errors.pp
 
 callspec$(PPUEXT) : $(INC)/callspec.pp $(SYSTEMUNIT)$(PPUEXT)
@@ -491,10 +491,10 @@ callspec$(PPUEXT) : $(INC)/callspec.pp $(SYSTEMUNIT)$(PPUEXT)
 cmem$(PPUEXT) : $(INC)/cmem.pp $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $(INC)/cmem.pp
 
-cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp $(SYSTEMUNIT)$(PPUEXT) unix$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) initc$(PPUEXT) dl$(PPUEXT)
+cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp $(SYSTEMUNIT)$(PPUEXT) unixtype$(PPUEXT) unix$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) initc$(PPUEXT) dl$(PPUEXT)
 	$(COMPILER) $(UNIXINC)/cthreads.pp
 
-cwstring$(PPUEXT) : $(UNIXINC)/cwstring.pp $(SYSTEMUNIT)$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) unix$(PPUEXT) unixtype$(PPUEXT) ctypes$(PPUEXT) dynlibs$(PPUEXT) unixcp$(PPUEXT)
+cwstring$(PPUEXT) : $(UNIXINC)/cwstring.pp $(SYSTEMUNIT)$(PPUEXT) unixtype$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) unix$(PPUEXT) unixtype$(PPUEXT) ctypes$(PPUEXT) dynlibs$(PPUEXT) unixcp$(PPUEXT)
 	$(COMPILER) $(UNIXINC)/cwstring.pp
 
 ctypes$(PPUEXT) :  $(INC)/ctypes.pp unixtype$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

+ 38 - 25
rtl/linux/x86_64/sighnd.inc

@@ -15,6 +15,7 @@
 
  **********************************************************************}
 
+{ $define SYSTEM_DEBUG}
 
 { use a trampoline which pushes the return address for proper unwinding }
 Procedure SignalToHandleErrorAddrFrame (Errno : longint;addr : CodePointer; frame : Pointer); nostackframe; assembler;
@@ -33,9 +34,8 @@ function GetFPUState(const SigContext : TSigContext) : word;
     else
       GetFPUState:=0;
   {$ifdef SYSTEM_DEBUG}
-    writeln('xx:',sigcontext.twd,' ',sigcontext.cwd);
-  {$endif SYSTEM_DEBUG}
-  {$ifdef SYSTEM_DEBUG}
+    if assigned(SigContext.fpstate) then
+    writeln('Tag: ',sigcontext.fpstate^.twd,' Cw: ',sigcontext.fpstate^.cwd);
     Writeln(stderr,'FpuState = ',result);
   {$endif SYSTEM_DEBUG}
   end;
@@ -85,32 +85,45 @@ procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; SigContext: PSigCon
                   { exceptions are handled, clear all flags
                     as we return from SignalToRunerrer, we have to clear the exception flags in the context }
                   if assigned(SigContext^.fpstate) then
-                    SigContext^.fpstate^.swd:=SigContext^.fpstate^.swd and not(FPU_All);
+                    SigContext^.fpstate^.swd:=SigContext^.fpstate^.swd and not($37ff);
                 end;
-                MMState:=getMMState(SigContext^);
-                if (MMState and MM_ExceptionMask)<>0 then
-                  begin
-                    { first check the more precise options }
-                    if (MMState and MM_DivisionByZero)<>0 then
-                      res:=208
-                    else if (MMState and MM_Invalid)<>0 Then
-                      res:=207
-                    else if (MMState and MM_Overflow)<>0 then
-                      res:=205
-                    else if (MMState and MM_Underflow)<>0 then
-                      res:=206
-                    else if (MMState and MM_Denormal)<>0 then
-                      res:=216
-                    else
-                      res:=207;  {'Coprocessor Error'}
+              MMState:=getMMState(SigContext^);
+              if (MMState and MM_ExceptionMask)<>0 then
+                begin
+                  { first check the more precise options }
+                  if (MMState and MM_DivisionByZero)<>0 then
+                    res:=208
+                  else if (MMState and MM_Invalid)<>0 Then
+                    res:=207
+                  else if (MMState and MM_Overflow)<>0 then
+                    res:=205
+                  else if (MMState and MM_Underflow)<>0 then
+                    res:=206
+                  else if (MMState and MM_Denormal)<>0 then
+                    res:=216
+                  else
+                    res:=207;  {'Coprocessor Error'}
 
-                    { exceptions are handled, clear all flags
-                      as we return from SignalToRunerrer, we have to clear the exception flags in the context }
-                    if assigned(SigContext^.fpstate) then
-                      SigContext^.fpstate^.mxcsr:=SigContext^.fpstate^.mxcsr and not(MM_ExceptionMask);
+                  { exceptions are handled, clear all flags
+                    as we return from SignalToRunerrer, we have to clear the exception flags in the context }
+                  if assigned(SigContext^.fpstate) then
+                    SigContext^.fpstate^.mxcsr:=SigContext^.fpstate^.mxcsr and not(MM_ExceptionMask);
+                end;
+              if assigned(SigContext^.fpstate) then
+                with SigContext^.fpstate^ do
+                  begin
+  {$ifdef SYSTEM_DEBUG}
+                    Writeln(stderr,'fpstate^.swd = ',swd);
+  {$endif SYSTEM_DEBUG}
+                    { acutally, I am not sure if we should really touch the controll word }
+                    cwd:=Default8087CW;
+                    { found by trial and error that setting to 0 means empty }
+                    twd:=$0;
+                    { clear top }
+                    swd:=swd and not($3700);
                   end;
+               SysResetFPU;
             end;
-          SysResetFPU;
         end;
       SIGILL,
       SIGBUS,

+ 18 - 0
tests/webtbs/tw34543.pp

@@ -0,0 +1,18 @@
+{ %norun }
+
+{$r+}
+procedure range_check_fail;
+var v : word;
+    vTo : word;
+    vNo : word;
+begin
+     vTo:=3;
+     vNo:=0;
+     for v:=vNo to vTo do {Error: range check error while evaluating constants (-1 must be between 0 and 65535)}
+     begin
+     end;
+end;
+
+begin
+end.
+

+ 28 - 0
tests/webtbs/tw37468b.pp

@@ -0,0 +1,28 @@
+program Project1;
+
+{$mode objfpc}{$H+}
+
+uses math, sysutils
+  { you can add units after this };
+
+begin
+  try
+    writeln(power(0, -4));
+  except
+    on e: Exception do ClearExceptions(false);
+  end;
+  try
+    writeln(power(0, -3));
+  except
+    on e: Exception do ClearExceptions(false);
+  end;
+  try
+    writeln(power(0, -4));
+  except
+    on e: Exception do ClearExceptions(false);
+  end;
+
+  writeln('caught');
+  writeln(power(16, 0.5));
+  writeln('done');
+end.

+ 5 - 6
utils/pas2js/dist/rtl.js

@@ -286,15 +286,14 @@ var rtl = {
   },
 
   initClass: function(c,parent,name,initfn,rttiname){
-    if (!rttiname) rttiname = name;
     parent[name] = c;
     c.$class = c; // Note: o.$class === Object.getPrototypeOf(o)
-    c.$classname = rttiname;
+    c.$classname = rttiname?rttiname:name;
     parent = rtl.initStruct(c,parent,name);
     c.$fullname = parent.$name+'.'+name;
     // rtti
     if (rtl.debug_rtti) rtl.debug('initClass '+c.$fullname);
-    var t = c.$module.$rtti.$Class(rttiname,{ "class": c });
+    var t = c.$module.$rtti.$Class(c.$classname,{ "class": c });
     c.$rtti = t;
     if (rtl.isObject(c.$ancestor)) t.ancestor = c.$ancestor.$rtti;
     if (!t.ancestor) t.ancestor = null;
@@ -402,7 +401,7 @@ var rtl = {
     }
   },
 
-  createHelper: function(parent,name,ancestor,initfn){
+  createHelper: function(parent,name,ancestor,initfn,rttiname){
     // create a helper,
     // ancestor must be null or a helper,
     var c = null;
@@ -415,11 +414,11 @@ var rtl = {
     };
     parent[name] = c;
     c.$class = c; // Note: o.$class === Object.getPrototypeOf(o)
-    c.$classname = name;
+    c.$classname = rttiname?rttiname:name;
     parent = rtl.initStruct(c,parent,name);
     c.$fullname = parent.$name+'.'+name;
     // rtti
-    var t = c.$module.$rtti.$Helper(c.$name,{ "helper": c });
+    var t = c.$module.$rtti.$Helper(c.$classname,{ "helper": c });
     c.$rtti = t;
     if (rtl.isObject(ancestor)) t.ancestor = ancestor.$rtti;
     if (!t.ancestor) t.ancestor = null;