Skip to content

Commit 8a705c1

Browse files
committed
feat: add wasm namespace
1 parent def5eab commit 8a705c1

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

lib/node_modules/@stdlib/types/index.d.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3773,3 +3773,151 @@ declare module '@stdlib/types/slice' {
37733773
data: ArrayLike<Slice | number | null>;
37743774
}
37753775
}
3776+
3777+
/**
3778+
* Module containing definitions for WebAssembly.
3779+
*
3780+
* @example
3781+
* import * as wasm from `@stdlib/types/wasm`;
3782+
*/
3783+
declare module '@stdlib/types/wasm' {
3784+
import { Collection, AccessorArrayLike } from '@stdlib/types/array';
3785+
3786+
/**
3787+
* WebAssembly memory interface.
3788+
*/
3789+
interface Memory {
3790+
/**
3791+
* Underlying `ArrayBuffer` (or `SharedArrayBuffer`) associated with a memory instance.
3792+
*/
3793+
buffer: ArrayBuffer;
3794+
3795+
/**
3796+
* Increases the size of the memory instance by a specified number of WebAssembly pages (i.e., 64KiB).
3797+
*
3798+
* ## Notes
3799+
*
3800+
* - Upon increasing the size, the previous `ArrayBuffer` is detached, thus invalidating any typed arrays which were views over the previous `ArrayBuffer`.
3801+
* - Detachment means that the previous `ArrayBuffer` byte length becomes zero, and it no longer has bytes accessible to JavaScript.
3802+
* - `ArrayBuffer` detachment applies even when `delta` is zero.
3803+
* - Detachment only applies for non-shared memory instances. For a shared memory instance, the initial buffer (which is a `SharedArrayBuffer`) will not become detached and, instead, its length will not be updated.
3804+
* - Accesses to the `buffer` property after growing a `SharedArrayBuffer` will yield a larger `SharedArrayBuffer` which may access a larger span of memory than the buffer before growing memory.
3805+
* - Every `SharedArrayBuffer` accessed via the `buffer` property will always refer to the start of the same memory address range and thus manipulate the same data.
3806+
*
3807+
* @param delta - number of WebAssembly pages (i.e., 64KiB) by which to grow the underlying memory
3808+
* @returns size of the previous `ArrayBuffer` (or `SharedArrayBuffer`)
3809+
*/
3810+
grow( delta: number ): number;
3811+
}
3812+
3813+
/**
3814+
* WebAssembly module wrapper interface.
3815+
*/
3816+
interface ModuleWrapper {
3817+
/**
3818+
* WebAssembly binary code.
3819+
*/
3820+
binary: Uint8Array;
3821+
3822+
/**
3823+
* WebAssembly memory.
3824+
*/
3825+
memory: Memory | null;
3826+
3827+
/**
3828+
* WebAssembly memory buffer as a Uint8Array.
3829+
*/
3830+
buffer: Uint8Array | null;
3831+
3832+
/**
3833+
* WebAssembly memory buffer as a DataView.
3834+
*/
3835+
view: DataView | null;
3836+
3837+
/**
3838+
* "Raw" WebAssembly module exports.
3839+
*/
3840+
exports: Object | null;
3841+
3842+
/**
3843+
* Asynchronously initializes a WebAssembly module instance.
3844+
*
3845+
* @returns promise which resolves upon initializing a WebAssembly module instance
3846+
*/
3847+
initialize(): Promise<ModuleWrapper>;
3848+
3849+
/**
3850+
* Asynchronously initializes a WebAssembly module instance.
3851+
*
3852+
* @param clbk - callback to invoke upon initializing a WebAssembly module
3853+
*/
3854+
initializeAsync( clbk: ( error: Error | null, mod?: ModuleWrapper ) => void ): void;
3855+
3856+
/**
3857+
* Synchronously initializes a WebAssembly module instance.
3858+
*
3859+
* @returns module wrapper instance
3860+
*/
3861+
initializeSync(): ModuleWrapper;
3862+
3863+
/**
3864+
* Reallocates the underlying WebAssembly memory instance to a specified number of bytes.
3865+
*
3866+
* ## Notes
3867+
*
3868+
* - WebAssembly memory can only **grow**, not shrink. Hence, if provided a number of bytes which is less than or equal to the size of the current memory, the function does nothing.
3869+
* - When non-shared memory is resized, the underlying the `ArrayBuffer` is detached, consequently invalidating any associated typed array views. Before resizing non-shared memory, ensure that associated typed array views no longer need byte access and can be garbage collected.
3870+
*
3871+
* @param nbytes - memory size (in bytes)
3872+
* @returns boolean indicating whether the resize operation was successful
3873+
*/
3874+
realloc( nbytes: number ): boolean;
3875+
3876+
/**
3877+
* Returns a boolean indicating whether the underlying WebAssembly memory instance has the capacity to store a provided list of values starting from a specified byte offset.
3878+
*
3879+
* @param byteOffset - byte offset at which to start writing values
3880+
* @param values - input array containing values to write
3881+
* @returns boolean indicating whether the underlying WebAssembly memory instance has enough capacity
3882+
*/
3883+
hasCapacity( byteOffset: number, values: Collection | AccessorArrayLike<any> ): boolean;
3884+
3885+
/**
3886+
* Returns a boolean indicating whether a provided list of values is a view of the underlying memory of the WebAssembly module.
3887+
*
3888+
* @param values - input array
3889+
* @returns boolean indicating whether the list is a memory view
3890+
*/
3891+
isView( values: Collection | AccessorArrayLike<any> ): boolean;
3892+
3893+
/**
3894+
* Writes values to the underlying WebAssembly memory instance.
3895+
*
3896+
* ## Notes
3897+
*
3898+
* - The function infers element size (i.e., number of bytes per element) from the data type of the input array. For example, if provided a `Float32Array`, the function writes each element as a single-precision floating-point number to the underlying WebAssembly memory instance.
3899+
* - In order to write elements as a different data type, you need to perform an explicit cast **before** calling this method. For example, in order to write single-precision floating-point numbers contained in a `Float32Array` as signed 32-bit integers, you must first convert the `Float32Array` to an `Int32Array` before passing the values to this method.
3900+
* - If provided an array having an unknown or "generic" data type, elements are written as double-precision floating-point numbers.
3901+
*
3902+
* @param byteOffset - byte offset at which to start writing values
3903+
* @param values - input array containing values to write
3904+
* @returns module wrapper instance
3905+
*/
3906+
write( byteOffset: number, values: Collection | AccessorArrayLike<any> ): ModuleWrapper;
3907+
3908+
/**
3909+
* Reads values from the underlying WebAssembly memory instance.
3910+
*
3911+
* ## Notes
3912+
*
3913+
* - The function infers element size (i.e., number of bytes per element) from the data type of the output array. For example, if provided a `Float32Array`, the function reads each element as a single-precision floating-point number from the underlying WebAssembly memory instance.
3914+
* - In order to read elements as a different data type, you need to perform an explicit cast **after** calling this method. For example, in order to read single-precision floating-point numbers contained in a `Float32Array` as signed 32-bit integers, you must convert the `Float32Array` to an `Int32Array` after reading memory values using this method.
3915+
* - If provided an output array having an unknown or "generic" data type, elements are read as double-precision floating-point numbers.
3916+
*
3917+
* @param byteOffset - byte offset at which to start reading values
3918+
* @param out - output array
3919+
* @returns module wrapper instance
3920+
*/
3921+
read( byteOffset: number, out: Collection | AccessorArrayLike<any> ): ModuleWrapper;
3922+
}
3923+
}

0 commit comments

Comments
 (0)