Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
nsMarkedJSFunctionHolder_base Class Reference

nsMarkedJSFunctionHolder<T> is used to store objects of XPCOM interface T. More...

#include <nsJSUtils.h>

Inheritance diagram for nsMarkedJSFunctionHolder_base:
Inheritance graph
[legend]
Collaboration diagram for nsMarkedJSFunctionHolder_base:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void Set (nsISupports *aPotentialFunction, nsIDOMGCParticipant *aParticipant)
already_AddRefed< nsISupports > Get (REFNSIID aIID)
 nsMarkedJSFunctionHolder_base ()
 ~nsMarkedJSFunctionHolder_base ()
PRBool TryMarkedSet (nsISupports *aPotentialFunction, nsIDOMGCParticipant *aParticipant)

Public Attributes

nsISupports * mObject

Detailed Description

nsMarkedJSFunctionHolder<T> is used to store objects of XPCOM interface T.

If the object stored is an XPConnect wrapped JS object and the wrapper can be preserved through nsDOMClassInfo, the holder will hold a weak reference and preserve the object from garbage collection as long as the garbage collector can reach |aParticipant|; once both |aParticipant| and the object are unreachable it will be garbage collected and the holder will hold null.

Otherwise, it holds a strong reference.

Definition at line 123 of file nsJSUtils.h.


Constructor & Destructor Documentation

Definition at line 129 of file nsJSUtils.h.

Definition at line 335 of file nsJSUtils.cpp.

{
  if (PRWord(mObject) & MARKED_OBJECT_BIT) {
    nsDOMClassInfo::ReleaseWrapper(this);
  }
  nsISupports *obj = (nsISupports*)(PRWord(mObject) & ~MARKED_OBJECT_BIT);
  NS_IF_RELEASE(obj);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 317 of file nsJSUtils.cpp.

{
  nsISupports *result;
  if (PRWord(mObject) & MARKED_OBJECT_BIT) {
    nsIWeakReference* weakRef =
      (nsIWeakReference*)(PRWord(mObject) & ~MARKED_OBJECT_BIT);
    nsresult rv =
      weakRef->QueryReferent(aIID, NS_REINTERPRET_CAST(void**, &result));
    if (NS_FAILED(rv)) {
      NS_NOTREACHED("GC preservation didn't work");
      result = nsnull;
    }
  } else {
    NS_IF_ADDREF(result = mObject);
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsMarkedJSFunctionHolder_base::Set ( nsISupports *  aPotentialFunction,
nsIDOMGCParticipant aParticipant 
)

Definition at line 249 of file nsJSUtils.cpp.

{
  if (PRWord(mObject) & MARKED_OBJECT_BIT) {
    nsDOMClassInfo::ReleaseWrapper(this);
  }
  nsISupports *oldVal = (nsISupports*)(PRWord(mObject) & ~MARKED_OBJECT_BIT);
  if (!TryMarkedSet(aPotentialFunction, aParticipant)) {
    NS_ASSERTION((PRWord(aPotentialFunction) & MARKED_OBJECT_BIT) == 0,
                 "low bit set");
    NS_IF_ADDREF(aPotentialFunction);
    mObject = aPotentialFunction;
  }
  NS_IF_RELEASE(oldVal);
}

Here is the call graph for this function:

PRBool nsMarkedJSFunctionHolder_base::TryMarkedSet ( nsISupports *  aPotentialFunction,
nsIDOMGCParticipant aParticipant 
)

Definition at line 287 of file nsJSUtils.cpp.

{
  if (!aParticipant)
    return PR_FALSE;

  nsCOMPtr<nsIXPConnectWrappedJS_MOZILLA_1_8_BRANCH> wrappedJS =
    do_QueryInterface(aPotentialFunction);
  if (!wrappedJS) // a non-JS implementation
    return PR_FALSE;

  // XXX We really only need to pass PR_TRUE for
  // root-if-externally-referenced if this is an onload, onerror,
  // onreadystatechange, etc., so we could pass the responsibility for
  // choosing that to the caller.
  nsresult rv =
    nsDOMClassInfo::PreserveWrapper(this, HolderToWrappedJS, aParticipant,
                                    PR_TRUE);
  NS_ENSURE_SUCCESS(rv, PR_FALSE);

  nsIWeakReference* weakRef; // [STRONG]
  wrappedJS->GetWeakReference(&weakRef);
  NS_ENSURE_TRUE(weakRef, PR_FALSE);

  NS_ASSERTION((PRWord(weakRef) & MARKED_OBJECT_BIT) == 0, "low bit set");
  mObject = (nsISupports*)(PRWord(weakRef) | MARKED_OBJECT_BIT);
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 134 of file nsJSUtils.h.


The documentation for this class was generated from the following files: