Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Static Private Attributes
nsMutationGuard Class Reference

Class used to detect unexpected mutations. More...

#include <nsGenericElement.h>

List of all members.

Public Member Functions

 nsMutationGuard ()
 ~nsMutationGuard ()
PRBool Mutated (PRUint8 aIgnoreCount)
 Returns true if any unexpected mutations have occured.

Static Public Member Functions

static void DidMutate ()

Private Types

enum  { eMaxMutations = 300 }

Private Attributes

PRUint32 mDelta

Static Private Attributes

static PRUint32 sMutationCount = 0

Detailed Description

Class used to detect unexpected mutations.

To use the class create an nsMutationGuard on the stack before unexpected mutations could occur. You can then at any time call Mutated to check if any unexpected mutations have occured.

When a guard is instantiated sMutationCount is set to 300. It is then decremented by every mutation (capped at 0). This means that we can only detect 300 mutations during the lifetime of a single guard, however that should be more then we ever care about as we usually only care if more then one mutation has occured.

When the guard goes out of scope it will adjust sMutationCount so that over the lifetime of the guard the guard itself has not affected sMutationCount, while mutations that happened while the guard was alive still will. This allows a guard to be instantiated even if there is another guard higher up on the callstack watching for mutations.

The only thing that has to be avoided is for an outer guard to be used while an inner guard is alive. This can be avoided by only ever instantiating a single guard per scope and only using the guard in the current scope.

Definition at line 373 of file nsGenericElement.h.

Member Enumeration Documentation

anonymous enum [private]

Definition at line 413 of file nsGenericElement.h.

{ eMaxMutations = 300 };

Constructor & Destructor Documentation

Definition at line 375 of file nsGenericElement.h.

    mDelta = eMaxMutations - sMutationCount;
    sMutationCount = eMaxMutations;

Definition at line 380 of file nsGenericElement.h.

Member Function Documentation

static void nsMutationGuard::DidMutate ( ) [inline, static]

Definition at line 398 of file nsGenericElement.h.

    if (sMutationCount) {

Here is the caller graph for this function:

PRBool nsMutationGuard::Mutated ( PRUint8  aIgnoreCount) [inline]

Returns true if any unexpected mutations have occured.

You can pass in an 8-bit ignore count to ignore a number of expected mutations.

Definition at line 390 of file nsGenericElement.h.

    return sMutationCount < NS_STATIC_CAST(PRUint32, eMaxMutations - aIgnoreCount);

Here is the caller graph for this function:

Member Data Documentation

Definition at line 409 of file nsGenericElement.h.

Definition at line 419 of file nsGenericElement.h.

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