Bug 715682 - Make sure to generate the appropriate initializing opcode for accessors in object literals. r=bhackett
authorJeff Walden <jwalden@mit.edu>
Thu, 05 Jan 2012 17:40:14 -0600
changeset 85194 c2c541acf20100e21afdaa10cca59aec89e6a817
parent 85193 7c34bef1d9eab4b50210ab9601dd9604e4865d24
child 85195 f03e02f515295167f3a02eb7e63f21cc18b0382c
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs715682
milestone12.0a1
Bug 715682 - Make sure to generate the appropriate initializing opcode for accessors in object literals. r=bhackett
js/src/frontend/Parser.cpp
js/src/tests/ecma_5/Expressions/jstests.list
js/src/tests/ecma_5/Expressions/object-literal-accessor-property-name.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -6943,19 +6943,30 @@ Parser::primaryExpr(TokenKind tt, JSBool
                     tt = tokenStream.getToken(TSF_KEYWORD_IS_NAME);
                     if (tt == TOK_NAME) {
                         atom = tokenStream.currentToken().name();
                         pn3 = NameNode::create(PNK_NAME, atom, tc);
                         if (!pn3)
                             return NULL;
                     } else if (tt == TOK_STRING) {
                         atom = tokenStream.currentToken().atom();
-                        pn3 = NameNode::create(PNK_STRING, atom, tc);
-                        if (!pn3)
-                            return NULL;
+
+                        uint32_t index;
+                        if (atom->isIndex(&index)) {
+                            pn3 = NullaryNode::create(PNK_NUMBER, tc);
+                            if (!pn3)
+                                return NULL;
+                            pn3->pn_dval = index;
+                            if (!js_ValueToAtom(context, DoubleValue(pn3->pn_dval), &atom))
+                                return NULL;
+                        } else {
+                            pn3 = NameNode::create(PNK_STRING, atom, tc);
+                            if (!pn3)
+                                return NULL;
+                        }
                     } else if (tt == TOK_NUMBER) {
                         pn3 = NullaryNode::create(PNK_NUMBER, tc);
                         if (!pn3)
                             return NULL;
                         pn3->pn_dval = tokenStream.currentToken().number();
                         if (!js_ValueToAtom(context, DoubleValue(pn3->pn_dval), &atom))
                             return NULL;
                     } else {
--- a/js/src/tests/ecma_5/Expressions/jstests.list
+++ b/js/src/tests/ecma_5/Expressions/jstests.list
@@ -1,6 +1,7 @@
 url-prefix ../../jsreftest.html?test=ecma_5/Expressions/
 script 11.1.5-01.js
 script named-accessor-function.js
 script nested-delete-name-in-evalcode.js
 script object-literal-accessor-arguments.js
+script object-literal-accessor-property-name.js
 script string-literal-escape-sequences.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/Expressions/object-literal-accessor-property-name.js
@@ -0,0 +1,30 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+var gTestfile = 'object-literal-accessor-property-name.js';
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 536472;
+var summary =
+  'ES5: { get x(v) { } } and { set x(v, v2) { } } should be syntax errors';
+
+print(BUGNUMBER + ": " + summary);
+
+//-----------------------------------------------------------------------------
+
+({ get "0"() { } });
+({ get 0() { } });
+({ get 0.0() { } });
+({ get 0.() { } });
+({ get 1.() { } });
+({ get 5.2322341234123() { } });
+
+({ set "0"(q) { } });
+({ set 0(q) { } });
+({ set 0.0(q) { } });
+({ set 0.(q) { } });
+({ set 1.(q) { } });
+({ set 5.2322341234123(q) { } });
+
+//-----------------------------------------------------------------------------
+
+reportCompare(true, true);