tcwebidl2wasmjob.pas 18 KB

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