Browse Source

webidl: property enum

mattias 3 years ago
parent
commit
9dabf6e3e4
1 changed files with 24 additions and 5 deletions
  1. 24 5
      packages/webidl/src/webidltowasmjob.pp

+ 24 - 5
packages/webidl/src/webidltowasmjob.pp

@@ -93,6 +93,7 @@ type
     function WriteUtilityMethods(Intf: TIDLInterfaceDefinition): Integer;
     function WriteUtilityMethods(Intf: TIDLInterfaceDefinition): Integer;
       override;
       override;
     // Definitions. Return true if a definition was written.
     // Definitions. Return true if a definition was written.
+    function WriteEnumDef(aDef: TIDLEnumDefinition): Boolean; override;
     function WriteDictionaryField(aField: TIDLDictionaryMemberDefinition
     function WriteDictionaryField(aField: TIDLDictionaryMemberDefinition
       ): Boolean; override;
       ): Boolean; override;
     function WriteForwardClassDef(D: TIDLStructuredDefinition): Boolean;
     function WriteForwardClassDef(D: TIDLStructuredDefinition): Boolean;
@@ -380,6 +381,12 @@ begin
   IncludeImplementationCode.Add(Code);
   IncludeImplementationCode.Add(Code);
 end;
 end;
 
 
+function TWebIDLToPasWasmJob.WriteEnumDef(aDef: TIDLEnumDefinition): Boolean;
+begin
+  Result:=True;
+  AddLn(GetName(aDef)+' = UnicodeString;');
+end;
+
 function TWebIDLToPasWasmJob.WriteDictionaryField(
 function TWebIDLToPasWasmJob.WriteDictionaryField(
   aField: TIDLDictionaryMemberDefinition): Boolean;
   aField: TIDLDictionaryMemberDefinition): Boolean;
 var
 var
@@ -471,7 +478,7 @@ begin
     'QWord': InvokeName:='InvokeJSMaxIntResult';
     'QWord': InvokeName:='InvokeJSMaxIntResult';
     'Single',
     'Single',
     'Double': InvokeName:='InvokeJSDoubleResult';
     'Double': InvokeName:='InvokeJSDoubleResult';
-    'UTF8String',
+    'UTF8String': InvokeName:='InvokeJSUTF8StringResult';
     'UnicodeString': InvokeName:='InvokeJSUnicodeStringResult';
     'UnicodeString': InvokeName:='InvokeJSUnicodeStringResult';
     'TJOB_JSValue': InvokeName:='InvokeJSValueResult';
     'TJOB_JSValue': InvokeName:='InvokeJSValueResult';
     'void','undefined':
     'void','undefined':
@@ -681,6 +688,7 @@ begin
       'QWord': GetFunc:='GetMaxInt';
       'QWord': GetFunc:='GetMaxInt';
       'Single',
       'Single',
       'Double': GetFunc:='GetDouble';
       'Double': GetFunc:='GetDouble';
+      'UTF8String',
       'UnicodeString': GetFunc:='GetString';
       'UnicodeString': GetFunc:='GetString';
       'TJOB_JSValue': GetFunc:='GetValue';
       'TJOB_JSValue': GetFunc:='GetValue';
       else
       else
@@ -726,6 +734,7 @@ begin
     'QWord',
     'QWord',
     'Single',
     'Single',
     'Double': GetFunc:='Result:=H.AllocDouble('+Call+');';
     'Double': GetFunc:='Result:=H.AllocDouble('+Call+');';
+    'UTF8String': GetFunc:='Result:=H.AllocString('+Call+');';
     'UnicodeString': GetFunc:='Result:=H.AllocString('+Call+');';
     'UnicodeString': GetFunc:='Result:=H.AllocString('+Call+');';
     'TJOB_JSValue': GetFunc:='Result:=H.AllocJSValue('+Call+');';
     'TJOB_JSValue': GetFunc:='Result:=H.AllocJSValue('+Call+');';
     else
     else
