Comments (5)
I hear the the frustration of wanting to use Javy in a browser environment out of the box and to able to use it in a similar capacity to Emscripten. I understand how convenient it would be.
To provide some context on why this is not currently feasible in Javy, we want to make it easy to run Wasm modules produced by Javy in a wide variety of WebAssembly runtimes including in a number of non-JavaScript environments outside the browser (for example, Wasmtime, Wazero, among others). To do that, we try to ensure Javy modules only import functions that are defined as part of WASI preview1 because host implementations for these functions are available for a wide variety of WebAssembly runtimes. Requiring host runtimes to implement additional Javy-specific functions to run Javy modules means that modules produced by Javy could not run in the same wide variety of host environments. To give you a concrete example, it's not currently possible to run WebAssembly modules compiled by Emscripten on Wasmtime because modules generated by Emscripten import Emscripten-specific functions that are not defined in Wasmtime. Unfortunately supporting a number of Web APIs would require the use of imported functions that are not defined as part of WASI preview1. For example, there isn't currently an API available in WASI preview1 to create a network request. So trying to add support for fetch
would mean Javy modules would require the host runtime to implement a non-standard function to be able to successfully instantiate. And that would mean that Javy modules would only be runnable on a much smaller set of Wasm runtimes than is the case today.
We are exploring options for improving Javy's extensibility as well as keeping an eye on ongoing work with the Wasm Component Model and WASI preview2 which may make supporting additional Web APIs more feasible in the future.
from javy.
Somehow related to this topic, I have released a JS-Runtime based on quickjs-wasm-rs. While it does not encompass the entire Minimum Common Web Platform API proposal, it does include the implementation of the Fetch API.
https://github.com/gc-victor/js-wasm-workers-runtime
https://common-min-api.proposal.wintercg.org/
from javy.
@jeffcharles I have a question. I am assuming this tool just embeds a js engine and makes it run our js code. So js code isn't really converted to anything else and remain as it is? I mean if it only embeds a js engine and makes it run our js code, js code can be extracted easily.
Or is the js code actually converted into bytecode?
Not related to this, but in the past week, I actually ended up making a system on top of assemblyscript for accessing every web API from the wasm side. Its not yet public though. Below is a screenshot of its syntax.
from javy.
I am assuming this tool just embeds a js engine and makes it run our js code. So js code isn't really converted to anything else and remain as it is?
We compile the JS source code to QuickJS bytecode as part of the javy compile ...
invocation and the QuickJS bytecode is stored in one or more data segments in the Wasm module that's produced.
I mean if it only embeds a js engine and makes it run our js code, js code can be extracted easily.
Agreed. We have a dynamic linking mode that can be activated with the -d
flag when using javy compile
and that creates a Wasm module that just contains the QuickJS bytecode and a small number of instructions to invoke functions in a different Wasm module to drive the interpreter. The interpreter Wasm module can be obtained by running javy emit-provider ...
.
from javy.
I'm going to close this for now as we're not planning on adding Web API support to this project for the time being. I suggest using the quickjs-wasm-rs
crate directly. It's what Javy uses to execute JS source code in a Rust application that's been compiled to Wasm. You can use the eval_global
and wrap_callback
functions on Context
to add the APIs you would like into the context that the JS code is evaluated inside.
from javy.
Related Issues (20)
- Avenues for rich host functions HOT 7
- Feature Request: Ability to Change Brotli Compression Level via CLI HOT 3
- Stop using cargo-wasi
- Support a WASI reactor target HOT 3
- Where can a dynamically linked WASM run? HOT 3
- Can javy receive command line args / env. Are they in scope? HOT 10
- Can't build javy main branch on Ubuntu 23.10 HOT 10
- imports HOT 6
- Imported functionallity from the host HOT 2
- Expose Rust structs to JavaScript as classes HOT 8
- [quickjs-wasm-sys] `JS_DupValue` is missing HOT 3
- [quickjs-wasm-rs] Should the closure passed to `wrap_callback` return `JSValueRef`? HOT 3
- Urgent help required : How to debug this ? Getting error at some line no in function.mjs HOT 6
- How to use Javy with asynchronous JavaScript code? (experimental_event_loop) HOT 5
- Errors in async top-level functions do not result in traps HOT 1
- Allow specifying which file descriptor is used in console.{log,err} from the CLI HOT 2
- accessing arguments.callee leads to TypeError: invalid property access HOT 2
- Serialize function / callbacks with enclosing context; HOT 4
- Example running using Node.js as a host HOT 13
- Implement Cancellable or interruptible setTimeout in javy HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javy.