Skip to content

Commit

Permalink
[web] add types for WASM Module
Browse files Browse the repository at this point in the history
Summary:
Based on
- [Module API](https://emscripten.org/docs/api_reference/module.html)
- [TS definition](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/emscripten/index.d.ts)
- inspection of printed module
- [class definition](https://github.com/CommE2E/comm/blob/097020a6acb44f45b8ecd692b37c57a1ab32b2bf/native/cpp/CommonCpp/DatabaseManagers/CommQueryExecutor.h#L7)

Depends on D8544

Test Plan: `flow`

Reviewers: michal, tomek

Reviewed By: michal

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D8545
  • Loading branch information
xsanm committed Jul 21, 2023
1 parent e51b9f0 commit 97d89c0
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
7 changes: 7 additions & 0 deletions web/database/types/comm-query-executor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @flow

declare export class CommQueryExecutor {
static testDBOperation: () => string;
}

export type CommQueryExecutorType = typeof CommQueryExecutor;
70 changes: 70 additions & 0 deletions web/database/types/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// @flow

import type { CommQueryExecutorType } from './comm-query-executor.js';
import type { FS } from './file-system.js';

interface WebAssembly$Module {}

type Emscripten$EnvironmentType = 'WEB' | 'NODE' | 'SHELL' | 'WORKER';

type Emscripten$WebAssemblyImports = $ReadOnlyArray<{
+name: string,
+kind: string,
}>;

type Emscripten$WebAssemblyExports = $ReadOnlyArray<{
+module: string,
+name: string,
+kind: string,
}>;

declare export class EmscriptenModule {
print(str: string): void;
printErr(str: string): void;
arguments: string[];
environment: Emscripten$EnvironmentType;
preInit: () => void | $ReadOnlyArray<() => void>;
preRun: $ReadOnlyArray<() => void>;
postRun: () => void | $ReadOnlyArray<() => void>;
onAbort: {
(what: mixed): void,
};
onRuntimeInitialized: () => void;
preinitializedWebGLContext: WebGLRenderingContext;
noInitialRun: boolean;
noExitRuntime: boolean;
logReadFiles: boolean;
filePackagePrefixURL: string;
wasmBinary: ArrayBuffer;
destroy(object: { +[key: string]: mixed }): void;
getPreloadedPackage(
remotePackageName: string,
remotePackageSize: number,
): ArrayBuffer;
instantiateWasm(
imports: Emscripten$WebAssemblyImports,
successCallback: (module: WebAssembly$Module) => void,
): Emscripten$WebAssemblyExports;
locateFile(url: string, scriptDirectory?: string): string;
onCustomMessage(event: MessageEvent): void;
HEAP: Int32Array;
IHEAP: Int32Array;
FHEAP: Float64Array;
HEAP8: Int8Array;
HEAP16: Int16Array;
HEAP32: Int32Array;
HEAPU8: Uint8Array;
HEAPU16: Uint16Array;
HEAPU32: Uint32Array;
HEAPF32: Float32Array;
HEAPF64: Float64Array;
TOTAL_STACK: number;
TOTAL_MEMORY: number;
FAST_MEMORY: number;
_malloc(size: number): number;
_free(ptr: number): void;

FS: FS;

CommQueryExecutor: CommQueryExecutorType;
}

0 comments on commit 97d89c0

Please sign in to comment.