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 upAdd methods to create a HandleValueArray. #319
Conversation
| pub fn new() -> HandleValueArray { | ||
| HandleValueArray { | ||
| length_: 0, | ||
| elements_: ptr::null_mut(), |
This comment has been minimized.
This comment has been minimized.
| } | ||
| } | ||
|
|
||
| pub fn from_slice(values: &[Value]) -> HandleValueArray { |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 21, 2016
Member
This is not clearly safe to me - it's easy to create a vector which isn't rooted, leading to a handle that can point to things that get GCed. We should either remove this constructor, figure out a way to make it safe, or mark it unsafe.
This comment has been minimized.
This comment has been minimized.
ejpbruel
Nov 21, 2016
Author
Contributor
Fair enough. Having this constructor is something I depend on quite often in the Rust Debugger API, so I'd prefer to keep it around.
I did try to make this function take a &[HandleValue] instead, since that would guarantee the values are rooted. Unfortunately, a HandleValue is not a pointer, but rather a pointer to a pointer, so you can't use it to create a HandleValueArray directly. Nor can we create a Vec from the &[HandleValue], since there's no way to keep that alive after this function returns.
Given the above, I'd like to opt to make this function unsafe.
This comment has been minimized.
This comment has been minimized.
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.
|
@bors-servo: r+ |
|
|
Add methods to create a HandleValueArray. 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. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/319) <!-- Reviewable:end -->
|
|
ejpbruel commentedNov 21, 2016
•
edited by larsbergstrom
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.
This change is