Bug 1466406: Work around a bindgen bug on Android. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 04 Jun 2018 19:14:20 +0200
changeset 803582 208386cc1994d0d774df08f2f563a77eecbaebf9
parent 803479 fa5724780fe76d6ccbbd08d978342a1db6a43d49
push id112157
push userbmo:emilio@crisal.io
push dateMon, 04 Jun 2018 17:15:53 +0000
reviewersxidorn
bugs1466406
milestone62.0a1
Bug 1466406: Work around a bindgen bug on Android. r?xidorn MozReview-Commit-ID: 2lltjH7IoZu
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
layout/style/ServoBindings.toml
servo/components/style/gecko/wrapper.rs
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -62,16 +62,17 @@
 #include "mozilla/SystemGroup.h"
 #include "mozilla/ServoTraversalStatistics.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/RWLock.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/ElementInlines.h"
 #include "mozilla/dom/HTMLTableCellElement.h"
 #include "mozilla/dom/HTMLBodyElement.h"
+#include "mozilla/dom/HTMLSlotElement.h"
 #include "mozilla/dom/MediaList.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/URLExtraData.h"
 #include "mozilla/dom/CSSMozDocumentRule.h"
 
 #if defined(MOZ_MEMORY)
 # include "mozmemory.h"
 #endif
@@ -177,16 +178,23 @@ Gecko_GetAnonymousContentForElement(RawG
 
 void
 Gecko_DestroyAnonymousContentList(nsTArray<nsIContent*>* aAnonContent)
 {
   MOZ_ASSERT(aAnonContent);
   delete aAnonContent;
 }
 
+const nsTArray<RefPtr<nsINode>>*
+Gecko_GetAssignedNodes(RawGeckoElementBorrowed aElement)
+{
+  MOZ_ASSERT(HTMLSlotElement::FromNode(aElement));
+  return &static_cast<const HTMLSlotElement*>(aElement)->AssignedNodes();
+}
+
 void
 Gecko_ComputedStyle_Init(
     mozilla::ComputedStyle* aStyle,
     const mozilla::ComputedStyle* aParentContext,
     RawGeckoPresContextBorrowed aPresContext,
     const ServoComputedData* aValues,
     mozilla::CSSPseudoElementType aPseudoType,
     nsAtom* aPseudoTag)
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -139,16 +139,17 @@ struct MediumFeaturesChangedResult {
   bool mUsesViewportUnits;
 };
 
 bool Gecko_IsSignificantChild(RawGeckoNodeBorrowed node, bool whitespace_is_significant);
 RawGeckoNodeBorrowedOrNull Gecko_GetLastChild(RawGeckoNodeBorrowed node);
 RawGeckoNodeBorrowedOrNull Gecko_GetFlattenedTreeParentNode(RawGeckoNodeBorrowed node);
 RawGeckoElementBorrowedOrNull Gecko_GetBeforeOrAfterPseudo(RawGeckoElementBorrowed element, bool is_before);
 nsTArray<nsIContent*>* Gecko_GetAnonymousContentForElement(RawGeckoElementBorrowed element);
+const nsTArray<RefPtr<nsINode>>* Gecko_GetAssignedNodes(RawGeckoElementBorrowed element);
 void Gecko_DestroyAnonymousContentList(nsTArray<nsIContent*>* anon_content);
 
 void Gecko_ComputedStyle_Init(mozilla::ComputedStyle* context,
                               ComputedStyleBorrowedOrNull parent_context,
                               RawGeckoPresContextBorrowed pres_context, ServoComputedDataBorrowed values,
                               mozilla::CSSPseudoElementType pseudo_type, nsAtom* pseudo_tag);
 void Gecko_ComputedStyle_Destroy(mozilla::ComputedStyle* context);
 
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -464,16 +464,17 @@ structs-types = [
     "mozilla::FontStretch",
     "mozilla::FontSlantStyle",
     "mozilla::FontWeight",
     "mozilla::MallocSizeOf",
     "mozilla::OriginFlags",
     "mozilla::UniquePtr",
     "ServoRawOffsetArc",
     "nsIContent",
+    "nsINode",
     "nsIDocument",
     "nsIDocument_DocumentTheme",
     "nsSimpleContentList",
     "MediumFeaturesChangedResult",
     "RawGeckoAnimationPropertySegment",
     "RawGeckoComputedTiming",
     "RawGeckoCSSPropertyIDList",
     "RawGeckoDocument",
--- a/servo/components/style/gecko/wrapper.rs
+++ b/servo/components/style/gecko/wrapper.rs
@@ -1108,17 +1108,27 @@ impl<'le> TElement for GeckoElement<'le>
 
         let slot: &structs::HTMLSlotElement = unsafe { mem::transmute(self.0) };
 
         if cfg!(debug_assertions) {
             let base: &RawGeckoElement = &slot._base._base._base._base;
             assert_eq!(base as *const _, self.0 as *const _, "Bad cast");
         }
 
-        let assigned_nodes: &[structs::RefPtr<structs::nsINode>] = &*slot.mAssignedNodes;
+        let assigned_nodes: &[structs::RefPtr<structs::nsINode>] =
+            if !cfg!(target_os = "android") {
+                debug_assert_eq!(
+                    unsafe { bindings::Gecko_GetAssignedNodes(self.0) },
+                    &slot.mAssignedNodes as *const _,
+                );
+
+                &*slot.mAssignedNodes
+            } else {
+                unsafe { &**bindings::Gecko_GetAssignedNodes(self.0) }
+            };
 
         debug_assert_eq!(
             mem::size_of::<structs::RefPtr<structs::nsINode>>(),
             mem::size_of::<Self::ConcreteNode>(),
             "Bad cast!"
         );
 
         unsafe { mem::transmute(assigned_nodes) }