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

Unified Diff: test/cctest/test-parsing.cc

Issue 641283003: Support lazy parsing of inner functions (Closed) Base URL: https://chromium.googlesource.com/external/v8.git@bleeding_edge
Patch Set: Actually track variable declarations in the preparser Created 6 years, 1 month 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/vector.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 700d104a51a396bfb11ba922e777b373e573fedc..e0879cd31234864cadc5776aeab5f93f37a77b9a 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -157,7 +157,12 @@ TEST(ScanHTMLEndComments) {
i::CompleteParserRecorder log;
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
scanner.Initialize(&stream);
- i::PreParser preparser(&scanner, &log, stack_limit);
+ i::Zone zone(CcTest::i_isolate());
+ i::AstValueFactory ast_value_factory(
+ &zone, CcTest::i_isolate()->heap()->HashSeed());
+ ast_value_factory.Internalize(CcTest::i_isolate());
+ i::PreParser preparser(&scanner, &log, &ast_value_factory, &zone,
+ stack_limit);
preparser.set_allow_lazy(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
@@ -171,7 +176,12 @@ TEST(ScanHTMLEndComments) {
i::CompleteParserRecorder log;
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
scanner.Initialize(&stream);
- i::PreParser preparser(&scanner, &log, stack_limit);
+ i::Zone zone(CcTest::i_isolate());
+ i::AstValueFactory ast_value_factory(
+ &zone, CcTest::i_isolate()->heap()->HashSeed());
+ ast_value_factory.Internalize(CcTest::i_isolate());
+ i::PreParser preparser(&scanner, &log, &ast_value_factory, &zone,
+ stack_limit);
preparser.set_allow_lazy(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
// Even in the case of a syntax error, kPreParseSuccess is returned.
@@ -293,6 +303,7 @@ TEST(PreparseFunctionDataIsUsed) {
TEST(StandAlonePreParser) {
v8::V8::Initialize();
+ v8::HandleScope handles(CcTest::isolate());
CcTest::i_isolate()->stack_guard()->SetStackLimit(
i::GetCurrentStackPosition() - 128 * 1024);
@@ -317,7 +328,12 @@ TEST(StandAlonePreParser) {
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
scanner.Initialize(&stream);
- i::PreParser preparser(&scanner, &log, stack_limit);
+ i::Zone zone(CcTest::i_isolate());
+ i::AstValueFactory ast_value_factory(
+ &zone, CcTest::i_isolate()->heap()->HashSeed());
+ ast_value_factory.Internalize(CcTest::i_isolate());
+ i::PreParser preparser(&scanner, &log, &ast_value_factory, &zone,
+ stack_limit);
preparser.set_allow_lazy(true);
preparser.set_allow_natives_syntax(true);
preparser.set_allow_arrow_functions(true);
@@ -330,6 +346,7 @@ TEST(StandAlonePreParser) {
TEST(StandAlonePreParserNoNatives) {
v8::V8::Initialize();
+ v8::HandleScope handles(CcTest::isolate());
CcTest::i_isolate()->stack_guard()->SetStackLimit(
i::GetCurrentStackPosition() - 128 * 1024);
@@ -351,7 +368,12 @@ TEST(StandAlonePreParserNoNatives) {
scanner.Initialize(&stream);
// Preparser defaults to disallowing natives syntax.
- i::PreParser preparser(&scanner, &log, stack_limit);
+ i::Zone zone(CcTest::i_isolate());
+ i::AstValueFactory ast_value_factory(
+ &zone, CcTest::i_isolate()->heap()->HashSeed());
+ ast_value_factory.Internalize(CcTest::i_isolate());
+ i::PreParser preparser(&scanner, &log, &ast_value_factory, &zone,
+ stack_limit);
preparser.set_allow_lazy(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
@@ -398,6 +420,7 @@ TEST(PreparsingObjectLiterals) {
TEST(RegressChromium62639) {
v8::V8::Initialize();
+ v8::HandleScope handles(CcTest::isolate());
i::Isolate* isolate = CcTest::i_isolate();
isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
@@ -416,7 +439,11 @@ TEST(RegressChromium62639) {
i::CompleteParserRecorder log;
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
scanner.Initialize(&stream);
- i::PreParser preparser(&scanner, &log,
+ i::Zone zone(CcTest::i_isolate());
+ i::AstValueFactory ast_value_factory(&zone,
+ CcTest::i_isolate()->heap()->HashSeed());
+ ast_value_factory.Internalize(CcTest::i_isolate());
+ i::PreParser preparser(&scanner, &log, &ast_value_factory, &zone,
CcTest::i_isolate()->stack_guard()->real_climit());
preparser.set_allow_lazy(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
@@ -448,7 +475,11 @@ TEST(Regress928) {
i::CompleteParserRecorder log;
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
scanner.Initialize(&stream);
- i::PreParser preparser(&scanner, &log,
+ i::Zone zone(CcTest::i_isolate());
+ i::AstValueFactory ast_value_factory(&zone,
+ CcTest::i_isolate()->heap()->HashSeed());
+ ast_value_factory.Internalize(CcTest::i_isolate());
+ i::PreParser preparser(&scanner, &log, &ast_value_factory, &zone,
CcTest::i_isolate()->stack_guard()->real_climit());
preparser.set_allow_lazy(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
@@ -478,6 +509,7 @@ TEST(Regress928) {
TEST(PreParseOverflow) {
v8::V8::Initialize();
+ v8::HandleScope handles(CcTest::isolate());
CcTest::i_isolate()->stack_guard()->SetStackLimit(
i::GetCurrentStackPosition() - 128 * 1024);
@@ -496,7 +528,12 @@ TEST(PreParseOverflow) {
i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
scanner.Initialize(&stream);
- i::PreParser preparser(&scanner, &log, stack_limit);
+ i::Zone zone(CcTest::i_isolate());
+ i::AstValueFactory ast_value_factory(&zone,
+ CcTest::i_isolate()->heap()->HashSeed());
+ ast_value_factory.Internalize(CcTest::i_isolate());
+ i::PreParser preparser(&scanner, &log, &ast_value_factory, &zone,
+ stack_limit);
preparser.set_allow_lazy(true);
preparser.set_allow_arrow_functions(true);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
@@ -1373,7 +1410,13 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
{
i::Scanner scanner(isolate->unicode_cache());
i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
- i::PreParser preparser(&scanner, &log, stack_limit);
+ i::Zone zone(CcTest::i_isolate());
+ i::AstValueFactory ast_value_factory(
+ &zone, CcTest::i_isolate()->heap()->HashSeed());
+ v8::HandleScope handles(CcTest::isolate());
+ ast_value_factory.Internalize(CcTest::i_isolate());
+ i::PreParser preparser(&scanner, &log, &ast_value_factory, &zone,
+ stack_limit);
SetParserFlags(&preparser, flags);
scanner.Initialize(&stream);
i::PreParser::PreParseResult result = preparser.PreParseProgram();
@@ -2389,6 +2432,9 @@ TEST(DontRegressPreParserDataSizes) {
// Functions insize lazy functions are not recorded.
{"function lazy() { function a() {} function b() {} function c() {} }", 1},
{"function lazy() { var x = {get foo(){} } }", 1},
+ // Functions inside eager functions are recorded.
+ {"(function() { function lazy() {} })()", 1},
+ {"(function() { var lazy = function() {} })()", 1},
{NULL, 0}
};
@@ -2417,6 +2463,91 @@ TEST(DontRegressPreParserDataSizes) {
}
+TEST(PreParserReportsUnboundIdentifiers) {
+ v8::V8::Initialize();
+ v8::Isolate* isolate = CcTest::isolate();
+ i::Factory* factory = CcTest::i_isolate()->factory();
+ v8::HandleScope handles(isolate);
+
+ CcTest::i_isolate()->stack_guard()->SetStackLimit(
+ i::GetCurrentStackPosition() - 128 * 1024);
+
+ struct TestCase {
+ const char* function;
+ i::StrictMode strict_mode;
+ const char* identifier;
+ } test_cases[] = {
+ {"{ a = 0; }", i::SLOPPY, "a"},
+ {"{ var a = 0; }", i::SLOPPY, NULL},
+ {"{ a(); }", i::SLOPPY, "a"},
+ {"{ function a(){} a(); }", i::SLOPPY, NULL},
+ {"{ function a(){ b = 0; } }", i::SLOPPY, "b"},
+ {"{ function a(b){ b = 0; } }", i::SLOPPY, NULL},
+ {"{ try { a = 0; } catch (e) {} }", i::SLOPPY, "a"},
+ {"{ a = 0; try { var a = 1; } catch (e) { a = e; } }", i::SLOPPY, NULL},
+ {"{ var a = {}; with (a) { b = 0; } }", i::SLOPPY, "b"},
+ {"{ var a = {}; with (a) { var b = 0; } b = 1; }", i::SLOPPY, NULL},
+ {"{ for (var i = 0; i < 2; i++) { a = i; } }", i::STRICT, "a"},
+ {"{ for (let i = 0; i < 2; i++) { a = i; } }", i::STRICT, "a"},
+ {"{ for (let i = 0; i < 2; i++) {} i++; }", i::STRICT, "i"},
+ {"{ for (let a in a) {} }", i::STRICT, "a"},
+ {"{ for (let a of a) {} }", i::STRICT, "a"},
+ {"{ var o = {}; for (let a of o;;) { a(); } }", i::STRICT, NULL},
+ {"{ var o = {}; for (let a of o;;) { a(); } }", i::STRICT, NULL},
+ {"{ class C {} return C; }", i::SLOPPY, NULL},
+ {"{ function a(){ class C {} } return C; }", i::SLOPPY, "C"},
+ {"{ function a(){ let b = 0; } b = 1; }", i::STRICT, "b"},
+ {"{ if (1) { let b = 0; } b = 1; }", i::STRICT, "b"},
+ {"{ let a = 0; a = 1; }", i::STRICT, NULL},
+ {"{ if (1) { const b = 0; } b = 1; }", i::STRICT, "b"},
+ {NULL, i::STRICT, 0}
+ };
+
+ for (int i = 0; test_cases[i].function; i++) {
+ const char* function = test_cases[i].function;
+ const i::StrictMode strict_mode = test_cases[i].strict_mode;
+ i::Handle<i::String> source = factory->NewStringFromAsciiChecked(function);
+ i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
+ i::SingletonLogger log;
+ i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
+ scanner.Initialize(&stream);
+ i::Zone zone(CcTest::i_isolate());
+ i::AstValueFactory ast_value_factory(
+ &zone, CcTest::i_isolate()->heap()->HashSeed());
+ ast_value_factory.Internalize(CcTest::i_isolate());
+ i::PreParser preparser(&scanner, &log, &ast_value_factory, &zone,
+ CcTest::i_isolate()->stack_guard()->real_climit());
+ preparser.set_allow_classes(true);
+ preparser.set_allow_harmony_scoping(true);
+
+ scanner.Next(); // Kick-start the scanner so we have a current_token
+ CHECK_EQ(preparser.PreParseLazyFunction(strict_mode, false, true, &log),
+ i::PreParser::kPreParseSuccess);
+
+ const char* expected_identifier = test_cases[i].identifier;
+ i::SingletonLogger::IdentifierIterator it = log.IdentifiersStart();
+ if (expected_identifier) {
+ const i::AstRawString* reported_identifier = it.Next();
+ if (!(reported_identifier &&
+ reported_identifier->IsOneByteEqualTo(expected_identifier))) {
+ v8::base::OS::Print(
+ "Expected lazy preparse of function:\n"
+ "\t%s\n"
+ "to report identifier %s.\n",
+ function, expected_identifier);
+ if (reported_identifier) {
+ v8::base::OS::Print("(Actually reported %.*s)\n",
+ reported_identifier->length(),
+ reported_identifier->raw_data());
+ }
+ CHECK(false);
+ }
+ }
+ CHECK_EQ(it.Next(), NULL);
+ }
+}
+
+
TEST(FunctionDeclaresItselfStrict) {
// Tests that we produce the right kinds of errors when a function declares
// itself strict (we cannot produce there errors as soon as we see the
« no previous file with comments | « src/vector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698