Skip to content

refactor: make Trace an unsafe trait for boa_engine compatibility#93

Merged
nekevss merged 1 commit into
boa-dev:mainfrom
shruti2522:unsafe
Jul 16, 2026
Merged

refactor: make Trace an unsafe trait for boa_engine compatibility#93
nekevss merged 1 commit into
boa-dev:mainfrom
shruti2522:unsafe

Conversation

@shruti2522

Copy link
Copy Markdown
Contributor

updated the Trace trait in both null_collector_branded and mark_sweep_branded to be an unsafe trait so we can
integrate it into boa_engine

my initial thought was to keep it a safe trait, but doing so broke the engine's closure type inference. Trace must be an unsafe trait, because if an implementor forgets to trace a GC pointer, it causes a UAF bug that the compiler can't catch.

I also changed the method signature from trace(&mut self) to trace(&self). This is necessary because gc objects frequently form reference cycles.

  • changed fn trace(&mut self) to unsafe fn trace(&self)
  • upgraded all impl Trace blocks to unsafe impl Trace
  • updated bounds to accept ?Sized types, added an as_ptr() helper to Gc

this ensures oscars is compatible with boa_engine, allowing to drop it in as a backend without changing any core engine code

@nekevss nekevss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's probably needed with the current approach here.

@nekevss
nekevss merged commit dffa8c0 into boa-dev:main Jul 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants