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


Ignore:
Timestamp:
Jan 26, 2008, 8:21:43 PM (17 years ago)
Author:
Darin Adler
Message:

JavaScriptCore:

Reviewed by Oliver.

Test: fast/js/function-toString-parentheses.html

The problem here was that a NumberNode with a negative number in it had the wrong
precedence. It's not a primary expression, it's a unary operator with a primary
expression after it.

Once the precedence of NumberNode was fixed, the cases from bug 17020 were also
fixed without trying to treat bracket nodes like dot nodes. That wasn't needed.
The reason we handle numbers before dot nodes specially is that the dot is a
legal character in a number. The same is not true of a bracket. Eventually we
could get smarter, and only add the parentheses when there is actual ambiguity.
There is none if the string form of the number already has a dot in it, or if
it's a number with a alphabetic name like infinity or NAN.

  • kjs/nodes.h: Renamed back from ObjectAccess to DotExpr. (KJS::NumberNode::precedence): Return PrecUnary for negative numbers, since they serialize as a unary operator, not a primary expression.
  • kjs/nodes2string.cpp: (KJS::SourceStream::operator<<): Clear m_numberNeedsParens if this adds parens; one set is enough. (KJS::bracketNodeStreamTo): Remove unneeded special flag here. Normal operator precedence suffices. (KJS::NewExprNode::streamTo): Ditto.

LayoutTests:

Reviewed by Oliver.

  • fast/js/function-toString-parentheses-expected.txt: Updated.
  • fast/js/resources/function-toString-parentheses.js: More test cases.
File:
1 edited

Legend:

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

    r29809 r29815  
    3131#include "SymbolTable.h"
    3232#include <wtf/ListRefPtr.h>
     33#include <wtf/MathExtras.h>
    3334#include <wtf/OwnPtr.h>
    3435#include <wtf/Vector.h>
     
    253254    virtual uint32_t evaluateToUInt32(ExecState*) KJS_FAST_CALL;
    254255    virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
    255     virtual Precedence precedence() const { return PrecPrimary; }
     256    virtual Precedence precedence() const { return signbit(m_double) ? PrecUnary : PrecPrimary; }
    256257
    257258    virtual bool isNumber() const KJS_FAST_CALL { return true; }
Note: See TracChangeset for help on using the changeset viewer.