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 "cppgc/macros.h"
13#include "v8-local-handle.h" // NOLINT(build/include_directory)
14#include "v8-microtask.h" // NOLINT(build/include_directory)
15#include "v8config.h" // NOLINT(build/include_directory)
16
17#ifdef V8_CPPGC_MICROTASK_QUEUE
19#include "cppgc/name-provider.h"
20#endif // V8_CPPGC_MICROTASK_QUEUE
21
22namespace v8 {
23
24class Function;
25
26namespace internal {
27class Isolate;
28class MicrotaskQueue;
29} // namespace internal
30
47#ifdef V8_CPPGC_MICROTASK_QUEUE
48 : public cppgc::GarbageCollected<MicrotaskQueue>,
50#else
51#error "Non-CppGC MicrotaskQueue definition is not supported."
52#endif // V8_CPPGC_MICROTASK_QUEUE
53{
54 public:
58#ifdef V8_CPPGC_MICROTASK_QUEUE
59 static MicrotaskQueue* New(Isolate* isolate,
60 MicrotasksPolicy policy = MicrotasksPolicy::kAuto);
61 virtual void Trace(cppgc::Visitor* visitor) const {}
62#endif // V8_CPPGC_MICROTASK_QUEUE
63
64 virtual ~MicrotaskQueue() = default;
65
69 virtual void EnqueueMicrotask(Isolate* isolate,
70 Local<Function> microtask) = 0;
71
72 V8_DEPRECATE_SOON("Use the MicrotaskCallbackWithData overload instead")
73 virtual void EnqueueMicrotask(v8::Isolate* isolate,
74 MicrotaskCallback callback,
75 void* data = nullptr) = 0;
79 virtual void EnqueueMicrotask(v8::Isolate* isolate,
81 v8::Local<v8::Data> data) = 0;
82
95 virtual void AddMicrotasksCompletedCallback(
96 MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
97
101 virtual void RemoveMicrotasksCompletedCallback(
102 MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
103
107 virtual void PerformCheckpoint(Isolate* isolate) = 0;
108
112 virtual bool IsRunningMicrotasks() const = 0;
113
118 virtual int GetMicrotasksScopeDepth() const = 0;
119
121 MicrotaskQueue& operator=(const MicrotaskQueue&) = delete;
122
123 private:
124 friend class internal::MicrotaskQueue;
125 MicrotaskQueue() = default;
126};
127
139
140 public:
141 enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
142
144 MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type);
146
150 static void PerformCheckpoint(Isolate* isolate);
151
155 static int GetCurrentDepth(Isolate* isolate);
156
160 static bool IsRunningMicrotasks(Isolate* isolate);
161
162 // Prevent copying.
165
166 private:
167 internal::Isolate* const i_isolate_;
168 internal::MicrotaskQueue* const microtask_queue_;
169 bool run_;
170};
171
172} // namespace v8
173
174#endif // INCLUDE_V8_MICROTASKS_QUEUE_H_
Definition: garbage-collected.h:53
Definition: name-provider.h:26
Definition: visitor.h:78
Definition: v8-data.h:18
Definition: v8-isolate.h:292
Definition: v8-local-handle.h:366
Definition: v8-microtask-queue.h:53
virtual void EnqueueMicrotask(Isolate *isolate, Local< Function > microtask)=0
virtual ~MicrotaskQueue()=default
Definition: v8-microtask-queue.h:137
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:141
static int GetCurrentDepth(Isolate *isolate)
static bool IsRunningMicrotasks(Isolate *isolate)
#define CPPGC_STACK_ALLOCATED()
Definition: macros.h:44
Definition: libplatform.h:15
void(*)(void *data) MicrotaskCallback
Definition: v8-microtask.h:17
MicrotasksPolicy
Definition: v8-microtask.h:28
void(*)(Isolate *, void *) MicrotasksCompletedCallbackWithData
Definition: v8-microtask.h:16
void(*)(Local< Data > data) MicrotaskCallbackWithData
Definition: v8-microtask.h:18
#define V8_EXPORT
Definition: v8config.h:867
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:624
#define V8_NODISCARD
Definition: v8config.h:703