Skip to content

Instantly share code, notes, and snippets.

@hajimehoshi
Created August 2, 2018 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hajimehoshi/fb2de3d2f223df8ac440a183a3c67806 to your computer and use it in GitHub Desktop.
Save hajimehoshi/fb2de3d2f223df8ac440a183a3c67806 to your computer and use it in GitHub Desktop.
diff --git a/include/v8.h b/include/v8.h
index 3275d97c43..5d44b30a89 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -21,6 +21,7 @@
#include <memory>
#include <utility>
#include <vector>
+#include <functional>
#include "v8-version.h" // NOLINT(build/include)
#include "v8config.h" // NOLINT(build/include)
@@ -10851,8 +10852,10 @@ size_t SnapshotCreator::AddData(Local<T> object) {
*/
-} // namespace v8
+V8_EXPORT void RegisterNotifyV8UsageFunc(std::function<void()> func);
+V8_EXPORT void NotifyV8Usage();
+} // namespace v8
#undef TYPE_CHECK
diff --git a/src/api.cc b/src/api.cc
index 2e8a848361..13f9576fd1 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -160,6 +160,7 @@ namespace v8 {
#define ENTER_V8(isolate, context, class_name, function_name, bailout_value, \
HandleScopeClass) \
+ NotifyV8Usage(); \
ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \
bailout_value, HandleScopeClass, true)
@@ -11025,4 +11026,5 @@ void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
#undef CALLBACK_SETTER
} // namespace internal
+
} // namespace v8
diff --git a/src/v8.cc b/src/v8.cc
index 69780aac55..57af289bb0 100644
--- a/src/v8.cc
+++ b/src/v8.cc
@@ -146,4 +146,16 @@ void V8::SetSnapshotBlob(StartupData* snapshot_blob) {
double Platform::SystemClockTimeMillis() {
return base::OS::TimeCurrentMillis();
}
+
+static std::function<void()> g_notify_v8_usage_func;
+
+void RegisterNotifyV8UsageFunc(std::function<void()> func) {
+ g_notify_v8_usage_func = func;
+}
+
+void NotifyV8Usage() {
+ if (g_notify_v8_usage_func)
+ g_notify_v8_usage_func();
+}
+
} // namespace v8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment