Add tests for v8::ScriptCompiler::kEagerCompile.

R=leszeks@chromium.org

Bug: v8:7591
Change-Id: Idcd2d586ab279dc070d2cfb2558298ebdd3ce33b
Reviewed-on: https://chromium-review.googlesource.com/991873
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52321}
This commit is contained in:
Yang Guo 2018-04-03 12:08:45 +02:00 committed by Commit Bot
parent 12420537c8
commit 4b09b0d557

View File

@ -786,5 +786,57 @@ TEST(InvocationCount) {
CHECK_EQ(4, foo->feedback_vector()->invocation_count());
}
TEST(ShallowEagerCompilation) {
i::FLAG_always_opt = false;
CcTest::InitializeVM();
LocalContext env;
i::Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::String> source = v8_str(
"function f(x) {"
" return x + x;"
"}"
"f(2)");
v8::ScriptCompiler::Source script_source(source);
v8::Local<v8::Script> script =
v8::ScriptCompiler::Compile(env.local(), &script_source,
v8::ScriptCompiler::kEagerCompile)
.ToLocalChecked();
{
v8::internal::DisallowCompilation no_compile_expected(isolate);
v8::Local<v8::Value> result = script->Run(env.local()).ToLocalChecked();
CHECK_EQ(4, result->Int32Value(env.local()).FromJust());
}
}
TEST(DeepEagerCompilation) {
i::FLAG_always_opt = false;
CcTest::InitializeVM();
LocalContext env;
i::Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::String> source = v8_str(
"function f(x) {"
" function g(x) {"
" function h(x) {"
" return x ** x;"
" }"
" return h(x) * h(x);"
" }"
" return g(x) + g(x);"
"}"
"f(2)");
v8::ScriptCompiler::Source script_source(source);
v8::Local<v8::Script> script =
v8::ScriptCompiler::Compile(env.local(), &script_source,
v8::ScriptCompiler::kEagerCompile)
.ToLocalChecked();
{
v8::internal::DisallowCompilation no_compile_expected(isolate);
v8::Local<v8::Value> result = script->Run(env.local()).ToLocalChecked();
CHECK_EQ(32, result->Int32Value(env.local()).FromJust());
}
}
} // namespace internal
} // namespace v8