@nocobase/plugin-workflow-javascript 2.1.0-beta.10 → 2.1.0-beta.12

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 (107) hide show
  1. package/dist/externalVersion.js +4 -4
  2. package/dist/node_modules/isolated-vm/.clang-tidy +13 -0
  3. package/dist/node_modules/isolated-vm/.dockerignore +9 -0
  4. package/dist/node_modules/isolated-vm/Dockerfile.alpine +9 -0
  5. package/dist/node_modules/isolated-vm/Dockerfile.debian +12 -0
  6. package/dist/node_modules/isolated-vm/LICENSE +13 -0
  7. package/dist/node_modules/isolated-vm/binding.gyp +120 -0
  8. package/dist/node_modules/isolated-vm/include.js +3 -0
  9. package/dist/node_modules/isolated-vm/inspector-example.js +59 -0
  10. package/dist/node_modules/isolated-vm/isolated-vm.d.ts +820 -0
  11. package/dist/node_modules/isolated-vm/isolated-vm.js +1 -0
  12. package/dist/node_modules/isolated-vm/native-example/binding.gyp +23 -0
  13. package/dist/node_modules/isolated-vm/native-example/example.cc +61 -0
  14. package/dist/node_modules/isolated-vm/native-example/package.json +13 -0
  15. package/dist/node_modules/isolated-vm/native-example/usage.js +35 -0
  16. package/dist/node_modules/isolated-vm/out/isolated_vm.node +0 -0
  17. package/dist/node_modules/isolated-vm/package.json +1 -0
  18. package/dist/node_modules/isolated-vm/src/external_copy/error.h +33 -0
  19. package/dist/node_modules/isolated-vm/src/external_copy/external_copy.cc +509 -0
  20. package/dist/node_modules/isolated-vm/src/external_copy/external_copy.h +117 -0
  21. package/dist/node_modules/isolated-vm/src/external_copy/serializer.cc +85 -0
  22. package/dist/node_modules/isolated-vm/src/external_copy/serializer.h +136 -0
  23. package/dist/node_modules/isolated-vm/src/external_copy/serializer_nortti.cc +73 -0
  24. package/dist/node_modules/isolated-vm/src/external_copy/string.cc +124 -0
  25. package/dist/node_modules/isolated-vm/src/external_copy/string.h +28 -0
  26. package/dist/node_modules/isolated-vm/src/isolate/allocator.h +32 -0
  27. package/dist/node_modules/isolated-vm/src/isolate/allocator_nortti.cc +142 -0
  28. package/dist/node_modules/isolated-vm/src/isolate/class_handle.h +334 -0
  29. package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.cc +220 -0
  30. package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.h +100 -0
  31. package/dist/node_modules/isolated-vm/src/isolate/environment.cc +626 -0
  32. package/dist/node_modules/isolated-vm/src/isolate/environment.h +381 -0
  33. package/dist/node_modules/isolated-vm/src/isolate/executor.cc +198 -0
  34. package/dist/node_modules/isolated-vm/src/isolate/executor.h +183 -0
  35. package/dist/node_modules/isolated-vm/src/isolate/external.h +64 -0
  36. package/dist/node_modules/isolated-vm/src/isolate/functor_runners.h +97 -0
  37. package/dist/node_modules/isolated-vm/src/isolate/generic/array.h +145 -0
  38. package/dist/node_modules/isolated-vm/src/isolate/generic/callbacks.h +272 -0
  39. package/dist/node_modules/isolated-vm/src/isolate/generic/error.h +140 -0
  40. package/dist/node_modules/isolated-vm/src/isolate/generic/extract_params.h +145 -0
  41. package/dist/node_modules/isolated-vm/src/isolate/generic/handle_cast.h +257 -0
  42. package/dist/node_modules/isolated-vm/src/isolate/generic/read_option.h +47 -0
  43. package/dist/node_modules/isolated-vm/src/isolate/holder.cc +88 -0
  44. package/dist/node_modules/isolated-vm/src/isolate/holder.h +63 -0
  45. package/dist/node_modules/isolated-vm/src/isolate/inspector.cc +200 -0
  46. package/dist/node_modules/isolated-vm/src/isolate/inspector.h +70 -0
  47. package/dist/node_modules/isolated-vm/src/isolate/node_wrapper.h +15 -0
  48. package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.cc +22 -0
  49. package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.h +46 -0
  50. package/dist/node_modules/isolated-vm/src/isolate/remote_handle.h +164 -0
  51. package/dist/node_modules/isolated-vm/src/isolate/run_with_timeout.h +171 -0
  52. package/dist/node_modules/isolated-vm/src/isolate/runnable.h +29 -0
  53. package/dist/node_modules/isolated-vm/src/isolate/scheduler.cc +191 -0
  54. package/dist/node_modules/isolated-vm/src/isolate/scheduler.h +165 -0
  55. package/dist/node_modules/isolated-vm/src/isolate/specific.h +35 -0
  56. package/dist/node_modules/isolated-vm/src/isolate/stack_trace.cc +219 -0
  57. package/dist/node_modules/isolated-vm/src/isolate/stack_trace.h +24 -0
  58. package/dist/node_modules/isolated-vm/src/isolate/strings.h +127 -0
  59. package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.cc +385 -0
  60. package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.h +136 -0
  61. package/dist/node_modules/isolated-vm/src/isolate/transferable.h +15 -0
  62. package/dist/node_modules/isolated-vm/src/isolate/util.h +45 -0
  63. package/dist/node_modules/isolated-vm/src/isolate/v8_inspector_wrapper.h +12 -0
  64. package/dist/node_modules/isolated-vm/src/isolate/v8_version.h +12 -0
  65. package/dist/node_modules/isolated-vm/src/isolated_vm.h +71 -0
  66. package/dist/node_modules/isolated-vm/src/lib/covariant.h +50 -0
  67. package/dist/node_modules/isolated-vm/src/lib/lockable.h +178 -0
  68. package/dist/node_modules/isolated-vm/src/lib/suspend.h +106 -0
  69. package/dist/node_modules/isolated-vm/src/lib/thread_pool.cc +98 -0
  70. package/dist/node_modules/isolated-vm/src/lib/thread_pool.h +45 -0
  71. package/dist/node_modules/isolated-vm/src/lib/timer.cc +233 -0
  72. package/dist/node_modules/isolated-vm/src/lib/timer.h +36 -0
  73. package/dist/node_modules/isolated-vm/src/module/callback.cc +151 -0
  74. package/dist/node_modules/isolated-vm/src/module/callback.h +64 -0
  75. package/dist/node_modules/isolated-vm/src/module/context_handle.cc +241 -0
  76. package/dist/node_modules/isolated-vm/src/module/context_handle.h +35 -0
  77. package/dist/node_modules/isolated-vm/src/module/evaluation.cc +109 -0
  78. package/dist/node_modules/isolated-vm/src/module/evaluation.h +99 -0
  79. package/dist/node_modules/isolated-vm/src/module/external_copy_handle.cc +119 -0
  80. package/dist/node_modules/isolated-vm/src/module/external_copy_handle.h +64 -0
  81. package/dist/node_modules/isolated-vm/src/module/isolate.cc +136 -0
  82. package/dist/node_modules/isolated-vm/src/module/isolate_handle.cc +611 -0
  83. package/dist/node_modules/isolated-vm/src/module/isolate_handle.h +47 -0
  84. package/dist/node_modules/isolated-vm/src/module/lib_handle.cc +77 -0
  85. package/dist/node_modules/isolated-vm/src/module/lib_handle.h +28 -0
  86. package/dist/node_modules/isolated-vm/src/module/module_handle.cc +475 -0
  87. package/dist/node_modules/isolated-vm/src/module/module_handle.h +68 -0
  88. package/dist/node_modules/isolated-vm/src/module/native_module_handle.cc +104 -0
  89. package/dist/node_modules/isolated-vm/src/module/native_module_handle.h +49 -0
  90. package/dist/node_modules/isolated-vm/src/module/reference_handle.cc +636 -0
  91. package/dist/node_modules/isolated-vm/src/module/reference_handle.h +106 -0
  92. package/dist/node_modules/isolated-vm/src/module/script_handle.cc +107 -0
  93. package/dist/node_modules/isolated-vm/src/module/script_handle.h +37 -0
  94. package/dist/node_modules/isolated-vm/src/module/session_handle.cc +173 -0
  95. package/dist/node_modules/isolated-vm/src/module/session_handle.h +31 -0
  96. package/dist/node_modules/isolated-vm/src/module/transferable.cc +268 -0
  97. package/dist/node_modules/isolated-vm/src/module/transferable.h +42 -0
  98. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.0.0.h +360 -0
  99. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.3.0.h +376 -0
  100. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v20.0.0.h +397 -0
  101. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v22.0.0.h +419 -0
  102. package/dist/node_modules/winston-transport/package.json +1 -1
  103. package/dist/server/IsolatedVm.js +75 -0
  104. package/dist/server/ScriptInstruction.d.ts +6 -0
  105. package/dist/server/ScriptInstruction.js +11 -1
  106. package/dist/server/Vm.js +42 -27
  107. package/package.json +3 -2
@@ -0,0 +1,268 @@
1
+ #include "external_copy/external_copy.h"
2
+ #include "isolate/class_handle.h"
3
+ #include "isolate/util.h"
4
+ #include "lib/lockable.h"
5
+ #include "callback.h"
6
+ #include "reference_handle.h"
7
+ #include "transferable.h"
8
+ #include "transferable.h"
9
+ #include "external_copy_handle.h"
10
+ #include <deque>
11
+
12
+ using namespace v8;
13
+
14
+ namespace ivm {
15
+ namespace {
16
+
17
+ // Shared state for `TransferablePromise` and `TransferablePromiseHolder`
18
+ struct TransferablePromiseStateStruct {
19
+ std::shared_ptr<Transferable> value;
20
+ // This would be a good case for a unique_ptr version of RemoteHandle
21
+ std::deque<RemoteTuple<Promise::Resolver, v8::Context>> waiting;
22
+ bool did_throw = false;
23
+ bool resolved = false;
24
+ };
25
+
26
+ using TransferablePromiseState = lockable_t<TransferablePromiseStateStruct>;
27
+
28
+ // Responsible for waiting for the promise in the isolate in which it was created
29
+ class TransferablePromiseHolder final : public ClassHandle {
30
+ public:
31
+ explicit TransferablePromiseHolder(
32
+ std::shared_ptr<TransferablePromiseState> state,
33
+ TransferOptions transfer_options
34
+ ) :
35
+ state{std::move(state)}, transfer_options{transfer_options} {}
36
+
37
+ TransferablePromiseHolder(const TransferablePromiseHolder&) = delete;
38
+
39
+ ~TransferablePromiseHolder() final {
40
+ Save(true, [&]() {
41
+ return std::make_shared<ExternalCopyError>(ExternalCopyError::ErrorType::Error, "Promise was abandoned");
42
+ });
43
+ }
44
+
45
+ auto operator=(const TransferablePromiseHolder&) = delete;
46
+
47
+ static auto Definition() -> v8::Local<v8::FunctionTemplate> {
48
+ return MakeClass("PromiseHolder", nullptr);
49
+ }
50
+
51
+ void Accept(Local<Promise> promise) {
52
+ auto state = promise->State();
53
+ if (state == Promise::PromiseState::kPending) {
54
+ auto* isolate = Isolate::GetCurrent();
55
+ auto context = isolate->GetCurrentContext();
56
+ auto handle = This();
57
+ promise = Unmaybe(promise->Then(context, Unmaybe(
58
+ Function::New(context,
59
+ FreeFunctionWithData<decltype(&Resolved), &Resolved>{}.callback, handle)
60
+ )));
61
+ Unmaybe(promise->Catch(context, Unmaybe(
62
+ Function::New(context,
63
+ FreeFunctionWithData<decltype(&Rejected), &Rejected>{}.callback, handle)
64
+ )));
65
+ } else {
66
+ if (state == Promise::PromiseState::kFulfilled) {
67
+ Resolved(*this, promise->Result());
68
+ } else {
69
+ IsolateEnvironment::GetCurrent().PromiseWasHandled(promise);
70
+ Rejected(*this, promise->Result());
71
+ }
72
+ }
73
+ }
74
+
75
+ static void Resolved(TransferablePromiseHolder& that, Local<Value> value) {
76
+ that.Save(false, [&]() {
77
+ return TransferOut(value, that.transfer_options);
78
+ });
79
+ }
80
+
81
+ private:
82
+ template <class Function>
83
+ void Save(bool did_throw, Function callback) {
84
+ std::shared_ptr<Transferable> resolved_value;
85
+ auto pending_tasks = [&]() -> std::deque<RemoteTuple<Promise::Resolver, v8::Context>> {
86
+ auto lock = state->write();
87
+ if (!lock->resolved) {
88
+ lock->resolved = true;
89
+ FunctorRunners::RunCatchExternal(Isolate::GetCurrent()->GetCurrentContext(), [&]() {
90
+ lock->value = callback();
91
+ lock->did_throw = did_throw;
92
+ }, [&](std::unique_ptr<ExternalCopy> error) {
93
+ lock->value = std::move(error);
94
+ did_throw = lock->did_throw = true;
95
+ });
96
+ }
97
+ resolved_value = lock->value;
98
+ return std::exchange(lock->waiting, {});
99
+ }();
100
+ for (auto& resolver : pending_tasks) {
101
+ auto holder = resolver.GetIsolateHolder();
102
+ holder->ScheduleTask(
103
+ std::make_unique<ResolveTask>(std::move(resolver), resolved_value, did_throw),
104
+ false, true);
105
+ }
106
+ }
107
+
108
+ static void Rejected(TransferablePromiseHolder& that, Local<Value> value) {
109
+ that.Save(true, [&]() {
110
+ return ExternalCopy::CopyThrownValue(value);
111
+ });
112
+ }
113
+
114
+ struct ResolveTask : Runnable {
115
+ ResolveTask(RemoteTuple<Promise::Resolver, v8::Context> resolver, std::shared_ptr<Transferable> value, bool did_throw) :
116
+ resolver{std::move(resolver)}, value{std::move(value)}, did_throw{did_throw} {}
117
+
118
+ void Run() final {
119
+ auto context = this->resolver.Deref<1>();
120
+ Context::Scope context_scope{context};
121
+ auto resolver = this->resolver.Deref<0>();
122
+ if (did_throw) {
123
+ Unmaybe(resolver->Reject(context, value->TransferIn()));
124
+ } else {
125
+ Unmaybe(resolver->Resolve(context, value->TransferIn()));
126
+ }
127
+ }
128
+
129
+ RemoteTuple<Promise::Resolver, v8::Context> resolver;
130
+ std::shared_ptr<Transferable> value;
131
+ bool did_throw;
132
+ };
133
+
134
+ std::shared_ptr<TransferablePromiseState> state;
135
+ TransferOptions transfer_options;
136
+ };
137
+
138
+ // Internal ivm promise transferable
139
+ class TransferablePromise : public Transferable {
140
+ public:
141
+ TransferablePromise(Local<Promise> promise, TransferOptions transfer_options) :
142
+ state{std::make_shared<TransferablePromiseState>()} {
143
+ MakeHolder(transfer_options).Accept(promise);
144
+ }
145
+
146
+ TransferablePromise(Local<Value> value, TransferOptions transfer_options) :
147
+ state{std::make_shared<TransferablePromiseState>()} {
148
+ TransferablePromiseHolder::Resolved(MakeHolder(transfer_options), value);
149
+ }
150
+
151
+ auto TransferIn() -> Local<Value> final {
152
+ auto* isolate = Isolate::GetCurrent();
153
+ auto context = isolate->GetCurrentContext();
154
+ auto resolver = Unmaybe(Promise::Resolver::New(context));
155
+ auto lock = state->write();
156
+ if (lock->resolved) {
157
+ if (lock->did_throw) {
158
+ Unmaybe(resolver->Reject(context, lock->value->TransferIn()));
159
+ } else {
160
+ Unmaybe(resolver->Resolve(context, lock->value->TransferIn()));
161
+ }
162
+ } else {
163
+ lock->waiting.emplace_back(resolver, context);
164
+ }
165
+ return resolver->GetPromise();
166
+ }
167
+
168
+ private:
169
+ auto MakeHolder(TransferOptions transfer_options) -> TransferablePromiseHolder& {
170
+ transfer_options.promise = false;
171
+ auto holder = ClassHandle::NewInstance<TransferablePromiseHolder>(state, transfer_options);
172
+ auto* object = ClassHandle::Unwrap<TransferablePromiseHolder>(holder);
173
+ return *object;
174
+ }
175
+
176
+ std::shared_ptr<TransferablePromiseState> state;
177
+ };
178
+
179
+ } // anonymous namespace
180
+
181
+ TransferOptions::TransferOptions(Local<Object> options, Type fallback) : fallback{fallback} {
182
+ ParseOptions(options);
183
+ }
184
+
185
+ TransferOptions::TransferOptions(MaybeLocal<Object> maybe_options, Type fallback) : fallback{fallback} {
186
+ Local<Object> options;
187
+ if (maybe_options.ToLocal(&options)) {
188
+ ParseOptions(options);
189
+ }
190
+ }
191
+
192
+ void TransferOptions::TransferOptions::ParseOptions(Local<Object> options) {
193
+ bool copy = ReadOption<bool>(options, StringTable::Get().copy, false);
194
+ bool externalCopy = ReadOption<bool>(options, StringTable::Get().externalCopy, false);
195
+ bool reference = ReadOption<bool>(options, StringTable::Get().reference, false);
196
+ if ((copy && externalCopy) || (copy && reference) || (externalCopy && reference)) {
197
+ throw RuntimeTypeError("Only one of `copy`, `externalCopy`, or `reference` may be set");
198
+ }
199
+ if (copy) {
200
+ type = Type::Copy;
201
+ } else if (externalCopy) {
202
+ type = Type::ExternalCopy;
203
+ } else if (reference) {
204
+ type = Type::Reference;
205
+ }
206
+ promise = ReadOption<bool>(options, StringTable::Get().promise, false);
207
+ }
208
+
209
+ auto OptionalTransferOut(Local<Value> value, TransferOptions options) -> std::unique_ptr<Transferable> {
210
+ auto TransferWithType = [&](TransferOptions::Type type) -> std::unique_ptr<Transferable> {
211
+ switch (type) {
212
+ default:
213
+ return nullptr;
214
+
215
+ case TransferOptions::Type::Copy:
216
+ return ExternalCopy::Copy(value);
217
+
218
+ case TransferOptions::Type::ExternalCopy:
219
+ return std::make_unique<ExternalCopyHandle::ExternalCopyTransferable>(ExternalCopy::Copy(value));
220
+
221
+ case TransferOptions::Type::DeepReference:
222
+ return std::make_unique<ReferenceHandleTransferable>(value, true);
223
+
224
+ case TransferOptions::Type::Reference:
225
+ return std::make_unique<ReferenceHandleTransferable>(value);
226
+ }
227
+ };
228
+
229
+ if (options.promise) {
230
+ if (value->IsPromise()) {
231
+ return std::make_unique<TransferablePromise>(value.As<Promise>(), options);
232
+ } else {
233
+ return std::make_unique<TransferablePromise>(value, options);
234
+ }
235
+ }
236
+
237
+ switch (options.type) {
238
+ case TransferOptions::Type::None: {
239
+ if (value->IsObject()) {
240
+ auto* ptr = ClassHandle::Unwrap<TransferableHandle>(value.As<Object>());
241
+ if (ptr != nullptr) {
242
+ return ptr->TransferOut();
243
+ }
244
+ if (value->IsFunction()) {
245
+ return std::make_unique<CallbackTransferable>(value.As<Function>());
246
+ }
247
+ }
248
+ auto result = ExternalCopy::CopyIfPrimitive(value);
249
+ if (result) {
250
+ return result;
251
+ }
252
+ return TransferWithType(options.fallback);
253
+ }
254
+
255
+ default:
256
+ return TransferWithType(options.type);
257
+ }
258
+ }
259
+
260
+ auto TransferOut(Local<Value> value, TransferOptions options) -> std::unique_ptr<Transferable> {
261
+ auto copy = OptionalTransferOut(value, options);
262
+ if (!copy) {
263
+ throw RuntimeTypeError("A non-transferable value was passed");
264
+ }
265
+ return copy;
266
+ }
267
+
268
+ } // namespace ivm
@@ -0,0 +1,42 @@
1
+ #pragma once
2
+ #include "isolate/class_handle.h"
3
+ #include "isolate/transferable.h"
4
+ #include <v8.h>
5
+ #include <memory>
6
+
7
+ namespace ivm {
8
+
9
+ class TransferableHandle : public ClassHandle {
10
+ public:
11
+ static auto Definition() -> v8::Local<v8::FunctionTemplate> {
12
+ return MakeClass("Transferable", nullptr);
13
+ }
14
+
15
+ virtual auto TransferOut() -> std::unique_ptr<Transferable> = 0;
16
+ };
17
+
18
+ class TransferOptions {
19
+ public:
20
+ enum class Type { None, Copy, ExternalCopy, Reference, DeepReference };
21
+
22
+ TransferOptions() = default;
23
+ explicit TransferOptions(Type fallback) : fallback{fallback} {};
24
+ explicit TransferOptions(v8::Local<v8::Object> options, Type fallback = Type::None);
25
+ explicit TransferOptions(v8::MaybeLocal<v8::Object> maybe_options, Type fallback = Type::None);
26
+
27
+ auto operator==(const TransferOptions& that) const -> bool {
28
+ return type == that.type && fallback == that.fallback && promise == that.promise;
29
+ }
30
+
31
+ Type type = Type::None;
32
+ Type fallback = Type::None;
33
+ bool promise = false;
34
+
35
+ private:
36
+ void ParseOptions(v8::Local<v8::Object> options);
37
+ };
38
+
39
+ auto OptionalTransferOut(v8::Local<v8::Value> value, TransferOptions options = {}) -> std::unique_ptr<Transferable>;
40
+ auto TransferOut(v8::Local<v8::Value> value, TransferOptions options = {}) -> std::unique_ptr<Transferable>;
41
+
42
+ } // namespace ivm
@@ -0,0 +1,360 @@
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
+
10
+ #include <cctype>
11
+ #include <memory>
12
+
13
+ #include "v8-isolate.h" // NOLINT(build/include_directory)
14
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
15
+
16
+ namespace v8 {
17
+ class Context;
18
+ class Name;
19
+ class Object;
20
+ class StackTrace;
21
+ class Value;
22
+ } // namespace v8
23
+
24
+ namespace v8_inspector {
25
+
26
+ namespace internal {
27
+ class V8DebuggerId;
28
+ } // namespace internal
29
+
30
+ namespace protocol {
31
+ namespace Debugger {
32
+ namespace API {
33
+ class SearchMatch;
34
+ }
35
+ }
36
+ namespace Runtime {
37
+ namespace API {
38
+ class RemoteObject;
39
+ class StackTrace;
40
+ class StackTraceId;
41
+ }
42
+ }
43
+ namespace Schema {
44
+ namespace API {
45
+ class Domain;
46
+ }
47
+ }
48
+ } // namespace protocol
49
+
50
+ class V8_EXPORT StringView {
51
+ public:
52
+ StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {}
53
+
54
+ StringView(const uint8_t* characters, size_t length)
55
+ : m_is8Bit(true), m_length(length), m_characters8(characters) {}
56
+
57
+ StringView(const uint16_t* characters, size_t length)
58
+ : m_is8Bit(false), m_length(length), m_characters16(characters) {}
59
+
60
+ bool is8Bit() const { return m_is8Bit; }
61
+ size_t length() const { return m_length; }
62
+
63
+ // TODO(dgozman): add DCHECK(m_is8Bit) to accessors once platform can be used
64
+ // here.
65
+ const uint8_t* characters8() const { return m_characters8; }
66
+ const uint16_t* characters16() const { return m_characters16; }
67
+
68
+ private:
69
+ bool m_is8Bit;
70
+ size_t m_length;
71
+ union {
72
+ const uint8_t* m_characters8;
73
+ const uint16_t* m_characters16;
74
+ };
75
+ };
76
+
77
+ class V8_EXPORT StringBuffer {
78
+ public:
79
+ virtual ~StringBuffer() = default;
80
+ virtual StringView string() const = 0;
81
+ // This method copies contents.
82
+ static std::unique_ptr<StringBuffer> create(StringView);
83
+ };
84
+
85
+ class V8_EXPORT V8ContextInfo {
86
+ public:
87
+ V8ContextInfo(v8::Local<v8::Context> context, int contextGroupId,
88
+ StringView humanReadableName)
89
+ : context(context),
90
+ contextGroupId(contextGroupId),
91
+ humanReadableName(humanReadableName),
92
+ hasMemoryOnConsole(false) {}
93
+
94
+ v8::Local<v8::Context> context;
95
+ // Each v8::Context is a part of a group. The group id must be non-zero.
96
+ int contextGroupId;
97
+ StringView humanReadableName;
98
+ StringView origin;
99
+ StringView auxData;
100
+ bool hasMemoryOnConsole;
101
+
102
+ static int executionContextId(v8::Local<v8::Context> context);
103
+
104
+ // Disallow copying and allocating this one.
105
+ enum NotNullTagEnum { NotNullLiteral };
106
+ void* operator new(size_t) = delete;
107
+ void* operator new(size_t, NotNullTagEnum, void*) = delete;
108
+ void* operator new(size_t, void*) = delete;
109
+ V8ContextInfo(const V8ContextInfo&) = delete;
110
+ V8ContextInfo& operator=(const V8ContextInfo&) = delete;
111
+ };
112
+
113
+ // This debugger id tries to be unique by generating two random
114
+ // numbers, which should most likely avoid collisions.
115
+ // Debugger id has a 1:1 mapping to context group. It is used to
116
+ // attribute stack traces to a particular debugging, when doing any
117
+ // cross-debugger operations (e.g. async step in).
118
+ // See also Runtime.UniqueDebuggerId in the protocol.
119
+ class V8_EXPORT V8DebuggerId {
120
+ public:
121
+ V8DebuggerId() = default;
122
+ V8DebuggerId(const V8DebuggerId&) = default;
123
+ V8DebuggerId& operator=(const V8DebuggerId&) = default;
124
+
125
+ std::unique_ptr<StringBuffer> toString() const;
126
+ bool isValid() const;
127
+ std::pair<int64_t, int64_t> pair() const;
128
+
129
+ private:
130
+ friend class internal::V8DebuggerId;
131
+ explicit V8DebuggerId(std::pair<int64_t, int64_t>);
132
+
133
+ int64_t m_first = 0;
134
+ int64_t m_second = 0;
135
+ };
136
+
137
+ class V8_EXPORT V8StackTrace {
138
+ public:
139
+ virtual StringView firstNonEmptySourceURL() const = 0;
140
+ virtual bool isEmpty() const = 0;
141
+ virtual StringView topSourceURL() const = 0;
142
+ virtual int topLineNumber() const = 0;
143
+ virtual int topColumnNumber() const = 0;
144
+ virtual int topScriptId() const = 0;
145
+ virtual StringView topFunctionName() const = 0;
146
+
147
+ virtual ~V8StackTrace() = default;
148
+ virtual std::unique_ptr<protocol::Runtime::API::StackTrace>
149
+ buildInspectorObject(int maxAsyncDepth) const = 0;
150
+ virtual std::unique_ptr<StringBuffer> toString() const = 0;
151
+
152
+ // Safe to pass between threads, drops async chain.
153
+ virtual std::unique_ptr<V8StackTrace> clone() = 0;
154
+ };
155
+
156
+ class V8_EXPORT V8InspectorSession {
157
+ public:
158
+ virtual ~V8InspectorSession() = default;
159
+
160
+ // Cross-context inspectable values (DOM nodes in different worlds, etc.).
161
+ class V8_EXPORT Inspectable {
162
+ public:
163
+ virtual v8::Local<v8::Value> get(v8::Local<v8::Context>) = 0;
164
+ virtual ~Inspectable() = default;
165
+ };
166
+ class V8_EXPORT CommandLineAPIScope {
167
+ public:
168
+ virtual ~CommandLineAPIScope() = default;
169
+ };
170
+ virtual void addInspectedObject(std::unique_ptr<Inspectable>) = 0;
171
+
172
+ // Dispatching protocol messages.
173
+ static bool canDispatchMethod(StringView method);
174
+ virtual void dispatchProtocolMessage(StringView message) = 0;
175
+ virtual std::vector<uint8_t> state() = 0;
176
+ virtual std::vector<std::unique_ptr<protocol::Schema::API::Domain>>
177
+ supportedDomains() = 0;
178
+
179
+ virtual std::unique_ptr<V8InspectorSession::CommandLineAPIScope>
180
+ initializeCommandLineAPIScope(int executionContextId) = 0;
181
+
182
+ // Debugger actions.
183
+ virtual void schedulePauseOnNextStatement(StringView breakReason,
184
+ StringView breakDetails) = 0;
185
+ virtual void cancelPauseOnNextStatement() = 0;
186
+ virtual void breakProgram(StringView breakReason,
187
+ StringView breakDetails) = 0;
188
+ virtual void setSkipAllPauses(bool) = 0;
189
+ virtual void resume(bool setTerminateOnResume = false) = 0;
190
+ virtual void stepOver() = 0;
191
+ virtual std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>>
192
+ searchInTextByLines(StringView text, StringView query, bool caseSensitive,
193
+ bool isRegex) = 0;
194
+
195
+ // Remote objects.
196
+ virtual std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(
197
+ v8::Local<v8::Context>, v8::Local<v8::Value>, StringView groupName,
198
+ bool generatePreview) = 0;
199
+
200
+ virtual bool unwrapObject(std::unique_ptr<StringBuffer>* error,
201
+ StringView objectId, v8::Local<v8::Value>*,
202
+ v8::Local<v8::Context>*,
203
+ std::unique_ptr<StringBuffer>* objectGroup) = 0;
204
+ virtual void releaseObjectGroup(StringView) = 0;
205
+ virtual void triggerPreciseCoverageDeltaUpdate(StringView occasion) = 0;
206
+ };
207
+
208
+ class V8_EXPORT V8InspectorClient {
209
+ public:
210
+ virtual ~V8InspectorClient() = default;
211
+
212
+ virtual void runMessageLoopOnPause(int contextGroupId) {}
213
+ virtual void quitMessageLoopOnPause() {}
214
+ virtual void runIfWaitingForDebugger(int contextGroupId) {}
215
+
216
+ virtual void muteMetrics(int contextGroupId) {}
217
+ virtual void unmuteMetrics(int contextGroupId) {}
218
+
219
+ virtual void beginUserGesture() {}
220
+ virtual void endUserGesture() {}
221
+
222
+ virtual std::unique_ptr<StringBuffer> valueSubtype(v8::Local<v8::Value>) {
223
+ return nullptr;
224
+ }
225
+ virtual std::unique_ptr<StringBuffer> descriptionForValueSubtype(
226
+ v8::Local<v8::Context>, v8::Local<v8::Value>) {
227
+ return nullptr;
228
+ }
229
+ virtual bool isInspectableHeapObject(v8::Local<v8::Object>) { return true; }
230
+
231
+ virtual v8::Local<v8::Context> ensureDefaultContextInGroup(
232
+ int contextGroupId) {
233
+ return v8::Local<v8::Context>();
234
+ }
235
+ virtual void beginEnsureAllContextsInGroup(int contextGroupId) {}
236
+ virtual void endEnsureAllContextsInGroup(int contextGroupId) {}
237
+
238
+ virtual void installAdditionalCommandLineAPI(v8::Local<v8::Context>,
239
+ v8::Local<v8::Object>) {}
240
+ virtual void consoleAPIMessage(int contextGroupId,
241
+ v8::Isolate::MessageErrorLevel level,
242
+ const StringView& message,
243
+ const StringView& url, unsigned lineNumber,
244
+ unsigned columnNumber, V8StackTrace*) {}
245
+ virtual v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate*,
246
+ v8::Local<v8::Context>) {
247
+ return v8::MaybeLocal<v8::Value>();
248
+ }
249
+
250
+ virtual void consoleTime(const StringView& title) {}
251
+ virtual void consoleTimeEnd(const StringView& title) {}
252
+ virtual void consoleTimeStamp(const StringView& title) {}
253
+ virtual void consoleClear(int contextGroupId) {}
254
+ virtual double currentTimeMS() { return 0; }
255
+ typedef void (*TimerCallback)(void*);
256
+ virtual void startRepeatingTimer(double, TimerCallback, void* data) {}
257
+ virtual void cancelTimer(void* data) {}
258
+
259
+ // TODO(dgozman): this was added to support service worker shadow page. We
260
+ // should not connect at all.
261
+ virtual bool canExecuteScripts(int contextGroupId) { return true; }
262
+
263
+ virtual void maxAsyncCallStackDepthChanged(int depth) {}
264
+
265
+ virtual std::unique_ptr<StringBuffer> resourceNameToUrl(
266
+ const StringView& resourceName) {
267
+ return nullptr;
268
+ }
269
+
270
+ // The caller would defer to generating a random 64 bit integer if
271
+ // this method returns 0.
272
+ virtual int64_t generateUniqueId() { return 0; }
273
+ };
274
+
275
+ // These stack trace ids are intended to be passed between debuggers and be
276
+ // resolved later. This allows to track cross-debugger calls and step between
277
+ // them if a single client connects to multiple debuggers.
278
+ struct V8_EXPORT V8StackTraceId {
279
+ uintptr_t id;
280
+ std::pair<int64_t, int64_t> debugger_id;
281
+ bool should_pause = false;
282
+
283
+ V8StackTraceId();
284
+ V8StackTraceId(const V8StackTraceId&) = default;
285
+ V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id);
286
+ V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id,
287
+ bool should_pause);
288
+ explicit V8StackTraceId(StringView);
289
+ V8StackTraceId& operator=(const V8StackTraceId&) = default;
290
+ V8StackTraceId& operator=(V8StackTraceId&&) noexcept = default;
291
+ ~V8StackTraceId() = default;
292
+
293
+ bool IsInvalid() const;
294
+ std::unique_ptr<StringBuffer> ToString();
295
+ };
296
+
297
+ class V8_EXPORT V8Inspector {
298
+ public:
299
+ static std::unique_ptr<V8Inspector> create(v8::Isolate*, V8InspectorClient*);
300
+ virtual ~V8Inspector() = default;
301
+
302
+ // Contexts instrumentation.
303
+ virtual void contextCreated(const V8ContextInfo&) = 0;
304
+ virtual void contextDestroyed(v8::Local<v8::Context>) = 0;
305
+ virtual void resetContextGroup(int contextGroupId) = 0;
306
+ virtual v8::MaybeLocal<v8::Context> contextById(int contextId) = 0;
307
+ virtual V8DebuggerId uniqueDebuggerId(int contextId) = 0;
308
+
309
+ // Various instrumentation.
310
+ virtual void idleStarted() = 0;
311
+ virtual void idleFinished() = 0;
312
+
313
+ // Async stack traces instrumentation.
314
+ virtual void asyncTaskScheduled(StringView taskName, void* task,
315
+ bool recurring) = 0;
316
+ virtual void asyncTaskCanceled(void* task) = 0;
317
+ virtual void asyncTaskStarted(void* task) = 0;
318
+ virtual void asyncTaskFinished(void* task) = 0;
319
+ virtual void allAsyncTasksCanceled() = 0;
320
+
321
+ virtual V8StackTraceId storeCurrentStackTrace(StringView description) = 0;
322
+ virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0;
323
+ virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0;
324
+
325
+ // Exceptions instrumentation.
326
+ virtual unsigned exceptionThrown(v8::Local<v8::Context>, StringView message,
327
+ v8::Local<v8::Value> exception,
328
+ StringView detailedMessage, StringView url,
329
+ unsigned lineNumber, unsigned columnNumber,
330
+ std::unique_ptr<V8StackTrace>,
331
+ int scriptId) = 0;
332
+ virtual void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
333
+ StringView message) = 0;
334
+ virtual bool associateExceptionData(v8::Local<v8::Context>,
335
+ v8::Local<v8::Value> exception,
336
+ v8::Local<v8::Name> key,
337
+ v8::Local<v8::Value> value) = 0;
338
+
339
+ // Connection.
340
+ class V8_EXPORT Channel {
341
+ public:
342
+ virtual ~Channel() = default;
343
+ virtual void sendResponse(int callId,
344
+ std::unique_ptr<StringBuffer> message) = 0;
345
+ virtual void sendNotification(std::unique_ptr<StringBuffer> message) = 0;
346
+ virtual void flushProtocolNotifications() = 0;
347
+ };
348
+ virtual std::unique_ptr<V8InspectorSession> connect(int contextGroupId,
349
+ Channel*,
350
+ StringView state) = 0;
351
+
352
+ // API methods.
353
+ virtual std::unique_ptr<V8StackTrace> createStackTrace(
354
+ v8::Local<v8::StackTrace>) = 0;
355
+ virtual std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) = 0;
356
+ };
357
+
358
+ } // namespace v8_inspector
359
+
360
+ #endif // V8_V8_INSPECTOR_H_