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

core: refactor how libuv companion objects are allocated #553

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

saghul
Copy link
Owner

@saghul saghul commented Jun 20, 2024

All native bindings are allocated and attached to the JS object in an opaque.

When what we attach is a native binding to a libuv handle there is a tricky situation: uv_close() is not synchronous, which means that we need to delay freeing the native object until the close callback was called. This is a problem when objects are freed as part of freeing the JS engine, since by the time the close callback is called the JS context and runtime have been freed.

In order to avoid this problem, allocate the memory for these "companion" objects with the tjs__ family of functions, which don't depend on the JS context.

This also allows us to refactor TJSFreeRuntime to a much more obvious flow. There is no need to walk and close all libuv handles, since they'll all be closed when the JS engine is terminated.

All native bindings are allocated and attached to the JS object in an
opaque.

When what we attach is a native binding to a libuv handle there is a
tricky situation: uv_close() is not synchronous, which means that we
need to delay freeing the native object until the close callback was
called. This is a problem when objects are freed as part of freeing the
JS engine, since by the time the close callback is called the JS context
and runtime have been freed.

In order to avoid this problem, allocate the memory for these
"companion" objects with the tjs__ family of functions, which don't
depend on the JS context.

This also allows us to refactor TJSFreeRuntime to a much more obvious
flow. There is no need to walk and close all libuv handles, since
they'll all be closed when the JS engine is terminated.
@saghul saghul force-pushed the alloc-close-refactor branch from 9170831 to 4cc8437 Compare June 20, 2024 14:59
@saghul saghul merged commit 8daf2b8 into master Jun 20, 2024
14 checks passed
@saghul saghul deleted the alloc-close-refactor branch June 20, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant