File tree Expand file tree Collapse file tree 3 files changed +27
-8
lines changed
Expand file tree Collapse file tree 3 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,13 @@ use crate::{
2323
2424use super :: { BuiltInConstructor , BuiltInObject , IntrinsicObject , builder:: BuiltInBuilder } ;
2525
26+ #[ cfg( test) ]
27+ mod tests;
28+
2629/// On GG collection, sends a message to a [`FinalizationRegistry`] indicating that it needs to
2730/// be collected.
2831#[ derive( Trace ) ]
29- #[ boa_gc( unsafe_empty_trace) ]
30- struct CleanupSignaler ( Cell < Option < async_channel:: WeakSender < ( ) > > > ) ;
32+ struct CleanupSignaler ( #[ unsafe_ignore_trace] Cell < Option < async_channel:: WeakSender < ( ) > > > ) ;
3133
3234impl Finalize for CleanupSignaler {
3335 fn finalize ( & self ) {
@@ -313,12 +315,7 @@ impl FinalizationRegistry {
313315 let _key = cell. target . key ( ) ;
314316 // TODO: it might be better to add a special ref for the value that
315317 // also preserves the original key instead.
316- // SAFETY: the original key is alive per our previous call to `key`,
317- // so if this returns `Some`, then the value cannot be collected
318- // until `key` gets dropped.
319- unsafe {
320- cell. target . value_ref ( ) . and_then ( |v| v. 0 . take ( ) ) ;
321- }
318+ cell. target . value ( ) . and_then ( |v| v. 0 . take ( ) ) ;
322319
323320 // ii. Set removed to true.
324321 removed = true ;
Original file line number Diff line number Diff line change 1+ use indoc:: indoc;
2+
3+ use crate :: { TestAction , run_test_actions} ;
4+
5+ #[ test]
6+ fn finalization_registry_simple ( ) {
7+ run_test_actions ( [
8+ TestAction :: run ( indoc ! { r#"
9+ let counter = 0;
10+ const registry = new FinalizationRegistry(() => {
11+ counter++;
12+ });
13+
14+ registry.register(["foo"]);
15+ "# } ) ,
16+ TestAction :: assert_eq ( "counter" , 0 ) ,
17+ TestAction :: inspect_context ( |_| boa_gc:: force_collect ( ) ) ,
18+ TestAction :: inspect_context ( |ctx| ctx. run_jobs ( ) . unwrap ( ) ) ,
19+ TestAction :: assert_eq ( "counter" , 1 ) ,
20+ ] ) ;
21+ }
Original file line number Diff line number Diff line change @@ -447,6 +447,7 @@ pub(crate) fn set_default_global_bindings(context: &mut Context) -> JsResult<()>
447447 global_binding :: < WeakSet > ( context) ?;
448448 global_binding :: < IteratorConstructor > ( context) ?;
449449 global_binding :: < Atomics > ( context) ?;
450+ global_binding :: < FinalizationRegistry > ( context) ?;
450451
451452 #[ cfg( feature = "annex-b" ) ]
452453 {
You can’t perform that action at this time.
0 commit comments