Function.toString does not parenthesise numbers for the bracket accessor
Reviewed by Maciej and Darin.
It turns out that logic was there for all of the dot accessor nodes to make numbers be
parenthesised properly, so it was a trivial extension to extend that to the bracket nodes.
I renamed the enum type to reflect the fact that it is now used for both dot and bracket
accessors.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@29813
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2008-01-26 Oliver Hunt <oliver@apple.com>
+
+ Reviewed by Maciej and Darin.
+
+ Fix for http://bugs.webkit.org/show_bug.cgi?id=17020
+ Function.toString does not parenthesise numbers for the bracket accessor
+
+ It turns out that logic was there for all of the dot accessor nodes to make numbers be
+ parenthesised properly, so it was a trivial extension to extend that to the bracket nodes.
+ I renamed the enum type to reflect the fact that it is now used for both dot and bracket
+ accessors.
+
+ * kjs/nodes2string.cpp:
+ (KJS::bracketNodeStreamTo):
+ (KJS::BracketAccessorNode::streamTo):
+
2008-01-26 Oliver Hunt <oliver@apple.com>
Reviewed by Darin.
enum EndlType { Endl };
enum IndentType { Indent };
enum UnindentType { Unindent };
-enum DotExprType { DotExpr };
+enum ObjectAccessType { ObjectAccess };
class SourceStream {
public:
SourceStream& operator<<(EndlType);
SourceStream& operator<<(IndentType);
SourceStream& operator<<(UnindentType);
- SourceStream& operator<<(DotExprType);
+ SourceStream& operator<<(ObjectAccessType);
SourceStream& operator<<(Precedence);
SourceStream& operator<<(const Node*);
template <typename T> SourceStream& operator<<(const RefPtr<T>& n) { return *this << n.get(); }
return *this;
}
-inline SourceStream& SourceStream::operator<<(DotExprType)
+inline SourceStream& SourceStream::operator<<(ObjectAccessType)
{
m_numberNeedsParens = true;
return *this;
static inline void bracketNodeStreamTo(SourceStream& s, const RefPtr<ExpressionNode>& base, const RefPtr<ExpressionNode>& subscript)
{
- s << PrecCall << base.get() << "[" << subscript.get() << "]";
+ s << ObjectAccess << PrecCall << base.get() << "[" << subscript.get() << "]";
}
static inline void dotNodeStreamTo(SourceStream& s, const RefPtr<ExpressionNode>& base, const Identifier& ident)
{
- s << DotExpr << PrecCall << base.get() << "." << ident;
+ s << ObjectAccess << PrecCall << base.get() << "." << ident;
}
// --------
void BracketAccessorNode::streamTo(SourceStream& s) const
{
- s << PrecCall << expr1 << "[" << expr2 << "]";
+ bracketNodeStreamTo(s, expr1, expr2);
}
void DotAccessorNode::streamTo(SourceStream& s) const
{
- s << DotExpr << PrecCall << expr << "." << ident;
+ dotNodeStreamTo(s, expr, ident);
}
void ArgumentListNode::streamTo(SourceStream& s) const
void NewExprNode::streamTo(SourceStream& s) const
{
- s << "new " << PrecMember << expr << args;
+ s << "new " << ObjectAccess << PrecMember << expr << args;
}
void FunctionCallValueNode::streamTo(SourceStream& s) const
+2008-01-26 Oliver Hunt <oliver@apple.com>
+
+ Reviewed by Maciej and Darin.
+
+ Test cases for http://bugs.webkit.org/show_bug.cgi?id=17020
+ Function.toString does not parenthesise numbers for the bracket accessor
+
+ * fast/js/function-toString-parentheses-expected.txt:
+ * fast/js/resources/function-toString-parentheses.js:
+
2008-01-26 Oliver Hunt <oliver@apple.com>
Reviewed by Darin.
PASS compileAndSerialize('!a--') is '!a--'
PASS compileAndSerialize('!(a--)') is '!a--'
PASS compileAndSerialize('(!a)--') is '(!a)--'
+PASS compileAndSerialize('(-1)[a]') is '(-1)[a]'
+PASS compileAndSerialize('(-1)[a] = b') is '(-1)[a] = b'
+PASS compileAndSerialize('(-1)[a] += b') is '(-1)[a] += b'
+PASS compileAndSerialize('(-1)[a]++') is '(-1)[a]++'
+PASS compileAndSerialize('++(-1)[a]') is '++(-1)[a]'
+PASS compileAndSerialize('(-1)[a]()') is '(-1)[a]()'
PASS compileAndSerializeLeftmostTest('({ }).x') is '({ }).x'
PASS compileAndSerializeLeftmostTest('x = { }') is 'x = { }'
PASS compileAndSerializeLeftmostTest('(function () { })()') is '(function () { })()'
shouldBe("compileAndSerialize('!a--')", "'!a--'");
shouldBe("compileAndSerialize('!(a--)')", "'!a--'");
shouldBe("compileAndSerialize('(!a)--')", "'(!a)--'");
+shouldBe("compileAndSerialize('(-1)[a]')", "'(-1)[a]'");
+shouldBe("compileAndSerialize('(-1)[a] = b')", "'(-1)[a] = b'");
+shouldBe("compileAndSerialize('(-1)[a] += b')", "'(-1)[a] += b'");
+shouldBe("compileAndSerialize('(-1)[a]++')", "'(-1)[a]++'");
+shouldBe("compileAndSerialize('++(-1)[a]')", "'++(-1)[a]'");
+shouldBe("compileAndSerialize('(-1)[a]()')", "'(-1)[a]()'");
+shouldBe("compileAndSerialize('new (-1)()')", "'new (-1)()'");
shouldBe("compileAndSerializeLeftmostTest('({ }).x')", "'({ }).x'");
shouldBe("compileAndSerializeLeftmostTest('x = { }')", "'x = { }'");
shouldBe("compileAndSerializeLeftmostTest('(function () { })()')", "'(function () { })()'");