aha-libv8-node 16.0.0.0-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/ext/libv8-node/.location.yml +1 -0
  3. data/ext/libv8-node/location.rb +76 -0
  4. data/ext/libv8-node/paths.rb +30 -0
  5. data/lib/libv8-node.rb +1 -0
  6. data/lib/libv8/node.rb +11 -0
  7. data/lib/libv8/node/version.rb +7 -0
  8. data/vendor/v8/include/cppgc/allocation.h +229 -0
  9. data/vendor/v8/include/cppgc/common.h +29 -0
  10. data/vendor/v8/include/cppgc/cross-thread-persistent.h +345 -0
  11. data/vendor/v8/include/cppgc/custom-space.h +97 -0
  12. data/vendor/v8/include/cppgc/default-platform.h +75 -0
  13. data/vendor/v8/include/cppgc/ephemeron-pair.h +30 -0
  14. data/vendor/v8/include/cppgc/garbage-collected.h +116 -0
  15. data/vendor/v8/include/cppgc/heap-consistency.h +236 -0
  16. data/vendor/v8/include/cppgc/heap-state.h +59 -0
  17. data/vendor/v8/include/cppgc/heap-statistics.h +110 -0
  18. data/vendor/v8/include/cppgc/heap.h +199 -0
  19. data/vendor/v8/include/cppgc/internal/api-constants.h +47 -0
  20. data/vendor/v8/include/cppgc/internal/atomic-entry-flag.h +48 -0
  21. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +68 -0
  22. data/vendor/v8/include/cppgc/internal/compiler-specific.h +38 -0
  23. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  24. data/vendor/v8/include/cppgc/internal/gc-info.h +47 -0
  25. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  26. data/vendor/v8/include/cppgc/internal/name-trait.h +111 -0
  27. data/vendor/v8/include/cppgc/internal/persistent-node.h +132 -0
  28. data/vendor/v8/include/cppgc/internal/pointer-policies.h +143 -0
  29. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
  30. data/vendor/v8/include/cppgc/internal/write-barrier.h +390 -0
  31. data/vendor/v8/include/cppgc/liveness-broker.h +74 -0
  32. data/vendor/v8/include/cppgc/macros.h +26 -0
  33. data/vendor/v8/include/cppgc/member.h +271 -0
  34. data/vendor/v8/include/cppgc/name-provider.h +65 -0
  35. data/vendor/v8/include/cppgc/object-size-trait.h +58 -0
  36. data/vendor/v8/include/cppgc/persistent.h +365 -0
  37. data/vendor/v8/include/cppgc/platform.h +151 -0
  38. data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
  39. data/vendor/v8/include/cppgc/process-heap-statistics.h +36 -0
  40. data/vendor/v8/include/cppgc/sentinel-pointer.h +32 -0
  41. data/vendor/v8/include/cppgc/source-location.h +91 -0
  42. data/vendor/v8/include/cppgc/testing.h +50 -0
  43. data/vendor/v8/include/cppgc/trace-trait.h +116 -0
  44. data/vendor/v8/include/cppgc/type-traits.h +228 -0
  45. data/vendor/v8/include/cppgc/visitor.h +340 -0
  46. data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
  47. data/vendor/v8/include/libplatform/libplatform.h +117 -0
  48. data/vendor/v8/include/libplatform/v8-tracing.h +334 -0
  49. data/vendor/v8/include/v8-cppgc.h +278 -0
  50. data/vendor/v8/include/v8-fast-api-calls.h +419 -0
  51. data/vendor/v8/include/v8-inspector-protocol.h +13 -0
  52. data/vendor/v8/include/v8-inspector.h +336 -0
  53. data/vendor/v8/include/v8-internal.h +462 -0
  54. data/vendor/v8/include/v8-metrics.h +189 -0
  55. data/vendor/v8/include/v8-platform.h +710 -0
  56. data/vendor/v8/include/v8-profiler.h +1116 -0
  57. data/vendor/v8/include/v8-unwinder-state.h +30 -0
  58. data/vendor/v8/include/v8-util.h +652 -0
  59. data/vendor/v8/include/v8-value-serializer-version.h +24 -0
  60. data/vendor/v8/include/v8-version-string.h +38 -0
  61. data/vendor/v8/include/v8-version.h +20 -0
  62. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  63. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  64. data/vendor/v8/include/v8.h +12479 -0
  65. data/vendor/v8/include/v8config.h +521 -0
  66. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  67. metadata +137 -0
