libv8-node 16.20.0.0-aarch64-linux → 17.9.1.0-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8-node/location.rb +1 -1
  3. data/ext/libv8-node/paths.rb +1 -1
  4. data/lib/libv8/node/version.rb +3 -3
  5. data/vendor/v8/aarch64-linux/libv8/obj/libv8_monolith.a +0 -0
  6. data/vendor/v8/include/cppgc/allocation.h +11 -5
  7. data/vendor/v8/include/cppgc/cross-thread-persistent.h +78 -26
  8. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +2 -2
  9. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +2 -0
  10. data/vendor/v8/include/cppgc/internal/gc-info.h +90 -10
  11. data/vendor/v8/include/cppgc/internal/name-trait.h +11 -0
  12. data/vendor/v8/include/cppgc/internal/persistent-node.h +44 -12
  13. data/vendor/v8/include/cppgc/internal/pointer-policies.h +22 -11
  14. data/vendor/v8/include/cppgc/internal/write-barrier.h +9 -1
  15. data/vendor/v8/include/cppgc/persistent.h +1 -1
  16. data/vendor/v8/include/cppgc/prefinalizer.h +1 -1
  17. data/vendor/v8/include/v8-array-buffer.h +433 -0
  18. data/vendor/v8/include/v8-callbacks.h +377 -0
  19. data/vendor/v8/include/v8-container.h +129 -0
  20. data/vendor/v8/include/v8-context.h +418 -0
  21. data/vendor/v8/include/v8-cppgc.h +5 -2
  22. data/vendor/v8/include/v8-data.h +65 -0
  23. data/vendor/v8/include/v8-date.h +43 -0
  24. data/vendor/v8/include/v8-debug.h +151 -0
  25. data/vendor/v8/include/v8-embedder-heap.h +238 -0
  26. data/vendor/v8/include/v8-exception.h +224 -0
  27. data/vendor/v8/include/v8-extension.h +62 -0
  28. data/vendor/v8/include/v8-external.h +37 -0
  29. data/vendor/v8/include/v8-fast-api-calls.h +63 -11
  30. data/vendor/v8/include/v8-forward.h +81 -0
  31. data/vendor/v8/include/v8-function-callback.h +475 -0
  32. data/vendor/v8/include/v8-function.h +122 -0
  33. data/vendor/v8/include/v8-initialization.h +282 -0
  34. data/vendor/v8/include/v8-inspector.h +11 -21
  35. data/vendor/v8/include/v8-internal.h +85 -22
  36. data/vendor/v8/include/v8-isolate.h +1662 -0
  37. data/vendor/v8/include/v8-json.h +47 -0
  38. data/vendor/v8/include/v8-local-handle.h +459 -0
  39. data/vendor/v8/include/v8-locker.h +148 -0
  40. data/vendor/v8/include/v8-maybe.h +137 -0
  41. data/vendor/v8/include/v8-memory-span.h +43 -0
  42. data/vendor/v8/include/v8-message.h +241 -0
  43. data/vendor/v8/include/v8-metrics.h +37 -1
  44. data/vendor/v8/include/v8-microtask-queue.h +152 -0
  45. data/vendor/v8/include/v8-microtask.h +28 -0
  46. data/vendor/v8/include/v8-object.h +770 -0
  47. data/vendor/v8/include/v8-persistent-handle.h +590 -0
  48. data/vendor/v8/include/v8-platform.h +41 -17
  49. data/vendor/v8/include/v8-primitive-object.h +118 -0
  50. data/vendor/v8/include/v8-primitive.h +858 -0
  51. data/vendor/v8/include/v8-profiler.h +10 -11
  52. data/vendor/v8/include/v8-promise.h +174 -0
  53. data/vendor/v8/include/v8-proxy.h +50 -0
  54. data/vendor/v8/include/v8-regexp.h +105 -0
  55. data/vendor/v8/include/v8-script.h +771 -0
  56. data/vendor/v8/include/v8-snapshot.h +198 -0
  57. data/vendor/v8/include/v8-statistics.h +215 -0
  58. data/vendor/v8/include/v8-template.h +1052 -0
  59. data/vendor/v8/include/v8-traced-handle.h +605 -0
  60. data/vendor/v8/include/v8-typed-array.h +282 -0
  61. data/vendor/v8/include/v8-unwinder-state.h +4 -3
  62. data/vendor/v8/include/v8-unwinder.h +129 -0
  63. data/vendor/v8/include/v8-util.h +7 -1
  64. data/vendor/v8/include/v8-value-serializer.h +249 -0
  65. data/vendor/v8/include/v8-value.h +526 -0
  66. data/vendor/v8/include/v8-version.h +3 -3
  67. data/vendor/v8/include/v8-wasm.h +245 -0
  68. data/vendor/v8/include/v8-weak-callback-info.h +73 -0
  69. data/vendor/v8/include/v8.h +41 -12604
  70. metadata +47 -5
