3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-01-05 02:28:45 +00:00

Add WebAssembly/TypeScript bindings (#5762)

* Add TypeScript bindings

* mark Z3_eval_smtlib2_string as async
This commit is contained in:
Kevin Gibbons 2022-01-09 17:16:38 -08:00 committed by GitHub
parent 9ac57fc510
commit 2b934b601d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 1722 additions and 33 deletions

View file

@ -0,0 +1,38 @@
// this wrapper works with async-fns to provide promise-based off-thread versions of some functions
let capability = null;
function resolve_async(val) {
// setTimeout is a workaround for https://github.com/emscripten-core/emscripten/issues/15900
if (capability == null) {
return;
}
let cap = capability;
capability = null;
setTimeout(() => {
cap.resolve(val);
}, 0);
}
function reject_async(val) {
if (capability == null) {
return;
}
let cap = capability;
capability = null;
setTimeout(() => {
cap.reject(val);
}, 0);
}
Module.async_call = function (f, ...args) {
if (capability !== null) {
throw new Error(`you can't execute multiple async functions at the same time; let the previous one finish first`);
}
let promise = new Promise((resolve, reject) => {
capability = { resolve, reject };
});
f(...args);
return promise;
};