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

refactor(promise): don't include the promise rejection tracker hook in the bytecode #1162

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ecreeth
Copy link

@ecreeth ecreeth commented Oct 18, 2023

Summary

We're including the rejection tracking hook in the Promise's bytecode.
According to the library authors, due to the performance cost, we should only do this during development

The React Native repo already is enabling the enablePromiseRejectionTracker during development.

// register the JavaScript implemented `enable` function into
// the Hermes' internal promise rejection tracker.
var enableHook = require('promise/setimmediate/rejection-tracking').enable
HermesInternal?.setPromiseRejectionTrackingHook?.(enableHook);

I just remove the hook registration and run the gen-promise-internal-bc.sh

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Oct 18, 2023
@ecreeth
Copy link
Author

ecreeth commented Oct 18, 2023

I'm getting an Uncaught TypeError: Promise rejection tracking hook was not registered from hermesInternalEnablePromiseRejectionTracker. I need to investigate a little, so I'm going to convert the PR to draft.

@ecreeth ecreeth marked this pull request as draft October 18, 2023 17:17
@avp
Copy link
Contributor

avp commented Oct 18, 2023

This part of the code has a couple moving parts, so maybe I can help explain what's going on here:

The code in promise/index.js in Hermes are calling setPromiseRejectionTrackingHook, which performs a different operation from enablePromiseRejectionTracker.

  • setPromiseRejectionTrackingHook is entirely internal to Hermes - it's only got the one callsite in InternalBytecode. It doesn't actually enable promise rejection tracking; it only sets up a single pointer inside the Runtime to point to the enable closure (https://github.com/facebook/hermes/blob/main/lib/VM/JSLib/HermesInternal.cpp#L712)

  • enablePromiseRejectionTracker is called (in development mode) by RN or any other integrator with any options they choose.

The reason you're getting a TypeError is that Hermes expects the hook to be set, because it has no way of knowing whether a caller wants to enable it.

The doc-comments on those two functions here might also help: https://github.com/facebook/hermes/blob/main/lib/VM/JSLib/HermesInternal.cpp#L697

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants