Back to index

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

#include <xpcprivate.h>

Collaboration diagram for AutoScriptEvaluate:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 AutoScriptEvaluate (JSContext *cx)
 Saves the JSContext as well as initializing our state.
void StartEvaluating (JSErrorReporter errorReporter=nsnull)
 Does the pre script evaluation and sets the error reporter if given This function should only be called once, and will assert if called more than once.
 ~AutoScriptEvaluate ()
 Does the post script evaluation and resets the error reporter.

Private Member Functions

 AutoScriptEvaluate (const AutoScriptEvaluate &)
AutoScriptEvaluateoperator= (const AutoScriptEvaluate &)

Private Attributes

JSContextmJSContext
JSExceptionStatemState
JSErrorReporter mOldErrorReporter
PRBool mEvaluated
jsword mContextHasThread

Detailed Description

Definition at line 3277 of file xpcprivate.h.


Constructor & Destructor Documentation

Saves the JSContext as well as initializing our state.

Parameters:
cxThe JSContext, this can be null, we don't do anything then

Definition at line 3284 of file xpcprivate.h.

Does the post script evaluation and resets the error reporter.

Definition at line 80 of file xpcwrappedjsclass.cpp.

{
    if(!mJSContext || !mEvaluated)
        return;
    if(mState)
        JS_RestoreExceptionState(mJSContext, mState);
    else
        JS_ClearPendingException(mJSContext);

    if(mContextHasThread)
        JS_EndRequest(mJSContext);

    // If this is a JSContext that has a private context that provides a
    // nsIXPCScriptNotify interface, then notify the object the script has
    // been executed.
    //
    // Note: We rely on the rule that if any JSContext in our JSRuntime has
    // private data that points to an nsISupports subclass, it has also set
    // the JSOPTION_PRIVATE_IS_NSISUPPORTS option.

    if (JS_GetOptions(mJSContext) & JSOPTION_PRIVATE_IS_NSISUPPORTS)
    {
        nsCOMPtr<nsIXPCScriptNotify> scriptNotify = 
            do_QueryInterface(NS_STATIC_CAST(nsISupports*,
                                             JS_GetContextPrivate(mJSContext)));
        if(scriptNotify)
            scriptNotify->ScriptExecuted();
    }
    JS_SetErrorReporter(mJSContext, mOldErrorReporter);
}

Here is the call graph for this function:


Member Function Documentation

AutoScriptEvaluate& AutoScriptEvaluate::operator= ( const AutoScriptEvaluate ) [private]
void AutoScriptEvaluate::StartEvaluating ( JSErrorReporter  errorReporter = nsnull)

Does the pre script evaluation and sets the error reporter if given This function should only be called once, and will assert if called more than once.

Parameters:
errorReporterthe error reporter callback function to set

Definition at line 51 of file xpcwrappedjsclass.cpp.

{
    NS_PRECONDITION(!mEvaluated, "AutoScriptEvaluate::Evaluate should only be called once");

    if(!mJSContext)
        return;
    mEvaluated = PR_TRUE;
    mOldErrorReporter = JS_SetErrorReporter(mJSContext, errorReporter);
    mContextHasThread = JS_GetContextThread(mJSContext);
    if (mContextHasThread)
        JS_BeginRequest(mJSContext);

    // Saving the exception state keeps us from interfering with another script
    // that may also be running on this context.  This occurred first with the
    // js debugger, as described in
    // http://bugzilla.mozilla.org/show_bug.cgi?id=88130 but presumably could
    // show up in any situation where a script calls into a wrapped js component
    // on the same context, while the context has a nonzero exception state.
    // Because JS_SaveExceptionState/JS_RestoreExceptionState use malloc
    // and addroot, we avoid them if possible by returning null (as opposed to
    // a JSExceptionState with no information) when there is no pending
    // exception.
    if(JS_IsExceptionPending(mJSContext))
    {
        mState = JS_SaveExceptionState(mJSContext);
        JS_ClearPendingException(mJSContext);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 3305 of file xpcprivate.h.

Definition at line 3304 of file xpcprivate.h.

Definition at line 3301 of file xpcprivate.h.

JSErrorReporter AutoScriptEvaluate::mOldErrorReporter [private]

Definition at line 3303 of file xpcprivate.h.

Definition at line 3302 of file xpcprivate.h.


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