Skip to content
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

J2v8 - Running Webassembly #590

Open
leandroZanatta opened this issue Feb 8, 2023 · 1 comment
Open

J2v8 - Running Webassembly #590

leandroZanatta opened this issue Feb 8, 2023 · 1 comment

Comments

@leandroZanatta
Copy link

leandroZanatta commented Feb 8, 2023

I need to run WebAssembly codes in J2V8.
Still no support?
If yes, node can I get an example in java?
If not, is there any way around it?

`
V8 v8 = V8.createV8Runtime();

JavaVoidCallback successCallback = new JavaVoidCallback() {
@OverRide
public void invoke(V8Object v8Object, V8Array v8Array) {
System.out.println("[SUCESS] " + v8Array);
}
};

JavaVoidCallback errorCallback = new JavaVoidCallback() {
@OverRide
public void invoke(V8Object v8Object, V8Array v8Array) {
System.out.println("[ERROR] " + v8Array);
}
};

v8.registerJavaMethod(successCallback, "onSuccess");
v8.registerJavaMethod(errorCallback, "onError");

v8.executeScript(String.format("%s; executeAssembly('%s').then(onSuccess).catch(onError);", jsCode, hash)))
`
Error: WebAssembly is undefined

@ostryhub
Copy link

Hello, a bit info:
I am also trying to get web assembly to work using this dependency 'com.eclipsesource.j2v8:j2v8:6.2.0@aar'.
This version does have WebAssembly defined and it successfully instantiates the webassembly instance (I am using a webpack generated umd package that needs custom XMLHttpRequest implementation that actually loads the wasm bytes into memory and returns them as Uint8Array to v8 runtime).

So using that j2v8 version that would solve the "Error: WebAssembly is undefined" problem mentioned above.
But thats not all one needs to get the WebAssembly working using j2v8.

After loading the wasm we are given a promise that when resolved gives us the loaded wasm module.
But in order to allow for the wasm compilation we need to keep pumping the v8 main loop (check this for details: https://groups.google.com/g/v8-users/c/lRe7WrCkHCE)

Now my question to j2v8 people is this:
Why is the V8 class's method V8.pumpMessageLoop() non public ?
When I try to force the call via reflection I do get this exception:

PumpRuntime() Error: java.lang.reflect.InvocationTargetException
PumpRuntime() CAUSE: java.lang.UnsupportedOperationException: pumpMessageLoop Not Supported.

Do you need to build the v8 in any particular way to support message loop pumping?

Any light shed on this would be greatly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants