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

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,338 +0,0 @@
1
- #pragma once
2
- #include <v8.h>
3
- #include "environment.h"
4
- #include "functor_runners.h"
5
- #include "util.h"
6
- #include "generic/callbacks.h"
7
- #include "generic/extract_params.h"
8
- #include "generic/handle_cast.h"
9
- #include "generic/read_option.h"
10
- #include "v8-function-callback.h"
11
-
12
- #include <cassert>
13
- #include <cstddef>
14
- #include <type_traits>
15
- #include <stdexcept>
16
-
17
- namespace ivm {
18
-
19
- namespace detail {
20
- struct ConstructorFunctionHolder : detail::FreeFunctionHolder {
21
- using FreeFunctionHolder::FreeFunctionHolder;
22
- };
23
-
24
- template <class Signature>
25
- struct ConstructorFunctionImpl;
26
-
27
- template <class Type>
28
- struct TemplateHolder {
29
- static IsolateSpecific<v8::FunctionTemplate> specific;
30
- };
31
-
32
- template <class Type>
33
- IsolateSpecific<v8::FunctionTemplate> TemplateHolder<Type>::specific;
34
-
35
- template <class Type, class = void>
36
- struct DontFreezePrototype : std::false_type{};
37
-
38
- template <class Type>
39
- struct DontFreezePrototype<Type, typename Type::DontFreezePrototype> : std::true_type {};
40
-
41
- template <class Type, class = void>
42
- struct DontFreezeInstance : std::false_type{};
43
-
44
- template <class Type>
45
- struct DontFreezeInstance<Type, typename Type::DontFreezeInstance> : std::true_type {};
46
-
47
- }
48
-
49
- /**
50
- * Analogous to node::ObjectWrap but Isolate-aware. Also has a bunch of unnecessary template stuff.
51
- */
52
- class ClassHandle {
53
- template <class Signature>
54
- friend struct detail::ConstructorFunctionImpl;
55
- private:
56
- v8::Persistent<v8::Value> handle;
57
-
58
- /**
59
- * Utility methods to set up object prototype
60
- */
61
- struct TemplateDefinition {
62
- v8::Isolate* isolate;
63
- v8::Local<v8::FunctionTemplate>& tmpl;
64
- v8::Local<v8::ObjectTemplate>& proto;
65
- v8::Local<v8::Signature>& sig;
66
-
67
- // This add regular methods
68
- template <typename... Args>
69
- void Add(const char* name, detail::MemberFunctionHolder impl, Args... args) {
70
- v8::Local<v8::String> name_handle = v8_symbol(name);
71
- proto->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, {}, sig, impl.length));
72
- Add(args...);
73
- }
74
-
75
- // This adds function templates to the prototype
76
- template <typename... Args>
77
- void Add(const char* name, v8::Local<v8::FunctionTemplate>& value, Args... args) {
78
- v8::Local<v8::String> name_handle = v8_symbol(name);
79
- proto->Set(name_handle, value);
80
- Add(args...);
81
- }
82
-
83
- // This adds static functions on the object constructor
84
- template <typename... Args>
85
- void Add(const char* name, detail::FreeFunctionHolder impl, Args... args) {
86
- v8::Local<v8::String> name_handle = v8_symbol(name);
87
- tmpl->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, {}, v8::Local<v8::Signature>(), impl.length));
88
- Add(args...);
89
- }
90
-
91
- // This adds accessors
92
- template <typename... Args>
93
- void Add(const char* name, detail::MemberAccessorHolder impl, Args... args) {
94
- v8::Local<v8::String> name_handle = v8_symbol(name);
95
- v8::Local<v8::FunctionTemplate> setter;
96
- if (impl.setter.callback != nullptr) {
97
- setter = v8::FunctionTemplate::New(isolate, impl.setter.callback, name_handle);
98
- }
99
- proto->SetAccessorProperty(name_handle, v8::FunctionTemplate::New(isolate, impl.getter.callback, {}), setter);
100
- Add(args...);
101
- }
102
-
103
- // This adds static accessors
104
- template <typename... Args>
105
- void Add(const char* name, detail::StaticAccessorHolder impl, Args... args) {
106
- v8::Local<v8::String> name_handle = v8_symbol(name);
107
- v8::Local<v8::FunctionTemplate> setter;
108
- if (impl.setter.callback != nullptr) {
109
- setter = v8::FunctionTemplate::New(isolate, impl.setter.callback, name_handle);
110
- }
111
- tmpl->SetAccessorProperty(name_handle, v8::FunctionTemplate::New(isolate, impl.getter.callback, {}), setter);
112
- Add(args...);
113
- }
114
-
115
- void Add() {} // NOLINT
116
- };
117
-
118
- /**
119
- * Convenience wrapper for the obtuse SetWeak function signature. When the callback is called
120
- * the handle will already be gone.
121
- */
122
- template <typename P, void (*F)(P*)>
123
- void SetWeak(P* param) {
124
- auto& isolate = IsolateEnvironment::GetCurrent();
125
- isolate.AddWeakCallback(&this->handle, (void(*)(void*))F, param);
126
- handle.SetWeak(param, WeakCallback<P, F>, v8::WeakCallbackType::kParameter);
127
- }
128
- template <typename P, void (*F)(P*)>
129
- static void WeakCallback(const v8::WeakCallbackInfo<P>& info) {
130
- F(info.GetParameter());
131
- }
132
-
133
- /**
134
- * Invoked once JS loses all references to this object
135
- */
136
- static void WeakCallback(void* param) {
137
- auto& isolate = IsolateEnvironment::GetCurrent();
138
- auto* that = reinterpret_cast<ClassHandle*>(param);
139
- isolate.RemoveWeakCallback(&that->handle);
140
- delete that; // NOLINT
141
- }
142
-
143
- /**
144
- * Transfer ownership of this C++ pointer to the v8 handle lifetime.
145
- */
146
- static void Wrap(std::unique_ptr<ClassHandle> ptr, v8::Local<v8::Object> handle) {
147
- handle->SetAlignedPointerInInternalField(0, ptr.get());
148
- ptr->handle.Reset(v8::Isolate::GetCurrent(), handle);
149
- ClassHandle* ptr_raw = ptr.release();
150
- ptr_raw->SetWeak<void, WeakCallback>(ptr_raw);
151
- }
152
-
153
- /**
154
- * It just throws when you call it; used when `nullptr` is passed as constructor
155
- */
156
- static void PrivateConstructor(const v8::FunctionCallbackInfo<v8::Value>& info) {
157
- throw RuntimeTypeError(detail::CalleeName(info)+ " constructor is private");
158
- }
159
-
160
- protected:
161
- /**
162
- * Sets up this object's FunctionTemplate inside the current isolate
163
- */
164
- template <typename... Args>
165
- static auto MakeClass(const char* class_name, detail::ConstructorFunctionHolder New, Args... args) -> v8::Local<v8::FunctionTemplate> {
166
- v8::Isolate* isolate = v8::Isolate::GetCurrent();
167
- v8::Local<v8::String> name_handle = v8_symbol(class_name);
168
- v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(
169
- isolate, New.callback == nullptr ? PrivateConstructor : New.callback,
170
- name_handle, {}, New.length
171
- );
172
- tmpl->SetClassName(name_handle);
173
-
174
- auto instance_tmpl = tmpl->InstanceTemplate();
175
- instance_tmpl->SetImmutableProto();
176
- instance_tmpl->SetInternalFieldCount(1);
177
-
178
- auto proto = tmpl->PrototypeTemplate();
179
- proto->SetImmutableProto();
180
- v8::Local<v8::Signature> sig = v8::Signature::New(isolate, tmpl);
181
- TemplateDefinition def{isolate, tmpl, proto, sig};
182
- def.Add(args...);
183
-
184
- return tmpl;
185
- }
186
-
187
- /**
188
- * Inherit from another class's FunctionTemplate
189
- */
190
- template <typename T>
191
- static auto Inherit(v8::Local<v8::FunctionTemplate> definition) -> v8::Local<v8::FunctionTemplate> {
192
- v8::Local<v8::FunctionTemplate> parent = GetFunctionTemplate<T>();
193
- definition->Inherit(parent);
194
- return definition;
195
- }
196
-
197
- public:
198
- ClassHandle() = default;
199
- ClassHandle(const ClassHandle&) = delete;
200
- auto operator= (const ClassHandle&) -> ClassHandle& = delete;
201
- virtual ~ClassHandle() {
202
- if (!handle.IsEmpty()) {
203
- handle.ClearWeak();
204
- handle.Reset();
205
- }
206
- }
207
-
208
- /**
209
- * Returns instance of this class for this context.
210
- */
211
- template <typename T>
212
- static auto Init() -> v8::Local<v8::Function> {
213
- return GetFunctionTemplate<T>()->GetFunction();
214
- }
215
-
216
- /**
217
- * Returns the FunctionTemplate for this isolate, generating it if needed.
218
- */
219
- template <class Type>
220
- static auto GetFunctionTemplate() -> v8::Local<v8::FunctionTemplate> {
221
- return detail::TemplateHolder<Type>::specific.Deref([&]() {
222
- return Type::Definition();
223
- });
224
- }
225
-
226
- /**
227
- * Freeze the handle and prototype unless `DontFreezeInstance` is set on the class handle
228
- */
229
- template <class Type>
230
- static auto MaybeFreeze(v8::Local<v8::Object> handle) {
231
- auto context = handle->GetIsolate()->GetCurrentContext();
232
- if (!detail::DontFreezePrototype<Type>::value) {
233
- handle->GetPrototype().As<v8::Object>()->SetIntegrityLevel(context, v8::IntegrityLevel::kFrozen);
234
- }
235
- if (!detail::DontFreezeInstance<Type>::value) {
236
- handle->SetIntegrityLevel(context, v8::IntegrityLevel::kFrozen);
237
- }
238
- }
239
-
240
- /**
241
- * Builds a new instance of T from scratch, used in factory functions.
242
- */
243
- template <typename T, typename ...Args>
244
- static auto NewInstance(Args&&... args) -> v8::Local<v8::Object> {
245
- auto context = v8::Isolate::GetCurrent()->GetCurrentContext();
246
- v8::Local<v8::Object> instance = Unmaybe(GetFunctionTemplate<T>()->InstanceTemplate()->NewInstance(context));
247
- MaybeFreeze<T>(instance);
248
- Wrap(std::make_unique<T>(std::forward<Args>(args)...), instance);
249
- return instance;
250
- }
251
-
252
- /**
253
- * Pull out native pointer from v8 handle
254
- */
255
- template <typename T>
256
- static auto Unwrap(v8::Local<v8::Object> handle) -> T* {
257
- assert(!handle.IsEmpty());
258
- if (!ClassHandle::GetFunctionTemplate<T>()->HasInstance(handle)) {
259
- return nullptr;
260
- }
261
- assert(handle->InternalFieldCount() > 0);
262
- return dynamic_cast<T*>(static_cast<ClassHandle*>(handle->GetAlignedPointerFromInternalField(0)));
263
- }
264
-
265
- /**
266
- * Returns the JS value that this ClassHandle points to
267
- */
268
- auto This() -> v8::Local<v8::Object> {
269
- return Deref(handle).As<v8::Object>();
270
- }
271
- };
272
-
273
- // Conversions from v8::Value -> Type&
274
- template <class Type>
275
- inline auto HandleCastImpl(v8::Local<v8::Value> value, const HandleCastArguments& /*arguments*/, HandleCastTag<Type&> /*tag*/) -> Type& {
276
- if (!value->IsObject()) {
277
- throw ParamIncorrect("an object");
278
- }
279
- v8::Local<v8::Object> handle = value.As<v8::Object>();
280
- if (handle->InternalFieldCount() != 1) {
281
- throw ParamIncorrect("something else");
282
- }
283
- auto* ptr = ClassHandle::Unwrap<Type>(handle);
284
- if (ptr == nullptr) {
285
- throw ParamIncorrect("something else");
286
- } else {
287
- return *ptr;
288
- }
289
- }
290
-
291
- namespace detail {
292
-
293
- template <class Signature>
294
- struct ConstructorFunctionImpl;
295
-
296
- template <class Signature>
297
- struct ConstructorFunctionImpl<Signature*> : ConstructorFunctionImpl<Signature> {};
298
-
299
- template <class Return, class ...Args>
300
- struct ConstructorFunctionImpl<Return(Args...)> {
301
- using Type = v8::Local<v8::Value>(*)(v8::Local<v8::Value> This, Args... args);
302
-
303
- template <Return(*Function)(Args...)>
304
- static inline auto Invoke(v8::Local<v8::Value> This, Args... args) -> v8::Local<v8::Value> {
305
- auto instance = Function(args...);
306
- if (instance) {
307
- v8::Local<v8::Object> handle = This.As<v8::Object>();
308
- ClassHandle::MaybeFreeze<typename decltype(instance)::element_type>(handle);
309
- ClassHandle::Wrap(std::move(instance), handle);
310
- return handle;
311
- } else {
312
- return Undefined(v8::Isolate::GetCurrent());
313
- }
314
- }
315
- };
316
-
317
- } // namespace detail
318
-
319
- template <class Signature, Signature Function>
320
- struct ConstructorFunction : detail::ConstructorFunctionHolder {
321
- using ConstructorFunctionHolder::ConstructorFunctionHolder;
322
- ConstructorFunction() : ConstructorFunctionHolder{
323
- Entry,
324
- std::tuple_size<typename detail::extract_arguments<Signature>::arguments>::value} {}
325
-
326
- static void Entry(const v8::FunctionCallbackInfo<v8::Value>& info) {
327
- detail::RunBarrier([&]() {
328
- if (!info.IsConstructCall()) {
329
- throw RuntimeTypeError(detail::CalleeName(info)+ " must be called with `new`");
330
- }
331
- ToCallback<-1, typename Impl::Type, &Impl::template Invoke<Function>>()(info);
332
- });
333
- }
334
-
335
- using Impl = detail::ConstructorFunctionImpl<Signature>;
336
- };
337
-
338
- } // namespace ivm
@@ -1,220 +0,0 @@
1
- #include "cpu_profile_manager.h"
2
- #include "environment.h"
3
- #include <algorithm>
4
- #include <climits>
5
- #include <cmath>
6
- #include <cstdio>
7
- #include <cstring>
8
- #include <memory>
9
- #include <mutex>
10
- #include <thread>
11
- #include <vector>
12
- #include "isolate/strings.h"
13
- #include "v8-platform.h"
14
- #include "v8.h"
15
-
16
- using namespace v8;
17
-
18
- namespace ivm {
19
-
20
- /**
21
- * CpuProfileManagerImpl
22
- */
23
- IVMCpuProfile::IVMCpuProfile(const std::shared_ptr<v8::CpuProfile>& cpuProfile):
24
- profile_thread(std::this_thread::get_id()),
25
- start_time(cpuProfile->GetStartTime()),
26
- end_time(cpuProfile->GetEndTime()),
27
- samples_count(cpuProfile->GetSamplesCount()) {
28
-
29
- samples.reserve(samples_count);
30
- timestamps.reserve(samples_count);
31
- for (int64_t i = 0; i < samples_count; i++) {
32
- const int idx = static_cast<int>(i);
33
- samples.push_back(cpuProfile->GetSample(idx)->GetNodeId());
34
- timestamps.push_back(cpuProfile->GetSampleTimestamp(idx));
35
- }
36
-
37
- // handle nodes
38
- FlatNodes(cpuProfile->GetTopDownRoot(), &profileNodes);
39
- }
40
-
41
- auto IVMCpuProfile::GetTidValue(Isolate *iso) -> Local<Value>{
42
- const auto tid = std::hash<std::thread::id>{}(profile_thread);
43
- return Number::New(iso, static_cast<double>(tid));
44
- }
45
-
46
- auto IVMCpuProfile::BuildCpuProfile(Isolate *iso) -> Local<Value> {
47
- auto& strings = StringTable::Get();
48
- auto context = iso->GetCurrentContext();
49
- auto profileObject = Object::New(iso);
50
-
51
- Unmaybe(profileObject->Set(context, strings.startTime, Number::New(iso, static_cast<double>(start_time))));
52
- Unmaybe(profileObject->Set(context, strings.endTime, Number::New(iso, static_cast<double>(end_time))));
53
-
54
- const Local<Array> samplesArr = Array::New(iso);
55
- const Local<Array> timeDeltasArr = Array::New(iso);
56
-
57
- for (int64_t i = 0; i < samples_count; i++) {
58
- Unmaybe(samplesArr->Set(context, i, Number::New(iso, static_cast<double>(samples[i]))));
59
- Unmaybe(timeDeltasArr->Set(context, i, Number::New(iso, static_cast<double>(timestamps[i] - start_time))));
60
- }
61
- Unmaybe(profileObject->Set(context, strings.samples, samplesArr));
62
- Unmaybe(profileObject->Set(context, strings.timeDeltas, timeDeltasArr));
63
-
64
- const Local<Array> nodeArr = Array::New(iso, static_cast<int>(profileNodes.size()));
65
- Unmaybe(profileObject->Set(context, strings.nodes, nodeArr));
66
-
67
- const size_t count = profileNodes.size();
68
- for (size_t i = 0; i < count; i++) {
69
- ProfileNode node = profileNodes[i];
70
- Unmaybe(nodeArr->Set(context, i, node.ToJSObject(iso)));
71
- }
72
-
73
- return profileObject;
74
- }
75
-
76
- auto IVMCpuProfile::ToJSObject(Isolate *iso) -> Local<Value> {
77
- auto& strings = StringTable::Get();
78
- auto context = iso->GetCurrentContext();
79
- auto result = Object::New(iso);
80
-
81
- Unmaybe(result->Set(context, (v8::Local<v8::Value>)strings.threadId, GetTidValue(iso)));
82
- Unmaybe(result->Set(context, strings.profile, BuildCpuProfile(iso)));
83
-
84
- return result;
85
- }
86
-
87
- IVMCpuProfile::CallFrame::CallFrame(const v8::CpuProfileNode* node):
88
- function_name(node->GetFunctionNameStr()),
89
- url(node->GetScriptResourceNameStr()),
90
- script_id(node->GetScriptId()),
91
- line_number(node->GetLineNumber()),
92
- column_number(node->GetColumnNumber()) {}
93
-
94
-
95
- auto IVMCpuProfile::CallFrame::ToJSObject(v8::Isolate *iso) -> Local<Value> {
96
- auto& strings = StringTable::Get();
97
- Local<Object> callFrame = Object::New(iso);
98
- const Local<Context> context = iso->GetCurrentContext();
99
- Unmaybe(callFrame->Set(context, strings.functionName, String::NewFromUtf8(iso, function_name).ToLocalChecked()));
100
- Unmaybe(callFrame->Set(context, strings.url, String::NewFromUtf8(iso, url).ToLocalChecked()));
101
- Unmaybe(callFrame->Set(context, strings.scriptId, Number::New(iso, script_id)));
102
- Unmaybe(callFrame->Set(context, strings.lineNumber, Number::New(iso, line_number)));
103
- Unmaybe(callFrame->Set(context, strings.columnNumber, Number::New(iso, column_number)));
104
- return callFrame;
105
- }
106
-
107
- IVMCpuProfile::ProfileNode::ProfileNode(const v8::CpuProfileNode* node):
108
- hit_count(node->GetHitCount()),
109
- node_id(node->GetNodeId()),
110
- bailout_reason(node->GetBailoutReason()),
111
- call_frame(node) {
112
- const int childrenCount = node->GetChildrenCount();
113
- children.reserve(childrenCount);
114
- for (int i = 0; i < childrenCount; i++) {
115
- children.push_back(node->GetChild(i)->GetNodeId());
116
- }
117
- }
118
-
119
- auto IVMCpuProfile::ProfileNode::ToJSObject(Isolate *iso) -> Local<Value> {
120
- auto& strings = StringTable::Get();
121
- auto context = iso->GetCurrentContext();
122
-
123
- Local<Object> nodeObj = Object::New(iso);
124
-
125
- Unmaybe(nodeObj->Set(context, strings.hitCount, Number::New(iso, hit_count)));
126
- Unmaybe(nodeObj->Set(context, strings.id, Number::New(iso, node_id)));
127
-
128
- if (strlen(bailout_reason) > 0) {
129
- Unmaybe(nodeObj->Set(context, strings.bailoutReason, String::NewFromUtf8(iso, bailout_reason).ToLocalChecked()));
130
- }
131
-
132
- const int children_count = static_cast<int>(children.size());
133
- const Local<Array> childrenArr = Array::New(iso, children_count);
134
- Unmaybe(nodeObj->Set(context, strings.children, childrenArr));
135
-
136
- for (int j = 0; j < children_count; j++) {
137
- Unmaybe(childrenArr->Set(context, j, Number::New(iso, static_cast<double>(children[j]))));
138
- }
139
-
140
- const Local<Value> callFrame = call_frame.ToJSObject(iso);
141
- Unmaybe(nodeObj->Set(context, strings.callFrame, callFrame));
142
-
143
- return nodeObj;
144
- }
145
-
146
- CpuProfileManager::CpuProfileManager() = default;
147
-
148
- void CpuProfileManager::StartProfiling(const char* title) {
149
- const std::lock_guard<std::mutex> lock(mutex);
150
- std::string str(title);
151
- profile_titles.insert(str);
152
- }
153
-
154
- auto CpuProfileManager::StopProfiling(const char* title) -> std::vector<IVMCpuProfile> {
155
- const std::lock_guard<std::mutex> lock(mutex);
156
- const std::string str_title(title);
157
-
158
- std::vector<IVMCpuProfile> currently_collected;
159
-
160
- if (profile_begin_ptrs.find(str_title) == profile_begin_ptrs.end()) {
161
- return currently_collected;
162
- }
163
-
164
- auto iter = profile_begin_ptrs[str_title];
165
-
166
- // Iterate using an iterator
167
- for (auto it = iter; it != profile_items.end(); ++it) {
168
- currently_collected.push_back(*it);
169
- }
170
-
171
- // remove the titles
172
- profile_titles.erase(str_title);
173
- // remove the profile ptr from map
174
- profile_begin_ptrs.erase(str_title);
175
-
176
- // TODO clean up old profiles, extract private method
177
- CleanProfiles();
178
-
179
- return currently_collected;
180
- }
181
-
182
- auto CpuProfileManager::IsProfiling() -> bool {
183
- return !profile_titles.empty();
184
- }
185
-
186
- auto CpuProfileManager::InjestCpuProfile(const std::shared_ptr<v8::CpuProfile>& cpuProfile) -> void {
187
- const std::lock_guard<std::mutex> lock(mutex);
188
- profile_items.emplace_back(cpuProfile);
189
-
190
- for(const std::string &title : profile_titles) {
191
- if (profile_begin_ptrs.find(title) == profile_begin_ptrs.end()) {
192
- profile_begin_ptrs[title] = std::prev(profile_items.end());
193
- }
194
- }
195
- }
196
-
197
- void CpuProfileManager::CleanProfiles() {
198
- if (profile_titles.empty()) {
199
- profile_items.clear();
200
- profile_begin_ptrs.clear();
201
- }
202
-
203
- int64_t min_start_time = INT_MAX;
204
-
205
- for (const auto& profile_item: profile_begin_ptrs) {
206
- if (profile_item.second->GetStartTime() < min_start_time) {
207
- min_start_time = profile_item.second->GetStartTime();
208
- }
209
- }
210
-
211
- for (auto it = profile_items.begin(); it != profile_items.end(); ) {
212
- if (it->GetStartTime() < min_start_time) {
213
- it = profile_items.erase(it);
214
- } else {
215
- ++it;
216
- }
217
- }
218
- }
219
-
220
- }
@@ -1,100 +0,0 @@
1
- #pragma once
2
- #include <ratio>
3
- #include <string>
4
- #include <thread>
5
- #include <v8.h>
6
-
7
- #include "executor.h"
8
- #include "v8-profiler.h"
9
-
10
- #include <mutex>
11
- #include <queue>
12
- #include <set>
13
- #include <unordered_map>
14
- #include <vector>
15
- #include <list>
16
-
17
- namespace ivm {
18
-
19
- class IVMCpuProfile {
20
- public:
21
- explicit IVMCpuProfile(const std::shared_ptr<v8::CpuProfile>& cpuProfile);
22
- ~IVMCpuProfile() = default;
23
-
24
- class CallFrame {
25
- public:
26
- explicit CallFrame(const v8::CpuProfileNode* node);
27
- ~CallFrame() = default;
28
-
29
- auto ToJSObject(v8::Isolate *iso) -> v8::Local<v8::Value>;
30
- private:
31
- const char* function_name;
32
- const char* url;
33
- int script_id;
34
- int line_number;
35
- int column_number;
36
- };
37
-
38
- class ProfileNode {
39
- public:
40
- explicit ProfileNode(const v8::CpuProfileNode* node);
41
- ~ProfileNode() = default;
42
-
43
- auto ToJSObject(v8::Isolate *iso) -> v8::Local<v8::Value>;
44
- private:
45
- unsigned int hit_count;
46
- unsigned int node_id;
47
- const char* bailout_reason;
48
- std::vector<unsigned int> children;
49
- CallFrame call_frame;
50
- };
51
-
52
- auto GetStartTime() const -> int64_t { return start_time; }
53
-
54
- auto ToJSObject(v8::Isolate *iso) -> v8::Local<v8::Value>;
55
-
56
-
57
- private:
58
- std::thread::id profile_thread;
59
- int64_t start_time;
60
- int64_t end_time;
61
- int64_t samples_count;
62
- std::vector<unsigned int> samples;
63
- std::vector<int64_t> timestamps;
64
- std::vector<ProfileNode> profileNodes;
65
-
66
- auto GetTidValue(v8::Isolate *iso) -> v8::Local<v8::Value>;
67
-
68
- auto BuildCpuProfile(v8::Isolate *iso) -> v8::Local<v8::Value>;
69
-
70
- void FlatNodes(const v8::CpuProfileNode* node, std::vector<ProfileNode>* nodes) { // NOLINT(misc-no-recursion)
71
- nodes->emplace_back(node);
72
- const int childrenCount = node->GetChildrenCount();
73
-
74
- for (int index = 0; index < childrenCount; ++index) {
75
- FlatNodes(node->GetChild(index), nodes);
76
- }
77
- }
78
-
79
- };
80
-
81
- class CpuProfileManager {
82
- public:
83
- CpuProfileManager();
84
- void StartProfiling(const char* title);
85
- auto StopProfiling(const char* title) -> std::vector<IVMCpuProfile>;
86
- auto IsProfiling() -> bool;
87
- auto InjestCpuProfile(const std::shared_ptr<v8::CpuProfile>& cpuProfile) -> void;
88
-
89
- CpuProfileManager(const CpuProfileManager&) = delete;
90
- auto operator= (const CpuProfileManager) = delete;
91
- ~CpuProfileManager() = default;
92
- private:
93
- void CleanProfiles();
94
-
95
- std::set<std::string> profile_titles{};
96
- std::list<IVMCpuProfile> profile_items{};
97
- std::unordered_map<std::string, std::list<IVMCpuProfile>::iterator> profile_begin_ptrs{};
98
- std::mutex mutex;
99
- };
100
- }