@@ -751,7 +760,7 @@ function TWebIDLToPasWasmJob.WritePrivateGetter(Attr: TIDLAttributeDefinition
 var
 var
   Data: TPasDataWasmJob;
   Data: TPasDataWasmJob;
   FuncName, aClassName, Code, ReadFuncName, Call,
   FuncName, aClassName, Code, ReadFuncName, Call,
-    AttrTypeName, AttrResolvedTypeName: String;
+    AttrTypeName, AttrResolvedTypeName, ObjClassName: String;
   AttrType: TIDLDefinition;
   AttrType: TIDLDefinition;
 begin
 begin
   Result:=true;
   Result:=true;
@@ -765,7 +774,10 @@ begin
   if AttrType is TIDLInterfaceDefinition then
   if AttrType is TIDLInterfaceDefinition then
     AttrTypeName:=GetPasIntfName(AttrType)
     AttrTypeName:=GetPasIntfName(AttrType)
   else if AttrType is TIDLFunctionDefinition then
   else if AttrType is TIDLFunctionDefinition then
-    exit;
+    exit // not supported yet
+  else if AttrType is TIDLEnumDefinition then
+    AttrResolvedTypeName:='UnicodeString';
+
   AddLn('function '+FuncName+': '+AttrTypeName+';');
   AddLn('function '+FuncName+': '+AttrTypeName+';');
 
 
   if Data.GetterBody<>'' then exit;
   if Data.GetterBody<>'' then exit;
@@ -785,10 +797,14 @@ begin
   'QWord': ReadFuncName:='ReadJSPropertyInt64';
   'QWord': ReadFuncName:='ReadJSPropertyInt64';
   'Single',
   'Single',
   'Double': ReadFuncName:='ReadJSPropertyDouble';
   'Double': ReadFuncName:='ReadJSPropertyDouble';
+  'UTF8String': ReadFuncName:='ReadJSPropertyUTF8String';
   'UnicodeString': ReadFuncName:='ReadJSPropertyUnicodeString';
   'UnicodeString': ReadFuncName:='ReadJSPropertyUnicodeString';
   'TJOB_JSValue': ReadFuncName:='ReadJSPropertyValue';
   'TJOB_JSValue': ReadFuncName:='ReadJSPropertyValue';
   else
   else
-    Call:='ReadJSPropertyObject('''+Attr.Name+''','+GetName(AttrType)+') as '+AttrTypeName;
+    ObjClassName:=GetName(AttrType);
+    if ObjClassName='' then
+      ObjClassName:=IntfToPasClassName(AttrTypeName);
+    Call:='ReadJSPropertyObject('''+Attr.Name+''','+ObjClassName+') as '+AttrTypeName;
   end;
   end;
 
 
   if Call='' then
   if Call='' then
@@ -823,7 +839,9 @@ begin
   if AttrType is TIDLInterfaceDefinition then
   if AttrType is TIDLInterfaceDefinition then
     AttrTypeName:=GetPasIntfName(AttrType)
     AttrTypeName:=GetPasIntfName(AttrType)
   else if AttrType is TIDLFunctionDefinition then
   else if AttrType is TIDLFunctionDefinition then
-    exit;
+    exit // not supported yet
+  else if AttrType is TIDLEnumDefinition then
+    AttrResolvedTypeName:='UnicodeString';
 
 
   AddLn('procedure '+FuncName+'(const aValue: '+AttrTypeName+');');
   AddLn('procedure '+FuncName+'(const aValue: '+AttrTypeName+');');
 
 
@@ -844,6 +862,7 @@ begin
   'QWord': WriteFuncName:='WriteJSPropertyDouble';
   'QWord': WriteFuncName:='WriteJSPropertyDouble';
   'Single',
   'Single',
   'Double': WriteFuncName:='WriteJSPropertyDouble';
   'Double': WriteFuncName:='WriteJSPropertyDouble';
+  'UTF8String': WriteFuncName:='WriteJSPropertyUTF8String';
   'UnicodeString': WriteFuncName:='WriteJSPropertyUnicodeString';
   'UnicodeString': WriteFuncName:='WriteJSPropertyUnicodeString';
   'TJOB_JSValue': WriteFuncName:='WriteJSPropertyValue';
   'TJOB_JSValue': WriteFuncName:='WriteJSPropertyValue';
   else
   else