Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions | Variables
jscntxt.h File Reference
#include "jsarena.h"
#include "jsclist.h"
#include "jslong.h"
#include "jsatom.h"
#include "jsconfig.h"
#include "jsdhash.h"
#include "jsgc.h"
#include "jsinterp.h"
#include "jsobj.h"
#include "jsprvtd.h"
#include "jspubtd.h"
#include "jsregexp.h"
#include "jsutil.h"
#include "js.msg"

Go to the source code of this file.

Classes

struct  JSGSNCache
struct  JSPropertyTreeEntry
struct  JSRuntime
struct  JSStackHeader
struct  JSResolvingKey
struct  JSResolvingEntry
struct  JSLocalRootChunk
struct  JSLocalRootStack
struct  JSContext

Defines

#define GSN_CACHE_METER(cache, cnt)   /* nothing */
#define GSN_CACHE_CLEAR(cache)
#define JS_CLEAR_GSN_CACHE(cx)   GSN_CACHE_CLEAR(&JS_GSN_CACHE(cx))
#define JS_METER_GSN_CACHE(cx, cnt)   GSN_CACHE_METER(&JS_GSN_CACHE(cx), cnt)
#define JS_GSN_CACHE(cx)   ((cx)->runtime->gsnCache)
#define JS_RUNTIME_METER(rt, which)   /* nothing */
#define JS_RUNTIME_UNMETER(rt, which)   /* nothing */
#define JS_KEEP_ATOMS(rt)   JS_ATOMIC_INCREMENT(&(rt)->gcKeepAtoms);
#define JS_UNKEEP_ATOMS(rt)   JS_ATOMIC_DECREMENT(&(rt)->gcKeepAtoms);
#define JS_STACK_SEGMENT(sh)   ((jsval *)(sh) + 2)
#define JSRESFLAG_LOOKUP   0x1 /* resolving id from lookup */
#define JSRESFLAG_WATCH   0x2 /* resolving id from watch */
#define JSLRS_CHUNK_SHIFT   8
#define JSLRS_CHUNK_SIZE   JS_BIT(JSLRS_CHUNK_SHIFT)
#define JSLRS_CHUNK_MASK   JS_BITMASK(JSLRS_CHUNK_SHIFT)
#define JSLRS_NULL_MARK   ((uint32) -1)
#define JSTVU_SINGLE
#define JSTVU_MARKER
#define JSTVU_SPROP   (-3) /* u.sprop roots property tree node */
#define JSTVU_WEAK_ROOTS   (-4) /* u.weakRoots points to saved weak roots */
#define JSTVU_SCRIPT   (-5) /* u.script roots JSScript* */
#define JS_PUSH_TEMP_ROOT_COMMON(cx, x, tvr, cnt, kind)
#define JS_POP_TEMP_ROOT(cx, tvr)
#define JS_PUSH_TEMP_ROOT(cx, cnt, arr, tvr)
#define JS_PUSH_SINGLE_TEMP_ROOT(cx, val, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, val, tvr, JSTVU_SINGLE, value)
#define JS_PUSH_TEMP_ROOT_OBJECT(cx, obj, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, obj, tvr, JSTVU_SINGLE, object)
#define JS_PUSH_TEMP_ROOT_STRING(cx, str, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, str, tvr, JSTVU_SINGLE, string)
#define JS_PUSH_TEMP_ROOT_QNAME(cx, qn, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, qn, tvr, JSTVU_SINGLE, qname)
#define JS_PUSH_TEMP_ROOT_NAMESPACE(cx, ns, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, ns, tvr, JSTVU_SINGLE, nspace)
#define JS_PUSH_TEMP_ROOT_XML(cx, xml_, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, xml_, tvr, JSTVU_SINGLE, xml)
#define JS_PUSH_TEMP_ROOT_MARKER(cx, marker_, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, marker_, tvr, JSTVU_MARKER, marker)
#define JS_PUSH_TEMP_ROOT_SPROP(cx, sprop_, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, sprop_, tvr, JSTVU_SPROP, sprop)
#define JS_PUSH_TEMP_ROOT_WEAK_COPY(cx, weakRoots_, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, weakRoots_, tvr, JSTVU_WEAK_ROOTS, weakRoots)
#define JS_PUSH_TEMP_ROOT_SCRIPT(cx, script_, tvr)   JS_PUSH_TEMP_ROOT_COMMON(cx, script_, tvr, JSTVU_SCRIPT, script)
#define JS_HAS_OPTION(cx, option)   (((cx)->options & (option)) != 0)
#define JS_HAS_STRICT_OPTION(cx)   JS_HAS_OPTION(cx, JSOPTION_STRICT)
#define JS_HAS_WERROR_OPTION(cx)   JS_HAS_OPTION(cx, JSOPTION_WERROR)
#define JS_HAS_COMPILE_N_GO_OPTION(cx)   JS_HAS_OPTION(cx, JSOPTION_COMPILE_N_GO)
#define JS_HAS_ATLINE_OPTION(cx)   JS_HAS_OPTION(cx, JSOPTION_ATLINE)
#define JSVERSION_MASK   0x0FFF /* see JSVersion in jspubtd.h */
#define JSVERSION_HAS_XML   0x1000 /* flag induced by XML option */
#define JSVERSION_NUMBER(cx)   ((cx)->version & JSVERSION_MASK)
#define JS_HAS_XML_OPTION(cx)
#define JS_HAS_NATIVE_BRANCH_CALLBACK_OPTION(cx)   JS_HAS_OPTION(cx, JSOPTION_NATIVE_BRANCH_CALLBACK)
#define JS_VERSION_IS_ECMA(cx)   JSVERSION_IS_ECMA(JSVERSION_NUMBER(cx))
#define js_LeaveLocalRootScope(cx)   js_LeaveLocalRootScopeWithResult(cx, JSVAL_NULL)
#define MSG_DEF(name, number, count, exception, format)   name = number,
#define JS_CHECK_STACK_SIZE(cx, lval)   ((jsuword)&(lval) > (cx)->stackLimit)

Typedefs

typedef JS_BEGIN_EXTERN_C
struct JSGSNCache 
JSGSNCache
typedef enum JSDestroyContextMode JSDestroyContextMode
typedef enum JSRuntimeState JSRuntimeState
typedef struct JSPropertyTreeEntry JSPropertyTreeEntry
typedef struct JSNativeIteratorState
typedef struct JSResolvingKey JSResolvingKey
typedef struct JSResolvingEntry JSResolvingEntry
typedef struct JSLocalRootChunk
typedef struct JSLocalRootStack JSLocalRootStack
typedef enum JSErrNum JSErrNum

Enumerations

enum  JSDestroyContextMode { JSDCM_NO_GC, JSDCM_MAYBE_GC, JSDCM_FORCE_GC, JSDCM_NEW_FAILED }
enum  JSRuntimeState { JSRTS_DOWN, JSRTS_LAUNCHING, JSRTS_UP, JSRTS_LANDING }
enum  JSErrNum { MSG_DEF, MSG_DEF }

Functions

 JS_STATIC_ASSERT (sizeof(JSTempValueUnion)==sizeof(jsval))
void js_OnVersionChange (JSContext *cx)
void js_SetVersion (JSContext *cx, JSVersion version)
JSContextjs_NewContext (JSRuntime *rt, size_t stackChunkSize)
void js_DestroyContext (JSContext *cx, JSDestroyContextMode mode)
JSBool js_ValidContextPointer (JSRuntime *rt, JSContext *cx)
JSContextjs_ContextIterator (JSRuntime *rt, JSBool unlocked, JSContext **iterp)
JSBool js_StartResolving (JSContext *cx, JSResolvingKey *key, uint32 flag, JSResolvingEntry **entryp)
void js_StopResolving (JSContext *cx, JSResolvingKey *key, uint32 flag, JSResolvingEntry *entry, uint32 generation)
JSBool js_EnterLocalRootScope (JSContext *cx)
void js_LeaveLocalRootScopeWithResult (JSContext *cx, jsval rval)
void js_ForgetLocalRoot (JSContext *cx, jsval v)
int js_PushLocalRoot (JSContext *cx, JSLocalRootStack *lrs, jsval v)
void js_MarkLocalRoots (JSContext *cx, JSLocalRootStack *lrs)
const JSErrorFormatStringjs_GetErrorMessage (void *userRef, const char *locale, const uintN errorNumber)
void js_ReportOutOfMemory (JSContext *cx)
 JS_FRIEND_API (void) js_ReportErrorAgain(JSContext *cx
void js_ReportIsNotDefined (JSContext *cx, const char *name)

Variables

const char * message
const char JSErrorReportreport
JSErrorFormatString js_ErrorFormatString [JSErr_Limit]

Class Documentation

struct JSGSNCache

Definition at line 66 of file jscntxt.h.

Collaboration diagram for JSGSNCache:
Class Members
JSScript * script
JSDHashTable table
struct JSPropertyTreeEntry

Definition at line 161 of file jscntxt.h.

Collaboration diagram for JSPropertyTreeEntry:
Class Members
JSScopeProperty * child
JSDHashEntryHdr hdr
struct JSRuntime

Definition at line 171 of file jscntxt.h.

Collaboration diagram for JSRuntime:
Class Members
JSObject * anynameObject
JSAtomState atomState
JSInterpreterHook callHook
void * callHookData
JSCheckAccessOp checkObjectAccess
JSCList contextList
JSContextCallback cxCallback
void * data
JSDebugErrorHook debugErrorHook
void * debugErrorHookData
JSTrapHandler debuggerHandler
void * debuggerHandlerData
const char * decimalSeparator
JSHashTable * deflatedStringCache
JSDestroyScriptHook destroyScriptHook
void * destroyScriptHookData
JSString * emptyString
JSInterpreterHook executeHook
void * executeHookData
JSObjectPrincipalsFinder findObjectPrincipals
JSObject * functionNamespaceObject
JSGCArenaList gcArenaList
uint32 gcBytes
JSGCCallback gcCallback
JSGCCloseState gcCloseState
JSPtrTable gcIteratorTable
jsrefcount gcKeepAtoms
uint32 gcLastBytes
uint32 gcLevel
JSDHashTable * gcLocksHash
uint32 gcMallocBytes
uint32 gcMaxBytes
uint32 gcMaxMallocBytes
uint32 gcNumber
uint16 gcPadding
JSPackedBool gcPoke
uint32 gcPrivateBytes
JSDHashTable gcRootsHash
JSPackedBool gcRunning
JSGCArena * gcUnscannedArenaStackTop
JSGSNCache gsnCache
JSTrapHandler interruptHandler
void * interruptHandlerData
jsdouble * jsNaN
jsdouble * jsNegativeInfinity
jsdouble * jsPositiveInfinity
JSNativeIteratorState * nativeIteratorStates
JSNewScriptHook newScriptHook
void * newScriptHookData
const char * numGrouping
JSObjectHook objectHook
void * objectHookData
JSPrincipalsTranscoder principalsTranscoder
JSArenaPool propertyArenaPool
JSPropertyCache propertyCache
JSScopeProperty * propertyFreeList
int32 propertyRemovals
JSDHashTable propertyTreeHash
int64 rngAddend
jsdouble rngDscale
JSBool rngInitialized
int64 rngMask
int64 rngMultiplier
int64 rngSeed
JSCList scriptFilenamePrefixes
struct JSHashTable * scriptFilenameTable
JSSourceHandler sourceHandler
void * sourceHandlerData
JSRuntimeState state
const char * thousandsSeparator
JSTrapHandler throwHook
void * throwHookData
JSCList trapList
JSCList watchPointList
struct JSStackHeader

Definition at line 479 of file jscntxt.h.

Collaboration diagram for JSStackHeader:
Class Members
JSStackHeader * down
uintN nslots
struct JSResolvingKey

Definition at line 492 of file jscntxt.h.

Collaboration diagram for JSResolvingKey:
Class Members
jsid id
JSObject * obj
struct JSResolvingEntry

Definition at line 497 of file jscntxt.h.

Collaboration diagram for JSResolvingEntry:
Class Members
uint32 flags
JSDHashEntryHdr hdr
JSResolvingKey key
struct JSLocalRootChunk

Definition at line 512 of file jscntxt.h.

Collaboration diagram for JSLocalRootChunk:
Class Members
JSLocalRootChunk * down
jsval roots
struct JSLocalRootStack

Definition at line 517 of file jscntxt.h.

Collaboration diagram for JSLocalRootStack:
Class Members
JSLocalRootChunk firstChunk
uint32 rootCount
uint32 scopeMark
JSLocalRootChunk * topChunk
struct JSContext

Definition at line 613 of file jscntxt.h.

Collaboration diagram for JSContext:
Class Members
JSArgumentFormatMap * argumentFormatMap
JSBranchCallback branchCallback
JSPackedBool creatingException
void * data
JSStackFrame * dormantFrameChain
JSErrorReporter errorReporter
jsval exception
JSStackFrame * fp
JSObject * globalObject
JSPackedBool insideGCMarkCallback
uintN interpLevel
jsbytecode jsop_eq
jsbytecode jsop_ne
char * lastMessage
JSCList links
JSLocaleCallbacks * localeCallbacks
JSLocalRootStack * localRootStack
uint32 options
JSRegExpStatics regExpStatics
JSDHashTable * resolvingTable
JSRuntime * runtime
jsval rval2
JSPackedBool rval2set
JSSharpObjectMap sharpObjectMap
JSStackHeader * stackHeaders
jsuword stackLimit
JSArenaPool stackPool
JSArenaPool tempPool
JSTempValueRooter * tempValueRooters
JSPackedBool throwing
uint16 version
JSWeakRoots weakRoots
uint8 xmlSettingFlags

Define Documentation

Value:
JS_BEGIN_MACRO                                                            \
        (cache)->script = NULL;                                               \
        if ((cache)->table.ops) {                                             \
            JS_DHashTableFinish(&(cache)->table);                             \
            (cache)->table.ops = NULL;                                        \
        }                                                                     \
        GSN_CACHE_METER(cache, clears);                                       \
    JS_END_MACRO

Definition at line 80 of file jscntxt.h.

#define GSN_CACHE_METER (   cache,
  cnt 
)    /* nothing */

Definition at line 76 of file jscntxt.h.

#define JS_CHECK_STACK_SIZE (   cx,
  lval 
)    ((jsuword)&(lval) > (cx)->stackLimit)

Definition at line 959 of file jscntxt.h.

Definition at line 91 of file jscntxt.h.

#define JS_GSN_CACHE (   cx)    ((cx)->runtime->gsnCache)

Definition at line 415 of file jscntxt.h.

Definition at line 808 of file jscntxt.h.

Definition at line 807 of file jscntxt.h.

Definition at line 817 of file jscntxt.h.

#define JS_HAS_OPTION (   cx,
  option 
)    (((cx)->options & (option)) != 0)

Definition at line 804 of file jscntxt.h.

Definition at line 805 of file jscntxt.h.

Definition at line 806 of file jscntxt.h.

Value:

Definition at line 814 of file jscntxt.h.

#define JS_KEEP_ATOMS (   rt)    JS_ATOMIC_INCREMENT(&(rt)->gcKeepAtoms);

Definition at line 462 of file jscntxt.h.

Definition at line 886 of file jscntxt.h.

#define JS_METER_GSN_CACHE (   cx,
  cnt 
)    GSN_CACHE_METER(&JS_GSN_CACHE(cx), cnt)

Definition at line 92 of file jscntxt.h.

#define JS_POP_TEMP_ROOT (   cx,
  tvr 
)
Value:
JS_BEGIN_MACRO                                                            \
        JS_ASSERT((cx)->tempValueRooters == (tvr));                           \
        (cx)->tempValueRooters = (tvr)->down;                                 \
    JS_END_MACRO

Definition at line 571 of file jscntxt.h.

Definition at line 583 of file jscntxt.h.

#define JS_PUSH_TEMP_ROOT (   cx,
  cnt,
  arr,
  tvr 
)
Value:
JS_BEGIN_MACRO                                                            \
        JS_ASSERT((ptrdiff_t)(cnt) >= 0);                                     \
        JS_PUSH_TEMP_ROOT_COMMON(cx, arr, tvr, (ptrdiff_t) (cnt), array);     \
    JS_END_MACRO

Definition at line 577 of file jscntxt.h.

#define JS_PUSH_TEMP_ROOT_COMMON (   cx,
  x,
  tvr,
  cnt,
  kind 
)
Value:
JS_BEGIN_MACRO                                                            \
        JS_ASSERT((cx)->tempValueRooters != (tvr));                           \
        (tvr)->count = (cnt);                                                 \
        (tvr)->u.kind = (x);                                                  \
        (tvr)->down = (cx)->tempValueRooters;                                 \
        (cx)->tempValueRooters = (tvr);                                       \
    JS_END_MACRO

