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

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/speechrecognitionprivate", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "constof_SpeechRecognitionType": (ref: heap.Ref<string>): number => {
     8        const idx = ["onDevice", "network"].indexOf(A.H.get(ref));
     9        return idx < 0 ? 0 : idx + 1;
    10      },
    11  
    12      "store_SpeechRecognitionErrorEvent": (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 + 9, false);
    17          A.store.Bool(ptr + 8, false);
    18          A.store.Int32(ptr + 0, 0);
    19          A.store.Ref(ptr + 4, undefined);
    20        } else {
    21          A.store.Bool(ptr + 9, true);
    22          A.store.Bool(ptr + 8, "clientId" in x ? true : false);
    23          A.store.Int32(ptr + 0, x["clientId"] === undefined ? 0 : (x["clientId"] as number));
    24          A.store.Ref(ptr + 4, x["message"]);
    25        }
    26      },
    27      "load_SpeechRecognitionErrorEvent": (
    28        ptr: Pointer,
    29        create: heap.Ref<boolean>,
    30        ref: heap.Ref<any>
    31      ): heap.Ref<any> => {
    32        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    33  
    34        if (A.load.Bool(ptr + 8)) {
    35          x["clientId"] = A.load.Int32(ptr + 0);
    36        } else {
    37          delete x["clientId"];
    38        }
    39        x["message"] = A.load.Ref(ptr + 4, undefined);
    40        return create === A.H.TRUE ? A.H.push(x) : ref;
    41      },
    42  
    43      "store_SpeechRecognitionResultEvent": (ptr: Pointer, ref: heap.Ref<any>) => {
    44        const x = A.H.get<any>(ref);
    45  
    46        if (typeof x === "undefined") {
    47          A.store.Bool(ptr + 11, false);
    48          A.store.Bool(ptr + 9, false);
    49          A.store.Int32(ptr + 0, 0);
    50          A.store.Ref(ptr + 4, undefined);
    51          A.store.Bool(ptr + 10, false);
    52          A.store.Bool(ptr + 8, false);
    53        } else {
    54          A.store.Bool(ptr + 11, true);
    55          A.store.Bool(ptr + 9, "clientId" in x ? true : false);
    56          A.store.Int32(ptr + 0, x["clientId"] === undefined ? 0 : (x["clientId"] as number));
    57          A.store.Ref(ptr + 4, x["transcript"]);
    58          A.store.Bool(ptr + 10, "isFinal" in x ? true : false);
    59          A.store.Bool(ptr + 8, x["isFinal"] ? true : false);
    60        }
    61      },
    62      "load_SpeechRecognitionResultEvent": (
    63        ptr: Pointer,
    64        create: heap.Ref<boolean>,
    65        ref: heap.Ref<any>
    66      ): heap.Ref<any> => {
    67        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    68  
    69        if (A.load.Bool(ptr + 9)) {
    70          x["clientId"] = A.load.Int32(ptr + 0);
    71        } else {
    72          delete x["clientId"];
    73        }
    74        x["transcript"] = A.load.Ref(ptr + 4, undefined);
    75        if (A.load.Bool(ptr + 10)) {
    76          x["isFinal"] = A.load.Bool(ptr + 8);
    77        } else {
    78          delete x["isFinal"];
    79        }
    80        return create === A.H.TRUE ? A.H.push(x) : ref;
    81      },
    82  
    83      "store_SpeechRecognitionStopEvent": (ptr: Pointer, ref: heap.Ref<any>) => {
    84        const x = A.H.get<any>(ref);
    85  
    86        if (typeof x === "undefined") {
    87          A.store.Bool(ptr + 5, false);
    88          A.store.Bool(ptr + 4, false);
    89          A.store.Int32(ptr + 0, 0);
    90        } else {
    91          A.store.Bool(ptr + 5, true);
    92          A.store.Bool(ptr + 4, "clientId" in x ? true : false);
    93          A.store.Int32(ptr + 0, x["clientId"] === undefined ? 0 : (x["clientId"] as number));
    94        }
    95      },
    96      "load_SpeechRecognitionStopEvent": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    97        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    98  
    99        if (A.load.Bool(ptr + 4)) {
   100          x["clientId"] = A.load.Int32(ptr + 0);
   101        } else {
   102          delete x["clientId"];
   103        }
   104        return create === A.H.TRUE ? A.H.push(x) : ref;
   105      },
   106  
   107      "store_StartOptions": (ptr: Pointer, ref: heap.Ref<any>) => {
   108        const x = A.H.get<any>(ref);
   109  
   110        if (typeof x === "undefined") {
   111          A.store.Bool(ptr + 11, false);
   112          A.store.Bool(ptr + 9, false);
   113          A.store.Int32(ptr + 0, 0);
   114          A.store.Ref(ptr + 4, undefined);
   115          A.store.Bool(ptr + 10, false);
   116          A.store.Bool(ptr + 8, false);
   117        } else {
   118          A.store.Bool(ptr + 11, true);
   119          A.store.Bool(ptr + 9, "clientId" in x ? true : false);
   120          A.store.Int32(ptr + 0, x["clientId"] === undefined ? 0 : (x["clientId"] as number));
   121          A.store.Ref(ptr + 4, x["locale"]);
   122          A.store.Bool(ptr + 10, "interimResults" in x ? true : false);
   123          A.store.Bool(ptr + 8, x["interimResults"] ? true : false);
   124        }
   125      },
   126      "load_StartOptions": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
   127        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
   128  
   129        if (A.load.Bool(ptr + 9)) {
   130          x["clientId"] = A.load.Int32(ptr + 0);
   131        } else {
   132          delete x["clientId"];
   133        }
   134        x["locale"] = A.load.Ref(ptr + 4, undefined);
   135        if (A.load.Bool(ptr + 10)) {
   136          x["interimResults"] = A.load.Bool(ptr + 8);
   137        } else {
   138          delete x["interimResults"];
   139        }
   140        return create === A.H.TRUE ? A.H.push(x) : ref;
   141      },
   142  
   143      "store_StopOptions": (ptr: Pointer, ref: heap.Ref<any>) => {
   144        const x = A.H.get<any>(ref);
   145  
   146        if (typeof x === "undefined") {
   147          A.store.Bool(ptr + 5, false);
   148          A.store.Bool(ptr + 4, false);
   149          A.store.Int32(ptr + 0, 0);
   150        } else {
   151          A.store.Bool(ptr + 5, true);
   152          A.store.Bool(ptr + 4, "clientId" in x ? true : false);
   153          A.store.Int32(ptr + 0, x["clientId"] === undefined ? 0 : (x["clientId"] as number));
   154        }
   155      },
   156      "load_StopOptions": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
   157        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
   158  
   159        if (A.load.Bool(ptr + 4)) {
   160          x["clientId"] = A.load.Int32(ptr + 0);
   161        } else {
   162          delete x["clientId"];
   163        }
   164        return create === A.H.TRUE ? A.H.push(x) : ref;
   165      },
   166      "has_OnError": (): heap.Ref<boolean> => {
   167        if (WEBEXT?.speechRecognitionPrivate?.onError && "addListener" in WEBEXT?.speechRecognitionPrivate?.onError) {
   168          return A.H.TRUE;
   169        }
   170        return A.H.FALSE;
   171      },
   172      "func_OnError": (fn: Pointer): void => {
   173        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.onError.addListener);
   174      },
   175      "call_OnError": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   176        const _ret = WEBEXT.speechRecognitionPrivate.onError.addListener(A.H.get<object>(callback));
   177      },
   178      "try_OnError": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   179        try {
   180          const _ret = WEBEXT.speechRecognitionPrivate.onError.addListener(A.H.get<object>(callback));
   181          return A.H.TRUE;
   182        } catch (err: any) {
   183          A.store.Ref(errPtr, err);
   184          return A.H.FALSE;
   185        }
   186      },
   187      "has_OffError": (): heap.Ref<boolean> => {
   188        if (WEBEXT?.speechRecognitionPrivate?.onError && "removeListener" in WEBEXT?.speechRecognitionPrivate?.onError) {
   189          return A.H.TRUE;
   190        }
   191        return A.H.FALSE;
   192      },
   193      "func_OffError": (fn: Pointer): void => {
   194        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.onError.removeListener);
   195      },
   196      "call_OffError": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   197        const _ret = WEBEXT.speechRecognitionPrivate.onError.removeListener(A.H.get<object>(callback));
   198      },
   199      "try_OffError": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   200        try {
   201          const _ret = WEBEXT.speechRecognitionPrivate.onError.removeListener(A.H.get<object>(callback));
   202          return A.H.TRUE;
   203        } catch (err: any) {
   204          A.store.Ref(errPtr, err);
   205          return A.H.FALSE;
   206        }
   207      },
   208      "has_HasOnError": (): heap.Ref<boolean> => {
   209        if (WEBEXT?.speechRecognitionPrivate?.onError && "hasListener" in WEBEXT?.speechRecognitionPrivate?.onError) {
   210          return A.H.TRUE;
   211        }
   212        return A.H.FALSE;
   213      },
   214      "func_HasOnError": (fn: Pointer): void => {
   215        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.onError.hasListener);
   216      },
   217      "call_HasOnError": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   218        const _ret = WEBEXT.speechRecognitionPrivate.onError.hasListener(A.H.get<object>(callback));
   219        A.store.Bool(retPtr, _ret);
   220      },
   221      "try_HasOnError": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   222        try {
   223          const _ret = WEBEXT.speechRecognitionPrivate.onError.hasListener(A.H.get<object>(callback));
   224          A.store.Bool(retPtr, _ret);
   225          return A.H.TRUE;
   226        } catch (err: any) {
   227          A.store.Ref(errPtr, err);
   228          return A.H.FALSE;
   229        }
   230      },
   231      "has_OnResult": (): heap.Ref<boolean> => {
   232        if (WEBEXT?.speechRecognitionPrivate?.onResult && "addListener" in WEBEXT?.speechRecognitionPrivate?.onResult) {
   233          return A.H.TRUE;
   234        }
   235        return A.H.FALSE;
   236      },
   237      "func_OnResult": (fn: Pointer): void => {
   238        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.onResult.addListener);
   239      },
   240      "call_OnResult": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   241        const _ret = WEBEXT.speechRecognitionPrivate.onResult.addListener(A.H.get<object>(callback));
   242      },
   243      "try_OnResult": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   244        try {
   245          const _ret = WEBEXT.speechRecognitionPrivate.onResult.addListener(A.H.get<object>(callback));
   246          return A.H.TRUE;
   247        } catch (err: any) {
   248          A.store.Ref(errPtr, err);
   249          return A.H.FALSE;
   250        }
   251      },
   252      "has_OffResult": (): heap.Ref<boolean> => {
   253        if (
   254          WEBEXT?.speechRecognitionPrivate?.onResult &&
   255          "removeListener" in WEBEXT?.speechRecognitionPrivate?.onResult
   256        ) {
   257          return A.H.TRUE;
   258        }
   259        return A.H.FALSE;
   260      },
   261      "func_OffResult": (fn: Pointer): void => {
   262        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.onResult.removeListener);
   263      },
   264      "call_OffResult": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   265        const _ret = WEBEXT.speechRecognitionPrivate.onResult.removeListener(A.H.get<object>(callback));
   266      },
   267      "try_OffResult": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   268        try {
   269          const _ret = WEBEXT.speechRecognitionPrivate.onResult.removeListener(A.H.get<object>(callback));
   270          return A.H.TRUE;
   271        } catch (err: any) {
   272          A.store.Ref(errPtr, err);
   273          return A.H.FALSE;
   274        }
   275      },
   276      "has_HasOnResult": (): heap.Ref<boolean> => {
   277        if (WEBEXT?.speechRecognitionPrivate?.onResult && "hasListener" in WEBEXT?.speechRecognitionPrivate?.onResult) {
   278          return A.H.TRUE;
   279        }
   280        return A.H.FALSE;
   281      },
   282      "func_HasOnResult": (fn: Pointer): void => {
   283        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.onResult.hasListener);
   284      },
   285      "call_HasOnResult": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   286        const _ret = WEBEXT.speechRecognitionPrivate.onResult.hasListener(A.H.get<object>(callback));
   287        A.store.Bool(retPtr, _ret);
   288      },
   289      "try_HasOnResult": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   290        try {
   291          const _ret = WEBEXT.speechRecognitionPrivate.onResult.hasListener(A.H.get<object>(callback));
   292          A.store.Bool(retPtr, _ret);
   293          return A.H.TRUE;
   294        } catch (err: any) {
   295          A.store.Ref(errPtr, err);
   296          return A.H.FALSE;
   297        }
   298      },
   299      "has_OnStop": (): heap.Ref<boolean> => {
   300        if (WEBEXT?.speechRecognitionPrivate?.onStop && "addListener" in WEBEXT?.speechRecognitionPrivate?.onStop) {
   301          return A.H.TRUE;
   302        }
   303        return A.H.FALSE;
   304      },
   305      "func_OnStop": (fn: Pointer): void => {
   306        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.onStop.addListener);
   307      },
   308      "call_OnStop": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   309        const _ret = WEBEXT.speechRecognitionPrivate.onStop.addListener(A.H.get<object>(callback));
   310      },
   311      "try_OnStop": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   312        try {
   313          const _ret = WEBEXT.speechRecognitionPrivate.onStop.addListener(A.H.get<object>(callback));
   314          return A.H.TRUE;
   315        } catch (err: any) {
   316          A.store.Ref(errPtr, err);
   317          return A.H.FALSE;
   318        }
   319      },
   320      "has_OffStop": (): heap.Ref<boolean> => {
   321        if (WEBEXT?.speechRecognitionPrivate?.onStop && "removeListener" in WEBEXT?.speechRecognitionPrivate?.onStop) {
   322          return A.H.TRUE;
   323        }
   324        return A.H.FALSE;
   325      },
   326      "func_OffStop": (fn: Pointer): void => {
   327        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.onStop.removeListener);
   328      },
   329      "call_OffStop": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   330        const _ret = WEBEXT.speechRecognitionPrivate.onStop.removeListener(A.H.get<object>(callback));
   331      },
   332      "try_OffStop": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   333        try {
   334          const _ret = WEBEXT.speechRecognitionPrivate.onStop.removeListener(A.H.get<object>(callback));
   335          return A.H.TRUE;
   336        } catch (err: any) {
   337          A.store.Ref(errPtr, err);
   338          return A.H.FALSE;
   339        }
   340      },
   341      "has_HasOnStop": (): heap.Ref<boolean> => {
   342        if (WEBEXT?.speechRecognitionPrivate?.onStop && "hasListener" in WEBEXT?.speechRecognitionPrivate?.onStop) {
   343          return A.H.TRUE;
   344        }
   345        return A.H.FALSE;
   346      },
   347      "func_HasOnStop": (fn: Pointer): void => {
   348        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.onStop.hasListener);
   349      },
   350      "call_HasOnStop": (retPtr: Pointer, callback: heap.Ref<object>): void => {
   351        const _ret = WEBEXT.speechRecognitionPrivate.onStop.hasListener(A.H.get<object>(callback));
   352        A.store.Bool(retPtr, _ret);
   353      },
   354      "try_HasOnStop": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
   355        try {
   356          const _ret = WEBEXT.speechRecognitionPrivate.onStop.hasListener(A.H.get<object>(callback));
   357          A.store.Bool(retPtr, _ret);
   358          return A.H.TRUE;
   359        } catch (err: any) {
   360          A.store.Ref(errPtr, err);
   361          return A.H.FALSE;
   362        }
   363      },
   364      "has_Start": (): heap.Ref<boolean> => {
   365        if (WEBEXT?.speechRecognitionPrivate && "start" in WEBEXT?.speechRecognitionPrivate) {
   366          return A.H.TRUE;
   367        }
   368        return A.H.FALSE;
   369      },
   370      "func_Start": (fn: Pointer): void => {
   371        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.start);
   372      },
   373      "call_Start": (retPtr: Pointer, options: Pointer): void => {
   374        const options_ffi = {};
   375  
   376        if (A.load.Bool(options + 9)) {
   377          options_ffi["clientId"] = A.load.Int32(options + 0);
   378        }
   379        options_ffi["locale"] = A.load.Ref(options + 4, undefined);
   380        if (A.load.Bool(options + 10)) {
   381          options_ffi["interimResults"] = A.load.Bool(options + 8);
   382        }
   383  
   384        const _ret = WEBEXT.speechRecognitionPrivate.start(options_ffi);
   385        A.store.Ref(retPtr, _ret);
   386      },
   387      "try_Start": (retPtr: Pointer, errPtr: Pointer, options: Pointer): heap.Ref<boolean> => {
   388        try {
   389          const options_ffi = {};
   390  
   391          if (A.load.Bool(options + 9)) {
   392            options_ffi["clientId"] = A.load.Int32(options + 0);
   393          }
   394          options_ffi["locale"] = A.load.Ref(options + 4, undefined);
   395          if (A.load.Bool(options + 10)) {
   396            options_ffi["interimResults"] = A.load.Bool(options + 8);
   397          }
   398  
   399          const _ret = WEBEXT.speechRecognitionPrivate.start(options_ffi);
   400          A.store.Ref(retPtr, _ret);
   401          return A.H.TRUE;
   402        } catch (err: any) {
   403          A.store.Ref(errPtr, err);
   404          return A.H.FALSE;
   405        }
   406      },
   407      "has_Stop": (): heap.Ref<boolean> => {
   408        if (WEBEXT?.speechRecognitionPrivate && "stop" in WEBEXT?.speechRecognitionPrivate) {
   409          return A.H.TRUE;
   410        }
   411        return A.H.FALSE;
   412      },
   413      "func_Stop": (fn: Pointer): void => {
   414        A.store.Ref(fn, WEBEXT.speechRecognitionPrivate.stop);
   415      },
   416      "call_Stop": (retPtr: Pointer, options: Pointer): void => {
   417        const options_ffi = {};
   418  
   419        if (A.load.Bool(options + 4)) {
   420          options_ffi["clientId"] = A.load.Int32(options + 0);
   421        }
   422  
   423        const _ret = WEBEXT.speechRecognitionPrivate.stop(options_ffi);
   424        A.store.Ref(retPtr, _ret);
   425      },
   426      "try_Stop": (retPtr: Pointer, errPtr: Pointer, options: Pointer): heap.Ref<boolean> => {
   427        try {
   428          const options_ffi = {};
   429  
   430          if (A.load.Bool(options + 4)) {
   431            options_ffi["clientId"] = A.load.Int32(options + 0);
   432          }
   433  
   434          const _ret = WEBEXT.speechRecognitionPrivate.stop(options_ffi);
   435          A.store.Ref(retPtr, _ret);
   436          return A.H.TRUE;
   437        } catch (err: any) {
   438          A.store.Ref(errPtr, err);
   439          return A.H.FALSE;
   440        }
   441      },
   442    };
   443  });