Commit 7895b396 authored by jochen's avatar jochen Committed by Commit bot

[api] Introduce MicrotasksScope::IsRunningMicrotasks

Returns true while V8 executes microtasks

BUG=
R=verwaest@chromium.org

Review URL: https://codereview.chromium.org/1920813002

Cr-Commit-Position: refs/heads/master@{#35769}
parent 4e8736da
...@@ -5140,6 +5140,11 @@ class V8_EXPORT MicrotasksScope { ...@@ -5140,6 +5140,11 @@ class V8_EXPORT MicrotasksScope {
*/ */
static int GetCurrentDepth(Isolate* isolate); static int GetCurrentDepth(Isolate* isolate);
/**
* Returns true while microtasks are being executed.
*/
static bool IsRunningMicrotasks(Isolate* isolate);
private: private:
internal::Isolate* const isolate_; internal::Isolate* const isolate_;
bool run_; bool run_;
......
...@@ -7913,6 +7913,10 @@ int MicrotasksScope::GetCurrentDepth(Isolate* v8Isolate) { ...@@ -7913,6 +7913,10 @@ int MicrotasksScope::GetCurrentDepth(Isolate* v8Isolate) {
return isolate->handle_scope_implementer()->GetMicrotasksScopeDepth(); return isolate->handle_scope_implementer()->GetMicrotasksScopeDepth();
} }
bool MicrotasksScope::IsRunningMicrotasks(Isolate* v8Isolate) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8Isolate);
return isolate->IsRunningMicrotasks();
}
String::Utf8Value::Utf8Value(v8::Local<v8::Value> obj) String::Utf8Value::Utf8Value(v8::Local<v8::Value> obj)
: str_(NULL), length_(0) { : str_(NULL), length_(0) {
......
...@@ -1858,6 +1858,7 @@ Isolate::Isolate(bool enable_serializer) ...@@ -1858,6 +1858,7 @@ Isolate::Isolate(bool enable_serializer)
#if TRACE_MAPS #if TRACE_MAPS
next_unique_sfi_id_(0), next_unique_sfi_id_(0),
#endif #endif
is_running_microtasks_(false),
use_counter_callback_(NULL), use_counter_callback_(NULL),
basic_block_profiler_(NULL), basic_block_profiler_(NULL),
cancelable_task_manager_(new CancelableTaskManager()), cancelable_task_manager_(new CancelableTaskManager()),
...@@ -2780,7 +2781,9 @@ void Isolate::RunMicrotasks() { ...@@ -2780,7 +2781,9 @@ void Isolate::RunMicrotasks() {
// Increase call depth to prevent recursive callbacks. // Increase call depth to prevent recursive callbacks.
v8::Isolate::SuppressMicrotaskExecutionScope suppress( v8::Isolate::SuppressMicrotaskExecutionScope suppress(
reinterpret_cast<v8::Isolate*>(this)); reinterpret_cast<v8::Isolate*>(this));
is_running_microtasks_ = true;
RunMicrotasksInternal(); RunMicrotasksInternal();
is_running_microtasks_ = false;
FireMicrotasksCompletedCallback(); FireMicrotasksCompletedCallback();
} }
......
...@@ -1064,6 +1064,7 @@ class Isolate { ...@@ -1064,6 +1064,7 @@ class Isolate {
void EnqueueMicrotask(Handle<Object> microtask); void EnqueueMicrotask(Handle<Object> microtask);
void RunMicrotasks(); void RunMicrotasks();
bool IsRunningMicrotasks() const { return is_running_microtasks_; }
void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback); void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
void CountUsage(v8::Isolate::UseCounterFeature feature); void CountUsage(v8::Isolate::UseCounterFeature feature);
...@@ -1343,6 +1344,7 @@ class Isolate { ...@@ -1343,6 +1344,7 @@ class Isolate {
// List of callbacks after microtasks were run. // List of callbacks after microtasks were run.
List<MicrotasksCompletedCallback> microtasks_completed_callbacks_; List<MicrotasksCompletedCallback> microtasks_completed_callbacks_;
bool is_running_microtasks_;
v8::Isolate::UseCounterCallback use_counter_callback_; v8::Isolate::UseCounterCallback use_counter_callback_;
BasicBlockProfiler* basic_block_profiler_; BasicBlockProfiler* basic_block_profiler_;
......
...@@ -20885,6 +20885,7 @@ TEST(CallCompletedCallbackTwoExceptions) { ...@@ -20885,6 +20885,7 @@ TEST(CallCompletedCallbackTwoExceptions) {
static void MicrotaskOne(const v8::FunctionCallbackInfo<Value>& info) { static void MicrotaskOne(const v8::FunctionCallbackInfo<Value>& info) {
CHECK(v8::MicrotasksScope::IsRunningMicrotasks(info.GetIsolate()));
v8::HandleScope scope(info.GetIsolate()); v8::HandleScope scope(info.GetIsolate());
v8::MicrotasksScope microtasks(info.GetIsolate(), v8::MicrotasksScope microtasks(info.GetIsolate(),
v8::MicrotasksScope::kDoNotRunMicrotasks); v8::MicrotasksScope::kDoNotRunMicrotasks);
...@@ -20893,6 +20894,7 @@ static void MicrotaskOne(const v8::FunctionCallbackInfo<Value>& info) { ...@@ -20893,6 +20894,7 @@ static void MicrotaskOne(const v8::FunctionCallbackInfo<Value>& info) {
static void MicrotaskTwo(const v8::FunctionCallbackInfo<Value>& info) { static void MicrotaskTwo(const v8::FunctionCallbackInfo<Value>& info) {
CHECK(v8::MicrotasksScope::IsRunningMicrotasks(info.GetIsolate()));
v8::HandleScope scope(info.GetIsolate()); v8::HandleScope scope(info.GetIsolate());
v8::MicrotasksScope microtasks(info.GetIsolate(), v8::MicrotasksScope microtasks(info.GetIsolate(),
v8::MicrotasksScope::kDoNotRunMicrotasks); v8::MicrotasksScope::kDoNotRunMicrotasks);
...@@ -20911,6 +20913,7 @@ static void MicrotaskThree(void* data) { ...@@ -20911,6 +20913,7 @@ static void MicrotaskThree(void* data) {
TEST(EnqueueMicrotask) { TEST(EnqueueMicrotask) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
CHECK(!v8::MicrotasksScope::IsRunningMicrotasks(env->GetIsolate()));
CompileRun( CompileRun(
"var ext1Calls = 0;" "var ext1Calls = 0;"
"var ext2Calls = 0;"); "var ext2Calls = 0;");
......
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