webidl: nicer error messages, fixed function returning Object

This commit is contained in:
mattias 2022-07-25 18:49:45 +02:00
parent f0eccda1ab
commit 9b1d5ef92a
2 changed files with 23 additions and 1 deletions

View File

@ -278,6 +278,8 @@ end;
function TBaseWebIDLToPas.GetPasClassName(const aName: string): string;
begin
if aName='' then
raise EConvertError.Create('[20220725184209] empty name');
Result:=ClassPrefix+aName+ClassSuffix;
end;
@ -1499,6 +1501,8 @@ begin
CN:=D.Name;
if D Is TIDLInterfaceDefinition then
begin
if CN='' then
raise EConvertError.Create('[20220725184324] at '+GetDefPos(D));
if not TIDLInterfaceDefinition(D).IsPartial then
AddJSIdentifier(D);
CN:=ClassPrefix+CN+ClassSuffix;
@ -1508,6 +1512,8 @@ begin
end
else if D Is TIDLDictionaryDefinition then
begin
if CN='' then
raise EConvertError.Create('[20220725184410] at '+GetDefPos(D));
if not TIDLDictionaryDefinition(D).IsPartial then
AddJSIdentifier(D);
if coDictionaryAsClass in BaseOptions then

View File

@ -143,6 +143,8 @@ begin
and (RightStr(Result,length(ClassSuffix))=ClassSuffix)
then
Result:=copy(Result,length(ClassPrefix)+1,length(Result)-length(ClassPrefix)-length(ClassSuffix));
if Result='' then
raise EConvertError.Create('[20220725184518]');
Result:=PasInterfacePrefix+Result+PasInterfaceSuffix;
end;
@ -153,6 +155,8 @@ begin
and (RightStr(Result,length(PasInterfaceSuffix))=PasInterfaceSuffix)
then
Result:=copy(Result,length(PasInterfacePrefix)+1,length(Result)-length(PasInterfacePrefix)-length(PasInterfaceSuffix));
if Result='' then
raise EConvertError.Create('[20220725184440]');
Result:=ClassPrefix+Result+ClassSuffix;
end;
@ -244,13 +248,20 @@ begin
and (LeftStr(Result,length(PasInterfacePrefix))<>PasInterfacePrefix)
and (RightStr(Result,length(PasInterfaceSuffix))<>PasInterfaceSuffix)
then
begin
if Result='' then
raise EConvertError.Create('[20220725184536]');
Result:=PasInterfacePrefix+Result+PasInterfaceSuffix;
end;
end;
end;
function TWebIDLToPasWasmJob.GetPasIntfName(Intf: TIDLDefinition): string;
begin
Result:=GetPasClassName(GetName(Intf));
Result:=GetName(Intf);
if Result='' then
raise EConvertError.Create('[20220725184653] missing name at '+GetDefPos(Intf));
Result:=GetPasClassName(Result);
end;
function TWebIDLToPasWasmJob.GetInterfaceDefHead(Intf: TIDLInterfaceDefinition
@ -456,6 +467,7 @@ begin
'QWord': InvokeName:='InvokeJSMaxIntResult';
'Single',
'Double': InvokeName:='InvokeJSDoubleResult';
'UTF8String',
'UnicodeString': InvokeName:='InvokeJSUnicodeStringResult';
'TJOB_JSValue': InvokeName:='InvokeJSValueResult';
'void','undefined':
@ -473,6 +485,10 @@ begin
InvokeClassName:=ReturnTypeName;
ReturnTypeName:=GetPasIntfName(ReturnDef);
end
else if ResolvedReturnTypeName=PasInterfacePrefix+'Object'+PasInterfaceSuffix then
begin
InvokeClassName:=ClassPrefix+'Object'+ClassSuffix;
end
else
raise EConvertError.Create('[20220725172242] not yet supported: function return type '+ResolvedReturnTypeName+' '+ReturnDef.ClassName+' at '+GetDefPos(aDef));
end;