Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 15 additions & 9 deletions types/emscripten/emscripten-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ function ModuleTest(): void {
Module.logReadFiles = false;
Module.filePackagePrefixURL = "http://www.example.org/";
Module.preinitializedWebGLContext = new WebGLRenderingContext();
Module.onAbort = what => console.log("abort");
Module.onAbort = (what) => console.log("abort");
Module.onRuntimeInitialized = () => console.log("init");

const package: ArrayBuffer = Module.getPreloadedPackage("package-name", 100);
const exports: Emscripten.WebAssemblyExports = Module.instantiateWasm(
[{ name: "func-name", kind: "function" }],
(module: WebAssembly.Module) => {},
const exports: WebAssembly.Exports | undefined = Module.instantiateWasm(
{ a: { n: function __syscall_chmod() {} } },
(module: WebAssembly.Instance) => {},
);
const memFile: string = Module.locateFile("file.mem", "http://www.example.org/");
Module.onCustomMessage(new MessageEvent("TestType"));

Module.print = text => alert("stdout: " + text);
Module.print = (text) => alert("stdout: " + text);

const int_sqrt_number = Module.cwrap("int_sqrt", "number", ["number"]);
const int_sqrt_null = Module.cwrap("int_sqrt", null, ["number"]);
Expand All @@ -58,8 +58,8 @@ function ModuleTest(): void {
function FSTest(): void {
FS.init(
() => null,
_ => null,
_ => null,
(_) => null,
(_) => null,
);
FS.init(null, null, null);

Expand All @@ -70,13 +70,13 @@ function FSTest(): void {
FS.mkdir("/data");
FS.mount(IDBFS, {}, "/data");

FS.syncfs(true, err => {
FS.syncfs(true, (err) => {
// handle callback
});
}

function myAppShutdown() {
FS.syncfs(err => {
FS.syncfs((err) => {
// handle callback
});
}
Expand Down Expand Up @@ -117,6 +117,12 @@ function FSTest(): void {
FS.createDataFile("/", "dummy2", data, true, true, true);

const lookup = FS.lookupPath("path", { parent: true });
// $ExpectType number
lookup.node.mode;

const analyze = FS.analyzePath("path");
// $ExpectType boolean
analyze.exists;
}

/// String conversions
Expand Down
53 changes: 27 additions & 26 deletions types/emscripten/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ declare namespace Emscripten {
type CPointerType = "i8*" | "i16*" | "i32*" | "i64*" | "float*" | "double*" | "*";
type CType = CIntType | CFloatType | CPointerType;

type WebAssemblyImports = Array<{
name: string;
kind: string;
}>;

type WebAssemblyExports = Array<{
module: string;
name: string;
kind: string;
}>;

interface CCallOpts {
async?: boolean | undefined;
}
Expand All @@ -51,9 +40,9 @@ interface EmscriptenModule {
destroy(object: object): void;
getPreloadedPackage(remotePackageName: string, remotePackageSize: number): ArrayBuffer;
instantiateWasm(
imports: Emscripten.WebAssemblyImports,
successCallback: (module: WebAssembly.Module) => void,
): Emscripten.WebAssemblyExports;
imports: WebAssembly.Imports,
successCallback: (module: WebAssembly.Instance) => void,
): WebAssembly.Exports | undefined;
locateFile(url: string, scriptDirectory: string): string;
onCustomMessage(event: MessageEvent): void;

Expand Down Expand Up @@ -114,9 +103,27 @@ declare namespace FS {
node: FSNode;
}

interface Analyze {
isRoot: boolean;
exists: boolean;
error: Error;
name: string;
path: Lookup["path"];
object: Lookup["node"];
parentExists: boolean;
parentPath: Lookup["path"];
parentObject: Lookup["node"];
}

interface FSStream {}
interface FSNode {}
interface ErrnoError {}
interface FSNode {
mode: number;
}

class ErrnoError extends Error {
name: "ErronoError";
errno: number;
}

let ignorePermissions: boolean;
let trackingDelegate: any;
Expand All @@ -128,6 +135,7 @@ declare namespace FS {
//
function lookupPath(path: string, opts: any): Lookup;
function getPath(node: FSNode): string;
function analyzePath(path: string, dontResolveLastLink?: boolean): Analyze;

//
// nodes
Expand Down Expand Up @@ -263,8 +271,7 @@ type ArgsToType<T extends Array<Emscripten.JSType | null>> = Extract<
any[]
>;

type ReturnToType<R extends Emscripten.JSType | null> = R extends null ? null
: StringToType<Exclude<R, null>>;
type ReturnToType<R extends Emscripten.JSType | null> = R extends null ? null : StringToType<Exclude<R, null>>;

// Below runtime function/variable declarations are exportable by
// -s EXTRA_EXPORTED_RUNTIME_METHODS. You can extend or merge
Expand All @@ -280,20 +287,14 @@ type ReturnToType<R extends Emscripten.JSType | null> = R extends null ? null
//
// See: https://emscripten.org/docs/getting_started/FAQ.html#why-do-i-get-typeerror-module-something-is-not-a-function

declare function cwrap<
I extends Array<Emscripten.JSType | null> | [],
R extends Emscripten.JSType | null,
>(
declare function cwrap<I extends Array<Emscripten.JSType | null> | [], R extends Emscripten.JSType | null>(
ident: string,
returnType: R,
argTypes: I,
opts?: Emscripten.CCallOpts,
): (...arg: ArgsToType<I>) => ReturnToType<R>;

declare function ccall<
I extends Array<Emscripten.JSType | null> | [],
R extends Emscripten.JSType | null,
>(
declare function ccall<I extends Array<Emscripten.JSType | null> | [], R extends Emscripten.JSType | null>(
ident: string,
returnType: R,
argTypes: I,
Expand Down
2 changes: 2 additions & 0 deletions types/emscripten/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"projects": [
"https://emscripten.org"
],
"nonNpm": "conflict",
"nonNpmDescription": "Unrelated to the abandoned npm package of the same name",
"devDependencies": {
"@types/emscripten": "workspace:."
},
Expand Down