@@ -0,0 +1,137 @@
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_MAYBE_H_
6
+ #define INCLUDE_V8_MAYBE_H_
7
+
8
+ #include "v8-internal.h" // NOLINT(build/include_directory)
9
+ #include "v8config.h" // NOLINT(build/include_directory)
10
+
11
+ namespace v8 {
12
+
13
+ namespace api_internal {
14
+ // Called when ToChecked is called on an empty Maybe.
15
+ V8_EXPORT void FromJustIsNothing();
16
+ } // namespace api_internal
17
+
18
+ /**
19
+ * A simple Maybe type, representing an object which may or may not have a
20
+ * value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html.
21
+ *
22
+ * If an API method returns a Maybe<>, the API method can potentially fail
23
+ * either because an exception is thrown, or because an exception is pending,
24
+ * e.g. because a previous API call threw an exception that hasn't been caught
25
+ * yet, or because a TerminateExecution exception was thrown. In that case, a
26
+ * "Nothing" value is returned.
27
+ */
28
+ template <class T>
29
+ class Maybe {
30
+ public:
31
+ V8_INLINE bool IsNothing() const { return !has_value_; }
32
+ V8_INLINE bool IsJust() const { return has_value_; }
33
+
34
+ /**
35
+ * An alias for |FromJust|. Will crash if the Maybe<> is nothing.
36
+ */
37
+ V8_INLINE T ToChecked() const { return FromJust(); }
38
+
39
+ /**
40
+ * Short-hand for ToChecked(), which doesn't return a value. To be used, where
41
+ * the actual value of the Maybe is not needed like Object::Set.
42
+ */
43
+ V8_INLINE void Check() const {
44
+ if (V8_UNLIKELY(!IsJust())) api_internal::FromJustIsNothing();
45
+ }
46
+
47
+ /**
48
+ * Converts this Maybe<> to a value of type T. If this Maybe<> is
49
+ * nothing (empty), |false| is returned and |out| is left untouched.
50
+ */
51
+ V8_WARN_UNUSED_RESULT V8_INLINE bool To(T* out) const {
52
+ if (V8_LIKELY(IsJust())) *out = value_;
53
+ return IsJust();
54
+ }
55
+
56
+ /**
57
+ * Converts this Maybe<> to a value of type T. If this Maybe<> is
58
+ * nothing (empty), V8 will crash the process.
59
+ */
60
+ V8_INLINE T FromJust() const {
61
+ if (V8_UNLIKELY(!IsJust())) api_internal::FromJustIsNothing();
62
+ return value_;
63
+ }
64
+
65
+ /**
66
+ * Converts this Maybe<> to a value of type T, using a default value if this
67
+ * Maybe<> is nothing (empty).
68
+ */
69
+ V8_INLINE T FromMaybe(const T& default_value) const {
70
+ return has_value_ ? value_ : default_value;
71
+ }
72
+
73
+ V8_INLINE bool operator==(const Maybe& other) const {
74
+ return (IsJust() == other.IsJust()) &&
75
+ (!IsJust() || FromJust() == other.FromJust());
76
+ }
77
+
78
+ V8_INLINE bool operator!=(const Maybe& other) const {
79
+ return !operator==(other);
80
+ }
81
+
82
+ private:
83
+ Maybe() : has_value_(false) {}
84
+ explicit Maybe(const T& t) : has_value_(true), value_(t) {}
85
+
86
+ bool has_value_;
87
+ T value_;
88
+
89
+ template <class U>
90
+ friend Maybe<U> Nothing();
91
+ template <class U>
92
+ friend Maybe<U> Just(const U& u);
93
+ };
94
+
95
+ template <class T>
96
+ inline Maybe<T> Nothing() {
97
+ return Maybe<T>();
98
+ }
99
+
100
+ template <class T>
101
+ inline Maybe<T> Just(const T& t) {
102
+ return Maybe<T>(t);
103
+ }
104
+
105
+ // A template specialization of Maybe<T> for the case of T = void.
106
+ template <>
107
+ class Maybe<void> {
108
+ public:
109
+ V8_INLINE bool IsNothing() const { return !is_valid_; }
110
+ V8_INLINE bool IsJust() const { return is_valid_; }
111
+
112
+ V8_INLINE bool operator==(const Maybe& other) const {
113
+ return IsJust() == other.IsJust();
114
+ }
115
+
116
+ V8_INLINE bool operator!=(const Maybe& other) const {
117
+ return !operator==(other);
118
+ }
119
+
120
+ private:
121
+ struct JustTag {};
122
+
123
+ Maybe() : is_valid_(false) {}
124
+ explicit Maybe(JustTag) : is_valid_(true) {}
125
+
126
+ bool is_valid_;
127
+
128
+ template <class U>
129
+ friend Maybe<U> Nothing();
130
+ friend Maybe<void> JustVoid();
131
+ };
132
+
133
+ inline Maybe<void> JustVoid() { return Maybe<void>(Maybe<void>::JustTag()); }
134
+
135
+ } // namespace v8
136
+
137
+ #endif // INCLUDE_V8_MAYBE_H_
@@ -0,0 +1,43 @@
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_MEMORY_SPAN_H_
6
+ #define INCLUDE_V8_MEMORY_SPAN_H_
7
+
8
+ #include <stddef.h>
9
+
10
+ #include "v8config.h" // NOLINT(build/include_directory)
11
+
12
+ namespace v8 {
13
+
14
+ /**
15
+ * Points to an unowned continous buffer holding a known number of elements.
16
+ *
17
+ * This is similar to std::span (under consideration for C++20), but does not
18
+ * require advanced C++ support. In the (far) future, this may be replaced with
19
+ * or aliased to std::span.
20
+ *
21
+ * To facilitate future migration, this class exposes a subset of the interface
22
+ * implemented by std::span.
23
+ */
24
+ template <typename T>
25
+ class V8_EXPORT MemorySpan {
26
+ public:
27
+ /** The default constructor creates an empty span. */
28
+ constexpr MemorySpan() = default;
29
+
30
+ constexpr MemorySpan(T* data, size_t size) : data_(data), size_(size) {}
31
+
32
+ /** Returns a pointer to the beginning of the buffer. */
33
+ constexpr T* data() const { return data_; }
34
+ /** Returns the number of elements that the buffer holds. */
35
+ constexpr size_t size() const { return size_; }
36
+
37
+ private:
38
+ T* data_ = nullptr;
39
+ size_t size_ = 0;
40
+ };
41
+
42
+ } // namespace v8
43
+ #endif // INCLUDE_V8_MEMORY_SPAN_H_
@@ -0,0 +1,241 @@
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_MESSAGE_H_
6
+ #define INCLUDE_V8_MESSAGE_H_
7
+
8
+ #include <stdio.h>
9
+
10
+ #include <iosfwd>
11
+
12
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
13
+ #include "v8-maybe.h" // NOLINT(build/include_directory)
14
+ #include "v8config.h" // NOLINT(build/include_directory)
15
+
16
+ namespace v8 {
17
+
18
+ class Integer;
19
+ class PrimitiveArray;
20
+ class StackTrace;
21
+ class String;
22
+ class Value;
23
+
24
+ /**
25
+ * The optional attributes of ScriptOrigin.
26
+ */
27
+ class ScriptOriginOptions {
28
+ public:
29
+ V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
30
+ bool is_opaque = false, bool is_wasm = false,
31
+ bool is_module = false)
32
+ : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
33
+ (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
34
+ (is_module ? kIsModule : 0)) {}
35
+ V8_INLINE ScriptOriginOptions(int flags)
36
+ : flags_(flags &
37
+ (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
38
+
39
+ bool IsSharedCrossOrigin() const {
40
+ return (flags_ & kIsSharedCrossOrigin) != 0;
41
+ }
42
+ bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
43
+ bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
44
+ bool IsModule() const { return (flags_ & kIsModule) != 0; }
45
+
46
+ int Flags() const { return flags_; }
47
+
48
+ private:
49
+ enum {
50
+ kIsSharedCrossOrigin = 1,
51
+ kIsOpaque = 1 << 1,
52
+ kIsWasm = 1 << 2,
53
+ kIsModule = 1 << 3
54
+ };
55
+ const int flags_;
56
+ };
57
+
58
+ /**
59
+ * The origin, within a file, of a script.
60
+ */
61
+ class V8_EXPORT ScriptOrigin {
62
+ public:
63
+ #if defined(_MSC_VER) && _MSC_VER >= 1910 /* Disable on VS2015 */
64
+ V8_DEPRECATE_SOON("Use constructor with primitive C++ types")
65
+ #endif
66
+ ScriptOrigin(
67
+ Local<Value> resource_name, Local<Integer> resource_line_offset,
68
+ Local<Integer> resource_column_offset,
69
+ Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
70
+ Local<Integer> script_id = Local<Integer>(),
71
+ Local<Value> source_map_url = Local<Value>(),
72
+ Local<Boolean> resource_is_opaque = Local<Boolean>(),
73
+ Local<Boolean> is_wasm = Local<Boolean>(),
74
+ Local<Boolean> is_module = Local<Boolean>(),
75
+ Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
76
+ #if defined(_MSC_VER) && _MSC_VER >= 1910 /* Disable on VS2015 */
77
+ V8_DEPRECATE_SOON("Use constructor that takes an isolate")
78
+ #endif
79
+ explicit ScriptOrigin(
80
+ Local<Value> resource_name, int resource_line_offset = 0,
81
+ int resource_column_offset = 0,
82
+ bool resource_is_shared_cross_origin = false, int script_id = -1,
83
+ Local<Value> source_map_url = Local<Value>(),
84
+ bool resource_is_opaque = false, bool is_wasm = false,
85
+ bool is_module = false,
86
+ Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>());
87
+ V8_INLINE ScriptOrigin(
88
+ Isolate* isolate, Local<Value> resource_name,
89
+ int resource_line_offset = 0, int resource_column_offset = 0,
90
+ bool resource_is_shared_cross_origin = false, int script_id = -1,
91
+ Local<Value> source_map_url = Local<Value>(),
92
+ bool resource_is_opaque = false, bool is_wasm = false,
93
+ bool is_module = false,
94
+ Local<PrimitiveArray> host_defined_options = Local<PrimitiveArray>())
95
+ : isolate_(isolate),
96
+ resource_name_(resource_name),
97
+ resource_line_offset_(resource_line_offset),
98
+ resource_column_offset_(resource_column_offset),
99
+ options_(resource_is_shared_cross_origin, resource_is_opaque, is_wasm,
100
+ is_module),
101
+ script_id_(script_id),
102
+ source_map_url_(source_map_url),
103
+ host_defined_options_(host_defined_options) {}
104
+
105
+ V8_INLINE Local<Value> ResourceName() const;
106
+ V8_DEPRECATE_SOON("Use getter with primitive C++ types.")
107
+ V8_INLINE Local<Integer> ResourceLineOffset() const;
108
+ V8_DEPRECATE_SOON("Use getter with primitive C++ types.")
109
+ V8_INLINE Local<Integer> ResourceColumnOffset() const;
110
+ V8_DEPRECATE_SOON("Use getter with primitive C++ types.")
111
+ V8_INLINE Local<Integer> ScriptID() const;
112
+ V8_INLINE int LineOffset() const;
113
+ V8_INLINE int ColumnOffset() const;
114
+ V8_INLINE int ScriptId() const;
115
+ V8_INLINE Local<Value> SourceMapUrl() const;
116
+ V8_INLINE Local<PrimitiveArray> HostDefinedOptions() const;
117
+ V8_INLINE ScriptOriginOptions Options() const { return options_; }
118
+
119
+ private:
120
+ Isolate* isolate_;
121
+ Local<Value> resource_name_;
122
+ int resource_line_offset_;
123
+ int resource_column_offset_;
124
+ ScriptOriginOptions options_;
125
+ int script_id_;
126
+ Local<Value> source_map_url_;
127
+ Local<PrimitiveArray> host_defined_options_;
128
+ };
129
+
130
+ /**
131
+ * An error message.
132
+ */
133
+ class V8_EXPORT Message {
134
+ public:
135
+ Local<String> Get() const;
136
+
137
+ /**
138
+ * Return the isolate to which the Message belongs.
139
+ */
140
+ Isolate* GetIsolate() const;
141
+
142
+ V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSource(
143
+ Local<Context> context) const;
144
+ V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
145
+ Local<Context> context) const;
146
+
147
+ /**
148
+ * Returns the origin for the script from where the function causing the
149
+ * error originates.
150
+ */
151
+ ScriptOrigin GetScriptOrigin() const;
152
+
153
+ /**
154
+ * Returns the resource name for the script from where the function causing
155
+ * the error originates.
156
+ */
157
+ Local<Value> GetScriptResourceName() const;
158
+
159
+ /**
160
+ * Exception stack trace. By default stack traces are not captured for
161
+ * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
162
+ * to change this option.
163
+ */
164
+ Local<StackTrace> GetStackTrace() const;
165
+
166
+ /**
167
+ * Returns the number, 1-based, of the line where the error occurred.
168
+ */
169
+ V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
170
+
171
+ /**
172
+ * Returns the index within the script of the first character where
173
+ * the error occurred.
174
+ */
175
+ int GetStartPosition() const;
176
+
177
+ /**
178
+ * Returns the index within the script of the last character where
179
+ * the error occurred.
180
+ */
181
+ int GetEndPosition() const;
182
+
183
+ /**
184
+ * Returns the Wasm function index where the error occurred. Returns -1 if
185
+ * message is not from a Wasm script.
186
+ */
187
+ int GetWasmFunctionIndex() const;
188
+
189
+ /**
190
+ * Returns the error level of the message.
191
+ */
192
+ int ErrorLevel() const;
193
+
194
+ /**
195
+ * Returns the index within the line of the first character where
196
+ * the error occurred.
197
+ */
198
+ int GetStartColumn() const;
199
+ V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
200
+
201
+ /**
202
+ * Returns the index within the line of the last character where
203
+ * the error occurred.
204
+ */
205
+ int GetEndColumn() const;
206
+ V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
207
+
208
+ /**
209
+ * Passes on the value set by the embedder when it fed the script from which
210
+ * this Message was generated to V8.
211
+ */
212
+ bool IsSharedCrossOrigin() const;
213
+ bool IsOpaque() const;
214
+
215
+ V8_DEPRECATE_SOON("Use the version that takes a std::ostream&.")
216
+ static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
217
+ static void PrintCurrentStackTrace(Isolate* isolate, std::ostream& out);
218
+
219
+ static const int kNoLineNumberInfo = 0;
220
+ static const int kNoColumnInfo = 0;
221
+ static const int kNoScriptIdInfo = 0;
222
+ static const int kNoWasmFunctionIndexInfo = -1;
223
+ };
224
+
225
+ Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
226
+
227
+ Local<PrimitiveArray> ScriptOrigin::HostDefinedOptions() const {
228
+ return host_defined_options_;
229
+ }
230
+
231
+ int ScriptOrigin::LineOffset() const { return resource_line_offset_; }
232
+
233
+ int ScriptOrigin::ColumnOffset() const { return resource_column_offset_; }
234
+
235
+ int ScriptOrigin::ScriptId() const { return script_id_; }
236
+
237
+ Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
238
+
239
+ } // namespace v8
240
+
241
+ #endif // INCLUDE_V8_MESSAGE_H_
@@ -5,9 +5,19 @@
5
5
  #ifndef V8_METRICS_H_
6
6
  #define V8_METRICS_H_
7
7
 
8
- #include "v8.h" // NOLINT(build/include_directory)
8
+ #include <stddef.h>
9
+ #include <stdint.h>
10
+
11
+ #include <vector>
12
+
13
+ #include "v8-internal.h" // NOLINT(build/include_directory)
14
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
9
15
 
10
16
  namespace v8 {
17
+
18
+ class Context;
19
+ class Isolate;
20
+
11
21
  namespace metrics {
12
22
 
13
23
  struct GarbageCollectionPhases {
@@ -196,6 +206,32 @@ class V8_EXPORT Recorder {
196
206
  static ContextId GetContextId(Local<Context> context);
197
207
  };
198
208
 
209
+ /**
210
+ * Experimental API intended for the LongTasks UKM (crbug.com/1173527).
211
+ * The Reset() method should be called at the start of a potential
212
+ * long task. The Get() method returns durations of V8 work that
213
+ * happened during the task.
214
+ *
215
+ * This API is experimental and may be removed/changed in the future.
216
+ */
217
+ struct V8_EXPORT LongTaskStats {
218
+ /**
219
+ * Resets durations of V8 work for the new task.
220
+ */
221
+ V8_INLINE static void Reset(Isolate* isolate) {
222
+ v8::internal::Internals::IncrementLongTasksStatsCounter(isolate);
223
+ }
224
+
225
+ /**
226
+ * Returns durations of V8 work that happened since the last Reset().
227
+ */
228
+ static LongTaskStats Get(Isolate* isolate);
229
+
230
+ int64_t gc_full_atomic_wall_clock_duration_us = 0;
231
+ int64_t gc_full_incremental_wall_clock_duration_us = 0;
232
+ int64_t gc_young_wall_clock_duration_us = 0;
233
+ };
234
+
199
235
  } // namespace metrics
200
236
  } // namespace v8
201
237
 
@@ -0,0 +1,152 @@
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
+
16
+ namespace v8 {
17
+
18
+ class Function;
19
+
20
+ namespace internal {
21
+ class Isolate;
22
+ class MicrotaskQueue;
23
+ } // namespace internal
24
+
25
+ /**
26
+ * Represents the microtask queue, where microtasks are stored and processed.
27
+ * https://html.spec.whatwg.org/multipage/webappapis.html#microtask-queue
28
+ * https://html.spec.whatwg.org/multipage/webappapis.html#enqueuejob(queuename,-job,-arguments)
29
+ * https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint
30
+ *
31
+ * A MicrotaskQueue instance may be associated to multiple Contexts by passing
32
+ * it to Context::New(), and they can be detached by Context::DetachGlobal().
33
+ * The embedder must keep the MicrotaskQueue instance alive until all associated
34
+ * Contexts are gone or detached.
35
+ *
36
+ * Use the same instance of MicrotaskQueue for all Contexts that may access each
37
+ * other synchronously. E.g. for Web embedding, use the same instance for all
38
+ * origins that share the same URL scheme and eTLD+1.
39
+ */
40
+ class V8_EXPORT MicrotaskQueue {
41
+ public:
42
+ /**
43
+ * Creates an empty MicrotaskQueue instance.
44
+ */
45
+ static std::unique_ptr<MicrotaskQueue> New(
46
+ Isolate* isolate, MicrotasksPolicy policy = MicrotasksPolicy::kAuto);
47
+
48
+ virtual ~MicrotaskQueue() = default;
49
+
50
+ /**
51
+ * Enqueues the callback to the queue.
52
+ */
53
+ virtual void EnqueueMicrotask(Isolate* isolate,
54
+ Local<Function> microtask) = 0;
55
+
56
+ /**
57
+ * Enqueues the callback to the queue.
58
+ */
59
+ virtual void EnqueueMicrotask(v8::Isolate* isolate,
60
+ MicrotaskCallback callback,
61
+ void* data = nullptr) = 0;
62
+
63
+ /**
64
+ * Adds a callback to notify the embedder after microtasks were run. The
65
+ * callback is triggered by explicit RunMicrotasks call or automatic
66
+ * microtasks execution (see Isolate::SetMicrotasksPolicy).
67
+ *
68
+ * Callback will trigger even if microtasks were attempted to run,
69
+ * but the microtasks queue was empty and no single microtask was actually
70
+ * executed.
71
+ *
72
+ * Executing scripts inside the callback will not re-trigger microtasks and
73
+ * the callback.
74
+ */
75
+ virtual void AddMicrotasksCompletedCallback(
76
+ MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
77
+
78
+ /**
79
+ * Removes callback that was installed by AddMicrotasksCompletedCallback.
80
+ */
81
+ virtual void RemoveMicrotasksCompletedCallback(
82
+ MicrotasksCompletedCallbackWithData callback, void* data = nullptr) = 0;
83
+
84
+ /**
85
+ * Runs microtasks if no microtask is running on this MicrotaskQueue instance.
86
+ */
87
+ virtual void PerformCheckpoint(Isolate* isolate) = 0;
88
+
89
+ /**
90
+ * Returns true if a microtask is running on this MicrotaskQueue instance.
91
+ */
92
+ virtual bool IsRunningMicrotasks() const = 0;
93
+
94
+ /**
95
+ * Returns the current depth of nested MicrotasksScope that has
96
+ * kRunMicrotasks.
97
+ */
98
+ virtual int GetMicrotasksScopeDepth() const = 0;
99
+
100
+ MicrotaskQueue(const MicrotaskQueue&) = delete;
101
+ MicrotaskQueue& operator=(const MicrotaskQueue&) = delete;
102
+
103
+ private:
104
+ friend class internal::MicrotaskQueue;
105
+ MicrotaskQueue() = default;
106
+ };
107
+
108
+ /**
109
+ * This scope is used to control microtasks when MicrotasksPolicy::kScoped
110
+ * is used on Isolate. In this mode every non-primitive call to V8 should be
111
+ * done inside some MicrotasksScope.
112
+ * Microtasks are executed when topmost MicrotasksScope marked as kRunMicrotasks
113
+ * exits.
114
+ * kDoNotRunMicrotasks should be used to annotate calls not intended to trigger
115
+ * microtasks.
116
+ */
117
+ class V8_EXPORT V8_NODISCARD MicrotasksScope {
118
+ public:
119
+ enum Type { kRunMicrotasks, kDoNotRunMicrotasks };
120
+
121
+ MicrotasksScope(Isolate* isolate, Type type);
122
+ MicrotasksScope(Isolate* isolate, MicrotaskQueue* microtask_queue, Type type);
123
+ ~MicrotasksScope();
124
+
125
+ /**
126
+ * Runs microtasks if no kRunMicrotasks scope is currently active.
127
+ */
128
+ static void PerformCheckpoint(Isolate* isolate);
129
+
130
+ /**
131
+ * Returns current depth of nested kRunMicrotasks scopes.
132
+ */
133
+ static int GetCurrentDepth(Isolate* isolate);
134
+
135
+ /**
136
+ * Returns true while microtasks are being executed.
137
+ */
138
+ static bool IsRunningMicrotasks(Isolate* isolate);
139
+
140
+ // Prevent copying.
141
+ MicrotasksScope(const MicrotasksScope&) = delete;
142
+ MicrotasksScope& operator=(const MicrotasksScope&) = delete;
143
+
144
+ private:
145
+ internal::Isolate* const isolate_;
146
+ internal::MicrotaskQueue* const microtask_queue_;
147
+ bool run_;
148
+ };
149
+
150
+ } // namespace v8
151
+
152
+ #endif // INCLUDE_V8_MICROTASKS_QUEUE_H_
@@ -0,0 +1,28 @@
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_MICROTASK_H_
6
+ #define INCLUDE_V8_MICROTASK_H_
7
+
8
+ namespace v8 {
9
+
10
+ class Isolate;
11
+
12
+ // --- Microtasks Callbacks ---
13
+ using MicrotasksCompletedCallbackWithData = void (*)(Isolate*, void*);
14
+ using MicrotaskCallback = void (*)(void* data);
15
+
16
+ /**
17
+ * Policy for running microtasks:
18
+ * - explicit: microtasks are invoked with the
19
+ * Isolate::PerformMicrotaskCheckpoint() method;
20
+ * - scoped: microtasks invocation is controlled by MicrotasksScope objects;
21
+ * - auto: microtasks are invoked when the script call depth decrements
22
+ * to zero.
23
+ */
24
+ enum class MicrotasksPolicy { kExplicit, kScoped, kAuto };
25
+
26
+ } // namespace v8
27
+
28
+ #endif // INCLUDE_V8_MICROTASK_H_