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