2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-19 02:01:16 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
1999-11-06 05:47:15 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 05:47:15 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-19 02:01:16 +04:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-29 00:14:13 +04:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-19 02:01:16 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-19 02:01:16 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-11-05 11:57:24 +03:00
|
|
|
* JavaScript Debugging support - Call stack support
|
|
|
|
*/
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
#include "jsd.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1998-11-05 11:57:24 +03:00
|
|
|
void JSD_ASSERT_VALID_THREAD_STATE(JSDThreadState* jsdthreadstate)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_ASSERT(jsdthreadstate);
|
|
|
|
JS_ASSERT(jsdthreadstate->stackDepth > 0);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
void JSD_ASSERT_VALID_STACK_FRAME(JSDStackFrameInfo* jsdframe)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_ASSERT(jsdframe);
|
|
|
|
JS_ASSERT(jsdframe->jsdthreadstate);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static JSDStackFrameInfo*
|
1998-11-05 11:57:24 +03:00
|
|
|
_addNewFrame(JSDContext* jsdc,
|
1998-03-28 05:44:41 +03:00
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSScript* script,
|
1998-11-05 11:57:24 +03:00
|
|
|
jsuword pc,
|
|
|
|
JSStackFrame* fp)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
|
|
|
JSDStackFrameInfo* jsdframe;
|
2002-02-14 10:57:30 +03:00
|
|
|
JSDScript* jsdscript = NULL;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2002-02-14 10:57:30 +03:00
|
|
|
if (!JS_IsNativeFrame(jsdthreadstate->context, fp))
|
|
|
|
{
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
jsdscript = jsd_FindJSDScript(jsdc, script);
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
2003-04-19 00:12:11 +04:00
|
|
|
if (!jsdscript || (jsdc->flags & JSD_HIDE_DISABLED_FRAMES &&
|
|
|
|
!JSD_IS_DEBUG_ENABLED(jsdc, jsdscript)))
|
|
|
|
{
|
2002-02-14 10:57:30 +03:00
|
|
|
return NULL;
|
2003-04-19 00:12:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!JSD_IS_DEBUG_ENABLED(jsdc, jsdscript))
|
|
|
|
jsdthreadstate->flags |= TS_HAS_DISABLED_FRAME;
|
2002-02-14 10:57:30 +03:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
jsdframe = (JSDStackFrameInfo*) calloc(1, sizeof(JSDStackFrameInfo));
|
1998-03-28 05:44:41 +03:00
|
|
|
if( ! jsdframe )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
jsdframe->jsdthreadstate = jsdthreadstate;
|
2001-09-01 22:01:28 +04:00
|
|
|
jsdframe->jsdscript = jsdscript;
|
|
|
|
jsdframe->pc = pc;
|
|
|
|
jsdframe->fp = fp;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_APPEND_LINK(&jsdframe->links, &jsdthreadstate->stack);
|
1998-03-28 05:44:41 +03:00
|
|
|
jsdthreadstate->stackDepth++;
|
|
|
|
|
|
|
|
return jsdframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-11-05 11:57:24 +03:00
|
|
|
_destroyFrame(JSDStackFrameInfo* jsdframe)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
|
|
|
/* kill any alloc'd objects in frame here... */
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
if( jsdframe )
|
|
|
|
free(jsdframe);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JSDThreadState*
|
|
|
|
jsd_NewThreadState(JSDContext* jsdc, JSContext *cx )
|
|
|
|
{
|
|
|
|
JSDThreadState* jsdthreadstate;
|
|
|
|
JSStackFrame * iter = NULL;
|
|
|
|
JSStackFrame * fp;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
jsdthreadstate = (JSDThreadState*)calloc(1, sizeof(JSDThreadState));
|
1998-03-28 05:44:41 +03:00
|
|
|
if( ! jsdthreadstate )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
jsdthreadstate->context = cx;
|
1998-11-05 11:57:24 +03:00
|
|
|
jsdthreadstate->thread = JSD_CURRENT_THREAD();
|
|
|
|
JS_INIT_CLIST(&jsdthreadstate->stack);
|
1998-03-28 05:44:41 +03:00
|
|
|
jsdthreadstate->stackDepth = 0;
|
|
|
|
|
|
|
|
while( NULL != (fp = JS_FrameIterator(cx, &iter)) )
|
|
|
|
{
|
|
|
|
JSScript* script = JS_GetFrameScript(cx, fp);
|
1998-11-05 11:57:24 +03:00
|
|
|
jsuword pc = (jsuword) JS_GetFramePC(cx, fp);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2002-02-14 10:57:30 +03: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.
|
|
|
|
*/
|
|
|
|
if (JS_GetFrameThis(cx, fp) &&
|
|
|
|
((jsdc->flags & JSD_INCLUDE_NATIVE_FRAMES) ||
|
|
|
|
!JS_IsNativeFrame(cx, fp)))
|
|
|
|
{
|
2003-04-19 00:12:11 +04:00
|
|
|
JSDStackFrameInfo *frame;
|
|
|
|
|
|
|
|
frame = _addNewFrame( jsdc, jsdthreadstate, script, pc, fp );
|
|
|
|
|
2003-04-19 00:48:43 +04:00
|
|
|
if ((jsdthreadstate->stackDepth == 0 && !frame) ||
|
2003-04-19 00:12:11 +04:00
|
|
|
(jsdthreadstate->stackDepth == 1 && frame &&
|
2004-08-08 23:56:49 +04:00
|
|
|
frame->jsdscript && !JSD_IS_DEBUG_ENABLED(jsdc, frame->jsdscript)))
|
2002-02-27 12:24:14 +03:00
|
|
|
{
|
|
|
|
/*
|
2003-04-19 00:12:11 +04:00
|
|
|
* if we failed to create the first frame, or the top frame
|
|
|
|
* is not enabled for debugging, fail the entire thread state.
|
2002-02-27 12:24:14 +03:00
|
|
|
*/
|
2003-04-19 00:12:11 +04:00
|
|
|
JS_INIT_CLIST(&jsdthreadstate->links);
|
|
|
|
jsd_DestroyThreadState(jsdc, jsdthreadstate);
|
|
|
|
return NULL;
|
2002-02-27 12:24:14 +03:00
|
|
|
}
|
2002-02-14 10:57:30 +03:00
|
|
|
}
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|
2003-04-19 00:12:11 +04:00
|
|
|
|
|
|
|
if (jsdthreadstate->stackDepth == 0)
|
1998-11-05 11:57:24 +03:00
|
|
|
{
|
|
|
|
free(jsdthreadstate);
|
|
|
|
return NULL;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
2003-04-19 00:12:11 +04:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
JS_APPEND_LINK(&jsdthreadstate->links, &jsdc->threadsStates);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
return jsdthreadstate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsd_DestroyThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
|
|
|
JSDStackFrameInfo* jsdframe;
|
1998-11-05 11:57:24 +03:00
|
|
|
JSCList* list;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2006-07-20 19:25:32 +04:00
|
|
|
JS_ASSERT(jsdthreadstate);
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_ASSERT(JSD_CURRENT_THREAD() == jsdthreadstate->thread);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
JS_REMOVE_LINK(&jsdthreadstate->links);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
list = &jsdthreadstate->stack;
|
|
|
|
while( (JSDStackFrameInfo*)list != (jsdframe = (JSDStackFrameInfo*)list->next) )
|
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_REMOVE_LINK(&jsdframe->links);
|
|
|
|
_destroyFrame(jsdframe);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
1998-11-05 11:57:24 +03:00
|
|
|
free(jsdthreadstate);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
uintN
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
uintN count = 0;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
if( jsd_IsValidThreadState(jsdc, jsdthreadstate) )
|
|
|
|
count = jsdthreadstate->stackDepth;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDStackFrameInfo*
|
|
|
|
jsd_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate)
|
|
|
|
{
|
|
|
|
JSDStackFrameInfo* jsdframe = NULL;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
if( jsd_IsValidThreadState(jsdc, jsdthreadstate) )
|
1998-11-05 11:57:24 +03:00
|
|
|
jsdframe = (JSDStackFrameInfo*) JS_LIST_HEAD(&jsdthreadstate->stack);
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
return jsdframe;
|
|
|
|
}
|
|
|
|
|
2001-10-30 16:41:32 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
JSDStackFrameInfo*
|
|
|
|
jsd_GetCallingStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSDStackFrameInfo* nextjsdframe = NULL;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
1998-11-05 11:57:24 +03:00
|
|
|
if( JS_LIST_HEAD(&jsdframe->links) != &jsdframe->jsdthreadstate->stack )
|
|
|
|
nextjsdframe = (JSDStackFrameInfo*) JS_LIST_HEAD(&jsdframe->links);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
return nextjsdframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDScript*
|
|
|
|
jsd_GetScriptForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSDScript* jsdscript = NULL;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
jsdscript = jsdframe->jsdscript;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
return jsdscript;
|
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
jsuword
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_GetPCForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
jsuword pc = 0;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
pc = jsdframe->pc;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSDValue*
|
|
|
|
jsd_GetCallObjectForStackFrame(JSDContext* jsdc,
|
1998-03-28 05:44:41 +03:00
|
|
|
JSDThreadState* jsdthreadstate,
|
1998-11-05 11:57:24 +03:00
|
|
|
JSDStackFrameInfo* jsdframe)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JSObject* obj;
|
|
|
|
JSDValue* jsdval = NULL;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
obj = JS_GetFrameCallObject(jsdthreadstate->context, jsdframe->fp);
|
|
|
|
if(obj)
|
|
|
|
jsdval = JSD_NewValue(jsdc, OBJECT_TO_JSVAL(obj));
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
return jsdval;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSDValue*
|
|
|
|
jsd_GetScopeChainForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JSObject* obj;
|
|
|
|
JSDValue* jsdval = NULL;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2006-06-13 02:39:55 +04:00
|
|
|
JS_BeginRequest(jsdthreadstate->context);
|
1998-11-05 11:57:24 +03:00
|
|
|
obj = JS_GetFrameScopeChain(jsdthreadstate->context, jsdframe->fp);
|
2006-06-13 02:39:55 +04:00
|
|
|
JS_EndRequest(jsdthreadstate->context);
|
1998-11-05 11:57:24 +03:00
|
|
|
if(obj)
|
|
|
|
jsdval = JSD_NewValue(jsdc, OBJECT_TO_JSVAL(obj));
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
return jsdval;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSDValue*
|
|
|
|
jsd_GetThisForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSObject* obj;
|
|
|
|
JSDValue* jsdval = NULL;
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
{
|
|
|
|
obj = JS_GetFrameThis(jsdthreadstate->context, jsdframe->fp);
|
|
|
|
if(obj)
|
|
|
|
jsdval = JSD_NewValue(jsdc, OBJECT_TO_JSVAL(obj));
|
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
return jsdval;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2002-02-14 10:57:30 +03:00
|
|
|
const char*
|
|
|
|
jsd_GetNameForStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
const char *rv = NULL;
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
{
|
|
|
|
JSFunction *fun = JS_GetFrameFunction (jsdthreadstate->context,
|
|
|
|
jsdframe->fp);
|
|
|
|
if (fun)
|
|
|
|
rv = JS_GetFunctionName (fun);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_IsStackFrameNative(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe)
|
|
|
|
{
|
|
|
|
JSBool rv;
|
|
|
|
|
|
|
|
JSD_LOCK_THREADSTATES(jsdc);
|
|
|
|
|
|
|
|
if( jsd_IsValidFrameInThreadState(jsdc, jsdthreadstate, jsdframe) )
|
|
|
|
{
|
|
|
|
rv = JS_IsNativeFrame(jsdthreadstate->context, jsdframe->fp);
|
|
|
|
}
|
2002-02-15 01:39:09 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = JS_FALSE;
|
|
|
|
}
|
2002-02-14 10:57:30 +03: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) )
|
|
|
|
{
|
|
|
|
rv = JS_IsDebuggerFrame(jsdthreadstate->context, jsdframe->fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) )
|
|
|
|
{
|
|
|
|
rv = JS_IsConstructorFrame(jsdthreadstate->context, jsdframe->fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSD_UNLOCK_THREADSTATES(jsdc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSBool
|
2001-04-20 07:47:09 +04:00
|
|
|
jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe,
|
|
|
|
const jschar *bytes, uintN length,
|
2002-01-29 09:15:58 +03:00
|
|
|
const char *filename, uintN lineno,
|
|
|
|
JSBool eatExceptions, jsval *rval)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JSBool retval;
|
|
|
|
JSBool valid;
|
2002-01-30 11:37:57 +03:00
|
|
|
JSExceptionState* exceptionState = NULL;
|
1998-11-05 11:57:24 +03:00
|
|
|
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);
|
|
|
|
|
2002-01-29 09:15:58 +03:00
|
|
|
if (eatExceptions)
|
|
|
|
exceptionState = JS_SaveExceptionState(cx);
|
|
|
|
JS_ClearPendingException(cx);
|
1998-11-05 11:57:24 +03:00
|
|
|
jsd_StartingEvalUsingFilename(jsdc, filename);
|
2001-04-20 07:47:09 +04:00
|
|
|
retval = JS_EvaluateUCInStackFrame(cx, jsdframe->fp, bytes, length,
|
|
|
|
filename, lineno, rval);
|
1998-11-05 11:57:24 +03:00
|
|
|
jsd_FinishedEvalUsingFilename(jsdc, filename);
|
2002-01-29 09:15:58 +03:00
|
|
|
if (eatExceptions)
|
|
|
|
JS_RestoreExceptionState(cx, exceptionState);
|
1998-11-05 11:57:24 +03:00
|
|
|
|
|
|
|
return retval;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2001-04-20 07:47:09 +04:00
|
|
|
JSBool
|
|
|
|
jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe,
|
|
|
|
const char *bytes, uintN length,
|
2002-01-29 09:15:58 +03:00
|
|
|
const char *filename, uintN lineno,
|
|
|
|
JSBool eatExceptions, jsval *rval)
|
2001-04-20 07:47:09 +04:00
|
|
|
{
|
2001-04-25 03:02:58 +04:00
|
|
|
JSBool retval;
|
2001-04-20 07:47:09 +04:00
|
|
|
JSBool valid;
|
2002-01-30 11:37:57 +03:00
|
|
|
JSExceptionState* exceptionState = NULL;
|
2001-04-20 07:47:09 +04:00
|
|
|
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);
|
2001-04-25 03:02:58 +04:00
|
|
|
|
2002-01-29 09:15:58 +03:00
|
|
|
if (eatExceptions)
|
|
|
|
exceptionState = JS_SaveExceptionState(cx);
|
|
|
|
JS_ClearPendingException(cx);
|
2001-04-25 03:02:58 +04:00
|
|
|
jsd_StartingEvalUsingFilename(jsdc, filename);
|
|
|
|
retval = JS_EvaluateInStackFrame(cx, jsdframe->fp, bytes, length,
|
|
|
|
filename, lineno, rval);
|
|
|
|
jsd_FinishedEvalUsingFilename(jsdc, filename);
|
2002-01-29 09:15:58 +03:00
|
|
|
if (eatExceptions)
|
|
|
|
JS_RestoreExceptionState(cx, exceptionState);
|
2001-04-25 03:02:58 +04:00
|
|
|
|
|
|
|
return retval;
|
2001-04-20 07:47:09 +04:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSString*
|
|
|
|
jsd_ValToStringInStackFrame(JSDContext* jsdc,
|
|
|
|
JSDThreadState* jsdthreadstate,
|
|
|
|
JSDStackFrameInfo* jsdframe,
|
|
|
|
jsval val)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
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;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_IsValidThreadState(JSDContext* jsdc,
|
1998-11-05 11:57:24 +03:00
|
|
|
JSDThreadState* jsdthreadstate)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
|
|
|
JSDThreadState *cur;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_ASSERT( JSD_THREADSTATES_LOCKED(jsdc) );
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
for( cur = (JSDThreadState*)jsdc->threadsStates.next;
|
1998-03-28 05:44:41 +03:00
|
|
|
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,
|
1998-11-05 11:57:24 +03:00
|
|
|
JSDStackFrameInfo* jsdframe)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_ASSERT(JSD_THREADSTATES_LOCKED(jsdc));
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
1998-11-05 11:57:24 +03:00
|
|
|
|
|
|
|
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;
|
2001-04-20 07:47:09 +04:00
|
|
|
}
|
|
|
|
|