Skip to content

fix semicolon after interface + improve import object definition #1175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/loader/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
/// <reference lib="esnext.bigint" />

interface ResultObject {
module: WebAssembly.Module,
instance: WebAssembly.Instance
};
export interface ResultObject {
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<string, any> {
export interface Imports extends Record<string, Record<string, ImportValue>> {
env?: {
memory?: WebAssembly.Memory,
table?: WebAssembly.Table,
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;

Expand Down Expand Up @@ -99,19 +102,19 @@ interface ASUtil {
/** Asynchronously instantiates an AssemblyScript module from anything that can be instantiated. */
export declare function instantiate<T extends {}>(
source: WebAssembly.Module | BufferSource | Response | PromiseLike<WebAssembly.Module | BufferSource | Response>,
imports?: ImportsObject
imports?: Imports
): Promise<ResultObject & { exports: ASUtil & T }>;

/** Synchronously instantiates an AssemblyScript module from a WebAssembly.Module or binary buffer. */
export declare function instantiateSync<T extends {}>(
source: WebAssembly.Module | BufferSource,
imports?: ImportsObject
imports?: Imports
): ResultObject & { exports: ASUtil & T };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related to this PR, but according to MDN there's also a slight variance here: If a WebAssembly.Module is provided, this API returns just a WebAssembly.Instance, otherwise a ResultObject.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this. but if you see this is reasonable we could do thus in separate pr


/** Asynchronously instantiates an AssemblyScript module from a response, i.e. as obtained by `fetch`. */
export declare function instantiateStreaming<T extends {}>(
source: Response | PromiseLike<Response>,
imports?: ImportsObject
imports?: Imports
): Promise<ResultObject & { exports: ASUtil & T }>;

/** Demangles an AssemblyScript module's exports to a friendly object structure. */
Expand Down