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

Missing default rejection tracking and console.log() polyfill to the Hermes CLI #1480

Open
wcandillon opened this issue Aug 16, 2024 · 4 comments
Labels
need-repro Potentially valid, but blocked on missing test case to reproduce

Comments

@wcandillon
Copy link

Bug Description

The following code returns 10 on v8 but doesn't return anything using the hermes binary:

function resolveAfter2Seconds(x) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(x);
    }, 2000);
  });
}

async function f1() {
  const x = await resolveAfter2Seconds(10);
  console.log(x); // 10
}

f1();

The Expected Behavior

To return 10;

@wcandillon wcandillon added the bug Something isn't working label Aug 16, 2024
@tmikov tmikov added need-repro Potentially valid, but blocked on missing test case to reproduce and removed bug Something isn't working labels Aug 16, 2024
@tmikov
Copy link
Contributor

tmikov commented Aug 16, 2024

I am afraid I can't reproduce this. I just tried it and it works as expected. See the attached screenshot:

Screenshot 2024-08-16 at 1 51 27 PM

@tmikov
Copy link
Contributor

tmikov commented Aug 16, 2024

Your example uses console.log(), which isn't provided by the Hermes CLI. An exception is thrown in the primise.

@tmikov tmikov closed this as completed Aug 16, 2024
@wcandillon
Copy link
Author

$ cat oo.js
function resolveAfter2Seconds(x) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(x);
    }, 2000);
  });
}

async function f1() {
  const x = await resolveAfter2Seconds(10);
  console.log(x); // 10
}

f1();
$ ./bin/hermes foo.js
$  echo $?
0

no output nor exception. How do I reconcile the difference of behaviour?
Using print() does yield the "expected" result.

@tmikov
Copy link
Contributor

tmikov commented Aug 17, 2024

@wcandillon there is no real difference in behavior. The spec does not specify how unhandled Promise rejection should be handled by the host environment. It is up to the integrator of the JS engine. Browsers and NodeJS provide their own mechanisms. I suspect React Native does too, or it should.

The Hermes CLI tool is a very minimalistic integration of the engine, it only provides print() and a couple of more things. It doesn't configure a rejection hook.

If you need this behavior, you can configure the rejection hook yourself from JS like this:

HermesInternal.enablePromiseRejectionTracker({
  allRejections: true,
  onUnhandled: function(id, error) {
    print("Unhandled Promise rejection:", error.stack);
  },
});

I think there is a good point to be made that the Hermes CLI tool should set this by default and it should also probably provide a very simple polyfill for console.log(). We will look into it.

@tmikov tmikov reopened this Aug 17, 2024
@tmikov tmikov changed the title async example yield different result than v8 Add default rejection tracking and console.log() polyfill to the Hermes CLI Aug 17, 2024
@tmikov tmikov changed the title Add default rejection tracking and console.log() polyfill to the Hermes CLI Missing default rejection tracking and console.log() polyfill to the Hermes CLI Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-repro Potentially valid, but blocked on missing test case to reproduce
Projects
None yet
Development

No branches or pull requests

2 participants