* Fix stringifier

This commit is contained in:
Michaël Van Canneyt 2024-04-09 15:13:05 +02:00
parent 43487dac24
commit 38dac868e0
4 changed files with 58 additions and 11 deletions

View File

@ -310,10 +310,11 @@ end;
function TBaseWebIDLToPas.GetName(ADef: TIDLDefinition): String; function TBaseWebIDLToPas.GetName(ADef: TIDLDefinition): String;
begin begin
If Assigned(ADef) and (ADef.Data is TPasData) then If Assigned(ADef) then
Result:=TPasData(ADef.Data).PasName if (ADef.Data is TPasData) then
else Result:=TPasData(ADef.Data).PasName
Result:=ADef.Name; else
Result:=ADef.Name;
end; end;
function TBaseWebIDLToPas.GetPasClassName(const aName: string): string; function TBaseWebIDLToPas.GetPasClassName(const aName: string): string;

View File

@ -1075,11 +1075,17 @@ var
begin begin
aClassName:=GetName(aParent); aClassName:=GetName(aParent);
// case
// stringifier ;
// is equivalent to toString : DOMString
// no n
if (Attr.Name='') and (aoStringifier in Attr.Options) then
Exit;
if Attr.AttributeType=nil then
Exit;
AttrType:=GetPrivateGetterInfo(Attr,AttrTypeName,AttrResolvedTypeName,FuncName); AttrType:=GetPrivateGetterInfo(Attr,AttrTypeName,AttrResolvedTypeName,FuncName);
Call:=GetReadPropertyCall(AttrResolvedTypeName, AttrTypeName, Attr.Name, AttrType); Call:=GetReadPropertyCall(AttrResolvedTypeName, AttrTypeName, Attr.Name, AttrType);
Addln('function '+aClassName+'.'+FuncName+': '+AttrTypeName+';'); Addln('function '+aClassName+'.'+FuncName+': '+AttrTypeName+';');
Addln('begin'); Addln('begin');
Addln(' Result:='+Call+';'); Addln(' Result:='+Call+';');
@ -1095,6 +1101,8 @@ var
begin begin
Result:=true; Result:=true;
if (Attr.Name='') and (aoStringifier in Attr.Options) then
Exit;
if Attr.AttributeType=nil then if Attr.AttributeType=nil then
exit; exit;
AttrType:=GetPrivateGetterInfo(Attr,AttrTypeName,AttrResolvedTypeName,FuncName); AttrType:=GetPrivateGetterInfo(Attr,AttrTypeName,AttrResolvedTypeName,FuncName);
@ -1105,6 +1113,8 @@ function TWebIDLToPasWasmJob.GetPrivateSetterInfo(Attr: TIDLAttributeDefinition;
begin begin
Result:=nil; Result:=nil;
if (Attr.Name='') and (aoStringifier in Attr.Options) then
Exit;
if Attr.AttributeType=nil then if Attr.AttributeType=nil then
exit; exit;
FuncName:=SetterPrefix+GetName(Attr); FuncName:=SetterPrefix+GetName(Attr);

View File

@ -39,6 +39,7 @@ type
// attributes // attributes
procedure TestWJ_IntfAttribute_Boolean; procedure TestWJ_IntfAttribute_Boolean;
procedure TestWJ_IntfStringifier;
// todo procedure TestWJ_IntfAttribute_Any; // todo procedure TestWJ_IntfAttribute_Any;
// functions // functions
@ -478,6 +479,43 @@ begin
'']); '']);
end; end;
procedure TTestWebIDL2WasmJob.TestWJ_IntfStringifier;
begin
TestWebIDL([
'interface Attr {',
' stringifier;',
'};',
''],
['Type',
' // Forward class definitions',
' IJSAttr = interface;',
' TJSAttr = class;',
' { --------------------------------------------------------------------',
' TJSAttr',
' --------------------------------------------------------------------}',
'',
' IJSAttr = interface(IJSObject)',
' [''{AA94F45E-60F0-381A-A2A6-208CA4B2AF2A}'']',
' end;',
'',
' TJSAttr = class(TJSObject,IJSAttr)',
' Private',
' Public',
' class function Cast(const Intf: IJSObject): IJSAttr;',
' end;',
'',
'implementation',
'',
'class function TJSAttr.Cast(const Intf: IJSObject): IJSAttr;',
'begin',
' Result:=TJSAttr.JOBCast(Intf);',
'end;',
'',
'end.',
'']);
end;
procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_Void; procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_Void;
begin begin
TestWebIDL([ TestWebIDL([

View File

@ -22,13 +22,13 @@
</PublishOptions> </PublishOptions>
<RunParams> <RunParams>
<local> <local>
<CommandLineParams Value="--suite=TTestMapLikeInterfaceParser"/> <CommandLineParams Value="--suite=TTestWebIDL2WasmJob.TestWJ_IntfStringifier"/>
</local> </local>
<FormatVersion Value="2"/> <FormatVersion Value="2"/>
<Modes Count="1"> <Modes Count="1">
<Mode0 Name="default"> <Mode0 Name="default">
<local> <local>
<CommandLineParams Value="--suite=TTestMapLikeInterfaceParser"/> <CommandLineParams Value="--suite=TTestWebIDL2WasmJob.TestWJ_IntfStringifier"/>
</local> </local>
</Mode0> </Mode0>
</Modes> </Modes>
@ -89,6 +89,7 @@
</CodeGeneration> </CodeGeneration>
<Linking> <Linking>
<Debugging> <Debugging>
<DebugInfoType Value="dsDwarf3"/>
<TrashVariables Value="True"/> <TrashVariables Value="True"/>
</Debugging> </Debugging>
<Options> <Options>
@ -97,9 +98,6 @@
</Win32> </Win32>
</Options> </Options>
</Linking> </Linking>
<Other>
<CustomOptions Value="-tunicodertl"/>
</Other>
</CompilerOptions> </CompilerOptions>
<Debugging> <Debugging>
<Exceptions Count="3"> <Exceptions Count="3">