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

Unified Diff: src/parser.cc

Issue 1027183002: [es6] call ToString() on template substitutions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Test ToString behaviour for tagged templates + String.raw Created 5 years, 9 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-value-factory.h ('k') | test/mjsunit/es6/string-raw.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
« no previous file with comments | « src/ast-value-factory.h ('k') | test/mjsunit/es6/string-raw.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698