Commit 4d3a0a7c authored by bradnelson's avatar bradnelson Committed by Commit bot

Treat the x*1 generated by parsing a unary + as containing a dot.

Since we convert +x to x*1, we loose information about whether
the 1 was intended to be a floating point value for asm.js or not.

Mark the generated 1 as containing a dot (i.e. 1.0).

BUG= https://code.google.com/p/v8/issues/detail?id=4203
TEST=test-parser
R=rossberg@chromium.org,titzer@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/1306683003

Cr-Commit-Position: refs/heads/master@{#30481}
parent 8b781ecc
......@@ -626,7 +626,7 @@ Expression* ParserTraits::BuildUnaryExpression(Expression* expression,
// Desugar '+foo' => 'foo*1'
if (op == Token::ADD) {
return factory->NewBinaryOperation(
Token::MUL, expression, factory->NewNumberLiteral(1, pos), pos);
Token::MUL, expression, factory->NewNumberLiteral(1, pos, true), pos);
}
// The same idea for '-foo' => 'foo*(-1)'.
if (op == Token::SUB) {
......
......@@ -1134,10 +1134,19 @@ static void CheckParsesToNumber(const char* source, bool with_dot) {
CHECK(fun->body()->length() == 1);
CHECK(fun->body()->at(0)->IsReturnStatement());
i::ReturnStatement* ret = fun->body()->at(0)->AsReturnStatement();
CHECK(ret->expression()->IsLiteral());
i::Literal* lit = ret->expression()->AsLiteral();
const i::AstValue* val = lit->raw_value();
CHECK(with_dot == val->ContainsDot());
if (lit != NULL) {
const i::AstValue* val = lit->raw_value();
CHECK(with_dot == val->ContainsDot());
} else if (with_dot) {
i::BinaryOperation* bin = ret->expression()->AsBinaryOperation();
CHECK(bin != NULL);
CHECK_EQ(i::Token::MUL, bin->op());
i::Literal* rlit = bin->right()->AsLiteral();
const i::AstValue* val = rlit->raw_value();
CHECK(with_dot == val->ContainsDot());
CHECK_EQ(1.0, val->AsNumber());
}
}
......@@ -1148,6 +1157,7 @@ TEST(ParseNumbers) {
CheckParsesToNumber("134.e44", true);
CheckParsesToNumber("134.44e44", true);
CheckParsesToNumber(".44", true);
CheckParsesToNumber("+x", true);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment