| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 481a901 commit b982335
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | 37 | # Reset this number to 0 on major V8 upgrades. | |
| 38 | 38 | # Increment by one for each non-official patch applied to deps/v8. | |
| 39 | - 'v8_embedder_string': '-node.10', | ||
| 39 | + 'v8_embedder_string': '-node.11', | ||
| 40 | 40 | ||
| 41 | 41 | ##### V8 defaults for Node.js ##### | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -921,12 +921,22 @@ class V8_EXPORT EmbedderGraph { | |||
| 921 | 921 | virtual ~EmbedderGraph() = default; | |
| 922 | 922 | }; | |
| 923 | 923 | ||
| 924 | + class QueryObjectPredicate { | ||
| 925 | + public: | ||
| 926 | + virtual ~QueryObjectPredicate() = default; | ||
| 927 | + virtual bool Filter(v8::Local<v8::Object> object) = 0; | ||
| 928 | + }; | ||
| 929 | + | ||
| 924 | 930 | /** | |
| 925 | 931 | * Interface for controlling heap profiling. Instance of the | |
| 926 | 932 | * profiler can be retrieved using v8::Isolate::GetHeapProfiler. | |
| 927 | 933 | */ | |
| 928 | 934 | class V8_EXPORT HeapProfiler { | |
| 929 | 935 | public: | |
| 936 | + void QueryObjects(v8::Local<v8::Context> context, | ||
| 937 | + QueryObjectPredicate* predicate, | ||
| 938 | + std::vector<v8::Global<v8::Object>>* objects); | ||
| 939 | + | ||
| 930 | 940 | enum SamplingFlags { | |
| 931 | 941 | kSamplingNoFlags = 0, | |
| 932 | 942 | kSamplingForceGC = 1 << 0, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11134,6 +11134,16 @@ int HeapProfiler::GetSnapshotCount() { | |||
| 11134 | 11134 | return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount(); | |
| 11135 | 11135 | } | |
| 11136 | 11136 | ||
| 11137 | + void HeapProfiler::QueryObjects(Local<Context> v8_context, | ||
| 11138 | + QueryObjectPredicate* predicate, | ||
| 11139 | + std::vector<Global<Object>>* objects) { | ||
| 11140 | + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_context->GetIsolate()); | ||
| 11141 | + i::HeapProfiler* profiler = reinterpret_cast<i::HeapProfiler*>(this); | ||
| 11142 | + DCHECK_EQ(isolate, profiler->isolate()); | ||
| 11143 | + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | ||
| 11144 | + profiler->QueryObjects(Utils::OpenHandle(*v8_context), predicate, objects); | ||
| 11145 | + } | ||
| 11146 | + | ||
| 11137 | 11147 | const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) { | |
| 11138 | 11148 | return reinterpret_cast<const HeapSnapshot*>( | |
| 11139 | 11149 | reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1211,15 +1211,6 @@ v8::MaybeLocal<v8::Value> EvaluateGlobalForTesting( | |||
| 1211 | 1211 | RETURN_ESCAPED(result); | |
| 1212 | 1212 | } | |
| 1213 | 1213 | ||
| 1214 | - void QueryObjects(v8::Local<v8::Context> v8_context, | ||
| 1215 | - QueryObjectPredicate* predicate, | ||
| 1216 | - std::vector<v8::Global<v8::Object>>* objects) { | ||
| 1217 | - i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_context->GetIsolate()); | ||
| 1218 | - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | ||
| 1219 | - isolate->heap_profiler()->QueryObjects(Utils::OpenHandle(*v8_context), | ||
| 1220 | - predicate, objects); | ||
| 1221 | - } | ||
| 1222 | - | ||
| 1223 | 1214 | void GlobalLexicalScopeNames(v8::Local<v8::Context> v8_context, | |
| 1224 | 1215 | std::vector<v8::Global<v8::String>>* names) { | |
| 1225 | 1216 | i::Handle<i::Context> context = Utils::OpenHandle(*v8_context); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -530,16 +530,6 @@ class V8_EXPORT_PRIVATE StackTraceIterator { | |||
| 530 | 530 | bool throw_on_side_effect) = 0; | |
| 531 | 531 | }; | |
| 532 | 532 | ||
| 533 | - class QueryObjectPredicate { | ||
| 534 | - public: | ||
| 535 | - virtual ~QueryObjectPredicate() = default; | ||
| 536 | - virtual bool Filter(v8::Local<v8::Object> object) = 0; | ||
| 537 | - }; | ||
| 538 | - | ||
| 539 | - void QueryObjects(v8::Local<v8::Context> context, | ||
| 540 | - QueryObjectPredicate* predicate, | ||
| 541 | - std::vector<v8::Global<v8::Object>>* objects); | ||
| 542 | - | ||
| 543 | 533 | void GlobalLexicalScopeNames(v8::Local<v8::Context> context, | |
| 544 | 534 | std::vector<v8::Global<v8::String>>* names); | |
| 545 | 535 | ||
| 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" | |
@@ -38,7 +39,7 @@ void cleanupExpiredWeakPointers(Map& map) { | |||
| 38 | 39 | } | |
| 39 | 40 | } | |
| 40 | 41 | ||
| 41 | - class MatchPrototypePredicate : public v8::debug::QueryObjectPredicate { | ||
| 42 | + class MatchPrototypePredicate : public v8::QueryObjectPredicate { | ||
| 42 | 43 | public: | |
| 43 | 44 | MatchPrototypePredicate(V8InspectorImpl* inspector, | |
| 44 | 45 | v8::Local<v8::Context> context, | |
@@ -994,7 +995,7 @@ v8::Local<v8::Array> V8Debugger::queryObjects(v8::Local<v8::Context> context, | |||
| 994 | 995 | v8::Isolate* isolate = context->GetIsolate(); | |
| 995 | 996 | std::vector<v8::Global<v8::Object>> v8_objects; | |
| 996 | 997 | MatchPrototypePredicate predicate(m_inspector, context, prototype); | |
| 997 | - v8::debug::QueryObjects(context, &predicate, &v8_objects); | ||
| 998 | + isolate->GetHeapProfiler()->QueryObjects(context, &predicate, &v8_objects); | ||
| 998 | 999 | ||
| 999 | 1000 | v8::MicrotasksScope microtasksScope(context, | |
| 1000 | 1001 | v8::MicrotasksScope::kDoNotRunMicrotasks); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -283,7 +283,7 @@ Heap* HeapProfiler::heap() const { return ids_->heap(); } | |||
| 283 | 283 | Isolate* HeapProfiler::isolate() const { return heap()->isolate(); } | |
| 284 | 284 | ||
| 285 | 285 | void HeapProfiler::QueryObjects(Handle<Context> context, | |
| 286 | - debug::QueryObjectPredicate* predicate, | ||
| 286 | + v8::QueryObjectPredicate* predicate, | ||
| 287 | 287 | std::vector<v8::Global<v8::Object>>* objects) { | |
| 288 | 288 | // We need a stack marker here to allow deterministic passes over the stack. | |
| 289 | 289 | // The garbage collection and the two object heap iterators should scan the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,7 @@ class StringsStorage; | |||
| 30 | 30 | // generate consistent IDs for moved objects. | |
| 31 | 31 | class HeapProfilerNativeMoveListener { | |
| 32 | 32 | public: | |
| 33 | - HeapProfilerNativeMoveListener(HeapProfiler* profiler) | ||
| 33 | + explicit HeapProfilerNativeMoveListener(HeapProfiler* profiler) | ||
| 34 | 34 | : profiler_(profiler) {} | |
| 35 | 35 | HeapProfilerNativeMoveListener(const HeapProfilerNativeMoveListener& other) = | |
| 36 | 36 | delete; | |
@@ -119,8 +119,7 @@ class HeapProfiler : public HeapObjectAllocationTracker { | |||
| 119 | 119 | ||
| 120 | 120 | Isolate* isolate() const; | |
| 121 | 121 | ||
| 122 | - void QueryObjects(Handle<Context> context, | ||
| 123 | - debug::QueryObjectPredicate* predicate, | ||
| 122 | + void QueryObjects(Handle<Context> context, QueryObjectPredicate* predicate, | ||
| 124 | 123 | std::vector<v8::Global<v8::Object>>* objects); | |
| 125 | 124 | void set_native_move_listener( | |
| 126 | 125 | std::unique_ptr<HeapProfilerNativeMoveListener> listener) { | |
| 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" | |
@@ -4068,6 +4069,67 @@ TEST(SamplingHeapProfilerSampleDuringDeopt) { | |||
| 4068 | 4069 | heap_profiler->StopSamplingHeapProfiler(); | |
| 4069 | 4070 | } | |
| 4070 | 4071 | ||
| 4072 | + namespace { | ||
| 4073 | + class TestQueryObjectPredicate : public v8::QueryObjectPredicate { | ||
| 4074 | + public: | ||
| 4075 | + TestQueryObjectPredicate(v8::Local<v8::Context> context, | ||
| 4076 | + v8::Local<v8::Symbol> symbol) | ||
| 4077 | + : context_(context), symbol_(symbol) {} | ||
| 4078 | + | ||
| 4079 | + bool Filter(v8::Local<v8::Object> object) override { | ||
| 4080 | + return object->HasOwnProperty(context_, symbol_).FromMaybe(false); | ||
| 4081 | + } | ||
| 4082 | + | ||
| 4083 | + private: | ||
| 4084 | + v8::Local<v8::Context> context_; | ||
| 4085 | + v8::Local<v8::Symbol> symbol_; | ||
| 4086 | + }; | ||
| 4087 | + | ||
| 4088 | + class IncludeAllQueryObjectPredicate : public v8::QueryObjectPredicate { | ||
| 4089 | + public: | ||
| 4090 | + IncludeAllQueryObjectPredicate() {} | ||
| 4091 | + bool Filter(v8::Local<v8::Object> object) override { return true; } | ||
| 4092 | + }; | ||
| 4093 | + } // anonymous namespace | ||
| 4094 | + | ||
| 4095 | + TEST(QueryObjects) { | ||
| 4096 | + LocalContext env; | ||
| 4097 | + v8::Isolate* isolate = env->GetIsolate(); | ||
| 4098 | + v8::HandleScope scope(isolate); | ||
| 4099 | + v8::Local<v8::Context> context = env.local(); | ||
| 4100 | + | ||
| 4101 | + v8::Local<v8::Symbol> sym = | ||
| 4102 | + v8::Symbol::New(isolate, v8_str("query_object_test")); | ||
| 4103 | + context->Global()->Set(context, v8_str("test_symbol"), sym).Check(); | ||
| 4104 | + v8::Local<v8::Value> arr = CompileRun(R"( | ||
| 4105 | + const arr = []; | ||
| 4106 | + for (let i = 0; i < 10; ++i) { | ||
| 4107 | + arr.push({[test_symbol]: true}); | ||
| 4108 | + } | ||
| 4109 | + arr; | ||
| 4110 | + )"); | ||
| 4111 | + context->Global()->Set(context, v8_str("arr"), arr).Check(); | ||
| 4112 | + v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | ||
| 4113 | + | ||
| 4114 | + { | ||
| 4115 | + TestQueryObjectPredicate predicate(context, sym); | ||
| 4116 | + std::vector<v8::Global<v8::Object>> out; | ||
| 4117 | + heap_profiler->QueryObjects(context, &predicate, &out); | ||
| 4118 | + | ||
| 4119 | + CHECK_EQ(out.size(), 10); | ||
| 4120 | + for (size_t i = 0; i < out.size(); ++i) { | ||
| 4121 | + CHECK(out[i].Get(isolate)->HasOwnProperty(context, sym).FromMaybe(false)); | ||
| 4122 | + } | ||
| 4123 | + } | ||
| 4124 | + | ||
| 4125 | + { | ||
| 4126 | + IncludeAllQueryObjectPredicate predicate; | ||
| 4127 | + std::vector<v8::Global<v8::Object>> out; | ||
| 4128 | + heap_profiler->QueryObjects(context, &predicate, &out); | ||
| 4129 | + CHECK_GE(out.size(), 10); | ||
| 4130 | + } | ||
| 4131 | + } | ||
| 4132 | + | ||
| 4071 | 4133 | TEST(WeakReference) { | |
| 4072 | 4134 | v8::Isolate* isolate = CcTest::isolate(); | |
| 4073 | 4135 | i::Isolate* i_isolate = CcTest::i_isolate(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments