Changeset 34372 in webkit for trunk/JavaScriptCore/VM/Machine.cpp


Ignore:
Timestamp:
Jun 4, 2008, 10:36:55 PM (17 years ago)
Author:
[email protected]
Message:

2008-06-04 Sam Weinig <[email protected]>

Reviewed by Maciej Stachowiak.

Big cleanup of formatting and whitespace.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/Machine.cpp

    r34371 r34372  
    8181{
    8282    int scopeDepth = 0;
    83     ScopeChainIterator iter = sc.begin(); 
    84     ScopeChainIterator end = sc.end(); 
     83    ScopeChainIterator iter = sc.begin();
     84    ScopeChainIterator end = sc.end();
    8585    while (!(*iter)->isVariableObject()) {
    8686        ++iter;
     
    8989    return scopeDepth;
    9090}
    91    
     91
    9292static inline bool jsLess(ExecState* exec, JSValue* v1, JSValue* v2)
    9393{
     
    219219    return false;
    220220}
    221    
     221
    222222static bool NEVER_INLINE resolve_skip(ExecState* exec, Instruction* vPC, Register* r, ScopeChainNode* scopeChain, CodeBlock* codeBlock, JSValue*& exceptionValue)
    223223{
     
    225225    int property = (vPC + 2)->u.operand;
    226226    int skip = (vPC + 3)->u.operand + codeBlock->needsFullScopeChain;
    227    
     227
    228228    ScopeChainIterator iter = scopeChain->begin();
    229229    ScopeChainIterator end = scopeChain->end();
     
    280280    int propDst = (vPC + 2)->u.operand;
    281281    int property = (vPC + 3)->u.operand;
    282    
     282
    283283    ScopeChainIterator iter = scopeChain->begin();
    284284    ScopeChainIterator end = scopeChain->end();
    285    
     285
    286286    // FIXME: add scopeDepthIsZero optimization
    287    
     287
    288288    ASSERT(iter != end);
    289    
     289
    290290    Identifier& ident = codeBlock->identifiers[property];
    291291    JSObject* base;
     
    298298            if (exceptionValue)
    299299                return false;
    300             r[propDst].u.jsValue = result;   
     300            r[propDst].u.jsValue = result;
    301301            r[baseDst].u.jsValue = base;
    302302            return true;
     
    304304        ++iter;
    305305    } while (iter != end);
    306    
     306
    307307    exceptionValue = createUndefinedVariableError(exec, ident);
    308308    return false;
     
    317317    ScopeChainIterator iter = scopeChain->begin();
    318318    ScopeChainIterator end = scopeChain->end();
    319    
     319
    320320    // FIXME: add scopeDepthIsZero optimization
    321    
     321
    322322    ASSERT(iter != end);
    323    
     323
    324324    Identifier& ident = codeBlock->identifiers[property];
    325325    JSObject* base;
     
    340340            if (exceptionValue)
    341341                return false;
    342            
     342
    343343            r[baseDst].u.jsValue = thisObj;
    344344            r[funcDst].u.jsValue = result;
     
    385385        }
    386386        r = (*registerBase) + registerOffset;
    387        
     387
    388388        int omittedArgCount = newCodeBlock->numParameters - argc;
    389389        Register* endOfParams = r - newCodeBlock->numVars;
     
    400400        }
    401401        r = (*registerBase) + registerOffset;
    402        
     402
    403403        Register* it = r - newCodeBlock->numLocals - Machine::CallFrameHeaderSize - shift;
    404404        Register* end = it + Machine::CallFrameHeaderSize + newCodeBlock->numParameters;
     
    436436
    437437    JSValue* program = r[argv + 1].u.jsValue;
    438    
     438
    439439    if (!program->isString())
    440440        return program;
    441    
     441
    442442    Profiler** profiler = Profiler::enabledProfilerReference();
    443443    if (*profiler)
     
    448448    UString errMsg;
    449449    RefPtr<EvalNode> evalNode = parser().parse<EvalNode>(exec, UString(), 1, UStringSourceProvider::create(static_cast<StringImp*>(program)->value()), &sourceId, &errLine, &errMsg);
    450    
     450
    451451    if (!evalNode) {
    452452        exceptionValue = Error::create(exec, SyntaxError, errMsg, errLine, sourceId, NULL);
     
    491491    printf("     use      |   address  |    value   \n");
    492492    printf("----------------------------------------\n");
    493    
     493
    494494    const Register* it;
    495495    const Register* end;
    496    
     496
    497497    if (isGlobalCallFrame(registerFile->basePointer(), r)) {
    498498        it = r - registerFile->numGlobalSlots();
     
    515515            printf("----------------------------------------\n");
    516516        }
    517        
     517
    518518        end = it + codeBlock->numParameters;
    519519        if (it != end) {
     
    559559    CodeBlock* oldCodeBlock = codeBlock;
    560560    Register* callFrame = r - oldCodeBlock->numLocals - CallFrameHeaderSize;
    561    
     561
    562562    if (Debugger* debugger = exec->dynamicGlobalObject()->debugger()) {
    563563        DebuggerCallFrame debuggerCallFrame(this, exec->dynamicGlobalObject(), codeBlock, scopeChain, exceptionValue, registerBase, r - *registerBase);
     
    577577    if (oldCodeBlock->needsFullScopeChain)
    578578        scopeChain->deref();
    579    
     579
    580580    if (isGlobalCallFrame(registerBase, r))
    581581        return false;
     
    620620    // Calculate an exception handler vPC, unwinding call frames as necessary.
    621621
    622     int scopeDepth;       
     622    int scopeDepth;
    623623    Instruction* handlerVPC;
    624624
    625     while (!codeBlock->getHandlerForVPC(vPC, handlerVPC, scopeDepth))
     625    while (!codeBlock->getHandlerForVPC(vPC, handlerVPC, scopeDepth)) {
    626626        if (!unwindCallFrame(exec, exceptionValue, registerBase, vPC, codeBlock, k, scopeChain, r))
    627627            return 0;
     628    }
    628629
    629630    // Now unwind the scope chain within the exception handler's call frame.
    630    
     631
    631632    ScopeChain sc(scopeChain);
    632633    int scopeDelta = depth(sc) - scopeDepth;
     
    659660
    660661    r[ProgramCodeThisRegister].u.jsValue = thisObj;
    661    
     662
    662663    if (codeBlock->needsFullScopeChain)
    663664        scopeChain = scopeChain->copy();
     
    692693    int argv = CallFrameHeaderSize;
    693694    int argc = args.size() + 1; // implicit "this" parameter
    694    
     695
    695696    size_t oldSize = registerFile->size();
    696697    if (!registerFile->grow(oldSize + CallFrameHeaderSize + argc)) {
     
    698699        return 0;
    699700    }
    700        
     701
    701702    Register** registerBase = registerFile->basePointer();
    702703    int registerOffset = oldSize;
    703704    int callFrameOffset = registerOffset;
    704705    Register* callFrame = (*registerBase) + callFrameOffset;
    705    
     706
    706707    // put args in place, including "this"
    707708    Register* dst = callFrame + CallFrameHeaderSize;
    708709    (*dst).u.jsValue = thisObj;
    709    
     710
    710711    List::const_iterator end = args.end();
    711712    for (List::const_iterator it = args.begin(); it != end; ++it)
     
    722723    }
    723724
    724     scopeChain = scopeChainForCall(functionBodyNode, newCodeBlock, scopeChain, registerBase, r);           
     725    scopeChain = scopeChainForCall(functionBodyNode, newCodeBlock, scopeChain, registerBase, r);
    725726
    726727    ExecState newExec(exec, this, registerFile, scopeChain, callFrameOffset);
    727    
     728
    728729    Profiler** profiler = Profiler::enabledProfilerReference();
    729730    if (*profiler)
     
    746747
    747748    EvalCodeBlock* codeBlock = &evalNode->code(scopeChain);
    748    
     749
    749750    JSVariableObject* variableObject;
    750751    for (ScopeChainNode* node = scopeChain; ; node = node->next) {
     
    755756        }
    756757    }
    757    
     758
    758759    const Node::VarStack& varStack = codeBlock->ownerNode->varStack();
    759760    Node::VarStack::const_iterator varStackEnd = varStack.end();
     
    763764            variableObject->put(exec, ident, jsUndefined());
    764765    }
    765    
     766
    766767    const Node::FunctionStack& functionStack = codeBlock->ownerNode->functionStack();
    767768    Node::FunctionStack::const_iterator functionStackEnd = functionStack.end();
    768769    for (Node::FunctionStack::const_iterator it = functionStack.begin(); it != functionStackEnd; ++it)
    769770        variableObject->put(exec, (*it)->m_ident, (*it)->makeFunction(exec, scopeChain));
    770    
     771
    771772    size_t oldSize = registerFile->size();
    772773    size_t newSize = registerOffset + codeBlock->numVars + codeBlock->numTemporaries + CallFrameHeaderSize;
     
    777778
    778779    Register* callFrame = *registerFile->basePointer() + registerOffset;
    779    
     780
    780781    // put call frame in place, using a 0 codeBlock to indicate a built-in caller
    781782    initializeCallFrame(callFrame, 0, 0, 0, registerOffset, 0, 0, 0, 0, 0);
     
    889890    JSValue** k = codeBlock->jsValues.data();
    890891    Profiler** enabledProfilerReference = Profiler::enabledProfilerReference();
    891    
     892
    892893#if HAVE(COMPUTED_GOTO)
    893894    // Yet another hack around GCC's various foibles, in this case fetching the
     
    922923    #define BEGIN_OPCODE(opcode) case opcode:
    923924#endif
    924     while(1) // iterator loop begins
     925    while (1) // iterator loop begins
    925926    switch (vPC->u.opcode)
    926927#endif
     
    934935        int src = (++vPC)->u.operand;
    935936        r[dst].u.jsValue = k[src];
    936        
     937
    937938        ++vPC;
    938939        NEXT_OPCODE;
     
    946947        int dst = (++vPC)->u.operand;
    947948        r[dst].u.jsValue = scopeChain->globalObject()->objectConstructor()->construct(exec, exec->emptyList());
    948        
     949
    949950        ++vPC;
    950951        NEXT_OPCODE;
     
    958959        int dst = (++vPC)->u.operand;
    959960        r[dst].u.jsValue = scopeChain->globalObject()->arrayConstructor()->construct(exec, exec->emptyList());
    960        
     961
    961962        ++vPC;
    962963        NEXT_OPCODE;
     
    10461047        else
    10471048            dst = jsBoolean(strictEqual(src1, src2));
    1048        
     1049
    10491050        ++vPC;
    10501051        NEXT_OPCODE;
     
    11171118        VM_CHECK_EXCEPTION();
    11181119        r[srcDst].u.jsValue = result;
    1119        
     1120
    11201121        ++vPC;
    11211122        NEXT_OPCODE;
     
    12811282        /* mod dst(r) dividend(r) divisor(r)
    12821283
    1283            Divides register dividend (converted to number) by 
     1284           Divides register dividend (converted to number) by
    12841285           register divisor (converted to number), and puts the
    12851286           remainder in register dst.
     
    13341335        }
    13351336        dst = result;
    1336        
     1337
    13371338        ++vPC;
    13381339        NEXT_OPCODE;
     
    13561357        }
    13571358        dst = result;
    1358        
     1359
    13591360        ++vPC;
    13601361        NEXT_OPCODE;
     
    13781379        }
    13791380        dst = result;
    1380        
     1381
    13811382        ++vPC;
    13821383        NEXT_OPCODE;
     
    14001401        }
    14011402        dst = result;
    1402        
     1403
    14031404        ++vPC;
    14041405        NEXT_OPCODE;
     
    14221423        }
    14231424        dst = result;
    1424        
     1425
    14251426        ++vPC;
    14261427        NEXT_OPCODE;
     
    14441445        }
    14451446        dst = result;
    1446        
     1447
    14471448        ++vPC;
    14481449        NEXT_OPCODE;
     
    14831484           Tests whether register value is an instance of register
    14841485           constructor, and puts the boolean result in register dst.
    1485          
     1486
    14861487           Raises an exception if register constructor is not an
    14871488           object.
     
    15201521           Tests whether register base has a property named register
    15211522           property, and puts the boolean result in register dst.
    1522          
     1523
    15231524           Raises an exception if register constructor is not an
    15241525           object.
     
    15631564    BEGIN_OPCODE(op_resolve_skip) {
    15641565        /* resolve_skip dst(r) property(id) skip(n)
    1565          
     1566
    15661567         Looks up the property named by identifier property in the
    15671568         scope chain skipping the top 'skip' levels, and writes the resulting
     
    15701571        if (UNLIKELY(!resolve_skip(exec, vPC, r, scopeChain, codeBlock, exceptionValue)))
    15711572            goto vm_throw;
    1572        
     1573
    15731574        vPC += 4;
    1574        
     1575
    15751576        NEXT_OPCODE;
    15761577    }
    15771578    BEGIN_OPCODE(op_get_scoped_var) {
    15781579        /* get_scoped_var dst(r) index(n) skip(n)
    1579          
     1580
    15801581         Loads the contents of the index-th local from the scope skip nodes from
    15811582         the top of the scope chain, and places it in register dst
     
    15841585        int index = (++vPC)->u.operand;
    15851586        int skip = (++vPC)->u.operand + codeBlock->needsFullScopeChain;
    1586        
     1587
    15871588        ScopeChainIterator iter = scopeChain->begin();
    15881589        ScopeChainIterator end = scopeChain->end();
     
    15921593            ASSERT(iter != end);
    15931594        }
    1594        
     1595
    15951596        ASSERT((*iter)->isVariableObject());
    15961597        JSVariableObject* scope = static_cast<JSVariableObject*>(*iter);
     
    16061607        int skip = (++vPC)->u.operand + codeBlock->needsFullScopeChain;
    16071608        int value = (++vPC)->u.operand;
    1608        
     1609
    16091610        ScopeChainIterator iter = scopeChain->begin();
    16101611        ScopeChainIterator end = scopeChain->end();
     
    16141615            ASSERT(iter != end);
    16151616        }
    1616        
     1617
    16171618        ASSERT((*iter)->isVariableObject());
    16181619        JSVariableObject* scope = static_cast<JSVariableObject*>(*iter);
     
    17001701           Sets register value on register base as the property named
    17011702           by identifier property. Base is converted to object first.
    1702  
     1703
    17031704           Unlike many opcodes, this one does not write any output to
    17041705           the register file.
     
    17101711        int registerOffset = r - (*registerBase);
    17111712#endif
    1712        
     1713
    17131714        Identifier& ident = codeBlock->identifiers[property];
    17141715        r[base].u.jsValue->put(exec, ident, r[value].u.jsValue);
    17151716        ASSERT(registerOffset == (r - (*registerBase)));
    1716        
     1717
    17171718        VM_CHECK_EXCEPTION();
    17181719        ++vPC;
     
    17321733
    17331734        JSObject* baseObj = r[base].u.jsValue->toObject(exec);
    1734        
     1735
    17351736        Identifier& ident = codeBlock->identifiers[property];
    17361737        JSValue* result = jsBoolean(baseObj->deleteProperty(exec, ident));
     
    17531754
    17541755        JSValue* baseValue = r[base].u.jsValue;
    1755        
     1756
    17561757        JSValue* subscript = r[property].u.jsValue;
    17571758        JSValue* result;
     
    17721773            result = baseObj->get(exec, property);
    17731774        }
    1774        
     1775
    17751776        VM_CHECK_EXCEPTION();
    17761777        r[dst].u.jsValue = result;
     
    17851786           first. register property is nominally converted to string
    17861787           but numbers are treated more efficiently.
    1787  
     1788
    17881789           Unlike many opcodes, this one does not write any output to
    17891790           the register file.
     
    17941795
    17951796        JSValue* baseValue = r[base].u.jsValue;
    1796        
     1797
    17971798        JSValue* subscript = r[property].u.jsValue;
    17981799
     
    18131814            baseObj->put(exec, property, r[value].u.jsValue);
    18141815        }
    1815        
     1816
    18161817        VM_CHECK_EXCEPTION();
    18171818        ++vPC;
     
    18431844            result = jsBoolean(baseObj->deleteProperty(exec, property));
    18441845        }
    1845        
     1846
    18461847        VM_CHECK_EXCEPTION();
    18471848        r[dst].u.jsValue = result;
     
    18561857           object first. register property is nominally converted to
    18571858           string but numbers are treated more efficiently.
    1858  
     1859
    18591860           Unlike many opcodes, this one does not write any output to
    18601861           the register file.
     
    18731874    BEGIN_OPCODE(op_jmp) {
    18741875        /* jmp target(offset)
    1875          
     1876
    18761877           Jumps unconditionally to offset target from the current
    18771878           instruction.
     
    18841885    BEGIN_OPCODE(op_jtrue) {
    18851886        /* jtrue cond(r) target(offset)
    1886          
     1887
    18871888           Jumps to offset target from the current instruction, if and
    18881889           only if register cond converts to boolean as true.
     
    19001901    BEGIN_OPCODE(op_jfalse) {
    19011902        /* jfalse cond(r) target(offset)
    1902          
     1903
    19031904           Jumps to offset target from the current instruction, if and
    19041905           only if register cond converts to boolean as false.
     
    19661967        JSValue* funcVal = r[func].u.jsValue;
    19671968        JSValue* baseVal = r[thisVal].u.jsValue;
    1968        
     1969
    19691970        if (baseVal == scopeChain->globalObject() && funcVal == scopeChain->globalObject()->evalFunction()) {
    19701971            int registerOffset = r - (*registerBase);
     
    19831984
    19841985            r[dst].u.jsValue = result;
    1985            
     1986
    19861987            ++vPC;
    19871988            NEXT_OPCODE;
    19881989        }
    1989        
     1990
    19901991        // We didn't find the blessed version of eval, so reset vPC and process
    19911992        // this instruction as a normal function call, supplying the proper 'this'
     
    20442045        int firstArg = (++vPC)->u.operand;
    20452046        int argCount = (++vPC)->u.operand;
    2046        
     2047
    20472048        JSValue* v = r[func].u.jsValue;
    2048        
     2049
    20492050        CallData callData;
    20502051        CallType callType = v->getCallData(callData);
    2051        
     2052
    20522053        if (callType == CallTypeJS) {
    20532054            if (*enabledProfilerReference)
     
    21402141            returnValue = thisObject;
    21412142        }
    2142          
     2143
    21432144        codeBlock = callFrame[CallerCodeBlock].u.codeBlock;
    21442145        if (!codeBlock)
    21452146            return returnValue;
    2146        
     2147
    21472148        k = codeBlock->jsValues.data();
    21482149        vPC = callFrame[ReturnVPC].u.vPC;
     
    22542255        JSObject* o = v->toObject(exec);
    22552256        VM_CHECK_EXCEPTION();
    2256        
     2257
    22572258        setScopeChain(exec, scopeChain, scopeChain->push(o));
    22582259
     
    23182319        int count = (++vPC)->u.operand;
    23192320        int target = (++vPC)->u.operand;
    2320        
     2321
    23212322        ScopeChainNode* tmp = scopeChain;
    23222323        while (count--)
    23232324            tmp = tmp->pop();
    23242325        setScopeChain(exec, scopeChain, tmp);
    2325            
     2326
    23262327        vPC += target;
    23272328        NEXT_OPCODE;
     
    23852386        int type = (++vPC)->u.operand;
    23862387        int message = (++vPC)->u.operand;
    2387        
     2388
    23882389        r[dst].u.jsValue = Error::create(exec, (ErrorType)type, k[message]->toString(exec), codeBlock->lineNumberForVPC(vPC), codeBlock->ownerNode->sourceId(), codeBlock->ownerNode->sourceURL());
    2389        
     2390
    23902391        ++vPC;
    23912392        NEXT_OPCODE;
     
    24072408    BEGIN_OPCODE(op_put_getter) {
    24082409        /* put_getter base(r) property(id) function(r)
    2409          
     2410
    24102411           Sets register function on register base as the getter named
    24112412           by identifier property. Base and function are assumed to be
    24122413           objects as this op should only be used for getters defined
    24132414           in object literal form.
    2414          
     2415
    24152416           Unlike many opcodes, this one does not write any output to
    24162417           the register file.
     
    24192420        int property = (++vPC)->u.operand;
    24202421        int function = (++vPC)->u.operand;
    2421        
     2422
    24222423        ASSERT(r[base].u.jsValue->isObject());
    24232424        JSObject* baseObj = static_cast<JSObject*>(r[base].u.jsValue);
     
    24312432    BEGIN_OPCODE(op_put_setter) {
    24322433        /* put_setter base(r) property(id) function(r)
    2433          
     2434
    24342435           Sets register function on register base as the setter named
    24352436           by identifier property. Base and function are assumed to be
    24362437           objects as this op should only be used for setters defined
    24372438           in object literal form.
    2438          
     2439
    24392440           Unlike many opcodes, this one does not write any output to
    24402441           the register file.
     
    24432444        int property = (++vPC)->u.operand;
    24442445        int function = (++vPC)->u.operand;
    2445        
     2446
    24462447        ASSERT(r[base].u.jsValue->isObject());
    24472448        JSObject* baseObj = static_cast<JSObject*>(r[base].u.jsValue);
     
    24492450        ASSERT(r[function].u.jsValue->isObject());
    24502451        baseObj->defineSetter(exec, ident, static_cast<JSObject* >(r[function].u.jsValue));
    2451        
     2452
    24522453        ++vPC;
    24532454        NEXT_OPCODE;
     
    24552456    BEGIN_OPCODE(op_jsr) {
    24562457        /* jsr retAddrDst(r) target(offset)
    2457          
     2458
    24582459           Places the address of the next instruction into the retAddrDst
    24592460           register and jumps to offset target from the current instruction.
     
    24682469    BEGIN_OPCODE(op_sret) {
    24692470        /* sret retAddrSrc(r)
    2470          
     2471
    24712472         Jumps to the address stored in the retAddrSrc register. This
    24722473         differs from op_jmp because the target address is stored in a
     
    24792480    BEGIN_OPCODE(op_debug) {
    24802481        /* debug debugHookID(n) firstLine(n) lastLine(n)
    2481          
     2482
    24822483         Notifies the debugger of the current state of execution. This opcode
    24832484         is only generated while the debugger is attached.
     
    25022503        vPC = handlerVPC;
    25032504        NEXT_OPCODE;
    2504     }         
     2505    }
    25052506    }
    25062507    #undef NEXT_OPCODE
Note: See TracChangeset for help on using the changeset viewer.