github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/mojoprivate/apis_js_wasm.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package mojoprivate
     5  
     6  import (
     7  	"github.com/primecitizens/pcz/std/ffi/js"
     8  	"github.com/primecitizens/pcz/std/plat/js/webext/mojoprivate/bindings"
     9  )
    10  
    11  // HasFuncRequireAsync returns true if the function "WEBEXT.mojoPrivate.requireAsync" exists.
    12  func HasFuncRequireAsync() bool {
    13  	return js.True == bindings.HasFuncRequireAsync()
    14  }
    15  
    16  // FuncRequireAsync returns the function "WEBEXT.mojoPrivate.requireAsync".
    17  func FuncRequireAsync() (fn js.Func[func(name js.String) js.Any]) {
    18  	bindings.FuncRequireAsync(
    19  		js.Pointer(&fn),
    20  	)
    21  	return
    22  }
    23  
    24  // RequireAsync calls the function "WEBEXT.mojoPrivate.requireAsync" directly.
    25  func RequireAsync(name js.String) (ret js.Any) {
    26  	bindings.CallRequireAsync(
    27  		js.Pointer(&ret),
    28  		name.Ref(),
    29  	)
    30  
    31  	return
    32  }
    33  
    34  // TryRequireAsync calls the function "WEBEXT.mojoPrivate.requireAsync"
    35  // in a try/catch block and returns (_, err, ok = false) when it went through
    36  // the catch clause.
    37  func TryRequireAsync(name js.String) (ret js.Any, exception js.Any, ok bool) {
    38  	ok = js.True == bindings.TryRequireAsync(
    39  		js.Pointer(&ret), js.Pointer(&exception),
    40  		name.Ref(),
    41  	)
    42  
    43  	return
    44  }