-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Investigate Alternative JS Engine #6
Comments
With v0.4.0 of KaTeX, we start to abstract the JS engine behind a common trait. Help is needed to add more JS engine backend in addition to the QuickJS. |
@xu-cheng, from the candidates you described, it doesn't seem like there's a good option as an alternative in the near future, right? The wasm issue also mentions https://github.com/theduke/slimjs, but that seems more like an experiment than anything with a future. I was looking at incorporating your crate (chipsenkbeil/vimwiki-rs#109) to support server-side rendering alternative to MathJax. I've also got |
Just as I mentioned above, my thought is to provide multiple JS backends in this crate. Therefore, the users can choose the suitable backend to their needs by assigning the corresponding feature to this crate. I am planning to add two new backends for now: rusty_v8 and wasm-binding (i.e., using the JS from the browser directly). But I don't have too much free time for now. So PR is welcome. Also, it is worth mentioning that the common JS engine trait is not fixed and can be changed when we add new JS backend. In long term, I hope we can add boa and slimjs support. |
@xu-cheng, I wonder if it's possible to embed wasmer into this crate and use it to load a QuickJS wasm file. In wasmer readme's quickstart, it specifically shows loading a QuickJS wasm file and using it via the cli. If you can load that, wondering if that would get around the need for quickjs-rs support for a WASM target. I haven't read much into wasmer myself. |
This seems like a very viable option, considering |
The prebuilt quickjs module is a WASM version of the quickjs CLI, so not particularly useful. Would https://duktape.org/ be worth looking into? EDIT: I doubt duktape would work, seems to support only a tiny subset of ES6 |
QuickJS on |
Hi, sorry for the late response. Unfortunately, there are multiple issues with quickjs wasm.
I still think the best (maintainable) approach is to add existing well maintained backends like v8 and wasm-bindings. And if someone can maintain a rust version of quickjs (like slimjs), it would solve all our problems. |
Agreed, the lack of maintenance isn't great. However, the source is available: https://github.com/saghul/wasi-lab/tree/master/qjs-wasi and while an untrusted binary isn't great, it is running in a sandboxed environment.
Yes, that's what I meant when I wrote that it doesn't fit the Engine-API well (and is probably very inefficient)
The problem with quickjs is the lack of Windows/MSVC support. There are forks with Windows/MSVC support, but the official version isn't viable for the main Rust on Windows platform. v8 is probably the only real option right now |
Might also be worth looking into rust-mozjs, the rust binding to spidermonkey. These binding also include an example of using it with a string for evaluating as a script. Since spidermonkey is a relatively well tested JS engine and has support for most OS's, this might a viable alternative. |
I have now released There are some unsolved issues.
|
Could deno be another possible candidate? |
@joseluis deno uses v8 as its js engine. PR is welcome to add v8 or other js engines support to this crate. |
It might be more desirable to AOT compile the JS. Their documentation is rather poor, though. |
Never mind, javy uses QuickJs under the hood. |
I don't think Hop supports Windows so it defeats the purpose… |
Is Webview a good idea? |
An alive webview library would instead be Wry used by Tauri. |
I think |
Does this change that quickjs only works in Linux? wry looks like a more attractive option, especially since it uses the "native" webview instead of embedding a gigantic engine (although I don't know if it works without a visible window) |
Wry won't work unless we make a big change… The webviews can only be spawned on the main thread. |
you could try rquickjs: |
@hhstore a PR is welcome. |
What does this solve? quickjs itself is an issue as outlined in the original post |
rquickjs solves the issue by applying to quickjs the patches that has yet to be accepted upstream. It requires that you have the patch binary (e.g. from msys2) in your path though. |
I am trying to implement the backend using It compiles successfully. However, it passes all the tests except
To whom might be interested in this implementation, any help would be appreciated. (*) I slightly modified the test |
fyi, quickjs_es_runtime can now also be used with quickjs-ng which is currently actively maintained. |
This crate requires an embedded JS engine to execute katex. Currently, this is done using quickjs and its rust binding. However, it has certain shortages:
As such, we may want to find an alternative JS engine. Since this crate never exposes the types from the underlying JS engine, changing it will not create any breaking changes. Ideally, the alternatives need supporting all the current used features, addressing the above problems, being small to be embedded, and being well maintained.
Some candidates:
The text was updated successfully, but these errors were encountered: