GithubHelp home page GithubHelp logo

Comments (9)

tmikov avatar tmikov commented on April 28, 2024

I am sorry, can you please provide a minimal reproduction of the problem using the Hermes CLI?

from hermes.

cs-robert avatar cs-robert commented on April 28, 2024

I am sorry, can you please provide a minimal reproduction of the problem using the Hermes CLI?

The same code executed directly by the hermes command on a mac is fine, but the results of a jsi call on android are not as expected
(modify /HermesTest/src/main/assets/test.js JsNativeLog(msg);=>print(msg); test.js can be executed directly with the hermes command)
图片

from hermes.

cs-robert avatar cs-robert commented on April 28, 2024

I am sorry, can you please provide a minimal reproduction of the problem using the Hermes CLI?

The logic of executing js is very simple, just inject a JsNativeLog method to print the log, and then execute test.js
all code is in https://github.com/cs-robert/hermesTest
`
Java_com_example_hermestest_MainActivity_evaluateJavaScript(JNIEnv *env, jclass clazz,
jstring script) {
try {
std::shared_ptrfacebook::hermes::HermesRuntime runtime = facebook::hermes::makeHermesRuntime();
runtime->global().setProperty(*runtime, "JsNativeLog", facebook::jsi::Function::createFromHostFunction(
*runtime,
facebook::jsi::PropNameID::forAscii(*runtime, "JsNativeLog"),
0,
[](facebook::jsi::Runtime &rt,
const facebook::jsi::Value &thisVal,
const facebook::jsi::Value *arguments,
size_t argumentCount) {
auto str = arguments[0].getString(rt).utf8(rt);
__android_log_print(ANDROID_LOG_INFO, "JsNativeLog", "JSLog %s", str.c_str());
return facebook::jsi::Value();
}));
const char *scriptChar = env->GetStringUTFChars(script, nullptr);
std::string source = std::string(scriptChar);
std::shared_ptr hbcPtr = std::make_uniquefacebook::jsi::StringBuffer(source);
runtime->evaluateJavaScript(hbcPtr, "test.js");
} catch (const facebook::jsi::JSError &error) {
__android_log_print(ANDROID_LOG_ERROR, "JsNativeLog", "%s %s", error.getMessage().c_str(), error.getStack().c_str());
} catch (const facebook::jsi::JSIException &err) {
__android_log_print(ANDROID_LOG_ERROR, "JsNativeLog", "%s", err.what());

} catch (const std::exception &ex) {
    __android_log_print(ANDROID_LOG_ERROR, "JsNativeLog", "%s", ex.what());

} catch (...) {

}

}
`

from hermes.

cs-robert avatar cs-robert commented on April 28, 2024

I am sorry, can you please provide a minimal reproduction of the problem using the Hermes CLI?

Strangely enough, when I delete some of the WebPack-generated code in the js file, it works fine.What I'm removing is a closure that won't execute and doesn't affect the logic。
my_engineGlobal, my_engineGlobal2, my_engineGlobal3, my_engineGlobal4... These variables are simply defined and printed in a method without any logic to modify them

from hermes.

cs-robert avatar cs-robert commented on April 28, 2024

image

from hermes.

cs-robert avatar cs-robert commented on April 28, 2024

hbc doesn't seem to have this problem, not sure if it's a coincidence or really OK

from hermes.

tmikov avatar tmikov commented on April 28, 2024

@cs-robert in your first post you said Hermes version 0.6.0. That version is almost 4 years old. Can you reproduce this with the latest Hermes version?

from hermes.

cs-robert avatar cs-robert commented on April 28, 2024

@cs-robert in your first post you said Hermes version 0.6.0. That version is almost 4 years old. Can you reproduce this with the latest Hermes version?

@tmikov 0.7.2 work fine,Why is hbc OK? And want to understand the specific logic of what caused it? How was it repaired?

from hermes.

tmikov avatar tmikov commented on April 28, 2024

@cs-robert it is hard to say, many things have changed in 4 years. Still, resolution of variables is very important, so I am pretty sure that even old versions didn't have major bugs related to it. You might be seeing a problem related to lazy compilation in an unexpected context: when running from source, Hermes lazily compiles every function when it is called the first time, which is a complicated process.

from hermes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.