File indexing completed on 2025-02-21 10:05:25
0001
0002
0003
0004
0005 #ifndef INCLUDE_V8_MICROTASKS_QUEUE_H_
0006 #define INCLUDE_V8_MICROTASKS_QUEUE_H_
0007
0008 #include <stddef.h>
0009
0010 #include <memory>
0011
0012 #include "v8-local-handle.h" // NOLINT(build/include_directory)
0013 #include "v8-microtask.h" // NOLINT(build/include_directory)
0014 #include "v8config.h" // NOLINT(build/include_directory)
0015
0016 namespace v8 {
0017
0018 class Function;
0019
0020 namespace internal {
0021 class Isolate;
0022 class MicrotaskQueue;
0023 }
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 class V8_EXPORT MicrotaskQueue {
0041 public:
0042
0043
0044
0045 static std::unique_ptr<MicrotaskQueue> New(
0046 Isolate* isolate, MicrotasksPolicy policy = MicrotasksPolicy::kAuto);
0047
0048 virtual ~MicrotaskQueue() = default;
0049
0050
0051
0052
0053 virtual void EnqueueMicrotask(Isolate* isolate,
0054 Local<Function> microtask) = 0;
0055
0056
0057
0058
0059 virtual void EnqueueMicrotask(v8::Isolate* isolate,
0060 MicrotaskCallback callback,
0061 void* data = nullptr) = 0;
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 virtual void AddMicrotasksCompletedCallback(
0076 MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
0077
0078
0079
0080
0081 virtual void RemoveMicrotasksCompletedCallback(
0082 MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
0083
0084
0085
0086
0087 virtual void PerformCheckpoint(Isolate* isolate) = 0;
0088
0089
0090
0091
0092 virtual bool IsRunningMicrotasks() const = 0;
0093
0094
0095
0096
0097
0098 virtual int GetMicrotasksScopeDepth() const = 0;
0099
0100 MicrotaskQueue(const MicrotaskQueue&) = delete;
0101 MicrotaskQueue& operator=(const MicrotaskQueue&) = delete;
0102
0103 private:
0104 friend class internal::MicrotaskQueue;
0105 MicrotaskQueue() = default;
0106 };
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 class V8_EXPORT V8_NODISCARD MicrotasksScope {
0118 public:
0119 enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
0120
0121 V8_DEPRECATE_SOON(
0122 "May be incorrect if context was created with non-default microtask "
0123 "queue")
0124 MicrotasksScope(Isolate* isolate, Type type);
0125
0126 MicrotasksScope(Local<Context> context, Type type);
0127 MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type);
0128 ~MicrotasksScope();
0129
0130
0131
0132
0133 static void PerformCheckpoint(Isolate* isolate);
0134
0135
0136
0137
0138 static int GetCurrentDepth(Isolate* isolate);
0139
0140
0141
0142
0143 static bool IsRunningMicrotasks(Isolate* isolate);
0144
0145
0146 MicrotasksScope(const MicrotasksScope&) = delete;
0147 MicrotasksScope& operator=(const MicrotasksScope&) = delete;
0148
0149 private:
0150 internal::Isolate* const i_isolate_;
0151 internal::MicrotaskQueue* const microtask_queue_;
0152 bool run_;
0153 };
0154
0155 }
0156
0157 #endif