Index: test/cctest/test-parsing.cc |
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
index 7d1f46ccb3ff83e03b1eddf5f768156dfa564f72..5ae7b527348e602047f8666e3d4482a2aff260bf 100644 |
--- a/test/cctest/test-parsing.cc |
+++ b/test/cctest/test-parsing.cc |
@@ -260,6 +260,86 @@ TEST(Preparsing) { |
} |
+TEST(PreparseFunctionDataIsUsed) { |
+ // This tests that we actually do use the function data generated by the |
+ // preparser. |
+ v8::Isolate* isolate = CcTest::isolate(); |
+ v8::HandleScope handles(isolate); |
+ v8::Local<v8::Context> context = v8::Context::New(isolate); |
+ v8::Context::Scope context_scope(context); |
+ int marker; |
+ CcTest::i_isolate()->stack_guard()->SetStackLimit( |
+ reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
+ |
+ const char* good_source = |
+ "function this_is_lazy() { var a; } function foo() { return 25; } foo();"; |
+ |
+ // Insert a syntax error inside the lazy function. |
+ const char* bad_source = |
+ "function this_is_lazy() { if ( } function foo() { return 25; } foo();"; |
+ |
+ v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source)); |
+ CHECK(!preparse->HasError()); |
+ |
+ // Now compile the erroneous code with the good preparse data. If the preparse |
+ // data is used, the lazy function is skipped and it should compile fine. |
+ v8::ScriptCompiler::Source source( |
+ v8_str(bad_source), |
+ v8::ScriptCompiler::CachedData( |
+ reinterpret_cast<const uint8_t*>(preparse->Data()), |
+ preparse->Length())); |
+ v8::Local<v8::Value> result = |
+ v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run(); |
+ CHECK(result->IsInt32()); |
+ CHECK_EQ(25, result->Int32Value()); |
+ delete preparse; |
+} |
+ |
+ |
+TEST(PreparseSymbolDataIsUsed) { |
+ // This tests that we actually do use the symbol data generated by the |
+ // preparser. |
+ |
+ // Only do one compilation pass in this test (otherwise we will parse the |
+ // source code again without preparse data and it will fail). |
+ i::FLAG_crankshaft = false; |
+ |
+ v8::Isolate* isolate = CcTest::isolate(); |
+ v8::HandleScope handles(isolate); |
+ v8::Local<v8::Context> context = v8::Context::New(isolate); |
+ v8::Context::Scope context_scope(context); |
+ int marker; |
+ CcTest::i_isolate()->stack_guard()->SetStackLimit( |
+ reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
+ |
+ // Note that the ( before function makes the |
+ const char* good_source = |
+ "(function weird() { var foo = 26; return foo; })()"; |
+ |
+ // Insert an undefined identifier. If the preparser data is used, the symbol |
+ // stream is used instead, and this identifier resolves correctly to"foo". |
+ const char* bad_source = |
+ "(function weird() { var foo = 26; return wut; })()"; |
+ |
+ v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source)); |
+ CHECK(!preparse->HasError()); |
+ |
+ // Now compile the erroneous code with the good preparse data. If the preparse |
+ // data is used, we will see a second occurrence of "foo" instead of the |
+ // unknown "wut". |
+ v8::ScriptCompiler::Source source( |
+ v8_str(bad_source), |
+ v8::ScriptCompiler::CachedData( |
+ reinterpret_cast<const uint8_t*>(preparse->Data()), |
+ preparse->Length())); |
+ v8::Local<v8::Value> result = |
+ v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run(); |
+ CHECK(result->IsInt32()); |
+ CHECK_EQ(26, result->Int32Value()); |
+ delete preparse; |
+} |
+ |
+ |
TEST(StandAlonePreParser) { |
v8::V8::Initialize(); |