mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
script: introduce safe wrappers for js val conversions (#38004)
Introduce a safe wrapper trait for the unsafe `ToJSValConvertible`, and use it in `script/dom` where the default `T` implementation works. Part of https://github.com/servo/servo/issues/37951 --------- Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
parent
9e2ee0029a
commit
027954dbad
16 changed files with 149 additions and 187 deletions
|
@ -31,10 +31,22 @@ use crate::inheritance::Castable;
|
|||
use crate::num::Finite;
|
||||
use crate::reflector::{DomObject, Reflector};
|
||||
use crate::root::DomRoot;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
use crate::str::{ByteString, DOMString, USVString};
|
||||
use crate::trace::RootedTraceableBox;
|
||||
use crate::utils::{DOMClass, DOMJSClass};
|
||||
|
||||
/// A safe wrapper for `ToJSValConvertible`.
|
||||
pub trait SafeToJSValConvertible {
|
||||
fn safe_to_jsval(&self, cx: SafeJSContext, rval: MutableHandleValue);
|
||||
}
|
||||
|
||||
impl<T: ToJSValConvertible> SafeToJSValConvertible for T {
|
||||
fn safe_to_jsval(&self, cx: SafeJSContext, rval: MutableHandleValue) {
|
||||
unsafe { self.to_jsval(*cx, rval) };
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait to check whether a given `JSObject` implements an IDL interface.
|
||||
pub trait IDLInterface {
|
||||
/// Returns whether the given DOM class derives that interface.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue