Kudo / react-native-v8

Opt-in V8 runtime for React Native Android
MIT License
917 stars 69 forks source link

WebAssembly doesn't work #89

Closed jzxchiang1 closed 2 years ago

jzxchiang1 commented 2 years ago

I've tried this on an Android Pixel 3 emulator with:

RN v0.64.1, v8-android-jit v9.88.0 (V8 v8.x) RN v0.65.1, v8-android-jit v9.93.0 (V8 v9.x)

The result is the same: await WebAssembly.compile(...) and await WebAssembly.instantiate(...) hang forever and never complete. Funny enough, WebAssembly.validate(...) (which is not async) completes just fine.

To reproduce this, try running this in your top-level index.js file:

import {decode} from 'base64-arraybuffer';
const base64 = 
'AGFzbQEAAAABBgFgAX8BfwMCAQAEBQFwAQEBBQMBABEHEQIGbWVtb3J5AgAEYWRkMQAACgkBBwAgAEEBagsACwdsaW5raW5nAwEAAA4EbmFtZQEHAQAEYWRkMQ==';
const bytes = decode(base64);
global.WebAssembly.compile(bytes).then(() => console.log('compiled'));

This is a very short wasm program (only 2 instructions). You'll notice that "compiled" never gets printed.


I've raised this issue with the chromium V8 team, and they think it's a problem with the embedder, this piece of C++ in the react-native-v8 codebase.

I'm wondering if you've seen this issue, whether you can reproduce it, and what you think is the cause of this. Thank you!

jzxchiang1 commented 2 years ago

The latest update is that we might need to "pump the message loop".

See the following links for context:

https://bugs.chromium.org/p/v8/issues/detail?id=12318&q=component%3AWebAssembly&can=1 https://groups.google.com/g/v8-users/c/lRe7WrCkHCE

jzxchiang1 commented 2 years ago

Do these commits fix the issue?

Would you like me to help test? Thanks.

jzxchiang1 commented 2 years ago

This is awesome, thank you. I tested it in 0.65 and it works.