Changeset 33370

Show
Ignore:
Timestamp:
05/12/08 23:06:43 (6 months ago)
Author:
mrowe@apple.com
Message:

JavaScriptCore:

2008-05-12 Geoffrey Garen <ggaren@apple.com>

Reviewed by Maciej Stachowiak.

Introduced support for function.caller.

Improved support for walking interesting scopes for function introspection.

This fixes all remaining layout tests not blocked by rebasing to trunk.

SunSpider reports no change.

  • VM/Machine.cpp: (KJS::Machine::dumpRegisters): Fixed a spacing issue.

LayoutTests:

2008-05-12 Geoffrey Garen <ggaren@apple.com>

Reviewed by Maciej Stachowiak.

Layout test for function.arguments and function.caller in interesting
scopes.

  • fast/js/function-dot-arguments-and-caller-expected.txt: Added.
  • fast/js/function-dot-arguments-and-caller.html: Added.
Location:
branches/squirrelfish
Files:
2 added
5 modified

Legend:

Unmodified
Added
Removed
  • branches/squirrelfish/JavaScriptCore/ChangeLog

    r33369 r33370  
     12008-05-12  Geoffrey Garen  <ggaren@apple.com> 
     2 
     3        Reviewed by Maciej Stachowiak. 
     4         
     5        Introduced support for function.caller. 
     6         
     7        Improved support for walking interesting scopes for function introspection. 
     8         
     9        This fixes all remaining layout tests not blocked by rebasing to trunk. 
     10         
     11        SunSpider reports no change. 
     12 
     13        * VM/Machine.cpp: 
     14        (KJS::Machine::dumpRegisters): Fixed a spacing issue. 
     15 
    1162008-05-11  Cameron Zwarich  <cwzwarich@uwaterloo.ca> 
    217 
  • branches/squirrelfish/JavaScriptCore/VM/Machine.cpp

    r33367 r33370  
    6161#endif 
    6262 
     63// Retrieves the offset of a calling function within the current register file. 
     64bool getCallerFunctionOffset(Register** registerBase, int callOffset, int& callerOffset) 
     65{ 
     66    Register* callFrame = (*registerBase) + callOffset; 
     67 
     68    CodeBlock* callerCodeBlock = callFrame[Machine::CallerCodeBlock].u.codeBlock; 
     69    if (!callerCodeBlock) // test for top frame of re-entrant function call 
     70        return false; 
     71 
     72    callerOffset = callFrame[Machine::CallerRegisterOffset].u.i - callerCodeBlock->numLocals - Machine::CallFrameHeaderSize; 
     73    if (callerOffset < 0) // test for global frame 
     74        return false; 
     75 
     76    Register* callerCallFrame = (*registerBase) + callerOffset; 
     77    if (!callerCallFrame[Machine::CallerCodeBlock].u.codeBlock) // test for eval frame 
     78        return false; 
     79 
     80    return true; 
     81} 
     82 
    6383// Returns the depth of the scope chain within a given call frame. 
    6484static int depth(ScopeChain& sc) 
     
    442462        if (it != end) { 
    443463            do { 
    444                 printf("[call frame] | %10p | %10p \n", it, (*it).u.jsValue); 
     464                printf("[call frame]  | %10p | %10p \n", it, (*it).u.jsValue); 
    445465                ++it; 
    446466            } while (it != end); 
     
    20422062} 
    20432063 
     2064JSValue* Machine::retrieveCaller(ExecState* exec, FunctionImp* function) const 
     2065{ 
     2066    Register** registerBase; 
     2067    int callFrameOffset; 
     2068 
     2069    if (!getCallFrame(exec, function, registerBase, callFrameOffset)) 
     2070        return jsNull(); 
     2071 
     2072    int callerFrameOffset; 
     2073    if (!getCallerFunctionOffset(registerBase, callFrameOffset, callerFrameOffset)) 
     2074        return jsNull(); 
     2075 
     2076    Register* callerFrame = (*registerBase) + callerFrameOffset; 
     2077    ASSERT(callerFrame[Callee].u.jsValue); 
     2078    return callerFrame[Callee].u.jsValue; 
     2079} 
     2080 
    20442081bool Machine::getCallFrame(ExecState* exec, FunctionImp* function, Register**& registerBase, int& callFrameOffset) const 
    20452082{ 
    20462083    callFrameOffset = exec->m_callFrameOffset; 
    2047     if (callFrameOffset < 0) 
    2048         return false; 
    2049      
    2050     registerBase = exec->m_registerFile->basePointer(); 
    2051     Register* callFrame = (*registerBase) + callFrameOffset; 
    2052     return callFrame[Callee].u.jsValue == function; 
     2084 
     2085    while (1) { 
     2086        while (callFrameOffset < 0) { 
     2087            exec = exec->m_prev; 
     2088            if (!exec) 
     2089                return false; 
     2090            callFrameOffset = exec->m_callFrameOffset; 
     2091        } 
     2092 
     2093        registerBase = exec->m_registerFile->basePointer(); 
     2094        Register* callFrame = (*registerBase) + callFrameOffset; 
     2095        if (callFrame[Callee].u.jsValue == function) 
     2096            return true; 
     2097 
     2098        if (!getCallerFunctionOffset(registerBase, callFrameOffset, callFrameOffset)) 
     2099            callFrameOffset = -1; 
     2100    } 
    20532101} 
    20542102 
  • branches/squirrelfish/JavaScriptCore/VM/Machine.h

    r33346 r33370  
    9090         
    9191        JSValue* retrieveArguments(ExecState*, FunctionImp*) const; 
     92        JSValue* retrieveCaller(ExecState*, FunctionImp*) const; 
    9293         
    9394    private: 
  • branches/squirrelfish/JavaScriptCore/kjs/function.cpp

    r33367 r33370  
    111111    FunctionImp* thisObj = static_cast<FunctionImp*>(slot.slotBase()); 
    112112    ASSERT(exec->machine()); 
    113     UNUSED_PARAM(exec); 
    114     UNUSED_PARAM(slot); 
    115     UNUSED_PARAM(thisObj); 
    116     // FIXME: Implement this. 
    117     return jsNull(); 
     113    return exec->machine()->retrieveCaller(exec, thisObj); 
    118114} 
    119115 
  • branches/squirrelfish/LayoutTests/ChangeLog

    r33369 r33370  
     12008-05-12  Geoffrey Garen  <ggaren@apple.com> 
     2 
     3        Reviewed by Maciej Stachowiak. 
     4         
     5        Layout test for function.arguments and function.caller in interesting 
     6        scopes. 
     7 
     8        * fast/js/function-dot-arguments-and-caller-expected.txt: Added. 
     9        * fast/js/function-dot-arguments-and-caller.html: Added. 
     10 
    1112008-05-11  Cameron Zwarich  <cwzwarich@uwaterloo.ca> 
    212