CHANGELOG & additional comments (#368)

This commit is contained in:
Jaco
2022-06-21 16:35:45 +03:00
committed by GitHub
parent 3b5dcd41d9
commit 9b65fe6c86
3 changed files with 51 additions and 13 deletions
+2 -1
View File
@@ -4,7 +4,8 @@
Changes:
- Adjust assert inside `withWasm`
- Adjust assert usage in all internal non-test code
- Additional comments where missing
## 6.1.1 May 13, 2022
+48 -12
View File
@@ -84,12 +84,18 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return this.#wasm;
}
/** @description Gets an object from the heap */
/**
* @internal
* @description Gets an object from the heap
*/
getObject (idx: number): unknown {
return this.#heap[idx];
}
/** @description Removes an object from the heap */
/**
* @internal
* @description Removes an object from the heap
*/
dropObject (idx: number) {
if (idx < 36) {
return;
@@ -99,7 +105,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
this.#heapNext = idx;
}
/** @description Retrieves and removes an object to the heap */
/**
* @internal
* @description Retrieves and removes an object to the heap
*/
takeObject (idx: number): unknown {
const ret = this.getObject(idx);
@@ -108,7 +117,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return ret;
}
/** @description Adds an object to the heap */
/**
* @internal
* @description Adds an object to the heap
*/
addObject (obj: unknown): number {
if (this.#heapNext === this.#heap.length) {
this.#heap.push(this.#heap.length + 1);
@@ -122,7 +134,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return idx;
}
/** @description Retrieve an Int32 in the WASM interface */
/**
* @internal
* @description Retrieve an Int32 in the WASM interface
*/
getInt32 (): Int32Array {
if (this.#cachegetInt32 === null || this.#cachegetInt32.buffer !== this.#wasm!.memory.buffer) {
this.#cachegetInt32 = new Int32Array(this.#wasm!.memory.buffer);
@@ -131,7 +146,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return this.#cachegetInt32;
}
/** @description Retrieve an Uint8Array in the WASM interface */
/**
* @internal
* @description Retrieve an Uint8Array in the WASM interface
*/
getUint8 (): Uint8Array {
if (this.#cachegetUint8 === null || this.#cachegetUint8.buffer !== this.#wasm!.memory.buffer) {
this.#cachegetUint8 = new Uint8Array(this.#wasm!.memory.buffer);
@@ -140,17 +158,26 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return this.#cachegetUint8;
}
/** @description Retrieves an Uint8Array in the WASM interface */
/**
* @internal
* @description Retrieves an Uint8Array in the WASM interface
*/
getU8a (ptr: number, len: number): Uint8Array {
return this.getUint8().subarray(ptr / 1, ptr / 1 + len);
}
/** @description Retrieves a string in the WASM interface */
/**
* @internal
* @description Retrieves a string in the WASM interface
*/
getString (ptr: number, len: number): string {
return u8aToString(this.getU8a(ptr, len));
}
/** @description Allocates an Uint8Array in the WASM interface */
/**
* @internal
* @description Allocates an Uint8Array in the WASM interface
*/
allocU8a (arg: Uint8Array): [number, number] {
const ptr = this.#wasm!.__wbindgen_malloc(arg.length * 1);
@@ -159,12 +186,18 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return [ptr, arg.length];
}
/** @description Allocates a string in the WASM interface */
/**
* @internal
* @description Allocates a string in the WASM interface
*/
allocString (arg: string): [number, number] {
return this.allocU8a(stringToU8a(arg));
}
/** @description Retrieves an Uint8Array from the WASM interface */
/**
* @internal
* @description Retrieves an Uint8Array from the WASM interface
*/
resultU8a (): Uint8Array {
const r0 = this.getInt32()[8 / 4 + 0];
const r1 = this.getInt32()[8 / 4 + 1];
@@ -175,7 +208,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return ret;
}
/** @description Retrieve a string from the WASM interface */
/**
* @internal
* @description Retrieve a string from the WASM interface
*/
resultString (): string {
return u8aToString(this.resultU8a());
}
+1
View File
@@ -9,6 +9,7 @@ const DEFAULT_CRYPTO = { getRandomValues };
const DEFAULT_SELF = { crypto: DEFAULT_CRYPTO };
/**
* @name Wbg
* @description
* This defines the internal interfaces that wasm-bindgen used to communicate
* with the host layer. None of these functions are available to the user, rather