mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
script: Impl safe from_jsval
wrapper (#38149)
Implement `SafeFromJSValConvertible`, a safe wrapper for `ToJSValConvertible`. And, replace unsafe `ToJSValConvertible` with `SafeFromJSValConvertible` in `script/dom` to reduce the amount of unsafe code in `script`. This would support the implementation of `AdoptedStylesheet` where we will need to have a setter/getter of sequence, that was implemented by `any` types. Part of https://github.com/servo/servo/issues/37951 Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
This commit is contained in:
parent
dcae2dd9fd
commit
3ce95b2ba5
6 changed files with 79 additions and 64 deletions
|
@ -21,7 +21,9 @@ pub(crate) use script_bindings::error::*;
|
|||
|
||||
#[cfg(feature = "js_backtrace")]
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::conversions::{ConversionResult, FromJSValConvertible, root_from_object};
|
||||
use crate::dom::bindings::conversions::{
|
||||
ConversionResult, SafeFromJSValConvertible, root_from_object,
|
||||
};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::domexception::{DOMErrorName, DOMException};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
|
@ -208,7 +210,7 @@ impl ErrorInfo {
|
|||
}
|
||||
}
|
||||
|
||||
match unsafe { USVString::from_jsval(*cx, value, ()) } {
|
||||
match USVString::safe_from_jsval(cx, value, ()) {
|
||||
Ok(ConversionResult::Success(USVString(string))) => ErrorInfo {
|
||||
message: format!("uncaught exception: {}", string),
|
||||
filename: String::new(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue