Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves WASM-backed object memory safety by preventing double-free scenarios between manual dispose() and FinalizationRegistry-driven cleanup, and adds tests to validate GC-based cleanup behavior.
Changes:
- Refactors
FinalizationRegistrysetup to share logic and avoid capturingthisvia bound cleanup functions. - Updates
WasmObject.dispose()to invalidate the finalizer token pointer after manual cleanup. - Adds GC/double-free regression tests plus a shared test helper, and enables
--expose-gcfor the Node test runner.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/webcanvas/vitest.config.ts | Enables exposed GC for Node-based Vitest runs. |
| packages/webcanvas/src/interop/registry.ts | Deduplicates registry construction via createRegistry(). |
| packages/webcanvas/src/interop/WasmObject.ts | Stores a mutable registry token and zeros ptr on dispose to avoid double-free. |
| packages/webcanvas/test/helpers.ts | Adds utilities to force finalization and assert GC cleanup / no double-free. |
| packages/webcanvas/test/text.test.ts | Adds dispose+GC and GC-cleanup tests for Text. |
| packages/webcanvas/test/shape.test.ts | Adds dispose+GC and GC-cleanup tests for Shape. |
| packages/webcanvas/test/scene.test.ts | Adds dispose+GC and GC-cleanup tests for Scene. |
| packages/webcanvas/test/picture.test.ts | Adds dispose+GC and GC-cleanup tests for Picture. |
| packages/webcanvas/test/gradient.test.ts | Adds dispose+GC and GC-cleanup tests for gradients. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
881d488 to
e117590
Compare
e117590 to
cdd075a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🚀 Playground preview deployment ready! 🎮 Playground: https://thorvg-playground-rdod1sn0e-thorvg-web.vercel.app |
|
Hold, I've found minor issue. Under reviewing. |
cdd075a to
b1b1cbf
Compare
|
🚀 Playground preview deployment ready! 🎮 Playground: https://thorvg-playground-4zqz89iov-thorvg-web.vercel.app |
|
🚀 Playground preview deployment ready! 🎮 Playground: https://thorvg-playground-p89jvez8u-thorvg-web.vercel.app |
d47e2e6 to
f3fe918
Compare
|
🚀 Playground preview deployment ready! 🎮 Playground: https://thorvg-playground-haiknsopy-thorvg-web.vercel.app |
f3fe918 to
bcbbca7
Compare
|
🚀 Playground preview deployment ready! 🎮 Playground: https://thorvg-playground-1qg9f1fnm-thorvg-web.vercel.app |
When dispose() was called explicitly and GC fired afterward, the FinalizationRegistry callback would call `tvg_paint_unref` / `tvg_gradient_del` again on the already-freed pointer, corrupting the WASM heap.
bcbbca7 to
2b41698
Compare
|
🚀 Playground preview deployment ready! 🎮 Playground: https://thorvg-playground-rigjmp6oi-thorvg-web.vercel.app |
When
dispose()was called explicitly and GC fired afterward, the FinalizationRegistry callback would call_tvg_paint_unref/_tvg_gradient_delagain on the already-freed pointer, corrupting the WASM heap.This PR adds: