github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/sharedmodule/bindings/ffi_bindings.ts (about)

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/sharedmodule", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "store_Export": (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 + 4, false);
    12          A.store.Ref(ptr + 0, undefined);
    13        } else {
    14          A.store.Bool(ptr + 4, true);
    15          A.store.Ref(ptr + 0, x["allowlist"]);
    16        }
    17      },
    18      "load_Export": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    19        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    20  
    21        x["allowlist"] = A.load.Ref(ptr + 0, undefined);
    22        return create === A.H.TRUE ? A.H.push(x) : ref;
    23      },
    24  
    25      "store_Import": (ptr: Pointer, ref: heap.Ref<any>) => {
    26        const x = A.H.get<any>(ref);
    27  
    28        if (typeof x === "undefined") {
    29          A.store.Bool(ptr + 8, false);
    30          A.store.Ref(ptr + 0, undefined);
    31          A.store.Ref(ptr + 4, undefined);
    32        } else {
    33          A.store.Bool(ptr + 8, true);
    34          A.store.Ref(ptr + 0, x["id"]);
    35          A.store.Ref(ptr + 4, x["minimum_version"]);
    36        }
    37      },
    38      "load_Import": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    39        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    40  
    41        x["id"] = A.load.Ref(ptr + 0, undefined);
    42        x["minimum_version"] = A.load.Ref(ptr + 4, undefined);
    43        return create === A.H.TRUE ? A.H.push(x) : ref;
    44      },
    45  
    46      "store_ManifestKeys": (ptr: Pointer, ref: heap.Ref<any>) => {
    47        const x = A.H.get<any>(ref);
    48  
    49        if (typeof x === "undefined") {
    50          A.store.Bool(ptr + 9, false);
    51          A.store.Ref(ptr + 0, undefined);
    52  
    53          A.store.Bool(ptr + 4 + 4, false);
    54          A.store.Ref(ptr + 4 + 0, undefined);
    55        } else {
    56          A.store.Bool(ptr + 9, true);
    57          A.store.Ref(ptr + 0, x["import"]);
    58  
    59          if (typeof x["export"] === "undefined") {
    60            A.store.Bool(ptr + 4 + 4, false);
    61            A.store.Ref(ptr + 4 + 0, undefined);
    62          } else {
    63            A.store.Bool(ptr + 4 + 4, true);
    64            A.store.Ref(ptr + 4 + 0, x["export"]["allowlist"]);
    65          }
    66        }
    67      },
    68      "load_ManifestKeys": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    69        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    70  
    71        x["import"] = A.load.Ref(ptr + 0, undefined);
    72        if (A.load.Bool(ptr + 4 + 4)) {
    73          x["export"] = {};
    74          x["export"]["allowlist"] = A.load.Ref(ptr + 4 + 0, undefined);
    75        } else {
    76          delete x["export"];
    77        }
    78        return create === A.H.TRUE ? A.H.push(x) : ref;
    79      },
    80    };
    81  });