Commit a98aabf
quickjs napi: track napi_refs in env and release at Detach
During teardown the QuickJS implementation of Napi::Detach would leave
outstanding strong napi_refs dangling. Those refs pin JS values from
outside the gc_obj_list graph, so the cycle collector in JS_FreeRuntime
cannot break them and the list_empty(gc_obj_list) assertion fires.
Mirror the V8 impl (napi_env__::DeleteMe): track every RefInfo created
by napi_create_reference in a per-env list and release their JS side in
Detach. The RefInfo allocations themselves are left for their owning
C++ holders to destroy (typically later, via wrapper finalizers); those
subsequent napi_delete_reference calls take a detached-env path that
is a no-op.
Also implement gc_mark on NapiCallback so the strong newTarget ref it
holds participates in cycle collection, fix a leak of the callbackData
ref in create_function_internal, and run JS_RunGC twice at the end of
Detach so wrapper finalizers (which release embedded Napi::Reference
instances) execute while the env is still valid.
Tests: 136/136 passing. Reduces teardown leak count significantly; a
small residual set of externally-pinned objects still prevents the
gc_obj_list assertion from passing in all cases.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent f9e10bb commit a98aabf
3 files changed
Lines changed: 105 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
52 | 78 | | |
53 | 79 | | |
54 | 80 | | |
| |||
62 | 88 | | |
63 | 89 | | |
64 | 90 | | |
65 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
66 | 108 | | |
67 | 109 | | |
68 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
180 | | - | |
| 179 | + | |
181 | 180 | | |
182 | 181 | | |
183 | 182 | | |
184 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
185 | 196 | | |
186 | 197 | | |
187 | 198 | | |
| |||
190 | 201 | | |
191 | 202 | | |
192 | 203 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
| 204 | + | |
198 | 205 | | |
199 | 206 | | |
200 | 207 | | |
| |||
218 | 225 | | |
219 | 226 | | |
220 | 227 | | |
221 | | - | |
| 228 | + | |
222 | 229 | | |
223 | 230 | | |
224 | 231 | | |
| |||
943 | 950 | | |
944 | 951 | | |
945 | 952 | | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | | - | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
954 | 962 | | |
955 | 963 | | |
956 | 964 | | |
| |||
1699 | 1707 | | |
1700 | 1708 | | |
1701 | 1709 | | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
1702 | 1713 | | |
1703 | 1714 | | |
1704 | 1715 | | |
| |||
1709 | 1720 | | |
1710 | 1721 | | |
1711 | 1722 | | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
1712 | 1729 | | |
1713 | 1730 | | |
1714 | 1731 | | |
1715 | 1732 | | |
1716 | 1733 | | |
1717 | 1734 | | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
1718 | 1743 | | |
1719 | 1744 | | |
1720 | 1745 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
| |||
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
20 | 41 | | |
21 | 42 | | |
22 | 43 | | |
| |||
0 commit comments