* Support for enum return type

This commit is contained in:
Michaël Van Canneyt 2024-04-09 10:34:04 +02:00
parent fd68d3bfbb
commit 43487dac24
2 changed files with 55 additions and 4 deletions

View File

@ -75,7 +75,7 @@ type
FPasInterfaceSuffix: TIDLString;
function GetFunctionSuffix(aDef: TIDLFunctionDefinition; Overloads: TFPObjectList): String;
function GetInvokeClassName(aResultDef: TIDLDefinition; aName: TIDLString; aDef: TIDLFunctionDefinition=nil): TIDLString;
function GetInvokeNameFromTypeName(aTypeName: TIDLString): TIDLString;
function GetInvokeNameFromTypeName(aTypeName: TIDLString; aType: TIDLDefinition): TIDLString;
Protected
function BaseUnits: String; override;
@ -518,7 +518,7 @@ begin
end;
end;
function TWebIDLToPasWasmJob.GetInvokeNameFromTypeName(aTypeName : TIDLString): TIDLString;
function TWebIDLToPasWasmJob.GetInvokeNameFromTypeName(aTypeName : TIDLString; aType : TIDLDefinition): TIDLString;
begin
case aTypeName of
@ -543,7 +543,10 @@ begin
Result:='InvokeJSNoResult';
end;
else
Result:='InvokeJSObjectResult';
if aType is TIDLEnumDefinition then
Result:='InvokeJSUnicodeStringResult'
else
Result:='InvokeJSObjectResult';
end;
end;
@ -591,7 +594,7 @@ begin
else
begin
FuncName:=GetName(aDef);
InvokeName:=GetInvokeNameFromTypeName(ResolvedReturnTypeName);
InvokeName:=GetInvokeNameFromTypeName(ResolvedReturnTypeName,Result);
case InvokeName of
'InvokeJSNoResult' :
begin

View File

@ -46,6 +46,7 @@ type
procedure TestWJ_IntfFunction_SetEventHandler;
procedure TestWJ_IntfFunction_Promise;
procedure TestWJ_IntfFunction_ArgAny;
procedure TestWJ_IntfFunction_EnumResult;
// Namespace attribute
procedure TestWJ_NamespaceAttribute_Boolean;
// maplike
@ -688,6 +689,53 @@ begin
'']);
end;
procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_EnumResult;
begin
TestWebIDL([
'enum E { ',
' "allowed", ',
' "disallowed" ',
'}; ',
'interface IE { ',
' E get(long a); ',
'};'
],[
'Type',
' // Forward class definitions',
' IJSIE = interface;',
' TJSIE = class;',
' TE = UnicodeString;',
' { --------------------------------------------------------------------',
' TJSIE',
' --------------------------------------------------------------------}',
' IJSIE = interface(IJSObject)',
' [''{04D06E4C-6063-3E89-A483-3296C9C8AA41}'']',
' function get(a: Integer) : TE;',
' end;',
'',
' TJSIE = class(TJSObject,IJSIE)',
' Private',
' Public',
' function get(a: Integer) : TE;',
' class function Cast(const Intf: IJSObject): IJSIE;',
' end;',
'',
'implementation',
'',
'function TJSIE.get(a: Integer) : TE;',
'begin',
' Result:=InvokeJSUnicodeStringResult(''get'',[a]);',
'end;',
'',
'class function TJSIE.Cast(const Intf: IJSObject): IJSIE;',
'begin',
' Result:=TJSIE.JOBCast(Intf);',
'end;',
'',
'end.'
]);
end;
procedure TTestWebIDL2WasmJob.TestWJ_NamespaceAttribute_Boolean;
begin
TestWebIDL([