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


Ignore:
Timestamp:
May 20, 2006, 1:19:22 PM (19 years ago)
Author:
andersca
Message:

JavaScriptCore:

2006-05-20 Anders Carlsson <[email protected]>

Reviewed by Geoff.

http://bugzilla.opendarwin.org/show_bug.cgi?id=8993
Support function declaration in case statements


  • kjs/grammar.y: Get rid of StatementList and use SourceElements instead.


  • kjs/nodes.cpp: (CaseClauseNode::evalStatements): (CaseClauseNode::processVarDecls): (CaseClauseNode::processFuncDecl): (ClauseListNode::processFuncDecl): (CaseBlockNode::processFuncDecl): (SwitchNode::processFuncDecl):
  • kjs/nodes.h: (KJS::CaseClauseNode::CaseClauseNode): (KJS::ClauseListNode::ClauseListNode): (KJS::ClauseListNode::getClause): (KJS::ClauseListNode::getNext): (KJS::ClauseListNode::releaseNext): (KJS::SwitchNode::SwitchNode): Add processFuncDecl for the relevant nodes.
  • kjs/nodes2string.cpp: (CaseClauseNode::streamTo): next got renamed to source.

LayoutTests:

2006-05-20 Anders Carlsson <[email protected]>

Reviewed by Geoff.

  • fast/js/function-declarations-in-switch-statement-expected.txt: Added.
  • fast/js/function-declarations-in-switch-statement.html: Added.
  • fast/js/resources/function-declarations-in-switch-statement.js: Added.
File:
1 edited

Legend:

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

    r14429 r14502  
    15091509}
    15101510
    1511 // ------------------------------ StatListNode ---------------------------------
    1512 
    1513 StatListNode::StatListNode(StatementNode *s)
    1514   : statement(s), next(this)
    1515 {
    1516     Parser::noteNodeCycle(this);
    1517     setLoc(s->firstLine(), s->lastLine());
    1518 }
    1519  
    1520 StatListNode::StatListNode(StatListNode *l, StatementNode *s)
    1521   : statement(s), next(l->next)
    1522 {
    1523   l->next = this;
    1524   setLoc(l->firstLine(), s->lastLine());
    1525 }
    1526 
    1527 // ECMA 12.1
    1528 Completion StatListNode::execute(ExecState *exec)
    1529 {
    1530   Completion c = statement->execute(exec);
    1531   KJS_ABORTPOINT
    1532   if (c.complType() != Normal)
    1533     return c;
    1534  
    1535   JSValue *v = c.value();
    1536  
    1537   for (StatListNode *n = next.get(); n; n = n->next.get()) {
    1538     Completion c2 = n->statement->execute(exec);
    1539     KJS_ABORTPOINT
    1540     if (c2.complType() != Normal)
    1541       return c2;
    1542 
    1543     if (c2.isValueCompletion())
    1544       v = c2.value();
    1545     c = c2;
    1546   }
    1547 
    1548   return Completion(c.complType(), v, c.target());
    1549 }
    1550 
    1551 void StatListNode::processVarDecls(ExecState *exec)
    1552 {
    1553   for (StatListNode *n = this; n; n = n->next.get())
    1554     n->statement->processVarDecls(exec);
    1555 }
    1556 
    1557 void StatListNode::breakCycle()
    1558 {
    1559     next = 0;
    1560 }
    1561 
    15621511// ------------------------------ AssignExprNode -------------------------------
    15631512
     
    20952044Completion CaseClauseNode::evalStatements(ExecState *exec)
    20962045{
    2097   if (next)
    2098     return next->execute(exec);
     2046  if (source)
     2047    return source->execute(exec);
    20992048  else
    21002049    return Completion(Normal, jsUndefined());
     
    21032052void CaseClauseNode::processVarDecls(ExecState *exec)
    21042053{
    2105   if (next)
    2106     next->processVarDecls(exec);
     2054  if (source)
     2055    source->processVarDecls(exec);
     2056}
     2057
     2058void CaseClauseNode::processFuncDecl(ExecState* exec)
     2059{
     2060  if (source)
     2061      source->processFuncDecl(exec);
    21072062}
    21082063
     
    21222077    if (n->clause)
    21232078      n->clause->processVarDecls(exec);
     2079}
     2080
     2081void ClauseListNode::processFuncDecl(ExecState* exec)
     2082{
     2083  for (ClauseListNode* n = this; n; n = n->next.get())
     2084    if (n->clause)
     2085      n->clause->processFuncDecl(exec);
    21242086}
    21252087
     
    22312193}
    22322194
     2195void CaseBlockNode::processFuncDecl(ExecState* exec)
     2196{
     2197  if (list1)
     2198   list1->processFuncDecl(exec);
     2199  if (def)
     2200    def->processFuncDecl(exec);
     2201  if (list2)
     2202    list2->processFuncDecl(exec);
     2203}
     2204
    22332205// ------------------------------ SwitchNode -----------------------------------
    22342206
     
    22532225{
    22542226  block->processVarDecls(exec);
     2227}
     2228
     2229void SwitchNode::processFuncDecl(ExecState* exec)
     2230{
     2231  block->processFuncDecl(exec);
    22552232}
    22562233
Note: See TracChangeset for help on using the changeset viewer.