From 6ff4275792a97335b2588751290443c28b60b769 Mon Sep 17 00:00:00 2001 From: Henrique Gottardi Werlang Date: Tue, 16 Jan 2024 17:17:22 -0300 Subject: [PATCH] Now the make function can create records. --- packages/rtl/src/rtti.pas | 15 ++++++++++++++- packages/rtl/src/typinfo.pas | 10 +++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/rtl/src/rtti.pas b/packages/rtl/src/rtti.pas index be892e6..44ef1d1 100644 --- a/packages/rtl/src/rtti.pas +++ b/packages/rtl/src/rtti.pas @@ -71,6 +71,7 @@ type generic function IsType(const EmptyAsAnyType: Boolean = True): Boolean; overload; function GetArrayElement(aIndex: SizeInt): TValue; function GetArrayLength: SizeInt; + function GetReferenceToRawData: Pointer; function IsArray: boolean; function IsClass: boolean; function IsObject: boolean; @@ -833,8 +834,15 @@ end; class procedure TValue.Make(const ABuffer: JSValue; const ATypeInfo: PTypeInfo; var Result: TValue); begin - Result.FData := ABuffer; Result.FTypeInfo := ATypeInfo; + + if Result.FTypeInfo.Kind = tkRecord then + if Assigned(ABuffer) then + Result.FData := TTypeInfoRecord(ATypeInfo).RecordInfo.Assign(ABuffer) + else + Result.FData := TTypeInfoRecord(ATypeInfo).RecordInfo.New + else + Result.FData := ABuffer; end; generic class procedure TValue.Make(const Value: T; var Result: TValue); @@ -1175,6 +1183,11 @@ begin raise EInvalidCast.Create(SErrInvalidTypecast); end; +function TValue.GetReferenceToRawData: Pointer; +begin + Result := Pointer(GetData); +end; + function TValue.IsType(ATypeInfo: TTypeInfo): boolean; begin Result := ATypeInfo = TypeInfo; diff --git a/packages/rtl/src/typinfo.pas b/packages/rtl/src/typinfo.pas index 7cd4888..01333a0 100644 --- a/packages/rtl/src/typinfo.pas +++ b/packages/rtl/src/typinfo.pas @@ -291,9 +291,17 @@ type { TTypeInfoRecord - Kind = tkRecord } + TRecordInfo = class external name 'Object'(TJSObject) + public + function Assign(Source: JSValue): JSValue; external name '$assign'; + function Clone(Source: JSValue): JSValue; external name '$clone'; + function Equals(Source: JSValue): Boolean; external name '$eq'; + function New: JSValue; external name '$new'; + end; + TTypeInfoRecord = class external name 'rtl.tTypeInfoRecord'(TTypeInfoStruct) public - RecordType: TJSObject external name '$record'; // only records with class vars, else jsundefined + RecordInfo: TRecordInfo external name '$record'; // only records with class vars, else jsundefined end; { TTypeInfoClass - Kind = tkClass }