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


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.h

    r14256 r14502  
    735735  };
    736736
    737   class StatListNode : public StatementNode {
    738   public:
    739     // list pointer is tail of a circular list, cracked in the CaseClauseNode ctor
    740     StatListNode(StatementNode *s);
    741     StatListNode(StatListNode *l, StatementNode *s);
    742     virtual Completion execute(ExecState*);
    743     virtual void processVarDecls(ExecState*);
    744     virtual void streamTo(SourceStream&) const;
    745     PassRefPtr<StatListNode> releaseNext() { return next.release(); }
    746     virtual void breakCycle();
    747   private:
    748     friend class CaseClauseNode;
    749     RefPtr<StatementNode> statement;
    750     ListRefPtr<StatListNode> next;
    751   };
    752 
    753737  class AssignExprNode : public Node {
    754738  public:
     
    932916    RefPtr<Node> expr;
    933917    RefPtr<StatementNode> statement;
    934   };
    935 
    936   class CaseClauseNode : public Node {
    937   public:
    938     CaseClauseNode(Node *e) : expr(e) { }
    939     CaseClauseNode(Node *e, StatListNode *l)
    940       : expr(e), next(l->next.release()) { Parser::removeNodeCycle(next.get()); }
    941     JSValue* evaluate(ExecState*);
    942     Completion evalStatements(ExecState*);
    943     virtual void processVarDecls(ExecState*);
    944     virtual void streamTo(SourceStream&) const;
    945   private:
    946     RefPtr<Node> expr;
    947     RefPtr<StatListNode> next;
    948   };
    949 
    950   class ClauseListNode : public Node {
    951   public:
    952     // list pointer is tail of a circular list, cracked in the CaseBlockNode ctor
    953     ClauseListNode(CaseClauseNode *c) : clause(c), next(this) { Parser::noteNodeCycle(this); }
    954     ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
    955       : clause(c), next(n->next) { n->next = this; }
    956     JSValue* evaluate(ExecState*);
    957     CaseClauseNode *getClause() const { return clause.get(); }
    958     ClauseListNode *getNext() const { return next.get(); }
    959     virtual void processVarDecls(ExecState*);
    960     virtual void streamTo(SourceStream&) const;
    961     PassRefPtr<ClauseListNode> releaseNext() { return next.release(); }
    962     virtual void breakCycle();
    963   private:
    964     friend class CaseBlockNode;
    965     RefPtr<CaseClauseNode> clause;
    966     ListRefPtr<ClauseListNode> next;
    967   };
    968 
    969   class CaseBlockNode : public Node {
    970   public:
    971     CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
    972     JSValue* evaluate(ExecState*);
    973     Completion evalBlock(ExecState *exec, JSValue *input);
    974     virtual void processVarDecls(ExecState*);
    975     virtual void streamTo(SourceStream&) const;
    976   private:
    977     RefPtr<ClauseListNode> list1;
    978     RefPtr<CaseClauseNode> def;
    979     RefPtr<ClauseListNode> list2;
    980   };
    981 
    982   class SwitchNode : public StatementNode {
    983   public:
    984     SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
    985     virtual Completion execute(ExecState*);
    986     virtual void processVarDecls(ExecState*);
    987     virtual void streamTo(SourceStream&) const;
    988   private:
    989     RefPtr<Node> expr;
    990     RefPtr<CaseBlockNode> block;
    991918  };
    992919
     
    10881015  class SourceElementsNode : public StatementNode {
    10891016  public:
    1090       static int count;
     1017    static int count;
    10911018    // list pointer is tail of a circular list, cracked in the BlockNode (or subclass) ctor
    10921019    SourceElementsNode(StatementNode*);
     
    11011028  private:
    11021029    friend class BlockNode;
     1030    friend class CaseClauseNode;
    11031031    RefPtr<StatementNode> node;
    11041032    ListRefPtr<SourceElementsNode> next;
    11051033  };
    11061034
     1035  class CaseClauseNode : public Node {
     1036  public:
     1037      CaseClauseNode(Node *e) : expr(e) { }
     1038      CaseClauseNode(Node *e, SourceElementsNode *s)
     1039      : expr(e), source(s->next.release()) { Parser::removeNodeCycle(source.get()); }
     1040      JSValue* evaluate(ExecState*);
     1041      Completion evalStatements(ExecState*);
     1042      void processFuncDecl(ExecState*);
     1043      virtual void processVarDecls(ExecState*);
     1044      virtual void streamTo(SourceStream&) const;
     1045  private:
     1046      RefPtr<Node> expr;
     1047      RefPtr<SourceElementsNode> source;
     1048  };
     1049 
     1050  class ClauseListNode : public Node {
     1051  public:
     1052      // list pointer is tail of a circular list, cracked in the CaseBlockNode ctor
     1053      ClauseListNode(CaseClauseNode *c) : clause(c), next(this) { Parser::noteNodeCycle(this); }
     1054      ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
     1055      : clause(c), next(n->next) { n->next = this; }
     1056      JSValue* evaluate(ExecState*);
     1057      CaseClauseNode *getClause() const { return clause.get(); }
     1058      ClauseListNode *getNext() const { return next.get(); }
     1059      virtual void processVarDecls(ExecState*);
     1060      void processFuncDecl(ExecState*);
     1061      virtual void streamTo(SourceStream&) const;
     1062      PassRefPtr<ClauseListNode> releaseNext() { return next.release(); }
     1063      virtual void breakCycle();
     1064  private:
     1065      friend class CaseBlockNode;
     1066      RefPtr<CaseClauseNode> clause;
     1067      ListRefPtr<ClauseListNode> next;
     1068  };
     1069 
     1070  class CaseBlockNode : public Node {
     1071  public:
     1072      CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
     1073      JSValue* evaluate(ExecState*);
     1074      Completion evalBlock(ExecState *exec, JSValue *input);
     1075      virtual void processVarDecls(ExecState*);
     1076      void processFuncDecl(ExecState*);
     1077      virtual void streamTo(SourceStream&) const;
     1078  private:
     1079      RefPtr<ClauseListNode> list1;
     1080      RefPtr<CaseClauseNode> def;
     1081      RefPtr<ClauseListNode> list2;
     1082  };
     1083 
     1084  class SwitchNode : public StatementNode {
     1085  public:
     1086      SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
     1087      virtual Completion execute(ExecState*);
     1088      virtual void processVarDecls(ExecState*);
     1089      virtual void processFuncDecl(ExecState*);
     1090      virtual void streamTo(SourceStream&) const;
     1091  private:
     1092      RefPtr<Node> expr;
     1093      RefPtr<CaseBlockNode> block;
     1094  };
     1095 
    11071096  class ProgramNode : public FunctionBodyNode {
    11081097  public:
Note: See TracChangeset for help on using the changeset viewer.