(not part of mozilla build) added source hook to jsdbgapi so that debugger can get clean access to source from jsscan when the JSFILE hack is used

git-svn-id: svn://10.0.0.236/trunk@9810 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jband%netscape.com
1998-09-11 04:04:26 +00:00
parent 7c46498749
commit 8d91096b15
7 changed files with 86 additions and 60 deletions

View File

@@ -1082,6 +1082,63 @@ static JSPropertySpec its_props[] = {
{0}
};
#ifdef JSD_LOWLEVEL_SOURCE
/*
* This facilitates sending source to JSD (the debugger system) in the shell
* where the source is loaded using the JSFILE hack in jsscan. The function
* below is used as a callback for the jsdbgapi JS_SetSourceHandler hook.
* A more normal embedding (e.g. mozilla) loads source itself and can send
* source directly to JSD without using this hook scheme.
*
* XXX At some future point JSD will understand Unicode source and the
* *very* ugly conversion below will be unnecessary.
*/
static void
SendSourceToJSDebugger(const char *filename, uintN lineno,
jschar *str, size_t length,
void **listenerTSData, JSDContext* jsdc)
{
JSDSourceText *jsdsrc = (JSDSourceText *) *listenerTSData;
if (!jsdsrc) {
if (!filename)
filename = "typein";
if (1 == lineno) {
jsdsrc = JSD_NewSourceText(jsdc, filename);
} else {
jsdsrc = JSD_FindSourceForURL(jsdc, filename);
if (jsdsrc && JSD_SOURCE_PARTIAL !=
JSD_GetSourceStatus(jsdc, jsdsrc)) {
jsdsrc = NULL;
}
}
}
if (jsdsrc) {
/* here we convert our Unicode into a C string to pass to JSD */
#define JSD_BUF_SIZE 1024
static char* buf = NULL;
int remaining = length;
if (!buf)
buf = malloc(JSD_BUF_SIZE);
if (buf)
{
while (remaining && jsdsrc) {
int bytes = PR_MIN(remaining, JSD_BUF_SIZE);
int i;
for (i = 0; i < bytes; i++)
buf[i] = (const char) *(str++);
jsdsrc = JSD_AppendSourceText(jsdc,jsdsrc,
buf, bytes,
JSD_SOURCE_PARTIAL);
remaining -= bytes;
}
}
}
*listenerTSData = jsdsrc;
}
#endif /* JSD_LOWLEVEL_SOURCE */
static JSBool its_noisy; /* whether to be noisy when finalizing it */
static JSBool
@@ -1438,7 +1495,9 @@ main(int argc, char **argv)
if (!_jsdc)
return 1;
JSD_JSContextInUse(_jsdc, cx);
#ifdef JSD_LOWLEVEL_SOURCE
JS_SetSourceHandler(rt, SendSourceToJSDebugger, _jsdc);
#endif /* JSD_LOWLEVEL_SOURCE */
#ifdef JSDEBUGGER_JAVA_UI
_jsdjc = JSDJ_CreateContext();
if (! _jsdjc)

View File

@@ -82,6 +82,8 @@ struct JSRuntime {
void *destroyScriptHookData;
JSTrapHandler debuggerHandler;
void *debuggerHandlerData;
JSSourceHandler sourceHandler;
void *sourceHandlerData;
/* More debugging state, see jsdbgapi.c. */
PRCList trapList;

View File

@@ -806,3 +806,11 @@ JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure)
rt->debuggerHandlerData = closure;
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure)
{
rt->sourceHandler = handler;
rt->sourceHandlerData = closure;
return JS_TRUE;
}

View File

@@ -223,6 +223,9 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
extern JS_PUBLIC_API(JSBool)
JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure);
extern JS_PUBLIC_API(JSBool)
JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
PR_END_EXTERN_C
#endif /* jsdbgapi_h___ */

View File

@@ -96,4 +96,9 @@ typedef void
JSScript *script,
void *callerdata );
typedef void
(*JSSourceHandler)(const char *filename, uintN lineno,
jschar *str, size_t length,
void **listenerTSData, void *closure);
#endif /* jsprvtd_h___ */

View File

@@ -201,9 +201,8 @@ js_NewBufferTokenStream(JSContext *cx, const jschar *base, size_t length)
ts->userbuf.base = (jschar *)base;
ts->userbuf.limit = (jschar *)base + length;
ts->userbuf.ptr = (jschar *)base;
#ifdef JSD_LOWLEVEL_SOURCE
ts->jsdc = JSD_JSDContextForJSContext(cx);
#endif
ts->listener = cx->runtime->sourceHandler;
ts->listenerData = cx->runtime->sourceHandlerData;
return ts;
}
@@ -250,48 +249,6 @@ js_CloseTokenStream(JSContext *cx, JSTokenStream *ts)
#endif
}
#ifdef JSD_LOWLEVEL_SOURCE
static void
SendSourceToJSDebugger(JSTokenStream *ts, jschar *str, size_t length)
{
if (!ts->jsdsrc) {
const char* filename = ts->filename ? ts->filename : "typein";
if (1 == ts->lineno) {
ts->jsdsrc = JSD_NewSourceText(ts->jsdc, filename);
} else {
ts->jsdsrc = JSD_FindSourceForURL(ts->jsdc, filename);
if (ts->jsdsrc && JSD_SOURCE_PARTIAL !=
JSD_GetSourceStatus(ts->jsdc, ts->jsdsrc)) {
ts->jsdsrc = NULL;
}
}
}
if (ts->jsdsrc) {
/* here we convert our Unicode into a C string to pass to JSD */
#define JSD_BUF_SIZE 1024
static char* buf = NULL;
int remaining = length;
if (!buf)
buf = malloc(JSD_BUF_SIZE);
if (buf)
{
while (remaining && ts->jsdsrc) {
int bytes = PR_MIN(remaining, JSD_BUF_SIZE);
int i;
for (i = 0; i < bytes; i++)
buf[i] = (const char) *(str++);
ts->jsdsrc = JSD_AppendSourceText(ts->jsdc,ts->jsdsrc,
buf, bytes,
JSD_SOURCE_PARTIAL);
remaining -= bytes;
}
}
}
}
#endif
static int32
GetChar(JSTokenStream *ts)
{
@@ -341,12 +298,9 @@ GetChar(JSTokenStream *ts)
return EOF;
}
}
#ifdef JSD_LOWLEVEL_SOURCE
if (ts->jsdc)
SendSourceToJSDebugger(ts, ts->userbuf.ptr, len);
#endif
if (ts->listener)
(*ts->listener)(ts->filename, ts->lineno, ts->userbuf.ptr, len,
&ts->listenerTSData, ts->listenerData);
/*
* Any one of \n, \r, or \r\n ends a line (longest match wins).
*/

View File

@@ -29,10 +29,6 @@
#include "jsprvtd.h"
#include "jspubtd.h"
#ifdef JSD_LOWLEVEL_SOURCE
#include "jsdebug.h"
#endif
PR_BEGIN_EXTERN_C
typedef enum JSTokenType {
@@ -152,10 +148,9 @@ struct JSTokenStream {
FILE *file; /* stdio stream if reading from file */
#endif
JSPrincipals *principals; /* principals associated with given input */
#ifdef JSD_LOWLEVEL_SOURCE
JSDContext *jsdc; /* used to cram source into debugger */
JSDSourceText *jsdsrc; /* used to cram source into debugger */
#endif
JSSourceHandler listener; /* callback for source; eg debugger */
void *listenerData; /* listener 'this' data */
void *listenerTSData;/* listener data for this TokenStream */
};
/* JSTokenStream flags */