WIP: parsePattern draft
authorDavid Teller <dteller@mozilla.com>
Sun, 06 Aug 2017 16:32:20 +0200
changeset 641390 54a1427bdc26e06bb697c84ae357a106c17b1c7c
parent 641389 d25624af658f8f584ee078ae6ccfba1e5ec5a7d3
child 641391 0bd1e89ab3b2d273f0329b9fd5848b0b7dcff120
push id72504
push userdteller@mozilla.com
push dateSun, 06 Aug 2017 22:28:40 +0000
milestone57.0a1
WIP: parsePattern MozReview-Commit-ID: 8Eofsdi7cqR
js/src/frontend/BinSource.cpp
--- a/js/src/frontend/BinSource.cpp
+++ b/js/src/frontend/BinSource.cpp
@@ -2390,16 +2390,58 @@ ASTReader::parsePatternList(SimpleTokenR
         result->append(pattern.release());
     }
 
     out = Move(result);
     return true;
 }
 
 bool
+ASTReader::parsePatternAux(SimpleTokenReader* reader, const BinKind kind, const SimpleTokenReader::BinFields& fields, UniquePtr<ParseNode>& out) {
+    if (out) {
+        return this->raiseError();
+    }
+
+    switch (kind) {
+        case BinKind::identifier: {
+            RootedAtom id(cx);
+            for (auto field: fields) {
+                switch (field) {
+                    case BinField::name:
+                        if (!this->readString(reader, &id)) {
+                            return false;
+                        }
+                        break;
+                    default:
+                        return this->raiseError();
+                }
+            }
+
+            if (!id) {
+                return this->raiseError();
+            }
+
+            UniquePtr<ParseNode> result(new_<NameNode>(PNK_NAME, JSOP_GETNAME, id, TokenPos()));
+            if (!result) {
+                return false;
+            }
+
+            out = Move(result);
+            return true;
+            break;
+        }
+        default:
+            // For the moment, we only support identifiers.
+            return this->raiseError();
+    }
+
+    return true;
+}
+
+bool
 ASTReader::readString(SimpleTokenReader* reader, MutableHandle<PropertyName*> out) {
     if (out) {
         return this->raiseError();
     }
 
     RootedAtom atom(cx);
 
     if (!this->readString(reader, &atom)) {