@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,106 @@
1
+ #pragma once
2
+ #include "isolate/remote_handle.h"
3
+ #include "transferable.h"
4
+ #include <v8.h>
5
+ #include <memory>
6
+ #include <utility>
7
+ #include <vector>
8
+
9
+ namespace ivm {
10
+ namespace detail {
11
+
12
+ /**
13
+ * Holds common data for ReferenceHandle and ReferenceHandleTransferable
14
+ */
15
+ class ReferenceData {
16
+ friend class AccessorRunner;
17
+ public:
18
+ enum class TypeOf { Null, Undefined, Number, String, Boolean, Object, Function };
19
+
20
+ explicit ReferenceData(v8::Local<v8::Value> value, bool inherit = false);
21
+ ReferenceData(
22
+ std::shared_ptr<IsolateHolder> isolate,
23
+ RemoteHandle<v8::Value> reference,
24
+ RemoteHandle<v8::Context> context,
25
+ TypeOf type_of,
26
+ bool accessors,
27
+ bool inherit
28
+ );
29
+
30
+ protected:
31
+ std::shared_ptr<IsolateHolder> isolate;
32
+ RemoteHandle<v8::Value> reference;
33
+ RemoteHandle<v8::Context> context;
34
+ TypeOf type_of;
35
+ bool accessors;
36
+ bool inherit;
37
+ };
38
+
39
+ } // namespace detail
40
+
41
+ /**
42
+ * This will be a reference to any v8 Value in any isolate.
43
+ */
44
+ class ReferenceHandle : public TransferableHandle, public detail::ReferenceData {
45
+ friend class ApplyRunner;
46
+ friend class CopyRunner;
47
+ friend class AccessorRunner;
48
+ friend class GetRunner;
49
+ public:
50
+ using TypeOf = detail::ReferenceData::TypeOf;
51
+
52
+ template <class ...Args>
53
+ explicit ReferenceHandle(Args&&... args) : ReferenceData{std::forward<Args>(args)...} {}
54
+
55
+ static auto Definition() -> v8::Local<v8::FunctionTemplate>;
56
+ static auto New(v8::Local<v8::Value> value, v8::MaybeLocal<v8::Object> options)
57
+ -> std::unique_ptr<ReferenceHandle>;
58
+ auto TransferOut() -> std::unique_ptr<Transferable> final;
59
+
60
+ auto Deref(v8::MaybeLocal<v8::Object> maybe_options) -> v8::Local<v8::Value>;
61
+ auto DerefInto(v8::MaybeLocal<v8::Object> maybe_options) -> v8::Local<v8::Value>;
62
+ auto Release() -> v8::Local<v8::Value>;
63
+ auto TypeOfGetter() -> v8::Local<v8::Value>;
64
+
65
+ template <int async>
66
+ auto Apply(
67
+ v8::MaybeLocal<v8::Value> recv_handle,
68
+ v8::Maybe<ArrayRange> maybe_arguments,
69
+ v8::MaybeLocal<v8::Object> maybe_options
70
+ ) -> v8::Local<v8::Value>;
71
+
72
+ template <int async>
73
+ auto Copy() -> v8::Local<v8::Value>;
74
+
75
+ template <int async>
76
+ auto Get(
77
+ v8::Local<v8::Value> key_handle,
78
+ v8::MaybeLocal<v8::Object> maybe_options
79
+ ) -> v8::Local<v8::Value>;
80
+
81
+ template <int async>
82
+ auto Delete(v8::Local<v8::Value> key_handle) -> v8::Local<v8::Value>;
83
+
84
+ template <int async>
85
+ auto Set(
86
+ v8::Local<v8::Value> key_handle,
87
+ v8::Local<v8::Value> val_handle,
88
+ v8::MaybeLocal<v8::Object> maybe_options
89
+ ) -> v8::Local<v8::Value>;
90
+
91
+ private:
92
+ void CheckDisposed() const;
93
+ };
94
+
95
+ /**
96
+ * Instances of this turn into a ReferenceHandle when they are transferred in
97
+ */
98
+ class ReferenceHandleTransferable : public Transferable, public detail::ReferenceData {
99
+ public:
100
+ template <class ...Args>
101
+ explicit ReferenceHandleTransferable(Args&&... args) : ReferenceData{std::forward<Args>(args)...} {}
102
+
103
+ auto TransferIn() -> v8::Local<v8::Value> final;
104
+ };
105
+
106
+ } // namespace ivm
@@ -0,0 +1,107 @@
1
+ #include "isolate/run_with_timeout.h"
2
+ #include "isolate/three_phase_task.h"
3
+ #include "context_handle.h"
4
+ #include "script_handle.h"
5
+
6
+ using namespace v8;
7
+
8
+ namespace ivm {
9
+
10
+ /**
11
+ * ScriptHandle implementation
12
+ */
13
+ ScriptHandle::ScriptHandle(RemoteHandle<UnboundScript> script) :
14
+ script{std::move(script)} {}
15
+
16
+ auto ScriptHandle::Definition() -> Local<FunctionTemplate> {
17
+ return Inherit<TransferableHandle>(MakeClass(
18
+ "Script", nullptr,
19
+ "release", MemberFunction<decltype(&ScriptHandle::Release), &ScriptHandle::Release>{},
20
+ "run", MemberFunction<decltype(&ScriptHandle::Run<1>), &ScriptHandle::Run<1>>{},
21
+ "runIgnored", MemberFunction<decltype(&ScriptHandle::Run<2>), &ScriptHandle::Run<2>>{},
22
+ "runSync", MemberFunction<decltype(&ScriptHandle::Run<0>), &ScriptHandle::Run<0>>{}
23
+ ));
24
+ }
25
+
26
+ auto ScriptHandle::TransferOut() -> std::unique_ptr<Transferable> {
27
+ return std::make_unique<ScriptHandleTransferable>(script);
28
+ }
29
+
30
+ auto ScriptHandle::Release() -> Local<Value> {
31
+ script = {};
32
+ return Undefined(Isolate::GetCurrent());
33
+ }
34
+
35
+ /*
36
+ * Run this script in a given context
37
+ */
38
+ struct RunRunner /* lol */ : public ThreePhaseTask {
39
+ RunRunner(
40
+ RemoteHandle<UnboundScript>& script,
41
+ ContextHandle& context_handle,
42
+ MaybeLocal<Object> maybe_options
43
+ ) : context{context_handle.GetContext()} {
44
+ // Sanity check
45
+ if (!script) {
46
+ throw RuntimeGenericError("Script has been released");
47
+ }
48
+ if (script.GetIsolateHolder() != context.GetIsolateHolder()) {
49
+ throw RuntimeGenericError("Invalid context");
50
+ }
51
+
52
+ // Parse options
53
+ bool release = false;
54
+ Local<Object> options;
55
+ if (maybe_options.ToLocal(&options)) {
56
+ release = ReadOption<bool>(options, StringTable::Get().release, false);
57
+ timeout_ms = ReadOption<int32_t>(options, StringTable::Get().timeout, 0);
58
+ }
59
+ if (release) {
60
+ this->script = std::move(script);
61
+ } else {
62
+ this->script = script;
63
+ }
64
+ transfer_options = TransferOptions{maybe_options};
65
+ }
66
+
67
+ void Phase2() final {
68
+ // Enter script's context and run it
69
+ Local<Context> context_local = Deref(context);
70
+ Context::Scope context_scope{context_local};
71
+ Local<Script> script_handle = Deref(script)->BindToCurrentContext();
72
+ Local<Value> script_result = RunWithTimeout(timeout_ms, [&script_handle, &context_local]() {
73
+ return script_handle->Run(context_local);
74
+ });
75
+ result = OptionalTransferOut(script_result, transfer_options);
76
+ }
77
+
78
+ auto Phase3() -> Local<Value> final {
79
+ if (result) {
80
+ return result->TransferIn();
81
+ } else {
82
+ return Undefined(Isolate::GetCurrent()).As<Value>();
83
+ }
84
+ }
85
+
86
+ RemoteHandle<UnboundScript> script;
87
+ RemoteHandle<Context> context;
88
+ TransferOptions transfer_options;
89
+ std::unique_ptr<Transferable> result;
90
+ uint32_t timeout_ms = 0;
91
+ };
92
+ template <int async>
93
+ auto ScriptHandle::Run(ContextHandle& context_handle, MaybeLocal<Object> maybe_options) -> Local<Value> {
94
+ return ThreePhaseTask::Run<async, RunRunner>(*script.GetIsolateHolder(), script, context_handle, maybe_options);
95
+ }
96
+
97
+ /**
98
+ * ScriptHandleTransferable implementation
99
+ */
100
+ ScriptHandle::ScriptHandleTransferable::ScriptHandleTransferable(RemoteHandle<UnboundScript> script) :
101
+ script{std::move(script)} {}
102
+
103
+ auto ScriptHandle::ScriptHandleTransferable::TransferIn() -> Local<Value> {
104
+ return ClassHandle::NewInstance<ScriptHandle>(script);
105
+ };
106
+
107
+ } // namespace ivm
@@ -0,0 +1,37 @@
1
+ #pragma once
2
+ #include "isolate/remote_handle.h"
3
+ #include "transferable.h"
4
+ #include "transferable.h"
5
+ #include <v8.h>
6
+ #include <memory>
7
+
8
+ namespace ivm {
9
+
10
+ class ContextHandle;
11
+
12
+ class ScriptHandle : public TransferableHandle {
13
+ public:
14
+ using DontFreezeInstance = void;
15
+
16
+ explicit ScriptHandle(RemoteHandle<v8::UnboundScript> script);
17
+ static auto Definition() -> v8::Local<v8::FunctionTemplate>;
18
+
19
+ auto TransferOut() -> std::unique_ptr<Transferable> final;
20
+
21
+ auto Release() -> v8::Local<v8::Value>;
22
+ template <int async>
23
+ auto Run(ContextHandle& context_handle, v8::MaybeLocal<v8::Object> maybe_options) -> v8::Local<v8::Value>;
24
+
25
+ private:
26
+ class ScriptHandleTransferable : public Transferable {
27
+ public:
28
+ explicit ScriptHandleTransferable(RemoteHandle<v8::UnboundScript> script);
29
+ auto TransferIn() -> v8::Local<v8::Value> final;
30
+ private:
31
+ RemoteHandle<v8::UnboundScript> script;
32
+ };
33
+
34
+ RemoteHandle<v8::UnboundScript> script;
35
+ };
36
+
37
+ } // namespace ivm
@@ -0,0 +1,173 @@
1
+ #include "session_handle.h"
2
+ #include "isolate/remote_handle.h"
3
+ #include "isolate/util.h"
4
+
5
+ using namespace v8;
6
+ using namespace v8_inspector;
7
+ using std::shared_ptr;
8
+ using std::unique_ptr;
9
+
10
+ namespace ivm {
11
+
12
+ /**
13
+ * This class handles sending messages from the backend to the frontend
14
+ */
15
+ class SessionImpl : public InspectorSession {
16
+ public:
17
+ shared_ptr<IsolateHolder> isolate; // This is the isolate that owns the session
18
+ RemoteHandle<Function> onNotification;
19
+ RemoteHandle<Function> onResponse;
20
+
21
+ explicit SessionImpl(IsolateEnvironment& isolate) : InspectorSession(isolate) {}
22
+
23
+ private:
24
+ // Helper
25
+ static auto bufferToString(StringBuffer& buffer) -> MaybeLocal<String> {
26
+ const StringView& view = buffer.string();
27
+ if (view.is8Bit()) {
28
+ return String::NewFromOneByte(Isolate::GetCurrent(), view.characters8(), NewStringType::kNormal, view.length());
29
+ } else {
30
+ return String::NewFromTwoByte(Isolate::GetCurrent(), view.characters16(), NewStringType::kNormal, view.length());
31
+ }
32
+ }
33
+
34
+ // These functions are invoked directly from v8
35
+ void sendResponse(int call_id, unique_ptr<StringBuffer> message) final {
36
+ if (!onResponse) {
37
+ return;
38
+ }
39
+ struct SendResponseTask : public Runnable {
40
+ int call_id;
41
+ unique_ptr<StringBuffer> message;
42
+ RemoteHandle<Function> onResponse;
43
+
44
+ SendResponseTask(
45
+ int call_id, unique_ptr<StringBuffer> message, RemoteHandle<Function> onResponse
46
+ ) : call_id(call_id), message(std::move(message)), onResponse(std::move(onResponse)) {}
47
+
48
+ void Run() final {
49
+ Isolate* isolate = Isolate::GetCurrent();
50
+ TryCatch try_catch(isolate);
51
+ Local<String> string;
52
+ if (bufferToString(*message).ToLocal(&string)) {
53
+ Local<Function> fn = Deref(onResponse);
54
+ Local<Value> argv[2];
55
+ argv[0] = Integer::New(isolate, call_id);
56
+ argv[1] = string;
57
+ try {
58
+ Unmaybe(fn->Call(isolate->GetCurrentContext(), Undefined(isolate), 2, argv));
59
+ } catch (const RuntimeError& err) {}
60
+ }
61
+ }
62
+ };
63
+ isolate->ScheduleTask(std::make_unique<SendResponseTask>(call_id, std::move(message), onResponse), false, true);
64
+ }
65
+
66
+ void sendNotification(unique_ptr<StringBuffer> message) final {
67
+ if (!onNotification) {
68
+ return;
69
+ }
70
+ struct SendNotificationTask : public Runnable {
71
+ unique_ptr<StringBuffer> message;
72
+ RemoteHandle<Function> onNotification;
73
+ SendNotificationTask(
74
+ unique_ptr<StringBuffer> message, RemoteHandle<Function> onNotification
75
+ ) : message(std::move(message)), onNotification(std::move(onNotification)) {}
76
+
77
+ void Run() final {
78
+ Isolate* isolate = Isolate::GetCurrent();
79
+ TryCatch try_catch(isolate);
80
+ Local<String> string;
81
+ if (bufferToString(*message).ToLocal(&string)) {
82
+ Local<Function> fn = Deref(onNotification);
83
+ Local<Value> argv[1];
84
+ argv[0] = string;
85
+ try {
86
+ Unmaybe(fn->Call(isolate->GetCurrentContext(), Undefined(isolate), 1, argv));
87
+ } catch (const RuntimeError& err) {}
88
+ }
89
+ }
90
+ };
91
+ isolate->ScheduleTask(std::make_unique<SendNotificationTask>(std::move(message), onNotification), false, true);
92
+ }
93
+
94
+ void flushProtocolNotifications() final {}
95
+ };
96
+
97
+ /**
98
+ * SessionHandle implementation
99
+ */
100
+ SessionHandle::SessionHandle(IsolateEnvironment& isolate) : session(std::make_shared<SessionImpl>(isolate)) {
101
+ session->isolate = IsolateEnvironment::GetCurrentHolder();
102
+ }
103
+
104
+ auto SessionHandle::Definition() -> Local<FunctionTemplate> {
105
+ return MakeClass(
106
+ "Session", nullptr,
107
+ "dispatchProtocolMessage", MemberFunction<decltype(&SessionHandle::DispatchProtocolMessage), &SessionHandle::DispatchProtocolMessage>{},
108
+ "dispose", MemberFunction<decltype(&SessionHandle::Dispose), &SessionHandle::Dispose>{},
109
+ "onNotification", MemberAccessor<
110
+ decltype(&SessionHandle::OnNotificationGetter), &SessionHandle::OnNotificationGetter,
111
+ decltype(&SessionHandle::OnNotificationSetter), &SessionHandle::OnNotificationSetter
112
+ >{},
113
+ "onResponse", MemberAccessor<
114
+ decltype(&SessionHandle::OnResponseGetter), &SessionHandle::OnResponseGetter,
115
+ decltype(&SessionHandle::OnResponseSetter), &SessionHandle::OnResponseSetter
116
+ >{}
117
+ );
118
+ }
119
+
120
+ void SessionHandle::CheckDisposed() {
121
+ if (!session) {
122
+ throw RuntimeGenericError("Session is dead");
123
+ }
124
+ }
125
+
126
+ /**
127
+ * JS API methods
128
+ */
129
+ auto SessionHandle::DispatchProtocolMessage(Local<String> message) -> Local<Value> {
130
+ Isolate* isolate = Isolate::GetCurrent();
131
+ CheckDisposed();
132
+ String::Value v8_str{isolate, message};
133
+ session->DispatchBackendProtocolMessage(std::vector<uint16_t>(*v8_str, *v8_str + v8_str.length()));
134
+ return Undefined(isolate);
135
+ }
136
+
137
+ auto SessionHandle::Dispose() -> Local<Value> {
138
+ CheckDisposed();
139
+ session.reset();
140
+ return Undefined(Isolate::GetCurrent());
141
+ }
142
+
143
+ // .onNotification
144
+ auto SessionHandle::OnNotificationGetter() -> Local<Value> {
145
+ CheckDisposed();
146
+ if (session->onNotification) {
147
+ return Deref(session->onNotification);
148
+ } else {
149
+ return Undefined(Isolate::GetCurrent());
150
+ }
151
+ }
152
+
153
+ void SessionHandle::OnNotificationSetter(Local<Function> value) {
154
+ CheckDisposed();
155
+ session->onNotification = RemoteHandle<Function>(value);
156
+ }
157
+
158
+ // .onResponse
159
+ auto SessionHandle::OnResponseGetter() -> Local<Value> {
160
+ CheckDisposed();
161
+ if (session->onResponse) {
162
+ return Deref(session->onResponse);
163
+ } else {
164
+ return Undefined(Isolate::GetCurrent());
165
+ }
166
+ }
167
+
168
+ void SessionHandle::OnResponseSetter(Local<Function> value) {
169
+ CheckDisposed();
170
+ session->onResponse = RemoteHandle<Function>(value);
171
+ }
172
+
173
+ } // namespace ivm
@@ -0,0 +1,31 @@
1
+ #pragma once
2
+ #include <v8.h>
3
+ #include "isolate/class_handle.h"
4
+ #include "isolate/inspector.h"
5
+ #include <memory>
6
+
7
+ namespace ivm {
8
+
9
+ /**
10
+ * This handle is given to the client and encapsulates an inspector session. Non-transferable.
11
+ */
12
+ class SessionHandle : public ClassHandle {
13
+ private:
14
+ std::shared_ptr<class SessionImpl> session;
15
+
16
+ public:
17
+ using DontFreezePrototype = void;
18
+ using DontFreezeInstance = void;
19
+ explicit SessionHandle(IsolateEnvironment& isolate);
20
+ static auto Definition() -> v8::Local<v8::FunctionTemplate>;
21
+
22
+ void CheckDisposed();
23
+ auto DispatchProtocolMessage(v8::Local<v8::String> message) -> v8::Local<v8::Value>;
24
+ auto Dispose() -> v8::Local<v8::Value>;
25
+ auto OnNotificationGetter() -> v8::Local<v8::Value>;
26
+ void OnNotificationSetter(v8::Local<v8::Function> value);
27
+ auto OnResponseGetter() -> v8::Local<v8::Value>;
28
+ void OnResponseSetter(v8::Local<v8::Function> value);
29
+ };
30
+
31
+ } // namespace ivm