Commit a8cc89c4 authored by marja@chromium.org's avatar marja@chromium.org

Add tests which ensure that the data produced by the preparser is really used.

R=rossberg@chromium.org
BUG=

Review URL: https://codereview.chromium.org/201133005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20003 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9a340d1f
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment