github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/loginscreenstorage/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package loginscreenstorage 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/abi" 8 "github.com/primecitizens/pcz/std/ffi/js" 9 "github.com/primecitizens/pcz/std/plat/js/webext/loginscreenstorage/bindings" 10 ) 11 12 type RetrieveCallbackFunc func(this js.Ref, data js.String) js.Ref 13 14 func (fn RetrieveCallbackFunc) Register() js.Func[func(data js.String)] { 15 return js.RegisterCallback[func(data js.String)]( 16 fn, abi.FuncPCABIInternal(fn), 17 ) 18 } 19 20 func (fn RetrieveCallbackFunc) DispatchCallback( 21 targetPC uintptr, ctx *js.CallbackContext, 22 ) { 23 args := ctx.Args() 24 if len(args) != 1+1 /* js this */ || 25 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 26 js.ThrowInvalidCallbackInvocation() 27 } 28 29 if ctx.Return(fn( 30 args[0], 31 32 js.String{}.FromRef(args[0+1]), 33 )) { 34 return 35 } 36 37 js.ThrowCallbackValueNotReturned() 38 } 39 40 type RetrieveCallback[T any] struct { 41 Fn func(arg T, this js.Ref, data js.String) js.Ref 42 Arg T 43 } 44 45 func (cb *RetrieveCallback[T]) Register() js.Func[func(data js.String)] { 46 return js.RegisterCallback[func(data js.String)]( 47 cb, abi.FuncPCABIInternal(cb.Fn), 48 ) 49 } 50 51 func (cb *RetrieveCallback[T]) DispatchCallback( 52 targetPC uintptr, ctx *js.CallbackContext, 53 ) { 54 args := ctx.Args() 55 if len(args) != 1+1 /* js this */ || 56 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 57 js.ThrowInvalidCallbackInvocation() 58 } 59 60 if ctx.Return(cb.Fn( 61 cb.Arg, 62 args[0], 63 64 js.String{}.FromRef(args[0+1]), 65 )) { 66 return 67 } 68 69 js.ThrowCallbackValueNotReturned() 70 } 71 72 type StoreCallbackFunc func(this js.Ref) js.Ref 73 74 func (fn StoreCallbackFunc) Register() js.Func[func()] { 75 return js.RegisterCallback[func()]( 76 fn, abi.FuncPCABIInternal(fn), 77 ) 78 } 79 80 func (fn StoreCallbackFunc) DispatchCallback( 81 targetPC uintptr, ctx *js.CallbackContext, 82 ) { 83 args := ctx.Args() 84 if len(args) != 0+1 /* js this */ || 85 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 86 js.ThrowInvalidCallbackInvocation() 87 } 88 89 if ctx.Return(fn( 90 args[0], 91 )) { 92 return 93 } 94 95 js.ThrowCallbackValueNotReturned() 96 } 97 98 type StoreCallback[T any] struct { 99 Fn func(arg T, this js.Ref) js.Ref 100 Arg T 101 } 102 103 func (cb *StoreCallback[T]) Register() js.Func[func()] { 104 return js.RegisterCallback[func()]( 105 cb, abi.FuncPCABIInternal(cb.Fn), 106 ) 107 } 108 109 func (cb *StoreCallback[T]) DispatchCallback( 110 targetPC uintptr, ctx *js.CallbackContext, 111 ) { 112 args := ctx.Args() 113 if len(args) != 0+1 /* js this */ || 114 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 115 js.ThrowInvalidCallbackInvocation() 116 } 117 118 if ctx.Return(cb.Fn( 119 cb.Arg, 120 args[0], 121 )) { 122 return 123 } 124 125 js.ThrowCallbackValueNotReturned() 126 } 127 128 // HasFuncRetrieveCredentials returns true if the function "WEBEXT.loginScreenStorage.retrieveCredentials" exists. 129 func HasFuncRetrieveCredentials() bool { 130 return js.True == bindings.HasFuncRetrieveCredentials() 131 } 132 133 // FuncRetrieveCredentials returns the function "WEBEXT.loginScreenStorage.retrieveCredentials". 134 func FuncRetrieveCredentials() (fn js.Func[func() js.Promise[js.String]]) { 135 bindings.FuncRetrieveCredentials( 136 js.Pointer(&fn), 137 ) 138 return 139 } 140 141 // RetrieveCredentials calls the function "WEBEXT.loginScreenStorage.retrieveCredentials" directly. 142 func RetrieveCredentials() (ret js.Promise[js.String]) { 143 bindings.CallRetrieveCredentials( 144 js.Pointer(&ret), 145 ) 146 147 return 148 } 149 150 // TryRetrieveCredentials calls the function "WEBEXT.loginScreenStorage.retrieveCredentials" 151 // in a try/catch block and returns (_, err, ok = false) when it went through 152 // the catch clause. 153 func TryRetrieveCredentials() (ret js.Promise[js.String], exception js.Any, ok bool) { 154 ok = js.True == bindings.TryRetrieveCredentials( 155 js.Pointer(&ret), js.Pointer(&exception), 156 ) 157 158 return 159 } 160 161 // HasFuncRetrievePersistentData returns true if the function "WEBEXT.loginScreenStorage.retrievePersistentData" exists. 162 func HasFuncRetrievePersistentData() bool { 163 return js.True == bindings.HasFuncRetrievePersistentData() 164 } 165 166 // FuncRetrievePersistentData returns the function "WEBEXT.loginScreenStorage.retrievePersistentData". 167 func FuncRetrievePersistentData() (fn js.Func[func(ownerId js.String) js.Promise[js.String]]) { 168 bindings.FuncRetrievePersistentData( 169 js.Pointer(&fn), 170 ) 171 return 172 } 173 174 // RetrievePersistentData calls the function "WEBEXT.loginScreenStorage.retrievePersistentData" directly. 175 func RetrievePersistentData(ownerId js.String) (ret js.Promise[js.String]) { 176 bindings.CallRetrievePersistentData( 177 js.Pointer(&ret), 178 ownerId.Ref(), 179 ) 180 181 return 182 } 183 184 // TryRetrievePersistentData calls the function "WEBEXT.loginScreenStorage.retrievePersistentData" 185 // in a try/catch block and returns (_, err, ok = false) when it went through 186 // the catch clause. 187 func TryRetrievePersistentData(ownerId js.String) (ret js.Promise[js.String], exception js.Any, ok bool) { 188 ok = js.True == bindings.TryRetrievePersistentData( 189 js.Pointer(&ret), js.Pointer(&exception), 190 ownerId.Ref(), 191 ) 192 193 return 194 } 195 196 // HasFuncStoreCredentials returns true if the function "WEBEXT.loginScreenStorage.storeCredentials" exists. 197 func HasFuncStoreCredentials() bool { 198 return js.True == bindings.HasFuncStoreCredentials() 199 } 200 201 // FuncStoreCredentials returns the function "WEBEXT.loginScreenStorage.storeCredentials". 202 func FuncStoreCredentials() (fn js.Func[func(extensionId js.String, credentials js.String) js.Promise[js.Void]]) { 203 bindings.FuncStoreCredentials( 204 js.Pointer(&fn), 205 ) 206 return 207 } 208 209 // StoreCredentials calls the function "WEBEXT.loginScreenStorage.storeCredentials" directly. 210 func StoreCredentials(extensionId js.String, credentials js.String) (ret js.Promise[js.Void]) { 211 bindings.CallStoreCredentials( 212 js.Pointer(&ret), 213 extensionId.Ref(), 214 credentials.Ref(), 215 ) 216 217 return 218 } 219 220 // TryStoreCredentials calls the function "WEBEXT.loginScreenStorage.storeCredentials" 221 // in a try/catch block and returns (_, err, ok = false) when it went through 222 // the catch clause. 223 func TryStoreCredentials(extensionId js.String, credentials js.String) (ret js.Promise[js.Void], exception js.Any, ok bool) { 224 ok = js.True == bindings.TryStoreCredentials( 225 js.Pointer(&ret), js.Pointer(&exception), 226 extensionId.Ref(), 227 credentials.Ref(), 228 ) 229 230 return 231 } 232 233 // HasFuncStorePersistentData returns true if the function "WEBEXT.loginScreenStorage.storePersistentData" exists. 234 func HasFuncStorePersistentData() bool { 235 return js.True == bindings.HasFuncStorePersistentData() 236 } 237 238 // FuncStorePersistentData returns the function "WEBEXT.loginScreenStorage.storePersistentData". 239 func FuncStorePersistentData() (fn js.Func[func(extensionIds js.Array[js.String], data js.String) js.Promise[js.Void]]) { 240 bindings.FuncStorePersistentData( 241 js.Pointer(&fn), 242 ) 243 return 244 } 245 246 // StorePersistentData calls the function "WEBEXT.loginScreenStorage.storePersistentData" directly. 247 func StorePersistentData(extensionIds js.Array[js.String], data js.String) (ret js.Promise[js.Void]) { 248 bindings.CallStorePersistentData( 249 js.Pointer(&ret), 250 extensionIds.Ref(), 251 data.Ref(), 252 ) 253 254 return 255 } 256 257 // TryStorePersistentData calls the function "WEBEXT.loginScreenStorage.storePersistentData" 258 // in a try/catch block and returns (_, err, ok = false) when it went through 259 // the catch clause. 260 func TryStorePersistentData(extensionIds js.Array[js.String], data js.String) (ret js.Promise[js.Void], exception js.Any, ok bool) { 261 ok = js.True == bindings.TryStorePersistentData( 262 js.Pointer(&ret), js.Pointer(&exception), 263 extensionIds.Ref(), 264 data.Ref(), 265 ) 266 267 return 268 }