Comments (7)
This is allowed already although itβs not documented. Emscripten modules can have their WASM module overridden. You can try doing so by reading over our code in variants.ts and trying to see where you could inject the WASM module you import in your own code via import
.
from quickjs-emscripten.
There are a few more issues to cloudflare workers to this that I've found following this
First you need to replace a ton of { credentials: "xxx" }
fetch objects with {}
because fetch does not support that in it's implementation on workers.
You also need to do some global
and self
overriding because self.href
does not exist.
Here is my code so far:
import { newQuickJSAsyncWASMModule } from 'quickjs-emscripten'
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
(global as any).window = self as any;
(self as any).location = { href: "/" } as any;
const m = await newQuickJSAsyncWASMModule()
const vm = m.newContext()
const world = vm.newString("world")
vm.setProp(vm.global, "NAME", world)
world.dispose()
let res
const result = vm.evalCode(`"Hello " + NAME + "!"`)
if (result.error) {
console.log("Execution failed:", vm.dump(result.error))
result.error.dispose()
} else {
res = vm.dump(result.value)
console.log("Success:", res)
result.value.dispose()
}
vm.dispose()
return new Response("Hello World!");
},
};
Making a request to this leaves with a massive b64 dump ending like:
FABBz6wECxUXAAAAABcAAAAACRQAAAAAABQAABQAQf2sBAsBFgBBia0ECycVAAAAABUAAAAACRYAAAAAABYAABYAADAxMjM0NTY3ODlBQkNERUYAQdStBAsBCQBB/K0ECwj//////////wBBxK4ECx0DAAAAAAAAAAIAAAAAAAAAAQAAAAEAAAABAAAABQBB7K4ECwJ2AQBBhK8ECwt3AQAAeAEAAJgcAQBBnK8ECwECAEGsrwQLCP//////////AEHwrwQLCWAXAQAAAAAABQBBhLAECwJ5AQBBnLAECw53AQAAegEAAKgcAQAABABBtLAECwEBAEHEsAQLBf////8KAEGIsQQLB/gXAQCgIlE=";if(!V.startsWith(U)){var
xa=V;V=a.locateFile?a.locateFile(xa,v):v+xa}function ya(){var b=V;try{if(b==V&&H)return new
Uint8Array(H);var c=D(b);if(c)return c;if(y)return y(b);throw"both async and sync fetching of
the wasm failed";}catch(d){G(d)}}
^
at G
(/Users/dangoodman/code/test-quickjs-worker/node_modules/quickjs-emscripten/ts/generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js:21:71)
at
(/Users/dangoodman/code/test-quickjs-worker/node_modules/quickjs-emscripten/ts/generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js:36:414)
β [ERROR] Uncaught (in response) CompileError: Aborted(CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder). Build with -s ASSERTIONS=1 for more info.
Possibly newQuickJSAsyncWASMModule()
is not the correct one I was supposed to use from the variants.ts
file?
from quickjs-emscripten.
I have also noticed there is a significant delay in request processing before this error throws, maybe about a second
from quickjs-emscripten.
Thanks Jake, I'll look into that.
Dan, I think the fetch code won't be used when the module is loaded via an import
from quickjs-emscripten.
@Hades32 @danthegoodman1 I think the changes in 0.25.0 should make it much easier to get quickjs-emscripten in Cloudflare Workers.
from quickjs-emscripten.
I tried it out, and there's a bunch of challenges.
from quickjs-emscripten.
I just release v0.26.0, which supports Cloudflare Workers with some setup. See the instructions here: https://github.com/justjake/quickjs-emscripten#webassembly-loading
from quickjs-emscripten.
Related Issues (20)
- How does WebAssembly play a role in this project? HOT 2
- Execute exported function? HOT 6
- utility functions to convert plain object/array to vm.newObject or vm.newArray? HOT 2
- ASYNCIFY_STACK_SIZE seems a little low HOT 1
- Is there a way to limit the standard library/built-in functions? HOT 4
- Can we get a more stripped down npm package? HOT 8
- Resolving a promise with an object creates undisposable references HOT 4
- Evaluating a module (any code that uses import) always returns undefined HOT 6
- Module "fs", "path", and "crypto" have been externalized for browser compatibility HOT 2
- Tests fail on s390x machines HOT 5
- Proxy log receiver blocking error HOT 1
- Async Regression "TypeError: Object not disposable" in v0.26.0 HOT 4
- wish to add a new api (QuickJSHandle.keepAlive) HOT 2
- evalCodeAsync running in module mode throws `proxy: cannot set property` error HOT 1
- Feature Request: Interrupt handler (or equivalent) for contexts (not just runtimes) HOT 5
- Latest release does not include browser fix HOT 1
- Question: how to inject setInterval? HOT 4
- Bundle size too big because of debug HOT 3
- QuickJSContext had no callback with id error when newFunction was called many times HOT 4
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 quickjs-emscripten.