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

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

Issue 203353002: New compilation API, part 2. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 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 | « test/cctest/test-debug.cc ('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 2e282cef8a52f0029680d45bae27b94a4a48ade6..5a2ee1303852b9ab440351b8f16b9f67fdec81db 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -215,11 +215,11 @@ TEST(Preparsing) {
ScriptResource* resource = new ScriptResource(source, source_length);
v8::ScriptCompiler::Source script_source(
v8::String::NewExternal(isolate, resource),
- v8::ScriptCompiler::CachedData(
+ new v8::ScriptCompiler::CachedData(
reinterpret_cast<const uint8_t*>(preparse->Data()),
preparse->Length()));
v8::ScriptCompiler::Compile(isolate,
- v8::ScriptCompiler::Source(script_source));
+ &script_source);
}
{
@@ -228,10 +228,10 @@ TEST(Preparsing) {
ScriptResource* resource = new ScriptResource(source, source_length);
v8::ScriptCompiler::Source script_source(
v8::String::NewExternal(isolate, resource),
- v8::ScriptCompiler::CachedData(
+ new v8::ScriptCompiler::CachedData(
reinterpret_cast<const uint8_t*>(preparse->Data()),
preparse->Length()));
- v8::ScriptCompiler::CompileUnbound(isolate, script_source);
+ v8::ScriptCompiler::CompileUnbound(isolate, &script_source);
}
delete preparse;
i::FLAG_lazy = lazy_flag;
@@ -263,6 +263,10 @@ TEST(Preparsing) {
TEST(PreparseFunctionDataIsUsed) {
// This tests that we actually do use the function data generated by the
// preparser.
+
+ // Make preparsing work for short scripts.
+ i::FLAG_min_preparse_length = 0;
+
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handles(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
@@ -271,28 +275,31 @@ TEST(PreparseFunctionDataIsUsed) {
CcTest::i_isolate()->stack_guard()->SetStackLimit(
reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
- const char* good_source =
+ const char* good_code =
"function this_is_lazy() { var a; } function foo() { return 25; } foo();";
// Insert a syntax error inside the lazy function.
- const char* bad_source =
+ const char* bad_code =
"function this_is_lazy() { if ( } function foo() { return 25; } foo();";
- v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source));
- CHECK(!preparse->HasError());
+ v8::ScriptCompiler::Source good_source(v8_str(good_code));
+ v8::ScriptCompiler::Compile(isolate, &good_source,
+ v8::ScriptCompiler::kProduceDataToCache);
+
+ const v8::ScriptCompiler::CachedData* cached_data =
+ good_source.GetCachedData();
+ CHECK(cached_data->data != NULL);
+ CHECK_GT(cached_data->length, 0);
// 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::ScriptCompiler::Source bad_source(
+ v8_str(bad_code), new v8::ScriptCompiler::CachedData(
+ cached_data->data, cached_data->length));
v8::Local<v8::Value> result =
- v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run();
+ v8::ScriptCompiler::Compile(isolate, &bad_source)->Run();
CHECK(result->IsInt32());
CHECK_EQ(25, result->Int32Value());
- delete preparse;
}
@@ -304,6 +311,9 @@ TEST(PreparseSymbolDataIsUsed) {
// source code again without preparse data and it will fail).
i::FLAG_crankshaft = false;
+ // Make preparsing work for short scripts.
+ i::FLAG_min_preparse_length = 0;
+
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handles(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
@@ -313,30 +323,33 @@ TEST(PreparseSymbolDataIsUsed) {
reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
// Note that the ( before function makes the function not lazily compiled.
- const char* good_source =
+ const char* good_code =
"(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 to "foo".
- const char* bad_source =
+ const char* bad_code =
"(function weird() { var foo = 26; return wut; })()";
- v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source));
- CHECK(!preparse->HasError());
+ v8::ScriptCompiler::Source good_source(v8_str(good_code));
+ v8::ScriptCompiler::Compile(isolate, &good_source,
+ v8::ScriptCompiler::kProduceDataToCache);
+
+ const v8::ScriptCompiler::CachedData* cached_data =
+ good_source.GetCachedData();
+ CHECK(cached_data->data != NULL);
+ CHECK_GT(cached_data->length, 0);
// 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::ScriptCompiler::Source bad_source(
+ v8_str(bad_code), new v8::ScriptCompiler::CachedData(
+ cached_data->data, cached_data->length));
v8::Local<v8::Value> result =
- v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run();
+ v8::ScriptCompiler::Compile(isolate, &bad_source)->Run();
CHECK(result->IsInt32());
CHECK_EQ(26, result->Int32Value());
- delete preparse;
}
« no previous file with comments | « test/cctest/test-debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698