Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index be8c3f30de25af5f19fe5285a8411083486f9390..ff95f994a23233bceb52a3cc21306ffba9e3b6eb 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -5478,27 +5478,24 @@ Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start, |
if (!tag) { |
// Build tree of BinaryOps to simplify code-generation |
- Expression* expr = NULL; |
+ Expression* expr = cooked_strings->at(0); |
+ int i = 0; |
+ while (i < expressions->length()) { |
+ Expression* sub = expressions->at(i++); |
+ Expression* cooked_str = cooked_strings->at(i); |
+ |
+ // Let middle be ToString(sub). |
+ ZoneList<Expression*>* args = |
+ new (zone()) ZoneList<Expression*>(1, zone()); |
+ args->Add(sub, zone()); |
+ Expression* middle = factory()->NewCallRuntime( |
+ ast_value_factory()->to_string_string(), NULL, args, |
+ sub->position()); |
- if (expressions->length() == 0) { |
- // Simple case: treat as string literal |
- expr = cooked_strings->at(0); |
- } else { |
- int i; |
- Expression* cooked_str = cooked_strings->at(0); |
expr = factory()->NewBinaryOperation( |
- Token::ADD, cooked_str, expressions->at(0), cooked_str->position()); |
- for (i = 1; i < expressions->length(); ++i) { |
- cooked_str = cooked_strings->at(i); |
- expr = factory()->NewBinaryOperation( |
- Token::ADD, expr, factory()->NewBinaryOperation( |
- Token::ADD, cooked_str, expressions->at(i), |
- cooked_str->position()), |
- cooked_str->position()); |
- } |
- cooked_str = cooked_strings->at(i); |
- expr = factory()->NewBinaryOperation(Token::ADD, expr, cooked_str, |
- cooked_str->position()); |
+ Token::ADD, factory()->NewBinaryOperation( |
+ Token::ADD, expr, middle, expr->position()), |
+ cooked_str, sub->position()); |
} |
return expr; |
} else { |