Bug 1309109 part 6 - Declare nullable strong borrowed ref type for RawServoDeclarationBlock. r=mystor draft
authorManish Goregaokar <manishsmail@gmail.com>
Fri, 14 Oct 2016 00:30:08 +1100
changeset 426169 5f8c706d7361f0be2c27f90ad960237845efd238
parent 426168 5ddf7f31447125e470f869e31496db79909634ad
child 426170 b476cdcc3ae63935a4ecf46b8fb73efb3483ef49
push id32640
push userxquan@mozilla.com
push dateTue, 18 Oct 2016 00:25:47 +0000
reviewersmystor
bugs1309109
milestone52.0a1
Bug 1309109 part 6 - Declare nullable strong borrowed ref type for RawServoDeclarationBlock. r=mystor MozReview-Commit-ID: 2SDPK6lp4ue
layout/style/ServoBindings.h
servo/components/style/binding_tools/regen.py
servo/components/style/gecko_bindings/bindings.rs
servo/components/style/gecko_bindings/sugar/ownership.rs
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -97,16 +97,17 @@ using mozilla::dom::StyleChildrenIterato
 #define DECL_NULLABLE_OWNED_REF_TYPE_FOR(type_)    \
   typedef type_* type_##OwnedOrNull;               \
   DECL_NULLABLE_BORROWED_REF_TYPE_FOR(type_)       \
   DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR(type_)
 
 DECL_ARC_REF_TYPE_FOR(ServoComputedValues)
 DECL_ARC_REF_TYPE_FOR(RawServoStyleSheet)
 DECL_ARC_REF_TYPE_FOR(RawServoDeclarationBlock)
+DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoDeclarationBlockStrong)
 
 DECL_OWNED_REF_TYPE_FOR(RawServoStyleSet)
 DECL_NULLABLE_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
 DECL_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
 
 // We don't use BorrowedMut because the nodes may alias
 // Servo itself doesn't directly read or mutate these;
 // it only asks Gecko to do so. In case we wish to in
--- a/servo/components/style/binding_tools/regen.py
+++ b/servo/components/style/binding_tools/regen.py
@@ -237,16 +237,17 @@ COMPILATION_TARGETS = {
         "servo_owned_types": [
             "RawServoStyleSet",
             "StyleChildrenIterator",
         ],
         "servo_immutable_borrow_types": [
             "RawGeckoNode",
             "RawGeckoElement",
             "RawGeckoDocument",
+            "RawServoDeclarationBlockStrong",
         ],
         "whitelist_functions": [
             "Servo_.*",
             "Gecko_.*"
         ]
     },
 
     "atoms": {
--- a/servo/components/style/gecko_bindings/bindings.rs
+++ b/servo/components/style/gecko_bindings/bindings.rs
@@ -16,16 +16,18 @@ pub type RawServoDeclarationBlockBorrowe
 enum RawServoDeclarationBlockVoid{ }
 pub struct RawServoDeclarationBlock(RawServoDeclarationBlockVoid);
 pub type RawGeckoNodeBorrowed<'a> = &'a RawGeckoNode;
 pub type RawGeckoNodeBorrowedOrNull<'a> = Option<&'a RawGeckoNode>;
 pub type RawGeckoElementBorrowed<'a> = &'a RawGeckoElement;
 pub type RawGeckoElementBorrowedOrNull<'a> = Option<&'a RawGeckoElement>;
 pub type RawGeckoDocumentBorrowed<'a> = &'a RawGeckoDocument;
 pub type RawGeckoDocumentBorrowedOrNull<'a> = Option<&'a RawGeckoDocument>;
+pub type RawServoDeclarationBlockStrongBorrowed<'a> = &'a RawServoDeclarationBlockStrong;
+pub type RawServoDeclarationBlockStrongBorrowedOrNull<'a> = Option<&'a RawServoDeclarationBlockStrong>;
 pub type RawServoStyleSetBorrowed<'a> = &'a RawServoStyleSet;
 pub type RawServoStyleSetBorrowedMut<'a> = &'a mut RawServoStyleSet;
 pub type RawServoStyleSetOwned = ::gecko_bindings::sugar::ownership::Owned<RawServoStyleSet>;
 pub type RawServoStyleSetBorrowedOrNull<'a> = Option<&'a RawServoStyleSet>;
 pub type RawServoStyleSetBorrowedMutOrNull<'a> = Option<&'a mut RawServoStyleSet>;
 pub type RawServoStyleSetOwnedOrNull = ::gecko_bindings::sugar::ownership::OwnedOrNull<RawServoStyleSet>;
 enum RawServoStyleSetVoid{ }
 pub struct RawServoStyleSet(RawServoStyleSetVoid);
--- a/servo/components/style/gecko_bindings/sugar/ownership.rs
+++ b/servo/components/style/gecko_bindings/sugar/ownership.rs
@@ -157,16 +157,30 @@ impl<T> Strong<T> {
         if self.is_null() {
             None
         } else {
             unsafe { Some(transmute(self)) }
         }
     }
 
     #[inline]
+    /// Given a reference to a strong FFI reference,
+    /// converts it into a reference to a servo-side Arc
+    /// Returns None on null.
+    ///
+    /// Strong<GeckoType> -> Arc<ServoType>
+    pub fn into_arc_opt_borrow<U>(&self) -> Option<&Arc<U>> where U: HasArcFFI<FFIType = T> {
+        if self.is_null() {
+            None
+        } else {
+            unsafe { Some(transmute(self)) }
+        }
+    }
+
+    #[inline]
     /// Produces a null strong FFI reference
     pub fn null() -> Self {
         unsafe { transmute(ptr::null::<T>()) }
     }
 }
 
 pub unsafe trait FFIArcHelpers {
     type Inner: HasArcFFI;