Commit 29471bdb authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap-profiler] Annotate "const/let" refs in top level script context.

This patch extends ExtractContextReferences to handle all declaration
contexts, not only function/module/eval contexts.

Bug: chromium:817954
Change-Id: Ibe2827a9d6b2939552da26a60df959c9b22ea059
Reviewed-on: https://chromium-review.googlesource.com/962763
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51945}
parent 7c8476a2
......@@ -1033,8 +1033,8 @@ void V8HeapExplorer::ExtractJSWeakCollectionReferences(int entry,
}
void V8HeapExplorer::ExtractContextReferences(int entry, Context* context) {
if (context == context->declaration_context()) {
ScopeInfo* scope_info = context->closure()->shared()->scope_info();
if (!context->IsNativeContext() && context->is_declaration_context()) {
ScopeInfo* scope_info = context->scope_info();
// Add context allocated locals.
int context_locals = scope_info->ContextLocalCount();
for (int i = 0; i < context_locals; ++i) {
......
......@@ -2891,6 +2891,37 @@ TEST(JSPromise) {
}
}
TEST(HeapSnapshotScriptContext) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("class Foo{}; const foo = new Foo();");
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot();
CHECK(ValidateSnapshot(snapshot));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* native_context =
GetProperty(env->GetIsolate(), global, v8::HeapGraphEdge::kInternal,
"native_context");
CHECK(native_context);
const v8::HeapGraphNode* script_context_table =
GetProperty(env->GetIsolate(), native_context,
v8::HeapGraphEdge::kInternal, "script_context_table");
CHECK(script_context_table);
bool found_foo = false;
for (int i = 0, count = script_context_table->GetChildrenCount(); i < count;
++i) {
const v8::HeapGraphNode* context =
script_context_table->GetChild(i)->GetToNode();
const v8::HeapGraphNode* foo = GetProperty(
env->GetIsolate(), context, v8::HeapGraphEdge::kContextVariable, "foo");
if (foo) {
found_foo = true;
}
}
CHECK(found_foo);
}
class EmbedderNode : public v8::EmbedderGraph::Node {
public:
EmbedderNode(const char* name, size_t size,
......
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