@nocobase/plugin-workflow-javascript 2.1.0-beta.26 → 2.1.0-beta.27

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 (139) hide show
  1. package/dist/externalVersion.js +4 -4
  2. package/dist/node_modules/joi/package.json +1 -1
  3. package/dist/node_modules/quickjs-emscripten/017c8a1a1898bfe7b7ae.wasm +0 -0
  4. package/dist/node_modules/quickjs-emscripten/161.index.js +50 -0
  5. package/dist/node_modules/quickjs-emscripten/277.index.js +27 -0
  6. package/dist/node_modules/quickjs-emscripten/302.index.js +55 -0
  7. package/dist/node_modules/quickjs-emscripten/45d53437811cf6eec760.wasm +0 -0
  8. package/dist/node_modules/quickjs-emscripten/712.index.js +5566 -0
  9. package/dist/node_modules/quickjs-emscripten/96b24985ab62871ec2a0.wasm +0 -0
  10. package/dist/node_modules/quickjs-emscripten/9a4b9654a8a7f4d515ba.wasm +0 -0
  11. package/dist/node_modules/quickjs-emscripten/LICENSE +21 -0
  12. package/dist/node_modules/quickjs-emscripten/dist/index.d.mts +57 -0
  13. package/dist/node_modules/quickjs-emscripten/dist/index.d.ts +57 -0
  14. package/dist/node_modules/quickjs-emscripten/dist/index.global.js +7309 -0
  15. package/dist/node_modules/quickjs-emscripten/dist/index.js +1 -0
  16. package/dist/node_modules/quickjs-emscripten/dist/variants.d.mts +39 -0
  17. package/dist/node_modules/quickjs-emscripten/dist/variants.d.ts +39 -0
  18. package/dist/node_modules/quickjs-emscripten/dist/variants.js +2 -0
  19. package/dist/node_modules/quickjs-emscripten/package.json +1 -0
  20. package/dist/node_modules/winston-transport/package.json +1 -1
  21. package/dist/server/QuickJs.js +135 -0
  22. package/dist/server/ScriptInstruction.d.ts +1 -1
  23. package/dist/server/ScriptInstruction.js +2 -2
  24. package/package.json +3 -8
  25. package/dist/node_modules/isolated-vm/.clang-tidy +0 -13
  26. package/dist/node_modules/isolated-vm/.dockerignore +0 -9
  27. package/dist/node_modules/isolated-vm/Dockerfile.alpine +0 -9
  28. package/dist/node_modules/isolated-vm/Dockerfile.debian +0 -12
  29. package/dist/node_modules/isolated-vm/LICENSE +0 -13
  30. package/dist/node_modules/isolated-vm/binding.gyp +0 -120
  31. package/dist/node_modules/isolated-vm/include.js +0 -3
  32. package/dist/node_modules/isolated-vm/inspector-example.js +0 -59
  33. package/dist/node_modules/isolated-vm/isolated-vm-6.1.2.tgz +0 -0
  34. package/dist/node_modules/isolated-vm/isolated-vm.d.ts +0 -820
  35. package/dist/node_modules/isolated-vm/isolated-vm.js +0 -1
  36. package/dist/node_modules/isolated-vm/native-example/binding.gyp +0 -23
  37. package/dist/node_modules/isolated-vm/native-example/example.cc +0 -61
  38. package/dist/node_modules/isolated-vm/native-example/package.json +0 -13
  39. package/dist/node_modules/isolated-vm/native-example/usage.js +0 -35
  40. package/dist/node_modules/isolated-vm/package.json +0 -1
  41. package/dist/node_modules/isolated-vm/prebuilds/darwin-arm64/isolated-vm.abi127.node +0 -0
  42. package/dist/node_modules/isolated-vm/prebuilds/darwin-arm64/isolated-vm.abi137.node +0 -0
  43. package/dist/node_modules/isolated-vm/prebuilds/linux-arm64/isolated-vm.abi127.glibc.node +0 -0
  44. package/dist/node_modules/isolated-vm/prebuilds/linux-arm64/isolated-vm.abi127.musl.node +0 -0
  45. package/dist/node_modules/isolated-vm/prebuilds/linux-arm64/isolated-vm.abi137.glibc.node +0 -0
  46. package/dist/node_modules/isolated-vm/prebuilds/linux-arm64/isolated-vm.abi137.musl.node +0 -0
  47. package/dist/node_modules/isolated-vm/prebuilds/linux-x64/isolated-vm.abi127.glibc.node +0 -0
  48. package/dist/node_modules/isolated-vm/prebuilds/linux-x64/isolated-vm.abi127.musl.node +0 -0
  49. package/dist/node_modules/isolated-vm/prebuilds/linux-x64/isolated-vm.abi137.glibc.node +0 -0
  50. package/dist/node_modules/isolated-vm/prebuilds/linux-x64/isolated-vm.abi137.musl.node +0 -0
  51. package/dist/node_modules/isolated-vm/prebuilds/win32-x64/isolated-vm.abi127.node +0 -0
  52. package/dist/node_modules/isolated-vm/prebuilds/win32-x64/isolated-vm.abi137.node +0 -0
  53. package/dist/node_modules/isolated-vm/scripts/run-prebuild.js +0 -33
  54. package/dist/node_modules/isolated-vm/src/external_copy/error.h +0 -33
  55. package/dist/node_modules/isolated-vm/src/external_copy/external_copy.cc +0 -509
  56. package/dist/node_modules/isolated-vm/src/external_copy/external_copy.h +0 -117
  57. package/dist/node_modules/isolated-vm/src/external_copy/serializer.cc +0 -85
  58. package/dist/node_modules/isolated-vm/src/external_copy/serializer.h +0 -136
  59. package/dist/node_modules/isolated-vm/src/external_copy/serializer_nortti.cc +0 -73
  60. package/dist/node_modules/isolated-vm/src/external_copy/string.cc +0 -124
  61. package/dist/node_modules/isolated-vm/src/external_copy/string.h +0 -28
  62. package/dist/node_modules/isolated-vm/src/isolate/allocator.h +0 -30
  63. package/dist/node_modules/isolated-vm/src/isolate/allocator_nortti.cc +0 -131
  64. package/dist/node_modules/isolated-vm/src/isolate/class_handle.h +0 -338
  65. package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.cc +0 -220
  66. package/dist/node_modules/isolated-vm/src/isolate/cpu_profile_manager.h +0 -100
  67. package/dist/node_modules/isolated-vm/src/isolate/environment.cc +0 -627
  68. package/dist/node_modules/isolated-vm/src/isolate/environment.h +0 -381
  69. package/dist/node_modules/isolated-vm/src/isolate/executor.cc +0 -198
  70. package/dist/node_modules/isolated-vm/src/isolate/executor.h +0 -183
  71. package/dist/node_modules/isolated-vm/src/isolate/external.h +0 -64
  72. package/dist/node_modules/isolated-vm/src/isolate/functor_runners.h +0 -97
  73. package/dist/node_modules/isolated-vm/src/isolate/generic/array.h +0 -145
  74. package/dist/node_modules/isolated-vm/src/isolate/generic/callbacks.h +0 -264
  75. package/dist/node_modules/isolated-vm/src/isolate/generic/error.h +0 -140
  76. package/dist/node_modules/isolated-vm/src/isolate/generic/extract_params.h +0 -145
  77. package/dist/node_modules/isolated-vm/src/isolate/generic/handle_cast.h +0 -257
  78. package/dist/node_modules/isolated-vm/src/isolate/generic/read_option.h +0 -47
  79. package/dist/node_modules/isolated-vm/src/isolate/holder.cc +0 -88
  80. package/dist/node_modules/isolated-vm/src/isolate/holder.h +0 -69
  81. package/dist/node_modules/isolated-vm/src/isolate/inspector.cc +0 -200
  82. package/dist/node_modules/isolated-vm/src/isolate/inspector.h +0 -70
  83. package/dist/node_modules/isolated-vm/src/isolate/node_wrapper.h +0 -15
  84. package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.cc +0 -22
  85. package/dist/node_modules/isolated-vm/src/isolate/platform_delegate.h +0 -46
  86. package/dist/node_modules/isolated-vm/src/isolate/remote_handle.h +0 -164
  87. package/dist/node_modules/isolated-vm/src/isolate/run_with_timeout.h +0 -171
  88. package/dist/node_modules/isolated-vm/src/isolate/runnable.h +0 -29
  89. package/dist/node_modules/isolated-vm/src/isolate/scheduler.cc +0 -191
  90. package/dist/node_modules/isolated-vm/src/isolate/scheduler.h +0 -165
  91. package/dist/node_modules/isolated-vm/src/isolate/specific.h +0 -35
  92. package/dist/node_modules/isolated-vm/src/isolate/stack_trace.cc +0 -218
  93. package/dist/node_modules/isolated-vm/src/isolate/stack_trace.h +0 -24
  94. package/dist/node_modules/isolated-vm/src/isolate/strings.h +0 -127
  95. package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.cc +0 -385
  96. package/dist/node_modules/isolated-vm/src/isolate/three_phase_task.h +0 -136
  97. package/dist/node_modules/isolated-vm/src/isolate/transferable.h +0 -15
  98. package/dist/node_modules/isolated-vm/src/isolate/util.h +0 -45
  99. package/dist/node_modules/isolated-vm/src/isolate/v8_inspector_wrapper.h +0 -14
  100. package/dist/node_modules/isolated-vm/src/isolate/v8_version.h +0 -12
  101. package/dist/node_modules/isolated-vm/src/isolated_vm.h +0 -71
  102. package/dist/node_modules/isolated-vm/src/lib/covariant.h +0 -50
  103. package/dist/node_modules/isolated-vm/src/lib/lockable.h +0 -178
  104. package/dist/node_modules/isolated-vm/src/lib/suspend.h +0 -106
  105. package/dist/node_modules/isolated-vm/src/lib/thread_pool.cc +0 -98
  106. package/dist/node_modules/isolated-vm/src/lib/thread_pool.h +0 -45
  107. package/dist/node_modules/isolated-vm/src/lib/timer.cc +0 -233
  108. package/dist/node_modules/isolated-vm/src/lib/timer.h +0 -36
  109. package/dist/node_modules/isolated-vm/src/module/callback.cc +0 -155
  110. package/dist/node_modules/isolated-vm/src/module/callback.h +0 -64
  111. package/dist/node_modules/isolated-vm/src/module/context_handle.cc +0 -241
  112. package/dist/node_modules/isolated-vm/src/module/context_handle.h +0 -35
  113. package/dist/node_modules/isolated-vm/src/module/evaluation.cc +0 -108
  114. package/dist/node_modules/isolated-vm/src/module/evaluation.h +0 -99
  115. package/dist/node_modules/isolated-vm/src/module/external_copy_handle.cc +0 -125
  116. package/dist/node_modules/isolated-vm/src/module/external_copy_handle.h +0 -64
  117. package/dist/node_modules/isolated-vm/src/module/isolate.cc +0 -136
  118. package/dist/node_modules/isolated-vm/src/module/isolate_handle.cc +0 -623
  119. package/dist/node_modules/isolated-vm/src/module/isolate_handle.h +0 -47
  120. package/dist/node_modules/isolated-vm/src/module/lib_handle.cc +0 -77
  121. package/dist/node_modules/isolated-vm/src/module/lib_handle.h +0 -28
  122. package/dist/node_modules/isolated-vm/src/module/module_handle.cc +0 -475
  123. package/dist/node_modules/isolated-vm/src/module/module_handle.h +0 -68
  124. package/dist/node_modules/isolated-vm/src/module/native_module_handle.cc +0 -108
  125. package/dist/node_modules/isolated-vm/src/module/native_module_handle.h +0 -49
  126. package/dist/node_modules/isolated-vm/src/module/reference_handle.cc +0 -640
  127. package/dist/node_modules/isolated-vm/src/module/reference_handle.h +0 -106
  128. package/dist/node_modules/isolated-vm/src/module/script_handle.cc +0 -107
  129. package/dist/node_modules/isolated-vm/src/module/script_handle.h +0 -37
  130. package/dist/node_modules/isolated-vm/src/module/session_handle.cc +0 -173
  131. package/dist/node_modules/isolated-vm/src/module/session_handle.h +0 -31
  132. package/dist/node_modules/isolated-vm/src/module/transferable.cc +0 -268
  133. package/dist/node_modules/isolated-vm/src/module/transferable.h +0 -42
  134. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.0.0.h +0 -360
  135. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v18.3.0.h +0 -376
  136. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v20.0.0.h +0 -397
  137. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v22.0.0.h +0 -419
  138. package/dist/node_modules/isolated-vm/vendor/v8_inspector/nodejs_v24.0.0.h +0 -426
  139. package/dist/server/IsolatedVm.js +0 -75
@@ -1,106 +0,0 @@
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
@@ -1,107 +0,0 @@
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
@@ -1,37 +0,0 @@
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
@@ -1,173 +0,0 @@
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
@@ -1,31 +0,0 @@
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