Definition at line 562 of file jscntxt.h.

#define JS_PUSH_TEMP_ROOT_MARKER (   cx,
  marker_,
  tvr 
)    JS_PUSH_TEMP_ROOT_COMMON(cx, marker_, tvr, JSTVU_MARKER, marker)

Definition at line 601 of file jscntxt.h.

#define JS_PUSH_TEMP_ROOT_NAMESPACE (   cx,
  ns,
  tvr 
)    JS_PUSH_TEMP_ROOT_COMMON(cx, ns, tvr, JSTVU_SINGLE, nspace)

Definition at line 595 of file jscntxt.h.

Definition at line 586 of file jscntxt.h.

#define JS_PUSH_TEMP_ROOT_QNAME (   cx,
  qn,
  tvr 
)    JS_PUSH_TEMP_ROOT_COMMON(cx, qn, tvr, JSTVU_SINGLE, qname)

Definition at line 592 of file jscntxt.h.

#define JS_PUSH_TEMP_ROOT_SCRIPT (   cx,
  script_,
  tvr 
)    JS_PUSH_TEMP_ROOT_COMMON(cx, script_, tvr, JSTVU_SCRIPT, script)

Definition at line 610 of file jscntxt.h.

#define JS_PUSH_TEMP_ROOT_SPROP (   cx,
  sprop_,
  tvr 
)    JS_PUSH_TEMP_ROOT_COMMON(cx, sprop_, tvr, JSTVU_SPROP, sprop)

Definition at line 604 of file jscntxt.h.

Definition at line 589 of file jscntxt.h.

#define JS_PUSH_TEMP_ROOT_WEAK_COPY (   cx,
  weakRoots_,
  tvr 
)    JS_PUSH_TEMP_ROOT_COMMON(cx, weakRoots_, tvr, JSTVU_WEAK_ROOTS, weakRoots)

Definition at line 607 of file jscntxt.h.

#define JS_PUSH_TEMP_ROOT_XML (   cx,
  xml_,
  tvr 
)    JS_PUSH_TEMP_ROOT_COMMON(cx, xml_, tvr, JSTVU_SINGLE, xml)

Definition at line 598 of file jscntxt.h.

#define JS_RUNTIME_METER (   rt,
  which 
)    /* nothing */

Definition at line 458 of file jscntxt.h.

#define JS_RUNTIME_UNMETER (   rt,
  which 
)    /* nothing */

Definition at line 459 of file jscntxt.h.

#define JS_STACK_SEGMENT (   sh)    ((jsval *)(sh) + 2)

Definition at line 484 of file jscntxt.h.

#define JS_UNKEEP_ATOMS (   rt)    JS_ATOMIC_DECREMENT(&(rt)->gcKeepAtoms);

Definition at line 463 of file jscntxt.h.

Definition at line 824 of file jscntxt.h.

Definition at line 510 of file jscntxt.h.

Definition at line 508 of file jscntxt.h.

Definition at line 509 of file jscntxt.h.

Definition at line 524 of file jscntxt.h.

#define JSRESFLAG_LOOKUP   0x1 /* resolving id from lookup */

Definition at line 503 of file jscntxt.h.

#define JSRESFLAG_WATCH   0x2 /* resolving id from watch */

Definition at line 504 of file jscntxt.h.

Value:
(-2)    /* u.marker is a hook to mark a custom
                                     * structure */

Definition at line 542 of file jscntxt.h.

Definition at line 545 of file jscntxt.h.

Value:
(-1)    /* u.value or u.<gcthing> is single jsval
                                       or GC-thing */

Definition at line 541 of file jscntxt.h.

#define JSTVU_SPROP   (-3) /* u.sprop roots property tree node */

Definition at line 543 of file jscntxt.h.

#define JSTVU_WEAK_ROOTS   (-4) /* u.weakRoots points to saved weak roots */

Definition at line 544 of file jscntxt.h.

#define JSVERSION_HAS_XML   0x1000 /* flag induced by XML option */

Definition at line 811 of file jscntxt.h.

#define JSVERSION_MASK   0x0FFF /* see JSVersion in jspubtd.h */

Definition at line 810 of file jscntxt.h.

Definition at line 813 of file jscntxt.h.

#define MSG_DEF (   name,
  number,
  count,
  exception,
  format 
)    name = number,

Definition at line 906 of file jscntxt.h.


Typedef Documentation

typedef enum JSErrNum JSErrNum
typedef struct JSLocalRootChunk

Definition at line 506 of file jscntxt.h.

typedef struct JSNativeIteratorState

Definition at line 169 of file jscntxt.h.


Enumeration Type Documentation

Enumerator:
JSDCM_NO_GC 
JSDCM_MAYBE_GC 
JSDCM_FORCE_GC 
JSDCM_NEW_FAILED 

Definition at line 147 of file jscntxt.h.

enum JSErrNum
Enumerator:
MSG_DEF 
MSG_DEF 

Definition at line 905 of file jscntxt.h.

                      {
#define MSG_DEF(name, number, count, exception, format) \
    name = number,
#include "js.msg"
#undef MSG_DEF
    JSErr_Limit
} JSErrNum;
Enumerator:
JSRTS_DOWN 
JSRTS_LAUNCHING 
JSRTS_UP 
JSRTS_LANDING 

Definition at line 154 of file jscntxt.h.


Function Documentation

JSContext* js_ContextIterator ( JSRuntime rt,
JSBool  unlocked,
JSContext **  iterp 
)

