@@ -2176,129 +2176,6 @@ TEST(DeleteHeapSnapshot) {
21762176 CHECK(!FindHeapSnapshot(heap_profiler, s3));
21772177}
21782178
2179- class NameResolver : public v8::HeapProfiler::ObjectNameResolver {
2180- public:
2181- const char* GetName(v8::Local<v8::Object> object) override {
2182- return "Global object name";
2183- }
2184- };
2185-
2186- TEST(GlobalObjectNameSimple) {
2187- LocalContext env;
2188- v8::HandleScope scope(env.isolate());
2189- v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
2190-
2191- CompileRun("document = { URL:\"abcdefgh\" };");
2192-
2193- // Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
2194- // TODO(https://crbug.com/333672197): remove.
2195- START_ALLOW_USE_DEPRECATED()
2196- NameResolver name_resolver;
2197- const v8::HeapSnapshot* snapshot =
2198- heap_profiler->TakeHeapSnapshot(nullptr, &name_resolver);
2199- END_ALLOW_USE_DEPRECATED()
2200- CHECK(ValidateSnapshot(snapshot));
2201- const v8::HeapGraphNode* native_context = GetNativeContext(snapshot);
2202- CHECK_NOT_NULL(native_context);
2203- CHECK_EQ(std::string("system / NativeContext / Global object name"),
2204- std::string(GetName(native_context)));
2205-
2206- const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2207- CHECK_NOT_NULL(global);
2208- CHECK_EQ(std::string("Object (global*) / Global object name"),
2209- std::string(GetName(global)));
2210-
2211- const v8::HeapGraphNode* global_proxy = GetProperty(
2212- env.isolate(), global, v8::HeapGraphEdge::kInternal, "global_proxy");
2213- CHECK_NOT_NULL(global_proxy);
2214- CHECK_EQ(std::string("Object (global) / Global object name"),
2215- std::string(GetName(global_proxy)));
2216- }
2217-
2218- TEST(GlobalObjectName) {
2219- v8::Isolate* isolate = CcTest::isolate();
2220- v8::HandleScope scope(isolate);
2221-
2222- v8::Local<v8::FunctionTemplate> global_constructor =
2223- v8::FunctionTemplate::New(isolate);
2224- global_constructor->SetClassName(v8_str("MyGlobal"));
2225-
2226- v8::Local<v8::ObjectTemplate> global_template =
2227- v8::ObjectTemplate::New(isolate, global_constructor);
2228- LocalContext env(isolate, nullptr, global_template);
2229-
2230- v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
2231-
2232- CompileRun("document = { URL:\"abcdefgh\" };");
2233-
2234- // Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
2235- // TODO(https://crbug.com/333672197): remove.
2236- START_ALLOW_USE_DEPRECATED()
2237- NameResolver name_resolver;
2238- const v8::HeapSnapshot* snapshot =
2239- heap_profiler->TakeHeapSnapshot(nullptr, &name_resolver);
2240- END_ALLOW_USE_DEPRECATED()
2241- CHECK(ValidateSnapshot(snapshot));
2242- const v8::HeapGraphNode* native_context = GetNativeContext(snapshot);
2243- CHECK_NOT_NULL(native_context);
2244- CHECK_EQ(std::string("system / NativeContext / Global object name"),
2245- std::string(GetName(native_context)));
2246-
2247- const v8::HeapGraphNode* global = GetGlobalObject(snapshot, false);
2248- CHECK_NOT_NULL(global);
2249- CHECK_EQ(std::string("MyGlobal (global*) / Global object name"),
2250- std::string(GetName(global)));
2251-
2252- const v8::HeapGraphNode* global_proxy = GetProperty(
2253- env.isolate(), global, v8::HeapGraphEdge::kInternal, "global_proxy");
2254- CHECK_NOT_NULL(global_proxy);
2255- CHECK_EQ(std::string("MyGlobal (global) / Global object name"),
2256- std::string(GetName(global_proxy)));
2257- }
2258-
2259- TEST(GlobalObjectNameDetached) {
2260- v8::Isolate* isolate = CcTest::isolate();
2261- v8::HandleScope scope(isolate);
2262-
2263- v8::Local<v8::FunctionTemplate> global_constructor =
2264- v8::FunctionTemplate::New(isolate);
2265- global_constructor->SetClassName(v8_str("MyGlobal"));
2266-
2267- v8::Local<v8::ObjectTemplate> global_template =
2268- v8::ObjectTemplate::New(isolate, global_constructor);
2269- LocalContext env(isolate, nullptr, global_template);
2270-
2271- v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
2272-
2273- CompileRun("document = { URL:\"abcdefgh\" };");
2274-
2275- env->DetachGlobal();
2276-
2277- // Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
2278- // TODO(https://crbug.com/333672197): remove.
2279- START_ALLOW_USE_DEPRECATED()
2280- NameResolver name_resolver;
2281- const v8::HeapSnapshot* snapshot =
2282- heap_profiler->TakeHeapSnapshot(nullptr, &name_resolver);
2283- END_ALLOW_USE_DEPRECATED()
2284- CHECK(ValidateSnapshot(snapshot));
2285- const v8::HeapGraphNode* native_context = GetNativeContext(snapshot);
2286- CHECK_NOT_NULL(native_context);
2287- CHECK_EQ(std::string("system / NativeContext / Global object name"),
2288- std::string(GetName(native_context)));
2289-
2290- const v8::HeapGraphNode* global = GetGlobalObject(snapshot, false);
2291- CHECK_NOT_NULL(global);
2292- CHECK_EQ(std::string("MyGlobal (global*) / Global object name"),
2293- std::string(GetName(global)));
2294-
2295- const v8::HeapGraphNode* global_proxy = GetProperty(
2296- env.isolate(), global, v8::HeapGraphEdge::kInternal, "global_proxy");
2297- CHECK_NOT_NULL(global_proxy);
2298- CHECK_EQ(std::string("Object (global) / <detached>"),
2299- std::string(GetName(global_proxy)));
2300- }
2301-
23022179class ContextNameResolver : public v8::HeapProfiler::ContextNameResolver {
23032180 public:
23042181 const char* GetName(v8::Local<v8::Context> context) override {
0 commit comments