/** * Signal an error by creating the object and throwing the exception. * See also SignalErrorf * * @param cname the name of the class of the exception object to be created * @param str the message to be passed to the constructor of the exception object */ void SignalError(const char* cname, const char* str) { Hjava_lang_Throwable* obj; if (str == NULL || *str == '\0') { obj = (Hjava_lang_Throwable*)execute_java_constructor(cname, NULL, NULL, ERROR_SIGNATURE0); } else { obj = (Hjava_lang_Throwable*)execute_java_constructor(cname, NULL, NULL, ERROR_SIGNATURE, checkPtr(stringC2Java(str))); } throwException(obj); }
struct Hnetscape_jsdebug_SourceLocation *netscape_jsdebug_JSPC_getSourceLocation(struct Hnetscape_jsdebug_JSPC * self) { JSDScript* jsdscript; struct Hnetscape_jsdebug_Script* script; struct Hnetscape_jsdebug_JSPC* newPCOb; int line; int newpc; int pc; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return NULL; script = unhand(self)->script; if( ! script ) return NULL; jsdscript = (JSDScript*) unhand(script)->_nativePtr; if( ! jsdscript ) return NULL; pc = unhand(self)->pc; line = JSD_GetClosestLine(context, jsdscript, pc); newpc = JSD_GetClosestPC(context, jsdscript, line); newPCOb = _constructJSPC(ee, script, newpc ); if( ! newPCOb ) return NULL; return (struct Hnetscape_jsdebug_SourceLocation *) execute_java_constructor( ee, "netscape/jsdebug/JSSourceLocation", 0, "(Lnetscape/jsdebug/JSPC;I)", newPCOb, line ); }
struct Hnetscape_jsdebug_JSPC* _constructJSPC( ExecEnv* ee, struct Hnetscape_jsdebug_Script* script, long pc ) { struct Hnetscape_jsdebug_JSPC * pcOb; pcOb = (struct Hnetscape_jsdebug_JSPC *) execute_java_constructor( ee, "netscape/jsdebug/JSPC", 0, "(Lnetscape/jsdebug/Script;I)", script, pc ); if( ! pcOb ) return NULL; /* XXX fill in additional fields */ return pcOb; }
struct Hnetscape_jsdebug_JSStackFrameInfo* _constructJSStackFrameInfo( ExecEnv* ee, JSDStackFrameInfo* jsdframe, struct Hnetscape_jsdebug_JSThreadState* threadState ) { struct Hnetscape_jsdebug_JSStackFrameInfo* frame; frame = (struct Hnetscape_jsdebug_JSStackFrameInfo*) execute_java_constructor( ee, "netscape/jsdebug/JSStackFrameInfo", 0, "(Lnetscape/jsdebug/JSThreadState;)", threadState ); if( ! frame ) return NULL; /* XXX fill in additional fields */ unhand(frame)->_nativePtr = (long) jsdframe; return frame; }
void netscape_jsdebug_JSSourceTextProvider_refreshSourceTextVector(struct Hnetscape_jsdebug_JSSourceTextProvider * self) { JHandle* vec; JHandle* itemOb; JSDSourceText* iterp = 0; JSDSourceText* item; const char* url; struct Hjava_lang_String* urlOb; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return; /* create new vector */ vec = (JHandle*) execute_java_constructor(ee, "netscape/util/Vector", 0, "()"); if( ! vec ) return; /* lock the native subsystem */ JSD_LockSourceTextSubsystem(context); /* iterate through the native items */ while( 0 != (item = JSD_IterateSources(context, &iterp)) ) { int urlStrLen; int status = JSD_GetSourceStatus(context,item); /* try to find Java object */ url = JSD_GetSourceURL(context, item); if( ! url || 0 == (urlStrLen = strlen(url)) ) /* ignoring those with no url */ continue; urlOb = makeJavaString((char*)url,urlStrLen); if( ! urlOb ) continue; itemOb = (JHandle*) execute_java_dynamic_method( ee, (JHandle*)self, "findSourceTextItem0", "(Ljava/lang/String;)Lnetscape/jsdebug/SourceTextItem;", urlOb ); if( ! itemOb ) { /* if not found then generate new item */ struct Hjava_lang_String* textOb; const char* str; int length; if( ! JSD_GetSourceText(context, item, &str, &length ) ) { str = ""; length = 0; } textOb = makeJavaString((char*)str, length); itemOb = (JHandle*) execute_java_constructor(ee, "netscape/jsdebug/SourceTextItem",0, "(Ljava/lang/String;Ljava/lang/String;I)", urlOb, textOb, status ); } else if( JSD_IsSourceDirty(context, item) && JSD_SOURCE_CLEARED != status ) { /* if found and dirty then update */ struct Hjava_lang_String* textOb; const char* str; int length; if( ! JSD_GetSourceText(context, item, &str, &length ) ) { str = ""; length = 0; } textOb = makeJavaString((char*)str, length); execute_java_dynamic_method(ee, itemOb, "setText", "(Ljava/lang/String;)V", textOb); execute_java_dynamic_method(ee, itemOb, "setStatus", "(I)V", status ); execute_java_dynamic_method(ee, itemOb, "setDirty", "(Z)V", 1 ); } /* we have our copy; clear the native cached text */ if( JSD_SOURCE_INITED != status && JSD_SOURCE_PARTIAL != status && JSD_SOURCE_CLEARED != status ) { JSD_ClearSourceText(context, item); } /* set the item clean */ JSD_SetSourceDirty(context, item, FALSE ); /* add the item to the vector */ if( itemOb ) execute_java_dynamic_method(ee, vec, "addElement", "(Ljava/lang/Object;)V", itemOb ); } /* unlock the native subsystem */ JSD_UnlockSourceTextSubsystem(context); /* set main vector to our new vector */ unhand(self)->_sourceTextVector = (struct Hnetscape_util_Vector*) vec; }
static JHandle* _constructInteger(ExecEnv *ee, long i) { return (JHandle*) execute_java_constructor(ee, "java/lang/Integer", 0, "(I)", i); }
unsigned _executionHook( JSDContext* jsdc, JSDThreadState* jsdstate, unsigned type, void* callerdata ) { Hnetscape_jsdebug_JSThreadState* threadState; Hnetscape_jsdebug_Script* script; JHandle* pcOb; JSDStackFrameInfo* jsdframe; JSDScript* jsdscript; int pc; JHandle* tblScript; JHandle* keyScript; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return JSD_HOOK_RETURN_HOOK_ERROR; /* get the JSDStackFrameInfo */ jsdframe = JSD_GetStackFrame(jsdc, jsdstate); if( ! jsdframe ) return JSD_HOOK_RETURN_HOOK_ERROR; /* get the JSDScript */ jsdscript = JSD_GetScriptForStackFrame(jsdc, jsdstate, jsdframe); if( ! jsdscript ) return JSD_HOOK_RETURN_HOOK_ERROR; /* find Java Object for Script */ tblScript = (JHandle*) unhand(controller)->scriptTable; keyScript = _constructInteger(ee, (long)jsdscript); script = (Hnetscape_jsdebug_Script*) _getHash( ee, tblScript, keyScript ); if( ! script ) return JSD_HOOK_RETURN_HOOK_ERROR; /* generate a JSPC */ pc = JSD_GetPCForStackFrame(jsdc, jsdstate, jsdframe); pcOb = (JHandle*) _constructJSPC(ee, script, pc); if( ! pcOb ) return JSD_HOOK_RETURN_HOOK_ERROR; /* build a JSThreadState */ threadState = (struct Hnetscape_jsdebug_JSThreadState*) execute_java_constructor( ee, "netscape/jsdebug/JSThreadState",0,"()"); if( ! threadState ) return JSD_HOOK_RETURN_HOOK_ERROR; /* populate the ThreadState */ /* XXX FILL IN THE REST... */ unhand(threadState)->valid = 1; /* correct value for true? */ unhand(threadState)->currentFramePtr = (long) jsdframe; unhand(threadState)->nativeThreadState = (long) jsdstate; unhand(threadState)->continueState = netscape_jsdebug_JSThreadState_DEBUG_STATE_RUN; /* XXX FILL IN THE REST... */ /* find and call the appropriate Hook */ if( JSD_HOOK_INTERRUPTED == type ) { JHandle* hook; /* clear the JSD level hook (must reset on next sendInterrupt0()*/ JSD_ClearInterruptHook(context); hook = (JHandle*) unhand(controller)->interruptHook; if( ! hook ) return JSD_HOOK_RETURN_HOOK_ERROR; /* call the hook */ execute_java_dynamic_method( ee, hook, "aboutToExecute", "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V", threadState, pcOb ); } else if( JSD_HOOK_DEBUG_REQUESTED == type ) { JHandle* hook; hook = (JHandle*) unhand(controller)->debugBreakHook; if( ! hook ) return JSD_HOOK_RETURN_HOOK_ERROR; /* call the hook */ execute_java_dynamic_method( ee, hook, "aboutToExecute", "(Lnetscape/jsdebug/ThreadStateBase;Lnetscape/jsdebug/PC;)V", threadState, pcOb ); } else if( JSD_HOOK_BREAKPOINT == type ) { JHandle* hook; hook = (JHandle*) execute_java_dynamic_method( ee,(JHandle*)controller, "getInstructionHook0", "(Lnetscape/jsdebug/PC;)Lnetscape/jsdebug/InstructionHook;", pcOb ); if( ! hook ) return JSD_HOOK_RETURN_HOOK_ERROR; /* call the hook */ execute_java_dynamic_method( ee, hook, "aboutToExecute", "(Lnetscape/jsdebug/ThreadStateBase;)V", threadState ); } if( netscape_jsdebug_JSThreadState_DEBUG_STATE_THROW == unhand(threadState)->continueState ) return JSD_HOOK_RETURN_ABORT; return JSD_HOOK_RETURN_CONTINUE; }
void _scriptHook( JSDContext* jsdc, JSDScript* jsdscript, JSBool creating, void* callerdata ) { Hnetscape_jsdebug_Script* script; ExecEnv* ee = EE(); if( ! context || ! controller || ! ee ) return; if( creating ) { char* url = (char*)JSD_GetScriptFilename (jsdc, jsdscript); JSString* function = JSD_GetScriptFunctionId (jsdc, jsdscript); int base = JSD_GetScriptBaseLineNumber (jsdc, jsdscript); int extent = JSD_GetScriptLineExtent (jsdc, jsdscript); if( ! url ) { return; /* url = ""; */ } /* create Java Object for Script */ script = (Hnetscape_jsdebug_Script*) execute_java_constructor(ee, "netscape/jsdebug/Script", 0, "()"); if( ! script ) return; /* set the members */ unhand(script)->_url = makeJavaString(url,strlen(url)); unhand(script)->_function = function ? makeJavaString(function,strlen(function)) : 0; unhand(script)->_baseLineNumber = base; unhand(script)->_lineExtent = extent; unhand(script)->_nativePtr = (long)jsdscript; /* add it to the hash table */ _putHash( ee, (JHandle*) unhand(controller)->scriptTable, _constructInteger(ee, (long)jsdscript), (JHandle*)script ); /* call the hook */ if( unhand(controller)->scriptHook ) { execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook, "justLoadedScript", "(Lnetscape/jsdebug/Script;)V", script ); } } else { JHandle* tbl = (JHandle*) unhand(controller)->scriptTable; JHandle* key = _constructInteger(ee,(long)jsdscript); /* find Java Object for Script */ script = (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key ); if( ! script ) return; /* remove it from the hash table */ _removeHash( ee, tbl, key ); /* call the hook */ if( unhand(controller)->scriptHook ) { execute_java_dynamic_method( ee,(JHandle*)unhand(controller)->scriptHook, "aboutToUnloadScript", "(Lnetscape/jsdebug/Script;)V", script ); } /* set the Script as invalid */ execute_java_dynamic_method( ee,(JHandle*)script, "_setInvalid", "()V" ); } }