tcwebidl2wasmjob.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. unit tcwebidl2wasmjob;
  2. {$mode ObjFPC}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, fpcunit, testregistry, webidltowasmjob, pascodegen;
  6. type
  7. { TCustomTestWebIDL2WasmJob }
  8. TCustomTestWebIDL2WasmJob = Class(TTestCase)
  9. private
  10. FHeaderSrc: String;
  11. FWebIDLToPas: TWebIDLToPasWasmJob;
  12. procedure OnLog(Sender: TObject; LogType: TCodegenLogType; const Msg: String
  13. );
  14. protected
  15. procedure Setup; override;
  16. procedure TearDown; override;
  17. public
  18. procedure TestWebIDL(const WebIDLSrc, ExpectedPascalSrc: array of string); virtual;
  19. procedure CheckDiff(Msg, Expected, Actual: string); virtual;
  20. property WebIDLToPas: TWebIDLToPasWasmJob read FWebIDLToPas;
  21. property HeaderSrc: String read FHeaderSrc write FHeaderSrc;
  22. end;
  23. { TTestWebIDL2WasmJob }
  24. TTestWebIDL2WasmJob = Class(TCustomTestWebIDL2WasmJob)
  25. published
  26. procedure TestWJ_Empty;
  27. // typedefs
  28. procedure TestWJ_Typedef_Boolean;
  29. procedure TestWJ_Typedef_Sequence;
  30. // attributes
  31. procedure TestWJ_IntfAttribute_Boolean;
  32. // todo procedure TestWJ_IntfAttribute_Any;
  33. // functions
  34. procedure TestWJ_IntfFunction_Void;
  35. procedure TestWJ_IntfFunction_SetEventHandler;
  36. procedure TestWJ_IntfFunction_Promise;
  37. procedure TestWJ_IntfFunction_ArgAny;
  38. end;
  39. function LinesToStr(Args: array of const): string;
  40. function CheckSrcDiff(Expected, Actual: string; out Msg: string): boolean;
  41. implementation
  42. function LinesToStr(Args: array of const): string;
  43. var
  44. s: String;
  45. i: Integer;
  46. begin
  47. s:='';
  48. for i:=Low(Args) to High(Args) do
  49. case Args[i].VType of
  50. vtChar: s += Args[i].VChar+LineEnding;
  51. vtString: s += Args[i].VString^+LineEnding;
  52. vtPChar: s += Args[i].VPChar+LineEnding;
  53. vtWideChar: s += AnsiString(Args[i].VWideChar)+LineEnding;
  54. vtPWideChar: s += AnsiString(Args[i].VPWideChar)+LineEnding;
  55. vtAnsiString: s += AnsiString(Args[i].VAnsiString)+LineEnding;
  56. vtWidestring: s += AnsiString(WideString(Args[i].VWideString))+LineEnding;
  57. vtUnicodeString:s += AnsiString(UnicodeString(Args[i].VUnicodeString))+LineEnding;
  58. end;
  59. Result:=s;
  60. end;
  61. function CheckSrcDiff(Expected, Actual: string; out Msg: string): boolean;
  62. // search diff, ignore changes in spaces
  63. const
  64. SpaceChars = [#9,#10,#13,' '];
  65. var
  66. ExpectedP, ActualP: PChar;
  67. function FindLineEnd(p: PChar): PChar;
  68. begin
  69. Result:=p;
  70. while not (Result^ in [#0,#10,#13]) do inc(Result);
  71. end;
  72. function FindLineStart(p, MinP: PChar): PChar;
  73. begin
  74. while (p>MinP) and not (p[-1] in [#10,#13]) do dec(p);
  75. Result:=p;
  76. end;
  77. procedure SkipLineEnd(var p: PChar);
  78. begin
  79. if p^ in [#10,#13] then
  80. begin
  81. if (p[1] in [#10,#13]) and (p^<>p[1]) then
  82. inc(p,2)
  83. else
  84. inc(p);
  85. end;
  86. end;
  87. function HasSpecialChar(s: string): boolean;
  88. var
  89. i: Integer;
  90. begin
  91. for i:=1 to length(s) do
  92. if s[i] in [#0..#31,#127..#255] then
  93. exit(true);
  94. Result:=false;
  95. end;
  96. function HashSpecialChars(s: string): string;
  97. var
  98. i: Integer;
  99. begin
  100. Result:='';
  101. for i:=1 to length(s) do
  102. if s[i] in [#0..#31,#127..#255] then
  103. Result:=Result+'#'+hexstr(ord(s[i]),2)
  104. else
  105. Result:=Result+s[i];
  106. end;
  107. procedure DiffFound;
  108. var
  109. ActLineStartP, ActLineEndP, p, StartPos: PChar;
  110. ExpLine, ActLine: String;
  111. i, LineNo, DiffLineNo: Integer;
  112. begin
  113. writeln('Diff found "',Msg,'". Lines:');
  114. // write correct lines
  115. p:=PChar(Expected);
  116. LineNo:=0;
  117. DiffLineNo:=0;
  118. repeat
  119. StartPos:=p;
  120. while not (p^ in [#0,#10,#13]) do inc(p);
  121. ExpLine:=copy(Expected,StartPos-PChar(Expected)+1,p-StartPos);
  122. SkipLineEnd(p);
  123. inc(LineNo);
  124. if (p<=ExpectedP) and (p^<>#0) then
  125. begin
  126. writeln('= ',ExpLine);
  127. end else begin
  128. // diff line
  129. if DiffLineNo=0 then DiffLineNo:=LineNo;
  130. // write actual line
  131. ActLineStartP:=FindLineStart(ActualP,PChar(Actual));
  132. ActLineEndP:=FindLineEnd(ActualP);
  133. ActLine:=copy(Actual,ActLineStartP-PChar(Actual)+1,ActLineEndP-ActLineStartP);
  134. writeln('- ',ActLine);
  135. if HasSpecialChar(ActLine) then
  136. writeln('- ',HashSpecialChars(ActLine));
  137. // write expected line
  138. writeln('+ ',ExpLine);
  139. if HasSpecialChar(ExpLine) then
  140. writeln('- ',HashSpecialChars(ExpLine));
  141. // write empty line with pointer ^
  142. for i:=1 to 2+ExpectedP-StartPos do write(' ');
  143. writeln('^');
  144. Msg:='expected "'+ExpLine+'", but got "'+ActLine+'".';
  145. CheckSrcDiff:=false;
  146. // write up to ten following actual lines to get some context
  147. for i:=1 to 10 do begin
  148. ActLineStartP:=ActLineEndP;
  149. SkipLineEnd(ActLineStartP);
  150. if ActLineStartP^=#0 then break;
  151. ActLineEndP:=FindLineEnd(ActLineStartP);
  152. ActLine:=copy(Actual,ActLineStartP-PChar(Actual)+1,ActLineEndP-ActLineStartP);
  153. writeln('~ ',ActLine);
  154. end;
  155. exit;
  156. end;
  157. until p^=#0;
  158. // internal error:
  159. writeln('DiffFound Actual:-----------------------');
  160. writeln(Actual);
  161. writeln('DiffFound Expected:---------------------');
  162. writeln(Expected);
  163. writeln('DiffFound ------------------------------');
  164. Msg:='diff found, but lines are the same, internal error';
  165. CheckSrcDiff:=false;
  166. end;
  167. var
  168. IsSpaceNeeded: Boolean;
  169. LastChar, Quote: Char;
  170. begin
  171. Result:=true;
  172. Msg:='';
  173. if Expected='' then Expected:=' ';
  174. if Actual='' then Actual:=' ';
  175. ExpectedP:=PChar(Expected);
  176. ActualP:=PChar(Actual);
  177. repeat
  178. //writeln('TTestModule.CheckDiff Exp="',ExpectedP^,'" Act="',ActualP^,'"');
  179. case ExpectedP^ of
  180. #0:
  181. begin
  182. // check that rest of Actual has only spaces
  183. while ActualP^ in SpaceChars do inc(ActualP);
  184. if ActualP^<>#0 then
  185. begin
  186. DiffFound;
  187. exit;
  188. end;
  189. exit(true);
  190. end;
  191. ' ',#9,#10,#13:
  192. begin
  193. // skip space in Expected
  194. IsSpaceNeeded:=false;
  195. if ExpectedP>PChar(Expected) then
  196. LastChar:=ExpectedP[-1]
  197. else
  198. LastChar:=#0;
  199. while ExpectedP^ in SpaceChars do inc(ExpectedP);
  200. if (LastChar in ['a'..'z','A'..'Z','0'..'9','_','$'])
  201. and (ExpectedP^ in ['a'..'z','A'..'Z','0'..'9','_','$']) then
  202. IsSpaceNeeded:=true;
  203. if IsSpaceNeeded and (not (ActualP^ in SpaceChars)) then
  204. begin
  205. DiffFound;
  206. exit;
  207. end;
  208. while ActualP^ in SpaceChars do inc(ActualP);
  209. end;
  210. '''','"':
  211. begin
  212. while ActualP^ in SpaceChars do inc(ActualP);
  213. if ExpectedP^<>ActualP^ then
  214. begin
  215. DiffFound;
  216. exit;
  217. end;
  218. Quote:=ExpectedP^;
  219. repeat
  220. inc(ExpectedP);
  221. inc(ActualP);
  222. if ExpectedP^<>ActualP^ then
  223. begin
  224. DiffFound;
  225. exit;
  226. end;
  227. if (ExpectedP^ in [#0,#10,#13]) then
  228. break
  229. else if (ExpectedP^=Quote) then
  230. begin
  231. inc(ExpectedP);
  232. inc(ActualP);
  233. break;
  234. end;
  235. until false;
  236. end;
  237. else
  238. while ActualP^ in SpaceChars do inc(ActualP);
  239. if ExpectedP^<>ActualP^ then
  240. begin
  241. DiffFound;
  242. exit;
  243. end;
  244. inc(ExpectedP);
  245. inc(ActualP);
  246. end;
  247. until false;
  248. end;
  249. { TCustomTestWebIDL2WasmJob }
  250. procedure TCustomTestWebIDL2WasmJob.OnLog(Sender: TObject;
  251. LogType: TCodegenLogType; const Msg: String);
  252. begin
  253. if LogType=cltInfo then ;
  254. if Sender=nil then ;
  255. writeln('TCustomTestWebIDL2WasmJob.OnLog ',Msg);
  256. end;
  257. procedure TCustomTestWebIDL2WasmJob.Setup;
  258. begin
  259. inherited Setup;
  260. FWebIDLToPas:=TWebIDLToPasWasmJob.Create(nil);
  261. WebIDLToPas.OnLog:=@OnLog;
  262. WebIDLToPas.InputFileName:='test1.webidl';
  263. WebIDLToPas.InputStream:=TMemoryStream.Create;
  264. WebIDLToPas.OutputFileName:='test1.pas';
  265. WebIDLToPas.OutputStream:=TMemoryStream.Create;
  266. HeaderSrc:=LinesToStr([
  267. 'Unit test1;',
  268. '',
  269. '{$MODE ObjFPC}',
  270. '{$H+}',
  271. 'interface',
  272. '',
  273. 'uses SysUtils, JOB_JS;',
  274. '']);
  275. end;
  276. procedure TCustomTestWebIDL2WasmJob.TearDown;
  277. begin
  278. WebIDLToPas.InputStream.Free;
  279. WebIDLToPas.InputStream:=nil;
  280. WebIDLToPas.OutputStream.Free;
  281. WebIDLToPas.OutputStream:=nil;
  282. FreeAndNil(FWebIDLToPas);
  283. inherited TearDown;
  284. end;
  285. procedure TCustomTestWebIDL2WasmJob.TestWebIDL(const WebIDLSrc,
  286. ExpectedPascalSrc: array of string);
  287. var
  288. i: Integer;
  289. Line, ExpectedSrc, InputSrc, OutputSrc: String;
  290. InputMS: TMemoryStream;
  291. begin
  292. {$IFDEF VerboseWebidl2WasmJob}
  293. writeln('TCustomTestWebIDL2WasmJob.TestWebIDL WebIDL:----------------------');
  294. {$ENDIF}
  295. InputMS:=WebIDLToPas.InputStream as TMemoryStream;
  296. for i:=0 to high(WebIDLSrc) do
  297. begin
  298. Line:=WebIDLSrc[i]+sLineBreak;
  299. InputMS.Write(Line[1],length(Line));
  300. {$IFDEF VerboseWebidl2WasmJob}
  301. write(Line);
  302. {$ENDIF}
  303. end;
  304. InputMS.Position:=0;
  305. {$IFDEF VerboseWebidl2WasmJob}
  306. writeln('TCustomTestWebIDL2WasmJob.TestWebIDL ExpectedPascal: BEGIN--------');
  307. {$ENDIF}
  308. ExpectedSrc:=HeaderSrc;
  309. for i:=0 to high(ExpectedPascalSrc) do
  310. ExpectedSrc:=ExpectedSrc+ExpectedPascalSrc[i]+sLineBreak;
  311. {$IFDEF VerboseWebidl2WasmJob}
  312. writeln(ExpectedSrc);
  313. writeln('TCustomTestWebIDL2WasmJob.TestWebIDL ExpectedPascal END-----------');
  314. {$ENDIF}
  315. WebIDLToPas.Execute;
  316. SetLength(InputSrc{%H-},InputMS.Size);
  317. if length(InputSrc)>0 then
  318. Move(InputMS.Memory^,InputSrc[1],length(InputSrc));
  319. OutputSrc:=WebIDLToPas.Source.Text;
  320. {$IFDEF VerboseWebidl2WasmJob}
  321. writeln('TCustomTestWebIDL2WasmJob.TestWebIDL ActualPascal: BEGIN----------');
  322. writeln(OutputSrc);
  323. writeln('TCustomTestWebIDL2WasmJob.TestWebIDL ActualPascal: END------------');
  324. {$ENDIF}
  325. CheckDiff('TCustomTestWebIDL2WasmJob.TestWebIDL',ExpectedSrc,OutputSrc);
  326. end;
  327. procedure TCustomTestWebIDL2WasmJob.CheckDiff(Msg, Expected, Actual: string);
  328. // search diff, ignore changes in spaces
  329. var
  330. s: string;
  331. begin
  332. if CheckSrcDiff(Expected,Actual,s) then exit;
  333. Fail(Msg+': '+s);
  334. end;
  335. { TTestWebIDL2WasmJob }
  336. procedure TTestWebIDL2WasmJob.TestWJ_Empty;
  337. begin
  338. TestWebIDL([
  339. ''],
  340. ['Type',
  341. ' // Forward class definitions',
  342. 'implementation',
  343. 'end.',
  344. '']);
  345. end;
  346. procedure TTestWebIDL2WasmJob.TestWJ_Typedef_Boolean;
  347. begin
  348. TestWebIDL([
  349. 'typedef boolean PerformanceEntry;',
  350. ''],
  351. ['Type',
  352. ' // Forward class definitions',
  353. ' TPerformanceEntry = Boolean;',
  354. 'implementation',
  355. 'end.',
  356. '']);
  357. end;
  358. procedure TTestWebIDL2WasmJob.TestWJ_Typedef_Sequence;
  359. begin
  360. TestWebIDL([
  361. 'typedef boolean PerformanceEntry;',
  362. 'typedef sequence <PerformanceEntry> PerformanceEntryList;',
  363. ''],
  364. ['Type',
  365. ' // Forward class definitions',
  366. ' TPerformanceEntry = Boolean;',
  367. ' TPerformanceEntryList = IJSArray; // array of TPerformanceEntry',
  368. 'implementation',
  369. 'end.',
  370. '']);
  371. end;
  372. procedure TTestWebIDL2WasmJob.TestWJ_IntfAttribute_Boolean;
  373. begin
  374. TestWebIDL([
  375. 'interface Attr {',
  376. ' attribute boolean aBoolean;',
  377. '};',
  378. ''],
  379. ['Type',
  380. ' // Forward class definitions',
  381. ' IJSAttr = interface;',
  382. ' TJSAttr = class;',
  383. ' { --------------------------------------------------------------------',
  384. ' TJSAttr',
  385. ' --------------------------------------------------------------------}',
  386. '',
  387. ' IJSAttr = interface(IJSObject)',
  388. ' [''{AA94F48A-7955-3EBA-B086-85B24440AF2A}'']',
  389. ' function _GetaBoolean: Boolean;',
  390. ' procedure _SetaBoolean(const aValue: Boolean);',
  391. ' property aBoolean: Boolean read _GetaBoolean write _SetaBoolean;',
  392. ' end;',
  393. '',
  394. ' TJSAttr = class(TJSObject,IJSAttr)',
  395. ' Private',
  396. ' function _GetaBoolean: Boolean;',
  397. ' procedure _SetaBoolean(const aValue: Boolean);',
  398. ' Public',
  399. ' class function Cast(Intf: IJSObject): IJSAttr;',
  400. ' property aBoolean: Boolean read _GetaBoolean write _SetaBoolean;',
  401. ' end;',
  402. '',
  403. 'implementation',
  404. '',
  405. 'function TJSAttr._GetaBoolean: Boolean;',
  406. 'begin',
  407. ' Result:=ReadJSPropertyBoolean(''aBoolean'');',
  408. 'end;',
  409. '',
  410. 'procedure TJSAttr._SetaBoolean(const aValue: Boolean);',
  411. 'begin',
  412. ' WriteJSPropertyBoolean(''aBoolean'',aValue);',
  413. 'end;',
  414. '',
  415. 'class function TJSAttr.Cast(Intf: IJSObject): IJSAttr;',
  416. 'begin',
  417. ' Result:=TJSAttr.JOBCast(Intf);',
  418. 'end;',
  419. '',
  420. 'end.',
  421. '']);
  422. end;
  423. procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_Void;
  424. begin
  425. TestWebIDL([
  426. 'interface Attr {',
  427. ' void append(Attr node);',
  428. '};',
  429. ''],
  430. ['Type',
  431. ' // Forward class definitions',
  432. ' IJSAttr = interface;',
  433. ' TJSAttr = class;',
  434. ' { --------------------------------------------------------------------',
  435. ' TJSAttr',
  436. ' --------------------------------------------------------------------}',
  437. '',
  438. ' IJSAttr = interface(IJSObject)',
  439. ' [''{AA94F48A-84D7-3FAA-A2A6-208CA4B2AF2A}'']',
  440. ' procedure append(aNode: IJSAttr);',
  441. ' end;',
  442. '',
  443. ' TJSAttr = class(TJSObject,IJSAttr)',
  444. ' Private',
  445. ' Public',
  446. ' procedure append(aNode: IJSAttr);',
  447. ' class function Cast(Intf: IJSObject): IJSAttr;',
  448. ' end;',
  449. '',
  450. 'implementation',
  451. '',
  452. 'procedure TJSAttr.append(aNode: IJSAttr);',
  453. 'begin',
  454. ' InvokeJSNoResult(''append'',[aNode]);',
  455. 'end;',
  456. '',
  457. 'class function TJSAttr.Cast(Intf: IJSObject): IJSAttr;',
  458. 'begin',
  459. ' Result:=TJSAttr.JOBCast(Intf);',
  460. 'end;',
  461. '',
  462. 'end.',
  463. '']);
  464. end;
  465. procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_SetEventHandler;
  466. begin
  467. TestWebIDL([
  468. '[LegacyTreatNonObjectAsNull]',
  469. 'callback EventHandlerNonNull = any (long event);',
  470. 'typedef EventHandlerNonNull? EventHandler;',
  471. '',
  472. 'interface Attr {',
  473. ' void setEventHandler([TreatNonCallableAsNull] EventHandler handler);',
  474. '};',
  475. ''],
  476. ['Type',
  477. ' // Forward class definitions',
  478. ' IJSAttr = interface;',
  479. ' TJSAttr = class;',
  480. ' TEventHandlerNonNull = function (event: Integer): Variant of object;',
  481. ' TEventHandler = TEventHandlerNonNull;',
  482. '',
  483. ' { --------------------------------------------------------------------',
  484. ' TJSAttr',
  485. ' --------------------------------------------------------------------}',
  486. '',
  487. ' IJSAttr = interface(IJSObject)',
  488. ' [''{AA94F48A-121D-33BC-96FE-420246F2AF2A}'']',
  489. ' procedure setEventHandler(const aHandler: TEventHandler);',
  490. ' end;',
  491. '',
  492. ' TJSAttr = class(TJSObject,IJSAttr)',
  493. ' Private',
  494. ' Public',
  495. ' procedure setEventHandler(const aHandler: TEventHandler);',
  496. ' class function Cast(Intf: IJSObject): IJSAttr;',
  497. ' end;',
  498. '',
  499. 'implementation',
  500. '',
  501. 'function JOBCallTEventHandlerNonNull(const aMethod: TMethod; var H: TJOBCallbackHelper): PByte;',
  502. 'var',
  503. ' event: Integer;',
  504. 'begin',
  505. ' event:=H.GetLongInt;',
  506. ' Result:=H.AllocVariant(TEventHandlerNonNull(aMethod)(event));',
  507. 'end;',
  508. '',
  509. 'procedure TJSAttr.setEventHandler(const aHandler: TEventHandler);',
  510. 'var',
  511. ' m: TJOB_Method;',
  512. 'begin',
  513. ' m:=TJOB_Method.Create(TMethod(aHandler),@JOBCallTEventHandlerNonNull);',
  514. ' try',
  515. ' InvokeJSNoResult(''setEventHandler'',[m]);',
  516. ' finally',
  517. ' m.free;',
  518. ' end;',
  519. 'end;',
  520. '',
  521. 'class function TJSAttr.Cast(Intf: IJSObject): IJSAttr;',
  522. 'begin',
  523. ' Result:=TJSAttr.JOBCast(Intf);',
  524. 'end;',
  525. '',
  526. 'end.',
  527. '']);
  528. end;
  529. procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_Promise;
  530. begin
  531. // Promise<void> exitFullscreen();
  532. TestWebIDL([
  533. 'interface Attr {',
  534. ' Promise<void> exitFullscreen();',
  535. ' Promise<any> addCertException(boolean isTemporary);',
  536. ' Promise<Attr> fly();',
  537. '};',
  538. ''],
  539. ['Type',
  540. ' // Forward class definitions',
  541. ' IJSAttr = interface;',
  542. ' TJSAttr = class;',
  543. ' { --------------------------------------------------------------------',
  544. ' TJSAttr',
  545. ' --------------------------------------------------------------------}',
  546. '',
  547. ' IJSAttr = interface(IJSObject)',
  548. ' [''{74BB0007-0E0F-3C5D-B270-B1C656002861}'']',
  549. ' function exitFullscreen: IJSPromise; // Promise<void>',
  550. ' function addCertException(aIsTemporary: Boolean): IJSPromise; // Promise<any>',
  551. ' function fly: IJSPromise; // Promise<Attr>',
  552. ' end;',
  553. '',
  554. ' TJSAttr = class(TJSObject,IJSAttr)',
  555. ' Private',
  556. ' Public',
  557. ' function exitFullscreen: IJSPromise; // Promise<void>',
  558. ' function addCertException(aIsTemporary: Boolean): IJSPromise; // Promise<any>',
  559. ' function fly: IJSPromise; // Promise<Attr>',
  560. ' class function Cast(Intf: IJSObject): IJSAttr;',
  561. ' end;',
  562. '',
  563. 'implementation',
  564. '',
  565. 'function TJSAttr.exitFullscreen: IJSPromise; // Promise<void>',
  566. 'begin',
  567. ' Result:=InvokeJSObjectResult(''exitFullscreen'',[],TJSPromise) as IJSPromise;',
  568. 'end;',
  569. '',
  570. 'function TJSAttr.addCertException(aIsTemporary: Boolean): IJSPromise; // Promise<any>',
  571. 'begin',
  572. ' Result:=InvokeJSObjectResult(''addCertException'',[aIsTemporary],TJSPromise) as IJSPromise;',
  573. 'end;',
  574. '',
  575. 'function TJSAttr.fly: IJSPromise; // Promise<Attr>',
  576. 'begin',
  577. ' Result:=InvokeJSObjectResult(''fly'',[],TJSPromise) as IJSPromise;',
  578. 'end;',
  579. '',
  580. 'class function TJSAttr.Cast(Intf: IJSObject): IJSAttr;',
  581. 'begin',
  582. ' Result:=TJSAttr.JOBCast(Intf);',
  583. 'end;',
  584. '',
  585. 'end.',
  586. '']);
  587. end;
  588. procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_ArgAny;
  589. begin
  590. TestWebIDL([
  591. 'interface Attr {',
  592. ' void append(any node);',
  593. '};',
  594. ''],
  595. ['Type',
  596. ' // Forward class definitions',
  597. ' IJSAttr = interface;',
  598. ' TJSAttr = class;',
  599. ' { --------------------------------------------------------------------',
  600. ' TJSAttr',
  601. ' --------------------------------------------------------------------}',
  602. '',
  603. ' IJSAttr = interface(IJSObject)',
  604. ' [''{AA94F48A-84D7-3FAA-A2A6-208CA4B2AF2A}'']',
  605. ' procedure append(const aNode: Variant);',
  606. ' end;',
  607. '',
  608. ' TJSAttr = class(TJSObject,IJSAttr)',
  609. ' Private',
  610. ' Public',
  611. ' procedure append(const aNode: Variant);',
  612. ' class function Cast(Intf: IJSObject): IJSAttr;',
  613. ' end;',
  614. '',
  615. 'implementation',
  616. '',
  617. 'procedure TJSAttr.append(const aNode: Variant);',
  618. 'begin',
  619. ' InvokeJSNoResult(''append'',[aNode]);',
  620. 'end;',
  621. '',
  622. 'class function TJSAttr.Cast(Intf: IJSObject): IJSAttr;',
  623. 'begin',
  624. ' Result:=TJSAttr.JOBCast(Intf);',
  625. 'end;',
  626. '',
  627. 'end.',
  628. '']);
  629. end;
  630. initialization
  631. RegisterTests([TTestWebIDL2Wasmjob]);
  632. end.