Ignore:
Timestamp:
Aug 11, 2005, 3:26:54 AM (20 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Geoff.

Refactor assignment grammar to avoid Reference type, and to later
be able to take advantage of writeable PropertySlots, when those
are added. I also fixed a minor bug, turning a function to a
string lost parentheses, I made sure they are printed at least
where semantically significant.

Test cases: see WebCore

  • kjs/grammar.y: Change grammar so that assignment expressions are parsed directly to nodes that know how to set the kind of location being assigned, instead of having a generic assign node that counts on evaluateReference.
  • kjs/lexer.cpp: Include grammar_types.h.
  • kjs/nodes.cpp: (BracketAccessorNode): Renamed from AccessorNode1 for clarity. (DotAccessorNode): Renamed from AccessorNode2 for clarity. (combineForAssignment): Inline function for doing the proper kind of operation for various update assignments like += or *=. (AssignResolveNode): Node that handles assignment to a bare identifier. (AssignDotNode): Node that handles assignments of the form EXPR . IDENT = EXPR (AssignBracketNode): EXPR [ IDENT ] = EXPR
  • kjs/nodes.h: Updated for declarations/renames of new classes.
  • kjs/nodes2string.cpp: (GroupNode::streamTo): Fixed to print parens around the expression. (BracketAccessorNode::streamTo): Renamed. (DotAccessorNode::streamTo): Renamed. (AssignResolveNode::streamTo): Added. (AssignBracketNode::streamTo): Added. (AssignDotNode::streamTo): Added. (streamAssignmentOperatorTo): helper function for the above
  • kjs/property_slot.h: (KJS::PropertySlot::isSet): Made this const.

WebCore:

Reviewed by Geoff.

Test cases added:

  • layout-tests/fast/js/assign.html: Added. Test case for assignment to make sure I didn't break anything.
  • layout-tests/fast/js/code-serialize-paren.html: Added, test case for a minor bug I fixed where parens were not getting serialized at all when turning a function into a string.
File:
1 edited

Legend:

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

    r9768 r10135  
    125125void ResolveNode::streamTo(SourceStream &s) const { s << ident; }
    126126
     127void GroupNode::streamTo(SourceStream &s) const
     128{
     129  s << "(" << group << ")";
     130}
     131
    127132void ElementNode::streamTo(SourceStream &s) const
    128133{
     
    164169}
    165170
    166 void AccessorNode1::streamTo(SourceStream &s) const
     171void BracketAccessorNode::streamTo(SourceStream &s) const
    167172{
    168173  s << expr1 << "[" << expr2 << "]";
    169174}
    170175
    171 void AccessorNode2::streamTo(SourceStream &s) const
     176void DotAccessorNode::streamTo(SourceStream &s) const
    172177{
    173178  s << expr << "." << ident;
     
    339344}
    340345
    341 void AssignNode::streamTo(SourceStream &s) const
    342 {
    343   s << left;
     346void streamAssignmentOperatorTo(SourceStream &s, Operator oper)
     347{
    344348  const char *opStr;
    345349  switch (oper) {
     
    366370    break;
    367371  case OpURShift:
    368     opStr = " >>= ";
     372    opStr = " >>>= ";
    369373    break;
    370374  case OpAndEq:
     
    383387    opStr = " ?= ";
    384388  }
    385   s << opStr << expr;
     389  s << opStr;
     390}
     391
     392void AssignResolveNode::streamTo(SourceStream &s) const
     393{
     394  s << m_ident;
     395  streamAssignmentOperatorTo(s, m_oper);
     396  s << m_right;
     397}
     398
     399void AssignBracketNode::streamTo(SourceStream &s) const
     400{
     401  s << m_base << "[" << m_subscript << "]";
     402  streamAssignmentOperatorTo(s, m_oper);
     403  s << m_right;
     404}
     405
     406void AssignDotNode::streamTo(SourceStream &s) const
     407{
     408  s << m_base << "." << m_ident;
     409  streamAssignmentOperatorTo(s, m_oper);
     410  s << m_right;
    386411}
    387412
Note: See TracChangeset for help on using the changeset viewer.