Closed Bug 1234676 Opened 8 years ago Closed 8 years ago

nsComputedDOMStyle accessors should return already_AddRefed objects, instead of raw pointers to 0-refcount objects

Categories

(Core :: CSS Parsing and Computation, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla46
Tracking Status
firefox46 --- fixed

People

(Reporter: dholbert, Assigned: dholbert)

References

Details

Attachments

(7 files, 1 obsolete file)

nsComputedDOMStyle has a bunch of per-property getters, whose return value is described by this comment:
>  // All of the property getters below return a pointer to a refcounted object
>  // that has just been created, but the refcount is still 0. Caller must take
>  // ownership.
(This comment dates back to bug 585867, mozilla-central changeset 39ec013827f5.)
 
This pattern (returning a refcounted object w/ refcount=0) is odd & awkward, and it forces us to use bad coding practices inside of these functions. (It forces us to store new refcounted things in raw pointers, instead of RefPtrs.)

We should change these functions to return already_AddRefed<CSSValue>, so that their implementations can use RefPtr<> internally and return foo.forget(); at the end.
Depends on: 1234707
First part is to add & use a private CSSValue typedef in the .h file, so we don't end up with the super-long expression
  already_AddRefed<mozilla::dom::CSSValue>
as the return type of all of these methods.

This patch builds successfully on its own.
Assignee: nobody → dholbert
Status: NEW → ASSIGNED
Part 2 (the main change here) will be split into two sub-parts.

This first part just changes the function signatures of these getters and some associated helper-functions.
Attachment #8701951 - Attachment description: part 2a: Change function signature of DoGetXYZ functions (and associated helpers) → part 2a: Change function signature of DoGetXYZ functions & helpers (but don't change the code)
Attachment #8701951 - Attachment description: part 2a: Change function signature of DoGetXYZ functions & helpers (but don't change the code) → part 2a: Change function signature of DoGetXYZ functions & helpers (but don't change the impl)
Attachment #8701948 - Flags: review?(cam)
Attachment #8701951 - Flags: review?(cam)
...and this part changes the implementations of the functions whose signatures we modified in part 2a.

(I'll fold this together with 2a before landing, since we need both in order to build successfully.)
Attachment #8701953 - Flags: review?(cam)
Notes to assist in skimming / comfortability-with-skimming when reviewing here:
 - Part 1 is a typedef + search-and-replace (and doesn't change the code at all).
 - Part 2a was basically a search-and-replace of the return-value-type in function signatures.
 - Part 2b was several search-and-replaces, for local variables:
     s/nsROCSSPrimitiveValue */RefPtr<nsROCSSPrimitiveValue>/
     s/nsDOMCSSValueList *valueList/RefPtr<nsDOMCSSValueList>/
        (along with the other *-snuggling way of writing these pointers)
     s/return val;/return val.forget();/
     s/return value;/return value.forget();/
     s/return valueList;/return valueList.forget();/

I left just 12 "nsROCSSPrimitiveValue *" local-variables untouched -- those variables are passed to the nsDOMCSSRect constructor (happens twice) and the nsDOMCSSRGBColor constructor (happens once), and we'd need to fix those before we convert these local variables. That should be done separately, if it's worth doing.

Finally: I'll post one more part, "part 3", to cleanup XXX comments that I added in bug 1234707, which we can now address.
This final part removes the now-unneeded local variables which I introduced in bug 1234707 part 4 ("special handling") with XXXdholbert comments.  See bug 1234707 comment 10 & 12 for background on these (why these variables were introduced, & why they can go away now that we have already_AddRefed<> as the return value of the function that they're in and/or the function whose value they were capturing.)
Attachment #8701960 - Flags: review?(cam)
Attachment #8701961 - Attachment is patch: true
Sorry for the lack of patch-context in these -- I did that locally to reduce likelihood of (& amount of pain caused by) bitrot.

I'd suggest reviewing with a merge tool anyway -- if it's handy, these patches are layered on top of mozilla-central changeset 6c49bb716593 (currently only on m-i, but will be merged to m-c soon I expect).
(Happy to repost with more context if that's useful though.)
Realized I need one last change here -- I need to get rid of the now-obsolete comment that I quoted in comment 0 here.

(We don't really need a replacement; already_AddRefed<> is self-documenting about the refcount status.)
Attachment #8701962 - Flags: review?(cam)
Try run (looks good modulo intermittents I think): https://treeherder.mozilla.org/#/jobs?repo=try&revision=d0f9ae6013ec
Comment on attachment 8701948 [details] [diff] [review]
part 1: add & use a typedef for CSSValue in .h file

Review of attachment 8701948 [details] [diff] [review]:
-----------------------------------------------------------------

::: layout/style/nsComputedDOMStyle.h
@@ +49,4 @@
>  {
>  public:
>    typedef nsCSSProps::KTableEntry KTableEntry;
> +  typedef mozilla::dom::CSSValue CSSValue;

In comment 1 you said this would be a private typedef; did you mean to add it down lower in the file?  (KTableEntry could well become private too.)
Attachment #8701948 - Flags: review?(cam) → review+
Comment on attachment 8701951 [details] [diff] [review]
part 2a: Change function signature of DoGetXYZ functions & helpers (but don't change the impl)

Review of attachment 8701951 [details] [diff] [review]:
-----------------------------------------------------------------

::: layout/style/nsComputedDOMStyle.h
@@ +131,1 @@
>                                                 bool aAlignTrue,

Please fix the indenting of this and other multi-line declarations.
Attachment #8701951 - Flags: review?(cam) → review+
(In reply to Cameron McCormack (:heycam) (away Jan 1-3) from comment #11)
> In comment 1 you said this would be a private typedef; did you mean to add
> it down lower in the file?  (KTableEntry could well become private too.)

Oh, right you are. Here's the patch with that changed. (I made sure it still compiles.)  Carrying forward r+.
Attachment #8701948 - Attachment is obsolete: true
Attachment #8702386 - Flags: review+
(In reply to Cameron McCormack (:heycam) (away Jan 1-3) from comment #12)
> Please fix the indenting of this and other multi-line declarations.

Will do; I'll post that as a whitespace-only final patch here, with rs=you (rubberstamp)
Attachment #8701953 - Flags: review?(cam) → review+
(Here's the final patch to fix up indentation in decls & rewrap some too-long decls, per comment 12. I'm calling this rubberstamped, but comments are welcome if you feel like skimming it.)
Attachment #8702389 - Flags: review+
Attachment #8701960 - Flags: review?(cam) → review+
Attachment #8701962 - Flags: review?(cam) → review+
Comment on attachment 8702389 [details] [diff] [review]
part 5: fix indentation & rewrap too-long decls [rs=heycam]

Looks fine, thanks.
Flags: in-testsuite-
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: