Simplify control flow in nsXPCWrappedJS::GetNewOrUsed

RESOLVED FIXED in mozilla29

Status

()

RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: mccr8, Assigned: mccr8)

Tracking

Trunk
mozilla29
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(8 attachments)

(Assignee)

Description

5 years ago
Lot of gotos in there.
(Assignee)

Comment 1

5 years ago
Created attachment 8351197 [details] [diff] [review]
part 1 - Use smart pointer for clazz in nsXPCWrappedJS::GetNewOrUsed.

try run: https://tbpl.mozilla.org/?tree=Try&rev=20caa5300e5e

The trickiest thing the goto in GetNewOrUsed does is release clazz in some cases,
so using a smart pointer will simplify things.
Attachment #8351197 - Flags: review?(bobbyholley+bmo)
(Assignee)

Comment 2

5 years ago
Created attachment 8351198 [details] [diff] [review]
part 2 - Take advantage of new being infallible in nsXPCWrappedJS::GetNewOrUsed.
Attachment #8351198 - Flags: review?(bobbyholley+bmo)
(Assignee)

Comment 3

5 years ago
Created attachment 8351199 [details] [diff] [review]
part 3 - Eliminate goto return_wrapper.

Substitute in the tail of the function for each goto, then eliminate
the resulting branches where possible.
Attachment #8351199 - Flags: review?(bobbyholley+bmo)
(Assignee)

Comment 4

5 years ago
Created attachment 8351200 [details] [diff] [review]
part 4 - Eliminate now-unnecessary null check in nsXPCWrappedJS::GetNewOrUsed.
Attachment #8351200 - Flags: review?(bobbyholley+bmo)
(Assignee)

Comment 5

5 years ago
Created attachment 8351201 [details] [diff] [review]
part 5 - The null check at the end of nsXPCWrappedJS::GetNewOrUsed will always fail.
Attachment #8351201 - Flags: review?(bobbyholley+bmo)
(Assignee)

Comment 6

5 years ago
Created attachment 8351202 [details] [diff] [review]
part 6 - Add and use nsXPCWrappedJS::FindOrFindInherited.

FindInherited is only ever used after running Find, and the way the checks
are chained is a little weird.
Attachment #8351202 - Flags: review?(bobbyholley+bmo)
(Assignee)

Comment 7

5 years ago
Created attachment 8351203 [details] [diff] [review]
part 7 - Replace if with else in nsXPCWrappedJS::GetNewOrUsed.

We check for root, then don't change root and check for !root, so this can just be
an else.
Attachment #8351203 - Flags: review?(bobbyholley+bmo)
(Assignee)

Comment 8

5 years ago
Created attachment 8351204 [details] [diff] [review]
part 8 - Insert non-root wrappers into the list in the constructor for nsXPCWrappedJS.

A non-root wrapper has to be inserted into the list. There's only one place this is needed, but I
think it makes more sense like this.
Attachment #8351204 - Flags: review?(bobbyholley+bmo)
Comment on attachment 8351197 [details] [diff] [review]
part 1 - Use smart pointer for clazz in nsXPCWrappedJS::GetNewOrUsed.

Could you rename clazz to clasp while you're at it? Doing it in a followup patch is fine.
Attachment #8351197 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8351198 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8351199 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8351200 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8351201 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8351202 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8351203 - Flags: review?(bobbyholley+bmo) → review+
Comment on attachment 8351204 [details] [diff] [review]
part 8 - Insert non-root wrappers into the list in the constructor for nsXPCWrappedJS.

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

Nice.
Attachment #8351204 - Flags: review?(bobbyholley+bmo) → review+
You need to log in before you can comment on or make changes to this bug.