0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/js-native-api
Gabriel Schulhof 53ca0b9ae1 src: render N-API weak callbacks as cleanup hooks
Since worker threads are complete Node.js environments, including the
ability to load native addons, and since those native addons can
allocate resources to be freed when objects go out of scope, and since,
upon worker thread exit, the engine does not invoke the weak callbacks
responsible for freeing resources which still have references, this
modification introduces tracking for weak references such that a list
of outstanding weak references is maintained. This list is traversed
during environment teardown. The callbacks for the remaining weak
references are called.

This change is also relevant for Node.js embedder scenarios, because in
those cases the process also outlives the `node::Environment` and
therefore weak callbacks should also be rendered as environment cleanup
hooks to ensure proper cleanup after native addons. This changes
introduces the means by which this can be accomplished.

A benchmark is included which measures the time it takes to execute the
weak reference callback for a given number of weak references.

Re: https://github.com/tc39/proposal-weakrefs/issues/125#issuecomment-535832130
PR-URL: https://github.com/nodejs/node/pull/28428
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2019-10-13 00:07:43 -07:00
..
2_function_arguments
3_callbacks
4_object_factory
5_function_factory
6_object_wrap n-api: define ECMAScript-compliant accessors on napi_define_class 2019-06-17 12:07:08 +02:00
7_factory_wrap
8_passing_wrapped
test_array benchmark,doc,lib,test: capitalize comments 2019-02-28 18:31:10 +01:00
test_bigint
test_constructor n-api: refactor a previous commit 2019-07-26 15:09:04 -07:00
test_conversions
test_dataview
test_date n-api: mark version 5 N-APIs as stable 2019-09-05 09:16:54 -07:00
test_error test: refactoring test_error testing 2019-08-01 13:12:53 -07:00
test_exception
test_function n-api: refactoring napi_create_function testing 2019-07-31 23:19:41 -07:00
test_general src: render N-API weak callbacks as cleanup hooks 2019-10-13 00:07:43 -07:00
test_handle_scope benchmark,doc,lib,test: capitalize comments 2019-03-10 00:44:40 +01:00
test_instance_data n-api: add APIs for per-instance state management 2019-07-25 16:53:07 -07:00
test_new_target
test_number benchmark,doc,lib: capitalize more comments 2019-03-27 17:20:06 +01:00
test_object n-api: refactor a previous commit 2019-07-26 15:09:04 -07:00
test_promise
test_properties n-api: define ECMAScript-compliant accessors on napi_define_properties 2019-06-17 12:06:06 +02:00
test_reference test: check napi_get_reference_value() during finalization 2019-04-30 18:59:34 -07:00
test_string benchmark,doc,lib: capitalize more comments 2019-03-27 17:20:06 +01:00
test_symbol benchmark,doc,lib: capitalize more comments 2019-03-27 17:20:06 +01:00
test_typedarray benchmark,doc,lib,test: capitalize comments 2019-02-28 18:31:10 +01:00
.gitignore
common.c n-api: refactor a previous commit 2019-07-26 15:09:04 -07:00
common.h n-api: refactor a previous commit 2019-07-26 15:09:04 -07:00
entry_point.c
testcfg.py