Skip to content

New Asyncify #35

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

Open
wants to merge 2 commits into
base: wasm
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ run_emcc() {
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['cwrap']" \
--preload-file usr \
--preload-file tutor \
-s ASYNCIFY \
-s 'ASYNCIFY_IMPORTS=["vimwasm_wait_for_event","vimwasm_read_clipboard","vimwasm_eval_js"]' \
-s 'ASYNCIFY_STACK_SIZE=20480' \
$extraflags

if [[ "$RELEASE" != "" ]]; then
Expand Down
1 change: 1 addition & 0 deletions wasm/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
assert: 'readonly',
sinon: 'readonly',
IDBFS: 'readonly',
Asyncify: 'readonly',
__karma__: 'readonly',
},
parser: '@typescript-eslint/parser',
Expand Down
45 changes: 44 additions & 1 deletion wasm/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ interface StartMessageFromMain {
readonly kind: 'start';
readonly debug: boolean;
readonly perf: boolean;
readonly buffer: Int32Array;
readonly clipboard: boolean;
readonly canvasDomHeight: number;
readonly canvasDomWidth: number;
Expand All @@ -55,6 +54,50 @@ interface StartMessageFromMain {
readonly fetchFiles: { [fpath: string]: string };
readonly cmdArgs: string[];
}
interface ReadClipboardMessageFromMain {
readonly kind: 'read-clipboard:response';
readonly contents: ArrayBuffer | null; // UTF-8 clipboard contents
}
interface EvalFuncMessageFromMain {
readonly kind: 'evalfunc:response';
readonly success: boolean;
// UTF-8 encoded result of evaluation. On success, it represents returned value
// from the function. Otherwise, it represents an error message.
readonly result: ArrayBuffer;
}

type MessageFromMain =
| StartMessageFromMain
| ReadClipboardMessageFromMain
| EvalFuncMessageFromMain
| {
readonly kind: 'key';
readonly key: string;
readonly keyCode: number;
readonly ctrl: boolean;
readonly shift: boolean;
readonly alt: boolean;
readonly meta: boolean;
}
| {
readonly kind: 'resize';
readonly width: number;
readonly height: number;
}
| {
readonly kind: 'open-file';
readonly filename: string;
readonly contents: ArrayBuffer; // UTF-8 file contents
}
| {
readonly kind: 'cmdline';
readonly cmdline: string;
}
| {
readonly kind: 'emsg';
readonly message: string;
};
type MessageKindFromMain = MessageFromMain['kind'];

interface CmdlineResultFromWorker {
readonly kind: 'cmdline:response';
Expand Down
9 changes: 1 addition & 8 deletions wasm/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* main.ts: TypeScript main thread runtime for Wasm port of Vim by @rhysd.
*/

import { VimWasm, checkBrowserCompatibility, VIM_VERSION } from './vimwasm.js';
import { VimWasm, VIM_VERSION } from './vimwasm.js';

declare global {
interface Window {
Expand Down Expand Up @@ -53,13 +53,6 @@ function fatal(err: string | Error): never {
throw err;
}

{
const compatMessage = checkBrowserCompatibility();
if (compatMessage !== undefined) {
fatal(compatMessage);
}
}

const screenCanvasElement = document.getElementById('vim-screen') as HTMLCanvasElement;
const workerScriptPath = feature === 'normal' ? './vim.js' : `./${feature}/vim.js`;
const vim = new VimWasm({
Expand Down
3 changes: 3 additions & 0 deletions wasm/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ declare const Module: {
_malloc(bytes: number): CharPtr;
_free(ptr: CharPtr): void;
};
declare const Asyncify: {
handleSleep<T = any>(callback: (wakeUp: (ret?: T) => void) => void): unknown;
};

declare const LibraryManager: any;
declare function UTF8ToString(ptr: CharPtr, maxBytesToRead?: number): string;
Expand Down
Loading