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

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package topsites
     5  
     6  import (
     7  	"github.com/primecitizens/pcz/std/ffi/js"
     8  	"github.com/primecitizens/pcz/std/plat/js/webext/topsites/bindings"
     9  )
    10  
    11  type MostVisitedURL struct {
    12  	// Title is "MostVisitedURL.title"
    13  	//
    14  	// Required
    15  	Title js.String
    16  	// Url is "MostVisitedURL.url"
    17  	//
    18  	// Required
    19  	Url js.String
    20  
    21  	FFI_USE bool
    22  }
    23  
    24  // FromRef calls UpdateFrom and returns a MostVisitedURL with all fields set.
    25  func (p MostVisitedURL) FromRef(ref js.Ref) MostVisitedURL {
    26  	p.UpdateFrom(ref)
    27  	return p
    28  }
    29  
    30  // New creates a new MostVisitedURL in the application heap.
    31  func (p MostVisitedURL) New() js.Ref {
    32  	return bindings.MostVisitedURLJSLoad(
    33  		js.Pointer(&p), js.True, 0,
    34  	)
    35  }
    36  
    37  // UpdateFrom copies value of all fields of the heap object to p.
    38  func (p *MostVisitedURL) UpdateFrom(ref js.Ref) {
    39  	bindings.MostVisitedURLJSStore(
    40  		js.Pointer(p), ref,
    41  	)
    42  }
    43  
    44  // Update writes all fields of the p to the heap object referenced by ref.
    45  func (p *MostVisitedURL) Update(ref js.Ref) {
    46  	bindings.MostVisitedURLJSLoad(
    47  		js.Pointer(p), js.False, ref,
    48  	)
    49  }
    50  
    51  // FreeMembers frees fields with heap reference, if recursive is true
    52  // free all heap references reachable from p.
    53  func (p *MostVisitedURL) FreeMembers(recursive bool) {
    54  	js.Free(
    55  		p.Title.Ref(),
    56  		p.Url.Ref(),
    57  	)
    58  	p.Title = p.Title.FromRef(js.Undefined)
    59  	p.Url = p.Url.FromRef(js.Undefined)
    60  }
    61  
    62  // HasFuncGet returns true if the function "WEBEXT.topSites.get" exists.
    63  func HasFuncGet() bool {
    64  	return js.True == bindings.HasFuncGet()
    65  }
    66  
    67  // FuncGet returns the function "WEBEXT.topSites.get".
    68  func FuncGet() (fn js.Func[func() js.Promise[js.Array[MostVisitedURL]]]) {
    69  	bindings.FuncGet(
    70  		js.Pointer(&fn),
    71  	)
    72  	return
    73  }
    74  
    75  // Get calls the function "WEBEXT.topSites.get" directly.
    76  func Get() (ret js.Promise[js.Array[MostVisitedURL]]) {
    77  	bindings.CallGet(
    78  		js.Pointer(&ret),
    79  	)
    80  
    81  	return
    82  }
    83  
    84  // TryGet calls the function "WEBEXT.topSites.get"
    85  // in a try/catch block and returns (_, err, ok = false) when it went through
    86  // the catch clause.
    87  func TryGet() (ret js.Promise[js.Array[MostVisitedURL]], exception js.Any, ok bool) {
    88  	ok = js.True == bindings.TryGet(
    89  		js.Pointer(&ret), js.Pointer(&exception),
    90  	)
    91  
    92  	return
    93  }