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()); |