Bug 1275913 - Use already_addrefed properly when dealing with arcs sent from servo to gecko; r=bholley

MozReview-Commit-ID: 5FDS8J2Fo1G

--HG--
extra : rebase_source : ecbcb3c2eff5a390a24ab97f93899c87a463c791
This commit is contained in:
Manish Goregaokar 2016-08-16 10:38:46 +05:30
Родитель 6519960758
Коммит 3f96d89612
5 изменённых файлов: 38 добавлений и 16 удалений

Просмотреть файл

@ -76,7 +76,7 @@ ServoRestyleManager::RecreateStyleContexts(nsIContent* aContent,
if (aContent->IsDirtyForServo()) {
RefPtr<ServoComputedValues> computedValues =
dont_AddRef(Servo_GetComputedValues(aContent));
Servo_GetComputedValues(aContent).Consume();
MOZ_ASSERT(computedValues);
// NB: Change hint processing only applies to elements, at least until we

Просмотреть файл

@ -26,6 +26,17 @@
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/dom/Element.h"
#define IMPL_STRONG_REF_TYPE(name, T) \
already_AddRefed<T> name::Consume() { \
RefPtr<T> result = dont_AddRef(mPtr); \
mPtr = nullptr; \
return result.forget(); \
};
IMPL_STRONG_REF_TYPE(ServoComputedValuesStrong, ServoComputedValues);
IMPL_STRONG_REF_TYPE(RawServoStyleSheetStrong, RawServoStyleSheet);
uint32_t
Gecko_ChildrenCount(RawGeckoNode* aNode)
{

Просмотреть файл

@ -16,6 +16,13 @@
#include "nsStyleStruct.h"
#include "stdint.h"
#define DEFINE_STRONG_REF_TYPE(name, T) \
MOZ_MUST_USE_TYPE \
struct name { \
T* mPtr; \
already_AddRefed<T> Consume(); \
}
/*
* API for Servo to access Gecko data structures. This file must compile as valid
* C code in order for the binding generator to parse it.
@ -45,6 +52,10 @@ typedef nsIDocument RawGeckoDocument;
struct ServoNodeData;
struct ServoComputedValues;
struct RawServoStyleSheet;
/** <div rustbindgen private></div> */
DEFINE_STRONG_REF_TYPE(ServoComputedValuesStrong, ServoComputedValues);
/** <div rustbindgen private></div> */
DEFINE_STRONG_REF_TYPE(RawServoStyleSheetStrong, RawServoStyleSheet);
struct RawServoStyleSet;
class nsHTMLCSSStyleSheet;
struct nsStyleList;
@ -221,7 +232,7 @@ NS_DECL_THREADSAFE_FFI_REFCOUNTING(nsStyleCoord::Calc, Calc);
//
// TODO: Make these return already_AddRefed and UniquePtr when the binding
// generator is smart enough to handle them.
RawServoStyleSheet* Servo_StylesheetFromUTF8Bytes(
RawServoStyleSheetStrong Servo_StylesheetFromUTF8Bytes(
const uint8_t* bytes, uint32_t length,
mozilla::css::SheetParsingMode parsing_mode,
const uint8_t* base_bytes, uint32_t base_length,
@ -255,16 +266,16 @@ bool Servo_CSSSupports(const uint8_t* name, uint32_t name_length,
const uint8_t* value, uint32_t value_length);
// Computed style data.
ServoComputedValues* Servo_GetComputedValues(RawGeckoNode* node);
ServoComputedValues* Servo_GetComputedValuesForAnonymousBox(ServoComputedValues* parentStyleOrNull,
ServoComputedValuesStrong Servo_GetComputedValues(RawGeckoNode* node);
ServoComputedValuesStrong Servo_GetComputedValuesForAnonymousBox(ServoComputedValues* parentStyleOrNull,
nsIAtom* pseudoTag,
RawServoStyleSet* set);
ServoComputedValues* Servo_GetComputedValuesForPseudoElement(ServoComputedValues* parent_style,
ServoComputedValuesStrong Servo_GetComputedValuesForPseudoElement(ServoComputedValues* parent_style,
RawGeckoElement* match_element,
nsIAtom* pseudo_tag,
RawServoStyleSet* set,
bool is_probe);
ServoComputedValues* Servo_InheritComputedValues(ServoComputedValues* parent_style);
ServoComputedValuesStrong Servo_InheritComputedValues(ServoComputedValues* parent_style);
void Servo_AddRefComputedValues(ServoComputedValues*);
void Servo_ReleaseComputedValues(ServoComputedValues*);

Просмотреть файл

@ -96,7 +96,7 @@ ServoStyleSet::GetContext(nsIContent* aContent,
nsIAtom* aPseudoTag,
CSSPseudoElementType aPseudoType)
{
RefPtr<ServoComputedValues> computedValues = dont_AddRef(Servo_GetComputedValues(aContent));
RefPtr<ServoComputedValues> computedValues = Servo_GetComputedValues(aContent).Consume();
MOZ_ASSERT(computedValues);
return GetContext(computedValues.forget(), aParentContext, aPseudoTag, aPseudoType);
}
@ -145,7 +145,7 @@ ServoStyleSet::ResolveStyleForOtherNonElement(nsStyleContext* aParentContext)
// with the root of an anonymous subtree.
ServoComputedValues* parent =
aParentContext ? aParentContext->StyleSource().AsServoComputedValues() : nullptr;
RefPtr<ServoComputedValues> computedValues = dont_AddRef(Servo_InheritComputedValues(parent));
RefPtr<ServoComputedValues> computedValues = Servo_InheritComputedValues(parent).Consume();
MOZ_ASSERT(computedValues);
return GetContext(computedValues.forget(), aParentContext,
@ -167,9 +167,9 @@ ServoStyleSet::ResolvePseudoElementStyle(Element* aParentElement,
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
RefPtr<ServoComputedValues> computedValues =
dont_AddRef(Servo_GetComputedValuesForPseudoElement(
Servo_GetComputedValuesForPseudoElement(
aParentContext->StyleSource().AsServoComputedValues(),
aParentElement, pseudoTag, mRawSet.get(), /* is_probe = */ false));
aParentElement, pseudoTag, mRawSet.get(), /* is_probe = */ false).Consume();
MOZ_ASSERT(computedValues);
return GetContext(computedValues.forget(), aParentContext, pseudoTag, aType);
@ -191,8 +191,8 @@ ServoStyleSet::ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag,
aParentContext ? aParentContext->StyleSource().AsServoComputedValues()
: nullptr;
RefPtr<ServoComputedValues> computedValues =
dont_AddRef(Servo_GetComputedValuesForAnonymousBox(parentStyle, aPseudoTag,
mRawSet.get()));
Servo_GetComputedValuesForAnonymousBox(parentStyle, aPseudoTag,
mRawSet.get()).Consume();
#ifdef DEBUG
if (!computedValues) {
nsString pseudo;
@ -362,9 +362,9 @@ ServoStyleSet::ProbePseudoElementStyle(Element* aParentElement,
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
RefPtr<ServoComputedValues> computedValues =
dont_AddRef(Servo_GetComputedValuesForPseudoElement(
Servo_GetComputedValuesForPseudoElement(
aParentContext->StyleSource().AsServoComputedValues(),
aParentElement, pseudoTag, mRawSet.get(), /* is_probe = */ true));
aParentElement, pseudoTag, mRawSet.get(), /* is_probe = */ true).Consume();
if (!computedValues) {
return nullptr;

Просмотреть файл

@ -86,11 +86,11 @@ ServoStyleSheet::ParseSheet(const nsAString& aInput,
aBaseURI->GetSpec(baseString);
NS_ConvertUTF16toUTF8 input(aInput);
mSheet = already_AddRefed<RawServoStyleSheet>(Servo_StylesheetFromUTF8Bytes(
mSheet = Servo_StylesheetFromUTF8Bytes(
reinterpret_cast<const uint8_t*>(input.get()), input.Length(),
mParsingMode,
reinterpret_cast<const uint8_t*>(baseString.get()), baseString.Length(),
base, referrer, principal));
base, referrer, principal).Consume();
}
void