Back to index

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

#include <jsd_xpc.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_JSDISCRIPT
NS_DECL_JSDIEPHEMERAL 
jsdScript (JSDContext *aCx, JSDScript *aScript)
virtual ~jsdScript ()
void clearProfileData ()
 Clear profile data for this script.
unsigned long pcToLine (in unsigned long pc, in unsigned long pcmap)
 Get the closest line number to a given PC.
unsigned long lineToPc (in unsigned long line, in unsigned long pcmap)
 Get the first PC associated with a line.
boolean isLineExecutable (in unsigned long line, in unsigned long pcmap)
 Determine is a particular line is executable, like checking that lineToPc == pcToLine, except in one call.
void setBreakpoint (in unsigned long pc)
 Set a breakpoint at a PC in this script.
void clearBreakpoint (in unsigned long pc)
 Clear a breakpoint at a PC in this script.
void clearAllBreakpoints ()
 Clear all breakpoints set in this script.
void invalidate ()
 Mark this instance as invalid.

Static Public Member Functions

static jsdIScriptFromPtr (JSDContext *aCx, JSDScript *aScript)
static void InvalidateAll ()

Public Attributes

readonly attribute JSDContext JSDContext
 Internal use only.
readonly attribute JSDScript JSDScript
 Internal use only.
readonly attribute long version
 Last version set on this context.
readonly attribute unsigned long tag
 Tag value guaranteed unique among jsdIScript objects.
const unsigned long FLAG_PROFILE = 0x01
 FLAG_* values need to be kept in sync with JSD_SCRIPT_* #defines in jsdebug.h.
const unsigned long FLAG_DEBUG = 0x02
 Determines whether or not to ignore breakpoints, etc.
attribute unsigned long flags
 FLAG_* attributes from above, OR'd together.
readonly attribute string fileName
 Filename given for this script when it was compiled.
readonly attribute string functionName
 Function name for this script.
readonly attribute jsdIValue functionObject
 Fetch the function object as a jsdIValue.
readonly attribute AString functionSource
 Source code for this script, without function declaration.
readonly attribute unsigned long baseLineNumber
 Line number in source file containing the first line of this script.
readonly attribute unsigned long lineExtent
 Total number of lines in this script.
readonly attribute unsigned long callCount
 Number of times this script has been called.
readonly attribute unsigned long maxRecurseDepth
 Number of times this script called itself, directly or indirectly.
readonly attribute double minExecutionTime
 Shortest execution time recorded, in milliseconds.
readonly attribute double maxExecutionTime
 Longest execution time recorded, in milliseconds.
readonly attribute double totalExecutionTime
 Total time spent in this function, in milliseconds.
readonly attribute double minOwnExecutionTime
 Shortest execution time recorded, in milliseconds, excluding time spent in other called code.
readonly attribute double maxOwnExecutionTime
 Longest execution time recorded, in milliseconds, excluding time spent in other called code.
readonly attribute double totalOwnExecutionTime
 Total time spent in this function, in milliseconds, excluding time spent in other called code.
const unsigned long PCMAP_SOURCETEXT = 1
const unsigned long PCMAP_PRETTYPRINT = 2
readonly attribute boolean isValid
 |true| if this object is still valid.

Private Member Functions

 jsdScript ()
 jsdScript (const jsdScript &)
PCMapEntryCreatePPLineMap ()
PRUint32 PPPcToLine (PRUint32 aPC)
PRUint32 PPLineToPc (PRUint32 aLine)

Private Attributes

PRBool mValid
PRUint32 mTag
JSDContextmCx
JSDScriptmScript
nsCStringmFileName
nsCStringmFunctionName
PRUint32 mBaseLineNumber
PRUint32 mLineExtent
PCMapEntrymPPLineMap
PRUint32 mPCMapSize
jsuword mFirstPC

Static Private Attributes

static PRUint32 LastTag = 0

Detailed Description

Definition at line 133 of file jsd_xpc.h.


Constructor & Destructor Documentation

jsdScript::jsdScript ( JSDContext aCx,
JSDScript aScript 
)

Definition at line 969 of file jsd_xpc.cpp.

Here is the call graph for this function:

jsdScript::~jsdScript ( ) [virtual]

