Simplify control flow in nsXPCWrappedJS::GetNewOrUsed

RESOLVED FIXED in mozilla29

Status

()

Core
XPConnect
RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: mccr8, Assigned: mccr8)

Tracking

Trunk
mozilla29
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(8 attachments)

1.94 KB, patch
Bobby Holley (parental leave - send mail for anything urgent)
: review+
Details | Diff | Splinter Review
1.82 KB, patch
Bobby Holley (parental leave - send mail for anything urgent)
: review+
Details | Diff | Splinter Review
2.62 KB, patch
Bobby Holley (parental leave - send mail for anything urgent)
: review+
Details | Diff | Splinter Review
945 bytes, patch
Bobby Holley (parental leave - send mail for anything urgent)
: review+
Details | Diff | Splinter Review
1.08 KB, patch
Bobby Holley (parental leave - send mail for anything urgent)
: review+
Details | Diff | Splinter Review
3.55 KB, patch
Bobby Holley (parental leave - send mail for anything urgent)
: review+
Details | Diff | Splinter Review
1.06 KB, patch
Bobby Holley (parental leave - send mail for anything urgent)
: review+
Details | Diff | Splinter Review
1.58 KB, patch
Bobby Holley (parental leave - send mail for anything urgent)
: review+
Details | Diff | Splinter Review
(Assignee)

Description

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

Comment 1

4 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

4 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

4 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

4 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

4 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

4 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

4 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

4 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+
(Assignee)

Comment 11

4 years ago
Thanks for the reviews!

https://hg.mozilla.org/integration/mozilla-inbound/pushloghtml?changeset=bd14c8ecd480

I added the clazz -> clasp rename as part 9: https://hg.mozilla.org/integration/mozilla-inbound/rev/bd14c8ecd480
https://hg.mozilla.org/mozilla-central/rev/22d4298df5ce
https://hg.mozilla.org/mozilla-central/rev/ac58b9be41b1
https://hg.mozilla.org/mozilla-central/rev/38dcdb7bef22
https://hg.mozilla.org/mozilla-central/rev/aaed859bdda9
https://hg.mozilla.org/mozilla-central/rev/c2d39db1260a
https://hg.mozilla.org/mozilla-central/rev/d58e0d23b28e
https://hg.mozilla.org/mozilla-central/rev/a6163494c298
https://hg.mozilla.org/mozilla-central/rev/9f773778b44f
https://hg.mozilla.org/mozilla-central/rev/bd14c8ecd480
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla29
You need to log in before you can comment on or make changes to this bug.