github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/webaccessibleresources/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package webaccessibleresources 5 6 import ( 7 "github.com/primecitizens/pcz/std/ffi/js" 8 "github.com/primecitizens/pcz/std/plat/js/webext/webaccessibleresources/bindings" 9 ) 10 11 type WebAccessibleResource struct { 12 // Resources is "WebAccessibleResource.resources" 13 // 14 // Optional 15 Resources js.Array[js.String] 16 // Matches is "WebAccessibleResource.matches" 17 // 18 // Optional 19 Matches js.Array[js.String] 20 // ExtensionIds is "WebAccessibleResource.extension_ids" 21 // 22 // Optional 23 ExtensionIds js.Array[js.String] 24 // UseDynamicUrl is "WebAccessibleResource.use_dynamic_url" 25 // 26 // Optional 27 // 28 // NOTE: FFI_USE_UseDynamicUrl MUST be set to true to make this field effective. 29 UseDynamicUrl bool 30 31 FFI_USE_UseDynamicUrl bool // for UseDynamicUrl. 32 33 FFI_USE bool 34 } 35 36 // FromRef calls UpdateFrom and returns a WebAccessibleResource with all fields set. 37 func (p WebAccessibleResource) FromRef(ref js.Ref) WebAccessibleResource { 38 p.UpdateFrom(ref) 39 return p 40 } 41 42 // New creates a new WebAccessibleResource in the application heap. 43 func (p WebAccessibleResource) New() js.Ref { 44 return bindings.WebAccessibleResourceJSLoad( 45 js.Pointer(&p), js.True, 0, 46 ) 47 } 48 49 // UpdateFrom copies value of all fields of the heap object to p. 50 func (p *WebAccessibleResource) UpdateFrom(ref js.Ref) { 51 bindings.WebAccessibleResourceJSStore( 52 js.Pointer(p), ref, 53 ) 54 } 55 56 // Update writes all fields of the p to the heap object referenced by ref. 57 func (p *WebAccessibleResource) Update(ref js.Ref) { 58 bindings.WebAccessibleResourceJSLoad( 59 js.Pointer(p), js.False, ref, 60 ) 61 } 62 63 // FreeMembers frees fields with heap reference, if recursive is true 64 // free all heap references reachable from p. 65 func (p *WebAccessibleResource) FreeMembers(recursive bool) { 66 js.Free( 67 p.Resources.Ref(), 68 p.Matches.Ref(), 69 p.ExtensionIds.Ref(), 70 ) 71 p.Resources = p.Resources.FromRef(js.Undefined) 72 p.Matches = p.Matches.FromRef(js.Undefined) 73 p.ExtensionIds = p.ExtensionIds.FromRef(js.Undefined) 74 } 75 76 type ManifestKeys struct { 77 // WebAccessibleResources is "ManifestKeys.web_accessible_resources" 78 // 79 // Optional 80 WebAccessibleResources js.Array[WebAccessibleResource] 81 82 FFI_USE bool 83 } 84 85 // FromRef calls UpdateFrom and returns a ManifestKeys with all fields set. 86 func (p ManifestKeys) FromRef(ref js.Ref) ManifestKeys { 87 p.UpdateFrom(ref) 88 return p 89 } 90 91 // New creates a new ManifestKeys in the application heap. 92 func (p ManifestKeys) New() js.Ref { 93 return bindings.ManifestKeysJSLoad( 94 js.Pointer(&p), js.True, 0, 95 ) 96 } 97 98 // UpdateFrom copies value of all fields of the heap object to p. 99 func (p *ManifestKeys) UpdateFrom(ref js.Ref) { 100 bindings.ManifestKeysJSStore( 101 js.Pointer(p), ref, 102 ) 103 } 104 105 // Update writes all fields of the p to the heap object referenced by ref. 106 func (p *ManifestKeys) Update(ref js.Ref) { 107 bindings.ManifestKeysJSLoad( 108 js.Pointer(p), js.False, ref, 109 ) 110 } 111 112 // FreeMembers frees fields with heap reference, if recursive is true 113 // free all heap references reachable from p. 114 func (p *ManifestKeys) FreeMembers(recursive bool) { 115 js.Free( 116 p.WebAccessibleResources.Ref(), 117 ) 118 p.WebAccessibleResources = p.WebAccessibleResources.FromRef(js.Undefined) 119 }