github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/offscreen/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/offscreen", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_Reason": (ref: heap.Ref<string>): number => { 8 const idx = [ 9 "TESTING", 10 "AUDIO_PLAYBACK", 11 "IFRAME_SCRIPTING", 12 "DOM_SCRAPING", 13 "BLOBS", 14 "DOM_PARSER", 15 "USER_MEDIA", 16 "DISPLAY_MEDIA", 17 "WEB_RTC", 18 "CLIPBOARD", 19 "LOCAL_STORAGE", 20 "WORKERS", 21 "BATTERY_STATUS", 22 "MATCH_MEDIA", 23 "GEOLOCATION", 24 ].indexOf(A.H.get(ref)); 25 return idx < 0 ? 0 : idx + 1; 26 }, 27 28 "store_CreateParameters": (ptr: Pointer, ref: heap.Ref<any>) => { 29 const x = A.H.get<any>(ref); 30 31 if (typeof x === "undefined") { 32 A.store.Bool(ptr + 12, false); 33 A.store.Ref(ptr + 0, undefined); 34 A.store.Ref(ptr + 4, undefined); 35 A.store.Ref(ptr + 8, undefined); 36 } else { 37 A.store.Bool(ptr + 12, true); 38 A.store.Ref(ptr + 0, x["reasons"]); 39 A.store.Ref(ptr + 4, x["url"]); 40 A.store.Ref(ptr + 8, x["justification"]); 41 } 42 }, 43 "load_CreateParameters": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 44 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 45 46 x["reasons"] = A.load.Ref(ptr + 0, undefined); 47 x["url"] = A.load.Ref(ptr + 4, undefined); 48 x["justification"] = A.load.Ref(ptr + 8, undefined); 49 return create === A.H.TRUE ? A.H.push(x) : ref; 50 }, 51 "has_CloseDocument": (): heap.Ref<boolean> => { 52 if (WEBEXT?.offscreen && "closeDocument" in WEBEXT?.offscreen) { 53 return A.H.TRUE; 54 } 55 return A.H.FALSE; 56 }, 57 "func_CloseDocument": (fn: Pointer): void => { 58 A.store.Ref(fn, WEBEXT.offscreen.closeDocument); 59 }, 60 "call_CloseDocument": (retPtr: Pointer): void => { 61 const _ret = WEBEXT.offscreen.closeDocument(); 62 A.store.Ref(retPtr, _ret); 63 }, 64 "try_CloseDocument": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 65 try { 66 const _ret = WEBEXT.offscreen.closeDocument(); 67 A.store.Ref(retPtr, _ret); 68 return A.H.TRUE; 69 } catch (err: any) { 70 A.store.Ref(errPtr, err); 71 return A.H.FALSE; 72 } 73 }, 74 "has_CreateDocument": (): heap.Ref<boolean> => { 75 if (WEBEXT?.offscreen && "createDocument" in WEBEXT?.offscreen) { 76 return A.H.TRUE; 77 } 78 return A.H.FALSE; 79 }, 80 "func_CreateDocument": (fn: Pointer): void => { 81 A.store.Ref(fn, WEBEXT.offscreen.createDocument); 82 }, 83 "call_CreateDocument": (retPtr: Pointer, parameters: Pointer): void => { 84 const parameters_ffi = {}; 85 86 parameters_ffi["reasons"] = A.load.Ref(parameters + 0, undefined); 87 parameters_ffi["url"] = A.load.Ref(parameters + 4, undefined); 88 parameters_ffi["justification"] = A.load.Ref(parameters + 8, undefined); 89 90 const _ret = WEBEXT.offscreen.createDocument(parameters_ffi); 91 A.store.Ref(retPtr, _ret); 92 }, 93 "try_CreateDocument": (retPtr: Pointer, errPtr: Pointer, parameters: Pointer): heap.Ref<boolean> => { 94 try { 95 const parameters_ffi = {}; 96 97 parameters_ffi["reasons"] = A.load.Ref(parameters + 0, undefined); 98 parameters_ffi["url"] = A.load.Ref(parameters + 4, undefined); 99 parameters_ffi["justification"] = A.load.Ref(parameters + 8, undefined); 100 101 const _ret = WEBEXT.offscreen.createDocument(parameters_ffi); 102 A.store.Ref(retPtr, _ret); 103 return A.H.TRUE; 104 } catch (err: any) { 105 A.store.Ref(errPtr, err); 106 return A.H.FALSE; 107 } 108 }, 109 "has_HasDocument": (): heap.Ref<boolean> => { 110 if (WEBEXT?.offscreen && "hasDocument" in WEBEXT?.offscreen) { 111 return A.H.TRUE; 112 } 113 return A.H.FALSE; 114 }, 115 "func_HasDocument": (fn: Pointer): void => { 116 A.store.Ref(fn, WEBEXT.offscreen.hasDocument); 117 }, 118 "call_HasDocument": (retPtr: Pointer): void => { 119 const _ret = WEBEXT.offscreen.hasDocument(); 120 A.store.Ref(retPtr, _ret); 121 }, 122 "try_HasDocument": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 123 try { 124 const _ret = WEBEXT.offscreen.hasDocument(); 125 A.store.Ref(retPtr, _ret); 126 return A.H.TRUE; 127 } catch (err: any) { 128 A.store.Ref(errPtr, err); 129 return A.H.FALSE; 130 } 131 }, 132 }; 133 });