@@ -0,0 +1,419 @@
1
+ // Copyright 2020 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
+ /**
6
+ * This file provides additional API on top of the default one for making
7
+ * API calls, which come from embedder C++ functions. The functions are being
8
+ * called directly from optimized code, doing all the necessary typechecks
9
+ * in the compiler itself, instead of on the embedder side. Hence the "fast"
10
+ * in the name. Example usage might look like:
11
+ *
12
+ * \code
13
+ * void FastMethod(int param, bool another_param);
14
+ *
15
+ * v8::FunctionTemplate::New(isolate, SlowCallback, data,
16
+ * signature, length, constructor_behavior
17
+ * side_effect_type,
18
+ * &v8::CFunction::Make(FastMethod));
19
+ * \endcode
20
+ *
21
+ * By design, fast calls are limited by the following requirements, which
22
+ * the embedder should enforce themselves:
23
+ * - they should not allocate on the JS heap;
24
+ * - they should not trigger JS execution.
25
+ * To enforce them, the embedder could use the existing
26
+ * v8::Isolate::DisallowJavascriptExecutionScope and a utility similar to
27
+ * Blink's NoAllocationScope:
28
+ * https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/platform/heap/thread_state_scopes.h;l=16
29
+ *
30
+ * Due to these limitations, it's not directly possible to report errors by
31
+ * throwing a JS exception or to otherwise do an allocation. There is an
32
+ * alternative way of creating fast calls that supports falling back to the
33
+ * slow call and then performing the necessary allocation. When one creates
34
+ * the fast method by using CFunction::MakeWithFallbackSupport instead of
35
+ * CFunction::Make, the fast callback gets as last parameter an output variable,
36
+ * through which it can request falling back to the slow call. So one might
37
+ * declare their method like:
38
+ *
39
+ * \code
40
+ * void FastMethodWithFallback(int param, FastApiCallbackOptions& options);
41
+ * \endcode
42
+ *
43
+ * If the callback wants to signal an error condition or to perform an
44
+ * allocation, it must set options.fallback to true and do an early return from
45
+ * the fast method. Then V8 checks the value of options.fallback and if it's
46
+ * true, falls back to executing the SlowCallback, which is capable of reporting
47
+ * the error (either by throwing a JS exception or logging to the console) or
48
+ * doing the allocation. It's the embedder's responsibility to ensure that the
49
+ * fast callback is idempotent up to the point where error and fallback
50
+ * conditions are checked, because otherwise executing the slow callback might
51
+ * produce visible side-effects twice.
52
+ *
53
+ * An example for custom embedder type support might employ a way to wrap/
54
+ * unwrap various C++ types in JSObject instances, e.g:
55
+ *
56
+ * \code
57
+ *
58
+ * // Helper method with a check for field count.
59
+ * template <typename T, int offset>
60
+ * inline T* GetInternalField(v8::Local<v8::Object> wrapper) {
61
+ * assert(offset < wrapper->InternalFieldCount());
62
+ * return reinterpret_cast<T*>(
63
+ * wrapper->GetAlignedPointerFromInternalField(offset));
64
+ * }
65
+ *
66
+ * class CustomEmbedderType {
67
+ * public:
68
+ * // Returns the raw C object from a wrapper JS object.
69
+ * static CustomEmbedderType* Unwrap(v8::Local<v8::Object> wrapper) {
70
+ * return GetInternalField<CustomEmbedderType,
71
+ * kV8EmbedderWrapperObjectIndex>(wrapper);
72
+ * }
73
+ * static void FastMethod(v8::ApiObject receiver_obj, int param) {
74
+ * v8::Object* v8_object = reinterpret_cast<v8::Object*>(&api_object);
75
+ * CustomEmbedderType* receiver = static_cast<CustomEmbedderType*>(
76
+ * receiver_obj->GetAlignedPointerFromInternalField(
77
+ * kV8EmbedderWrapperObjectIndex));
78
+ *
79
+ * // Type checks are already done by the optimized code.
80
+ * // Then call some performance-critical method like:
81
+ * // receiver->Method(param);
82
+ * }
83
+ *
84
+ * static void SlowMethod(
85
+ * const v8::FunctionCallbackInfo<v8::Value>& info) {
86
+ * v8::Local<v8::Object> instance =
87
+ * v8::Local<v8::Object>::Cast(info.Holder());
88
+ * CustomEmbedderType* receiver = Unwrap(instance);
89
+ * // TODO: Do type checks and extract {param}.
90
+ * receiver->Method(param);
91
+ * }
92
+ * };
93
+ *
94
+ * // TODO(mslekova): Clean-up these constants
95
+ * // The constants kV8EmbedderWrapperTypeIndex and
96
+ * // kV8EmbedderWrapperObjectIndex describe the offsets for the type info
97
+ * // struct and the native object, when expressed as internal field indices
98
+ * // within a JSObject. The existance of this helper function assumes that
99
+ * // all embedder objects have their JSObject-side type info at the same
100
+ * // offset, but this is not a limitation of the API itself. For a detailed
101
+ * // use case, see the third example.
102
+ * static constexpr int kV8EmbedderWrapperTypeIndex = 0;
103
+ * static constexpr int kV8EmbedderWrapperObjectIndex = 1;
104
+ *
105
+ * // The following setup function can be templatized based on
106
+ * // the {embedder_object} argument.
107
+ * void SetupCustomEmbedderObject(v8::Isolate* isolate,
108
+ * v8::Local<v8::Context> context,
109
+ * CustomEmbedderType* embedder_object) {
110
+ * isolate->set_embedder_wrapper_type_index(
111
+ * kV8EmbedderWrapperTypeIndex);
112
+ * isolate->set_embedder_wrapper_object_index(
113
+ * kV8EmbedderWrapperObjectIndex);
114
+ *
115
+ * v8::CFunction c_func =
116
+ * MakeV8CFunction(CustomEmbedderType::FastMethod);
117
+ *
118
+ * Local<v8::FunctionTemplate> method_template =
119
+ * v8::FunctionTemplate::New(
120
+ * isolate, CustomEmbedderType::SlowMethod, v8::Local<v8::Value>(),
121
+ * v8::Local<v8::Signature>(), 1, v8::ConstructorBehavior::kAllow,
122
+ * v8::SideEffectType::kHasSideEffect, &c_func);
123
+ *
124
+ * v8::Local<v8::ObjectTemplate> object_template =
125
+ * v8::ObjectTemplate::New(isolate);
126
+ * object_template->SetInternalFieldCount(
127
+ * kV8EmbedderWrapperObjectIndex + 1);
128
+ * object_template->Set(isolate, "method", method_template);
129
+ *
130
+ * // Instantiate the wrapper JS object.
131
+ * v8::Local<v8::Object> object =
132
+ * object_template->NewInstance(context).ToLocalChecked();
133
+ * object->SetAlignedPointerInInternalField(
134
+ * kV8EmbedderWrapperObjectIndex,
135
+ * reinterpret_cast<void*>(embedder_object));
136
+ *
137
+ * // TODO: Expose {object} where it's necessary.
138
+ * }
139
+ * \endcode
140
+ *
141
+ * For instance if {object} is exposed via a global "obj" variable,
142
+ * one could write in JS:
143
+ * function hot_func() {
144
+ * obj.method(42);
145
+ * }
146
+ * and once {hot_func} gets optimized, CustomEmbedderType::FastMethod
147
+ * will be called instead of the slow version, with the following arguments:
148
+ * receiver := the {embedder_object} from above
149
+ * param := 42
150
+ *
151
+ * Currently supported return types:
152
+ * - void
153
+ * - bool
154
+ * - int32_t
155
+ * - uint32_t
156
+ * - float32_t
157
+ * - float64_t
158
+ * Currently supported argument types:
159
+ * - pointer to an embedder type
160
+ * - bool
161
+ * - int32_t
162
+ * - uint32_t
163
+ * - int64_t
164
+ * - uint64_t
165
+ * - float32_t
166
+ * - float64_t
167
+ *
168
+ * The 64-bit integer types currently have the IDL (unsigned) long long
169
+ * semantics: https://heycam.github.io/webidl/#abstract-opdef-converttoint
170
+ * In the future we'll extend the API to also provide conversions from/to
171
+ * BigInt to preserve full precision.
172
+ * The floating point types currently have the IDL (unrestricted) semantics,
173
+ * which is the only one used by WebGL. We plan to add support also for
174
+ * restricted floats/doubles, similarly to the BigInt conversion policies.
175
+ * We also differ from the specific NaN bit pattern that WebIDL prescribes
176
+ * (https://heycam.github.io/webidl/#es-unrestricted-float) in that Blink
177
+ * passes NaN values as-is, i.e. doesn't normalize them.
178
+ *
179
+ * To be supported types:
180
+ * - arrays of C types
181
+ * - arrays of embedder types
182
+ */
183
+
184
+ #ifndef INCLUDE_V8_FAST_API_CALLS_H_
185
+ #define INCLUDE_V8_FAST_API_CALLS_H_
186
+
187
+ #include <stddef.h>
188
+ #include <stdint.h>
189
+
190
+ #include "v8config.h" // NOLINT(build/include_directory)
191
+
192
+ namespace v8 {
193
+
194
+ class CTypeInfo {
195
+ public:
196
+ enum class Type : uint8_t {
197
+ kVoid,
198
+ kBool,
199
+ kInt32,
200
+ kUint32,
201
+ kInt64,
202
+ kUint64,
203
+ kFloat32,
204
+ kFloat64,
205
+ kV8Value,
206
+ };
207
+
208
+ // kCallbackOptionsType and kInvalidType are not part of the Type enum
209
+ // because they are only used internally. Use values 255 and 254 that
210
+ // are larger than any valid Type enum.
211
+ static constexpr Type kCallbackOptionsType = Type(255);
212
+ static constexpr Type kInvalidType = Type(254);
213
+
214
+ enum class ArgFlags : uint8_t {
215
+ kNone = 0,
216
+ };
217
+
218
+ explicit constexpr CTypeInfo(Type type, ArgFlags flags = ArgFlags::kNone)
219
+ : type_(type), flags_(flags) {}
220
+
221
+ constexpr Type GetType() const { return type_; }
222
+
223
+ constexpr ArgFlags GetFlags() const { return flags_; }
224
+
225
+ static const CTypeInfo& Invalid() {
226
+ static CTypeInfo invalid = CTypeInfo(kInvalidType);
227
+ return invalid;
228
+ }
229
+
230
+ private:
231
+ Type type_;
232
+ ArgFlags flags_;
233
+ };
234
+
235
+ class CFunctionInfo {
236
+ public:
237
+ virtual const CTypeInfo& ReturnInfo() const = 0;
238
+ virtual unsigned int ArgumentCount() const = 0;
239
+ virtual const CTypeInfo& ArgumentInfo(unsigned int index) const = 0;
240
+ virtual bool HasOptions() const = 0;
241
+ };
242
+
243
+ struct ApiObject {
244
+ uintptr_t address;
245
+ };
246
+
247
+ /**
248
+ * A struct which may be passed to a fast call callback, like so:
249
+ * \code
250
+ * void FastMethodWithOptions(int param, FastApiCallbackOptions& options);
251
+ * \endcode
252
+ */
253
+ struct FastApiCallbackOptions {
254
+ /**
255
+ * If the callback wants to signal an error condition or to perform an
256
+ * allocation, it must set options.fallback to true and do an early return
257
+ * from the fast method. Then V8 checks the value of options.fallback and if
258
+ * it's true, falls back to executing the SlowCallback, which is capable of
259
+ * reporting the error (either by throwing a JS exception or logging to the
260
+ * console) or doing the allocation. It's the embedder's responsibility to
261
+ * ensure that the fast callback is idempotent up to the point where error and
262
+ * fallback conditions are checked, because otherwise executing the slow
263
+ * callback might produce visible side-effects twice.
264
+ */
265
+ bool fallback;
266
+
267
+ /**
268
+ * The `data` passed to the FunctionTemplate constructor, or `undefined`.
269
+ */
270
+ const ApiObject data;
271
+ };
272
+
273
+ namespace internal {
274
+
275
+ template <typename T>
276
+ struct GetCType;
277
+
278
+ #define SPECIALIZE_GET_C_TYPE_FOR(ctype, ctypeinfo) \
279
+ template <> \
280
+ struct GetCType<ctype> { \
281
+ static constexpr CTypeInfo Get() { \
282
+ return CTypeInfo(CTypeInfo::Type::ctypeinfo); \
283
+ } \
284
+ };
285
+
286
+ #define SUPPORTED_C_TYPES(V) \
287
+ V(void, kVoid) \
288
+ V(bool, kBool) \
289
+ V(int32_t, kInt32) \
290
+ V(uint32_t, kUint32) \
291
+ V(int64_t, kInt64) \
292
+ V(uint64_t, kUint64) \
293
+ V(float, kFloat32) \
294
+ V(double, kFloat64) \
295
+ V(ApiObject, kV8Value)
296
+
297
+ SUPPORTED_C_TYPES(SPECIALIZE_GET_C_TYPE_FOR)
298
+
299
+ template <>
300
+ struct GetCType<FastApiCallbackOptions&> {
301
+ static constexpr CTypeInfo Get() {
302
+ return CTypeInfo(CTypeInfo::kCallbackOptionsType);
303
+ }
304
+ };
305
+
306
+ // Helper to count the number of occurances of `T` in `List`
307
+ template <typename T, typename... List>
308
+ struct count : std::integral_constant<int, 0> {};
309
+ template <typename T, typename... Args>
310
+ struct count<T, T, Args...>
311
+ : std::integral_constant<std::size_t, 1 + count<T, Args...>::value> {};
312
+ template <typename T, typename U, typename... Args>
313
+ struct count<T, U, Args...> : count<T, Args...> {};
314
+
315
+ template <typename R, typename... Args>
316
+ class CFunctionInfoImpl : public CFunctionInfo {
317
+ public:
318
+ static constexpr int kOptionsArgCount =
319
+ count<FastApiCallbackOptions&, Args...>();
320
+ static constexpr int kReceiverCount = 1;
321
+ CFunctionInfoImpl()
322
+ : return_info_(internal::GetCType<R>::Get()),
323
+ arg_count_(sizeof...(Args) - kOptionsArgCount),
324
+ arg_info_{internal::GetCType<Args>::Get()...} {
325
+ static_assert(kOptionsArgCount == 0 || kOptionsArgCount == 1,
326
+ "Only one options parameter is supported.");
327
+ static_assert(sizeof...(Args) >= kOptionsArgCount + kReceiverCount,
328
+ "The receiver or the fallback argument is missing.");
329
+ constexpr CTypeInfo::Type type = internal::GetCType<R>::Get().GetType();
330
+ static_assert(type == CTypeInfo::Type::kVoid ||
331
+ type == CTypeInfo::Type::kBool ||
332
+ type == CTypeInfo::Type::kInt32 ||
333
+ type == CTypeInfo::Type::kUint32 ||
334
+ type == CTypeInfo::Type::kFloat32 ||
335
+ type == CTypeInfo::Type::kFloat64,
336
+ "64-bit int and api object values are not currently "
337
+ "supported return types.");
338
+ }
339
+
340
+ const CTypeInfo& ReturnInfo() const override { return return_info_; }
341
+ unsigned int ArgumentCount() const override { return arg_count_; }
342
+ const CTypeInfo& ArgumentInfo(unsigned int index) const override {
343
+ if (index >= ArgumentCount()) {
344
+ return CTypeInfo::Invalid();
345
+ }
346
+ return arg_info_[index];
347
+ }
348
+ bool HasOptions() const override { return kOptionsArgCount == 1; }
349
+
350
+ private:
351
+ const CTypeInfo return_info_;
352
+ const unsigned int arg_count_;
353
+ const CTypeInfo arg_info_[sizeof...(Args)];
354
+ };
355
+
356
+ } // namespace internal
357
+
358
+ class V8_EXPORT CFunction {
359
+ public:
360
+ constexpr CFunction() : address_(nullptr), type_info_(nullptr) {}
361
+
362
+ const CTypeInfo& ReturnInfo() const { return type_info_->ReturnInfo(); }
363
+
364
+ const CTypeInfo& ArgumentInfo(unsigned int index) const {
365
+ return type_info_->ArgumentInfo(index);
366
+ }
367
+
368
+ unsigned int ArgumentCount() const { return type_info_->ArgumentCount(); }
369
+
370
+ const void* GetAddress() const { return address_; }
371
+ const CFunctionInfo* GetTypeInfo() const { return type_info_; }
372
+
373
+ template <typename F>
374
+ static CFunction Make(F* func) {
375
+ return ArgUnwrap<F*>::Make(func);
376
+ }
377
+
378
+ template <typename F>
379
+ V8_DEPRECATED("Use CFunction::Make instead.")
380
+ static CFunction MakeWithFallbackSupport(F* func) {
381
+ return ArgUnwrap<F*>::Make(func);
382
+ }
383
+
384
+ template <typename F>
385
+ static CFunction Make(F* func, const CFunctionInfo* type_info) {
386
+ return CFunction(reinterpret_cast<const void*>(func), type_info);
387
+ }
388
+
389
+ private:
390
+ const void* address_;
391
+ const CFunctionInfo* type_info_;
392
+
393
+ CFunction(const void* address, const CFunctionInfo* type_info);
394
+
395
+ template <typename R, typename... Args>
396
+ static CFunctionInfo* GetCFunctionInfo() {
397
+ static internal::CFunctionInfoImpl<R, Args...> instance;
398
+ return &instance;
399
+ }
400
+
401
+ template <typename F>
402
+ class ArgUnwrap {
403
+ static_assert(sizeof(F) != sizeof(F),
404
+ "CFunction must be created from a function pointer.");
405
+ };
406
+
407
+ template <typename R, typename... Args>
408
+ class ArgUnwrap<R (*)(Args...)> {
409
+ public:
410
+ static CFunction Make(R (*func)(Args...)) {
411
+ return CFunction(reinterpret_cast<const void*>(func),
412
+ GetCFunctionInfo<R, Args...>());
413
+ }
414
+ };
415
+ };
416
+
417
+ } // namespace v8
418
+
419
+ #endif // INCLUDE_V8_FAST_API_CALLS_H_
@@ -0,0 +1,13 @@
1
+ // Copyright 2016 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 V8_V8_INSPECTOR_PROTOCOL_H_
6
+ #define V8_V8_INSPECTOR_PROTOCOL_H_
7
+
8
+ #include "inspector/Debugger.h" // NOLINT(build/include_directory)
9
+ #include "inspector/Runtime.h" // NOLINT(build/include_directory)
10
+ #include "inspector/Schema.h" // NOLINT(build/include_directory)
11
+ #include "v8-inspector.h" // NOLINT(build/include_directory)
12
+
13
+ #endif // V8_V8_INSPECTOR_PROTOCOL_H_
@@ -0,0 +1,336 @@
1
+ // Copyright 2016 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 V8_V8_INSPECTOR_H_
6
+ #define V8_V8_INSPECTOR_H_
7
+
8
+ #include <stdint.h>
9
+ #include <cctype>
10
+
11
+ #include <memory>
12
+ #include <unordered_map>
13
+
14
+ #include "v8.h" // NOLINT(build/include_directory)
15
+
16
+ namespace v8_inspector {
17
+
18
+ namespace protocol {
19
+ namespace Debugger {
20
+ namespace API {
21
+ class SearchMatch;
22
+ }
23
+ }
24
+ namespace Runtime {
25
+ namespace API {
26
+ class RemoteObject;
27
+ class StackTrace;
28
+ class StackTraceId;
29
+ }
30
+ }
31
+ namespace Schema {
32
+ namespace API {
33
+ class Domain;
34
+ }
35
+ }
36
+ } // namespace protocol
37
+
38
+ class V8_EXPORT StringView {
39
+ public:
40
+ StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {}
41
+
42
+ StringView(const uint8_t* characters, size_t length)
43
+ : m_is8Bit(true), m_length(length), m_characters8(characters) {}
44
+
45
+ StringView(const uint16_t* characters, size_t length)
46
+ : m_is8Bit(false), m_length(length), m_characters16(characters) {}
47
+
48
+ bool is8Bit() const { return m_is8Bit; }
49
+ size_t length() const { return m_length; }
50
+
51
+ // TODO(dgozman): add DCHECK(m_is8Bit) to accessors once platform can be used
52
+ // here.
53
+ const uint8_t* characters8() const { return m_characters8; }
54
+ const uint16_t* characters16() const { return m_characters16; }
55
+
56
+ private:
57
+ bool m_is8Bit;
58
+ size_t m_length;
59
+ union {
60
+ const uint8_t* m_characters8;
61
+ const uint16_t* m_characters16;
62
+ };
63
+ };
64
+
65
+ class V8_EXPORT StringBuffer {
66
+ public:
67
+ virtual ~StringBuffer() = default;
68
+ virtual StringView string() const = 0;
69
+ // This method copies contents.
70
+ static std::unique_ptr<StringBuffer> create(StringView);
71
+ };
72
+
73
+ class V8_EXPORT V8ContextInfo {
74
+ public:
75
+ V8ContextInfo(v8::Local<v8::Context> context, int contextGroupId,
76
+ StringView humanReadableName)
77
+ : context(context),
78
+ contextGroupId(contextGroupId),
79
+ humanReadableName(humanReadableName),
80
+ hasMemoryOnConsole(false) {}
81
+
82
+ v8::Local<v8::Context> context;
83
+ // Each v8::Context is a part of a group. The group id must be non-zero.
84
+ int contextGroupId;
85
+ StringView humanReadableName;
86
+ StringView origin;
87
+ StringView auxData;
88
+ bool hasMemoryOnConsole;
89
+
90
+ static int executionContextId(v8::Local<v8::Context> context);
91
+
92
+ // Disallow copying and allocating this one.
93
+ enum NotNullTagEnum { NotNullLiteral };
94
+ void* operator new(size_t) = delete;
95
+ void* operator new(size_t, NotNullTagEnum, void*) = delete;
96
+ void* operator new(size_t, void*) = delete;
97
+ V8ContextInfo(const V8ContextInfo&) = delete;
98
+ V8ContextInfo& operator=(const V8ContextInfo&) = delete;
99
+ };
100
+
101
+ class V8_EXPORT V8StackTrace {
102
+ public:
103
+ virtual StringView firstNonEmptySourceURL() const = 0;
104
+ virtual bool isEmpty() const = 0;
105
+ virtual StringView topSourceURL() const = 0;
106
+ virtual int topLineNumber() const = 0;
107
+ virtual int topColumnNumber() const = 0;
108
+ virtual StringView topScriptId() const = 0;
109
+ virtual int topScriptIdAsInteger() const = 0;
110
+ virtual StringView topFunctionName() const = 0;
111
+
112
+ virtual ~V8StackTrace() = default;
113
+ virtual std::unique_ptr<protocol::Runtime::API::StackTrace>
114
+ buildInspectorObject() const = 0;
115
+ virtual std::unique_ptr<protocol::Runtime::API::StackTrace>
116
+ buildInspectorObject(int maxAsyncDepth) const = 0;
117
+ virtual std::unique_ptr<StringBuffer> toString() const = 0;
118
+
119
+ // Safe to pass between threads, drops async chain.
120
+ virtual std::unique_ptr<V8StackTrace> clone() = 0;
121
+ };
122
+
123
+ class V8_EXPORT V8InspectorSession {
124
+ public:
125
+ virtual ~V8InspectorSession() = default;
126
+
127
+ // Cross-context inspectable values (DOM nodes in different worlds, etc.).
128
+ class V8_EXPORT Inspectable {
129
+ public:
130
+ virtual v8::Local<v8::Value> get(v8::Local<v8::Context>) = 0;
131
+ virtual ~Inspectable() = default;
132
+ };
133
+ virtual void addInspectedObject(std::unique_ptr<Inspectable>) = 0;
134
+
135
+ // Dispatching protocol messages.
136
+ static bool canDispatchMethod(StringView method);
137
+ virtual void dispatchProtocolMessage(StringView message) = 0;
138
+ virtual std::vector<uint8_t> state() = 0;
139
+ virtual std::vector<std::unique_ptr<protocol::Schema::API::Domain>>
140
+ supportedDomains() = 0;
141
+
142
+ // Debugger actions.
143
+ virtual void schedulePauseOnNextStatement(StringView breakReason,
144
+ StringView breakDetails) = 0;
145
+ virtual void cancelPauseOnNextStatement() = 0;
146
+ virtual void breakProgram(StringView breakReason,
147
+ StringView breakDetails) = 0;
148
+ virtual void setSkipAllPauses(bool) = 0;
149
+ virtual void resume(bool setTerminateOnResume = false) = 0;
150
+ virtual void stepOver() = 0;
151
+ virtual std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>>
152
+ searchInTextByLines(StringView text, StringView query, bool caseSensitive,
153
+ bool isRegex) = 0;
154
+
155
+ // Remote objects.
156
+ virtual std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(
157
+ v8::Local<v8::Context>, v8::Local<v8::Value>, StringView groupName,
158
+ bool generatePreview) = 0;
159
+
160
+ virtual bool unwrapObject(std::unique_ptr<StringBuffer>* error,
161
+ StringView objectId, v8::Local<v8::Value>*,
162
+ v8::Local<v8::Context>*,
163
+ std::unique_ptr<StringBuffer>* objectGroup) = 0;
164
+ virtual void releaseObjectGroup(StringView) = 0;
165
+ virtual void triggerPreciseCoverageDeltaUpdate(StringView occassion) = 0;
166
+ };
167
+
168
+ class V8_EXPORT V8InspectorClient {
169
+ public:
170
+ virtual ~V8InspectorClient() = default;
171
+
172
+ virtual void runMessageLoopOnPause(int contextGroupId) {}
173
+ virtual void quitMessageLoopOnPause() {}
174
+ virtual void runIfWaitingForDebugger(int contextGroupId) {}
175
+
176
+ virtual void muteMetrics(int contextGroupId) {}
177
+ virtual void unmuteMetrics(int contextGroupId) {}
178
+
179
+ virtual void beginUserGesture() {}
180
+ virtual void endUserGesture() {}
181
+
182
+ virtual std::unique_ptr<StringBuffer> valueSubtype(v8::Local<v8::Value>) {
183
+ return nullptr;
184
+ }
185
+ virtual std::unique_ptr<StringBuffer> descriptionForValueSubtype(
186
+ v8::Local<v8::Context>, v8::Local<v8::Value>) {
187
+ return nullptr;
188
+ }
189
+ virtual bool formatAccessorsAsProperties(v8::Local<v8::Value>) {
190
+ return false;
191
+ }
192
+ virtual bool isInspectableHeapObject(v8::Local<v8::Object>) { return true; }
193
+
194
+ virtual v8::Local<v8::Context> ensureDefaultContextInGroup(
195
+ int contextGroupId) {
196
+ return v8::Local<v8::Context>();
197
+ }
198
+ virtual void beginEnsureAllContextsInGroup(int contextGroupId) {}
199
+ virtual void endEnsureAllContextsInGroup(int contextGroupId) {}
200
+
201
+ virtual void installAdditionalCommandLineAPI(v8::Local<v8::Context>,
202
+ v8::Local<v8::Object>) {}
203
+ virtual void consoleAPIMessage(int contextGroupId,
204
+ v8::Isolate::MessageErrorLevel level,
205
+ const StringView& message,
206
+ const StringView& url, unsigned lineNumber,
207
+ unsigned columnNumber, V8StackTrace*) {}
208
+ virtual v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate*,
209
+ v8::Local<v8::Context>) {
210
+ return v8::MaybeLocal<v8::Value>();
211
+ }
212
+
213
+ virtual void consoleTime(const StringView& title) {}
214
+ virtual void consoleTimeEnd(const StringView& title) {}
215
+ virtual void consoleTimeStamp(const StringView& title) {}
216
+ virtual void consoleClear(int contextGroupId) {}
217
+ virtual double currentTimeMS() { return 0; }
218
+ typedef void (*TimerCallback)(void*);
219
+ virtual void startRepeatingTimer(double, TimerCallback, void* data) {}
220
+ virtual void cancelTimer(void* data) {}
221
+
222
+ // TODO(dgozman): this was added to support service worker shadow page. We
223
+ // should not connect at all.
224
+ virtual bool canExecuteScripts(int contextGroupId) { return true; }
225
+
226
+ virtual void maxAsyncCallStackDepthChanged(int depth) {}
227
+
228
+ virtual std::unique_ptr<StringBuffer> resourceNameToUrl(
229
+ const StringView& resourceName) {
230
+ return nullptr;
231
+ }
232
+
233
+ // The caller would defer to generating a random 64 bit integer if
234
+ // this method returns 0.
235
+ virtual int64_t generateUniqueId() { return 0; }
236
+ };
237
+
238
+ // These stack trace ids are intended to be passed between debuggers and be
239
+ // resolved later. This allows to track cross-debugger calls and step between
240
+ // them if a single client connects to multiple debuggers.
241
+ struct V8_EXPORT V8StackTraceId {
242
+ uintptr_t id;
243
+ std::pair<int64_t, int64_t> debugger_id;
244
+ bool should_pause = false;
245
+
246
+ V8StackTraceId();
247
+ V8StackTraceId(const V8StackTraceId&) = default;
248
+ V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id);
249
+ V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id,
250
+ bool should_pause);
251
+ explicit V8StackTraceId(StringView);
252
+ V8StackTraceId& operator=(const V8StackTraceId&) = default;
253
+ V8StackTraceId& operator=(V8StackTraceId&&) noexcept = default;
254
+ ~V8StackTraceId() = default;
255
+
256
+ bool IsInvalid() const;
257
+ std::unique_ptr<StringBuffer> ToString();
258
+ };
259
+
260
+ class V8_EXPORT V8Inspector {
261
+ public:
262
+ static std::unique_ptr<V8Inspector> create(v8::Isolate*, V8InspectorClient*);
263
+ virtual ~V8Inspector() = default;
264
+
265
+ // Contexts instrumentation.
266
+ virtual void contextCreated(const V8ContextInfo&) = 0;
267
+ virtual void contextDestroyed(v8::Local<v8::Context>) = 0;
268
+ virtual void resetContextGroup(int contextGroupId) = 0;
269
+ virtual v8::MaybeLocal<v8::Context> contextById(int contextId) = 0;
270
+
271
+ // Various instrumentation.
272
+ virtual void idleStarted() = 0;
273
+ virtual void idleFinished() = 0;
274
+
275
+ // Async stack traces instrumentation.
276
+ virtual void asyncTaskScheduled(StringView taskName, void* task,
277
+ bool recurring) = 0;
278
+ virtual void asyncTaskCanceled(void* task) = 0;
279
+ virtual void asyncTaskStarted(void* task) = 0;
280
+ virtual void asyncTaskFinished(void* task) = 0;
281
+ virtual void allAsyncTasksCanceled() = 0;
282
+
283
+ virtual V8StackTraceId storeCurrentStackTrace(StringView description) = 0;
284
+ virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0;
285
+ virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0;
286
+
287
+ // Exceptions instrumentation.
288
+ virtual unsigned exceptionThrown(v8::Local<v8::Context>, StringView message,
289
+ v8::Local<v8::Value> exception,
290
+ StringView detailedMessage, StringView url,
291
+ unsigned lineNumber, unsigned columnNumber,
292
+ std::unique_ptr<V8StackTrace>,
293
+ int scriptId) = 0;
294
+ virtual void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
295
+ StringView message) = 0;
296
+
297
+ // Connection.
298
+ class V8_EXPORT Channel {
299
+ public:
300
+ virtual ~Channel() = default;
301
+ virtual void sendResponse(int callId,
302
+ std::unique_ptr<StringBuffer> message) = 0;
303
+ virtual void sendNotification(std::unique_ptr<StringBuffer> message) = 0;
304
+ virtual void flushProtocolNotifications() = 0;
305
+ };
306
+ virtual std::unique_ptr<V8InspectorSession> connect(int contextGroupId,
307
+ Channel*,
308
+ StringView state) = 0;
309
+
310
+ // API methods.
311
+ virtual std::unique_ptr<V8StackTrace> createStackTrace(
312
+ v8::Local<v8::StackTrace>) = 0;
313
+ virtual std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) = 0;
314
+
315
+ // Performance counters.
316
+ class V8_EXPORT Counters : public std::enable_shared_from_this<Counters> {
317
+ public:
318
+ explicit Counters(v8::Isolate* isolate);
319
+ ~Counters();
320
+ const std::unordered_map<std::string, int>& getCountersMap() const {
321
+ return m_countersMap;
322
+ }
323
+
324
+ private:
325
+ static int* getCounterPtr(const char* name);
326
+
327
+ v8::Isolate* m_isolate;
328
+ std::unordered_map<std::string, int> m_countersMap;
329
+ };
330
+
331
+ virtual std::shared_ptr<Counters> enableCounters() = 0;
332
+ };
333
+
334
+ } // namespace v8_inspector
335
+
336
+ #endif // V8_V8_INSPECTOR_H_