Fix issue with numeric property names
We were not correctly treating 1.0 as 1, nor 1.20 as 1.2 in accessors. BUG=v8:3507 LOG=Y R=marja@chromium.org Review URL: https://codereview.chromium.org/493173003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23321 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
50ea93c614
commit
74a0d0f373
@ -628,6 +628,15 @@ const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) {
|
||||
}
|
||||
|
||||
|
||||
const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) {
|
||||
double double_value = parser_->scanner()->DoubleValue();
|
||||
char array[100];
|
||||
const char* string =
|
||||
DoubleToCString(double_value, Vector<char>(array, ARRAY_SIZE(array)));
|
||||
return ast_value_factory()->GetOneByteString(string);
|
||||
}
|
||||
|
||||
|
||||
const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
|
||||
return parser_->scanner()->NextSymbol(parser_->ast_value_factory_);
|
||||
}
|
||||
|
@ -534,6 +534,7 @@ class ParserTraits {
|
||||
// Producing data during the recursive descent.
|
||||
const AstRawString* GetSymbol(Scanner* scanner);
|
||||
const AstRawString* GetNextSymbol(Scanner* scanner);
|
||||
const AstRawString* GetNumberAsSymbol(Scanner* scanner);
|
||||
|
||||
Expression* ThisExpression(Scope* scope,
|
||||
AstNodeFactory<AstConstructionVisitor>* factory,
|
||||
|
@ -82,6 +82,11 @@ PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) {
|
||||
}
|
||||
|
||||
|
||||
PreParserIdentifier PreParserTraits::GetNumberAsSymbol(Scanner* scanner) {
|
||||
return PreParserIdentifier::Default();
|
||||
}
|
||||
|
||||
|
||||
PreParserExpression PreParserTraits::ExpressionFromString(
|
||||
int pos, Scanner* scanner, PreParserFactory* factory) {
|
||||
if (scanner->UnescapedLiteralMatches("use strict", 10)) {
|
||||
|
@ -1254,6 +1254,7 @@ class PreParserTraits {
|
||||
|
||||
// Producing data during the recursive descent.
|
||||
PreParserIdentifier GetSymbol(Scanner* scanner);
|
||||
PreParserIdentifier GetNumberAsSymbol(Scanner* scanner);
|
||||
|
||||
static PreParserIdentifier GetNextSymbol(Scanner* scanner) {
|
||||
return PreParserIdentifier::Default();
|
||||
@ -1895,10 +1896,7 @@ typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase<
|
||||
break;
|
||||
case Token::NUMBER:
|
||||
Consume(Token::NUMBER);
|
||||
// TODO(arv): Fix issue with numeric keys. get 1.0() should be
|
||||
// treated as if the key was '1'
|
||||
// https://code.google.com/p/v8/issues/detail?id=3507
|
||||
name = this->GetSymbol(scanner_);
|
||||
name = this->GetNumberAsSymbol(scanner_);
|
||||
break;
|
||||
default:
|
||||
name = ParseIdentifierName(
|
||||
|
@ -190,3 +190,73 @@ function testKeywordProperty(keyword) {
|
||||
for (var i = 0; i < keywords.length; i++) {
|
||||
testKeywordProperty(keywords[i]);
|
||||
}
|
||||
|
||||
|
||||
(function TestNumericNames() {
|
||||
var o = {
|
||||
1: 1,
|
||||
2.: 2,
|
||||
3.0: 3,
|
||||
4e0: 4,
|
||||
5E0: 5,
|
||||
6e-0: 6,
|
||||
7E-0: 7,
|
||||
0x8: 8,
|
||||
0X9: 9,
|
||||
}
|
||||
assertEquals(['1', '2', '3', '4', '5', '6', '7', '8', '9'], Object.keys(o));
|
||||
|
||||
o = {
|
||||
1.2: 1.2,
|
||||
1.30: 1.3
|
||||
};
|
||||
assertEquals(['1.2', '1.3'], Object.keys(o));
|
||||
})();
|
||||
|
||||
|
||||
function TestNumericNamesGetter(expectedKeys, object) {
|
||||
assertEquals(expectedKeys, Object.keys(object));
|
||||
expectedKeys.forEach(function(key) {
|
||||
var descr = Object.getOwnPropertyDescriptor(object, key);
|
||||
assertEquals(key, descr.get.name);
|
||||
});
|
||||
}
|
||||
TestNumericNamesGetter(['1', '2', '3', '4', '5', '6', '7', '8', '9'], {
|
||||
get 1() {},
|
||||
get 2.() {},
|
||||
get 3.0() {},
|
||||
get 4e0() {},
|
||||
get 5E0() {},
|
||||
get 6e-0() {},
|
||||
get 7E-0() {},
|
||||
get 0x8() {},
|
||||
get 0X9() {},
|
||||
});
|
||||
TestNumericNamesGetter(['1.2', '1.3'], {
|
||||
get 1.2() {},
|
||||
get 1.30() {}
|
||||
});
|
||||
|
||||
|
||||
function TestNumericNamesSetter(expectedKeys, object) {
|
||||
assertEquals(expectedKeys, Object.keys(object));
|
||||
expectedKeys.forEach(function(key) {
|
||||
var descr = Object.getOwnPropertyDescriptor(object, key);
|
||||
assertEquals(key, descr.set.name);
|
||||
});
|
||||
}
|
||||
TestNumericNamesSetter(['1', '2', '3', '4', '5', '6', '7', '8', '9'], {
|
||||
set 1(_) {},
|
||||
set 2.(_) {},
|
||||
set 3.0(_) {},
|
||||
set 4e0(_) {},
|
||||
set 5E0(_) {},
|
||||
set 6e-0(_) {},
|
||||
set 7E-0(_) {},
|
||||
set 0x8(_) {},
|
||||
set 0X9(_) {},
|
||||
});
|
||||
TestNumericNamesSetter(['1.2', '1.3'], {
|
||||
set 1.2(_) {; },
|
||||
set 1.30(_) {; }
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user