Revision: 23321
Author:   [email protected]
Date:     Fri Aug 22 14:40:38 2014 UTC
Log:      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
[email protected]

Review URL: https://codereview.chromium.org/493173003
https://code.google.com/p/v8/source/detail?r=23321

Modified:
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/src/parser.h
 /branches/bleeding_edge/src/preparser.cc
 /branches/bleeding_edge/src/preparser.h
 /branches/bleeding_edge/test/mjsunit/object-literal.js

=======================================
--- /branches/bleeding_edge/src/parser.cc       Fri Aug 22 11:12:29 2014 UTC
+++ /branches/bleeding_edge/src/parser.cc       Fri Aug 22 14:40:38 2014 UTC
@@ -626,6 +626,15 @@
   DCHECK(result != NULL);
   return result;
 }
+
+
+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) {
=======================================
--- /branches/bleeding_edge/src/parser.h        Fri Aug 22 11:12:29 2014 UTC
+++ /branches/bleeding_edge/src/parser.h        Fri Aug 22 14:40:38 2014 UTC
@@ -534,6 +534,7 @@
   // 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,
=======================================
--- /branches/bleeding_edge/src/preparser.cc    Thu Aug 21 09:22:08 2014 UTC
+++ /branches/bleeding_edge/src/preparser.cc    Fri Aug 22 14:40:38 2014 UTC
@@ -80,6 +80,11 @@
   }
   return PreParserIdentifier::Default();
 }
+
+
+PreParserIdentifier PreParserTraits::GetNumberAsSymbol(Scanner* scanner) {
+  return PreParserIdentifier::Default();
+}


 PreParserExpression PreParserTraits::ExpressionFromString(
=======================================
--- /branches/bleeding_edge/src/preparser.h     Fri Aug 22 11:12:29 2014 UTC
+++ /branches/bleeding_edge/src/preparser.h     Fri Aug 22 14:40:38 2014 UTC
@@ -1254,6 +1254,7 @@

   // 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 @@
             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(
=======================================
--- /branches/bleeding_edge/test/mjsunit/object-literal.js Mon Jun 20 10:20:57 2011 UTC +++ /branches/bleeding_edge/test/mjsunit/object-literal.js Fri Aug 22 14:40:38 2014 UTC
@@ -190,3 +190,73 @@
 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(_) {; }
+});

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to