diff options
author | Tim van der Lippe <TimvdLippe@users.noreply.github.com> | 2025-04-13 05:55:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-13 03:55:23 +0000 |
commit | dcc88b53aa84383b082bc903e54dbe1c43f663eb (patch) | |
tree | 465faf8795adcc7275bf115a621e11ded5e0c14f /components/script_bindings/callback.rs | |
parent | 0c045fc247e95edd2cbf2b016623116d0fa1edf0 (diff) | |
download | servo-dcc88b53aa84383b082bc903e54dbe1c43f663eb.tar.gz servo-dcc88b53aa84383b082bc903e54dbe1c43f663eb.zip |
Implement "Create a Trusted Type" algorithm (#36454)
This algorithm is quite straightforward written in the specification,
but leads to some type awkwardness in Rust. Most notably, the callbacks
have different types and cannot be unified easily. They also return
different string types. Similarly, the returning objects are all unique
types and don't have a common denominator.
Therefore, rather than implementing it in 1-to-1 fashion with the
specification text, it instead uses callbacks to instruct the type
system of what to call when.
This is further complicated by the fact that the callback can exist
or not, as well as return a value or not. This requires multiple
unwrangling, combined with the fact that the algorithm should throw
or not.
All in all, the number of lines is relatively low compared to the
specification algorithm and the Rust compiler does a lot of heavy
lifting figuring out which type is what.
Part of https://github.com/servo/servo/issues/36258
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Diffstat (limited to 'components/script_bindings/callback.rs')
-rw-r--r-- | components/script_bindings/callback.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/components/script_bindings/callback.rs b/components/script_bindings/callback.rs index a31b57f677f..2c43653c825 100644 --- a/components/script_bindings/callback.rs +++ b/components/script_bindings/callback.rs @@ -12,7 +12,7 @@ use std::rc::Rc; use js::jsapi::{ AddRawValueRoot, EnterRealm, Heap, IsCallable, JSObject, LeaveRealm, Realm, RemoveRawValueRoot, }; -use js::jsval::{JSVal, ObjectValue, UndefinedValue}; +use js::jsval::{JSVal, NullValue, ObjectValue, UndefinedValue}; use js::rust::wrappers::{JS_GetProperty, JS_WrapObject}; use js::rust::{HandleObject, MutableHandleValue, Runtime}; @@ -237,7 +237,11 @@ pub(crate) fn wrap_call_this_value<T: ThisReflector>( mut rval: MutableHandleValue, ) -> bool { rooted!(in(*cx) let mut obj = p.jsobject()); - assert!(!obj.is_null()); + + if obj.is_null() { + rval.set(NullValue()); + return true; + } unsafe { if !JS_WrapObject(*cx, obj.handle_mut()) { |