From 6cfef7344122a5bf50673594a372a77223d34138 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 16 Mar 2020 18:56:00 +0200 Subject: [PATCH 1/3] remove semicolons + improve import object definition --- lib/loader/index.d.ts | 99 ++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/lib/loader/index.d.ts b/lib/loader/index.d.ts index 5e2f883c2e..98477b405b 100644 --- a/lib/loader/index.d.ts +++ b/lib/loader/index.d.ts @@ -1,118 +1,121 @@ /// interface ResultObject { - module: WebAssembly.Module, + module: WebAssembly.Module instance: WebAssembly.Instance -}; +} + +type ImportValue = Function | WebAssembly.Global | WebAssembly.Memory | WebAssembly.Table | number /** WebAssembly imports with two levels of nesting. */ -interface ImportsObject extends Record { +interface Imports extends Record> { env?: { memory?: WebAssembly.Memory, table?: WebAssembly.Table, + seed?: Function, abort?(msg: number, file: number, line: number, column: number): void, trace?(msg: number, numArgs?: number, ...args: number[]): void - }; + } } /** Utility mixed in by the loader. */ interface ASUtil { - memory?: WebAssembly.Memory; - table?: WebAssembly.Table; + memory?: WebAssembly.Memory + table?: WebAssembly.Table /** Explicit start function, if requested. */ - _start(): void; + _start(): void /** Allocates a new string in the module's memory and returns a reference (pointer) to it. */ - __allocString(str: string): number; + __allocString(str: string): number /** Allocates a new array in the module's memory and returns a reference (pointer) to it. */ - __allocArray(id: number, values: ArrayLike): number; + __allocArray(id: number, values: ArrayLike): number /** Copies a string's value from the module's memory. */ - __getString(ptr: number): string; + __getString(ptr: number): string /** Copies an ArrayBuffer's value from the module's memory. */ - __getArrayBuffer(ptr: number): ArrayBuffer; + __getArrayBuffer(ptr: number): ArrayBuffer /** Copies an array's values from the module's memory. Infers the array type from RTTI. */ - __getArray(ptr: number): number[]; + __getArray(ptr: number): number[] /** Copies an Int8Array's values from the module's memory. */ - __getInt8Array(ptr: number): Int8Array; + __getInt8Array(ptr: number): Int8Array /** Copies an Uint8Array's values from the module's memory. */ - __getUint8Array(ptr: number): Uint8Array; + __getUint8Array(ptr: number): Uint8Array /** Copies an Uint8ClampedArray's values from the module's memory. */ - __getUint8ClampedArray(ptr: number): Uint8ClampedArray; + __getUint8ClampedArray(ptr: number): Uint8ClampedArray /** Copies an Int16Array's values from the module's memory. */ - __getInt16Array(ptr: number): Int16Array; + __getInt16Array(ptr: number): Int16Array /** Copies an Uint16Array's values from the module's memory. */ - __getUint16Array(ptr: number): Uint16Array; + __getUint16Array(ptr: number): Uint16Array /** Copies an Int32Array's values from the module's memory. */ - __getInt32Array(ptr: number): Int32Array; + __getInt32Array(ptr: number): Int32Array /** Copies an Uint32Array's values from the module's memory. */ - __getUint32Array(ptr: number): Uint32Array; + __getUint32Array(ptr: number): Uint32Array /** Copies an Int32Array's values from the module's memory. */ - __getInt64Array?(ptr: number): BigInt64Array; + __getInt64Array?(ptr: number): BigInt64Array /** Copies an Uint32Array's values from the module's memory. */ - __getUint64Array?(ptr: number): BigUint64Array; + __getUint64Array?(ptr: number): BigUint64Array /** Copies a Float32Array's values from the module's memory. */ - __getFloat32Array(ptr: number): Float32Array; + __getFloat32Array(ptr: number): Float32Array /** Copies a Float64Array's values from the module's memory. */ - __getFloat64Array(ptr: number): Float64Array; + __getFloat64Array(ptr: number): Float64Array /** Gets a live view on an array's values in the module's memory. Infers the array type from RTTI. */ - __getArrayView(ptr: number): ArrayBufferView; + __getArrayView(ptr: number): ArrayBufferView /** Gets a live view on an Int8Array's values in the module's memory. */ - __getInt8ArrayView(ptr: number): Int8Array; + __getInt8ArrayView(ptr: number): Int8Array /** Gets a live view on an Uint8Array's values in the module's memory. */ - __getUint8ArrayView(ptr: number): Uint8Array; + __getUint8ArrayView(ptr: number): Uint8Array /** Gets a live view on an Uint8ClampedArray's values in the module's memory. */ - __getUint8ClampedArrayView(ptr: number): Uint8ClampedArray; + __getUint8ClampedArrayView(ptr: number): Uint8ClampedArray /** Gets a live view on an Int16Array's values in the module's memory. */ - __getInt16ArrayView(ptr: number): Int16Array; + __getInt16ArrayView(ptr: number): Int16Array /** Gets a live view on an Uint16Array's values in the module's memory. */ - __getUint16ArrayView(ptr: number): Uint16Array; + __getUint16ArrayView(ptr: number): Uint16Array /** Gets a live view on an Int32Array's values in the module's memory. */ - __getInt32ArrayView(ptr: number): Int32Array; + __getInt32ArrayView(ptr: number): Int32Array /** Gets a live view on an Uint32Array's values in the module's memory. */ - __getUint32ArrayView(ptr: number): Uint32Array; + __getUint32ArrayView(ptr: number): Uint32Array /** Gets a live view on an Int32Array's values in the module's memory. */ - __getInt64ArrayView?(ptr: number): BigInt64Array; + __getInt64ArrayView?(ptr: number): BigInt64Array /** Gets a live view on an Uint32Array's values in the module's memory. */ - __getUint64ArrayView?(ptr: number): BigUint64Array; + __getUint64ArrayView?(ptr: number): BigUint64Array /** Gets a live view on a Float32Array's values in the module's memory. */ - __getFloat32ArrayView(ptr: number): Float32Array; + __getFloat32ArrayView(ptr: number): Float32Array /** Gets a live view on a Float64Array's values in the module's memory. */ - __getFloat64ArrayView(ptr: number): Float64Array; + __getFloat64ArrayView(ptr: number): Float64Array /** Retains a reference to a managed object externally, making sure that it doesn't become collected prematurely. Returns the pointer. */ - __retain(ptr: number): number; + __retain(ptr: number): number /** Releases a previously retained reference to a managed object, allowing the runtime to collect it once its reference count reaches zero. */ - __release(ptr: number): void; + __release(ptr: number): void /** Forcefully resets the heap to its initial offset, effectively clearing dynamic memory. Stub runtime only. */ - __reset?(): void; + __reset?(): void /** Allocates an instance of the class represented by the specified id. */ - __alloc(size: number, id: number): number; + __alloc(size: number, id: number): number /** Tests whether a managed object is an instance of the class represented by the specified base id. */ - __instanceof(ptr: number, baseId: number): boolean; + __instanceof(ptr: number, baseId: number): boolean /** Forces a cycle collection. Only relevant if objects potentially forming reference cycles are used. */ - __collect(): void; + __collect(): void } /** Asynchronously instantiates an AssemblyScript module from anything that can be instantiated. */ export declare function instantiate( source: WebAssembly.Module | BufferSource | Response | PromiseLike, - imports?: ImportsObject -): Promise; + imports?: Imports +): Promise /** Synchronously instantiates an AssemblyScript module from a WebAssembly.Module or binary buffer. */ export declare function instantiateSync( source: WebAssembly.Module | BufferSource, - imports?: ImportsObject -): ResultObject & { exports: ASUtil & T }; + imports?: Imports +): ResultObject & { exports: ASUtil & T } /** Asynchronously instantiates an AssemblyScript module from a response, i.e. as obtained by `fetch`. */ export declare function instantiateStreaming( source: Response | PromiseLike, - imports?: ImportsObject -): Promise; + imports?: Imports +): Promise /** Demangles an AssemblyScript module's exports to a friendly object structure. */ -export declare function demangle(exports: {}, extendedExports?: {}): T; +export declare function demangle(exports: {}, extendedExports?: {}): T From 754caebf419a612c0bf9a89d7ca753cb6cdbcd6b Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 16 Mar 2020 19:08:01 +0200 Subject: [PATCH 2/3] revert semicolons --- lib/loader/index.d.ts | 90 +++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/lib/loader/index.d.ts b/lib/loader/index.d.ts index 98477b405b..9d3b3f069f 100644 --- a/lib/loader/index.d.ts +++ b/lib/loader/index.d.ts @@ -1,11 +1,11 @@ /// interface ResultObject { - module: WebAssembly.Module - instance: WebAssembly.Instance + module: WebAssembly.Module; + instance: WebAssembly.Instance; } -type ImportValue = Function | WebAssembly.Global | WebAssembly.Memory | WebAssembly.Table | number +type ImportValue = Function | WebAssembly.Global | WebAssembly.Memory | WebAssembly.Table | number; /** WebAssembly imports with two levels of nesting. */ interface Imports extends Record> { @@ -15,107 +15,107 @@ interface Imports extends Record> { seed?: Function, abort?(msg: number, file: number, line: number, column: number): void, trace?(msg: number, numArgs?: number, ...args: number[]): void - } + }; } /** Utility mixed in by the loader. */ interface ASUtil { - memory?: WebAssembly.Memory - table?: WebAssembly.Table + memory?: WebAssembly.Memory; + table?: WebAssembly.Table; /** Explicit start function, if requested. */ - _start(): void + _start(): void; /** Allocates a new string in the module's memory and returns a reference (pointer) to it. */ - __allocString(str: string): number + __allocString(str: string): number; /** Allocates a new array in the module's memory and returns a reference (pointer) to it. */ - __allocArray(id: number, values: ArrayLike): number + __allocArray(id: number, values: ArrayLike): number; /** Copies a string's value from the module's memory. */ - __getString(ptr: number): string + __getString(ptr: number): string; /** Copies an ArrayBuffer's value from the module's memory. */ - __getArrayBuffer(ptr: number): ArrayBuffer + __getArrayBuffer(ptr: number): ArrayBuffer; /** Copies an array's values from the module's memory. Infers the array type from RTTI. */ - __getArray(ptr: number): number[] + __getArray(ptr: number): number[]; /** Copies an Int8Array's values from the module's memory. */ - __getInt8Array(ptr: number): Int8Array + __getInt8Array(ptr: number): Int8Array; /** Copies an Uint8Array's values from the module's memory. */ - __getUint8Array(ptr: number): Uint8Array + __getUint8Array(ptr: number): Uint8Array; /** Copies an Uint8ClampedArray's values from the module's memory. */ - __getUint8ClampedArray(ptr: number): Uint8ClampedArray + __getUint8ClampedArray(ptr: number): Uint8ClampedArray; /** Copies an Int16Array's values from the module's memory. */ - __getInt16Array(ptr: number): Int16Array + __getInt16Array(ptr: number): Int16Array; /** Copies an Uint16Array's values from the module's memory. */ - __getUint16Array(ptr: number): Uint16Array + __getUint16Array(ptr: number): Uint16Array; /** Copies an Int32Array's values from the module's memory. */ - __getInt32Array(ptr: number): Int32Array + __getInt32Array(ptr: number): Int32Array; /** Copies an Uint32Array's values from the module's memory. */ - __getUint32Array(ptr: number): Uint32Array + __getUint32Array(ptr: number): Uint32Array; /** Copies an Int32Array's values from the module's memory. */ - __getInt64Array?(ptr: number): BigInt64Array + __getInt64Array?(ptr: number): BigInt64Array; /** Copies an Uint32Array's values from the module's memory. */ - __getUint64Array?(ptr: number): BigUint64Array + __getUint64Array?(ptr: number): BigUint64Array; /** Copies a Float32Array's values from the module's memory. */ - __getFloat32Array(ptr: number): Float32Array + __getFloat32Array(ptr: number): Float32Array; /** Copies a Float64Array's values from the module's memory. */ - __getFloat64Array(ptr: number): Float64Array + __getFloat64Array(ptr: number): Float64Array; /** Gets a live view on an array's values in the module's memory. Infers the array type from RTTI. */ - __getArrayView(ptr: number): ArrayBufferView + __getArrayView(ptr: number): ArrayBufferView; /** Gets a live view on an Int8Array's values in the module's memory. */ - __getInt8ArrayView(ptr: number): Int8Array + __getInt8ArrayView(ptr: number): Int8Array; /** Gets a live view on an Uint8Array's values in the module's memory. */ - __getUint8ArrayView(ptr: number): Uint8Array + __getUint8ArrayView(ptr: number): Uint8Array; /** Gets a live view on an Uint8ClampedArray's values in the module's memory. */ - __getUint8ClampedArrayView(ptr: number): Uint8ClampedArray + __getUint8ClampedArrayView(ptr: number): Uint8ClampedArray; /** Gets a live view on an Int16Array's values in the module's memory. */ - __getInt16ArrayView(ptr: number): Int16Array + __getInt16ArrayView(ptr: number): Int16Array; /** Gets a live view on an Uint16Array's values in the module's memory. */ - __getUint16ArrayView(ptr: number): Uint16Array + __getUint16ArrayView(ptr: number): Uint16Array; /** Gets a live view on an Int32Array's values in the module's memory. */ - __getInt32ArrayView(ptr: number): Int32Array + __getInt32ArrayView(ptr: number): Int32Array; /** Gets a live view on an Uint32Array's values in the module's memory. */ - __getUint32ArrayView(ptr: number): Uint32Array + __getUint32ArrayView(ptr: number): Uint32Array; /** Gets a live view on an Int32Array's values in the module's memory. */ - __getInt64ArrayView?(ptr: number): BigInt64Array + __getInt64ArrayView?(ptr: number): BigInt64Array; /** Gets a live view on an Uint32Array's values in the module's memory. */ - __getUint64ArrayView?(ptr: number): BigUint64Array + __getUint64ArrayView?(ptr: number): BigUint64Array; /** Gets a live view on a Float32Array's values in the module's memory. */ - __getFloat32ArrayView(ptr: number): Float32Array + __getFloat32ArrayView(ptr: number): Float32Array; /** Gets a live view on a Float64Array's values in the module's memory. */ - __getFloat64ArrayView(ptr: number): Float64Array + __getFloat64ArrayView(ptr: number): Float64Array; /** Retains a reference to a managed object externally, making sure that it doesn't become collected prematurely. Returns the pointer. */ - __retain(ptr: number): number + __retain(ptr: number): number; /** Releases a previously retained reference to a managed object, allowing the runtime to collect it once its reference count reaches zero. */ - __release(ptr: number): void + __release(ptr: number): void; /** Forcefully resets the heap to its initial offset, effectively clearing dynamic memory. Stub runtime only. */ - __reset?(): void + __reset?(): void; /** Allocates an instance of the class represented by the specified id. */ - __alloc(size: number, id: number): number + __alloc(size: number, id: number): number; /** Tests whether a managed object is an instance of the class represented by the specified base id. */ - __instanceof(ptr: number, baseId: number): boolean + __instanceof(ptr: number, baseId: number): boolean; /** Forces a cycle collection. Only relevant if objects potentially forming reference cycles are used. */ - __collect(): void + __collect(): void; } /** Asynchronously instantiates an AssemblyScript module from anything that can be instantiated. */ export declare function instantiate( source: WebAssembly.Module | BufferSource | Response | PromiseLike, imports?: Imports -): Promise +): Promise; /** Synchronously instantiates an AssemblyScript module from a WebAssembly.Module or binary buffer. */ export declare function instantiateSync( source: WebAssembly.Module | BufferSource, imports?: Imports -): ResultObject & { exports: ASUtil & T } +): ResultObject & { exports: ASUtil & T }; /** Asynchronously instantiates an AssemblyScript module from a response, i.e. as obtained by `fetch`. */ export declare function instantiateStreaming( source: Response | PromiseLike, imports?: Imports -): Promise +): Promise; /** Demangles an AssemblyScript module's exports to a friendly object structure. */ -export declare function demangle(exports: {}, extendedExports?: {}): T +export declare function demangle(exports: {}, extendedExports?: {}): T; From 0c86b6abb5c95c99875c89438d6e4b8c9cd95bdc Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 16 Mar 2020 19:11:34 +0200 Subject: [PATCH 3/3] update according comments --- lib/loader/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/loader/index.d.ts b/lib/loader/index.d.ts index 9d3b3f069f..b57bd39189 100644 --- a/lib/loader/index.d.ts +++ b/lib/loader/index.d.ts @@ -1,6 +1,6 @@ /// -interface ResultObject { +export interface ResultObject { module: WebAssembly.Module; instance: WebAssembly.Instance; } @@ -8,18 +8,18 @@ interface ResultObject { type ImportValue = Function | WebAssembly.Global | WebAssembly.Memory | WebAssembly.Table | number; /** WebAssembly imports with two levels of nesting. */ -interface Imports extends Record> { +export interface Imports extends Record> { env?: { memory?: WebAssembly.Memory, table?: WebAssembly.Table, - seed?: Function, + seed?: () => number, abort?(msg: number, file: number, line: number, column: number): void, trace?(msg: number, numArgs?: number, ...args: number[]): void }; } /** Utility mixed in by the loader. */ -interface ASUtil { +export interface ASUtil { memory?: WebAssembly.Memory; table?: WebAssembly.Table;