Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsMarkedJSFunctionHolder< T > Class Template Reference

#include <nsJSUtils.h>

Inheritance diagram for nsMarkedJSFunctionHolder< T >:
Inheritance graph
[legend]
Collaboration diagram for nsMarkedJSFunctionHolder< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void Set (T *aPotentialFunction, nsIDOMGCParticipant *aParticipant)
already_AddRefed< TGet ()
void Get (T **aResult)

Protected Member Functions

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

Protected Attributes

nsISupports * mObject

Detailed Description

template<class T>
class nsMarkedJSFunctionHolder< T >

Definition at line 138 of file nsJSUtils.h.


Member Function Documentation

already_AddRefed< nsISupports > nsMarkedJSFunctionHolder_base::Get ( REFNSIID  aIID) [inherited]

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:

template<class T>
already_AddRefed<T> nsMarkedJSFunctionHolder< T >::Get ( ) [inline]

Definition at line 144 of file nsJSUtils.h.

Here is the caller graph for this function:

template<class T>
void nsMarkedJSFunctionHolder< T >::Get ( T **  aResult) [inline]

Definition at line 148 of file nsJSUtils.h.

                        {
    *aResult = Get().get();
  }
void nsMarkedJSFunctionHolder_base::Set ( nsISupports *  aPotentialFunction,
nsIDOMGCParticipant aParticipant 
) [inherited]

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:

template<class T>
void nsMarkedJSFunctionHolder< T >::Set ( T aPotentialFunction,
nsIDOMGCParticipant aParticipant 
) [inline]

Definition at line 141 of file nsJSUtils.h.

                                                                     {
    nsMarkedJSFunctionHolder_base::Set(aPotentialFunction, aParticipant);
  }

Here is the caller graph for this function:

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

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

nsISupports* nsMarkedJSFunctionHolder_base::mObject [inherited]

Definition at line 134 of file nsJSUtils.h.


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