github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/system/storage/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package storage 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/abi" 8 "github.com/primecitizens/pcz/std/core/mark" 9 "github.com/primecitizens/pcz/std/ffi/js" 10 "github.com/primecitizens/pcz/std/plat/js/webext/system/storage/bindings" 11 ) 12 13 type EjectDeviceCallbackFunc func(this js.Ref, result EjectDeviceResultCode) js.Ref 14 15 func (fn EjectDeviceCallbackFunc) Register() js.Func[func(result EjectDeviceResultCode)] { 16 return js.RegisterCallback[func(result EjectDeviceResultCode)]( 17 fn, abi.FuncPCABIInternal(fn), 18 ) 19 } 20 21 func (fn EjectDeviceCallbackFunc) DispatchCallback( 22 targetPC uintptr, ctx *js.CallbackContext, 23 ) { 24 args := ctx.Args() 25 if len(args) != 1+1 /* js this */ || 26 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 27 js.ThrowInvalidCallbackInvocation() 28 } 29 30 if ctx.Return(fn( 31 args[0], 32 33 EjectDeviceResultCode(0).FromRef(args[0+1]), 34 )) { 35 return 36 } 37 38 js.ThrowCallbackValueNotReturned() 39 } 40 41 type EjectDeviceCallback[T any] struct { 42 Fn func(arg T, this js.Ref, result EjectDeviceResultCode) js.Ref 43 Arg T 44 } 45 46 func (cb *EjectDeviceCallback[T]) Register() js.Func[func(result EjectDeviceResultCode)] { 47 return js.RegisterCallback[func(result EjectDeviceResultCode)]( 48 cb, abi.FuncPCABIInternal(cb.Fn), 49 ) 50 } 51 52 func (cb *EjectDeviceCallback[T]) DispatchCallback( 53 targetPC uintptr, ctx *js.CallbackContext, 54 ) { 55 args := ctx.Args() 56 if len(args) != 1+1 /* js this */ || 57 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 58 js.ThrowInvalidCallbackInvocation() 59 } 60 61 if ctx.Return(cb.Fn( 62 cb.Arg, 63 args[0], 64 65 EjectDeviceResultCode(0).FromRef(args[0+1]), 66 )) { 67 return 68 } 69 70 js.ThrowCallbackValueNotReturned() 71 } 72 73 type EjectDeviceResultCode uint32 74 75 const ( 76 _ EjectDeviceResultCode = iota 77 78 EjectDeviceResultCode_SUCCESS 79 EjectDeviceResultCode_IN_USE 80 EjectDeviceResultCode_NO_SUCH_DEVICE 81 EjectDeviceResultCode_FAILURE 82 ) 83 84 func (EjectDeviceResultCode) FromRef(str js.Ref) EjectDeviceResultCode { 85 return EjectDeviceResultCode(bindings.ConstOfEjectDeviceResultCode(str)) 86 } 87 88 func (x EjectDeviceResultCode) String() (string, bool) { 89 switch x { 90 case EjectDeviceResultCode_SUCCESS: 91 return "success", true 92 case EjectDeviceResultCode_IN_USE: 93 return "in_use", true 94 case EjectDeviceResultCode_NO_SUCH_DEVICE: 95 return "no_such_device", true 96 case EjectDeviceResultCode_FAILURE: 97 return "failure", true 98 default: 99 return "", false 100 } 101 } 102 103 type GetAvailableCapacityCallbackFunc func(this js.Ref, info *StorageAvailableCapacityInfo) js.Ref 104 105 func (fn GetAvailableCapacityCallbackFunc) Register() js.Func[func(info *StorageAvailableCapacityInfo)] { 106 return js.RegisterCallback[func(info *StorageAvailableCapacityInfo)]( 107 fn, abi.FuncPCABIInternal(fn), 108 ) 109 } 110 111 func (fn GetAvailableCapacityCallbackFunc) DispatchCallback( 112 targetPC uintptr, ctx *js.CallbackContext, 113 ) { 114 args := ctx.Args() 115 if len(args) != 1+1 /* js this */ || 116 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 117 js.ThrowInvalidCallbackInvocation() 118 } 119 var arg0 StorageAvailableCapacityInfo 120 arg0.UpdateFrom(args[0+1]) 121 defer arg0.FreeMembers(true) 122 123 if ctx.Return(fn( 124 args[0], 125 126 mark.NoEscape(&arg0), 127 )) { 128 return 129 } 130 131 js.ThrowCallbackValueNotReturned() 132 } 133 134 type GetAvailableCapacityCallback[T any] struct { 135 Fn func(arg T, this js.Ref, info *StorageAvailableCapacityInfo) js.Ref 136 Arg T 137 } 138 139 func (cb *GetAvailableCapacityCallback[T]) Register() js.Func[func(info *StorageAvailableCapacityInfo)] { 140 return js.RegisterCallback[func(info *StorageAvailableCapacityInfo)]( 141 cb, abi.FuncPCABIInternal(cb.Fn), 142 ) 143 } 144 145 func (cb *GetAvailableCapacityCallback[T]) DispatchCallback( 146 targetPC uintptr, ctx *js.CallbackContext, 147 ) { 148 args := ctx.Args() 149 if len(args) != 1+1 /* js this */ || 150 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 151 js.ThrowInvalidCallbackInvocation() 152 } 153 var arg0 StorageAvailableCapacityInfo 154 arg0.UpdateFrom(args[0+1]) 155 defer arg0.FreeMembers(true) 156 157 if ctx.Return(cb.Fn( 158 cb.Arg, 159 args[0], 160 161 mark.NoEscape(&arg0), 162 )) { 163 return 164 } 165 166 js.ThrowCallbackValueNotReturned() 167 } 168 169 type StorageAvailableCapacityInfo struct { 170 // Id is "StorageAvailableCapacityInfo.id" 171 // 172 // Optional 173 Id js.String 174 // AvailableCapacity is "StorageAvailableCapacityInfo.availableCapacity" 175 // 176 // Optional 177 // 178 // NOTE: FFI_USE_AvailableCapacity MUST be set to true to make this field effective. 179 AvailableCapacity float64 180 181 FFI_USE_AvailableCapacity bool // for AvailableCapacity. 182 183 FFI_USE bool 184 } 185 186 // FromRef calls UpdateFrom and returns a StorageAvailableCapacityInfo with all fields set. 187 func (p StorageAvailableCapacityInfo) FromRef(ref js.Ref) StorageAvailableCapacityInfo { 188 p.UpdateFrom(ref) 189 return p 190 } 191 192 // New creates a new StorageAvailableCapacityInfo in the application heap. 193 func (p StorageAvailableCapacityInfo) New() js.Ref { 194 return bindings.StorageAvailableCapacityInfoJSLoad( 195 js.Pointer(&p), js.True, 0, 196 ) 197 } 198 199 // UpdateFrom copies value of all fields of the heap object to p. 200 func (p *StorageAvailableCapacityInfo) UpdateFrom(ref js.Ref) { 201 bindings.StorageAvailableCapacityInfoJSStore( 202 js.Pointer(p), ref, 203 ) 204 } 205 206 // Update writes all fields of the p to the heap object referenced by ref. 207 func (p *StorageAvailableCapacityInfo) Update(ref js.Ref) { 208 bindings.StorageAvailableCapacityInfoJSLoad( 209 js.Pointer(p), js.False, ref, 210 ) 211 } 212 213 // FreeMembers frees fields with heap reference, if recursive is true 214 // free all heap references reachable from p. 215 func (p *StorageAvailableCapacityInfo) FreeMembers(recursive bool) { 216 js.Free( 217 p.Id.Ref(), 218 ) 219 p.Id = p.Id.FromRef(js.Undefined) 220 } 221 222 type StorageInfoCallbackFunc func(this js.Ref, info js.Array[StorageUnitInfo]) js.Ref 223 224 func (fn StorageInfoCallbackFunc) Register() js.Func[func(info js.Array[StorageUnitInfo])] { 225 return js.RegisterCallback[func(info js.Array[StorageUnitInfo])]( 226 fn, abi.FuncPCABIInternal(fn), 227 ) 228 } 229 230 func (fn StorageInfoCallbackFunc) DispatchCallback( 231 targetPC uintptr, ctx *js.CallbackContext, 232 ) { 233 args := ctx.Args() 234 if len(args) != 1+1 /* js this */ || 235 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 236 js.ThrowInvalidCallbackInvocation() 237 } 238 239 if ctx.Return(fn( 240 args[0], 241 242 js.Array[StorageUnitInfo]{}.FromRef(args[0+1]), 243 )) { 244 return 245 } 246 247 js.ThrowCallbackValueNotReturned() 248 } 249 250 type StorageInfoCallback[T any] struct { 251 Fn func(arg T, this js.Ref, info js.Array[StorageUnitInfo]) js.Ref 252 Arg T 253 } 254 255 func (cb *StorageInfoCallback[T]) Register() js.Func[func(info js.Array[StorageUnitInfo])] { 256 return js.RegisterCallback[func(info js.Array[StorageUnitInfo])]( 257 cb, abi.FuncPCABIInternal(cb.Fn), 258 ) 259 } 260 261 func (cb *StorageInfoCallback[T]) DispatchCallback( 262 targetPC uintptr, ctx *js.CallbackContext, 263 ) { 264 args := ctx.Args() 265 if len(args) != 1+1 /* js this */ || 266 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 267 js.ThrowInvalidCallbackInvocation() 268 } 269 270 if ctx.Return(cb.Fn( 271 cb.Arg, 272 args[0], 273 274 js.Array[StorageUnitInfo]{}.FromRef(args[0+1]), 275 )) { 276 return 277 } 278 279 js.ThrowCallbackValueNotReturned() 280 } 281 282 type StorageUnitType uint32 283 284 const ( 285 _ StorageUnitType = iota 286 287 StorageUnitType_FIXED 288 StorageUnitType_REMOVABLE 289 StorageUnitType_UNKNOWN 290 ) 291 292 func (StorageUnitType) FromRef(str js.Ref) StorageUnitType { 293 return StorageUnitType(bindings.ConstOfStorageUnitType(str)) 294 } 295 296 func (x StorageUnitType) String() (string, bool) { 297 switch x { 298 case StorageUnitType_FIXED: 299 return "fixed", true 300 case StorageUnitType_REMOVABLE: 301 return "removable", true 302 case StorageUnitType_UNKNOWN: 303 return "unknown", true 304 default: 305 return "", false 306 } 307 } 308 309 type StorageUnitInfo struct { 310 // Id is "StorageUnitInfo.id" 311 // 312 // Optional 313 Id js.String 314 // Name is "StorageUnitInfo.name" 315 // 316 // Optional 317 Name js.String 318 // Type is "StorageUnitInfo.type" 319 // 320 // Optional 321 Type StorageUnitType 322 // Capacity is "StorageUnitInfo.capacity" 323 // 324 // Optional 325 // 326 // NOTE: FFI_USE_Capacity MUST be set to true to make this field effective. 327 Capacity float64 328 329 FFI_USE_Capacity bool // for Capacity. 330 331 FFI_USE bool 332 } 333 334 // FromRef calls UpdateFrom and returns a StorageUnitInfo with all fields set. 335 func (p StorageUnitInfo) FromRef(ref js.Ref) StorageUnitInfo { 336 p.UpdateFrom(ref) 337 return p 338 } 339 340 // New creates a new StorageUnitInfo in the application heap. 341 func (p StorageUnitInfo) New() js.Ref { 342 return bindings.StorageUnitInfoJSLoad( 343 js.Pointer(&p), js.True, 0, 344 ) 345 } 346 347 // UpdateFrom copies value of all fields of the heap object to p. 348 func (p *StorageUnitInfo) UpdateFrom(ref js.Ref) { 349 bindings.StorageUnitInfoJSStore( 350 js.Pointer(p), ref, 351 ) 352 } 353 354 // Update writes all fields of the p to the heap object referenced by ref. 355 func (p *StorageUnitInfo) Update(ref js.Ref) { 356 bindings.StorageUnitInfoJSLoad( 357 js.Pointer(p), js.False, ref, 358 ) 359 } 360 361 // FreeMembers frees fields with heap reference, if recursive is true 362 // free all heap references reachable from p. 363 func (p *StorageUnitInfo) FreeMembers(recursive bool) { 364 js.Free( 365 p.Id.Ref(), 366 p.Name.Ref(), 367 ) 368 p.Id = p.Id.FromRef(js.Undefined) 369 p.Name = p.Name.FromRef(js.Undefined) 370 } 371 372 // HasFuncEjectDevice returns true if the function "WEBEXT.system.storage.ejectDevice" exists. 373 func HasFuncEjectDevice() bool { 374 return js.True == bindings.HasFuncEjectDevice() 375 } 376 377 // FuncEjectDevice returns the function "WEBEXT.system.storage.ejectDevice". 378 func FuncEjectDevice() (fn js.Func[func(id js.String) js.Promise[EjectDeviceResultCode]]) { 379 bindings.FuncEjectDevice( 380 js.Pointer(&fn), 381 ) 382 return 383 } 384 385 // EjectDevice calls the function "WEBEXT.system.storage.ejectDevice" directly. 386 func EjectDevice(id js.String) (ret js.Promise[EjectDeviceResultCode]) { 387 bindings.CallEjectDevice( 388 js.Pointer(&ret), 389 id.Ref(), 390 ) 391 392 return 393 } 394 395 // TryEjectDevice calls the function "WEBEXT.system.storage.ejectDevice" 396 // in a try/catch block and returns (_, err, ok = false) when it went through 397 // the catch clause. 398 func TryEjectDevice(id js.String) (ret js.Promise[EjectDeviceResultCode], exception js.Any, ok bool) { 399 ok = js.True == bindings.TryEjectDevice( 400 js.Pointer(&ret), js.Pointer(&exception), 401 id.Ref(), 402 ) 403 404 return 405 } 406 407 // HasFuncGetAvailableCapacity returns true if the function "WEBEXT.system.storage.getAvailableCapacity" exists. 408 func HasFuncGetAvailableCapacity() bool { 409 return js.True == bindings.HasFuncGetAvailableCapacity() 410 } 411 412 // FuncGetAvailableCapacity returns the function "WEBEXT.system.storage.getAvailableCapacity". 413 func FuncGetAvailableCapacity() (fn js.Func[func(id js.String) js.Promise[StorageAvailableCapacityInfo]]) { 414 bindings.FuncGetAvailableCapacity( 415 js.Pointer(&fn), 416 ) 417 return 418 } 419 420 // GetAvailableCapacity calls the function "WEBEXT.system.storage.getAvailableCapacity" directly. 421 func GetAvailableCapacity(id js.String) (ret js.Promise[StorageAvailableCapacityInfo]) { 422 bindings.CallGetAvailableCapacity( 423 js.Pointer(&ret), 424 id.Ref(), 425 ) 426 427 return 428 } 429 430 // TryGetAvailableCapacity calls the function "WEBEXT.system.storage.getAvailableCapacity" 431 // in a try/catch block and returns (_, err, ok = false) when it went through 432 // the catch clause. 433 func TryGetAvailableCapacity(id js.String) (ret js.Promise[StorageAvailableCapacityInfo], exception js.Any, ok bool) { 434 ok = js.True == bindings.TryGetAvailableCapacity( 435 js.Pointer(&ret), js.Pointer(&exception), 436 id.Ref(), 437 ) 438 439 return 440 } 441 442 // HasFuncGetInfo returns true if the function "WEBEXT.system.storage.getInfo" exists. 443 func HasFuncGetInfo() bool { 444 return js.True == bindings.HasFuncGetInfo() 445 } 446 447 // FuncGetInfo returns the function "WEBEXT.system.storage.getInfo". 448 func FuncGetInfo() (fn js.Func[func() js.Promise[js.Array[StorageUnitInfo]]]) { 449 bindings.FuncGetInfo( 450 js.Pointer(&fn), 451 ) 452 return 453 } 454 455 // GetInfo calls the function "WEBEXT.system.storage.getInfo" directly. 456 func GetInfo() (ret js.Promise[js.Array[StorageUnitInfo]]) { 457 bindings.CallGetInfo( 458 js.Pointer(&ret), 459 ) 460 461 return 462 } 463 464 // TryGetInfo calls the function "WEBEXT.system.storage.getInfo" 465 // in a try/catch block and returns (_, err, ok = false) when it went through 466 // the catch clause. 467 func TryGetInfo() (ret js.Promise[js.Array[StorageUnitInfo]], exception js.Any, ok bool) { 468 ok = js.True == bindings.TryGetInfo( 469 js.Pointer(&ret), js.Pointer(&exception), 470 ) 471 472 return 473 } 474 475 type OnAttachedEventCallbackFunc func(this js.Ref, info *StorageUnitInfo) js.Ref 476 477 func (fn OnAttachedEventCallbackFunc) Register() js.Func[func(info *StorageUnitInfo)] { 478 return js.RegisterCallback[func(info *StorageUnitInfo)]( 479 fn, abi.FuncPCABIInternal(fn), 480 ) 481 } 482 483 func (fn OnAttachedEventCallbackFunc) DispatchCallback( 484 targetPC uintptr, ctx *js.CallbackContext, 485 ) { 486 args := ctx.Args() 487 if len(args) != 1+1 /* js this */ || 488 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 489 js.ThrowInvalidCallbackInvocation() 490 } 491 var arg0 StorageUnitInfo 492 arg0.UpdateFrom(args[0+1]) 493 defer arg0.FreeMembers(true) 494 495 if ctx.Return(fn( 496 args[0], 497 498 mark.NoEscape(&arg0), 499 )) { 500 return 501 } 502 503 js.ThrowCallbackValueNotReturned() 504 } 505 506 type OnAttachedEventCallback[T any] struct { 507 Fn func(arg T, this js.Ref, info *StorageUnitInfo) js.Ref 508 Arg T 509 } 510 511 func (cb *OnAttachedEventCallback[T]) Register() js.Func[func(info *StorageUnitInfo)] { 512 return js.RegisterCallback[func(info *StorageUnitInfo)]( 513 cb, abi.FuncPCABIInternal(cb.Fn), 514 ) 515 } 516 517 func (cb *OnAttachedEventCallback[T]) DispatchCallback( 518 targetPC uintptr, ctx *js.CallbackContext, 519 ) { 520 args := ctx.Args() 521 if len(args) != 1+1 /* js this */ || 522 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 523 js.ThrowInvalidCallbackInvocation() 524 } 525 var arg0 StorageUnitInfo 526 arg0.UpdateFrom(args[0+1]) 527 defer arg0.FreeMembers(true) 528 529 if ctx.Return(cb.Fn( 530 cb.Arg, 531 args[0], 532 533 mark.NoEscape(&arg0), 534 )) { 535 return 536 } 537 538 js.ThrowCallbackValueNotReturned() 539 } 540 541 // HasFuncOnAttached returns true if the function "WEBEXT.system.storage.onAttached.addListener" exists. 542 func HasFuncOnAttached() bool { 543 return js.True == bindings.HasFuncOnAttached() 544 } 545 546 // FuncOnAttached returns the function "WEBEXT.system.storage.onAttached.addListener". 547 func FuncOnAttached() (fn js.Func[func(callback js.Func[func(info *StorageUnitInfo)])]) { 548 bindings.FuncOnAttached( 549 js.Pointer(&fn), 550 ) 551 return 552 } 553 554 // OnAttached calls the function "WEBEXT.system.storage.onAttached.addListener" directly. 555 func OnAttached(callback js.Func[func(info *StorageUnitInfo)]) (ret js.Void) { 556 bindings.CallOnAttached( 557 js.Pointer(&ret), 558 callback.Ref(), 559 ) 560 561 return 562 } 563 564 // TryOnAttached calls the function "WEBEXT.system.storage.onAttached.addListener" 565 // in a try/catch block and returns (_, err, ok = false) when it went through 566 // the catch clause. 567 func TryOnAttached(callback js.Func[func(info *StorageUnitInfo)]) (ret js.Void, exception js.Any, ok bool) { 568 ok = js.True == bindings.TryOnAttached( 569 js.Pointer(&ret), js.Pointer(&exception), 570 callback.Ref(), 571 ) 572 573 return 574 } 575 576 // HasFuncOffAttached returns true if the function "WEBEXT.system.storage.onAttached.removeListener" exists. 577 func HasFuncOffAttached() bool { 578 return js.True == bindings.HasFuncOffAttached() 579 } 580 581 // FuncOffAttached returns the function "WEBEXT.system.storage.onAttached.removeListener". 582 func FuncOffAttached() (fn js.Func[func(callback js.Func[func(info *StorageUnitInfo)])]) { 583 bindings.FuncOffAttached( 584 js.Pointer(&fn), 585 ) 586 return 587 } 588 589 // OffAttached calls the function "WEBEXT.system.storage.onAttached.removeListener" directly. 590 func OffAttached(callback js.Func[func(info *StorageUnitInfo)]) (ret js.Void) { 591 bindings.CallOffAttached( 592 js.Pointer(&ret), 593 callback.Ref(), 594 ) 595 596 return 597 } 598 599 // TryOffAttached calls the function "WEBEXT.system.storage.onAttached.removeListener" 600 // in a try/catch block and returns (_, err, ok = false) when it went through 601 // the catch clause. 602 func TryOffAttached(callback js.Func[func(info *StorageUnitInfo)]) (ret js.Void, exception js.Any, ok bool) { 603 ok = js.True == bindings.TryOffAttached( 604 js.Pointer(&ret), js.Pointer(&exception), 605 callback.Ref(), 606 ) 607 608 return 609 } 610 611 // HasFuncHasOnAttached returns true if the function "WEBEXT.system.storage.onAttached.hasListener" exists. 612 func HasFuncHasOnAttached() bool { 613 return js.True == bindings.HasFuncHasOnAttached() 614 } 615 616 // FuncHasOnAttached returns the function "WEBEXT.system.storage.onAttached.hasListener". 617 func FuncHasOnAttached() (fn js.Func[func(callback js.Func[func(info *StorageUnitInfo)]) bool]) { 618 bindings.FuncHasOnAttached( 619 js.Pointer(&fn), 620 ) 621 return 622 } 623 624 // HasOnAttached calls the function "WEBEXT.system.storage.onAttached.hasListener" directly. 625 func HasOnAttached(callback js.Func[func(info *StorageUnitInfo)]) (ret bool) { 626 bindings.CallHasOnAttached( 627 js.Pointer(&ret), 628 callback.Ref(), 629 ) 630 631 return 632 } 633 634 // TryHasOnAttached calls the function "WEBEXT.system.storage.onAttached.hasListener" 635 // in a try/catch block and returns (_, err, ok = false) when it went through 636 // the catch clause. 637 func TryHasOnAttached(callback js.Func[func(info *StorageUnitInfo)]) (ret bool, exception js.Any, ok bool) { 638 ok = js.True == bindings.TryHasOnAttached( 639 js.Pointer(&ret), js.Pointer(&exception), 640 callback.Ref(), 641 ) 642 643 return 644 } 645 646 type OnDetachedEventCallbackFunc func(this js.Ref, id js.String) js.Ref 647 648 func (fn OnDetachedEventCallbackFunc) Register() js.Func[func(id js.String)] { 649 return js.RegisterCallback[func(id js.String)]( 650 fn, abi.FuncPCABIInternal(fn), 651 ) 652 } 653 654 func (fn OnDetachedEventCallbackFunc) DispatchCallback( 655 targetPC uintptr, ctx *js.CallbackContext, 656 ) { 657 args := ctx.Args() 658 if len(args) != 1+1 /* js this */ || 659 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 660 js.ThrowInvalidCallbackInvocation() 661 } 662 663 if ctx.Return(fn( 664 args[0], 665 666 js.String{}.FromRef(args[0+1]), 667 )) { 668 return 669 } 670 671 js.ThrowCallbackValueNotReturned() 672 } 673 674 type OnDetachedEventCallback[T any] struct { 675 Fn func(arg T, this js.Ref, id js.String) js.Ref 676 Arg T 677 } 678 679 func (cb *OnDetachedEventCallback[T]) Register() js.Func[func(id js.String)] { 680 return js.RegisterCallback[func(id js.String)]( 681 cb, abi.FuncPCABIInternal(cb.Fn), 682 ) 683 } 684 685 func (cb *OnDetachedEventCallback[T]) DispatchCallback( 686 targetPC uintptr, ctx *js.CallbackContext, 687 ) { 688 args := ctx.Args() 689 if len(args) != 1+1 /* js this */ || 690 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 691 js.ThrowInvalidCallbackInvocation() 692 } 693 694 if ctx.Return(cb.Fn( 695 cb.Arg, 696 args[0], 697 698 js.String{}.FromRef(args[0+1]), 699 )) { 700 return 701 } 702 703 js.ThrowCallbackValueNotReturned() 704 } 705 706 // HasFuncOnDetached returns true if the function "WEBEXT.system.storage.onDetached.addListener" exists. 707 func HasFuncOnDetached() bool { 708 return js.True == bindings.HasFuncOnDetached() 709 } 710 711 // FuncOnDetached returns the function "WEBEXT.system.storage.onDetached.addListener". 712 func FuncOnDetached() (fn js.Func[func(callback js.Func[func(id js.String)])]) { 713 bindings.FuncOnDetached( 714 js.Pointer(&fn), 715 ) 716 return 717 } 718 719 // OnDetached calls the function "WEBEXT.system.storage.onDetached.addListener" directly. 720 func OnDetached(callback js.Func[func(id js.String)]) (ret js.Void) { 721 bindings.CallOnDetached( 722 js.Pointer(&ret), 723 callback.Ref(), 724 ) 725 726 return 727 } 728 729 // TryOnDetached calls the function "WEBEXT.system.storage.onDetached.addListener" 730 // in a try/catch block and returns (_, err, ok = false) when it went through 731 // the catch clause. 732 func TryOnDetached(callback js.Func[func(id js.String)]) (ret js.Void, exception js.Any, ok bool) { 733 ok = js.True == bindings.TryOnDetached( 734 js.Pointer(&ret), js.Pointer(&exception), 735 callback.Ref(), 736 ) 737 738 return 739 } 740 741 // HasFuncOffDetached returns true if the function "WEBEXT.system.storage.onDetached.removeListener" exists. 742 func HasFuncOffDetached() bool { 743 return js.True == bindings.HasFuncOffDetached() 744 } 745 746 // FuncOffDetached returns the function "WEBEXT.system.storage.onDetached.removeListener". 747 func FuncOffDetached() (fn js.Func[func(callback js.Func[func(id js.String)])]) { 748 bindings.FuncOffDetached( 749 js.Pointer(&fn), 750 ) 751 return 752 } 753 754 // OffDetached calls the function "WEBEXT.system.storage.onDetached.removeListener" directly. 755 func OffDetached(callback js.Func[func(id js.String)]) (ret js.Void) { 756 bindings.CallOffDetached( 757 js.Pointer(&ret), 758 callback.Ref(), 759 ) 760 761 return 762 } 763 764 // TryOffDetached calls the function "WEBEXT.system.storage.onDetached.removeListener" 765 // in a try/catch block and returns (_, err, ok = false) when it went through 766 // the catch clause. 767 func TryOffDetached(callback js.Func[func(id js.String)]) (ret js.Void, exception js.Any, ok bool) { 768 ok = js.True == bindings.TryOffDetached( 769 js.Pointer(&ret), js.Pointer(&exception), 770 callback.Ref(), 771 ) 772 773 return 774 } 775 776 // HasFuncHasOnDetached returns true if the function "WEBEXT.system.storage.onDetached.hasListener" exists. 777 func HasFuncHasOnDetached() bool { 778 return js.True == bindings.HasFuncHasOnDetached() 779 } 780 781 // FuncHasOnDetached returns the function "WEBEXT.system.storage.onDetached.hasListener". 782 func FuncHasOnDetached() (fn js.Func[func(callback js.Func[func(id js.String)]) bool]) { 783 bindings.FuncHasOnDetached( 784 js.Pointer(&fn), 785 ) 786 return 787 } 788 789 // HasOnDetached calls the function "WEBEXT.system.storage.onDetached.hasListener" directly. 790 func HasOnDetached(callback js.Func[func(id js.String)]) (ret bool) { 791 bindings.CallHasOnDetached( 792 js.Pointer(&ret), 793 callback.Ref(), 794 ) 795 796 return 797 } 798 799 // TryHasOnDetached calls the function "WEBEXT.system.storage.onDetached.hasListener" 800 // in a try/catch block and returns (_, err, ok = false) when it went through 801 // the catch clause. 802 func TryHasOnDetached(callback js.Func[func(id js.String)]) (ret bool, exception js.Any, ok bool) { 803 ok = js.True == bindings.TryHasOnDetached( 804 js.Pointer(&ret), js.Pointer(&exception), 805 callback.Ref(), 806 ) 807 808 return 809 }