Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement `AsHandle` and `AsHandleMut` traits. #320
Conversation
Rust-mozjs currently does not define any methods to create instances of HandleValueArray. Consequently, consumers have to create these instances manually. This is unnecessary boilerplate, and therefore should be abstracted behind a function.
2865d20
to
63a53f0
Several types in rust-mozjs, such as Heap, PersistentRooted, and RootedGuard, represent a rooted value. A common property of rooted values is that a handle can be obtained to it. Rather than implement this property separately for each of these types, we should abstract it out into these two traits. This has several advantages: for instance, one can write functions that take any rooted value as argument, regardless of how it is implemented, and then obtain a handle to it. Additionally, it allows one to implement these traits for newtypes which underlying type is a rooted value.
|
I'm generally neutral on these changes, since it will require importing another trait for fairly common functionality. I'm also concerned about the safety of the new Heap::set method. |
| let ptr = self.ptr.get(); | ||
| let prev = *ptr; | ||
| *ptr = v; | ||
| T::post_barrier(ptr, prev, v); |
This comment has been minimized.
This comment has been minimized.
| /// Given the types `$T` and `$U`, implements the trait `AsHandleMut<$T>` for the type `$U`, where | ||
| /// `$U` is a newtype whose underlying type implements `HandleMut<$T>`. | ||
| #[macro_export] | ||
| macro_rules! derive_as_handle_mut { |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 22, 2016
Member
I don't really see a purpose for defining these macros here. The implementations aren't hard to write by hand, and I haven't come up with a use case for this in Servo yet.
jimblandy
commented
Nov 23, 2016
|
I suggested |
|
|
|
Closing due to lack of activity. |
ejpbruel commentedNov 22, 2016
•
edited by larsbergstrom
Several types in rust-mozjs, such as Heap, PersistentRooted, and RootedGuard, represent a rooted
value. A common property of rooted values is that a handle can be obtained to it. Rather than
implement this property separately for each of these types, we should abstract it out into these
two traits.
This change is