static Hnetscape_jsdebug_Script*
_scriptObFromJSDScriptPtr( ExecEnv* ee, JSDScript* jsdscript )
{
    JHandle* tbl = (JHandle*) unhand(controller)->scriptTable;
    JHandle* key = _constructInteger(ee,(long)jsdscript);
    return (Hnetscape_jsdebug_Script*) _getHash( ee, tbl, key );
}
Beispiel #2
0
/* Method 2: Replace value, but don't delete link */
void insertMap (struct hashMap * ht, KeyType k, ValueType v) {
    ht->count++;
    if(tableLoad(ht) >= (float)LOAD_FACTOR_THRESHOLD)
        _setTableSize(ht, ht->tableSize*2);
    int i = _getHash(ht, k, hashFunc);
    struct hashLink *curr = ht->table[i];
    struct hashLink *prev = NULL;
    while(curr != NULL) {
        if(_compare(curr->key, k) == 0) {
            curr->value = v;                /* These two lines differ from Method 1 */
            return;
        }
        prev = curr;
        curr = _nextLink(curr);
    }
    curr = malloc(sizeof(struct hashLink));
    assert(curr != NULL);
    size_t keyMemBuf = (strlen(k) + 1) * sizeof(char);
    curr->key = malloc(keyMemBuf);
    memcpy(curr->key, k, keyMemBuf);
    curr->value = v;
    curr->next = NULL;
    if(prev != NULL)
        prev->next = curr;
    else
        ht->table[i] = curr;
}
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" );
    }
}