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

Unified Diff: src/parsing/parser.cc

Issue 2321533003: Properly handle holes following spreads in array literals (Closed)
Patch Set: Less auto Created 4 years, 3 months 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 | « src/ast/ast-value-factory.h ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 119c0164edd87b40de9b1c1742b78556d3bb8eec..28c12a836bd7dc437a831270fc1bc6ba5c832e33 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -5054,15 +5054,32 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
if (spread == nullptr) {
// If the element is not a spread, we're adding a single:
// %AppendElement($R, value)
- ZoneList<Expression*>* append_element_args = NewExpressionList(2);
- append_element_args->Add(factory()->NewVariableProxy(result), zone());
- append_element_args->Add(value, zone());
- do_block->statements()->Add(
- factory()->NewExpressionStatement(
- factory()->NewCallRuntime(Runtime::kAppendElement,
- append_element_args, kNoSourcePosition),
- kNoSourcePosition),
- zone());
+ // or, in case of a hole,
+ // ++($R.length)
+ if (!value->IsLiteral() ||
+ !value->AsLiteral()->raw_value()->IsTheHole()) {
+ ZoneList<Expression*>* append_element_args = NewExpressionList(2);
+ append_element_args->Add(factory()->NewVariableProxy(result), zone());
+ append_element_args->Add(value, zone());
+ do_block->statements()->Add(
+ factory()->NewExpressionStatement(
+ factory()->NewCallRuntime(Runtime::kAppendElement,
+ append_element_args,
+ kNoSourcePosition),
+ kNoSourcePosition),
+ zone());
+ } else {
+ Property* length_property = factory()->NewProperty(
+ factory()->NewVariableProxy(result),
+ factory()->NewStringLiteral(ast_value_factory()->length_string(),
+ kNoSourcePosition),
+ kNoSourcePosition);
+ CountOperation* count_op = factory()->NewCountOperation(
+ Token::INC, true /* prefix */, length_property, kNoSourcePosition);
+ do_block->statements()->Add(
+ factory()->NewExpressionStatement(count_op, kNoSourcePosition),
+ zone());
+ }
} else {
// If it's a spread, we're adding a for/of loop iterating through it.
Variable* each = NewTemporary(ast_value_factory()->dot_for_string());
« no previous file with comments | « src/ast/ast-value-factory.h ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698