| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6319ea6 commit a2f39e9
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -912,12 +912,22 @@ class V8_EXPORT EmbedderGraph { | |||
| 912 | 912 | virtual ~EmbedderGraph() = default; | |
| 913 | 913 | }; | |
| 914 | 914 | ||
| 915 | + class QueryObjectPredicate { | ||
| 916 | + public: | ||
| 917 | + virtual ~QueryObjectPredicate() = default; | ||
| 918 | + virtual bool Filter(v8::Local<v8::Object> object) = 0; | ||
| 919 | + }; | ||
| 920 | + | ||
| 915 | 921 | /** | |
| 916 | 922 | * Interface for controlling heap profiling. Instance of the | |
| 917 | 923 | * profiler can be retrieved using v8::Isolate::GetHeapProfiler. | |
| 918 | 924 | */ | |
| 919 | 925 | class V8_EXPORT HeapProfiler { | |
| 920 | 926 | public: | |
| 927 | + void QueryObjects(v8::Local<v8::Context> context, | ||
| 928 | + QueryObjectPredicate* predicate, | ||
| 929 | + std::vector<v8::Global<v8::Object>>* objects); | ||
| 930 | + | ||
| 921 | 931 | enum SamplingFlags { | |
| 922 | 932 | kSamplingNoFlags = 0, | |
| 923 | 933 | kSamplingForceGC = 1 << 0, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11011,6 +11011,16 @@ int HeapProfiler::GetSnapshotCount() { | |||
| 11011 | 11011 | return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount(); | |
| 11012 | 11012 | } | |
| 11013 | 11013 | ||
| 11014 | + void HeapProfiler::QueryObjects(Local<Context> v8_context, | ||
| 11015 | + QueryObjectPredicate* predicate, | ||
| 11016 | + std::vector<Global<Object>>* objects) { | ||
| 11017 | + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_context->GetIsolate()); | ||
| 11018 | + i::HeapProfiler* profiler = reinterpret_cast<i::HeapProfiler*>(this); | ||
| 11019 | + DCHECK_EQ(isolate, profiler->isolate()); | ||
| 11020 | + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | ||
| 11021 | + profiler->QueryObjects(Utils::OpenHandle(*v8_context), predicate, objects); | ||
| 11022 | + } | ||
| 11023 | + | ||
| 11014 | 11024 | const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) { | |
| 11015 | 11025 | return reinterpret_cast<const HeapSnapshot*>( | |
| 11016 | 11026 | reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1203,15 +1203,6 @@ v8::MaybeLocal<v8::Value> EvaluateGlobalForTesting( | |||
| 1203 | 1203 | RETURN_ESCAPED(result); | |
| 1204 | 1204 | } | |
| 1205 | 1205 | ||
| 1206 | - void QueryObjects(v8::Local<v8::Context> v8_context, | ||
| 1207 | - QueryObjectPredicate* predicate, | ||
| 1208 | - std::vector<v8::Global<v8::Object>>* objects) { | ||
| 1209 | - i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_context->GetIsolate()); | ||
| 1210 | - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | ||
| 1211 | - isolate->heap_profiler()->QueryObjects(Utils::OpenHandle(*v8_context), | ||
| 1212 | - predicate, objects); | ||
| 1213 | - } | ||
| 1214 | - | ||
| 1215 | 1206 | void GlobalLexicalScopeNames(v8::Local<v8::Context> v8_context, | |
| 1216 | 1207 | std::vector<v8::Global<v8::String>>* names) { | |
| 1217 | 1208 | i::Handle<i::Context> context = Utils::OpenHandle(*v8_context); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -523,16 +523,6 @@ class V8_EXPORT_PRIVATE StackTraceIterator { | |||
| 523 | 523 | bool throw_on_side_effect) = 0; | |
| 524 | 524 | }; | |
| 525 | 525 | ||
| 526 | - class QueryObjectPredicate { | ||
| 527 | - public: | ||
| 528 | - virtual ~QueryObjectPredicate() = default; | ||
| 529 | - virtual bool Filter(v8::Local<v8::Object> object) = 0; | ||
| 530 | - }; | ||
| 531 | - | ||
| 532 | - void QueryObjects(v8::Local<v8::Context> context, | ||
| 533 | - QueryObjectPredicate* predicate, | ||
| 534 | - std::vector<v8::Global<v8::Object>>* objects); | ||
| 535 | - | ||
| 536 | 526 | void GlobalLexicalScopeNames(v8::Local<v8::Context> context, | |
| 537 | 527 | std::vector<v8::Global<v8::String>>* names); | |
| 538 | 528 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ | |||
| 8 | 8 | #include "include/v8-context.h" | |
| 9 | 9 | #include "include/v8-function.h" | |
| 10 | 10 | #include "include/v8-microtask-queue.h" | |
| 11 | + #include "include/v8-profiler.h" | ||
| 11 | 12 | #include "include/v8-util.h" | |
| 12 | 13 | #include "src/inspector/inspected-context.h" | |
| 13 | 14 | #include "src/inspector/protocol/Protocol.h" | |
@@ -37,7 +38,7 @@ void cleanupExpiredWeakPointers(Map& map) { | |||
| 37 | 38 | } | |
| 38 | 39 | } | |
| 39 | 40 | ||
| 40 | - class MatchPrototypePredicate : public v8::debug::QueryObjectPredicate { | ||
| 41 | + class MatchPrototypePredicate : public v8::QueryObjectPredicate { | ||
| 41 | 42 | public: | |
| 42 | 43 | MatchPrototypePredicate(V8InspectorImpl* inspector, | |
| 43 | 44 | v8::Local<v8::Context> context, | |
@@ -1004,7 +1005,7 @@ v8::Local<v8::Array> V8Debugger::queryObjects(v8::Local<v8::Context> context, | |||
| 1004 | 1005 | v8::Isolate* isolate = context->GetIsolate(); | |
| 1005 | 1006 | std::vector<v8::Global<v8::Object>> v8_objects; | |
| 1006 | 1007 | MatchPrototypePredicate predicate(m_inspector, context, prototype); | |
| 1007 | - v8::debug::QueryObjects(context, &predicate, &v8_objects); | ||
| 1008 | + isolate->GetHeapProfiler()->QueryObjects(context, &predicate, &v8_objects); | ||
| 1008 | 1009 | ||
| 1009 | 1010 | v8::MicrotasksScope microtasksScope(context, | |
| 1010 | 1011 | v8::MicrotasksScope::kDoNotRunMicrotasks); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,7 +245,7 @@ Heap* HeapProfiler::heap() const { return ids_->heap(); } | |||
| 245 | 245 | Isolate* HeapProfiler::isolate() const { return heap()->isolate(); } | |
| 246 | 246 | ||
| 247 | 247 | void HeapProfiler::QueryObjects(Handle<Context> context, | |
| 248 | - debug::QueryObjectPredicate* predicate, | ||
| 248 | + v8::QueryObjectPredicate* predicate, | ||
| 249 | 249 | std::vector<v8::Global<v8::Object>>* objects) { | |
| 250 | 250 | { | |
| 251 | 251 | HandleScope handle_scope(isolate()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,8 +88,7 @@ class HeapProfiler : public HeapObjectAllocationTracker { | |||
| 88 | 88 | ||
| 89 | 89 | Isolate* isolate() const; | |
| 90 | 90 | ||
| 91 | - void QueryObjects(Handle<Context> context, | ||
| 92 | - debug::QueryObjectPredicate* predicate, | ||
| 91 | + void QueryObjects(Handle<Context> context, QueryObjectPredicate* predicate, | ||
| 93 | 92 | std::vector<v8::Global<v8::Object>>* objects); | |
| 94 | 93 | ||
| 95 | 94 | private: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,7 @@ | |||
| 30 | 30 | #include <ctype.h> | |
| 31 | 31 | ||
| 32 | 32 | #include <memory> | |
| 33 | + #include <vector> | ||
| 33 | 34 | ||
| 34 | 35 | #include "include/v8-function.h" | |
| 35 | 36 | #include "include/v8-json.h" | |
@@ -4060,6 +4061,67 @@ TEST(SamplingHeapProfilerSampleDuringDeopt) { | |||
| 4060 | 4061 | heap_profiler->StopSamplingHeapProfiler(); | |
| 4061 | 4062 | } | |
| 4062 | 4063 | ||
| 4064 | + namespace { | ||
| 4065 | + class TestQueryObjectPredicate : public v8::QueryObjectPredicate { | ||
| 4066 | + public: | ||
| 4067 | + TestQueryObjectPredicate(v8::Local<v8::Context> context, | ||
| 4068 | + v8::Local<v8::Symbol> symbol) | ||
| 4069 | + : context_(context), symbol_(symbol) {} | ||
| 4070 | + | ||
| 4071 | + bool Filter(v8::Local<v8::Object> object) override { | ||
| 4072 | + return object->HasOwnProperty(context_, symbol_).FromMaybe(false); | ||
| 4073 | + } | ||
| 4074 | + | ||
| 4075 | + private: | ||
| 4076 | + v8::Local<v8::Context> context_; | ||
| 4077 | + v8::Local<v8::Symbol> symbol_; | ||
| 4078 | + }; | ||
| 4079 | + | ||
| 4080 | + class IncludeAllQueryObjectPredicate : public v8::QueryObjectPredicate { | ||
| 4081 | + public: | ||
| 4082 | + IncludeAllQueryObjectPredicate() {} | ||
| 4083 | + bool Filter(v8::Local<v8::Object> object) override { return true; } | ||
| 4084 | + }; | ||
| 4085 | + } // anonymous namespace | ||
| 4086 | + | ||
| 4087 | + TEST(QueryObjects) { | ||
| 4088 | + LocalContext env; | ||
| 4089 | + v8::Isolate* isolate = env->GetIsolate(); | ||
| 4090 | + v8::HandleScope scope(isolate); | ||
| 4091 | + v8::Local<v8::Context> context = env.local(); | ||
| 4092 | + | ||
| 4093 | + v8::Local<v8::Symbol> sym = | ||
| 4094 | + v8::Symbol::New(isolate, v8_str("query_object_test")); | ||
| 4095 | + context->Global()->Set(context, v8_str("test_symbol"), sym).Check(); | ||
| 4096 | + v8::Local<v8::Value> arr = CompileRun(R"( | ||
| 4097 | + const arr = []; | ||
| 4098 | + for (let i = 0; i < 10; ++i) { | ||
| 4099 | + arr.push({[test_symbol]: true}); | ||
| 4100 | + } | ||
| 4101 | + arr; | ||
| 4102 | + )"); | ||
| 4103 | + context->Global()->Set(context, v8_str("arr"), arr).Check(); | ||
| 4104 | + v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | ||
| 4105 | + | ||
| 4106 | + { | ||
| 4107 | + TestQueryObjectPredicate predicate(context, sym); | ||
| 4108 | + std::vector<v8::Global<v8::Object>> out; | ||
| 4109 | + heap_profiler->QueryObjects(context, &predicate, &out); | ||
| 4110 | + | ||
| 4111 | + CHECK_EQ(out.size(), 10); | ||
| 4112 | + for (size_t i = 0; i < out.size(); ++i) { | ||
| 4113 | + CHECK(out[i].Get(isolate)->HasOwnProperty(context, sym).FromMaybe(false)); | ||
| 4114 | + } | ||
| 4115 | + } | ||
| 4116 | + | ||
| 4117 | + { | ||
| 4118 | + IncludeAllQueryObjectPredicate predicate; | ||
| 4119 | + std::vector<v8::Global<v8::Object>> out; | ||
| 4120 | + heap_profiler->QueryObjects(context, &predicate, &out); | ||
| 4121 | + CHECK_GE(out.size(), 10); | ||
| 4122 | + } | ||
| 4123 | + } | ||
| 4124 | + | ||
| 4063 | 4125 | TEST(WeakReference) { | |
| 4064 | 4126 | v8::Isolate* isolate = CcTest::isolate(); | |
| 4065 | 4127 | i::Isolate* i_isolate = CcTest::i_isolate(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments