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

Problems loading emscripten compiled js file in Hermes. Works on JSC/V8. #1456

Open
n9lsjr opened this issue Jul 9, 2024 · 7 comments
Open
Labels
bug Something isn't working

Comments

@n9lsjr
Copy link

n9lsjr commented Jul 9, 2024

Bug Description

I've been trying to load an emscripten compiled file with hermes with no success.
First I thought it was the minification of the emscripten flags present but it's still the same result even with all minifications turned off.
The code works (minfied) on both V8 and JSC engine. Can you give me any hints on what could be changed to make it work and what is the core difference between Hermes and the others engines?

  • [ x] I have run gradle clean and confirmed this bug does not occur with JSC
  • [ x] The issue is reproducible with the latest version of React Native.

Using the latest(?) version of hermes with

React Native version: 0.73.4
OS: Any
Platform: IOS/ANDROID

Steps To Reproduce

If you want to test it this is the file i'm trying to load.
https://github.com/kryptokrona/kryptokrona-crypto/blob/master/dist/turtlecoin-crypto.js (non-minified)

image

  1. The output should be an object with functions.
  2. Hermes can't find functions. ( with non-minified js)
    image

code example:

The Expected Behavior

image

@n9lsjr n9lsjr added the bug Something isn't working label Jul 9, 2024
@avp
Copy link
Contributor

avp commented Jul 9, 2024

Thanks for the report. It's difficult to tell completely without a minimal test case that we can run with the hermes command line tool that demonstrates differences between Hermes and the other engines.

A couple starting points:

  • Hermes doesn't support ES6 classes (we're working on it right now), so if you're able to actually run this JS file, it's being lowered/transformed in some way - we should directly investigate that file, the real input to Hermes.
  • The other engines have native WASM support, which Hermes doesn't at the moment (ordinarily people can just ship native code directly). The linked JS file appears to have some detection of this and it appears to change behavior, so it's worth looking into.

If you're able to find a more focused minimal reproduction, I think that'd really help make more progress.

@n9lsjr
Copy link
Author

n9lsjr commented Jul 9, 2024

Thanks for the quick reply and the detailed response, King.👑 I will try to investigate this further. 👍

@n9lsjr
Copy link
Author

n9lsjr commented Jul 11, 2024

I have scanned a few other discussions and issues about WASM support and what I can tell is that "asm.js" files should work in hermes?
So I think you were right about the WASM support. The JS file i provided is compiled with a newer emscripten which does not output asm.js.

The other file i was talking about (which does work on v8/jsc) compiled with "fastcomp" should output asm.js but this file does not work either. Could the optimizations and minification be a problem here?

https://github.com/kryptokrona/kryptokrona-crypto/blob/276cb2438b8ae619eaf275a713b1d3592a018149/dist/turtlecoin-crypto.js

const test = require('turtlecoin-crypto.js')

Does not give any output.

@avp
Copy link
Contributor

avp commented Jul 11, 2024

Found (one) difference in behavior upon modifying the code to call the result of the module.

Hermes throws a TypeError if you try to access .stack on a non-Error, and the code you've linked creates an object obj which has its .__proto__ set to a constructed Error. When you try to access obj.stack, we use a getter on the .stack property of the Error to construct the string for the stack trace. Hermes then throws because the this value passed to the getter isn't an Error, while V8 (e.g.) walks the prototype chain to find the JSError.

We'll look into possible solutions.

@n9lsjr
Copy link
Author

n9lsjr commented Jul 12, 2024

Ok interesting! Thanks for the help 👍

@n9lsjr
Copy link
Author

n9lsjr commented Jul 28, 2024

Any update on this?

@n9lsjr
Copy link
Author

n9lsjr commented Oct 8, 2024

There seem to be some commits regarding the prototype chain issue in RN 0.76. Can you make another one of your tests to see any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants