Chromium Code Reviews| Index: test/cctest/test-parsing.cc |
| diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
| index 2aa4eaf5cd13e5c623ec8ac7176e89230be2a235..eb9cc50561608f8191395477be6c0121760349b2 100644 |
| --- a/test/cctest/test-parsing.cc |
| +++ b/test/cctest/test-parsing.cc |
| @@ -1390,7 +1390,8 @@ void SetParserFlags(i::ParserBase<Traits>* parser, |
| void TestParserSyncWithFlags(i::Handle<i::String> source, |
| i::EnumSet<ParserFlag> flags, |
| - ParserSyncTestResult result) { |
| + ParserSyncTestResult result, |
| + int literals = -1) { |
|
Dmitry Lomov (no reviews)
2014/12/10 18:49:31
Instead of passing the expected number of literals
|
| i::Isolate* isolate = CcTest::i_isolate(); |
| i::Factory* factory = isolate->factory(); |
| @@ -1409,7 +1410,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source, |
| } |
| bool preparse_error = log.HasError(); |
| - |
| + int actual_materialized_literals; |
| // Parse the data |
| i::FunctionLiteral* function; |
| { |
| @@ -1423,6 +1424,9 @@ void TestParserSyncWithFlags(i::Handle<i::String> source, |
| info.MarkAsGlobal(); |
| parser.Parse(); |
| function = info.function(); |
| + if (function) { |
| + actual_materialized_literals = function->materialized_literal_count(); |
|
caitp (gmail)
2014/12/10 18:17:49
have to do this here because the contents of the f
|
| + } |
| } |
| // Check that preparsing fails iff parsing fails. |
| @@ -1488,6 +1492,14 @@ void TestParserSyncWithFlags(i::Handle<i::String> source, |
| "However, parser and preparser succeeded", |
| source->ToCString().get()); |
| CHECK(false); |
| + } else if (literals > -1) { |
| + if (actual_materialized_literals != literals) { |
| + v8::base::OS::Print( |
| + "Expected parsed function to have %d materialized literals, " |
| + "but it had %d.", literals, actual_materialized_literals |
| + ); |
| + CHECK(false); |
| + } |
| } |
| } |
| @@ -1499,7 +1511,8 @@ void TestParserSync(const char* source, |
| const ParserFlag* always_true_flags = NULL, |
| size_t always_true_flags_length = 0, |
| const ParserFlag* always_false_flags = NULL, |
| - size_t always_false_flags_length = 0) { |
| + size_t always_false_flags_length = 0, |
| + int literals = -1) { |
| i::Handle<i::String> str = |
| CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(source); |
| for (int bits = 0; bits < (1 << varying_flags_length); bits++) { |
| @@ -1516,7 +1529,7 @@ void TestParserSync(const char* source, |
| ++flag_index) { |
| flags.Remove(always_false_flags[flag_index]); |
| } |
| - TestParserSyncWithFlags(str, flags, result); |
| + TestParserSyncWithFlags(str, flags, result, literals); |
| } |
| } |
| @@ -1665,7 +1678,8 @@ void RunParserSyncTest(const char* context_data[][2], |
| const ParserFlag* always_true_flags = NULL, |
| int always_true_len = 0, |
| const ParserFlag* always_false_flags = NULL, |
| - int always_false_len = 0) { |
| + int always_false_len = 0, |
| + const int* expected_literals = NULL) { |
| v8::HandleScope handles(CcTest::isolate()); |
| v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| v8::Context::Scope context_scope(context); |
| @@ -1717,6 +1731,10 @@ void RunParserSyncTest(const char* context_data[][2], |
| context_data[i][0], |
| statement_data[j], |
| context_data[i][1]); |
| + int expected_literal_count = -1; |
| + if (expected_literals) { |
| + expected_literal_count = expected_literals[j]; |
| + } |
| CHECK(length == kProgramSize); |
| TestParserSync(program.start(), |
| flags, |
| @@ -1725,7 +1743,8 @@ void RunParserSyncTest(const char* context_data[][2], |
| always_true_flags, |
| always_true_len, |
| always_false_flags, |
| - always_false_len); |
| + always_false_len, |
| + expected_literal_count); |
| } |
| } |
| delete[] generated_flags; |
| @@ -4469,6 +4488,55 @@ TEST(ScanTaggedTemplateLiterals) { |
| } |
| +TEST(TaggedTemplateMaterializedLiterals) { |
| + const char* context_data[][2] = { |
| + { |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" |
| + "'use strict';", |
|
caitp (gmail)
2014/12/10 18:17:49
(lldb) p actual_materialized_literals
(int) $16 =
|
| + "" |
| + }, |
| + { |
| + "function test(){ 'use strict';" |
| + " function tag() {}" |
| + " var a, b, c; return ", |
| + "}" |
| + }, |
| + {NULL, NULL} |
| + }; |
| + |
| + const char* data[] = { |
| + "tag``;", |
| + "tag`a`;", |
| + "tag`a${1}b`;", |
| + "tag`a${1}b${2}c`;", |
| + NULL |
| + }; |
| + |
| + const int literals[] = { |
| + 2, |
| + 2, |
| + 2, |
| + 2 |
| + }; |
| + |
| + static const ParserFlag always_flags[] = {kAllowHarmonyTemplates}; |
| + RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| + arraysize(always_flags), NULL, 0, literals); |
| +} |
| + |
| + |
| TEST(ScanUnterminatedTemplateLiterals) { |
| const char* context_data[][2] = {{"'use strict';", ""}, |
| {"function foo(){ 'use strict';" |