Commit a5bd7732 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[serializer] Fix top-level assumption

Fix assumption that only top level code won't have outer scope infos.

Bug: v8:7690
Change-Id: Ia6eec7b406632ad301e7db557597204c7ca66730
Reviewed-on: https://chromium-review.googlesource.com/1107622Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53869}
parent 2439c967
......@@ -576,20 +576,19 @@ void SharedFunctionInfo::FlushCompiled() {
DCHECK(CanFlushCompiled());
Oddball* the_hole = GetIsolate()->heap()->the_hole_value();
if (is_compiled()) {
HeapObject* outer_scope_info = the_hole;
if (!is_toplevel()) {
if (scope_info()->HasOuterScopeInfo()) {
outer_scope_info = scope_info()->OuterScopeInfo();
}
HeapObject* outer_scope_info;
if (scope_info()->HasOuterScopeInfo()) {
outer_scope_info = scope_info()->OuterScopeInfo();
} else {
outer_scope_info = GetIsolate()->heap()->the_hole_value();
}
// Raw setter to avoid validity checks, since we're performing the unusual
// task of decompiling.
set_raw_outer_scope_info_or_feedback_metadata(outer_scope_info);
} else {
DCHECK(outer_scope_info()->IsScopeInfo() || is_toplevel());
DCHECK(outer_scope_info()->IsScopeInfo() ||
outer_scope_info()->IsTheHole());
}
set_builtin_id(Builtins::kCompileLazy);
......
......@@ -2618,6 +2618,51 @@ TEST(SnapshotCreatorNoExternalReferencesDefault) {
delete[] blob.data;
}
v8::StartupData CreateCustomSnapshotWithPreparseDataAndNoOuterScope() {
v8::SnapshotCreator creator;
v8::Isolate* isolate = creator.GetIsolate();
{
v8::HandleScope handle_scope(isolate);
{
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
CompileRun(
"var foo = {\n"
" // This function is not top-level, but also has no outer scope.\n"
" bar: function(){\n"
" // Add an inner function so that the outer one has preparse\n"
" // scope data.\n"
" return function(){}\n"
" }\n"
"};\n");
creator.SetDefaultContext(context);
}
}
return creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
}
TEST(SnapshotCreatorPreparseDataAndNoOuterScope) {
DisableAlwaysOpt();
v8::StartupData blob = CreateCustomSnapshotWithPreparseDataAndNoOuterScope();
// Deserialize with an incomplete list of external references.
{
v8::Isolate::CreateParams params;
params.snapshot_blob = &blob;
params.array_buffer_allocator = CcTest::array_buffer_allocator();
// Test-appropriate equivalent of v8::Isolate::New.
v8::Isolate* isolate = TestIsolate::New(params);
{
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
}
isolate->Dispose();
}
delete[] blob.data;
}
TEST(SnapshotCreatorNoExternalReferencesCustomFail1) {
DisableAlwaysOpt();
v8::StartupData blob = CreateSnapshotWithDefaultAndCustom();
......
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