democlasstopas.pas 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. program democlasstopas;
  2. uses JS, Types, SysUtils;
  3. function ClassToPas(Obj: TJSObject): string;
  4. var
  5. Names: TStringDynArray;
  6. i, j: Integer;
  7. t: String;
  8. p: TJSArray;
  9. f: TJSFunction;
  10. Value: JSValue;
  11. begin
  12. Result:='';
  13. p:=TJSArray.new;
  14. while Obj<>nil do
  15. begin
  16. Names:=TJSObject.getOwnPropertyNames(Obj);
  17. for i:=0 to length(Names)-1 do
  18. begin
  19. try
  20. Value:=Obj[Names[i]];
  21. except
  22. Result:=Result+'// not readable property "'+Names[i]+'"'+sLineBreak;
  23. end;
  24. if jsTypeOf(Value)='function' then
  25. begin
  26. f:=TJSFunction(Value);
  27. t:='function '+f.name+'(';
  28. for j:=1 to NativeInt(f['length']) do
  29. begin
  30. if j>1 then t:=t+';';
  31. t:=t+'arg'+IntToStr(j)+' : argtype'+IntToStr(j);
  32. end;
  33. t:=t+') : returntype;';
  34. end
  35. else
  36. t:=Names[i]+' : vartype;';
  37. if p.indexOf(t)<0 then
  38. begin
  39. p.push(t);
  40. Result:=Result+t+sLineBreak;
  41. end;
  42. end;
  43. Obj:=TJSObject.getPrototypeOf(Obj);
  44. if Obj<>nil then
  45. Result:=Result+'// next getPrototypeOf ...'+sLineBreak;
  46. end;
  47. end;
  48. procedure ShowRTLProps;
  49. var
  50. o: TJSObject;
  51. begin
  52. // get the new JavaScript object:
  53. asm
  54. o = window.localStorage; // rtl
  55. end;
  56. writeln(ClassToPas(o));
  57. end;
  58. begin
  59. ShowRTLProps;
  60. end.