weborworker.pas 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. unit weborworker;
  2. {$mode objfpc}
  3. {$modeswitch externalclass}
  4. interface
  5. uses
  6. JS, types;
  7. type
  8. TJSCryptoKey = Class;
  9. TJSSubtleCrypto = Class;
  10. TJSEventTarget = class;
  11. TIDBDatabase = class;
  12. TJSIDBObjectStore = class;
  13. TJSIDBRequest = class;
  14. TJSServiceWorker = class;
  15. TJSStorageManager = class external name 'StorageManager' (TJSObject)
  16. function estimate : TJSPromise;
  17. function persist : TJSPromise;
  18. function persisted : TJSPromise;
  19. end;
  20. TJSConsole = class external name 'Console' (TJSObject)
  21. Public
  22. procedure assert(anAssertion : string; Obj1 : JSValue); varargs;
  23. Procedure clear;
  24. procedure count; overload;
  25. procedure count(aCounter : String);
  26. procedure debug(Obj1 : JSValue); varargs of JSValue;
  27. procedure error(Obj1 : JSValue); varargs of JSValue;
  28. procedure group; overload;
  29. procedure group(aLabel : String); overload;
  30. procedure groupCollapsed; overload;
  31. procedure groupCollapsed(aLabel : String);overload;
  32. procedure groupEnd;
  33. procedure info(Obj1 : JSValue); varargs of JSValue;
  34. procedure log(Obj1 : JSValue); varargs of JSValue;
  35. procedure table(args: array of JSValue); overload;
  36. procedure table(args: array of JSValue; Columns : Array of string);
  37. procedure table(args: TJSObject); overload;
  38. procedure table(args: TJSObject; Columns : Array of string); overload;
  39. procedure time(aName : string);
  40. procedure timeEnd(aName : string);
  41. procedure trace;
  42. procedure warn(Obj1 : JSValue); varargs of JSValue;
  43. end;
  44. TJSTimerCallBack = reference to procedure; safecall;
  45. TJSEventInit = record
  46. bubbles : boolean;
  47. cancelable : boolean;
  48. scoped : boolean;
  49. composed : boolean;
  50. end;
  51. TJSEvent = class external name 'Event' (TJSObject)
  52. Private
  53. FBubbles : Boolean; external name 'bubbles';
  54. FCancelable : Boolean; external name 'cancelable';
  55. FComposed : Boolean; external name 'composed';
  56. FCurrentTarget : TJSEventTarget; external name 'currentTarget';
  57. FdefaultPrevented : Boolean; external name 'defaultPrevented';
  58. FEventPhase : NativeInt; external name 'eventPhase';
  59. FTarget : TJSEventTarget; external name 'target';
  60. FTimeStamp : NativeInt; external name 'timestamp';
  61. FType : String; external name 'type';
  62. FIsTrusted : Boolean; external name 'isTrusted';
  63. Public
  64. Const
  65. NONE = 0;
  66. CAPTURING_PHASE = 1;
  67. AT_TARGET = 2;
  68. BUBBLING_PHASE = 3;
  69. public
  70. cancelBubble : Boolean;
  71. constructor new (aType : String; const aInit : TJSEventInit); overload;
  72. constructor new (aType : String); overload;
  73. procedure preventDefault;
  74. procedure stopImmediatePropagation;
  75. procedure stopPropagation;
  76. Property bubbles : Boolean Read FBubbles;
  77. Property cancelable : Boolean Read FCancelable;
  78. Property composed : Boolean Read FComposed;
  79. property currentTarget : TJSEventTarget Read FCurrentTarget;
  80. // property currentTargetElement : TJSElement Read FCurrentTargetElement;
  81. property defaultPrevented : Boolean Read FdefaultPrevented;
  82. property eventPhase : NativeInt Read FEventPhase;
  83. property target : TJSEventTarget Read FTarget;
  84. // property targetElement : TJSElement Read FTargetElement;
  85. Property timestamp : NativeInt Read FTimeStamp;
  86. property _type : string read FType;
  87. property isTrusted : Boolean Read FIsTrusted;
  88. end;
  89. TJSExtendableEvent = class external name 'ExtendableEvent' (TJSEvent)
  90. Procedure waitUntil(aPromise : TJSPromise);
  91. end;
  92. TJSEventHandler = reference to function(Event: TJSEvent): boolean; safecall;
  93. TJSRawEventHandler = reference to Procedure(Event: TJSEvent); safecall;
  94. TJSEventTarget = class external name 'EventTarget' (TJSObject)
  95. public
  96. procedure addEventListener(aname : string; aListener : TJSEventHandler);
  97. procedure addEventListener(aname : string; aListener : TJSRawEventHandler);
  98. procedure addEventListener(aname : string; aListener : JSValue);
  99. function dispatchEvent(event : JSValue) : Boolean;
  100. procedure removeEventListener(aname : string; aListener : TJSEventHandler);
  101. procedure removeEventListener(aname : string; aListener : TJSRawEventHandler);
  102. procedure removeEventListener(aname : string; aListener : JSValue);
  103. end;
  104. TJSStructuredSerializeOptions = class external name 'Object' (TJSObject)
  105. transfer : TJSValueDynArray;
  106. end;
  107. TJSReadableStream = class external name 'ReadableStream' (TJSObject)
  108. private
  109. flocked: Boolean; external name 'locked';
  110. public
  111. property locked: Boolean read flocked;
  112. constructor new(underlyingSource: TJSObject);
  113. constructor new(underlyingSource, queueingStrategy: TJSObject);
  114. function cancel(reason: String): TJSPromise;
  115. function getReader(): TJSObject; overload;
  116. function getReader(mode: TJSObject): TJSObject; overload;
  117. function pipeThrough(transformStream: TJSObject): TJSReadableStream; overload;
  118. function pipeThrough(transformStream, options: TJSObject): TJSReadableStream; overload;
  119. function pipeTo(destination: TJSObject): TJSPromise; overload;
  120. function pipeTo(destination, options: TJSObject): TJSPromise; overload;
  121. function tee(): TJSArray; // array containing two TJSReadableStream instances
  122. end;
  123. TJSBlob = class external name 'Blob' (TJSEventTarget)
  124. private
  125. FSize: NativeInt; external name 'size';
  126. FType: string; external name 'type';
  127. Public
  128. procedure close;
  129. function slice : TJSBlob; overload;
  130. function slice(aStart : NativeInt) : TJSBlob; overload;
  131. function slice(aStart,aEnd : NativeInt) : TJSBlob; overload;
  132. function slice(aStart,aEnd : NativeInt; AContentType : String) : TJSBlob; overload;
  133. function arrayBuffer : TJSPromise;
  134. property size : NativeInt read FSize;
  135. property _type : string read FType; deprecated;
  136. property type_ : string read FType;
  137. end;
  138. TJSBody = class external name 'Body' (TJSObject)
  139. private
  140. fbody: TJSReadableStream; external name 'body';
  141. fbodyUsed: Boolean; external name 'bodyUsed';
  142. public
  143. property body: TJSReadableStream read fbody;
  144. property bodyUsed: Boolean read fbodyUsed;
  145. function arrayBuffer(): TJSPromise; // resolves to TJSArrayBuffer
  146. //function blob(): TJSPromise; // resolves to TJSBlob
  147. function blob: TJSBlob; {$IFNDEF SkipAsync}async;{$ENDIF}
  148. function json(): TJSPromise; // resolves to JSON / TJSValue
  149. //function text(): TJSPromise; // resolves to USVString, always decoded using UTF-8
  150. function text(): string; {$IFNDEF SkipAsync}async;{$ENDIF}
  151. end;
  152. TJSResponse = class external name 'Response' (TJSBody)
  153. private
  154. fheaders: TJSObject;external name 'headers';
  155. fok: Boolean; external name 'ok';
  156. fredirected: Boolean; external name 'redirected';
  157. fstatus: NativeInt; external name 'status';
  158. fstatusText: String; external name 'statusText';
  159. ftype: String; external name 'type';
  160. furl: String; external name 'url';
  161. fuseFinalUrl: Boolean; external name 'useFinalUrl';
  162. public
  163. property headers: TJSObject read fheaders; //
  164. property ok: Boolean read fok;
  165. property redirected: Boolean read fredirected;
  166. property status: NativeInt read fstatus;
  167. property statusText: String read fstatusText; //
  168. property type_: String read ftype; //
  169. property url: String read furl; //
  170. property useFinalUrl: Boolean read fuseFinalUrl write fuseFinalUrl;
  171. constructor new(body: TJSObject; init: TJSObject); overload; varargs; external name 'new';
  172. constructor new(Msg: string; init: TJSObject); overload; varargs; external name 'new';
  173. function clone(): TJSResponse;
  174. function error(): TJSResponse;
  175. function redirect(url: String; Status: NativeInt): TJSResponse;
  176. end;
  177. TJSIDBTransactionMode = class
  178. const
  179. readonly = 'readonly';
  180. readwrite = 'readwrite';
  181. versionchange = 'versionchange';
  182. end;
  183. { TJSIDBTransaction }
  184. TJSIDBTransaction = class external name 'IDBTransaction' (TJSEventTarget)
  185. private
  186. FDB : TIDBDatabase; external name 'db';
  187. FError: JSValue; external name 'error';
  188. FMode: String; external name 'mode';
  189. FObjectStoreNames: TStringDynArray; external name 'objectStoreNames';
  190. public
  191. procedure abort;
  192. function objectStore(aName : String) : TJSIDBObjectStore;
  193. property db : TIDBDatabase read FDB;
  194. property mode : String read FMode;
  195. property objectStoreNames : TStringDynArray read FObjectStoreNames;
  196. property error : JSValue read FError;
  197. end;
  198. { TJSIDBKeyRange }
  199. TJSIDBKeyRange = class external name 'IDBKeyRange' (TJSObject)
  200. private
  201. FLower: JSValue;
  202. FLowerOpen: Boolean;
  203. FUpper: JSValue;
  204. FUpperOpen: Boolean;
  205. Public
  206. Class Function bound(aLower,aUpper : JSValue) : TJSIDBKeyRange; overload;
  207. Class Function bound(aLower,aUpper : JSValue; aLowerOpen : Boolean) : TJSIDBKeyRange; overload;
  208. Class Function bound(aLower,aUpper : JSValue; aLowerOpen,aUpperOpen : Boolean) : TJSIDBKeyRange; overload;
  209. Class Function lowerBound(aLower : JSValue) : TJSIDBKeyRange; overload;
  210. Class Function lowerBound(aLower : JSValue; aOpen: Boolean) : TJSIDBKeyRange; overload;
  211. Class Function only(aValue : JSValue) : TJSIDBKeyRange;
  212. Class Function upperBound(aUpper : JSValue) : TJSIDBKeyRange; overload;
  213. Class Function upperBound(aUpper : JSValue; aOpen: Boolean) : TJSIDBKeyRange; overload;
  214. function includes (aValue : JSValue) : Boolean;
  215. property lower : JSValue read FLower;
  216. property lowerOpen : Boolean read FLowerOpen;
  217. property upper : JSValue read FUpper;
  218. property upperOpen : Boolean read FUpperOpen;
  219. end;
  220. TJSIDBIndexParameters = record
  221. unique : boolean;
  222. multiEntry : boolean;
  223. locale : string;
  224. end;
  225. { TJSIDBIndex }
  226. TJSIDBIndex = class external name 'IDBIndex' (TJSObject)
  227. private
  228. FKeyPath: JSValue; external name 'keyPath';
  229. FMultiEntry: Boolean; external name 'multiEntry';
  230. FObjectStore: TJSIDBObjectStore; external name 'objectStore';
  231. FUnique: boolean; external name 'unique';
  232. public
  233. name : string;
  234. function count : TJSIDBRequest;
  235. function get(aKey : jsValue) : TJSIDBRequest; overload;
  236. function get(aKey : TJSIDBKeyRange) : TJSIDBRequest; overload;
  237. function getAll(aKey : jsValue) : TJSIDBRequest; overload;
  238. function getAll(aKey : TJSIDBKeyRange) : TJSIDBRequest; overload;
  239. function getAll(aKey : jsValue; ACount : NativeInt) : TJSIDBRequest; overload;
  240. function getAll(aKey : TJSIDBKeyRange; ACount : NativeInt) : TJSIDBRequest; overload;
  241. function getAllKeys(aKey : jsValue) : TJSIDBRequest; overload;
  242. function getAllKeys(aKey : TJSIDBKeyRange) : TJSIDBRequest; overload;
  243. function getAllKeys(aKey : jsValue; ACount : NativeInt) : TJSIDBRequest; overload;
  244. function getAllKeys(aKey : TJSIDBKeyRange; ACount : NativeInt) : TJSIDBRequest; overload;
  245. function getKey(aKey : jsValue) : TJSIDBRequest;
  246. function openCursor : TJSIDBRequest; overload;
  247. function openCursor(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest; overload;
  248. function openCursor(aKeyRange : TJSIDBKeyRange; ADirection : String) : TJSIDBRequest;overload;
  249. function openKeyCursor : TJSIDBRequest;overload;
  250. function openKeyCursor(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest;overload;
  251. function openKeyCursor(aKeyRange : TJSIDBKeyRange; ADirection : String) : TJSIDBRequest;overload;
  252. Property keyPath : JSValue Read FKeyPath;
  253. property multiEntry : Boolean read FMultiEntry;
  254. property objectStore : TJSIDBObjectStore read FObjectStore;
  255. property unique : boolean read FUnique;
  256. end;
  257. TJSIDBCursorDirection = class external name 'IDBCursorDirection' (TJSObject)
  258. Const
  259. next = 'next';
  260. nextUnique = 'nextUnique';
  261. prev = 'prev';
  262. prevUnique = 'prevUnique';
  263. end;
  264. { TJSIDBCursor }
  265. TJSIDBCursor = class external name 'IDBCursor' (TJSObject)
  266. private
  267. FDirection: string; external name 'direction';
  268. FKey: JSValue; external name 'key';
  269. FValue : JSValue; external name 'value';
  270. FPrimaryKey: JSValue; external name 'primaryKey';
  271. FSource: JSValue; external name 'source';
  272. FSourceAsIndex: TJSIDBIndex; external name 'source';
  273. FSourceAsStore: TJSIDBObjectStore; external name 'source';
  274. Public
  275. procedure advance(aCount : NativeInt); overload;
  276. procedure advance(aKey : JSValue); overload;
  277. procedure continue(aKey : JSValue); overload;
  278. procedure continue; overload;
  279. procedure continuePrimaryKey(aKey : JSValue); overload;
  280. procedure continuePrimaryKey(aKey,aPrimaryKey : JSValue); overload;
  281. procedure delete;
  282. procedure update(aValue : JSValue);
  283. property source : JSValue read FSource;
  284. property sourceAsStore : TJSIDBObjectStore read FSourceAsStore;
  285. property sourceAsIndex : TJSIDBIndex read FSourceAsIndex;
  286. property key : JSValue read FKey;
  287. Property Value : JSValue Read FValue;
  288. property primaryKey : JSValue read FPrimaryKey;
  289. property direction : string read FDirection;
  290. end;
  291. TJSIDBObjectStore = class external name 'IDBObjectStore' (TJSEventTarget)
  292. public
  293. function add(aValue : JSValue; aKey : String) : TJSIDBRequest;
  294. function add(aValue : JSValue) : TJSIDBRequest;
  295. function clear : TJSIDBRequest;
  296. function delete(aKey : string) : TJSIDBRequest;
  297. function delete(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest;
  298. function get(aKey : string) : TJSIDBRequest; overload;
  299. function get(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest; overload;
  300. function getKey(aKey : string) : TJSIDBRequest; overload;
  301. function getKey(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest; overload;
  302. function getAll : TJSIDBRequest; overload;
  303. function getAll(aKey : String) : TJSIDBRequest; overload;
  304. function getAll(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest; overload;
  305. function getAll(aKey : String; aCount: NativeInt) : TJSIDBRequest; overload;
  306. function getAll(aKeyRange : TJSIDBKeyRange; aCount: NativeInt) : TJSIDBRequest; overload;
  307. function getAllKeys(aKey : String) : TJSIDBRequest; overload;
  308. function getAllKeys(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest; overload;
  309. function getAllKeys(aKey : String; aCount: NativeInt) : TJSIDBRequest; overload;
  310. function getAllKeys(aKeyRange : TJSIDBKeyRange; aCount: NativeInt) : TJSIDBRequest; overload;
  311. function createIndex (aIndexName : String; KeyPath : String) : TJSIDBIndex; overload;
  312. function createIndex (aIndexName : String; KeyPath : String; Options : TJSIDBIndexParameters) : TJSIDBIndex; overload;
  313. function createIndex (aIndexName : String; KeyPath : Array of String) : TJSIDBIndex; overload;
  314. function createIndex (aIndexName : String; KeyPath : Array of String; Options : TJSIDBIndexParameters) : TJSIDBIndex; overload;
  315. Procedure deleteIndex (aIndexName : String);
  316. function index (aIndexName : String) : TJSIDBIndex;
  317. function put(aValue : JSValue; aKey : String) : TJSIDBRequest; overload;
  318. function put(aValue : JSValue) : TJSIDBRequest; overload;
  319. function openCursor : TJSIDBRequest; overload;
  320. function openCursor(aKey : String) : TJSIDBRequest; overload;
  321. function openCursor(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest; overload;
  322. function openCursor(aKey : String; aDirection : string) : TJSIDBRequest; overload;
  323. function openCursor(aKeyRange : TJSIDBKeyRange; aDirection : string) : TJSIDBRequest; overload;
  324. function openKeyCursor : TJSIDBRequest; overload;
  325. function openKeyCursor(aKey : String) : TJSIDBRequest; overload;
  326. function openKeyCursor(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest; overload;
  327. function openKeyCursor(aKey : String; aDirection : string) : TJSIDBRequest; overload;
  328. function openKeyCursor(aKeyRange : TJSIDBKeyRange; aDirection : string) : TJSIDBRequest; overload;
  329. function count : TJSIDBRequest; overload;
  330. function count(aKey : String) : TJSIDBRequest; overload;
  331. function count(aKeyRange : TJSIDBKeyRange) : TJSIDBRequest; overload;
  332. property Indexes [aIndexName : String] : TJSIDBIndex read index;
  333. end;
  334. { TJSIDBRequest }
  335. TJSIDBRequest = class external name 'IDBRequest' (TJSEventTarget)
  336. private
  337. Ferror : JSValue; external name 'error'; // standards are not quite clear on this one
  338. FReadyState: string; external name 'readyState';
  339. FResult: JSValue; external name 'result';
  340. FResultDatabase: TIDBDatabase; external name 'result';
  341. FResultIndex: TJSIDBIndex; external name 'result';
  342. FResultObjectStore : TJSIDBObjectStore; external name 'result';
  343. FResultCursor : TJSIDBCursor; external name 'result';
  344. FSourceDatabase: TIDBDatabase; external name 'source';
  345. FSourceIndex: TJSIDBIndex; external name 'source';
  346. FSourceObjectStore : TJSIDBObjectStore; external name 'source';
  347. FSourceCursor : TJSIDBCursor; external name 'source';
  348. FSource: JSValue; external name 'source';
  349. FTransaction: TJSIDBTransaction; external name 'transaction';
  350. Public
  351. onerror : TJSEventHandler;
  352. onsuccess : TJSEventHandler;
  353. Property error : JSValue read FError;
  354. property readyState : string read FReadyState;
  355. property result : JSValue read FResult;
  356. property resultAsObjectStore : TJSIDBObjectStore read FResultObjectStore;
  357. property resultAsCursor : TJSIDBCursor read FResultCursor;
  358. property resultAsIndex : TJSIDBIndex read FResultIndex;
  359. property resultAsDatabase : TIDBDatabase read FResultDatabase;
  360. property source : JSValue read FSource;
  361. property sourceAsObjectStore : TJSIDBObjectStore read FSourceObjectStore;
  362. property sourceAsCursor : TJSIDBCursor read FSourceCursor;
  363. property sourceAsIndex : TJSIDBIndex read FSourceIndex;
  364. property sourceAsDatabase : TIDBDatabase read FSourceDatabase;
  365. property transaction : TJSIDBTransaction read FTransaction;
  366. end;
  367. TJSIDBOpenDBRequest = class external name 'IDBOpenDBRequest' (TJSIDBRequest)
  368. Public
  369. onblocked : TJSEventHandler;
  370. onupgradeneeded : TJSEventHandler;
  371. end;
  372. TJSCreateObjectStoreOptions = record
  373. keyPath : jsValue;
  374. autoIncrement : boolean;
  375. end;
  376. { TIDBDatabase }
  377. TIDBDatabase = class external name 'IDBDatabase' (TJSEventTarget)
  378. private
  379. FName: string; external name 'name';
  380. FobjectStoreNames: TStringDynArray; external name 'objectStoreNames';
  381. FVersion: integer; external name 'version';
  382. public
  383. procedure close;
  384. function createObjectStore(aName : string) : TJSIDBObjectStore; overload;
  385. function createObjectStore(aName : string; Options: TJSCreateObjectStoreOptions) : TJSIDBObjectStore; overload;
  386. procedure deleteObjectStore(aName : string);
  387. function transaction(aStoreNames : array of string) : TJSIDBTransaction; overload;
  388. function transaction(aStoreNames : array of string; aMode : string) : TJSIDBTransaction; overload;
  389. property name : string read FName;
  390. property version : integer read FVersion;
  391. property objectStoreNames : TStringDynArray read FobjectStoreNames;
  392. end;
  393. TJSIDBFactory = class external name 'IDBFactory' (TJSEventTarget)
  394. public
  395. function open(aName : string) : TJSIDBOpenDBRequest;
  396. function open(aName : string; aVersion : Integer) : TJSIDBOpenDBRequest;
  397. function deleteDatabase(aName : string) : TJSIDBOpenDBRequest;
  398. function cmp (a,b : jsValue) : NativeInt;
  399. end;
  400. { TJSRequest }
  401. TJSRequest = class external name 'Request' (TJSObject)
  402. private
  403. FBody: TJSReadableStream; external name 'body';
  404. FBodyUsed: Boolean; external name 'bodyUsed';
  405. FCache: String; external name 'cache';
  406. FCredentials: TJSObject; external name 'credentials';
  407. FDestination: String; external name 'destination';
  408. FHeaders: TJSObject; external name 'headers';
  409. FIntegrity: String; external name 'integrity';
  410. FMethod: String; external name 'method';
  411. FMode: String; external name 'mode';
  412. FReferrer: string; external name 'referrer';
  413. FReferrerPolicy: string; external name 'referrerPolicy';
  414. FURL: String;external name 'url';
  415. Public
  416. Property body : TJSReadableStream Read FBody;
  417. property bodyUsed : Boolean Read FBodyUsed;
  418. Property Cache : String Read FCache;
  419. Property Credentials : TJSObject Read FCredentials;
  420. Property Destination : String Read FDestination;
  421. // TODO : actually Headers object
  422. Property Headers : TJSObject Read FHeaders;
  423. Property Integrity : String Read FIntegrity;
  424. Property Method : String Read FMethod;
  425. Property Mode : String Read FMode;
  426. Property Referrer : string Read FReferrer;
  427. Property ReferrerPolicy : string Read FReferrerPolicy;
  428. Property URL : String Read FURL;
  429. end;
  430. TJSRequestDynArray = array of TJSRequest;
  431. TJSCacheDeleteOptions = class external name 'Object' (TJSObject)
  432. ignoreSearch : Boolean;
  433. ignoreMethod : Boolean;
  434. ignoreVary : Boolean;
  435. cacheName : string;
  436. end;
  437. TJSParamEnumCallBack = reference to procedure (const aKey,aValue : string);
  438. TJSURLSearchParams = class external name 'URLSearchParams' (TJSObject)
  439. Public
  440. constructor new(aQuery : String);
  441. Procedure append(const aName,aValue : string);
  442. Procedure delete(const aName : string);
  443. Function entries : TJSIterator;
  444. Procedure foreach(aEnumCallBack : TJSParamEnumCallBack);
  445. function get(const aName : string) : JSValue;
  446. // If you're sure the value exists...
  447. function getString(const aName : string) : string; external name 'get';
  448. function getAll(const aName : string) : TStringDynArray;
  449. function has(const aName : string) : Boolean;
  450. Function keys : TJSIterator; reintroduce;
  451. Procedure set_(const aName,aValue : string); external name 'set';
  452. Procedure sort;
  453. Function values : TJSIterator; reintroduce;
  454. end;
  455. TJSURL = class external name 'URL' (TJSObject)
  456. Private
  457. FOrigin : String; external name 'origin';
  458. FSearchParams : TJSURLSearchParams; external name 'searchParams';
  459. public
  460. hash : string;
  461. host : string;
  462. hostname : string;
  463. href : string;
  464. password : string;
  465. pathname : string;
  466. port : string;
  467. protocol : string;
  468. search : string;
  469. username : string;
  470. constructor new(aURL : String);
  471. constructor new(aURL,aBase : String);
  472. class function createObjectURL(const v: JSValue): string;
  473. class function revokeObjectURL(const S : String): string;
  474. function toJSON : String;
  475. Property Origin : String Read FOrigin;
  476. property SearchParams : TJSURLSearchParams read FSearchParams;
  477. end;
  478. TJSURLDynArray = array of TJSURL;
  479. { TJSNavigationPreloadState }
  480. TJSNavigationPreloadState = class external name 'navigationPreloadState'
  481. public
  482. enabled: boolean;
  483. headerValue: string;
  484. end;
  485. { TJSNavigationPreload }
  486. TJSNavigationPreload = class external name 'navigationPreload' (TJSObject)
  487. public
  488. function enable: boolean; async;
  489. function disable: boolean; async;
  490. function setHeaderValue(Value: string): TJSPromise;
  491. function getState: TJSNavigationPreloadState; async;
  492. end;
  493. TJSWorker = class external name 'Worker' (TJSEventTarget)
  494. public
  495. constructor new(aURL : string);
  496. procedure postMessage(aValue : JSValue);
  497. procedure postMessage(aValue : JSValue; aList : TJSValueDynArray);
  498. end;
  499. { TJSServiceWorkerRegistration }
  500. TJSServiceWorkerRegistration = class external name 'ServiceWorkerRegistration' (TJSObject)
  501. private
  502. FActive: TJSServiceWorker; external name 'active';
  503. FInstalling: TJSServiceWorker; external name 'installing';
  504. FScope: string; external name 'scope';
  505. FWaiting: TJSServiceWorker; external name 'waiting';
  506. FNavigationPreload: TJSNavigationPreload; external name 'navigationPreload';
  507. public
  508. function unregister : TJSPromise;
  509. procedure update;
  510. property Active : TJSServiceWorker read FActive;
  511. property Scope : string read FScope;
  512. property Waiting : TJSServiceWorker read FWaiting;
  513. property Installing : TJSServiceWorker read FInstalling;
  514. property NavigationPreload: TJSNavigationPreload read FNavigationPreload;
  515. end;
  516. { TJSServiceWorker }
  517. TJSServiceWorker = class external name 'ServiceWorker' (TJSWorker)
  518. private
  519. FRegistration: TJSServiceWorkerRegistration; external name 'registration';
  520. FScriptURL: String; external name 'scriptURL';
  521. FState: string; external name 'state';
  522. Public
  523. property State : string read FState;
  524. property ScriptURL : String Read FscriptURL;
  525. property Registration: TJSServiceWorkerRegistration read FRegistration;
  526. end;
  527. { TJSRequest }
  528. TJSCache = class external name 'Cache' (TJSObject)
  529. Public
  530. Function add(aRequest : String) : TJSPromise;
  531. Function add(aRequest : TJSURL) : TJSPromise;
  532. Function addAll(aRequests : TJSStringDynArray) : TJSPromise;
  533. Function addAll(aRequests : TJSURLDynArray) : TJSPromise;
  534. Function addAll(aRequests : TJSValueDynArray) : TJSPromise;
  535. Function put(aRequest : String; aResponse : TJSResponse) : TJSPromise;
  536. Function put(aRequest : TJSRequest; aResponse : TJSResponse) : TJSPromise;
  537. Function delete(aRequest : String) : TJSPromise;
  538. Function delete(aRequest : TJSRequest) : TJSPromise;
  539. Function delete(aRequest : String; aOptions : TJSObject) : TJSPromise;
  540. Function delete(aRequest : TJSRequest; aOptions : TJSObject) : TJSPromise;
  541. Function delete(aRequest : String; aOptions : TJSCacheDeleteOptions) : TJSPromise;
  542. Function delete(aRequest : TJSRequest; aOptions : TJSCacheDeleteOptions) : TJSPromise;
  543. Function keys : TJSPromise; reintroduce;
  544. Function match(aRequest : String): TJSPromise;
  545. Function match(aRequest : TJSRequest): TJSPromise;
  546. Function matchAll(aRequest : TJSStringDynArray): TJSPromise;
  547. Function matchAll(aRequest : TJSRequestDynArray): TJSPromise;
  548. Function matchAll(aRequests : TJSValueDynArray) : TJSPromise;
  549. end;
  550. TJSCacheStorage = class external name 'CacheStorage' (TJSObject)
  551. Public
  552. function delete(aName : string) : TJSPromise; // resolves to boolean
  553. function has(aName : string) : TJSPromise;
  554. Function keys : TJSPromise; reintroduce;
  555. Function match(aRequest : String): TJSPromise;
  556. Function match(aRequest : TJSRequest): TJSPromise;
  557. function open(aName : string) : TJSPromise;
  558. end;
  559. { TJSFetchEvent }
  560. TJSFetchEvent = class external name 'FetchEvent' (TJSExtendableEvent)
  561. private
  562. FClientID: String; external name 'clientId';
  563. FReplacesClientID: String; external name 'replacesClientId';
  564. FRequest: TJSRequest; external name 'request';
  565. FResultingClientID: String; external name 'resultingClientId';
  566. FPreloadResponse: TJSPromise; external name 'preloadResponse';
  567. Public
  568. Procedure respondWith(aPromise : TJSPromise);
  569. Procedure respondWith(aResponse : TJSResponse);
  570. Property ClientId : String Read FClientID;
  571. Property PreloadResponse : TJSPromise Read FPreloadResponse;
  572. Property ReplacesClientID : String Read FReplacesClientID;
  573. Property ResultingClientID : String Read FResultingClientID;
  574. Property request : TJSRequest Read FRequest;
  575. end;
  576. TJSMicrotaskProcedure = reference to Procedure;
  577. TJSImageBitmapOptions = class external name 'Object' (TJSObject)
  578. imageOrientation : string;
  579. premultiplyAlpha : string;
  580. colorSpaceConversion : String;
  581. resizeWidth : NativeInt;
  582. resizeHeight : NativeInt;
  583. resizeQuality : String;
  584. end;
  585. { ----------------------------------------------------------------------
  586. Crypto
  587. ----------------------------------------------------------------------}
  588. TJSCryptoAlgorithmIdentifier = JSValue;
  589. TJSCryptoNamedCurve = JSValue;
  590. TJSCryptoBigInteger = TJSUint8Array;
  591. TJSCryptoKeyUsage = string;
  592. TJSCryptoKeyType = string;
  593. TJSCryptoKeyFormat = string;
  594. { --------------------------------------------------------------------
  595. Algorithm
  596. --------------------------------------------------------------------}
  597. TJSCryptoAlgorithm = record
  598. name : String;
  599. end;
  600. { --------------------------------------------------------------------
  601. AesCbcParams
  602. --------------------------------------------------------------------}
  603. TJSCryptoAesCbcParams = record
  604. iv : TJSBufferSource;
  605. end;
  606. { --------------------------------------------------------------------
  607. AesCtrParams
  608. --------------------------------------------------------------------}
  609. TJSCryptoAesCtrParams = record
  610. counter : TJSBufferSource;
  611. length_ : Byte;external name 'length';
  612. end;
  613. { --------------------------------------------------------------------
  614. AesGcmParams
  615. --------------------------------------------------------------------}
  616. TJSCryptoAesGcmParams = record
  617. iv : TJSBufferSource;
  618. additionalData : TJSBufferSource;
  619. tagLength : Byte;
  620. end;
  621. { --------------------------------------------------------------------
  622. HmacImportParams
  623. --------------------------------------------------------------------}
  624. TJSCryptoHmacImportParams = record
  625. hash : TJSCryptoAlgorithmIdentifier;
  626. end;
  627. { --------------------------------------------------------------------
  628. Pbkdf2Params
  629. --------------------------------------------------------------------}
  630. TJSCryptoPbkdf2Params = record
  631. salt : TJSBufferSource;
  632. iterations : NativeInt;
  633. hash : TJSCryptoAlgorithmIdentifier;
  634. end;
  635. { --------------------------------------------------------------------
  636. RsaHashedImportParams
  637. --------------------------------------------------------------------}
  638. TJSCryptoRsaHashedImportParams = record
  639. hash : TJSCryptoAlgorithmIdentifier;
  640. end;
  641. { --------------------------------------------------------------------
  642. AesKeyGenParams
  643. --------------------------------------------------------------------}
  644. TJSCryptoAesKeyGenParams = record
  645. length_ : Integer;external name 'length';
  646. end;
  647. { --------------------------------------------------------------------
  648. HmacKeyGenParams
  649. --------------------------------------------------------------------}
  650. TJSCryptoHmacKeyGenParams = record
  651. hash : TJSCryptoAlgorithmIdentifier;
  652. length_ : Integer;external name 'length';
  653. end;
  654. { --------------------------------------------------------------------
  655. RsaHashedKeyGenParams
  656. --------------------------------------------------------------------}
  657. TJSCryptoRsaHashedKeyGenParams = record
  658. modulusLength : Integer;
  659. publicExponent : TJSCryptoBigInteger;
  660. hash : TJSCryptoAlgorithmIdentifier;
  661. end;
  662. { --------------------------------------------------------------------
  663. RsaOaepParams
  664. --------------------------------------------------------------------}
  665. TJSCryptoRsaOaepParams = record
  666. label_ : TJSBufferSource;external name 'label';
  667. end;
  668. { --------------------------------------------------------------------
  669. RsaPssParams
  670. --------------------------------------------------------------------}
  671. TJSCryptoRsaPssParams = record
  672. saltLength : Integer;
  673. end;
  674. { --------------------------------------------------------------------
  675. DhKeyGenParams
  676. --------------------------------------------------------------------}
  677. TJSCryptoDhKeyGenParams = record
  678. prime : TJSCryptoBigInteger;
  679. generator : TJSCryptoBigInteger;
  680. end;
  681. { --------------------------------------------------------------------
  682. EcKeyGenParams
  683. --------------------------------------------------------------------}
  684. TJSCryptoEcKeyGenParams = record
  685. _namedCurve : TJSCryptoNamedCurve;external name 'namedCurve';
  686. end;
  687. { --------------------------------------------------------------------
  688. AesDerivedKeyParams
  689. --------------------------------------------------------------------}
  690. TJSCryptoAesDerivedKeyParams = record
  691. length_ : Integer;external name 'length';
  692. end;
  693. { --------------------------------------------------------------------
  694. HmacDerivedKeyParams
  695. --------------------------------------------------------------------}
  696. TJSCryptoHmacDerivedKeyParams = record
  697. length_ : Integer;external name 'length';
  698. end;
  699. { --------------------------------------------------------------------
  700. EcdhKeyDeriveParams
  701. --------------------------------------------------------------------}
  702. TJSCryptoEcdhKeyDeriveParams = record
  703. public_ : TJSCryptoKey; external name 'public';
  704. end;
  705. { --------------------------------------------------------------------
  706. DhKeyDeriveParams
  707. --------------------------------------------------------------------}
  708. TJSCryptoDhKeyDeriveParams = record
  709. public_ : TJSCryptoKey; external name 'public';
  710. end;
  711. { --------------------------------------------------------------------
  712. DhImportKeyParams
  713. --------------------------------------------------------------------}
  714. TJSCryptoDhImportKeyParams = record
  715. prime : TJSCryptoBigInteger;
  716. generator : TJSCryptoBigInteger;
  717. end;
  718. { --------------------------------------------------------------------
  719. EcdsaParams
  720. --------------------------------------------------------------------}
  721. TJSCryptoEcdsaParams = record
  722. hash : TJSCryptoAlgorithmIdentifier;
  723. end;
  724. { --------------------------------------------------------------------
  725. EcKeyImportParams
  726. --------------------------------------------------------------------}
  727. TJSCryptoEcKeyImportParams = record
  728. _namedCurve : TJSCryptoNamedCurve;external name 'namedCurve';
  729. end;
  730. { --------------------------------------------------------------------
  731. HkdfParams
  732. --------------------------------------------------------------------}
  733. TJSCryptoHkdfParams = record
  734. hash : TJSCryptoAlgorithmIdentifier;
  735. salt : TJSBufferSource;
  736. info : TJSBufferSource;
  737. end;
  738. { --------------------------------------------------------------------
  739. RsaOtherPrimesInfo
  740. --------------------------------------------------------------------}
  741. TJSCryptoRsaOtherPrimesInfo = record
  742. r : String;
  743. d : String;
  744. t : String;
  745. end;
  746. { --------------------------------------------------------------------
  747. JsonWebKey
  748. --------------------------------------------------------------------}
  749. TJSCryptoRsaOtherPrimesInfoDynArray = Array of TJSCryptoRsaOtherPrimesInfo;
  750. TJSCryptoJsonWebKey = record
  751. kty : String;
  752. use : String;
  753. key_ops : TStringDynArray;
  754. alg : String;
  755. ext : boolean;
  756. crv : String;
  757. x : String;
  758. y : String;
  759. d : String;
  760. n : String;
  761. e : String;
  762. p : String;
  763. q : String;
  764. dp : String;
  765. dq : String;
  766. qi : String;
  767. oth : TJSCryptoRsaOtherPrimesInfoDynArray;
  768. k : String;
  769. end;
  770. { --------------------------------------------------------------------
  771. CryptoKeyPair
  772. --------------------------------------------------------------------}
  773. TJSCryptoKeyPair = record
  774. publicKey : TJSCryptoKey;
  775. privateKey : TJSCryptoKey;
  776. end;
  777. { --------------------------------------------------------------------
  778. TJSCryptoKey
  779. --------------------------------------------------------------------}
  780. TJSCryptoKeyUsageDynArray = Array of TJSCryptoKeyUsage;
  781. TJSCryptoKey = class external name 'CryptoKey'
  782. Private
  783. Ftype_ : TJSCryptoKeyType; external name 'type';
  784. Fextractable : boolean; external name 'extractable';
  785. Falgorithm : TJSObject; external name 'algorithm';
  786. Fusages : TJSCryptoKeyUsageDynArray; external name 'usages';
  787. Public
  788. Property type_ : TJSCryptoKeyType Read Ftype_;
  789. Property extractable : boolean Read Fextractable;
  790. Property algorithm : TJSObject Read Falgorithm;
  791. Property usages : TJSCryptoKeyUsageDynArray Read Fusages;
  792. end;
  793. { --------------------------------------------------------------------
  794. TJSSubtleCrypto
  795. --------------------------------------------------------------------}
  796. TJSSubtleCrypto = class external name 'SubtleCrypto'
  797. Private
  798. Public
  799. function encrypt(algorithm : TJSCryptoAlgorithmIdentifier; key : TJSCryptoKey; data : TJSBufferSource): TJSPromise;
  800. function decrypt(algorithm : TJSCryptoAlgorithmIdentifier; key : TJSCryptoKey; data : TJSBufferSource): TJSPromise;
  801. function sign(algorithm : TJSCryptoAlgorithmIdentifier; key : TJSCryptoKey; data : TJSBufferSource): TJSPromise;
  802. function verify(algorithm : TJSCryptoAlgorithmIdentifier; key : TJSCryptoKey; signature : TJSBufferSource; data : TJSBufferSource): TJSPromise;
  803. function digest(algorithm : TJSCryptoAlgorithmIdentifier; data : TJSBufferSource): TJSPromise;
  804. function generateKey(algorithm : TJSCryptoAlgorithmIdentifier; extractable : boolean; keyUsages : TJSCryptoKeyUsageDynArray): TJSPromise;
  805. function deriveKey(algorithm : TJSCryptoAlgorithmIdentifier; baseKey : TJSCryptoKey; derivedKeyType : TJSCryptoAlgorithmIdentifier; extractable : boolean; keyUsages : TJSCryptoKeyUsageDynArray): TJSPromise;
  806. function deriveBits(algorithm : TJSCryptoAlgorithmIdentifier; baseKey : TJSCryptoKey; length_ : NativeInt): TJSPromise;
  807. function importKey(format : TJSCryptoKeyFormat; keyData : TJSObject; algorithm : TJSCryptoAlgorithmIdentifier; extractable : boolean; keyUsages : TJSCryptoKeyUsageDynArray): TJSPromise;
  808. function exportKey(format : TJSCryptoKeyFormat; key : TJSCryptoKey): TJSPromise;
  809. function wrapKey(format : TJSCryptoKeyFormat; key : TJSCryptoKey; wrappingKey : TJSCryptoKey; wrapAlgorithm : TJSCryptoAlgorithmIdentifier): TJSPromise;
  810. function unwrapKey(format : TJSCryptoKeyFormat; wrappedKey : TJSBufferSource; unwrappingKey : TJSCryptoKey; unwrapAlgorithm : TJSCryptoAlgorithmIdentifier; unwrappedKeyAlgorithm : TJSCryptoAlgorithmIdentifier; extractable : boolean; keyUsages : TJSCryptoKeyUsageDynArray): TJSPromise;
  811. end;
  812. { TJSCrypto }
  813. TJSCrypto = class external name 'Crypto' (TJSObject)
  814. private
  815. Fsubtle: TJSSubtleCrypto; external name 'subtle';
  816. Public
  817. procedure getRandomValues (anArray : TJSTypedArray);
  818. property subtle : TJSSubtleCrypto Read Fsubtle;
  819. end;
  820. { TWindowOrWorkerGlobalScope }
  821. TWindowOrWorkerGlobalScope = Class external name 'Object' (TJSEventTarget)
  822. Private
  823. FCrypto: TJSCrypto; external name 'crypto';
  824. FisSecureContext : boolean; external name 'isSecureContext';
  825. FIDBFactory : TJSIDBFactory; external name 'IDBFactory';
  826. fcaches : TJSCacheStorage; external name 'caches';
  827. Public
  828. Function setInterval(ahandler : TJSTimerCallBack; aInterval : NativeUInt) : NativeInt; varargs;
  829. Function setTimeout(ahandler : TJSTimerCallBack; aTimeout : NativeUInt) : NativeInt; varargs;
  830. Function setTimeout(ahandler : TJSTimerCallBack) : NativeInt;
  831. Procedure clearInterval(aID: NativeInt);
  832. Procedure clearTimeout(aID: NativeInt);
  833. procedure queueMicrotask(callback : TJSMicrotaskProcedure);
  834. Function createImageBitmap(Source : JSValue) : TJSPromise;
  835. Function createImageBitmap(Source : JSValue; aOptions : TJSImageBitmapOptions) : TJSPromise;
  836. Function createImageBitmap(Source : JSValue; sx,sy,sw,sh : NativeInt; aOptions : TJSImageBitmapOptions) : TJSPromise;
  837. Function structuredClone(value : JSValue) : JSValue;
  838. Function structuredClone(value : JSValue; aOptions : TJSStructuredSerializeOptions) : JSValue;
  839. function fetch(resource: String; init: TJSObject): TJSPromise; overload; external name 'fetch';
  840. //function fetch(resource: String): TJSPromise; overload; external name 'fetch';
  841. function fetch(resource: String): TJSResponse; {$IFNDEF SkipAsync}async;{$ENDIF} overload; external name 'fetch';
  842. function fetch(resource: TJSObject; init: TJSObject): TJSPromise; overload; external name 'fetch';
  843. function fetch(resource: TJSObject): TJSPromise; overload; external name 'fetch';
  844. property isSecureContext : Boolean Read FisSecureContext;
  845. property IDBFactory : TJSIDBFactory Read FIDBFactory;
  846. property caches : TJSCacheStorage read fcaches;
  847. property crypto : TJSCrypto Read FCrypto;
  848. end;
  849. var
  850. Console : TJSConsole; external name 'console';
  851. Crypto: TJSCrypto; external name 'crypto';
  852. implementation
  853. end.