github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/search/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/search", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_Disposition": (ref: heap.Ref<string>): number => { 8 const idx = ["CURRENT_TAB", "NEW_TAB", "NEW_WINDOW"].indexOf(A.H.get(ref)); 9 return idx < 0 ? 0 : idx + 1; 10 }, 11 12 "store_QueryInfo": (ptr: Pointer, ref: heap.Ref<any>) => { 13 const x = A.H.get<any>(ref); 14 15 if (typeof x === "undefined") { 16 A.store.Bool(ptr + 13, false); 17 A.store.Ref(ptr + 0, undefined); 18 A.store.Enum(ptr + 4, -1); 19 A.store.Bool(ptr + 12, false); 20 A.store.Int32(ptr + 8, 0); 21 } else { 22 A.store.Bool(ptr + 13, true); 23 A.store.Ref(ptr + 0, x["text"]); 24 A.store.Enum(ptr + 4, ["CURRENT_TAB", "NEW_TAB", "NEW_WINDOW"].indexOf(x["disposition"] as string)); 25 A.store.Bool(ptr + 12, "tabId" in x ? true : false); 26 A.store.Int32(ptr + 8, x["tabId"] === undefined ? 0 : (x["tabId"] as number)); 27 } 28 }, 29 "load_QueryInfo": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 30 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 31 32 x["text"] = A.load.Ref(ptr + 0, undefined); 33 x["disposition"] = A.load.Enum(ptr + 4, ["CURRENT_TAB", "NEW_TAB", "NEW_WINDOW"]); 34 if (A.load.Bool(ptr + 12)) { 35 x["tabId"] = A.load.Int32(ptr + 8); 36 } else { 37 delete x["tabId"]; 38 } 39 return create === A.H.TRUE ? A.H.push(x) : ref; 40 }, 41 "has_Query": (): heap.Ref<boolean> => { 42 if (WEBEXT?.search && "query" in WEBEXT?.search) { 43 return A.H.TRUE; 44 } 45 return A.H.FALSE; 46 }, 47 "func_Query": (fn: Pointer): void => { 48 A.store.Ref(fn, WEBEXT.search.query); 49 }, 50 "call_Query": (retPtr: Pointer, queryInfo: Pointer): void => { 51 const queryInfo_ffi = {}; 52 53 queryInfo_ffi["text"] = A.load.Ref(queryInfo + 0, undefined); 54 queryInfo_ffi["disposition"] = A.load.Enum(queryInfo + 4, ["CURRENT_TAB", "NEW_TAB", "NEW_WINDOW"]); 55 if (A.load.Bool(queryInfo + 12)) { 56 queryInfo_ffi["tabId"] = A.load.Int32(queryInfo + 8); 57 } 58 59 const _ret = WEBEXT.search.query(queryInfo_ffi); 60 A.store.Ref(retPtr, _ret); 61 }, 62 "try_Query": (retPtr: Pointer, errPtr: Pointer, queryInfo: Pointer): heap.Ref<boolean> => { 63 try { 64 const queryInfo_ffi = {}; 65 66 queryInfo_ffi["text"] = A.load.Ref(queryInfo + 0, undefined); 67 queryInfo_ffi["disposition"] = A.load.Enum(queryInfo + 4, ["CURRENT_TAB", "NEW_TAB", "NEW_WINDOW"]); 68 if (A.load.Bool(queryInfo + 12)) { 69 queryInfo_ffi["tabId"] = A.load.Int32(queryInfo + 8); 70 } 71 72 const _ret = WEBEXT.search.query(queryInfo_ffi); 73 A.store.Ref(retPtr, _ret); 74 return A.H.TRUE; 75 } catch (err: any) { 76 A.store.Ref(errPtr, err); 77 return A.H.FALSE; 78 } 79 }, 80 }; 81 });