Definition at line 998 of file jsd_xpc.cpp.

{
    DEBUG_DESTROY ("jsdScript", gScriptCount);
    if (mFileName)
        delete mFileName;
    if (mFunctionName)
        delete mFunctionName;

    if (mPPLineMap)
        PR_Free(mPPLineMap);

    /* Invalidate() needs to be called to release an owning reference to
     * ourselves, so if we got here without being invalidated, something
     * has gone wrong with our ref count. */
    NS_ASSERTION (!mValid, "Script destroyed without being invalidated.");
}
jsdScript::jsdScript ( ) [private]

Here is the caller graph for this function:


Member Function Documentation

Clear all breakpoints set in this script.

void jsdIScript::clearBreakpoint ( in unsigned long  pc) [inherited]

Clear a breakpoint at a PC in this script.

Clear profile data for this script.

Definition at line 1021 of file jsd_xpc.cpp.

{    
    JSContext  *cx  = JSD_GetDefaultJSContext (mCx);
    JSObject   *obj = JS_NewObject(cx, NULL, NULL, NULL);
    JSFunction *fun = JSD_GetJSFunction (mCx, mScript);
    JSScript   *script;
    PRUint32    baseLine;
    PRBool      scriptOwner = PR_FALSE;
    
    if (fun) {
        if (fun->nargs > 12)
            return nsnull;
        JSString *jsstr = JS_DecompileFunctionBody (cx, fun, 4);
        if (!jsstr)
            return nsnull;
    
        const char *argnames[] = {"arg1", "arg2", "arg3", "arg4", 
                                  "arg5", "arg6", "arg7", "arg8",
                                  "arg9", "arg10", "arg11", "arg12" };
        fun = JS_CompileUCFunction (cx, obj, "ppfun", fun->nargs, argnames,
                                    JS_GetStringChars(jsstr),
                                    JS_GetStringLength(jsstr),
                                    "x-jsd:ppbuffer?type=function", 3);
        if (!fun || !(script = JS_GetFunctionScript(cx, fun)))
            return nsnull;
        baseLine = 3;
    } else {
        JSString *jsstr = JS_DecompileScript (cx, JSD_GetJSScript(mCx, mScript),
                                              "ppscript", 4);
        if (!jsstr)
            return nsnull;

        script = JS_CompileUCScript (cx, obj,
                                     JS_GetStringChars(jsstr),
                                     JS_GetStringLength(jsstr),
                                     "x-jsd:ppbuffer?type=script", 1);
        if (!script)
            return nsnull;
        scriptOwner = PR_TRUE;
        baseLine = 1;
    }
        
    PRUint32 scriptExtent = JS_GetScriptLineExtent (cx, script);
    jsbytecode* firstPC = JS_LineNumberToPC (cx, script, 0);
    /* allocate worst case size of map (number of lines in script + 1
     * for our 0 record), we'll shrink it with a realloc later. */
    mPPLineMap = 
        NS_STATIC_CAST(PCMapEntry *,
                       PR_Malloc((scriptExtent + 1) * sizeof (PCMapEntry)));
    if (mPPLineMap) {             
        mPCMapSize = 0;
        for (PRUint32 line = baseLine; line < scriptExtent + baseLine; ++line) {
            jsbytecode* pc = JS_LineNumberToPC (cx, script, line);
            if (line == JS_PCToLineNumber (cx, script, pc)) {
                mPPLineMap[mPCMapSize].line = line;
                mPPLineMap[mPCMapSize].pc = pc - firstPC;
                ++mPCMapSize;
            }
        }
        if (scriptExtent != mPCMapSize) {
            mPPLineMap =
                NS_STATIC_CAST(PCMapEntry *,
                               PR_Realloc(mPPLineMap,
                                          mPCMapSize * sizeof(PCMapEntry)));
        }
    }

    if (scriptOwner)
        JS_DestroyScript (cx, script);

    return mPPLineMap;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static jsdIScript* jsdScript::FromPtr ( JSDContext aCx,
JSDScript aScript 
) [inline, static]

Definition at line 144 of file jsd_xpc.h.

    {
        if (!aScript)
            return nsnull;

        void *data = JSD_GetScriptPrivate (aScript);
        jsdIScript *rv;
        
        if (data) {
            rv = NS_STATIC_CAST(jsdIScript *, data);
        } else {
            rv = new jsdScript (aCx, aScript);
            NS_IF_ADDREF(rv);  /* addref for the SetScriptPrivate, released in
                                * Invalidate() */
            JSD_SetScriptPrivate (aScript, NS_STATIC_CAST(void *, rv));
        }
        
        NS_IF_ADDREF(rv); /* addref for return value */
        return rv;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Mark this instance as invalid.

Definition at line 1174 of file jsd_xpc.cpp.

{
    JSDContext *cx;
    gJsds->GetJSDContext (&cx);
    JSDScript *script;
    JSDScript *iter = NULL;
    
    JSD_LockScriptSubsystem(cx);
    while((script = JSD_IterateScripts(cx, &iter)) != NULL) {
        nsCOMPtr<jsdIScript> jsdis = 
            NS_STATIC_CAST(jsdIScript *, JSD_GetScriptPrivate(script));
        if (jsdis)
            jsdis->Invalidate();
    }
    JSD_UnlockScriptSubsystem(cx);
}

Here is the call graph for this function:

boolean jsdIScript::isLineExecutable ( in unsigned long  line,
in unsigned long  pcmap 
) [inherited]

Determine is a particular line is executable, like checking that lineToPc == pcToLine, except in one call.

The |pcmap| argument specifies which pc to source line map to use.

unsigned long jsdIScript::lineToPc ( in unsigned long  line,
in unsigned long  pcmap 
) [inherited]

Get the first PC associated with a line.

The |pcmap| argument specifies which pc to source line map to use.

unsigned long jsdIScript::pcToLine ( in unsigned long  pc,
in unsigned long  pcmap 
) [inherited]

Get the closest line number to a given PC.

The |pcmap| argument specifies which pc to source line map to use.

PRUint32 jsdScript::PPLineToPc ( PRUint32  aLine) [private]

Definition at line 1109 of file jsd_xpc.cpp.

{
    if (!mPPLineMap && !CreatePPLineMap())
        return 0;
    PRUint32 i;
    for (i = 1; i < mPCMapSize; ++i) {
        if (mPPLineMap[i].line > aLine)
            return mPPLineMap[i - 1].pc;
    }

    return mPPLineMap[mPCMapSize - 1].pc;
}

Here is the call graph for this function:

Definition at line 1095 of file jsd_xpc.cpp.

{
    if (!mPPLineMap && !CreatePPLineMap())
        return 0;
    PRUint32 i;
    for (i = 1; i < mPCMapSize; ++i) {
        if (mPPLineMap[i].pc > aPC)
            return mPPLineMap[i - 1].line;            
    }

    return mPPLineMap[mPCMapSize - 1].line;
}

Here is the call graph for this function:

void jsdIScript::setBreakpoint ( in unsigned long  pc) [inherited]

Set a breakpoint at a PC in this script.


Member Data Documentation

readonly attribute unsigned long jsdIScript::baseLineNumber [inherited]

Line number in source file containing the first line of this script.

This data is copied from the underlying structure when the jsdIScript instance is created and is therefore available even after the script is invalidated.

Definition at line 928 of file jsdIDebuggerService.idl.

readonly attribute unsigned long jsdIScript::callCount [inherited]

Number of times this script has been called.

Definition at line 940 of file jsdIDebuggerService.idl.

readonly attribute string jsdIScript::fileName [inherited]

Filename given for this script when it was compiled.

This data is copied from the underlying structure when the jsdIScript instance is created and is therefore available even after the script is invalidated.

Definition at line 905 of file jsdIDebuggerService.idl.

const unsigned long jsdIScript::FLAG_DEBUG = 0x02 [inherited]

Determines whether or not to ignore breakpoints, etc.

in this script. The context flag JSD_DEBUG_WHEN_SET decides the logic.

Definition at line 892 of file jsdIDebuggerService.idl.

const unsigned long jsdIScript::FLAG_PROFILE = 0x01 [inherited]

FLAG_* values need to be kept in sync with JSD_SCRIPT_* #defines in jsdebug.h.

Determines whether or not to collect profile information for this script. The context flag FLAG_PROFILE_WHEN_SET decides the logic.

Definition at line 887 of file jsdIDebuggerService.idl.

attribute unsigned long jsdIScript::flags [inherited]

FLAG_* attributes from above, OR'd together.

Definition at line 897 of file jsdIDebuggerService.idl.

Function name for this script.

"anonymous" for unnamed functions (or a function actually named anonymous), empty for top level scripts. This data is copied from the underlying structure when the jsdIScript instance is created and is therefore available even after the script is invalidated.

Definition at line 913 of file jsdIDebuggerService.idl.

Fetch the function object as a jsdIValue.

Definition at line 917 of file jsdIDebuggerService.idl.

readonly attribute AString jsdIScript::functionSource [inherited]

Source code for this script, without function declaration.

Definition at line 921 of file jsdIDebuggerService.idl.

|true| if this object is still valid.

If not, many or all of the methods and/or properties of the inheritor may no longer be callable.

Definition at line 691 of file jsdIDebuggerService.idl.

Internal use only.

Definition at line 861 of file jsdIDebuggerService.idl.

Internal use only.

Definition at line 863 of file jsdIDebuggerService.idl.

PRUint32 jsdScript::LastTag = 0 [static, private]

Definition at line 168 of file jsd_xpc.h.

readonly attribute unsigned long jsdIScript::lineExtent [inherited]

Total number of lines in this script.

This data is copied from the underlying structure when the jsdIScript instance is created and is therefore available even after the script is invalidated.

Definition at line 935 of file jsdIDebuggerService.idl.

readonly attribute double jsdIScript::maxExecutionTime [inherited]

Longest execution time recorded, in milliseconds.

Definition at line 952 of file jsdIDebuggerService.idl.

readonly attribute double jsdIScript::maxOwnExecutionTime [inherited]

Longest execution time recorded, in milliseconds, excluding time spent in other called code.

Definition at line 966 of file jsdIDebuggerService.idl.

readonly attribute unsigned long jsdIScript::maxRecurseDepth [inherited]

Number of times this script called itself, directly or indirectly.

Definition at line 944 of file jsdIDebuggerService.idl.

Definition at line 182 of file jsd_xpc.h.

Definition at line 178 of file jsd_xpc.h.

Definition at line 180 of file jsd_xpc.h.

Definition at line 185 of file jsd_xpc.h.

Definition at line 181 of file jsd_xpc.h.

readonly attribute double jsdIScript::minExecutionTime [inherited]

Shortest execution time recorded, in milliseconds.

Definition at line 948 of file jsdIDebuggerService.idl.

readonly attribute double jsdIScript::minOwnExecutionTime [inherited]

Shortest execution time recorded, in milliseconds, excluding time spent in other called code.

Definition at line 961 of file jsdIDebuggerService.idl.

Definition at line 182 of file jsd_xpc.h.

Definition at line 184 of file jsd_xpc.h.

Definition at line 183 of file jsd_xpc.h.

Definition at line 179 of file jsd_xpc.h.

Definition at line 177 of file jsd_xpc.h.

Definition at line 176 of file jsd_xpc.h.

const unsigned long jsdIScript::PCMAP_PRETTYPRINT = 2 [inherited]

Definition at line 979 of file jsdIDebuggerService.idl.

const unsigned long jsdIScript::PCMAP_SOURCETEXT = 1 [inherited]

Definition at line 978 of file jsdIDebuggerService.idl.

readonly attribute unsigned long jsdIScript::tag [inherited]

Tag value guaranteed unique among jsdIScript objects.

Useful as a hash key in script.

Definition at line 876 of file jsdIDebuggerService.idl.

readonly attribute double jsdIScript::totalExecutionTime [inherited]

Total time spent in this function, in milliseconds.

Definition at line 956 of file jsdIDebuggerService.idl.

readonly attribute double jsdIScript::totalOwnExecutionTime [inherited]

Total time spent in this function, in milliseconds, excluding time spent in other called code.

Definition at line 971 of file jsdIDebuggerService.idl.

readonly attribute long jsdIScript::version [inherited]

Last version set on this context.

Scripts typically select this with the "language" attribute. See the VERSION_* consts on jsdIDebuggerService.

Definition at line 870 of file jsdIDebuggerService.idl.


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