lib.wx.wasm.d.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*! *****************************************************************************
  2. Copyright (c) 2024 Tencent, Inc. All rights reserved.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. this software and associated documentation files (the "Software"), to deal in
  5. the Software without restriction, including without limitation the rights to
  6. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  7. of the Software, and to permit persons to whom the Software is furnished to do
  8. so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.
  18. ***************************************************************************** */
  19. /** [WXWebAssembly](https://developers.weixin.qq.com/miniprogram/dev/framework/performance/wasm.html)
  20. *
  21. * WXWebAssembly */
  22. declare namespace WXWebAssembly {
  23. type BufferSource = ArrayBufferView | ArrayBuffer
  24. type CompileError = Error
  25. const CompileError: {
  26. prototype: CompileError
  27. new (message?: string): CompileError
  28. (message?: string): CompileError
  29. }
  30. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) */
  31. interface Instance {
  32. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports) */
  33. readonly exports: Exports
  34. }
  35. const Instance: {
  36. prototype: Instance
  37. new (module: Module, importObject?: Imports): Instance
  38. }
  39. type LinkError = Error
  40. const LinkError: {
  41. prototype: LinkError
  42. new (message?: string): LinkError
  43. (message?: string): LinkError
  44. }
  45. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) */
  46. interface Memory {
  47. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer) */
  48. readonly buffer: ArrayBuffer
  49. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow) */
  50. grow(delta: number): number
  51. }
  52. const Memory: {
  53. prototype: Memory
  54. new (descriptor: MemoryDescriptor): Memory
  55. }
  56. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) */
  57. interface Module {}
  58. const Module: {
  59. prototype: Module
  60. new (bytes: BufferSource): Module
  61. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections) */
  62. customSections(moduleObject: Module, sectionName: string): ArrayBuffer[]
  63. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports) */
  64. exports(moduleObject: Module): ModuleExportDescriptor[]
  65. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports) */
  66. imports(moduleObject: Module): ModuleImportDescriptor[]
  67. }
  68. interface RuntimeError extends Error {}
  69. const RuntimeError: {
  70. prototype: RuntimeError
  71. new (message?: string): RuntimeError
  72. (message?: string): RuntimeError
  73. }
  74. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) */
  75. interface Table {
  76. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length) */
  77. readonly length: number
  78. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get) */
  79. get(index: number): any
  80. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow) */
  81. grow(delta: number, value?: any): number
  82. /** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set) */
  83. set(index: number, value?: any): void
  84. }
  85. const Table: {
  86. prototype: Table
  87. new (descriptor: TableDescriptor, value?: any): Table
  88. }
  89. interface MemoryDescriptor {
  90. initial: number
  91. maximum?: number
  92. shared?: boolean
  93. }
  94. interface ModuleExportDescriptor {
  95. kind: ImportExportKind
  96. name: string
  97. }
  98. interface ModuleImportDescriptor {
  99. kind: ImportExportKind
  100. module: string
  101. name: string
  102. }
  103. interface TableDescriptor {
  104. element: TableKind
  105. initial: number
  106. maximum?: number
  107. }
  108. type ImportExportKind = 'function' | 'global' | 'memory' | 'table'
  109. type TableKind = 'anyfunc' | 'externref'
  110. type ValueType =
  111. | 'anyfunc'
  112. | 'externref'
  113. | 'f32'
  114. | 'f64'
  115. | 'i32'
  116. | 'i64'
  117. | 'v128'
  118. // eslint-disable-next-line @typescript-eslint/ban-types
  119. type ExportValue = Function | Memory | Table
  120. type Exports = Record<string, ExportValue>
  121. type ImportValue = ExportValue | number
  122. type Imports = Record<string, ModuleImports>
  123. type ModuleImports = Record<string, ImportValue>
  124. /** [WXWebAssembly](https://developers.weixin.qq.com/miniprogram/dev/framework/performance/wasm.html) */
  125. function instantiate(
  126. path: string,
  127. importObject?: Imports
  128. ): Promise<Instance>
  129. }