hermes icon indicating copy to clipboard operation
hermes copied to clipboard

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

Open n9lsjr opened this issue 1 year ago • 6 comments

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 avatar Jul 09 '24 20:07 n9lsjr

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.

avp avatar Jul 09 '24 22:07 avp

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

n9lsjr avatar Jul 09 '24 22:07 n9lsjr

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.

n9lsjr avatar Jul 11 '24 19:07 n9lsjr

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.

avp avatar Jul 11 '24 23:07 avp

Ok interesting! Thanks for the help 👍

n9lsjr avatar Jul 12 '24 13:07 n9lsjr

Any update on this?

n9lsjr avatar Jul 28 '24 19:07 n9lsjr

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?

n9lsjr avatar Oct 08 '24 23:10 n9lsjr