* if we failed to create the first frame, fail the entire * thread state.
* if we failed to create the first frame, or the top frame * is not enabled for debugging, fail the entire thread state.
jsd_NewThreadState(JSDContext* jsdc, JSContext *cx ){    JSDThreadState* jsdthreadstate;    JSStackFrame *  iter = NULL;    JSStackFrame *  fp;    jsdthreadstate = (JSDThreadState*)calloc(1, sizeof(JSDThreadState));    if( ! jsdthreadstate )        return NULL;    jsdthreadstate->context = cx;    jsdthreadstate->thread = JSD_CURRENT_THREAD();    JS_INIT_CLIST(&jsdthreadstate->stack);    jsdthreadstate->stackDepth = 0;    while( NULL != (fp = JS_FrameIterator(cx, &iter)) )    {        JSScript* script = JS_GetFrameScript(cx, fp);        jsuword  pc = (jsuword) JS_GetFramePC(cx, fp);        /*         * don't construct a JSDStackFrame for dummy frames (those without a         * |this| object, or native frames, if JSD_INCLUDE_NATIVE_FRAMES         * isn't set.         */        if (JS_GetFrameThis(cx, fp) &&            ((jsdc->flags & JSD_INCLUDE_NATIVE_FRAMES) ||             !JS_IsNativeFrame(cx, fp)))        {                        if (!_addNewFrame( jsdc, jsdthreadstate, script, pc, fp ) &&                jsdthreadstate->stackDepth == 0)             {                /*                 * if we failed to create the first frame, fail the entire                 * thread state.                 */                break;            }        }    }        /* if there is no stack, then this threadstate can not be constructed */    if( 0 == jsdthreadstate->stackDepth )    {        free(jsdthreadstate);        return NULL;    }    JSD_LOCK_THREADSTATES(jsdc);    JS_APPEND_LINK(&jsdthreadstate->links, &jsdc->threadsStates);    JSD_UNLOCK_THREADSTATES(jsdc);    return jsdthreadstate;}