Closed Bug 961551 Opened 10 years ago Closed 10 years ago

Clean up XPCWrappedJS::GetNewOrUsed some more

Categories

(Core :: XPConnect, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla29

People

(Reporter: mccr8, Assigned: mccr8)

Details

Attachments

(9 files)

      No description provided.
This reduces the length of nsXPCWrappedJS::GetNewOrUsed by 28 lines, and makes the body just barely fit all on my screen at once.

https://tbpl.mozilla.org/?tree=Try&rev=e199e1d1446c
This paves the way for smart pointerization.
Attachment #8362681 - Flags: review?(bobbyholley+bmo)
This is trickier than it looks, because this change causes additional
refcount traffic on |root| in the case where FindOrFindInherited
succeeds. This is potentially bad because if a WJS has a refcount of 1,
and no weak references to it, then if it goes to a refcount of 2 then
back to 1 it will be deleted.  A WJS can get in this state if it
is a root with a refcount of 2, and has a weak reference, then
its refcount drops to 1, then later the weak reference goes away.

However, in this case, there can be no other WJS in the chain,
or the refcount would be greater than 1, so FindOrFindInherited
must end up returning |root|, so |wrapper == root|, and the
assignment to |wrapper| will make root go to a refcount of 3,
so the release of |root| on exit will only cause the refcount to
go to 2, so |root| won't be deleted.
Attachment #8362682 - Flags: review?(bobbyholley+bmo)
GetNewOrUsed now always releases |root| when |root| is non-null, so
release_root can be eliminated.
Attachment #8362683 - Flags: review?(bobbyholley+bmo)
Attachment #8362684 - Flags: review?(bobbyholley+bmo)
Attachment #8362685 - Flags: review?(bobbyholley+bmo)
Also, move the declaration of |clasp| down to where it is used.
Attachment #8362686 - Flags: review?(bobbyholley+bmo)
The code at the end of nsXPCWrappedJS::GetNewOrUsed will now correctly
construct a root wrapper when |root == nullptr|, so we can consolidate
the two places that construct |wrapper|.
Attachment #8362687 - Flags: review?(bobbyholley+bmo)
Comment on attachment 8362680 [details] [diff] [review]
part 1 - Add root wrappers to the map in XPCWrappedJS ctor.

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

::: js/xpconnect/src/XPCWrappedJS.cpp
@@ +411,5 @@
>      NS_ADDREF_THIS();
>  
> +    if (IsRootWrapper()) {
> +        nsXPConnect::GetRuntimeInstance()->GetWrappedJSMap()->Add(cx, this);
> +     } else {

Indentation
Attachment #8362680 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8362681 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8362682 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8362683 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8362684 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8362685 - Flags: review?(bobbyholley+bmo) → review+
Attachment #8362686 - Flags: review?(bobbyholley+bmo) → review+
Comment on attachment 8362687 [details] [diff] [review]
part 8 - Use the code at the end of XPCWJS::GetNewOrUsed to build a new root wrapper.

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

Clever.
Attachment #8362687 - Flags: review?(bobbyholley+bmo) → review+
Comment on attachment 8362688 [details] [diff] [review]
part 9 - Split scope of |wrapper|, plus other cleanup.

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

::: js/xpconnect/src/XPCWrappedJS.cpp
@@ +368,1 @@
>      wrapper = new nsXPCWrappedJS(cx, jsObj, clasp, root);

How about combining these two lines into a declare + assign?
Attachment #8362688 - Flags: review?(bobbyholley+bmo) → review+
Also - I'm not sure if this is a new thing, but I'm kind of uncomfortable with writing |r=bholley| in the commit message of unreviewed patches that get published on bugzilla, since these things could float around and accidentally get committed. I always add the r= afterwards (using an interactive rebase) as a sanity-check to make sure that all patches I'm committing were r+ed. And I think doing this is important. Thoughts?
Flags: needinfo?(continuation)
> How about combining these two lines into a declare + assign?

It made the line a tiny bit wide, but I can do that.
Flags: needinfo?(continuation)
> Thoughts?

I'm not sure exactly what your concern is. Are you worried that somebody will accidentally commit a patch that is floating around in their git repo or that somebody will commit a patch that somebody else uploaded to bugzilla?  I assume the former.  Anyways, I'm pretty methodical with my patch landing, so I'm not really concerned about that personally (including looking at each bug and making sure I've addressed all review comments).  Though maybe I could write out a more explicit check list to follow.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: