mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-24 18:39:27 +02:00
Now the make function can create records.
This commit is contained in:
parent
038b896f03
commit
6ff4275792
@ -71,6 +71,7 @@ type
|
|||||||
generic function IsType<T>(const EmptyAsAnyType: Boolean = True): Boolean; overload;
|
generic function IsType<T>(const EmptyAsAnyType: Boolean = True): Boolean; overload;
|
||||||
function GetArrayElement(aIndex: SizeInt): TValue;
|
function GetArrayElement(aIndex: SizeInt): TValue;
|
||||||
function GetArrayLength: SizeInt;
|
function GetArrayLength: SizeInt;
|
||||||
|
function GetReferenceToRawData: Pointer;
|
||||||
function IsArray: boolean;
|
function IsArray: boolean;
|
||||||
function IsClass: boolean;
|
function IsClass: boolean;
|
||||||
function IsObject: boolean;
|
function IsObject: boolean;
|
||||||
@ -833,8 +834,15 @@ end;
|
|||||||
|
|
||||||
class procedure TValue.Make(const ABuffer: JSValue; const ATypeInfo: PTypeInfo; var Result: TValue);
|
class procedure TValue.Make(const ABuffer: JSValue; const ATypeInfo: PTypeInfo; var Result: TValue);
|
||||||
begin
|
begin
|
||||||
Result.FData := ABuffer;
|
|
||||||
Result.FTypeInfo := ATypeInfo;
|
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;
|
end;
|
||||||
|
|
||||||
generic class procedure TValue.Make<T>(const Value: T; var Result: TValue);
|
generic class procedure TValue.Make<T>(const Value: T; var Result: TValue);
|
||||||
@ -1175,6 +1183,11 @@ begin
|
|||||||
raise EInvalidCast.Create(SErrInvalidTypecast);
|
raise EInvalidCast.Create(SErrInvalidTypecast);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TValue.GetReferenceToRawData: Pointer;
|
||||||
|
begin
|
||||||
|
Result := Pointer(GetData);
|
||||||
|
end;
|
||||||
|
|
||||||
function TValue.IsType(ATypeInfo: TTypeInfo): boolean;
|
function TValue.IsType(ATypeInfo: TTypeInfo): boolean;
|
||||||
begin
|
begin
|
||||||
Result := ATypeInfo = TypeInfo;
|
Result := ATypeInfo = TypeInfo;
|
||||||
|
@ -291,9 +291,17 @@ type
|
|||||||
|
|
||||||
{ TTypeInfoRecord - Kind = tkRecord }
|
{ 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)
|
TTypeInfoRecord = class external name 'rtl.tTypeInfoRecord'(TTypeInfoStruct)
|
||||||
public
|
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;
|
end;
|
||||||
|
|
||||||
{ TTypeInfoClass - Kind = tkClass }
|
{ TTypeInfoClass - Kind = tkClass }
|
||||||
|
Loading…
Reference in New Issue
Block a user