@nocobase/plugin-workflow-javascript 2.1.0-beta.25 → 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,191 +0,0 @@
1
- #include "environment.h"
2
- #include "executor.h"
3
- #include "node_wrapper.h"
4
- #include "scheduler.h"
5
- #include <memory>
6
- #include <v8.h>
7
- #include <utility>
8
-
9
- using namespace v8;
10
- namespace ivm {
11
- namespace {
12
- thread_pool_t thread_pool{std::thread::hardware_concurrency() + 1};
13
- }
14
-
15
- /*
16
- * Scheduler implementation
17
- */
18
- void Scheduler::CancelAsync() {
19
- if (async_wait != nullptr) {
20
- async_wait->Cancel();
21
- }
22
- }
23
-
24
- void Scheduler::DoneRunning() {
25
- assert(status == Status::Running);
26
- status = Status::Waiting;
27
- }
28
-
29
- void Scheduler::InterruptIsolate() {
30
- assert(status == Status::Running);
31
- // Since this callback will be called by v8 we can be certain the pointer to `isolate` is still valid
32
- env.GetIsolate()->RequestInterrupt([](Isolate* /*isolate_ptr*/, void* env_ptr) {
33
- static_cast<IsolateEnvironment*>(env_ptr)->InterruptEntryAsync();
34
- }, &env);
35
- }
36
-
37
- void Scheduler::InterruptSyncIsolate() {
38
- env.GetIsolate()->RequestInterrupt([](Isolate* /*isolate_ptr*/, void* env_ptr) {
39
- static_cast<IsolateEnvironment*>(env_ptr)->InterruptEntrySync();
40
- }, &env);
41
- }
42
-
43
- auto Scheduler::WakeIsolate(std::shared_ptr<IsolateEnvironment> isolate_ptr) -> bool {
44
- if (status == Status::Waiting) {
45
- status = Status::Running;
46
- // Move shared reference to this scheduler to ensure the IsolateEnvironment won't be deleted
47
- // before a thread picks up this work.
48
- assert(!env_ref);
49
- env_ref = std::move(isolate_ptr);
50
- IncrementUvRef();
51
- SendWake();
52
- return true;
53
- } else {
54
- return false;
55
- }
56
- }
57
-
58
- auto LockedScheduler::GetForegroundTaskRunner() -> std::shared_ptr<v8::TaskRunner> {
59
- return env.GetTaskRunner();
60
- }
61
-
62
- void LockedScheduler::DecrementUvRefForIsolate(const std::shared_ptr<IsolateHolder>& holder) {
63
- auto ref = holder->GetIsolate();
64
- if (ref) {
65
- ref->scheduler->DecrementUvRef();
66
- }
67
- }
68
-
69
- void LockedScheduler::IncrementUvRefForIsolate(const std::shared_ptr<IsolateHolder>& holder) {
70
- auto ref = holder->GetIsolate();
71
- if (ref) {
72
- ref->scheduler->IncrementUvRef();
73
- }
74
- }
75
-
76
- IsolatedScheduler::IsolatedScheduler(IsolateEnvironment& env, UvScheduler& default_scheduler) :
77
- LockedScheduler{env},
78
- default_scheduler{default_scheduler} {}
79
-
80
- void IsolatedScheduler::DecrementUvRef() {
81
- default_scheduler.DecrementUvRef();
82
- }
83
-
84
- void IsolatedScheduler::IncrementUvRef() {
85
- default_scheduler.IncrementUvRef();
86
- }
87
-
88
- void IsolatedScheduler::SendWake() {
89
- thread_pool.exec(thread_affinity, [](bool pool_thread, void* param) {
90
- auto& scheduler = *static_cast<IsolatedScheduler*>(param);
91
- auto ref = std::exchange(scheduler.env_ref, {});
92
- ref->AsyncEntry();
93
- if (!pool_thread) {
94
- ref->GetIsolate()->DiscardThreadSpecificMetadata();
95
- }
96
- // Grab reference to default scheduler, since resetting `ref` may deallocate `scheduler` and
97
- // invalidate the instance. Resetting `ref` must take place here because the destructor might
98
- // invoke cleanup tasks on the default isolate which will increment `uv_ref_count`.
99
- // `uv_ref_count` needs to be incremented before it's decremented otherwise `UvScheduler` will
100
- // try to invoke `uv_ref` from a non-default thread.
101
- auto& default_scheduler = scheduler.default_scheduler;
102
- ref = {};
103
- if (--default_scheduler.uv_ref_count == 0) {
104
- // Wake up the libuv loop so we can unref the async handle from the default thread.
105
- uv_async_send(default_scheduler.uv_async);
106
- }
107
- }, this);
108
- }
109
-
110
- UvScheduler::UvScheduler(IsolateEnvironment& env) :
111
- LockedScheduler{env},
112
- loop{node::GetCurrentEventLoop(v8::Isolate::GetCurrent())},
113
- uv_async{new uv_async_t} {
114
- uv_async_init(loop, uv_async, [](uv_async_t* async) {
115
- auto& scheduler = *static_cast<UvScheduler*>(async->data);
116
- auto ref = [&]() {
117
- // Lock is required to access env_ref on the default scheduler but a non-default scheduler
118
- // doesn't need it. This is because `WakeIsolate` can trigger this function via
119
- // `uv_async_send` while another thread is writing to `env_ref`
120
- std::lock_guard<std::mutex> lock{scheduler.mutex};
121
- return std::exchange(scheduler.env_ref, {});
122
- }();
123
- if (ref) {
124
- ref->AsyncEntry();
125
- if (--scheduler.uv_ref_count == 0) {
126
- uv_unref(reinterpret_cast<uv_handle_t*>(scheduler.uv_async));
127
- }
128
- } else {
129
- if (scheduler.uv_ref_count.load() == 0) {
130
- uv_unref(reinterpret_cast<uv_handle_t*>(scheduler.uv_async));
131
- }
132
- }
133
- });
134
- uv_async->data = this;
135
- uv_unref(reinterpret_cast<uv_handle_t*>(uv_async));
136
- }
137
-
138
- UvScheduler::~UvScheduler() {
139
- uv_close(reinterpret_cast<uv_handle_t*>(uv_async), [](uv_handle_t* handle) {
140
- delete reinterpret_cast<uv_async_t*>(handle);
141
- });
142
- }
143
-
144
- void UvScheduler::DecrementUvRef() {
145
- if (--uv_ref_count == 0) {
146
- if (Executor::IsDefaultThread()) {
147
- uv_unref(reinterpret_cast<uv_handle_t*>(uv_async));
148
- } else {
149
- uv_async_send(uv_async);
150
- }
151
- }
152
- }
153
-
154
- void UvScheduler::IncrementUvRef() {
155
- if (++uv_ref_count == 1) {
156
- // Only the default thread should be able to reach this branch
157
- assert(Executor::IsDefaultThread());
158
- uv_ref(reinterpret_cast<uv_handle_t*>(uv_async));
159
- }
160
- }
161
-
162
- void UvScheduler::SendWake() {
163
- uv_async_send(uv_async);
164
- }
165
-
166
- /*
167
- * Scheduler::AsyncWait implementation
168
- */
169
- Scheduler::AsyncWait::~AsyncWait() {
170
- scheduler.Lock()->async_wait = nullptr;
171
- }
172
-
173
- void Scheduler::AsyncWait::Cancel() {
174
- *state.write() = canceled;
175
- state.notify_one();
176
- }
177
-
178
- void Scheduler::AsyncWait::Done() {
179
- *state.write() = finished;
180
- state.notify_one();
181
- }
182
-
183
- auto Scheduler::AsyncWait::Wait() const -> Scheduler::AsyncWait::State {
184
- auto lock = state.read<true>();
185
- while (*lock == pending) {
186
- lock.wait();
187
- }
188
- return *lock;
189
- }
190
-
191
- } // namespace ivm
@@ -1,165 +0,0 @@
1
- #pragma once
2
- #include "platform_delegate.h"
3
- #include "runnable.h"
4
- #include "lib/lockable.h"
5
- #include "lib/thread_pool.h"
6
- #include <uv.h>
7
- #include <atomic>
8
- #include <condition_variable>
9
- #include <memory>
10
- #include <mutex>
11
- #include <queue>
12
-
13
- namespace ivm {
14
- class IsolateEnvironment;
15
- class IsolateHolder;
16
-
17
- // gcc 5's std::queue implementation has an explicit default ctor so std::exchange(..., {})
18
- // doesn't work. This changed in C++11 and I guess they're behind.
19
- template <class Type>
20
- auto ExchangeDefault(Type& container) {
21
- return std::exchange(container, Type{});
22
- }
23
-
24
- /**
25
- * Keeps track of tasks an isolate needs to run and manages its run state (running or waiting).
26
- * This does all the interaction with libuv async and the thread pool.
27
- */
28
- class UvScheduler;
29
- class Scheduler {
30
- friend IsolateEnvironment;
31
- friend class LockedScheduler;
32
- private:
33
- using TaskQueue = std::queue<std::unique_ptr<Runnable>>;
34
-
35
- public:
36
- explicit Scheduler(IsolateEnvironment& env) : env{env} {}
37
- Scheduler(const Scheduler&) = delete;
38
- ~Scheduler() = default;
39
- auto operator=(const Scheduler&) = delete;
40
-
41
- // Request cancellation of current async task
42
- void CancelAsync();
43
- // Called after AsyncEntry finishes
44
- void DoneRunning();
45
- // Request an interrupt in this isolate. `status` must == Running to invoke this.
46
- void InterruptIsolate();
47
- // Interrupts an isolate running in the default thread
48
- void InterruptSyncIsolate();
49
- // Returns true if a wake was scheduled, false if the isolate is already running.
50
- auto WakeIsolate(std::shared_ptr<IsolateEnvironment> isolate_ptr) -> bool;
51
-
52
- // Scheduler::AsyncWait will pause the current thread until woken up by another thread
53
- class AsyncWait {
54
- public:
55
- enum State { pending, finished, canceled };
56
-
57
- // This is templated so we can cast to the protected base class here instead of at the call
58
- // site
59
- template <class Type>
60
- explicit AsyncWait(Type& scheduler) :
61
- scheduler{scheduler} {
62
- auto lock = scheduler.Lock();
63
- assert(lock->async_wait == nullptr);
64
- lock->async_wait = this;
65
- }
66
- AsyncWait(const AsyncWait&) = delete;
67
- ~AsyncWait();
68
- auto operator=(const AsyncWait&) = delete;
69
-
70
- void Cancel();
71
- void Done();
72
- auto Wait() const -> State;
73
-
74
- class LockedScheduler& scheduler;
75
- lockable_t<State, false, true> state{pending};
76
- };
77
-
78
- // Task queues
79
- TaskQueue tasks;
80
- TaskQueue handle_tasks;
81
- TaskQueue interrupts;
82
- TaskQueue sync_interrupts;
83
-
84
- protected:
85
- mutable std::mutex mutex;
86
- mutable std::condition_variable cv;
87
- std::shared_ptr<IsolateEnvironment> env_ref;
88
- IsolateEnvironment& env;
89
-
90
- private:
91
- virtual void IncrementUvRef() = 0;
92
- virtual void DecrementUvRef() = 0;
93
- virtual void SendWake() = 0;
94
-
95
- enum class Status { Waiting, Running };
96
- AsyncWait* async_wait = nullptr;
97
- Status status = Status::Waiting;
98
- };
99
-
100
- class LockedScheduler : protected Scheduler, public node::IsolatePlatformDelegate {
101
- friend Scheduler::AsyncWait;
102
- public:
103
- using Scheduler::Scheduler;
104
-
105
- // Locks the scheduler and return a lock with access to public interface
106
- auto Lock() {
107
- // TODO: Would be nice to find a way to roll this into the lockable abstraction
108
- class Lock {
109
- public:
110
- auto operator*() -> auto& { return scheduler; }
111
- auto operator->() { return &scheduler; }
112
-
113
- explicit Lock(Scheduler& scheduler, std::mutex& mutex) :
114
- lock{mutex},
115
- scheduler{scheduler} {}
116
-
117
- private:
118
- std::unique_lock<std::mutex> lock;
119
- Scheduler& scheduler;
120
- };
121
- return Lock{*this, mutex};
122
- }
123
-
124
- // IsolatePlatformDelegate overrides
125
- auto GetForegroundTaskRunner() -> std::shared_ptr<v8::TaskRunner> final;
126
- auto IdleTasksEnabled() -> bool final { return false; }
127
-
128
- // Used to ref/unref the uv handle from C++ API
129
- static void DecrementUvRefForIsolate(const std::shared_ptr<IsolateHolder>& holder);
130
- static void IncrementUvRefForIsolate(const std::shared_ptr<IsolateHolder>& holder);
131
- };
132
-
133
- class IsolatedScheduler final : public LockedScheduler {
134
- public:
135
- explicit IsolatedScheduler(IsolateEnvironment& env, UvScheduler& default_scheduler);
136
-
137
- private:
138
- void DecrementUvRef() override;
139
- void IncrementUvRef() override;
140
- void SendWake() override;
141
-
142
- thread_pool_t::affinity_t thread_affinity;
143
- UvScheduler& default_scheduler;
144
- };
145
-
146
- class UvScheduler final : public LockedScheduler {
147
- friend IsolatedScheduler;
148
- friend Scheduler;
149
- public:
150
- explicit UvScheduler(IsolateEnvironment& env);
151
- UvScheduler(const UvScheduler&) = delete;
152
- ~UvScheduler();
153
- auto operator=(const UvScheduler&) = delete;
154
-
155
- private:
156
- void DecrementUvRef() override;
157
- void IncrementUvRef() override;
158
- void SendWake() override;
159
-
160
- uv_loop_t* loop = nullptr;
161
- uv_async_t* uv_async = nullptr;
162
- std::atomic<int> uv_ref_count{0};
163
- };
164
-
165
- } // namespace ivm
@@ -1,35 +0,0 @@
1
- #pragma once
2
- #include <v8.h>
3
- #include <atomic>
4
-
5
- namespace ivm {
6
- namespace detail {
7
- extern std::atomic<size_t> IsolateSpecificSize;
8
- }
9
-
10
- /**
11
- * Like thread_local data, but specific to an Isolate instead.
12
- */
13
- template <class Type>
14
- class IsolateSpecific {
15
- template <class>
16
- friend class IsolateSpecific;
17
-
18
- public:
19
- IsolateSpecific() = default;
20
-
21
- template <class Functor>
22
- auto Deref(Functor callback) -> v8::Local<Type>;
23
-
24
- private:
25
- size_t key{detail::IsolateSpecificSize++};
26
- union HandleConvert {
27
- explicit HandleConvert(v8::Local<v8::Data> data) : data{data} {}
28
- v8::Local<v8::Data> data;
29
- v8::Local<Type> value;
30
- };
31
- };
32
-
33
- } // namespace ivm
34
-
35
- #include "environment.h"
@@ -1,218 +0,0 @@
1
- #include "stack_trace.h"
2
- #include "functor_runners.h"
3
- #include "specific.h"
4
- #include "v8_version.h"
5
- #include <cstring>
6
- #include <sstream>
7
- #include <string>
8
-
9
- using namespace v8;
10
-
11
- namespace ivm {
12
-
13
- static auto StringConcat(Isolate* isolate, Local<String> left, Local<String> right) -> Local<String> {
14
- return String::Concat(isolate, left, right);
15
- }
16
-
17
- /**
18
- * This returns an object that's like Symbol() in JS but only C++ can see it.
19
- */
20
- auto GetPrivateStackSymbol() -> Local<Private> {
21
- static IsolateSpecific<Private> holder;
22
- return holder.Deref([]() {
23
- return Private::New(Isolate::GetCurrent());
24
- });
25
- }
26
-
27
- /**
28
- * Helper which renders to string either a String (pass-through), StackTrace (render), or Array
29
- * (recursion pair)
30
- */
31
- auto RenderErrorStack(Local<Value> data) -> Local<String> {
32
- Isolate* isolate = Isolate::GetCurrent();
33
- if (data->IsString()) {
34
- // Plain string. We need to remove the first line of `stack` to avoid repeating the error
35
- // message
36
- String::Utf8Value string_value{isolate, data.As<String>()};
37
- const char* c_str = *string_value;
38
- // If it starts with " at" then the message has already been removed
39
- if (strncmp(c_str, " at", 6) == 0) {
40
- return data.As<String>();
41
- }
42
- // Find the newline
43
- const char* pos = strchr(c_str, '\n');
44
- while (pos != nullptr) {
45
- if (strncmp(pos + 1, " at", 6) == 0) {
46
- // Found the start of the stack
47
- return Unmaybe(String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(pos), NewStringType::kNormal));
48
- }
49
- pos = strchr(pos + 1, '\n');
50
- }
51
- // No stack, just a message
52
- return String::Empty(isolate);
53
-
54
- } else if (data->IsArray()) {
55
- // Array pair
56
- Local<Context> context = isolate->GetCurrentContext();
57
- Local<Array> array = data.As<Array>();
58
- return StringConcat(isolate,
59
- StringConcat(isolate,
60
- RenderErrorStack(Unmaybe(array->Get(context, 1))),
61
- Unmaybe(String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>("\n at (<isolated-vm boundary>)"), NewStringType::kNormal))
62
- ),
63
- RenderErrorStack(Unmaybe(array->Get(context, 0)))
64
- );
65
- } else {
66
- // StackTraceHolder
67
- StackTraceHolder& that = *ClassHandle::Unwrap<StackTraceHolder>(data.As<Object>());
68
- Local<StackTrace> stack_trace = Deref(that.stack_trace);
69
- return Unmaybe(String::NewFromUtf8(isolate, StackTraceHolder::RenderSingleStack(stack_trace).c_str(), NewStringType::kNormal));
70
- }
71
- }
72
-
73
- /**
74
- * Accessor on error `stack`. Renders from previously saved stack trace.
75
- */
76
- void ErrorStackGetter(Local<Name> /*property*/, const PropertyCallbackInfo<Value>& info) {
77
- FunctorRunners::RunCallback(info, [ &info ]() {
78
- Isolate* isolate = Isolate::GetCurrent();
79
- Local<Context> context = isolate->GetCurrentContext();
80
- Local<Object> holder = info.This();
81
- Local<Value> name = Unmaybe(holder->Get(context, StringTable::Get().name));
82
- if (!name->IsString()) {
83
- name = holder->GetConstructorName();
84
- }
85
- return StringConcat(isolate,
86
- StringConcat(isolate, name.As<String>(), StringTable::Get().colonSpace),
87
- StringConcat(isolate,
88
- Unmaybe(
89
- Unmaybe(info.This()->Get(context, StringTable::Get().message))->ToString(context)
90
- ),
91
- RenderErrorStack(Unmaybe(holder->GetPrivate(context, GetPrivateStackSymbol())))
92
- )
93
- );
94
- });
95
- }
96
-
97
- /**
98
- * Utility function which sets the stack getter on an error object
99
- */
100
- void AttachStackGetter(Local<Object> error, Local<Value> data) {
101
- Local<Context> context = Isolate::GetCurrent()->GetCurrentContext();
102
- Unmaybe(error->SetPrivate(context, GetPrivateStackSymbol(), data));
103
- Unmaybe(error->SetNativeDataProperty(
104
- context,
105
- StringTable::Get().stack,
106
- ErrorStackGetter, nullptr,
107
- Local<Value>(),
108
- PropertyAttribute::DontEnum
109
- ));
110
- }
111
-
112
- /**
113
- * StackTraceHolder implementation
114
- */
115
- StackTraceHolder::StackTraceHolder(Local<StackTrace> stack_handle) : stack_trace(Isolate::GetCurrent(), stack_handle) {}
116
-
117
- auto StackTraceHolder::Definition() -> Local<FunctionTemplate> {
118
- return MakeClass("StackTraceHolder", nullptr);
119
- }
120
-
121
- void StackTraceHolder::AttachStack(Local<Object> error, Local<StackTrace> stack) {
122
- AttachStackGetter(error, ClassHandle::NewInstance<StackTraceHolder>(stack));
123
- }
124
-
125
- void StackTraceHolder::ChainStack(Local<Object> error, Local<StackTrace> stack) {
126
- Isolate* isolate = Isolate::GetCurrent();
127
- Local<Context> context = isolate->GetCurrentContext();
128
- Local<Value> existing_data = Unmaybe(error->GetPrivate(context, GetPrivateStackSymbol()));
129
- if (existing_data->IsUndefined()) {
130
- // This error has not passed through ivm yet. Get the existing stack trace.
131
- Local<StackTrace> existing_stack = Exception::GetStackTrace(error);
132
- if (existing_stack.IsEmpty()) {
133
- // In this case it's probably passed through ExternalCopy which flattens the `stack` property
134
- // into a plain value
135
- existing_data = Unmaybe(error->Get(context, StringTable::Get().stack));
136
- if (existing_data->IsUndefined() || !existing_data->IsString()) {
137
- return AttachStack(error, stack);
138
- }
139
- } else {
140
- existing_data = ClassHandle::NewInstance<StackTraceHolder>(existing_stack);
141
- }
142
- }
143
- Local<Array> pair = Array::New(isolate, 2);
144
- Unmaybe(pair->Set(context, 0, ClassHandle::NewInstance<StackTraceHolder>(stack)));
145
- Unmaybe(pair->Set(context, 1, existing_data));
146
- AttachStackGetter(error, pair);
147
- }
148
-
149
- auto StackTraceHolder::RenderSingleStack(Local<StackTrace> stack_trace) -> std::string {
150
- Isolate* isolate = Isolate::GetCurrent();
151
- std::stringstream ss;
152
- int size = stack_trace->GetFrameCount();
153
- for (int ii = 0; ii < size; ++ii) {
154
- Local<StackFrame> frame = stack_trace->GetFrame(isolate, ii);
155
- ss <<"\n at ";
156
- String::Utf8Value fn_name{isolate, frame->GetFunctionName()};
157
- if (frame->IsWasm()) {
158
- String::Utf8Value script_name{isolate, frame->GetScriptName()};
159
- bool has_name = fn_name.length() != 0 || script_name.length() != 0;
160
- if (has_name) {
161
- if (script_name.length() == 0) {
162
- ss <<*fn_name;
163
- } else {
164
- ss <<*script_name;
165
- if (fn_name.length() != 0) {
166
- ss <<"." <<*fn_name;
167
- }
168
- }
169
- ss <<" (<WASM>";
170
- }
171
- ss <<frame->GetLineNumber() <<":" <<frame->GetColumn();
172
- if (has_name) {
173
- ss <<")";
174
- }
175
- } else {
176
- if (frame->IsConstructor()) {
177
- ss <<"new ";
178
- if (fn_name.length() == 0) {
179
- ss <<"<anonymous>";
180
- } else {
181
- ss <<*fn_name;
182
- }
183
- } else if (fn_name.length() != 0) {
184
- ss <<*fn_name;
185
- } else {
186
- AppendFileLocation(isolate, frame, ss);
187
- return ss.str();
188
- }
189
- ss <<" (";
190
- AppendFileLocation(isolate, frame, ss);
191
- ss <<")";
192
- }
193
- }
194
- return ss.str();
195
- }
196
-
197
- void StackTraceHolder::AppendFileLocation(Isolate* /*isolate*/, Local<StackFrame> frame, std::stringstream& ss) {
198
- String::Utf8Value script_name{Isolate::GetCurrent(), frame->GetScriptNameOrSourceURL()};
199
- if (script_name.length() == 0) {
200
- if (frame->IsEval()) {
201
- ss <<"[eval]";
202
- } else {
203
- ss <<"<anonymous>";
204
- }
205
- } else {
206
- ss <<*script_name;
207
- }
208
- int line_number = frame->GetLineNumber();
209
- if (line_number != -1) {
210
- ss <<":" <<line_number;
211
- int column = frame->GetColumn();
212
- if (column != -1) {
213
- ss <<":" <<column;
214
- }
215
- }
216
- }
217
-
218
- } // namespace ivm
@@ -1,24 +0,0 @@
1
- #pragma once
2
- #include <v8.h>
3
- #include "class_handle.h"
4
- #include <string>
5
-
6
- namespace ivm {
7
-
8
- /**
9
- * v8::StackTrace doesn't inherit from v8::Value so it can't be set as a property of an object which
10
- * is what we need to do to pass stack traces in an efficent way. So this gets around that.
11
- */
12
- class StackTraceHolder : public ClassHandle {
13
- private:
14
- static void AppendFileLocation(v8::Isolate* isolate, v8::Local<v8::StackFrame> frame, std::stringstream& ss);
15
- public:
16
- v8::Global<v8::StackTrace> stack_trace;
17
- explicit StackTraceHolder(v8::Local<v8::StackTrace> stack_handle);
18
- static auto Definition() -> v8::Local<v8::FunctionTemplate>;
19
- static void AttachStack(v8::Local<v8::Object> error, v8::Local<v8::StackTrace> stack);
20
- static void ChainStack(v8::Local<v8::Object> error, v8::Local<v8::StackTrace> stack);
21
- static auto RenderSingleStack(v8::Local<v8::StackTrace> stack_trace) -> std::string;
22
- };
23
-
24
- } // namespace ivm