Commit 4b09b0d5 authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

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: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52321}
parent 12420537
......@@ -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
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