github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/topsites/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/topsites", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "store_MostVisitedURL": (ptr: Pointer, ref: heap.Ref<any>) => { 8 const x = A.H.get<any>(ref); 9 10 if (typeof x === "undefined") { 11 A.store.Bool(ptr + 8, false); 12 A.store.Ref(ptr + 0, undefined); 13 A.store.Ref(ptr + 4, undefined); 14 } else { 15 A.store.Bool(ptr + 8, true); 16 A.store.Ref(ptr + 0, x["title"]); 17 A.store.Ref(ptr + 4, x["url"]); 18 } 19 }, 20 "load_MostVisitedURL": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 21 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 22 23 x["title"] = A.load.Ref(ptr + 0, undefined); 24 x["url"] = A.load.Ref(ptr + 4, undefined); 25 return create === A.H.TRUE ? A.H.push(x) : ref; 26 }, 27 "has_Get": (): heap.Ref<boolean> => { 28 if (WEBEXT?.topSites && "get" in WEBEXT?.topSites) { 29 return A.H.TRUE; 30 } 31 return A.H.FALSE; 32 }, 33 "func_Get": (fn: Pointer): void => { 34 A.store.Ref(fn, WEBEXT.topSites.get); 35 }, 36 "call_Get": (retPtr: Pointer): void => { 37 const _ret = WEBEXT.topSites.get(); 38 A.store.Ref(retPtr, _ret); 39 }, 40 "try_Get": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 41 try { 42 const _ret = WEBEXT.topSites.get(); 43 A.store.Ref(retPtr, _ret); 44 return A.H.TRUE; 45 } catch (err: any) { 46 A.store.Ref(errPtr, err); 47 return A.H.FALSE; 48 } 49 }, 50 }; 51 });