diff options
author | Oriol Brufau <obrufau@igalia.com> | 2024-09-13 17:59:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-13 15:59:57 +0000 |
commit | a76daaf04c121b70c9b0f3883b682983d676ff7f (patch) | |
tree | b5068d707d5fa98500893f50a0cda980d81045ac /components/script/dom/node.rs | |
parent | 261d60e456b678939b8a0ceff4d8eafcd44e582e (diff) | |
download | servo-a76daaf04c121b70c9b0f3883b682983d676ff7f.tar.gz servo-a76daaf04c121b70c9b0f3883b682983d676ff7f.zip |
Upgrade stylo to 2024-09-02 (#33370)
* Upgrade stylo to 2024-09-02
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Fixup for https://phabricator.services.mozilla.com/D217308
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Fixup for https://phabricator.services.mozilla.com/D217626
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Fixup for https://phabricator.services.mozilla.com/D218488
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Fixup for https://phabricator.services.mozilla.com/D219537
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
* Update test expectations
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
---------
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r-- | components/script/dom/node.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 6122db3221a..f53f7193bdf 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1297,16 +1297,7 @@ where /// returns it. #[allow(unsafe_code)] pub unsafe fn from_untrusted_node_address(candidate: UntrustedNodeAddress) -> DomRoot<Node> { - // https://github.com/servo/servo/issues/6383 - let candidate = candidate.0 as usize; - // let object: *mut JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime, - // candidate); - let object = candidate as *mut JSObject; - if object.is_null() { - panic!("Attempted to create a `Dom<Node>` from an invalid pointer!") - } - let boxed_node = conversions::private_from_object(object) as *const Node; - DomRoot::from_ref(&*boxed_node) + DomRoot::from_ref(Node::from_untrusted_node_address(candidate)) } #[allow(unsafe_code)] @@ -2430,6 +2421,24 @@ impl Node { .map_or(ns!(), |elem| elem.locate_namespace(prefix)), } } + + /// If the given untrusted node address represents a valid DOM node in the given runtime, + /// returns it. + /// + /// # Safety + /// + /// Callers should ensure they pass an UntrustedNodeAddress that points to a valid `JSObject` + /// in memory that represents a `Node`. + #[allow(unsafe_code)] + pub unsafe fn from_untrusted_node_address(candidate: UntrustedNodeAddress) -> &'static Self { + // https://github.com/servo/servo/issues/6383 + let candidate = candidate.0 as usize; + let object = candidate as *mut JSObject; + if object.is_null() { + panic!("Attempted to create a `Node` from an invalid pointer!") + } + &*(conversions::private_from_object(object) as *const Self) + } } impl NodeMethods for Node { |