Definition at line 466 of file jscntxt.c.

{
    JSContext *cx = *iterp;

    if (unlocked)
        JS_LOCK_GC(rt);
    if (!cx)
        cx = (JSContext *)&rt->contextList;
    cx = (JSContext *)cx->links.next;
    if (&cx->links == &rt->contextList)
        cx = NULL;
    *iterp = cx;
    if (unlocked)
        JS_UNLOCK_GC(rt);
    return cx;
}

Here is the caller graph for this function:

Definition at line 298 of file jscntxt.c.

{
    JSRuntime *rt;
    JSContextCallback cxCallback;
    JSBool last;
    JSArgumentFormatMap *map;
    JSLocalRootStack *lrs;
    JSLocalRootChunk *lrc;

    rt = cx->runtime;

    if (mode != JSDCM_NEW_FAILED) {
        cxCallback = rt->cxCallback;
        if (cxCallback) {
            /*
             * JSCONTEXT_DESTROY callback is not allowed to fail and must
             * return true.
             */
#ifdef DEBUG
            JSBool callbackStatus =
#endif
            cxCallback(cx, JSCONTEXT_DESTROY);
            JS_ASSERT(callbackStatus);
        }
    }

    /* Remove cx from context list first. */
    JS_LOCK_GC(rt);
    JS_ASSERT(rt->state == JSRTS_UP || rt->state == JSRTS_LAUNCHING);
    JS_REMOVE_LINK(&cx->links);
    last = (rt->contextList.next == &rt->contextList);
    if (last)
        rt->state = JSRTS_LANDING;
    JS_UNLOCK_GC(rt);

    if (last) {
#ifdef JS_THREADSAFE
        /*
         * If cx is not in a request already, begin one now so that we wait
         * for any racing GC started on a not-last context to finish, before
         * we plow ahead and unpin atoms.  Note that even though we begin a
         * request here if necessary, we end all requests on cx below before
         * forcing a final GC.  This lets any not-last context destruction
         * racing in another thread try to force or maybe run the GC, but by
         * that point, rt->state will not be JSRTS_UP, and that GC attempt
         * will return early.
         */
        if (cx->requestDepth == 0)
            JS_BeginRequest(cx);
#endif

        /* Unpin all pinned atoms before final GC. */
        js_UnpinPinnedAtoms(&rt->atomState);

        /* Unlock and clear GC things held by runtime pointers. */
        js_FinishRuntimeNumberState(cx);
        js_FinishRuntimeStringState(cx);

        /* Clear debugging state to remove GC roots. */
        JS_ClearAllTraps(cx);
        JS_ClearAllWatchPoints(cx);
    }

    /*
     * Remove more GC roots in regExpStatics, then collect garbage.
     * XXX anti-modularity alert: we rely on the call to js_RemoveRoot within
     * XXX this function call to wait for any racing GC to complete, in the
     * XXX case where JS_DestroyContext is called outside of a request on cx
     */
    js_FreeRegExpStatics(cx, &cx->regExpStatics);

#ifdef JS_THREADSAFE
    /*
     * Destroying a context implicitly calls JS_EndRequest().  Also, we must
     * end our request here in case we are "last" -- in that event, another
     * js_DestroyContext that was not last might be waiting in the GC for our
     * request to end.  We'll let it run below, just before we do the truly
     * final GC and then free atom state.
     *
     * At this point, cx must be inaccessible to other threads.  It's off the
     * rt->contextList, and it should not be reachable via any object private
     * data structure.
     */
    while (cx->requestDepth != 0)
        JS_EndRequest(cx);
#endif

    if (last) {
        js_GC(cx, GC_LAST_CONTEXT);

        /* Try to free atom state, now that no unrooted scripts survive. */
        if (rt->atomState.liveAtoms == 0)
            js_FreeAtomState(cx, &rt->atomState);

        /* Also free the script filename table if it exists and is empty. */
        if (rt->scriptFilenameTable && rt->scriptFilenameTable->nentries == 0)
            js_FinishRuntimeScriptState(rt);

        /*
         * Free the deflated string cache, but only after the last GC has
         * collected all unleaked strings.
         */
        js_FinishDeflatedStringCache(rt);

        /* Take the runtime down, now that it has no contexts or atoms. */
        JS_LOCK_GC(rt);
        rt->state = JSRTS_DOWN;
        JS_NOTIFY_ALL_CONDVAR(rt->stateChange);
        JS_UNLOCK_GC(rt);
    } else {
        if (mode == JSDCM_FORCE_GC)
            js_GC(cx, GC_NORMAL);
        else if (mode == JSDCM_MAYBE_GC)
            JS_MaybeGC(cx);
    }

    /* Free the stuff hanging off of cx. */
    JS_FinishArenaPool(&cx->stackPool);
    JS_FinishArenaPool(&cx->tempPool);

    if (cx->lastMessage)
        free(cx->lastMessage);

    /* Remove any argument formatters. */
    map = cx->argumentFormatMap;
    while (map) {
        JSArgumentFormatMap *temp = map;
        map = map->next;
        JS_free(cx, temp);
    }

    /* Destroy the resolve recursion damper. */
    if (cx->resolvingTable) {
        JS_DHashTableDestroy(cx->resolvingTable);
        cx->resolvingTable = NULL;
    }

    lrs = cx->localRootStack;
    if (lrs) {
        while ((lrc = lrs->topChunk) != &lrs->firstChunk) {
            lrs->topChunk = lrc->down;
            JS_free(cx, lrc);
        }
        JS_free(cx, lrs);
    }

#ifdef JS_THREADSAFE
    js_ClearContextThread(cx);
#endif

    /* Finally, free cx itself. */
    free(cx);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 595 of file jscntxt.c.

{
    JSLocalRootStack *lrs;
    int mark;

    lrs = cx->localRootStack;
    if (!lrs) {
        lrs = (JSLocalRootStack *) JS_malloc(cx, sizeof *lrs);
        if (!lrs)
            return JS_FALSE;
        lrs->scopeMark = JSLRS_NULL_MARK;
        lrs->rootCount = 0;
        lrs->topChunk = &lrs->firstChunk;
        lrs->firstChunk.down = NULL;
        cx->localRootStack = lrs;
    }

    /* Push lrs->scopeMark to save it for restore when leaving. */
    mark = js_PushLocalRoot(cx, lrs, INT_TO_JSVAL(lrs->scopeMark));
    if (mark < 0)
        return JS_FALSE;
    lrs->scopeMark = (uint32) mark;
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 693 of file jscntxt.c.

{
    JSLocalRootStack *lrs;
    uint32 i, j, m, n, mark;
    JSLocalRootChunk *lrc, *lrc2;
    jsval top;

    lrs = cx->localRootStack;
    JS_ASSERT(lrs && lrs->rootCount);
    if (!lrs || lrs->rootCount == 0)
        return;

    /* Prepare to pop the top-most value from the stack. */
    n = lrs->rootCount - 1;
    m = n & JSLRS_CHUNK_MASK;
    lrc = lrs->topChunk;
    top = lrc->roots[m];

    /* Be paranoid about calls on an empty scope. */
    mark = lrs->scopeMark;
    JS_ASSERT(mark < n);
    if (mark >= n)
        return;

    /* If v was not the last root pushed in the top scope, find it. */
    if (top != v) {
        /* Search downward in case v was recently pushed. */
        i = n;
        j = m;
        lrc2 = lrc;
        while (--i > mark) {
            if (j == 0)
                lrc2 = lrc2->down;
            j = i & JSLRS_CHUNK_MASK;
            if (lrc2->roots[j] == v)
                break;
        }

        /* If we didn't find v in this scope, assert and bail out. */
        JS_ASSERT(i != mark);
        if (i == mark)
            return;

        /* Swap top and v so common tail code can pop v. */
        lrc2->roots[j] = top;
    }

    /* Pop the last value from the stack. */
    lrc->roots[m] = JSVAL_NULL;
    lrs->rootCount = n;
    if (m == 0) {
        JS_ASSERT(n != 0);
        JS_ASSERT(lrc != &lrs->firstChunk);
        lrs->topChunk = lrc->down;
        JS_free(cx, lrc);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const JSErrorFormatString* js_GetErrorMessage ( void userRef,
const char *  locale,
const uintN  errorNumber 
)

Definition at line 1224 of file jscntxt.c.

{
    if ((errorNumber > 0) && (errorNumber < JSErr_Limit))
        return &js_ErrorFormatString[errorNumber];
    return NULL;
}

Definition at line 621 of file jscntxt.c.

{
    JSLocalRootStack *lrs;
    uint32 mark, m, n;
    JSLocalRootChunk *lrc;

    /* Defend against buggy native callers. */
    lrs = cx->localRootStack;
    JS_ASSERT(lrs && lrs->rootCount != 0);
    if (!lrs || lrs->rootCount == 0)
        return;

    mark = lrs->scopeMark;
    JS_ASSERT(mark != JSLRS_NULL_MARK);
    if (mark == JSLRS_NULL_MARK)
        return;

    /* Free any chunks being popped by this leave operation. */
    m = mark >> JSLRS_CHUNK_SHIFT;
    n = (lrs->rootCount - 1) >> JSLRS_CHUNK_SHIFT;
    while (n > m) {
        lrc = lrs->topChunk;
        JS_ASSERT(lrc != &lrs->firstChunk);
        lrs->topChunk = lrc->down;
        JS_free(cx, lrc);
        --n;
    }

    /*
     * Pop the scope, restoring lrs->scopeMark.  If rval is a GC-thing, push
     * it on the caller's scope, or store it in lastInternalResult if we are
     * leaving the outermost scope.  We don't need to allocate a new lrc
     * because we can overwrite the old mark's slot with rval.
     */
    lrc = lrs->topChunk;
    m = mark & JSLRS_CHUNK_MASK;
    lrs->scopeMark = (uint32) JSVAL_TO_INT(lrc->roots[m]);
    if (JSVAL_IS_GCTHING(rval) && !JSVAL_IS_NULL(rval)) {
        if (mark == 0) {
            cx->weakRoots.lastInternalResult = rval;
        } else {
            /*
             * Increment m to avoid the "else if (m == 0)" case below.  If
             * rval is not a GC-thing, that case would take care of freeing
             * any chunk that contained only the old mark.  Since rval *is*
             * a GC-thing here, we want to reuse that old mark's slot.
             */
            lrc->roots[m++] = rval;
            ++mark;
        }
    }
    lrs->rootCount = (uint32) mark;

    /*
     * Free the stack eagerly, risking malloc churn.  The alternative would
     * require an lrs->entryCount member, maintained by Enter and Leave, and
     * tested by the GC in addition to the cx->localRootStack non-null test.
     *
     * That approach would risk hoarding 264 bytes (net) per context.  Right
     * now it seems better to give fresh (dirty in CPU write-back cache, and
     * the data is no longer needed) memory back to the malloc heap.
     */
    if (mark == 0) {
        cx->localRootStack = NULL;
        JS_free(cx, lrs);
    } else if (m == 0) {
        lrs->topChunk = lrc->down;
        JS_free(cx, lrc);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 788 of file jscntxt.c.

{
    uint32 n, m, mark;
    JSLocalRootChunk *lrc;

    n = lrs->rootCount;
    if (n == 0)
        return;

    mark = lrs->scopeMark;
    lrc = lrs->topChunk;
    do {
        while (--n > mark) {
#ifdef GC_MARK_DEBUG
            char name[22];
            JS_snprintf(name, sizeof name, "<local root %u>", n);
#endif
            m = n & JSLRS_CHUNK_MASK;
            JS_ASSERT(JSVAL_IS_GCTHING(lrc->roots[m]));
            GC_MARK(cx, JSVAL_TO_GCTHING(lrc->roots[m]), name);
            if (m == 0)
                lrc = lrc->down;
        }
        m = n & JSLRS_CHUNK_MASK;
        mark = JSVAL_TO_INT(lrc->roots[m]);
        if (m == 0)
            lrc = lrc->down;
    } while (n != 0);
    JS_ASSERT(!lrc);
}

Here is the caller graph for this function:

JSContext* js_NewContext ( JSRuntime rt,
size_t  stackChunkSize 
)

Definition at line 192 of file jscntxt.c.

{
    JSContext *cx;
    JSBool ok, first;
    JSContextCallback cxCallback;

    cx = (JSContext *) malloc(sizeof *cx);
    if (!cx)
        return NULL;
    memset(cx, 0, sizeof *cx);

    cx->runtime = rt;
#if JS_STACK_GROWTH_DIRECTION > 0
    cx->stackLimit = (jsuword)-1;
#endif
#ifdef JS_THREADSAFE
    JS_INIT_CLIST(&cx->threadLinks);
    js_SetContextThread(cx);
#endif

    JS_LOCK_GC(rt);
    for (;;) {
        first = (rt->contextList.next == &rt->contextList);
        if (rt->state == JSRTS_UP) {
            JS_ASSERT(!first);
            break;
        }
        if (rt->state == JSRTS_DOWN) {
            JS_ASSERT(first);
            rt->state = JSRTS_LAUNCHING;
            break;
        }
        JS_WAIT_CONDVAR(rt->stateChange, JS_NO_TIMEOUT);
    }
    JS_APPEND_LINK(&cx->links, &rt->contextList);
    JS_UNLOCK_GC(rt);

    /*
     * First we do the infallible, every-time per-context initializations.
     * Should a later, fallible initialization (js_InitRegExpStatics, e.g.,
     * or the stuff under 'if (first)' below) fail, at least the version
     * and arena-pools will be valid and safe to use (say, from the last GC
     * done by js_DestroyContext).
     */
    cx->version = JSVERSION_DEFAULT;
    cx->jsop_eq = JSOP_EQ;
    cx->jsop_ne = JSOP_NE;
    JS_InitArenaPool(&cx->stackPool, "stack", stackChunkSize, sizeof(jsval));
    JS_InitArenaPool(&cx->tempPool, "temp", 1024, sizeof(jsdouble));

    if (!js_InitRegExpStatics(cx, &cx->regExpStatics)) {
        js_DestroyContext(cx, JSDCM_NEW_FAILED);
        return NULL;
    }

    /*
     * If cx is the first context on this runtime, initialize well-known atoms,
     * keywords, numbers, and strings.  If one of these steps should fail, the
     * runtime will be left in a partially initialized state, with zeroes and
     * nulls stored in the default-initialized remainder of the struct.  We'll
     * clean the runtime up under js_DestroyContext, because cx will be "last"
     * as well as "first".
     */
    if (first) {
#ifdef JS_THREADSAFE
        JS_BeginRequest(cx);
#endif
        /*
         * Both atomState and the scriptFilenameTable may be left over from a
         * previous episode of non-zero contexts alive in rt, so don't re-init
         * either table if it's not necessary.  Just repopulate atomState with
         * well-known internal atoms, and with the reserved identifiers added
         * by the scanner.
         */
        ok = (rt->atomState.liveAtoms == 0)
             ? js_InitAtomState(cx, &rt->atomState)
             : js_InitPinnedAtoms(cx, &rt->atomState);
        if (ok && !rt->scriptFilenameTable)
            ok = js_InitRuntimeScriptState(rt);
        if (ok)
            ok = js_InitRuntimeNumberState(cx);
        if (ok)
            ok = js_InitRuntimeStringState(cx);
#ifdef JS_THREADSAFE
        JS_EndRequest(cx);
#endif
        if (!ok) {
            js_DestroyContext(cx, JSDCM_NEW_FAILED);
            return NULL;
        }

        JS_LOCK_GC(rt);
        rt->state = JSRTS_UP;
        JS_NOTIFY_ALL_CONDVAR(rt->stateChange);
        JS_UNLOCK_GC(rt);
    }

    cxCallback = rt->cxCallback;
    if (cxCallback && !cxCallback(cx, JSCONTEXT_NEW)) {
        js_DestroyContext(cx, JSDCM_NEW_FAILED);
        return NULL;
    }
    return cx;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 175 of file jscntxt.c.

{
#ifdef DEBUG
    JSVersion version = JSVERSION_NUMBER(cx);

    JS_ASSERT(version == JSVERSION_DEFAULT || version >= JSVERSION_ECMA_3);
#endif
}

Here is the caller graph for this function:

int js_PushLocalRoot ( JSContext cx,
JSLocalRootStack lrs,
jsval  v 
)

Definition at line 752 of file jscntxt.c.

{
    uint32 n, m;
    JSLocalRootChunk *lrc;

    n = lrs->rootCount;
    m = n & JSLRS_CHUNK_MASK;
    if (n == 0 || m != 0) {
        /*
         * At start of first chunk, or not at start of a non-first top chunk.
         * Check for lrs->rootCount overflow.
         */
        if ((uint32)(n + 1) == 0) {
            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                 JSMSG_TOO_MANY_LOCAL_ROOTS);
            return -1;
        }
        lrc = lrs->topChunk;
        JS_ASSERT(n != 0 || lrc == &lrs->firstChunk);
    } else {
        /*
         * After lrs->firstChunk, trying to index at a power-of-two chunk
         * boundary: need a new chunk.
         */
        lrc = (JSLocalRootChunk *) JS_malloc(cx, sizeof *lrc);
        if (!lrc)
            return -1;
        lrc->down = lrs->topChunk;
        lrs->topChunk = lrc;
    }
    lrs->rootCount = n + 1;
    lrc->roots[m] = v;
    return (int) n;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void js_ReportIsNotDefined ( JSContext cx,
const char *  name 
)

Definition at line 1205 of file jscntxt.c.

{
    JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_DEFINED, name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 858 of file jscntxt.c.

{
    JSStackFrame *fp;
    JSErrorReport report;
    JSErrorReporter onError = cx->errorReporter;

    /* Get the message for this error, but we won't expand any arguments. */
    const JSErrorFormatString *efs =
        js_GetLocalizedErrorMessage(cx, NULL, NULL, JSMSG_OUT_OF_MEMORY);
    const char *msg = efs ? efs->format : "Out of memory";

    /* Fill out the report, but don't do anything that requires allocation. */
    memset(&report, 0, sizeof (struct JSErrorReport));
    report.flags = JSREPORT_ERROR;
    report.errorNumber = JSMSG_OUT_OF_MEMORY;

    /*
     * Walk stack until we find a frame that is associated with some script
     * rather than a native frame.
     */
    for (fp = cx->fp; fp; fp = fp->down) {
        if (fp->script && fp->pc) {
            report.filename = fp->script->filename;
            report.lineno = js_PCToLineNumber(cx, fp->script, fp->pc);
            break;
        }
    }

    /*
     * If debugErrorHook is present then we give it a chance to veto
     * sending the error on to the regular ErrorReporter.
     */
    if (onError) {
        JSDebugErrorHook hook = cx->runtime->debugErrorHook;
        if (hook &&
            !hook(cx, msg, &report, cx->runtime->debugErrorHookData)) {
            onError = NULL;
        }
    }

    if (onError)
        onError(cx, msg, &report);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void js_SetVersion ( JSContext cx,
JSVersion  version 
)

Definition at line 185 of file jscntxt.c.

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_StartResolving ( JSContext cx,
JSResolvingKey key,
uint32  flag,
JSResolvingEntry **  entryp 
)

Definition at line 523 of file jscntxt.c.

{
    JSDHashTable *table;
    JSResolvingEntry *entry;

    table = cx->resolvingTable;
    if (!table) {
        table = JS_NewDHashTable(&resolving_dhash_ops, NULL,
                                 sizeof(JSResolvingEntry),
                                 JS_DHASH_MIN_SIZE);
        if (!table)
            goto outofmem;
        cx->resolvingTable = table;
    }

    entry = (JSResolvingEntry *)
            JS_DHashTableOperate(table, key, JS_DHASH_ADD);
    if (!entry)
        goto outofmem;

    if (entry->flags & flag) {
        /* An entry for (key, flag) exists already -- dampen recursion. */
        entry = NULL;
    } else {
        /* Fill in key if we were the first to add entry, then set flag. */
        if (!entry->key.obj)
            entry->key = *key;
        entry->flags |= flag;
    }
    *entryp = entry;
    return JS_TRUE;

outofmem:
    JS_ReportOutOfMemory(cx);
    return JS_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JS_STATIC_ASSERT ( sizeof(JSTempValueUnion = =sizeof(jsval))
void js_StopResolving ( JSContext cx,
JSResolvingKey key,
uint32  flag,
JSResolvingEntry entry,
uint32  generation 
)

Definition at line 562 of file jscntxt.c.

{
    JSDHashTable *table;

    /*
     * Clear flag from entry->flags and return early if other flags remain.
     * We must take care to re-lookup entry if the table has changed since
     * it was found by js_StartResolving.
     */
    table = cx->resolvingTable;
    if (!entry || table->generation != generation) {
        entry = (JSResolvingEntry *)
                JS_DHashTableOperate(table, key, JS_DHASH_LOOKUP);
    }
    JS_ASSERT(JS_DHASH_ENTRY_IS_BUSY(&entry->hdr));
    entry->flags &= ~flag;
    if (entry->flags)
        return;

    /*
     * Do a raw remove only if fewer entries were removed than would cause
     * alpha to be less than .5 (alpha is at most .75).  Otherwise, we just
     * call JS_DHashTableOperate to re-lookup the key and remove its entry,
     * compressing or shrinking the table as needed.
     */
    if (table->removedCount < JS_DHASH_TABLE_SIZE(table) >> 2)
        JS_DHashTableRawRemove(table, &entry->hdr);
    else
        JS_DHashTableOperate(table, key, JS_DHASH_REMOVE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 453 of file jscntxt.c.

{
    JSCList *cl;

    for (cl = rt->contextList.next; cl != &rt->contextList; cl = cl->next) {
        if (cl == &cx->links)
            return JS_TRUE;
    }
    JS_RUNTIME_METER(rt, deadContexts);
    return JS_FALSE;
}

Variable Documentation

Definition at line 1216 of file jscntxt.c.

const char* message

Definition at line 942 of file jscntxt.h.

Definition at line 942 of file jscntxt.h.