Ignore:
Timestamp:
May 11, 2007, 9:15:45 AM (18 years ago)
Author:
bdash
Message:

2007-05-11 Kimmo Kinnunen <Kimmo Kinnunen>

Reviewed by Darin.

  • kjs/nodes2string.cpp: (KJS::SourceStream::): Add boolean flag to indicate that if next item is a number, it should be grouped. Add new formatting enum which turns on the boolean flag. (KJS::SourceStream::SourceStream): Added. Initialize the flag. (SourceStream::operator<<): Added. New overloaded operator with double value as parameter. (NumberNode::streamTo): Use the double operator (ArrayNode::streamTo): (DotAccessorNode::streamTo): (FunctionCallDotNode::streamTo): (FunctionCallParenDotNode::streamTo): (PostfixDotNode::streamTo): (DeleteDotNode::streamTo): (PrefixDotNode::streamTo): (AssignDotNode::streamTo): Use the new formatting enum to turn on the grouping flag.

2007-05-11 Kimmo Kinnunen <Kimmo Kinnunen>

Reviewed by Darin.

Tests for http://bugs.webkit.org/show_bug.cgi?id=10878
Bug 10878: Incorrect decompilation for "4..x"

  • fast/js/resources/toString-number-dot-expr.js: Added.
  • fast/js/toString-number-dot-expr-expected.txt: Added.
  • fast/js/toString-number-dot-expr.html: Added.
File:
1 edited

Legend:

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

    r21027 r21406  
    3232  public:
    3333    enum Format {
    34       Endl, Indent, Unindent
     34      Endl, Indent, Unindent, DotExpr
    3535    };
    36 
     36    SourceStream() : m_groupIfNumber(false) {}
    3737    UString toString() const { return str; }
    3838    SourceStream& operator<<(const Identifier &);
    3939    SourceStream& operator<<(const UString &);
    4040    SourceStream& operator<<(const char *);
     41    SourceStream& operator<<(double);
    4142    SourceStream& operator<<(char);
    4243    SourceStream& operator<<(Format f);
    4344    SourceStream& operator<<(const Node *);
    4445    template <typename T> SourceStream& operator<<(RefPtr<T> n) { return this->operator<<(n.get()); }
     46
    4547  private:
    4648    UString str; /* TODO: buffer */
    4749    UString ind;
     50    bool m_groupIfNumber;
    4851  };
    4952}
     
    5356SourceStream& SourceStream::operator<<(char c)
    5457{
     58  m_groupIfNumber = false;
    5559  UChar ch(c);
    5660  str += UString(&ch, 1);
     
    6064SourceStream& SourceStream::operator<<(const char *s)
    6165{
     66  m_groupIfNumber = false;
    6267  str += UString(s);
    6368  return *this;
    6469}
    6570
     71SourceStream& SourceStream::operator<<(double value)
     72{
     73  if (m_groupIfNumber)
     74    str.append("(");
     75
     76  str += UString::from(value);
     77
     78  if (m_groupIfNumber)
     79    str.append(")");
     80
     81  m_groupIfNumber = false;
     82  return *this;
     83}
     84
    6685SourceStream& SourceStream::operator<<(const UString &s)
    6786{
     87  m_groupIfNumber = false;
    6888  str += s;
    6989  return *this;
     
    7292SourceStream& SourceStream::operator<<(const Identifier &s)
    7393{
     94  m_groupIfNumber = false;
    7495  str += s.ustring();
    7596  return *this;
     
    80101  if (n)
    81102    n->streamTo(*this);
     103  m_groupIfNumber = false;
    82104  return *this;
    83105}
     
    85107SourceStream& SourceStream::operator<<(Format f)
    86108{
     109  m_groupIfNumber = false;
    87110  switch (f) {
    88111    case Endl:
     
    95118      ind = ind.substr(0, ind.size() - 2);
    96119      break;
     120  case DotExpr:
     121      m_groupIfNumber = true;
     122      break;
    97123  }
    98124
     
    115141}
    116142
    117 void NumberNode::streamTo(SourceStream &s) const { s << UString::from(value); }
     143void NumberNode::streamTo(SourceStream &s) const { s << value; }
    118144
    119145void StringNode::streamTo(SourceStream &s) const
     
    206232void DotAccessorNode::streamTo(SourceStream &s) const
    207233{
    208   s << expr << "." << ident;
     234  s << SourceStream::DotExpr << expr << "." << ident;
    209235}
    210236
     
    248274void FunctionCallDotNode::streamTo(SourceStream &s) const
    249275{
    250   s << base << "." << ident << args;
     276  s << SourceStream::DotExpr << base << "." << ident << args;
    251277}
    252278
    253279void FunctionCallParenDotNode::streamTo(SourceStream &s) const
    254280{
    255   s << "(" << base << "." << ident << ")" << args;
     281  s << "(" << SourceStream::DotExpr << base << "." << ident << ")" << args;
    256282}
    257283
     
    276302void PostfixDotNode::streamTo(SourceStream &s) const
    277303{
    278   s << m_base << "." << m_ident;
     304  s << SourceStream::DotExpr << m_base << "." << m_ident;
    279305  if (m_oper == OpPlusPlus)
    280306    s << "++";
     
    304330void DeleteDotNode::streamTo(SourceStream &s) const
    305331{
    306   s << "delete " << m_base << "." << m_ident;
     332  s << "delete " << SourceStream::DotExpr << m_base << "." << m_ident;
    307333}
    308334
     
    351377  else
    352378    s << "--";
    353   s << m_base << "." << m_ident;
     379  s << SourceStream::DotExpr << m_base << "." << m_ident;
    354380}
    355381
     
    539565void AssignDotNode::streamTo(SourceStream &s) const
    540566{
    541   s << m_base << "." << m_ident;
     567  s << SourceStream::DotExpr << m_base << "." << m_ident;
    542568  streamAssignmentOperatorTo(s, m_oper);
    543569  s << m_right;
Note: See TracChangeset for help on using the changeset viewer.