Support using rooted macro with vectors.#697
Conversation
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
|
Ack, there was a new sccache release but it doesn't include x86_64 binaries for macOS, only arm64, so our x86_64 macOS build is busted. |
| impl From<&super::RootedGuard<'_, Vec<JSVal>>> for JS::HandleValueArray { | ||
| fn from(vec: &super::RootedGuard<'_, Vec<JSVal>>) -> JS::HandleValueArray { | ||
| JS::HandleValueArray { | ||
| length_: vec.len(), | ||
| elements_: vec.deref().as_ptr(), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I think it would make more sense to impl RootedGuard<'_, Vec<JSVal>> as that's how we do other stuff.
There was a problem hiding this comment.
Can you give an example of what you mean? There's a matching impl for RootedVec right above this one.
There was a problem hiding this comment.
Similarly,
mozjs/mozjs-sys/src/jsimpls.rs
Lines 142 to 167 in 369880c
There was a problem hiding this comment.
Above is impl for RootedVec, but RootedGuard usually have handle() and handle_mut() methods so here it would be smth like:
impl<'a,> RootedGuard<'a, Vec<JSVal>>
{
fn handle_value_array(&self) -> JS::HandleValueArray {
JS::HandleValueArray {
length_: self.len(),
elements_: self.deref().as_ptr(),
}
}
}There was a problem hiding this comment.
Hm, given that HandleValueArray has no lifetime associated it can outlive the root so it should be unsafe (thus all from conversions are unsound).
There was a problem hiding this comment.
For the purposes of this PR, I'd rather match the existing HandleValueArray creation code that I linked in https://github.com/servo/mozjs/pull/697/changes/BASE..60cd1d696448318e06ec28f103b30641c9c8ffa6#r2700733569. If we want to change that, I think we should change all of them together.
We can wait for mozilla/sccache#2554 or temporarily disable sccache on x86_64 macOS. |
| where | ||
| Vec<T>: RootKind, | ||
| { | ||
| pub fn push(&mut self, value: T) { |
There was a problem hiding this comment.
I think this is what I was trying to do here https://github.com/servo/mozjs/pull/630/changes#diff-737e12000758c48503126ab75c14db2c9d0854a95487ebdd0a51d99f991822efR289 but I ended up creating a whole new struct DynamicValueArray and struct FixedValueArray.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
…s artifacts (#41971) This bump includes some new safe wrappers: servo/mozjs#699 servo/mozjs#700 debugmozjs artifacts: servo/mozjs#544 rooted macros with vectors: servo/mozjs#697 Testing: Done in mozjs repo. Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
We created our
RootedVectype back before we supported storing arbitrary traceable types in SpiderMonkey'sRootedclass. Now that we can do that, we can replicate SpiderMonkey'sRootedVec, which is just a Rooted wrapper around a vector.Testing: New unit test added.
Servo PR: servo/servo#41921