|
| 1 | +export type RbErrno = number; |
| 2 | +export type RbId = number; |
| 3 | +export class RbAbiGuest { |
| 4 | + |
| 5 | + /** |
| 6 | + * The WebAssembly instance that this class is operating with. |
| 7 | + * This is only available after the `instantiate` method has |
| 8 | + * been called. |
| 9 | + */ |
| 10 | + instance: WebAssembly.Instance; |
| 11 | + |
| 12 | + /** |
| 13 | + * Constructs a new instance with internal state necessary to |
| 14 | + * manage a wasm instance. |
| 15 | + * |
| 16 | + * Note that this does not actually instantiate the WebAssembly |
| 17 | + * instance or module, you'll need to call the `instantiate` |
| 18 | + * method below to "activate" this class. |
| 19 | + */ |
| 20 | + constructor(); |
| 21 | + |
| 22 | + /** |
| 23 | + * This is a low-level method which can be used to add any |
| 24 | + * intrinsics necessary for this instance to operate to an |
| 25 | + * import object. |
| 26 | + * |
| 27 | + * The `import` object given here is expected to be used later |
| 28 | + * to actually instantiate the module this class corresponds to. |
| 29 | + * If the `instantiate` method below actually does the |
| 30 | + * instantiation then there's no need to call this method, but |
| 31 | + * if you're instantiating manually elsewhere then this can be |
| 32 | + * used to prepare the import object for external instantiation. |
| 33 | + */ |
| 34 | + addToImports(imports: any): void; |
| 35 | + |
| 36 | + /** |
| 37 | + * Initializes this object with the provided WebAssembly |
| 38 | + * module/instance. |
| 39 | + * |
| 40 | + * This is intended to be a flexible method of instantiating |
| 41 | + * and completion of the initialization of this class. This |
| 42 | + * method must be called before interacting with the |
| 43 | + * WebAssembly object. |
| 44 | + * |
| 45 | + * The first argument to this method is where to get the |
| 46 | + * wasm from. This can be a whole bunch of different types, |
| 47 | + * for example: |
| 48 | + * |
| 49 | + * * A precompiled `WebAssembly.Module` |
| 50 | + * * A typed array buffer containing the wasm bytecode. |
| 51 | + * * A `Promise` of a `Response` which is used with |
| 52 | + * `instantiateStreaming` |
| 53 | + * * A `Response` itself used with `instantiateStreaming`. |
| 54 | + * * An already instantiated `WebAssembly.Instance` |
| 55 | + * |
| 56 | + * If necessary the module is compiled, and if necessary the |
| 57 | + * module is instantiated. Whether or not it's necessary |
| 58 | + * depends on the type of argument provided to |
| 59 | + * instantiation. |
| 60 | + * |
| 61 | + * If instantiation is performed then the `imports` object |
| 62 | + * passed here is the list of imports used to instantiate |
| 63 | + * the instance. This method may add its own intrinsics to |
| 64 | + * this `imports` object too. |
| 65 | + */ |
| 66 | + instantiate( |
| 67 | + module: WebAssembly.Module | BufferSource | Promise<Response> | Response | WebAssembly.Instance, |
| 68 | + imports?: any, |
| 69 | + ): Promise<void>; |
| 70 | + rubyShowVersion(): void; |
| 71 | + rubyInit(): void; |
| 72 | + rubySysinit(args: string[]): void; |
| 73 | + rubyOptions(args: string[]): RbIseq; |
| 74 | + rubyScript(name: string): void; |
| 75 | + rubyInitLoadpath(): void; |
| 76 | + rbEvalStringProtect(str: string): [RbAbiValue, number]; |
| 77 | + rbFuncallvProtect(recv: RbAbiValue, mid: RbId, args: RbAbiValue[]): [RbAbiValue, number]; |
| 78 | + rbIntern(name: string): RbId; |
| 79 | + rbErrinfo(): RbAbiValue; |
| 80 | + rbClearErrinfo(): void; |
| 81 | + rstringPtr(value: RbAbiValue): string; |
| 82 | +} |
| 83 | + |
| 84 | +export class RbIseq { |
| 85 | + // Creates a new strong reference count as a new |
| 86 | + // object. This is only required if you're also |
| 87 | + // calling `drop` below and want to manually manage |
| 88 | + // the reference count from JS. |
| 89 | + // |
| 90 | + // If you don't call `drop`, you don't need to call |
| 91 | + // this and can simply use the object from JS. |
| 92 | + clone(): RbIseq; |
| 93 | + |
| 94 | + // Explicitly indicate that this JS object will no |
| 95 | + // longer be used. If the internal reference count |
| 96 | + // reaches zero then this will deterministically |
| 97 | + // destroy the underlying wasm object. |
| 98 | + // |
| 99 | + // This is not required to be called from JS. Wasm |
| 100 | + // destructors will be automatically called for you |
| 101 | + // if this is not called using the JS |
| 102 | + // `FinalizationRegistry`. |
| 103 | + // |
| 104 | + // Calling this method does not guarantee that the |
| 105 | + // underlying wasm object is deallocated. Something |
| 106 | + // else (including wasm) may be holding onto a |
| 107 | + // strong reference count. |
| 108 | + drop(): void; |
| 109 | +} |
| 110 | + |
| 111 | +export class RbAbiValue { |
| 112 | + // Creates a new strong reference count as a new |
| 113 | + // object. This is only required if you're also |
| 114 | + // calling `drop` below and want to manually manage |
| 115 | + // the reference count from JS. |
| 116 | + // |
| 117 | + // If you don't call `drop`, you don't need to call |
| 118 | + // this and can simply use the object from JS. |
| 119 | + clone(): RbAbiValue; |
| 120 | + |
| 121 | + // Explicitly indicate that this JS object will no |
| 122 | + // longer be used. If the internal reference count |
| 123 | + // reaches zero then this will deterministically |
| 124 | + // destroy the underlying wasm object. |
| 125 | + // |
| 126 | + // This is not required to be called from JS. Wasm |
| 127 | + // destructors will be automatically called for you |
| 128 | + // if this is not called using the JS |
| 129 | + // `FinalizationRegistry`. |
| 130 | + // |
| 131 | + // Calling this method does not guarantee that the |
| 132 | + // underlying wasm object is deallocated. Something |
| 133 | + // else (including wasm) may be holding onto a |
| 134 | + // strong reference count. |
| 135 | + drop(): void; |
| 136 | +} |
0 commit comments