Back to index

lightning-sunbird  0.9+nobinonly
jsd_java.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* this is all going away... replaced by code in js/jsd/java */
00039 
00040 #if 0
00041 
00042 #include "native.h"
00043 #include "jsdebug.h"
00044 
00045 #include "_gen/netscape_jsdebug_DebugController.h"
00046 #include "_gen/netscape_jsdebug_Script.h"
00047 #include "_gen/netscape_jsdebug_JSThreadState.h"
00048 #include "_gen/netscape_jsdebug_JSStackFrameInfo.h"
00049 #include "_gen/netscape_jsdebug_JSPC.h"
00050 #include "_gen/netscape_jsdebug_JSSourceTextProvider.h"
00051 #include "_gen/netscape_jsdebug_JSErrorReporter.h"
00052 
00053 static JSDContext* context = 0;
00054 static struct Hnetscape_jsdebug_DebugController* controller = 0;
00055 
00056 /***************************************************************************/
00057 /* helpers */
00058 
00059 static JHandle*
00060 _constructInteger(ExecEnv *ee, long i)
00061 {
00062     return (JHandle*) 
00063         execute_java_constructor(ee, "java/lang/Integer", 0, "(I)", i);
00064 }
00065 
00066 static JHandle*
00067 _putHash(ExecEnv *ee, JHandle* tbl, JHandle* key, JHandle* ob)
00068 {
00069     return (JHandle*) 
00070         execute_java_dynamic_method( 
00071             ee, tbl, "put",
00072             "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 
00073             key, ob );
00074 }
00075 
00076 static JHandle*
00077 _getHash(ExecEnv *ee, JHandle* tbl, JHandle* key)
00078 {
00079     return (JHandle*) 
00080         execute_java_dynamic_method( 
00081             ee, tbl, "get",
00082             "(Ljava/lang/Object;)Ljava/lang/Object;", 
00083             key );
00084 }
00085 
00086 static JHandle*
00087 _removeHash(ExecEnv *ee, JHandle* tbl, JHandle* key)
00088 {
00089     return (JHandle*) 
00090         execute_java_dynamic_method( 
00091             ee, tbl, "remove",
00092             "(Ljava/lang/Object;)Ljava/lang/Object;", 
00093             key );
00094 }
00095 
00096 struct Hnetscape_jsdebug_JSStackFrameInfo*
00097 _constructJSStackFrameInfo( ExecEnv* ee, JSDStackFrameInfo* jsdframe, 
00098                             struct Hnetscape_jsdebug_JSThreadState* threadState )
00099 {
00100     struct Hnetscape_jsdebug_JSStackFrameInfo* frame;
00101 
00102     frame = (struct Hnetscape_jsdebug_JSStackFrameInfo*)
00103         execute_java_constructor( ee, "netscape/jsdebug/JSStackFrameInfo", 0, 
00104                                   "(Lnetscape/jsdebug/JSThreadState;)",
00105                                   threadState );
00106     if( ! frame )
00107         return NULL;
00108 
00109     /* XXX fill in additional fields */
00110     unhand(frame)->_nativePtr = (long) jsdframe;
00111 
00112     return frame;
00113 }
00114 
00115 struct Hnetscape_jsdebug_JSPC*
00116 _constructJSPC( ExecEnv* ee, struct Hnetscape_jsdebug_Script* script, long pc )
00117 {
00118     struct Hnetscape_jsdebug_JSPC * pcOb;
00119 
00120     pcOb = (struct Hnetscape_jsdebug_JSPC *)
00121         execute_java_constructor( ee, "netscape/jsdebug/JSPC", 0, 
00122                                   "(Lnetscape/jsdebug/Script;I)",
00123                                   script, pc );
00124     if( ! pcOb )
00125         return NULL;
00126 
00127     /* XXX fill in additional fields */
00128 
00129     return pcOb;
00130 }
00131 
00132 static Hnetscape_jsdebug_Script*
00133 _scriptObFromJSDScriptPtr( ExecEnv* ee, JSDScript* jsdscript )
00134 {
00135     JHandle* tbl = (JHandle*) unhand(controller)->scriptTable;
00136     JHandle* key = _constructInteger(ee,(long)jsdscript);
00137     return (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key );
00138 }
00139 
00140 /***************************************************************************/
00141 
00142 void PR_CALLBACK
00143 _scriptHook( JSDContext* jsdc, 
00144              JSDScript*  jsdscript,
00145              JSBool      creating,
00146              void*       callerdata )
00147 {
00148     Hnetscape_jsdebug_Script* script;
00149     ExecEnv* ee = EE();
00150 
00151     if( ! context || ! controller || ! ee )
00152         return;
00153 
00154     if( creating )
00155     {
00156         char* url      = (char*)JSD_GetScriptFilename       (jsdc, jsdscript);
00157         char* function = (char*)JSD_GetScriptFunctionName   (jsdc, jsdscript);
00158         int base       =        JSD_GetScriptBaseLineNumber (jsdc, jsdscript);
00159         int extent     =        JSD_GetScriptLineExtent     (jsdc, jsdscript);
00160 
00161         if( ! url )
00162         {
00163             return;
00164             /* url = ""; */
00165         }
00166 
00167         /* create Java Object for Script */
00168         script = (Hnetscape_jsdebug_Script*)
00169                 execute_java_constructor(ee, "netscape/jsdebug/Script", 0, "()");
00170 
00171         if( ! script )
00172             return;
00173 
00174         /* set the members */
00175         unhand(script)->_url = makeJavaString(url,strlen(url));
00176         unhand(script)->_function = function ? makeJavaString(function,strlen(function)) : 0;
00177         unhand(script)->_baseLineNumber = base;
00178         unhand(script)->_lineExtent = extent;
00179         unhand(script)->_nativePtr = (long)jsdscript;
00180 
00181         /* add it to the hash table */
00182         _putHash( ee, (JHandle*) unhand(controller)->scriptTable,
00183                   _constructInteger(ee, (long)jsdscript), (JHandle*)script );
00184 
00185         /* call the hook */
00186         if( unhand(controller)->scriptHook )
00187         {
00188             execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook,
00189                                          "justLoadedScript",
00190                                          "(Lnetscape/jsdebug/Script;)V", 
00191                                          script );
00192         }
00193     }
00194     else
00195     {
00196         JHandle* tbl = (JHandle*) unhand(controller)->scriptTable;
00197         JHandle* key = _constructInteger(ee,(long)jsdscript);
00198 
00199         /* find Java Object for Script    */
00200         script = (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key );
00201 
00202         if( ! script )
00203             return;
00204 
00205         /* remove it from the hash table  */
00206         _removeHash( ee, tbl, key );
00207 
00208         /* call the hook */
00209         if( unhand(controller)->scriptHook )
00210         {
00211             execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook,
00212                                          "aboutToUnloadScript",
00213                                          "(Lnetscape/jsdebug/Script;)V", 
00214                                          script );
00215         }
00216         /* set the Script as invalid */
00217         execute_java_dynamic_method( ee,(JHandle*)script,
00218                                      "_setInvalid",
00219                                      "()V" );
00220     }
00221 }
00222 
00223 /***************************************************************************/
00224 PRUintn PR_CALLBACK
00225 _executionHook( JSDContext*     jsdc, 
00226                 JSDThreadState* jsdstate,
00227                 PRUintn         type,
00228                 void*           callerdata )
00229 {
00230     Hnetscape_jsdebug_JSThreadState* threadState;
00231     Hnetscape_jsdebug_Script* script;
00232     JHandle* pcOb;
00233     JSDStackFrameInfo* jsdframe;
00234     JSDScript*  jsdscript;
00235     int pc;
00236     JHandle* tblScript;
00237     JHandle* keyScript;
00238     ExecEnv* ee = EE();
00239 
00240     if( ! context || ! controller || ! ee )
00241         return JSD_HOOK_RETURN_HOOK_ERROR;
00242 
00243     /* get the JSDStackFrameInfo */
00244     jsdframe = JSD_GetStackFrame(jsdc, jsdstate);
00245     if( ! jsdframe )
00246         return JSD_HOOK_RETURN_HOOK_ERROR;
00247 
00248     /* get the JSDScript */
00249     jsdscript = JSD_GetScriptForStackFrame(jsdc, jsdstate, jsdframe);
00250     if( ! jsdscript )
00251         return JSD_HOOK_RETURN_HOOK_ERROR;
00252 
00253     /* find Java Object for Script    */
00254     tblScript = (JHandle*) unhand(controller)->scriptTable;
00255     keyScript = _constructInteger(ee, (long)jsdscript);
00256     script = (Hnetscape_jsdebug_Script*) _getHash( ee, tblScript, keyScript );
00257     if( ! script )
00258         return JSD_HOOK_RETURN_HOOK_ERROR;
00259 
00260     /* generate a JSPC */
00261     pc = JSD_GetPCForStackFrame(jsdc, jsdstate, jsdframe);
00262 
00263     pcOb = (JHandle*)
00264         _constructJSPC(ee, script, pc);
00265     if( ! pcOb )
00266         return JSD_HOOK_RETURN_HOOK_ERROR;
00267 
00268     /* build a JSThreadState */
00269     threadState = (struct Hnetscape_jsdebug_JSThreadState*)
00270             execute_java_constructor( ee, "netscape/jsdebug/JSThreadState",0,"()");
00271     if( ! threadState )
00272         return JSD_HOOK_RETURN_HOOK_ERROR;
00273 
00274     /* populate the ThreadState */
00275     /* XXX FILL IN THE REST... */
00276     unhand(threadState)->valid           = 1; /* correct value for true? */
00277     unhand(threadState)->currentFramePtr = (long) jsdframe;
00278     unhand(threadState)->nativeThreadState = (long) jsdstate;
00279     unhand(threadState)->continueState = netscape_jsdebug_JSThreadState_DEBUG_STATE_RUN;
00280 
00281     /* XXX FILL IN THE REST... */
00282 
00283 
00284     /* find and call the appropriate Hook */
00285     if( JSD_HOOK_INTERRUPTED == type )
00286     {
00287         JHandle* hook;
00288 
00289         /* clear the JSD level hook (must reset on next sendInterrupt0()*/
00290         JSD_ClearInterruptHook(context); 
00291 
00292         hook = (JHandle*) unhand(controller)->interruptHook;
00293         if( ! hook )
00294             return JSD_HOOK_RETURN_HOOK_ERROR;
00295 
00296         /* call the hook */
00297         execute_java_dynamic_method( 
00298             ee, hook, "aboutToExecute",
00299             "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V",
00300             threadState, pcOb );
00301     }
00302     else if( JSD_HOOK_DEBUG_REQUESTED == type )
00303     {
00304         JHandle* hook;
00305 
00306         hook = (JHandle*) unhand(controller)->debugBreakHook;
00307         if( ! hook )
00308             return JSD_HOOK_RETURN_HOOK_ERROR;
00309 
00310         /* call the hook */
00311         execute_java_dynamic_method( 
00312             ee, hook, "aboutToExecute",
00313             "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V",
00314             threadState, pcOb );
00315     }
00316     else if( JSD_HOOK_BREAKPOINT == type )
00317     {
00318         JHandle* hook;
00319 
00320         hook = (JHandle*)
00321                 execute_java_dynamic_method( 
00322                         ee,(JHandle*)controller,
00323                         "getInstructionHook0",
00324                         "(Lnetscape/jsdebug/PC;)Lnetscape/jsdebug/InstructionHook;",
00325                         pcOb );
00326         if( ! hook )
00327             return JSD_HOOK_RETURN_HOOK_ERROR;
00328 
00329         /* call the hook */
00330         execute_java_dynamic_method( 
00331             ee, hook, "aboutToExecute",
00332             "(Lnetscape/jsdebug/ThreadStateBase;)V",
00333             threadState );
00334     }
00335 
00336     if( netscape_jsdebug_JSThreadState_DEBUG_STATE_THROW == 
00337         unhand(threadState)->continueState )
00338         return JSD_HOOK_RETURN_ABORT;
00339 
00340     return JSD_HOOK_RETURN_CONTINUE;
00341 }
00342 
00343 PRUintn PR_CALLBACK
00344 _errorReporter( JSDContext*     jsdc, 
00345                 JSContext*      cx,
00346                 const char*     message, 
00347                 JSErrorReport*  report,
00348                 void*           callerdata )
00349 {
00350     JHandle* reporter;
00351     JHandle* msg         = NULL;
00352     JHandle* filename    = NULL;
00353     int      lineno      = 0;
00354     JHandle* linebuf     = NULL;
00355     int      tokenOffset = 0;
00356     ExecEnv* ee = EE();
00357 
00358     if( ! context || ! controller || ! ee )
00359         return JSD_ERROR_REPORTER_PASS_ALONG;
00360 
00361     reporter = (JHandle*) unhand(controller)->errorReporter;
00362     if( ! reporter )
00363         return JSD_ERROR_REPORTER_PASS_ALONG;
00364 
00365     if( message )
00366         msg = (JHandle*) makeJavaString((char*)message, strlen(message));
00367     if( report && report->filename )
00368         filename = (JHandle*) makeJavaString((char*)report->filename, strlen(report->filename));
00369     if( report && report->linebuf )
00370         linebuf = (JHandle*) makeJavaString((char*)report->linebuf, strlen(report->linebuf));
00371     if( report )
00372         lineno = report->lineno;
00373     if( report && report->linebuf && report->tokenptr )
00374         tokenOffset = report->tokenptr - report->linebuf;
00375 
00376     return (int) 
00377         execute_java_dynamic_method( 
00378                 ee, reporter, "reportError",
00379                 "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;I)I", 
00380                 msg,
00381                 filename,
00382                 lineno,
00383                 linebuf,
00384                 tokenOffset );
00385 }
00386 
00387 /***************************************************************************/
00388 /* from "_gen\netscape_jsdebug_DebugController.h" */
00389 
00390 
00391 /* XXX HACK */
00392 JSDContext* _simContext = 0;
00393 
00394 void netscape_jsdebug_DebugController__setController(struct Hnetscape_jsdebug_DebugController * self,/*boolean*/ long on)
00395 {
00396     if(on)
00397     {
00398         context = JSD_DebuggerOn();
00399         if( ! context )
00400             return;
00401 
00402         _simContext = context; /* XXX HACK */
00403 
00404         unhand(self)->_nativeContext = (long) context;
00405         controller = self;
00406         JSD_SetScriptHook(context, _scriptHook, (void*)1 );
00407         JSD_SetErrorReporter(context, _errorReporter, (void*)1 );
00408         JSD_SetDebugBreakHook(context, _executionHook, (void*)1 );
00409     }
00410     else
00411     {
00412         /* XXX stop somehow... */
00413         /* kill context        */
00414         JSD_SetDebugBreakHook(context, NULL, NULL );
00415         JSD_SetErrorReporter(context, NULL, NULL);
00416         JSD_SetScriptHook(context, NULL, NULL);
00417         context = 0;
00418         controller = 0;
00419     }
00420 }
00421 
00422 void netscape_jsdebug_DebugController_setInstructionHook0(struct Hnetscape_jsdebug_DebugController * self,struct Hnetscape_jsdebug_PC * pcOb)
00423 {
00424     Hnetscape_jsdebug_Script* script;
00425     JSDScript* jsdscript;
00426     PRUintn pc;
00427     ExecEnv* ee = EE();
00428 
00429     if( ! context || ! controller || ! ee )
00430         return;
00431 
00432     script = (Hnetscape_jsdebug_Script*)
00433         execute_java_dynamic_method(ee, (JHandle*)pcOb, "getScript","()Lnetscape/jsdebug/Script;");
00434 
00435     if( ! script )
00436         return;
00437 
00438     jsdscript = (JSDScript*) unhand(script)->_nativePtr;
00439     if( ! jsdscript )
00440         return;
00441 
00442     pc = (PRUintn)
00443         execute_java_dynamic_method(ee, (JHandle*)pcOb, "getPC","()I");
00444 
00445     JSD_SetExecutionHook(context, jsdscript, pc, _executionHook, 0);
00446 }
00447 
00448 void netscape_jsdebug_DebugController_sendInterrupt0(struct Hnetscape_jsdebug_DebugController * self)
00449 {
00450     if( ! context || ! controller )
00451         return;
00452     JSD_SetInterruptHook(context, _executionHook, 0);
00453 }
00454 
00455 struct Hjava_lang_String *netscape_jsdebug_DebugController_executeScriptInStackFrame0(struct Hnetscape_jsdebug_DebugController *self,struct Hnetscape_jsdebug_JSStackFrameInfo *frame,struct Hjava_lang_String *src,struct Hjava_lang_String *filename,long lineno)
00456 {
00457     struct Hnetscape_jsdebug_JSThreadState* threadStateOb;
00458     JSDThreadState* jsdthreadstate;
00459     JSDStackFrameInfo* jsdframe;
00460     char* filenameC;
00461     char* srcC;
00462     JSString* jsstr;
00463     jsval rval;
00464     JSBool success;
00465     int srclen;
00466 
00467     threadStateOb = (struct Hnetscape_jsdebug_JSThreadState*)unhand(frame)->threadState;
00468     jsdthreadstate = (JSDThreadState*) unhand(threadStateOb)->nativeThreadState;
00469 
00470     jsdframe = (JSDStackFrameInfo*) unhand(frame)->_nativePtr;
00471 
00472     if( ! context || ! controller || ! jsdframe )
00473         return NULL;
00474 
00475     filenameC = allocCString(filename);
00476     if( ! filenameC )
00477         return NULL;
00478     srcC = allocCString(src);
00479     if( ! srcC )
00480     {
00481         free(filenameC);
00482         return NULL;
00483     }
00484 
00485     srclen = strlen(srcC);
00486 
00487     success = JSD_EvaluateScriptInStackFrame(context, jsdthreadstate, jsdframe, 
00488                                              srcC, srclen,
00489                                              filenameC, lineno, &rval);
00490 
00491     /* XXX crashing on Windows under Symantec (though I can't see why!)*/
00492 
00493     free(filenameC);
00494     free(srcC);
00495 
00496 
00497     if( ! success )
00498         return NULL;
00499 
00500     if( JSVAL_IS_NULL(rval) || JSVAL_IS_VOID(rval) )
00501         return NULL;
00502 
00503     jsstr = JSD_ValToStringInStackFrame(context,jsdthreadstate,jsdframe,rval);
00504     if( ! jsstr )
00505         return NULL;
00506 
00507     /* XXXbe should use JS_GetStringChars and preserve Unicode. */
00508     return makeJavaString((char*)JS_GetStringBytes(jsstr), JS_GetStringLength(jsstr));
00509 }    
00510 
00511 long netscape_jsdebug_DebugController_getNativeMajorVersion(struct Hnetscape_jsdebug_DebugController* self)
00512 {
00513     return (long) JSD_GetMajorVersion();
00514 }
00515 
00516 long netscape_jsdebug_DebugController_getNativeMinorVersion(struct Hnetscape_jsdebug_DebugController* self)
00517 {
00518     return (long) JSD_GetMinorVersion();
00519 }
00520 
00521 /***************************************************************************/
00522 /* from "_gen\netscape_jsdebug_Script.h" */
00523 
00524 struct Hnetscape_jsdebug_JSPC *netscape_jsdebug_Script_getClosestPC(struct Hnetscape_jsdebug_Script * self,long line)
00525 {
00526     PRUintn pc;
00527     JSDScript* jsdscript;
00528 
00529     if( ! context || ! controller )
00530         return 0;
00531 
00532     jsdscript = (JSDScript*) unhand(self)->_nativePtr;
00533     if( ! jsdscript )
00534         return 0;
00535 
00536     pc = JSD_GetClosestPC(context, jsdscript, line);
00537 
00538     if( -1 == pc )
00539         return 0;
00540     return _constructJSPC( 0, self, pc);
00541 }
00542 
00543 /***************************************************************************/
00544 /* from "_gen\netscape_jsdebug_JSThreadState.h" */
00545 
00546 long netscape_jsdebug_JSThreadState_countStackFrames(struct Hnetscape_jsdebug_JSThreadState * self)
00547 {
00548     JSDThreadState* jsdstate;
00549         
00550     if( ! context || ! controller )
00551         return 0;
00552 
00553     jsdstate = (JSDThreadState*) unhand(self)->nativeThreadState;
00554 
00555     if( ! jsdstate )
00556         return 0;
00557 
00558     return (long) JSD_GetCountOfStackFrames(context, jsdstate);
00559 }
00560 
00561 struct Hnetscape_jsdebug_StackFrameInfo *netscape_jsdebug_JSThreadState_getCurrentFrame(struct Hnetscape_jsdebug_JSThreadState * self)
00562 {
00563     JSDThreadState* jsdstate;
00564     JSDStackFrameInfo* jsdframe;
00565         
00566     if( ! context || ! controller )
00567         return NULL;
00568 
00569     jsdstate = (JSDThreadState*) unhand(self)->nativeThreadState;
00570 
00571     if( ! jsdstate )
00572         return NULL;
00573 
00574     jsdframe = JSD_GetStackFrame(context, jsdstate);
00575     if( ! jsdframe )
00576         return NULL;
00577 
00578     return (struct Hnetscape_jsdebug_StackFrameInfo*)
00579                 _constructJSStackFrameInfo( 0, jsdframe, self );
00580 }
00581 
00582 
00583 /***************************************************************************/
00584 /* from "_gen\netscape_jsdebug_JSStackFrameInfo.h" */
00585 
00586 struct Hnetscape_jsdebug_StackFrameInfo *netscape_jsdebug_JSStackFrameInfo_getCaller0(struct Hnetscape_jsdebug_JSStackFrameInfo * self)
00587 {
00588     JSDStackFrameInfo* jsdframeCur;
00589     JSDStackFrameInfo* jsdframeCaller;
00590     struct Hnetscape_jsdebug_JSThreadState* threadState;
00591     JSDThreadState* jsdthreadstate;
00592 
00593     if( ! context || ! controller )
00594         return NULL;
00595 
00596     jsdframeCur = (JSDStackFrameInfo*) unhand(self)->_nativePtr;
00597     if( ! jsdframeCur )
00598         return NULL;
00599 
00600     threadState = (struct Hnetscape_jsdebug_JSThreadState*) unhand(self)->threadState;
00601     if( ! threadState )
00602         return NULL;
00603 
00604     jsdthreadstate = (JSDThreadState*) unhand(threadState)->nativeThreadState;
00605     if( ! jsdthreadstate )
00606         return NULL;
00607 
00608     jsdframeCaller = JSD_GetCallingStackFrame(context, jsdthreadstate, jsdframeCur);
00609     if( ! jsdframeCaller )
00610         return NULL;
00611 
00612     return (struct Hnetscape_jsdebug_StackFrameInfo*)
00613                 _constructJSStackFrameInfo( 0, jsdframeCaller, threadState );
00614 }
00615 struct Hnetscape_jsdebug_PC *netscape_jsdebug_JSStackFrameInfo_getPC(struct Hnetscape_jsdebug_JSStackFrameInfo * self)
00616 {
00617     JSDScript* jsdscript;
00618     JSDStackFrameInfo* jsdframe;
00619     struct Hnetscape_jsdebug_Script* script;
00620     struct Hnetscape_jsdebug_JSThreadState* threadState;
00621     JSDThreadState* jsdthreadstate;
00622     int pc;
00623     ExecEnv* ee = EE();
00624 
00625     if( ! context || ! controller || ! ee )
00626         return NULL;
00627 
00628     jsdframe = (JSDStackFrameInfo*) unhand(self)->_nativePtr;
00629     if( ! jsdframe )
00630         return NULL;
00631 
00632     threadState = (struct Hnetscape_jsdebug_JSThreadState*) unhand(self)->threadState;
00633     if( ! threadState )
00634         return NULL;
00635 
00636     jsdthreadstate = (JSDThreadState*) unhand(threadState)->nativeThreadState;
00637     if( ! jsdthreadstate )
00638         return NULL;
00639 
00640     jsdscript = JSD_GetScriptForStackFrame(context, jsdthreadstate, jsdframe );
00641     if( ! jsdscript )
00642         return NULL;
00643 
00644     script = _scriptObFromJSDScriptPtr(ee, jsdscript);
00645     if( ! script )
00646         return NULL;
00647 
00648     pc = JSD_GetPCForStackFrame(context, jsdthreadstate, jsdframe);
00649     if( ! pc )
00650         return NULL;
00651 
00652     return (struct Hnetscape_jsdebug_PC*) _constructJSPC(ee, script, pc);
00653 }
00654 
00655 /***************************************************************************/
00656 /* from "_gen\netscape_jsdebug_JSPC.h" */
00657 
00658 struct Hnetscape_jsdebug_SourceLocation *netscape_jsdebug_JSPC_getSourceLocation(struct Hnetscape_jsdebug_JSPC * self)
00659 {
00660     JSDScript* jsdscript;
00661     struct Hnetscape_jsdebug_Script* script;
00662     struct Hnetscape_jsdebug_JSPC* newPCOb;
00663     int line;
00664     int newpc;
00665     int pc;
00666     ExecEnv* ee = EE();
00667 
00668     if( ! context || ! controller || ! ee )
00669         return NULL;
00670 
00671     script = unhand(self)->script;
00672 
00673     if( ! script )
00674         return NULL;
00675 
00676     jsdscript = (JSDScript*) unhand(script)->_nativePtr;
00677     if( ! jsdscript )
00678         return NULL;
00679     pc = unhand(self)->pc;
00680 
00681     line = JSD_GetClosestLine(context, jsdscript, pc);
00682     newpc = JSD_GetClosestPC(context, jsdscript, line);
00683 
00684     newPCOb = _constructJSPC(ee, script, newpc );
00685     if( ! newPCOb )
00686         return NULL;
00687 
00688     return (struct Hnetscape_jsdebug_SourceLocation *)
00689         execute_java_constructor( ee, "netscape/jsdebug/JSSourceLocation", 0, 
00690                                   "(Lnetscape/jsdebug/JSPC;I)",
00691                                   newPCOb, line );
00692 }
00693 
00694 /***************************************************************************/
00695 /* from "_gen\netscape_jsdebug_JSSourceTextProvider.h" */
00696 
00697 struct Hnetscape_jsdebug_SourceTextItem *netscape_jsdebug_JSSourceTextProvider_loadSourceTextItem0(struct Hnetscape_jsdebug_JSSourceTextProvider * self,struct Hjava_lang_String * url)
00698 {
00699     /* this should attempt to load the source for the indicated URL */
00700     return NULL;    
00701 }
00702 
00703 void netscape_jsdebug_JSSourceTextProvider_refreshSourceTextVector(struct Hnetscape_jsdebug_JSSourceTextProvider * self)
00704 {
00705 
00706     JHandle* vec;
00707     JHandle* itemOb;
00708     JSDSourceText* iterp = 0;
00709     JSDSourceText* item;
00710     const char* url;
00711     struct Hjava_lang_String* urlOb;
00712     ExecEnv* ee = EE();
00713 
00714     if( ! context || ! controller || ! ee )
00715         return;
00716 
00717     /* create new vector */
00718     vec = (JHandle*) execute_java_constructor(ee, "netscape/util/Vector", 0, "()");
00719     if( ! vec )
00720         return;
00721 
00722     /* lock the native subsystem */
00723     JSD_LockSourceTextSubsystem(context);
00724 
00725     /* iterate through the native items */
00726     while( 0 != (item = JSD_IterateSources(context, &iterp)) )
00727     {
00728         int urlStrLen;
00729         int status = JSD_GetSourceStatus(context,item);
00730 
00731         /* try to find Java object */
00732         url = JSD_GetSourceURL(context, item);
00733         if( ! url || 0 == (urlStrLen = strlen(url)) ) /* ignoring those with no url */
00734             continue;
00735 
00736         urlOb = makeJavaString((char*)url,urlStrLen);
00737         if( ! urlOb )
00738             continue;
00739 
00740         itemOb = (JHandle*)
00741             execute_java_dynamic_method( ee, (JHandle*)self, "findSourceTextItem0",
00742                       "(Ljava/lang/String;)Lnetscape/jsdebug/SourceTextItem;",
00743                       urlOb );
00744                       
00745         if( ! itemOb )
00746         {
00747             /* if not found then generate new item */
00748             struct Hjava_lang_String* textOb;
00749             const char* str;
00750             int length;
00751 
00752             if( ! JSD_GetSourceText(context, item, &str, &length ) )
00753             {
00754                 str = "";
00755                 length = 0;
00756             }
00757             textOb = makeJavaString((char*)str, length);
00758 
00759             itemOb = (JHandle*)
00760                 execute_java_constructor(ee, "netscape/jsdebug/SourceTextItem",0,  
00761                      "(Ljava/lang/String;Ljava/lang/String;I)",
00762                      urlOb, textOb, status );
00763         }
00764         else if( JSD_IsSourceDirty(context, item) && 
00765                  JSD_SOURCE_CLEARED != status )
00766         {
00767             /* if found and dirty then update */
00768             struct Hjava_lang_String* textOb;
00769             const char* str;
00770             int length;
00771 
00772             if( ! JSD_GetSourceText(context, item, &str, &length ) )
00773             {
00774                 str = "";
00775                 length = 0;
00776             }
00777             textOb = makeJavaString((char*)str, length);
00778             execute_java_dynamic_method(ee, itemOb, "setText", 
00779                                         "(Ljava/lang/String;)V", textOb);
00780             execute_java_dynamic_method(ee, itemOb, "setStatus", 
00781                                         "(I)V", status );
00782             execute_java_dynamic_method(ee, itemOb, "setDirty", "(Z)V", 1 );
00783         }
00784 
00785         /* we have our copy; clear the native cached text */
00786         if( JSD_SOURCE_INITED  != status && 
00787             JSD_SOURCE_PARTIAL != status &&
00788             JSD_SOURCE_CLEARED != status )
00789         {
00790             JSD_ClearSourceText(context, item);
00791         }
00792 
00793         /* set the item clean */
00794         JSD_SetSourceDirty(context, item, FALSE );
00795 
00796         /* add the item to the vector */
00797         if( itemOb )
00798             execute_java_dynamic_method(ee, vec, "addElement", 
00799                                         "(Ljava/lang/Object;)V", itemOb );
00800     }
00801     /* unlock the native subsystem */
00802     JSD_UnlockSourceTextSubsystem(context);
00803 
00804     /* set main vector to our new vector */
00805 
00806     unhand(self)->_sourceTextVector = (struct Hnetscape_util_Vector*) vec;
00807 }    
00808 
00809 
00810 #endif