facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.57k stars 612 forks source link

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

Open n9lsjr opened 3 weeks ago

n9lsjr commented 3 weeks ago

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?

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

avp commented 3 weeks ago

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:

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

n9lsjr commented 3 weeks ago

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

n9lsjr commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

Ok interesting! Thanks for the help 👍

n9lsjr commented 1 week ago

Any update on this?