mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Introduce RootedTraceableBox.
This commit is contained in:
parent
8c8eb41cdf
commit
f1605ab149
2 changed files with 72 additions and 0 deletions
|
@ -37,6 +37,7 @@ use dom::bindings::js::Root;
|
|||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::reflector::{DomObject, Reflector};
|
||||
use dom::bindings::str::{ByteString, DOMString, USVString};
|
||||
use dom::bindings::trace::{JSTraceable, RootedTraceableBox};
|
||||
use dom::bindings::utils::DOMClass;
|
||||
use js;
|
||||
pub use js::conversions::{FromJSValConvertible, ToJSValConvertible, ConversionResult};
|
||||
|
@ -117,6 +118,22 @@ impl <T: DomObject + IDLInterface> FromJSValConvertible for Root<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl <T: FromJSValConvertible + JSTraceable> FromJSValConvertible for RootedTraceableBox<T> {
|
||||
type Config = T::Config;
|
||||
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: HandleValue,
|
||||
config: Self::Config)
|
||||
-> Result<ConversionResult<Self>, ()> {
|
||||
T::from_jsval(cx, value, config).map(|result| {
|
||||
match result {
|
||||
ConversionResult::Success(v) => ConversionResult::Success(RootedTraceableBox::new(v)),
|
||||
ConversionResult::Failure(e) => ConversionResult::Failure(e),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert `id` to a `DOMString`, assuming it is string-valued.
|
||||
///
|
||||
/// Handling of invalid UTF-16 in strings depends on the relevant option.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue