Bug 1496329 - Properly implement shorthand properties in BinAST. (r=arai)
authorEric Faust <efausbmo@gmail.com>
Mon, 15 Oct 2018 17:17:58 -0400
changeset 489583 521f2719026367be8315e33f5f9bae8a4aa65f15
parent 489582 cbd3b405f0e2c009957f4d802fb4ba402dafaf7e
child 489584 f7d0546ee3cecaef21bf86e44717d84632d61580
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersarai
bugs1496329
milestone64.0a1
Bug 1496329 - Properly implement shorthand properties in BinAST. (r=arai)
js/src/frontend/BinSource-auto.cpp
js/src/frontend/BinSource.yaml
js/src/jit-test/tests/binast/shorthand.binjs
js/src/jit-test/tests/binast/shorthand.js
--- a/js/src/frontend/BinSource-auto.cpp
+++ b/js/src/frontend/BinSource-auto.cpp
@@ -4533,21 +4533,22 @@ BinASTParser<Tok>::parseInterfaceShortha
 
 #if defined(DEBUG)
     const BinField expected_fields[1] = { BinField::Name };
     MOZ_TRY(tokenizer_->checkFields(kind, fields, expected_fields));
 #endif // defined(DEBUG)
 
     BINJS_MOZ_TRY_DECL(name, parseIdentifierExpression());
 
-    if (!factory_.isUsableAsObjectPropertyName(name)) {
-        BINJS_TRY_VAR(name, factory_.newObjectLiteralPropertyName(name->name(), tokenizer_->pos(start)));
-    }
-
-    BINJS_TRY_DECL(result, factory_.newObjectMethodOrPropertyDefinition(name, name, AccessorType::None));
+    MOZ_ASSERT(name->isKind(ParseNodeKind::Name));
+    MOZ_ASSERT(!factory_.isUsableAsObjectPropertyName(name));
+    BINJS_TRY_DECL(propName, factory_.newObjectLiteralPropertyName(name->name(), tokenizer_->pos(start)));
+
+    BINJS_TRY_DECL(result, factory_.newObjectMethodOrPropertyDefinition(propName, name, AccessorType::None));
+    result->setKind(ParseNodeKind::Shorthand);
     return result;
 }
 
 template<typename Tok> JS::Result<ParseNode*>
 BinASTParser<Tok>::parseInterfaceSpreadElement(const size_t start, const BinKind kind, const BinFields& fields)
 {
     return raiseError("FIXME: Not implemented yet in this preview release (SpreadElement)");
 }
--- a/js/src/frontend/BinSource.yaml
+++ b/js/src/frontend/BinSource.yaml
@@ -1101,21 +1101,22 @@ Script:
             after: |
                 forceStrictIfNecessary(parseContext_->sc(), directives);
     build:
         MOZ_TRY(checkClosedVars(parseContext_->varScope()));
         BINJS_MOZ_TRY_DECL(result, appendDirectivesToBody(/* body = */ statements, /* directives = */ directives));
 
 ShorthandProperty:
     build: |
-        if (!factory_.isUsableAsObjectPropertyName(name)) {
-            BINJS_TRY_VAR(name, factory_.newObjectLiteralPropertyName(name->name(), tokenizer_->pos(start)));
-        }
+        MOZ_ASSERT(name->isKind(ParseNodeKind::Name));
+        MOZ_ASSERT(!factory_.isUsableAsObjectPropertyName(name));
+        BINJS_TRY_DECL(propName, factory_.newObjectLiteralPropertyName(name->name(), tokenizer_->pos(start)));
 
-        BINJS_TRY_DECL(result, factory_.newObjectMethodOrPropertyDefinition(name, name, AccessorType::None));
+        BINJS_TRY_DECL(result, factory_.newObjectMethodOrPropertyDefinition(propName, name, AccessorType::None));
+        result->setKind(ParseNodeKind::Shorthand);
 
 SwitchCase:
     type-ok:
         CaseClause*
     build: |
         BINJS_TRY_DECL(result, factory_.newCaseOrDefault(start, test, consequent));
 
 SwitchDefault:
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..88139f6dfe48a27b3ebfce1f9c56d70128f0b9dd
GIT binary patch
literal 388
zc${5OO-sW-5M7oKiWDg#QpAIlB0YEzuU<?wgouffEnb3$Niy1%&4-gwnqThKG)1;J
zbD1|Y@6E?Dj31OtgT#v>FL~7kR;;<Z`H`oKZ~$)_$=@`DZL8~Q;k7LiV{wnU0m34N
z5@$<Y6}o!2gsVr*NMPcx5=rNlfAIpOAv3t+1NXW4|6EPie`8cmy5Ydo85ot<4W8YB
zF?)J8R1Az|zrp!a_JKLu%6O+TQ|p>|4OQ_>y%KSEx#j3Q!ZO=GGF7W2j00ugF(1j!
y{RWbo2@IS0pXn;`ecQpuV@EntY+VR<B;|o4Trt@6c7V>2JP~4YC|qYM_KLqJ4t{<B
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/binast/shorthand.js
@@ -0,0 +1,3 @@
+var y = 6;
+var x = { y };
+assertEq(x.y, 6);