Changeset 28608 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


Ignore:
Timestamp:
Dec 10, 2007, 9:47:41 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

Reviewed by Sam Weinig.

Split this:


FunctionBodyNode


|

ProgramNode


into this:


ScopeNode


| | |

FunctionBodyNode ProgramNode EvalNode

in preparation for specializing each class more while optimizing global
variable access.


Also removed some cruft from the FunctionBodyNode interface to simplify
things.


SunSpider says this patch is a .8% speedup, which seems reasonable,
since it eliminates a few branches and adds KJS_FAST_CALL in a few
places.


Layout tests and JS tests pass. Also, this baby builds on Windows! (Qt
mileage may vary...)

WebCore:

Reviewed by Sam Weinig.

Updated for rename in JavaScriptCore.

  • bridge/mac/WebCoreScriptDebugger.mm: (-[WebCoreScriptCallFrame scopeChain]): (-[WebCoreScriptCallFrame functionName]): (-[WebCoreScriptCallFrame evaluateWebScript:]):

WebKit/win:

Reviewed by Sam Weinig.

Updated for rename in JavaScriptCore.

  • WebScriptCallFrame.cpp: (WebScriptCallFrame::functionName): (WebScriptCallFrame::valueByEvaluatingJavaScriptFromString):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r28577 r28608  
    266266static inline int currentSourceId(ExecState* exec)
    267267{
    268     return exec->currentBody()->sourceId();
     268    return exec->scopeNode()->sourceId();
    269269}
    270270
     
    272272static inline const UString& currentSourceURL(ExecState* exec)
    273273{
    274     return exec->currentBody()->sourceURL();
     274    return exec->scopeNode()->sourceURL();
    275275}
    276276
     
    44014401// ------------------------------ FunctionBodyNode -----------------------------
    44024402
    4403 FunctionBodyNode::FunctionBodyNode(SourceElements* children)
     4403ScopeNode::ScopeNode(SourceElements* children)
    44044404    : BlockNode(children)
    44054405    , m_sourceURL(parser().sourceURL())
    44064406    , m_sourceId(parser().sourceId())
    4407     , m_initializedDeclarationStacks(false)
    4408     , m_initializedSymbolTable(false)
    4409     , m_optimizedResolveNodes(false)
    4410 {
    4411 }
    4412 
    4413 void FunctionBodyNode::initializeDeclarationStacks(ExecState* exec)
     4407{
     4408}
     4409
     4410ProgramNode::ProgramNode(SourceElements* children)
     4411    : ScopeNode(children)
     4412{
     4413}
     4414
     4415EvalNode::EvalNode(SourceElements* children)
     4416    : ScopeNode(children)
     4417{
     4418}
     4419
     4420FunctionBodyNode::FunctionBodyNode(SourceElements* children)
     4421    : ScopeNode(children)
     4422    , m_initialized(false)
     4423{
     4424}
     4425
     4426void ScopeNode::initializeDeclarationStacks(ExecState* exec)
    44144427{
    44154428    DeclarationStacks::NodeStack nodeStack;
     
    44304443        nodeStack.shrink(size);
    44314444    }
    4432 
    4433     m_initializedDeclarationStacks = true;
    44344445}
    44354446
     
    44484459    for (i = 0, size = m_functionStack.size(); i < size; ++i)
    44494460        m_symbolTable.set(m_functionStack[i]->ident.ustring().rep(), count++);
    4450 
    4451     m_initializedSymbolTable = true;
    44524461}
    44534462
     
    44694478        nodeStack.shrink(size);
    44704479    }
    4471 
    4472     m_optimizedResolveNodes = true;
    44734480}
    44744481
    44754482void FunctionBodyNode::processDeclarations(ExecState* exec)
    44764483{
    4477     if (!m_initializedDeclarationStacks)
     4484    if (!m_initialized) {
    44784485        initializeDeclarationStacks(exec);
    4479 
    4480     if (exec->codeType() == FunctionCode)
    4481         processDeclarationsForFunctionCode(exec);
    4482     else
    4483         processDeclarationsForProgramCode(exec);
    4484 }
    4485 
    4486 void FunctionBodyNode::processDeclarationsForFunctionCode(ExecState* exec)
    4487 {
    4488     if (!m_initializedSymbolTable)
    44894486        initializeSymbolTable();
    4490 
    4491     if (!m_optimizedResolveNodes)
    44924487        optimizeVariableAccess();
     4488       
     4489        m_initialized = true;
     4490    }
    44934491
    44944492    LocalStorage& localStorage = exec->variableObject()->localStorage();
     
    45214519}
    45224520
    4523 void FunctionBodyNode::processDeclarationsForProgramCode(ExecState* exec)
    4524 {
     4521void ProgramNode::processDeclarations(ExecState* exec)
     4522{
     4523    initializeDeclarationStacks(exec);
     4524
    45254525    size_t i, size;
    45264526
    4527     JSObject* variableObject = exec->variableObject();
    4528    
    4529     int minAttributes = Internal | (exec->codeType() != EvalCode ? DontDelete : 0);
     4527    JSVariableObject* variableObject = exec->variableObject();
     4528   
     4529    int minAttributes = Internal | DontDelete;
    45304530
    45314531    for (i = 0, size = m_varStack.size(); i < size; ++i) {
     
    45394539    }
    45404540
    4541     ASSERT(!m_parameters.size());
    4542 
    45434541    for (i = 0, size = m_functionStack.size(); i < size; ++i) {
    45444542        FuncDeclNode* node = m_functionStack[i];
     
    45474545}
    45484546
    4549 void FunctionBodyNode::addParam(const Identifier& ident)
    4550 {
    4551   m_parameters.append(ident);
     4547void EvalNode::processDeclarations(ExecState* exec)
     4548{
     4549    initializeDeclarationStacks(exec);
     4550
     4551    size_t i, size;
     4552
     4553    JSVariableObject* variableObject = exec->variableObject();
     4554   
     4555    int minAttributes = Internal;
     4556
     4557    for (i = 0, size = m_varStack.size(); i < size; ++i) {
     4558        VarDeclNode* node = m_varStack[i];
     4559        if (variableObject->hasProperty(exec, node->ident))
     4560            continue;
     4561        int attributes = minAttributes;
     4562        if (node->varType == VarDeclNode::Constant)
     4563            attributes |= ReadOnly;
     4564        variableObject->put(exec, node->ident, jsUndefined(), attributes);
     4565    }
     4566
     4567    for (i = 0, size = m_functionStack.size(); i < size; ++i) {
     4568        FuncDeclNode* node = m_functionStack[i];
     4569        variableObject->put(exec, node->ident, node->makeFunction(exec), minAttributes);
     4570    }
    45524571}
    45534572
     
    45554574{
    45564575  UString s("");
    4557   size_t count = numParams();
     4576  size_t count = m_parameters.size();
    45584577  for (size_t pos = 0; pos < count; ++pos) {
    45594578    if (!s.isEmpty())
    45604579        s += ", ";
    4561     s += paramName(pos).ustring();
     4580    s += m_parameters[pos].ustring();
    45624581  }
    45634582
    45644583  return s;
     4584}
     4585
     4586Completion ProgramNode::execute(ExecState* exec)
     4587{
     4588    processDeclarations(exec);
     4589    return ScopeNode::execute(exec);
     4590}
     4591
     4592Completion EvalNode::execute(ExecState* exec)
     4593{
     4594    processDeclarations(exec);
     4595    return ScopeNode::execute(exec);
    45654596}
    45664597
     
    45764607    }   
    45774608   
    4578     Completion completion = BlockNode::execute(exec);
     4609    Completion completion = ScopeNode::execute(exec);
    45794610   
    45804611    if (Debugger* dbg = exec->dynamicGlobalObject()->debugger()) {
     
    45974628{
    45984629  for (ParameterNode *p = param.get(); p != 0L; p = p->nextParam())
    4599     body->addParam(p->ident());
     4630    body->parameters().append(p->ident());
    46004631}
    46014632
     
    46134644  func->put(exec, exec->propertyNames().prototype, proto, Internal|DontDelete);
    46144645
    4615   func->put(exec, exec->propertyNames().length, jsNumber(body->numParams()), ReadOnly|DontDelete|DontEnum);
     4646  func->put(exec, exec->propertyNames().length, jsNumber(body->parameters().size()), ReadOnly|DontDelete|DontEnum);
    46164647  return func;
    46174648}
     
    46284659{
    46294660  for (ParameterNode *p = param.get(); p != 0L; p = p->nextParam())
    4630     body->addParam(p->ident());
     4661    body->parameters().append(p->ident());
    46314662}
    46324663
     
    46574688}
    46584689
    4659 ProgramNode::ProgramNode(SourceElements* children)
    4660     : FunctionBodyNode(children)
    4661 {
    4662 }
    4663 
    4664 }
     4690} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.