From 8d91096b152ff4930b18ae83a61a4dfd969b5fc6 Mon Sep 17 00:00:00 2001 From: "jband%netscape.com" Date: Fri, 11 Sep 1998 04:04:26 +0000 Subject: [PATCH] (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 --- mozilla/js/ref/js.c | 61 ++++++++++++++++++++++++++++++++++++++- mozilla/js/ref/jscntxt.h | 2 ++ mozilla/js/ref/jsdbgapi.c | 8 +++++ mozilla/js/ref/jsdbgapi.h | 3 ++ mozilla/js/ref/jsprvtd.h | 5 ++++ mozilla/js/ref/jsscan.c | 56 ++++------------------------------- mozilla/js/ref/jsscan.h | 11 ++----- 7 files changed, 86 insertions(+), 60 deletions(-) diff --git a/mozilla/js/ref/js.c b/mozilla/js/ref/js.c index 2dbe9833e0f..72331595977 100644 --- a/mozilla/js/ref/js.c +++ b/mozilla/js/ref/js.c @@ -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) diff --git a/mozilla/js/ref/jscntxt.h b/mozilla/js/ref/jscntxt.h index 5f2508e36b1..7068c9e03d9 100644 --- a/mozilla/js/ref/jscntxt.h +++ b/mozilla/js/ref/jscntxt.h @@ -82,6 +82,8 @@ struct JSRuntime { void *destroyScriptHookData; JSTrapHandler debuggerHandler; void *debuggerHandlerData; + JSSourceHandler sourceHandler; + void *sourceHandlerData; /* More debugging state, see jsdbgapi.c. */ PRCList trapList; diff --git a/mozilla/js/ref/jsdbgapi.c b/mozilla/js/ref/jsdbgapi.c index 48b3cdc36d3..965f5faf341 100644 --- a/mozilla/js/ref/jsdbgapi.c +++ b/mozilla/js/ref/jsdbgapi.c @@ -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; +} diff --git a/mozilla/js/ref/jsdbgapi.h b/mozilla/js/ref/jsdbgapi.h index 0db62504c5f..82be27a5927 100644 --- a/mozilla/js/ref/jsdbgapi.h +++ b/mozilla/js/ref/jsdbgapi.h @@ -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___ */ diff --git a/mozilla/js/ref/jsprvtd.h b/mozilla/js/ref/jsprvtd.h index 29c12ebb5c6..b1dac7d2613 100644 --- a/mozilla/js/ref/jsprvtd.h +++ b/mozilla/js/ref/jsprvtd.h @@ -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___ */ diff --git a/mozilla/js/ref/jsscan.c b/mozilla/js/ref/jsscan.c index edf3206cebb..e32a4c1781c 100644 --- a/mozilla/js/ref/jsscan.c +++ b/mozilla/js/ref/jsscan.c @@ -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). */ diff --git a/mozilla/js/ref/jsscan.h b/mozilla/js/ref/jsscan.h index 4f1a361ab5a..fd9b56d9165 100644 --- a/mozilla/js/ref/jsscan.h +++ b/mozilla/js/ref/jsscan.h @@ -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 */