0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-11 08:34:01 -05:00
denoland-rusty-v8/tests
Andreu Botella 1ed35fd22e
feat: Weak handles and finalizers (#895)
This change adds support for weak handles that don't prevent GC of the
referenced objects, through the `v8::Weak<T>` API. A weak handle can
be empty (if it was created empty or its object was GC'd) or
non-empty, and if non-empty it allows getting its object as a global
or local.

When creating a `v8::Weak` you can also set a finalizer that will be
called at some point after the object is GC'd, as long as the weak
handle is still alive at that point. This finalization corresponds to
the second-pass callback in `kParameter` mode in the C++ API, so it
will only be called after the object is GC'd. The finalizer function
is a `FnOnce` that may close over data, and which takes a
`&mut Isolate` as an argument.

The C++ finalization API doesn't guarantee _when_ or even _if_ the
finalizer will ever be called, but in order to prevent memory leaks,
the rusty_v8 wrapper ensures that it will be called at some point,
even if it's just before the isolate gets dropped.

`v8::Weak<T>` implements `Clone`, but a finalizer is tied to a single
weak handle, so its clones won't be able to keep the finalizer alive.
And in fact, cloning will create a new weak handle that isn't tied to
a finalizer at all. `v8::Weak::clone_with_finalizer` can be used to
make a clone of a weak handle which has a finalizer tied to it.

Note that `v8::Weak<T>` doesn't implement `Hash`, because the hash
would have to change once the handle's object is GC'd, which is a big
gotcha and would break some of the algorithms that rely on hashes,
such as the Rust std's `HashMap`.
2022-05-09 12:20:55 +02:00
..
compile_fail chore: upgrade Rust to 1.59.0 (#909) 2022-03-02 17:30:58 +05:30
slots.rs perf: avoid double boxing of Arc/Box/Rc in Isolate slot (#925) 2022-03-21 11:50:45 +01:00
test_api.rs feat: Weak handles and finalizers (#895) 2022-05-09 12:20:55 +02:00
test_api_entropy_source.rs Rolling to V8 10.0.139.6 (#915) 2022-03-09 14:41:46 +01:00
test_api_flags.rs chore: rename rusty_v8 to v8 (#803) 2021-10-27 14:32:12 +02:00
test_concurrent_isolate_creation_and_disposal.rs Rolling to V8 10.0.139.6 (#915) 2022-03-09 14:41:46 +01:00
test_platform_atomics_pump_message_loop.rs test: don't use --harmony-top-level-await flag (#854) 2021-12-12 21:25:01 -08:00
test_single_threaded_default_platform.rs Rolling to V8 10.0.139.6 (#915) 2022-03-09 14:41:46 +01:00
test_ui.rs Fix unused import warning (#875) 2022-01-22 04:10:38 +01:00