Commit 8f5d2d1
authored
feat(runtime): expose gc() as a callable globalThis property (#5712)
Follow-up to the `typeof gc` capability-guard fix. That change makes the
bare-identifier guard `if (typeof gc === "function") gc()` work, but the
other idiomatic capability-guard forms read `gc` as a VALUE:
if (globalThis.gc) globalThis.gc(); // Node CLI docs' own example
global.gc?.(); // Bun's documented form
const g = globalThis.gc; g?.();
These all read `globalThis.gc`, which Perry never installed, so they were
`undefined` / no-ops even though `gc()` is callable.
Install `gc` as a real callable property on the globalThis singleton (a
ClosureHeader-backed value, like `setTimeout`/`queueMicrotask`), routed to
the same `js_gc_collect` the bare `gc()` intrinsic uses. Non-enumerable; the
optional Node `force` argument is accepted but ignored (Perry's gc is a full
collection). Now `typeof globalThis.gc === "function"`, `globalThis.gc` is
truthy, and `globalThis.gc()` / `globalThis.gc?.()` / `gc?.()` all run a real
collection.1 parent 9ac7abc commit 8f5d2d1
4 files changed
Lines changed: 24 additions & 1 deletion
File tree
- crates/perry-runtime/src/object
- global_this
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
279 | 293 | | |
280 | 294 | | |
281 | 295 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
428 | 432 | | |
429 | 433 | | |
430 | 434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
199 | 204 | | |
200 | 205 | | |
201 | 206 | | |
| |||
0 commit comments