2013-04-15 11:33:03 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 04:12:37 -07:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* JavaScript Debugging support - Call stack support
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jsd.h"
|
2010-12-23 13:41:57 -08:00
|
|
|
#include "jsfriendapi.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void JSD_ASSERT_VALID_THREAD_STATE(JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
|
|
|
JS_ASSERT(jsdthreadstate);
|
|
|
|
JS_ASSERT(jsdthreadstate->stackDepth > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSD_ASSERT_VALID_STACK_FRAME(JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JS_ASSERT(jsdframe);
|
|
|
|
JS_ASSERT(jsdframe->jsdthreadstate);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static JSDStackFrameInfo*
|
|
|
|
_addNewFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSScript* script,
|
2012-01-11 00:23:05 -08:00
|
|
|
uintptr_t pc,
|
2013-01-25 00:49:29 -08:00
|
|
|
bool isConstructing,
|
|
|
|
JSAbstractFramePtr frame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSDStackFrameInfo* jsdframe;
|
|
|
|
JSDScript* jsdscript = NULL;
|
|
|
|
|
2012-08-17 18:05:06 -07:00
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
jsdscript = jsd_FindJSDScript(jsdc, script);
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
if (!jsdscript || (jsdc->flags & JSD_HIDE_DISABLED_FRAMES &&
|
|
|
|
!JSD_IS_DEBUG_ENABLED(jsdc, jsdscript)))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-17 18:05:06 -07:00
|
|
|
return NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-17 18:05:06 -07:00
|
|
|
|
|
|
|
if (!JSD_IS_DEBUG_ENABLED(jsdc, jsdscript))
|
|
|
|
jsdthreadstate->flags |= TS_HAS_DISABLED_FRAME;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
jsdframe = (JSDStackFrameInfo*) calloc(1, sizeof(JSDStackFrameInfo));
|
|
|
|
if( ! jsdframe )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
jsdframe->jsdthreadstate = jsdthreadstate;
|
|
|
|
jsdframe->jsdscript = jsdscript;
|
2013-01-25 00:49:29 -08:00
|
|
|
jsdframe->isConstructing = isConstructing;
|
2007-03-22 10:30:00 -07:00
|
|
|
jsdframe->pc = pc;
|
2013-01-25 00:49:29 -08:00
|
|
|
jsdframe->frame = frame;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JS_APPEND_LINK(&jsdframe->links, &jsdthreadstate->stack);
|
|
|
|
jsdthreadstate->stackDepth++;
|
|
|
|
|
|
|
|
return jsdframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_destroyFrame(JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
/* kill any alloc'd objects in frame here... */
|
|
|
|
|
|
|
|
if( jsdframe )
|
|
|
|
free(jsdframe);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDThreadState*
|
|
|
|
jsd_NewThreadState(JSDContext* jsdc, JSContext *cx )
|
|
|
|
{
|
|
|
|
JSDThreadState* jsdthreadstate;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-05-24 18:11:47 -07:00
|
|
|
JS_BeginRequest(jsdthreadstate->context);
|
2013-01-25 00:49:29 -08:00
|
|
|
|
|
|
|
JSBrokenFrameIterator iter(cx);
|
|
|
|
while(!iter.done())
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-25 00:49:29 -08:00
|
|
|
JSAbstractFramePtr frame = iter.abstractFramePtr();
|
|
|
|
JSScript* script = frame.script();
|
|
|
|
uintptr_t pc = (uintptr_t)iter.pc();
|
2013-03-06 08:41:43 -08:00
|
|
|
JS::RootedValue dummyThis(cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* don't construct a JSDStackFrame for dummy frames (those without a
|
|
|
|
* |this| object, or native frames, if JSD_INCLUDE_NATIVE_FRAMES
|
|
|
|
* isn't set.
|
|
|
|
*/
|
2013-01-25 00:49:29 -08:00
|
|
|
if (frame.getThisValue(cx, &dummyThis))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-25 00:49:29 -08:00
|
|
|
bool isConstructing = iter.isConstructing();
|
|
|
|
JSDStackFrameInfo *frameInfo = _addNewFrame( jsdc, jsdthreadstate, script, pc, isConstructing, frame );
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-25 00:49:29 -08:00
|
|
|
if ((jsdthreadstate->stackDepth == 0 && !frameInfo) ||
|
|
|
|
(jsdthreadstate->stackDepth == 1 && frameInfo &&
|
|
|
|
frameInfo->jsdscript && !JSD_IS_DEBUG_ENABLED(jsdc, frameInfo->jsdscript)))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* if we failed to create the first frame, or the top frame
|
|
|
|
* is not enabled for debugging, fail the entire thread state.
|
|
|
|
*/
|
|
|
|
JS_INIT_CLIST(&jsdthreadstate->links);
|
2010-05-24 18:11:47 -07:00
|
|
|
JS_EndRequest(jsdthreadstate->context);
|
2010-08-10 17:21:11 -07:00
|
|
|
jsd_DestroyThreadState(jsdc, jsdthreadstate);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 00:49:29 -08:00
|
|
|
|
|
|
|
++iter;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-05-24 18:11:47 -07:00
|
|
|
JS_EndRequest(jsdthreadstate->context);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (jsdthreadstate->stackDepth == 0)
|
|
|
|
{
|
|
|
|
free(jsdthreadstate);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
JS_APPEND_LINK(&jsdthreadstate->links, &jsdc->threadsStates);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
return jsdthreadstate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsd_DestroyThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
|
|
|
JSDStackFrameInfo* jsdframe;
|
|
|
|
JSCList* list;
|
|
|
|
|
|
|
|
JS_ASSERT(jsdthreadstate);
|
|
|
|
JS_ASSERT(JSD_CURRENT_THREAD() == jsdthreadstate->thread);
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
JS_REMOVE_LINK(&jsdthreadstate->links);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
list = &jsdthreadstate->stack;
|
|
|
|
while( (JSDStackFrameInfo*)list != (jsdframe = (JSDStackFrameInfo*)list->next) )
|
|
|
|
{
|
|
|
|
JS_REMOVE_LINK(&jsdframe->links);
|
|
|
|
_destroyFrame(jsdframe);
|
|
|
|
}
|
|
|
|
free(jsdthreadstate);
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned count = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidThreadState(jsdc, jsdthreadstate) )
|
|
|
|
count = jsdthreadstate->stackDepth;
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDStackFrameInfo*
|
|
|
|
jsd_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
|
|
|
JSDStackFrameInfo* jsdframe = NULL;
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidThreadState(jsdc, jsdthreadstate) )
|
|
|
|
jsdframe = (JSDStackFrameInfo*) JS_LIST_HEAD(&jsdthreadstate->stack);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
return jsdframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *
|
|
|
|
jsd_GetJSContext (JSDContext* jsdc, JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
|
|
|
JSContext* cx = NULL;
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
if( jsd_IsValidThreadState(jsdc, jsdthreadstate) )
|
|
|
|
cx = jsdthreadstate->context;
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
return cx;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDStackFrameInfo*
|
|
|
|
jsd_GetCallingStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSDStackFrameInfo* nextjsdframe = NULL;
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
if( JS_LIST_HEAD(&jsdframe->links) != &jsdframe->jsdthreadstate->stack )
|
|
|
|
nextjsdframe = (JSDStackFrameInfo*) JS_LIST_HEAD(&jsdframe->links);
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
return nextjsdframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDScript*
|
|
|
|
jsd_GetScriptForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSDScript* jsdscript = NULL;
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
jsdscript = jsdframe->jsdscript;
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
return jsdscript;
|
|
|
|
}
|
|
|
|
|
2012-01-11 00:23:05 -08:00
|
|
|
uintptr_t
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetPCForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
2012-01-11 00:23:05 -08:00
|
|
|
uintptr_t pc = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
pc = jsdframe->pc;
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDValue*
|
|
|
|
jsd_GetCallObjectForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSObject* obj;
|
|
|
|
JSDValue* jsdval = NULL;
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
{
|
2013-01-25 00:49:29 -08:00
|
|
|
obj = jsdframe->frame.callObject(jsdthreadstate->context);
|
2007-03-22 10:30:00 -07:00
|
|
|
if(obj)
|
|
|
|
jsdval = JSD_NewValue(jsdc, OBJECT_TO_JSVAL(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
return jsdval;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDValue*
|
|
|
|
jsd_GetScopeChainForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSObject* obj;
|
|
|
|
JSDValue* jsdval = NULL;
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
{
|
|
|
|
JS_BeginRequest(jsdthreadstate->context);
|
2013-01-25 00:49:29 -08:00
|
|
|
obj = jsdframe->frame.scopeChain(jsdthreadstate->context);
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_EndRequest(jsdthreadstate->context);
|
2013-01-25 00:49:29 -08:00
|
|
|
if(obj)
|
|
|
|
jsdval = JSD_NewValue(jsdc, OBJECT_TO_JSVAL(obj));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
return jsdval;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDValue*
|
|
|
|
jsd_GetThisForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSDValue* jsdval = NULL;
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
{
|
2010-10-12 11:50:03 -07:00
|
|
|
JSBool ok;
|
2013-03-06 08:41:43 -08:00
|
|
|
JS::RootedValue thisval(jsdthreadstate->context);
|
2010-05-24 18:11:47 -07:00
|
|
|
JS_BeginRequest(jsdthreadstate->context);
|
2013-01-25 00:49:29 -08:00
|
|
|
ok = jsdframe->frame.getThisValue(jsdthreadstate->context, &thisval);
|
2010-05-24 18:11:47 -07:00
|
|
|
JS_EndRequest(jsdthreadstate->context);
|
2010-10-12 11:50:03 -07:00
|
|
|
if(ok)
|
|
|
|
jsdval = JSD_NewValue(jsdc, thisval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
return jsdval;
|
|
|
|
}
|
|
|
|
|
2010-11-24 08:56:43 -08:00
|
|
|
JSString*
|
2011-01-29 13:40:29 -08:00
|
|
|
jsd_GetIdForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-11-24 08:56:43 -08:00
|
|
|
JSString *rv = NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
{
|
2013-01-25 00:49:29 -08:00
|
|
|
JSFunction *fun = jsdframe->frame.maybeFun();
|
2010-12-23 13:41:57 -08:00
|
|
|
if( fun )
|
|
|
|
{
|
2010-11-24 08:56:43 -08:00
|
|
|
rv = JS_GetFunctionId (fun);
|
2010-12-23 13:41:57 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For compatibility we return "anonymous", not an empty string
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
if( !rv )
|
|
|
|
rv = JS_GetAnonymousString(jsdc->jsrt);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_IsStackFrameDebugger(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSBool rv = JS_TRUE;
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
{
|
2013-01-25 00:49:29 -08:00
|
|
|
rv = jsdframe->frame.isDebuggerFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_IsStackFrameConstructing(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSBool rv = JS_TRUE;
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
{
|
2013-01-25 00:49:29 -08:00
|
|
|
rv = jsdframe->isConstructing;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe,
|
2012-02-28 15:11:11 -08:00
|
|
|
const jschar *bytes, unsigned length,
|
|
|
|
const char *filename, unsigned lineno,
|
2013-02-12 12:27:02 -08:00
|
|
|
JSBool eatExceptions, JS::MutableHandleValue rval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSBool retval;
|
|
|
|
JSBool valid;
|
|
|
|
JSExceptionState* exceptionState = NULL;
|
|
|
|
JSContext* cx;
|
|
|
|
|
|
|
|
JS_ASSERT(JSD_CURRENT_THREAD() == jsdthreadstate->thread);
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
valid = jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( ! valid )
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
cx = jsdthreadstate->context;
|
|
|
|
JS_ASSERT(cx);
|
|
|
|
|
|
|
|
if (eatExceptions)
|
|
|
|
exceptionState = JS_SaveExceptionState(cx);
|
|
|
|
JS_ClearPendingException(cx);
|
|
|
|
jsd_StartingEvalUsingFilename(jsdc, filename);
|
2013-01-25 00:49:29 -08:00
|
|
|
retval = jsdframe->frame.evaluateUCInStackFrame(cx, bytes, length, filename, lineno,
|
|
|
|
rval);
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_FinishedEvalUsingFilename(jsdc, filename);
|
|
|
|
if (eatExceptions)
|
|
|
|
JS_RestoreExceptionState(cx, exceptionState);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe,
|
2012-02-28 15:11:11 -08:00
|
|
|
const char *bytes, unsigned length,
|
|
|
|
const char *filename, unsigned lineno,
|
2013-02-12 12:27:02 -08:00
|
|
|
JSBool eatExceptions, JS::MutableHandleValue rval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSBool retval;
|
|
|
|
JSBool valid;
|
|
|
|
JSExceptionState* exceptionState = NULL;
|
|
|
|
JSContext *cx;
|
|
|
|
|
|
|
|
JS_ASSERT(JSD_CURRENT_THREAD() == jsdthreadstate->thread);
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
valid = jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if (!valid)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
cx = jsdthreadstate->context;
|
|
|
|
JS_ASSERT(cx);
|
|
|
|
|
|
|
|
if (eatExceptions)
|
|
|
|
exceptionState = JS_SaveExceptionState(cx);
|
|
|
|
JS_ClearPendingException(cx);
|
|
|
|
jsd_StartingEvalUsingFilename(jsdc, filename);
|
2013-01-25 00:49:29 -08:00
|
|
|
retval = jsdframe->frame.evaluateInStackFrame(cx, bytes, length, filename, lineno,
|
|
|
|
rval);
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_FinishedEvalUsingFilename(jsdc, filename);
|
|
|
|
if (eatExceptions)
|
|
|
|
JS_RestoreExceptionState(cx, exceptionState);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString*
|
|
|
|
jsd_ValToStringInStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe,
|
|
|
|
jsval val)
|
|
|
|
{
|
|
|
|
JSBool valid;
|
|
|
|
JSString* retval;
|
|
|
|
JSExceptionState* exceptionState;
|
|
|
|
JSContext* cx;
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
valid = jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( ! valid )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cx = jsdthreadstate->context;
|
|
|
|
JS_ASSERT(cx);
|
|
|
|
|
|
|
|
exceptionState = JS_SaveExceptionState(cx);
|
|
|
|
retval = JS_ValueToString(cx, val);
|
|
|
|
JS_RestoreExceptionState(cx, exceptionState);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_IsValidThreadState(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
|
|
|
JSDThreadState *cur;
|
|
|
|
|
|
|
|
JS_ASSERT( JSD_THREADSTATES_LOCKED(jsdc) );
|
|
|
|
|
|
|
|
for( cur = (JSDThreadState*)jsdc->threadsStates.next;
|
|
|
|
cur != (JSDThreadState*)&jsdc->threadsStates;
|
|
|
|
cur = (JSDThreadState*)cur->links.next )
|
|
|
|
{
|
|
|
|
if( cur == jsdthreadstate )
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_IsValidFrameInThreadState(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JS_ASSERT(JSD_THREADSTATES_LOCKED(jsdc));
|
|
|
|
|
|
|
|
if( ! jsd_IsValidThreadState(jsdc, jsdthreadstate) )
|
|
|
|
return JS_FALSE;
|
|
|
|
if( jsdframe->jsdthreadstate != jsdthreadstate )
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
JSD_ASSERT_VALID_THREAD_STATE(jsdthreadstate);
|
|
|
|
JSD_ASSERT_VALID_STACK_FRAME(jsdframe);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSContext*
|
|
|
|
_getContextForThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
|
|
|
JSBool valid;
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
valid = jsd_IsValidThreadState(jsdc, jsdthreadstate);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
if( valid )
|
|
|
|
return jsdthreadstate->context;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDValue*
|
|
|
|
jsd_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
|
|
|
JSContext* cx;
|
|
|
|
jsval val;
|
|
|
|
|
|
|
|
if(!(cx = _getContextForThreadState(jsdc, jsdthreadstate)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(JS_GetPendingException(cx, &val))
|
|
|
|
return jsd_NewValue(jsdc, val);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate,
|
|
|
|
JSDValue* jsdval)
|
|
|
|
{
|
|
|
|
JSContext* cx;
|
|
|
|
|
|
|
|
if(!(cx = _getContextForThreadState(jsdc, jsdthreadstate)))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
if(jsdval)
|
|
|
|
JS_SetPendingException(cx, JSD_GetValueWrappedJSVal(jsdc, jsdval));
|
|
|
|
else
|
|
|
|
JS_ClearPendingException(cx);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|