-
Notifications
You must be signed in to change notification settings - Fork 23
Fix issues with reference tracking #101
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add more asserts Move value,count to init instead of ctor
Try updating Android tooling versions
Remove step to install the Android emulator
…orInfo (otherwise the Finalize for that JS prototype object gets nullptr for private data and we get a crash)
Allan121
reviewed
Jan 20, 2025
Allan121
reviewed
Jan 20, 2025
bghgary
approved these changes
Jan 21, 2025
Co-authored-by: Gary Hsu <bghgary@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background refresher: We want to be able to track weak references to arbitrary JS objects (created either from JavaScript or from native). When this is a weak reference, we need to know when the JS object has been GC'd such that the reference evaluates to null. To track when an object is GC'd, we want to register a finalizer callback. However, the only way to know when an object is finalized with JSC is to create a new class and provide a
finalizecallback. Given this, what we do is create a "sentinel" JS object that is attached/linked to the actual JS object of interest, and only referenced by that JS object. This way when the JS object of interest is GC'd, the attached/linked sentinel JS object with a finalizer callback is also GC'd and our finalizer is called and we know the JS object of interest has been GC'd.There are two main issues being addressed in this PR:
NativeInfoinstance memory address as a unique identifier (tracked in our active reference list, and already attached to the sentinel JS object), which is safe because that object is not deleted until after the sentinel is GC'd, so it will definitely be valid (unique) for at least as long as the JS object being tracked. When adding a ref as well as when accessing the underlying value of the ref, we check this new unique identifier to make sure the JS object (at the stored memory address) is actually still the same one.Since there is now an object id check in
napi_ref__::value, this also exposed another napi bug, where we try to read properties off of a GC'd JS object. To fix this, I'm also taking this napi fix: https://github.com/nodejs/node-addon-api/pull/1607/files