mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-16 02:59:04 +02:00
* Patch from Henrique Werlang to access external classes RTTI info. Fix issue #38944
This commit is contained in:
parent
a8b1e1f7c4
commit
7f643577a7
@ -80,6 +80,7 @@ type
|
|||||||
|
|
||||||
TRttiType = class;
|
TRttiType = class;
|
||||||
TRttiInstanceType = class;
|
TRttiInstanceType = class;
|
||||||
|
TRttiInstanceExternalType = class;
|
||||||
|
|
||||||
{ TRTTIContext }
|
{ TRTTIContext }
|
||||||
|
|
||||||
@ -250,15 +251,17 @@ type
|
|||||||
FTypeInfo: TTypeInfo;
|
FTypeInfo: TTypeInfo;
|
||||||
//FMethods: specialize TArray<TRttiMethod>;
|
//FMethods: specialize TArray<TRttiMethod>;
|
||||||
function GetAsInstance: TRttiInstanceType;
|
function GetAsInstance: TRttiInstanceType;
|
||||||
|
function GetAsInstanceExternal: TRttiInstanceExternalType;
|
||||||
function GetQualifiedName: String;
|
function GetQualifiedName: String;
|
||||||
protected
|
protected
|
||||||
function GetName: string; override;
|
function GetName: string; override;
|
||||||
//function GetHandle: Pointer; override;
|
//function GetHandle: Pointer; override;
|
||||||
function GetIsInstance: boolean;
|
function GetIsInstance: Boolean;
|
||||||
//function GetIsManaged: boolean; virtual;
|
function GetIsInstanceExternal: Boolean;
|
||||||
function GetIsOrdinal: boolean; virtual;
|
//function GetIsManaged: Boolean; virtual;
|
||||||
function GetIsRecord: boolean; virtual;
|
function GetIsOrdinal: Boolean; virtual;
|
||||||
function GetIsSet: boolean; virtual;
|
function GetIsRecord: Boolean; virtual;
|
||||||
|
function GetIsSet: Boolean; virtual;
|
||||||
function GetTypeKind: TTypeKind; virtual;
|
function GetTypeKind: TTypeKind; virtual;
|
||||||
//function GetTypeSize: integer; virtual;
|
//function GetTypeSize: integer; virtual;
|
||||||
//function GetBaseType: TRttiType; virtual;
|
//function GetBaseType: TRttiType; virtual;
|
||||||
@ -279,13 +282,15 @@ type
|
|||||||
function GetDeclaredFields: TRttiFieldArray; virtual;
|
function GetDeclaredFields: TRttiFieldArray; virtual;
|
||||||
|
|
||||||
property Handle: TTypeInfo read FTypeInfo;
|
property Handle: TTypeInfo read FTypeInfo;
|
||||||
property IsInstance: boolean read GetIsInstance;
|
property IsInstance: Boolean read GetIsInstance;
|
||||||
//property isManaged: boolean read GetIsManaged;
|
property IsInstanceExternal: Boolean read GetIsInstanceExternal;
|
||||||
property IsOrdinal: boolean read GetIsOrdinal;
|
//property isManaged: Boolean read GetIsManaged;
|
||||||
property IsRecord: boolean read GetIsRecord;
|
property IsOrdinal: Boolean read GetIsOrdinal;
|
||||||
property IsSet: boolean read GetIsSet;
|
property IsRecord: Boolean read GetIsRecord;
|
||||||
|
property IsSet: Boolean read GetIsSet;
|
||||||
//property BaseType: TRttiType read GetBaseType;
|
//property BaseType: TRttiType read GetBaseType;
|
||||||
property AsInstance: TRttiInstanceType read GetAsInstance;
|
property AsInstance: TRttiInstanceType read GetAsInstance;
|
||||||
|
property AsInstanceExternal: TRttiInstanceExternalType read GetAsInstanceExternal;
|
||||||
property TypeKind: TTypeKind read GetTypeKind;
|
property TypeKind: TTypeKind read GetTypeKind;
|
||||||
//property TypeSize: integer read GetTypeSize;
|
//property TypeSize: integer read GetTypeSize;
|
||||||
property QualifiedName: String read GetQualifiedName;
|
property QualifiedName: String read GetQualifiedName;
|
||||||
@ -378,6 +383,21 @@ type
|
|||||||
property MetaclassType: TClass read GetMetaclassType;
|
property MetaclassType: TClass read GetMetaclassType;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TRttiInstanceExternalType }
|
||||||
|
|
||||||
|
TRttiInstanceExternalType = class(TRttiType)
|
||||||
|
private
|
||||||
|
function GetAncestor: TRttiInstanceExternalType;
|
||||||
|
function GetExternalName: String;
|
||||||
|
function GetExternalClassTypeInfo: TTypeInfoExtClass;
|
||||||
|
public
|
||||||
|
constructor Create(ATypeInfo: PTypeInfo);
|
||||||
|
|
||||||
|
property Ancestor: TRttiInstanceExternalType read GetAncestor;
|
||||||
|
property ExternalClassTypeInfo: TTypeInfoExtClass read GetExternalClassTypeInfo;
|
||||||
|
property ExternalName: String read GetExternalName;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TRttiOrdinalType }
|
{ TRttiOrdinalType }
|
||||||
|
|
||||||
TRttiOrdinalType = class(TRttiType)
|
TRttiOrdinalType = class(TRttiType)
|
||||||
@ -1271,6 +1291,31 @@ begin
|
|||||||
Result := InstanceType.MetaClassType;
|
Result := InstanceType.MetaClassType;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TRttiInstanceExternalType }
|
||||||
|
|
||||||
|
function TRttiInstanceExternalType.GetAncestor: TRttiInstanceExternalType;
|
||||||
|
begin
|
||||||
|
Result := GRttiContext.GetType(ExternalClassTypeInfo.Ancestor) as TRttiInstanceExternalType;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRttiInstanceExternalType.GetExternalClassTypeInfo: TTypeInfoExtClass;
|
||||||
|
begin
|
||||||
|
Result := TTypeInfoExtClass(FTypeInfo);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRttiInstanceExternalType.GetExternalName: String;
|
||||||
|
begin
|
||||||
|
Result := ExternalClassTypeInfo.JSClassName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TRttiInstanceExternalType.Create(ATypeInfo: PTypeInfo);
|
||||||
|
begin
|
||||||
|
if not (TTypeInfo(ATypeInfo) is TTypeInfoExtClass) then
|
||||||
|
raise EInvalidCast.Create('');
|
||||||
|
|
||||||
|
inherited Create(ATypeInfo);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TRTTIContext }
|
{ TRTTIContext }
|
||||||
|
|
||||||
class constructor TRTTIContext.Init;
|
class constructor TRTTIContext.Init;
|
||||||
@ -1319,7 +1364,7 @@ var
|
|||||||
TRttiType, // tkRefToProcVar
|
TRttiType, // tkRefToProcVar
|
||||||
TRttiInterfaceType, // tkInterface
|
TRttiInterfaceType, // tkInterface
|
||||||
TRttiType, // tkHelper
|
TRttiType, // tkHelper
|
||||||
TRttiInstanceType // tkExtClass
|
TRttiInstanceExternalType // tkExtClass
|
||||||
);
|
);
|
||||||
t: TTypeinfo absolute aTypeInfo;
|
t: TTypeinfo absolute aTypeInfo;
|
||||||
Name: String;
|
Name: String;
|
||||||
@ -1522,7 +1567,7 @@ end;
|
|||||||
|
|
||||||
function TRttiMethod.GetIsAsyncCall: Boolean;
|
function TRttiMethod.GetIsAsyncCall: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := pfAsync in GetProcedureFlags;
|
Result := (pfAsync in GetProcedureFlags) or Assigned(ReturnType) and ReturnType.IsInstanceExternal and (ReturnType.AsInstanceExternal.ExternalName = 'Promise');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TRttiMethod.GetIsSafeCall: Boolean;
|
function TRttiMethod.GetIsSafeCall: Boolean;
|
||||||
@ -1666,6 +1711,11 @@ begin
|
|||||||
Result:=Self is TRttiInstanceType;
|
Result:=Self is TRttiInstanceType;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TRttiType.GetIsInstanceExternal: boolean;
|
||||||
|
begin
|
||||||
|
Result:=Self is TRttiInstanceExternalType;
|
||||||
|
end;
|
||||||
|
|
||||||
function TRttiType.GetIsOrdinal: boolean;
|
function TRttiType.GetIsOrdinal: boolean;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
@ -1691,6 +1741,11 @@ begin
|
|||||||
Result := Self as TRttiInstanceType;
|
Result := Self as TRttiInstanceType;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TRttiType.GetAsInstanceExternal: TRttiInstanceExternalType;
|
||||||
|
begin
|
||||||
|
Result := Self as TRttiInstanceExternalType;
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TRttiType.Create(ATypeInfo: PTypeInfo);
|
constructor TRttiType.Create(ATypeInfo: PTypeInfo);
|
||||||
begin
|
begin
|
||||||
inherited Create();
|
inherited Create();
|
||||||
|
Loading…
Reference in New Issue
Block a user