Loading...
Searching...
No Matches
v8-microtask-queue.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_MICROTASKS_QUEUE_H_
6#define INCLUDE_V8_MICROTASKS_QUEUE_H_
7
8#include <stddef.h>
9
10#include <memory>
11
12#include "v8-local-handle.h" // NOLINT(build/include_directory)
13#include "v8-microtask.h" // NOLINT(build/include_directory)
14#include "v8config.h" // NOLINT(build/include_directory)
15
16namespace v8 {
17
18class Function;
19
20namespace internal {
21class Isolate;
22class MicrotaskQueue;
23} // namespace internal
24
41 public:
45 static std::unique_ptr<MicrotaskQueue> New(
46 Isolate* isolate, MicrotasksPolicy policy = MicrotasksPolicy::kAuto);
47
48 virtual ~MicrotaskQueue() = default;
49
53 virtual void EnqueueMicrotask(Isolate* isolate,
54 Local<Function> microtask) = 0;
55
59 virtual void EnqueueMicrotask(v8::Isolate* isolate,
60 MicrotaskCallback callback,
61 void* data = nullptr) = 0;
62
76 MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
77
82 MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
83
87 virtual void PerformCheckpoint(Isolate* isolate) = 0;
88
92 virtual bool IsRunningMicrotasks() const = 0;
93
98 virtual int GetMicrotasksScopeDepth() const = 0;
99
102
103 private:
104 friend class internal::MicrotaskQueue;
105 MicrotaskQueue() = default;
106};
107
118 public:
119 enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
120
122 MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type);
124
128 static void PerformCheckpoint(Isolate* isolate);
129
133 static int GetCurrentDepth(Isolate* isolate);
134
138 static bool IsRunningMicrotasks(Isolate* isolate);
139
140 // Prevent copying.
143
144 private:
145 internal::Isolate* const i_isolate_;
146 internal::MicrotaskQueue* const microtask_queue_;
147 bool run_;
148};
149
150} // namespace v8
151
152#endif // INCLUDE_V8_MICROTASKS_QUEUE_H_
Definition: v8-isolate.h:261
Definition: v8-local-handle.h:266
Definition: v8-microtask-queue.h:40
virtual bool IsRunningMicrotasks() const =0
virtual void EnqueueMicrotask(Isolate *isolate, Local< Function > microtask)=0
virtual void AddMicrotasksCompletedCallback(MicrotasksCompletedCallbackWithData callback, void *data=nullptr)=0
virtual void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallbackWithData callback, void *data=nullptr)=0
virtual void PerformCheckpoint(Isolate *isolate)=0
virtual int GetMicrotasksScopeDepth() const =0
static std::unique_ptr< MicrotaskQueue > New(Isolate *isolate, MicrotasksPolicy policy=MicrotasksPolicy::kAuto)
MicrotaskQueue(const MicrotaskQueue &)=delete
virtual void EnqueueMicrotask(v8::Isolate *isolate, MicrotaskCallback callback, void *data=nullptr)=0
MicrotaskQueue & operator=(const MicrotaskQueue &)=delete
virtual ~MicrotaskQueue()=default
Definition: v8-microtask-queue.h:117
MicrotasksScope & operator=(const MicrotasksScope &)=delete
static void PerformCheckpoint(Isolate *isolate)
MicrotasksScope(Isolate *isolate, MicrotaskQueue *microtask_queue, Type type)
MicrotasksScope(Local< Context > context, Type type)
MicrotasksScope(const MicrotasksScope &)=delete
Type
Definition: v8-microtask-queue.h:119
static int GetCurrentDepth(Isolate *isolate)
static bool IsRunningMicrotasks(Isolate *isolate)
Definition: libplatform.h:15
void(*)(void *data) MicrotaskCallback
Definition: v8-microtask.h:14
MicrotasksPolicy
Definition: v8-microtask.h:24
void(*)(Isolate *, void *) MicrotasksCompletedCallbackWithData
Definition: v8-microtask.h:13
#define V8_EXPORT
Definition: v8config.h:793
#define V8_NODISCARD
Definition: v8config.h:682