Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Unified Diff: src/ast.h

Issue 1309813007: [es6] implement destructuring assignment (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: An implementation Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/ast-expression-visitor.cc » ('j') | src/ast-expression-visitor.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index 14f71a6cc28bfb03e95f2f767c97cce90727542d..d48d1820437619422346bef34c29fbfe0f3c8c2d 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -75,6 +75,7 @@ namespace internal {
V(ObjectLiteral) \
V(ArrayLiteral) \
V(Assignment) \
+ V(AssignmentPattern) \
V(Yield) \
V(Throw) \
V(Property) \
@@ -2396,6 +2397,42 @@ class Assignment final : public Expression {
};
+class AssignmentPattern final : public Expression {
+ public:
+ DECLARE_NODE_TYPE(AssignmentPattern)
+
+ // AssignmentPattern should always be the Target of an Assignment.
+ // If encountered during compilation, and the assignment expression
+ // is not null (the node has been rewritten), the rewritten expression
+ // should be used in place of the normal assignment behaviour.
+ // Otherwise, the LHS is treated as the original pattern, which should
+ // result in an exception.
+ bool is_rewritten() const { return expression_ != pattern_; }
+ Expression* pattern() const { return pattern_; }
+ Expression* expression() const { return expression_; }
+
+ static int num_ids() { return parent_num_ids(); }
+
+ void set_expression(Expression* expr) {
+ // Only to be called by Parser::PatternRewriter
+ DCHECK_NE(expr, pattern_);
+ DCHECK_NOT_NULL(expr);
+ expression_ = expr;
+ }
+
+ protected:
+ AssignmentPattern(Zone* zone, Expression* pattern, int pos)
+ : Expression(zone, pos), pattern_(pattern), expression_(pattern) {}
+ static int parent_num_ids() { return Expression::num_ids(); }
+
+ private:
+ int local_id(int n) const { return base_id() + parent_num_ids() + n; }
+
+ Expression* pattern_;
+ Expression* expression_;
+};
+
+
class Yield final : public Expression {
public:
DECLARE_NODE_TYPE(Yield)
@@ -3557,6 +3594,11 @@ class AstNodeFactory final BASE_EMBEDDED {
return assign;
}
+ AssignmentPattern* NewAssignmentPattern(Expression* pattern, int pos) {
+ DCHECK(pattern->IsObjectLiteral() || pattern->IsArrayLiteral());
+ return new (local_zone_) AssignmentPattern(local_zone_, pattern, pos);
+ }
+
Yield* NewYield(Expression *generator_object,
Expression* expression,
Yield::Kind yield_kind,
« no previous file with comments | « no previous file | src/ast-expression-visitor.cc » ('j') | src/ast-expression-visitor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698