github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/sharedmodule/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package sharedmodule 5 6 import ( 7 "github.com/primecitizens/pcz/std/ffi/js" 8 "github.com/primecitizens/pcz/std/plat/js/webext/sharedmodule/bindings" 9 ) 10 11 type Export struct { 12 // Allowlist is "Export.allowlist" 13 // 14 // Optional 15 Allowlist js.Array[js.String] 16 17 FFI_USE bool 18 } 19 20 // FromRef calls UpdateFrom and returns a Export with all fields set. 21 func (p Export) FromRef(ref js.Ref) Export { 22 p.UpdateFrom(ref) 23 return p 24 } 25 26 // New creates a new Export in the application heap. 27 func (p Export) New() js.Ref { 28 return bindings.ExportJSLoad( 29 js.Pointer(&p), js.True, 0, 30 ) 31 } 32 33 // UpdateFrom copies value of all fields of the heap object to p. 34 func (p *Export) UpdateFrom(ref js.Ref) { 35 bindings.ExportJSStore( 36 js.Pointer(p), ref, 37 ) 38 } 39 40 // Update writes all fields of the p to the heap object referenced by ref. 41 func (p *Export) Update(ref js.Ref) { 42 bindings.ExportJSLoad( 43 js.Pointer(p), js.False, ref, 44 ) 45 } 46 47 // FreeMembers frees fields with heap reference, if recursive is true 48 // free all heap references reachable from p. 49 func (p *Export) FreeMembers(recursive bool) { 50 js.Free( 51 p.Allowlist.Ref(), 52 ) 53 p.Allowlist = p.Allowlist.FromRef(js.Undefined) 54 } 55 56 type Import struct { 57 // Id is "Import.id" 58 // 59 // Optional 60 Id js.String 61 // MinimumVersion is "Import.minimum_version" 62 // 63 // Optional 64 MinimumVersion js.String 65 66 FFI_USE bool 67 } 68 69 // FromRef calls UpdateFrom and returns a Import with all fields set. 70 func (p Import) FromRef(ref js.Ref) Import { 71 p.UpdateFrom(ref) 72 return p 73 } 74 75 // New creates a new Import in the application heap. 76 func (p Import) New() js.Ref { 77 return bindings.ImportJSLoad( 78 js.Pointer(&p), js.True, 0, 79 ) 80 } 81 82 // UpdateFrom copies value of all fields of the heap object to p. 83 func (p *Import) UpdateFrom(ref js.Ref) { 84 bindings.ImportJSStore( 85 js.Pointer(p), ref, 86 ) 87 } 88 89 // Update writes all fields of the p to the heap object referenced by ref. 90 func (p *Import) Update(ref js.Ref) { 91 bindings.ImportJSLoad( 92 js.Pointer(p), js.False, ref, 93 ) 94 } 95 96 // FreeMembers frees fields with heap reference, if recursive is true 97 // free all heap references reachable from p. 98 func (p *Import) FreeMembers(recursive bool) { 99 js.Free( 100 p.Id.Ref(), 101 p.MinimumVersion.Ref(), 102 ) 103 p.Id = p.Id.FromRef(js.Undefined) 104 p.MinimumVersion = p.MinimumVersion.FromRef(js.Undefined) 105 } 106 107 type ManifestKeys struct { 108 // Import is "ManifestKeys.import" 109 // 110 // Optional 111 Import js.Array[Import] 112 // Export is "ManifestKeys.export" 113 // 114 // Optional 115 // 116 // NOTE: Export.FFI_USE MUST be set to true to get Export used. 117 Export Export 118 119 FFI_USE bool 120 } 121 122 // FromRef calls UpdateFrom and returns a ManifestKeys with all fields set. 123 func (p ManifestKeys) FromRef(ref js.Ref) ManifestKeys { 124 p.UpdateFrom(ref) 125 return p 126 } 127 128 // New creates a new ManifestKeys in the application heap. 129 func (p ManifestKeys) New() js.Ref { 130 return bindings.ManifestKeysJSLoad( 131 js.Pointer(&p), js.True, 0, 132 ) 133 } 134 135 // UpdateFrom copies value of all fields of the heap object to p. 136 func (p *ManifestKeys) UpdateFrom(ref js.Ref) { 137 bindings.ManifestKeysJSStore( 138 js.Pointer(p), ref, 139 ) 140 } 141 142 // Update writes all fields of the p to the heap object referenced by ref. 143 func (p *ManifestKeys) Update(ref js.Ref) { 144 bindings.ManifestKeysJSLoad( 145 js.Pointer(p), js.False, ref, 146 ) 147 } 148 149 // FreeMembers frees fields with heap reference, if recursive is true 150 // free all heap references reachable from p. 151 func (p *ManifestKeys) FreeMembers(recursive bool) { 152 js.Free( 153 p.Import.Ref(), 154 ) 155 p.Import = p.Import.FromRef(js.Undefined) 156 if recursive { 157 p.Export.FreeMembers(true) 158 } 159 }