servo / mozjs

Servo's SpiderMonkey fork
255 stars 118 forks source link

MutableHandle are clonable breaking safety provided by &mut #520

Open sagudev opened 4 weeks ago

sagudev commented 4 weeks ago

mut is required for https://doc.servo.org/mozjs/gc/root/struct.MutableHandle.html#tymethod.set, but this is still weird as MutableHandle is clonable so &mut does not help a lot with safety.

_Originally posted by @sagudev in https://github.com/servo/servo/pull/34087#discussion_r1825494608_

When cloning MutableHandle we still have underlying pointer point to same location, so we can have two &mut that points to same location.

sagudev commented 4 weeks ago

I think the proper solution would be to not impl Clone/Copy for *Handle or at least mark it as unsafe.

sagudev commented 4 weeks ago

I think the first action point would be to remove all mozjs::rust::wrappers usages, then we can remove clone,copy in followup.