@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,623 +0,0 @@
1
- #include "isolate_handle.h"
2
- #include "context_handle.h"
3
- #include "external_copy_handle.h"
4
- #include "isolate/holder.h"
5
- #include "script_handle.h"
6
- #include "module_handle.h"
7
- #include "session_handle.h"
8
- #include "external_copy/external_copy.h"
9
- #include "lib/lockable.h"
10
- #include "isolate/allocator.h"
11
- #include "isolate/functor_runners.h"
12
- #include "isolate/platform_delegate.h"
13
- #include "isolate/remote_handle.h"
14
- #include "isolate/three_phase_task.h"
15
- #include "isolate/v8_version.h"
16
- #include "module/evaluation.h"
17
- #include "v8-platform.h"
18
- #include "v8-profiler.h"
19
- #include <cstring>
20
- #include <deque>
21
- #include <memory>
22
- #include <iostream>
23
-
24
- using namespace v8;
25
- using v8::CpuProfile;
26
- using std::shared_ptr;
27
- using std::unique_ptr;
28
-
29
- namespace ivm {
30
-
31
- /**
32
- * IsolateHandle implementation
33
- */
34
- IsolateHandle::IsolateHandleTransferable::IsolateHandleTransferable(shared_ptr<IsolateHolder> isolate) : isolate(std::move(isolate)) {}
35
-
36
- auto IsolateHandle::IsolateHandleTransferable::TransferIn() -> Local<Value> {
37
- return ClassHandle::NewInstance<IsolateHandle>(isolate);
38
- }
39
-
40
- IsolateHandle::IsolateHandle(shared_ptr<IsolateHolder> isolate) : isolate(std::move(isolate)) {}
41
-
42
- static std::unique_ptr<ClassHandle> IsolateHandle_New_Wrapper(v8::MaybeLocal<v8::Object> options) {
43
- return IsolateHandle::New(options);
44
- }
45
-
46
- auto IsolateHandle::Definition() -> Local<FunctionTemplate> {
47
- return Inherit<TransferableHandle>(MakeClass(
48
- "Isolate", ConstructorFunction<decltype(&IsolateHandle_New_Wrapper), &IsolateHandle_New_Wrapper>{},
49
- "createSnapshot", FreeFunction<decltype(&CreateSnapshot), &CreateSnapshot>{},
50
- "compileScript", MemberFunction<decltype(&IsolateHandle::CompileScript<1>), &IsolateHandle::CompileScript<1>>{},
51
- "compileScriptSync", MemberFunction<decltype(&IsolateHandle::CompileScript<0>), &IsolateHandle::CompileScript<0>>{},
52
- "compileModule", MemberFunction<decltype(&IsolateHandle::CompileModule<1>), &IsolateHandle::CompileModule<1>>{},
53
- "compileModuleSync", MemberFunction<decltype(&IsolateHandle::CompileModule<0>), &IsolateHandle::CompileModule<0>>{},
54
- "cpuTime", MemberAccessor<decltype(&IsolateHandle::GetCpuTime), &IsolateHandle::GetCpuTime>{},
55
- "createContext", MemberFunction<decltype(&IsolateHandle::CreateContext<1>), &IsolateHandle::CreateContext<1>>{},
56
- "createContextSync", MemberFunction<decltype(&IsolateHandle::CreateContext<0>), &IsolateHandle::CreateContext<0>>{},
57
- "createInspectorSession", MemberFunction<decltype(&IsolateHandle::CreateInspectorSession), &IsolateHandle::CreateInspectorSession>{},
58
- "dispose", MemberFunction<decltype(&IsolateHandle::Dispose), &IsolateHandle::Dispose>{},
59
- "getHeapStatistics", MemberFunction<decltype(&IsolateHandle::GetHeapStatistics<1>), &IsolateHandle::GetHeapStatistics<1>>{},
60
- "getHeapStatisticsSync", MemberFunction<decltype(&IsolateHandle::GetHeapStatistics<0>), &IsolateHandle::GetHeapStatistics<0>>{},
61
- "isDisposed", MemberAccessor<decltype(&IsolateHandle::IsDisposedGetter), &IsolateHandle::IsDisposedGetter>{},
62
- "referenceCount", MemberAccessor<decltype(&IsolateHandle::GetReferenceCount), &IsolateHandle::GetReferenceCount>{},
63
- "wallTime", MemberAccessor<decltype(&IsolateHandle::GetWallTime), &IsolateHandle::GetWallTime>{},
64
- "startCpuProfiler", MemberFunction<decltype(&IsolateHandle::StartCpuProfiler), &IsolateHandle::StartCpuProfiler>{},
65
- "stopCpuProfiler", MemberFunction<decltype(&IsolateHandle::StopCpuProfiler<1>), &IsolateHandle::StopCpuProfiler<1>>{}
66
- ));
67
- }
68
-
69
- /**
70
- * Create a new Isolate. It all starts here!
71
- */
72
- auto IsolateHandle::New(MaybeLocal<Object> maybe_options) -> unique_ptr<ClassHandle> {
73
- shared_ptr<v8::BackingStore> snapshot_blob;
74
- RemoteHandle<Function> error_handler;
75
- size_t snapshot_blob_length = 0;
76
- size_t memory_limit = 128;
77
- bool inspector = false;
78
-
79
- // Parse options
80
- Local<Object> options;
81
- if (maybe_options.ToLocal(&options)) {
82
-
83
- // Check memory limits
84
- memory_limit = ReadOption<double>(options, "memoryLimit", 128);
85
- if (memory_limit < 8) {
86
- throw RuntimeGenericError("`memoryLimit` must be at least 8");
87
- }
88
-
89
- // Set snapshot
90
- auto maybe_snapshot = ReadOption<MaybeLocal<Object>>(options, StringTable::Get().snapshot, {});
91
- Local<Object> snapshot_handle;
92
- if (maybe_snapshot.ToLocal(&snapshot_handle)) {
93
- auto* copy_handle = ClassHandle::Unwrap<ExternalCopyHandle>(snapshot_handle.As<Object>());
94
- if (copy_handle != nullptr) {
95
- ExternalCopyArrayBuffer* copy_ptr = dynamic_cast<ExternalCopyArrayBuffer*>(copy_handle->GetValue().get());
96
- if (copy_ptr != nullptr) {
97
- snapshot_blob = copy_ptr->Acquire();
98
- snapshot_blob_length = snapshot_blob->ByteLength();
99
- }
100
- }
101
- if (!snapshot_blob) {
102
- throw RuntimeTypeError("`snapshot` must be an ExternalCopy to ArrayBuffer");
103
- }
104
- }
105
-
106
- // Check inspector flag
107
- inspector = ReadOption<bool>(options, StringTable::Get().inspector, false);
108
-
109
- auto maybe_handler = ReadOption<MaybeLocal<Function>>(options, StringTable::Get().onCatastrophicError, {});
110
- Local<Function> error_handler_local;
111
- if (maybe_handler.ToLocal(&error_handler_local)) {
112
- error_handler = RemoteHandle<Function>{error_handler_local};
113
- }
114
- }
115
-
116
- // Return isolate handle
117
- auto holder = IsolateEnvironment::New(memory_limit, std::move(snapshot_blob), snapshot_blob_length);
118
- auto env = holder->GetIsolate();
119
- env->GetIsolate()->SetHostInitializeImportMetaObjectCallback(ModuleHandle::InitializeImportMeta);
120
- env->error_handler = error_handler;
121
- if (inspector) {
122
- env->EnableInspectorAgent();
123
- }
124
- return std::make_unique<IsolateHandle>(holder);
125
- }
126
-
127
- auto IsolateHandle::TransferOut() -> unique_ptr<Transferable> {
128
- return std::make_unique<IsolateHandleTransferable>(isolate);
129
- }
130
-
131
- /**
132
- * Create a new v8::Context in this isolate and returns a ContextHandle
133
- */
134
- struct CreateContextRunner : public ThreePhaseTask {
135
- bool enable_inspector = false;
136
- RemoteHandle<Context> context;
137
- RemoteHandle<Value> global;
138
-
139
- explicit CreateContextRunner(MaybeLocal<Object>& maybe_options) {
140
- enable_inspector = ReadOption<bool>(maybe_options, StringTable::Get().inspector, false);
141
- }
142
-
143
- void Phase2() final {
144
- // Use custom deleter on the shared_ptr which will notify the isolate when we're probably done with this context
145
- struct ContextDeleter {
146
- void operator() (v8::Persistent<Context>& context) const {
147
- auto& env = IsolateEnvironment::GetCurrent();
148
- context.Reset();
149
- env.GetIsolate()->ContextDisposedNotification();
150
- }
151
- };
152
-
153
- auto& env = IsolateEnvironment::GetCurrent();
154
-
155
- // Sanity check before we build the context
156
- if (enable_inspector && env.GetInspectorAgent() == nullptr) {
157
- Context::Scope context_scope{env.DefaultContext()}; // TODO: This is needed to throw, but is stupid and sloppy
158
- throw RuntimeGenericError("Inspector is not enabled for this isolate");
159
- }
160
-
161
- // Make a new context and setup shared pointers
162
- IsolateEnvironment::HeapCheck heap_check{env, true};
163
- Local<Context> context_handle = env.NewContext();
164
- if (enable_inspector) {
165
- env.GetInspectorAgent()->ContextCreated(context_handle, "<isolated-vm>");
166
- }
167
- context = RemoteHandle<Context>{context_handle, ContextDeleter{}};
168
- global = RemoteHandle<Value>{context_handle->Global()};
169
- heap_check.Epilogue();
170
- }
171
-
172
- auto Phase3() -> Local<Value> final {
173
- // Make a new Context{} JS class
174
- return ClassHandle::NewInstance<ContextHandle>(std::move(context), std::move(global));
175
- }
176
- };
177
- template <int async>
178
- auto IsolateHandle::CreateContext(MaybeLocal<Object> maybe_options) -> Local<Value> {
179
- return ThreePhaseTask::Run<async, CreateContextRunner>(*isolate, maybe_options);
180
- }
181
-
182
- /**
183
- * Compiles a script in this isolate and returns a ScriptHandle
184
- */
185
- struct CompileScriptRunner : public CodeCompilerHolder, public ThreePhaseTask {
186
- RemoteHandle<UnboundScript> script;
187
-
188
- CompileScriptRunner(const Local<String>& code_handle, const MaybeLocal<Object>& maybe_options) :
189
- CodeCompilerHolder{code_handle, maybe_options, false} {}
190
-
191
- void Phase2() final {
192
- // Compile in second isolate and return UnboundScript persistent
193
- auto& isolate = IsolateEnvironment::GetCurrent();
194
- Context::Scope context_scope(isolate.DefaultContext());
195
- IsolateEnvironment::HeapCheck heap_check{isolate, true};
196
- auto source = GetSource();
197
- ScriptCompiler::CompileOptions compile_options = ScriptCompiler::kNoCompileOptions;
198
- if (DidSupplyCachedData()) {
199
- compile_options = ScriptCompiler::kConsumeCodeCache;
200
- }
201
- script = RemoteHandle<UnboundScript>{RunWithAnnotatedErrors(
202
- [&isolate, &source, compile_options]() { return Unmaybe(ScriptCompiler::CompileUnboundScript(isolate, source.get(), compile_options)); }
203
- )};
204
-
205
- // Check cached data flags
206
- if (DidSupplyCachedData()) {
207
- SetCachedDataRejected(source->GetCachedData()->rejected);
208
- }
209
- if (ShouldProduceCachedData()) {
210
- ScriptCompiler::CachedData* cached_data = ScriptCompiler::CreateCodeCache(script.Deref());
211
- assert(cached_data != nullptr);
212
- SaveCachedData(cached_data);
213
- }
214
- ResetSource();
215
- heap_check.Epilogue();
216
- }
217
-
218
- auto Phase3() -> Local<Value> final {
219
- // Wrap UnboundScript in JS Script{} class
220
- Local<Object> value = ClassHandle::NewInstance<ScriptHandle>(std::move(script));
221
- WriteCompileResults(value);
222
- return value;
223
- }
224
- };
225
-
226
- struct StopCpuProfileRunner: public ThreePhaseTask {
227
- const char* title_;
228
- std::vector<IVMCpuProfile> profiles;
229
-
230
- explicit StopCpuProfileRunner(const char* title): title_(title) {}
231
-
232
- void Phase2() final {
233
- auto& isolate = IsolateEnvironment::GetCurrent();
234
- profiles = isolate.GetCpuProfileManager()->StopProfiling(title_);
235
- }
236
-
237
- auto Phase3() -> Local<Value> final {
238
- auto* isolate = Isolate::GetCurrent();
239
- auto ctx = isolate->GetCurrentContext();
240
-
241
- const int arr_size = static_cast<int>(profiles.size());
242
- auto arr = Array::New(isolate, arr_size);
243
-
244
- for (int i = 0; i < arr_size; i++) {
245
- IVMCpuProfile profile = profiles.at(i);
246
- Unmaybe(arr->Set(ctx, i, profile.ToJSObject(isolate)));
247
- }
248
-
249
- return arr;
250
- }
251
- };
252
-
253
- template <int async>
254
- auto IsolateHandle::CompileScript(Local<String> code_handle, MaybeLocal<Object> maybe_options) -> Local<Value> {
255
- return ThreePhaseTask::Run<async, CompileScriptRunner>(*this->isolate, code_handle, maybe_options);
256
- }
257
-
258
- /**
259
- * Compiles a module in this isolate and returns a ModuleHandle
260
- */
261
- struct CompileModuleRunner : public CodeCompilerHolder, public ThreePhaseTask {
262
- shared_ptr<ModuleInfo> module_info;
263
- RemoteHandle<Function> meta_callback;
264
-
265
- CompileModuleRunner(const Local<String>& code_handle, const MaybeLocal<Object>& maybe_options) :
266
- CodeCompilerHolder{code_handle, maybe_options, true} {
267
-
268
- auto maybe_meta_callback = ReadOption<MaybeLocal<Function>>(maybe_options, StringTable::Get().meta, {});
269
- Local<Function> meta_callback;
270
- if (maybe_meta_callback.ToLocal(&meta_callback)) {
271
- this->meta_callback = RemoteHandle<Function>{meta_callback};
272
- }
273
- }
274
-
275
- void Phase2() final {
276
- auto& isolate = IsolateEnvironment::GetCurrent();
277
- Context::Scope context_scope(isolate.DefaultContext());
278
- IsolateEnvironment::HeapCheck heap_check{isolate, true};
279
- auto source = GetSource();
280
- auto module_handle = RunWithAnnotatedErrors(
281
- [&]() { return Unmaybe(ScriptCompiler::CompileModule(isolate, source.get())); }
282
- );
283
-
284
- if (DidSupplyCachedData()) {
285
- SetCachedDataRejected(source->GetCachedData()->rejected);
286
- }
287
- if (ShouldProduceCachedData()) {
288
- ScriptCompiler::CachedData* cached_data = ScriptCompiler::CreateCodeCache(module_handle->GetUnboundModuleScript());
289
- assert(cached_data != nullptr);
290
- SaveCachedData(cached_data);
291
- }
292
-
293
- ResetSource();
294
- module_info = std::make_shared<ModuleInfo>(module_handle);
295
- if (meta_callback) {
296
- if (meta_callback.GetSharedIsolateHolder() != IsolateEnvironment::GetCurrentHolder()) {
297
- throw RuntimeGenericError("`meta` callback must belong to entered isolate");
298
- }
299
- module_info->meta_callback = meta_callback;
300
- }
301
- heap_check.Epilogue();
302
- }
303
-
304
- auto Phase3() -> Local<Value> final {
305
- Local<Object> value = ClassHandle::NewInstance<ModuleHandle>(std::move(module_info));
306
- WriteCompileResults(value);
307
- return value;
308
- }
309
- };
310
-
311
- template <int async>
312
- auto IsolateHandle::CompileModule(Local<String> code_handle, MaybeLocal<Object> maybe_options) -> Local<Value> {
313
- return ThreePhaseTask::Run<async, CompileModuleRunner>(*this->isolate, code_handle, maybe_options);
314
- }
315
-
316
- /**
317
- * Create a new channel for debugging on the inspector
318
- */
319
- auto IsolateHandle::CreateInspectorSession() -> Local<Value> {
320
- if (IsolateEnvironment::GetCurrentHolder() == isolate) {
321
- throw RuntimeGenericError("An isolate is not debuggable from within itself");
322
- }
323
- shared_ptr<IsolateEnvironment> env = isolate->GetIsolate();
324
- if (!env) {
325
- throw RuntimeGenericError("Isolate is diposed");
326
- }
327
- if (env->GetInspectorAgent() == nullptr) {
328
- throw RuntimeGenericError("Inspector is not enabled for this isolate");
329
- }
330
- return ClassHandle::NewInstance<SessionHandle>(*env);
331
- }
332
-
333
- /**
334
- * Dispose an isolate
335
- */
336
- auto IsolateHandle::Dispose() -> Local<Value> {
337
- if (!isolate->Dispose()) {
338
- throw RuntimeGenericError("Isolate is already disposed");
339
- }
340
- return Undefined(Isolate::GetCurrent());
341
- }
342
-
343
- /**
344
- * Get heap statistics from v8
345
- */
346
- struct HeapStatRunner : public ThreePhaseTask {
347
- HeapStatistics heap;
348
- size_t externally_allocated_size = 0;
349
- size_t adjustment = 0;
350
-
351
- // Dummy constructor to workaround gcc bug
352
- explicit HeapStatRunner(int /*unused*/) {}
353
-
354
- void Phase2() final {
355
- IsolateEnvironment& isolate = IsolateEnvironment::GetCurrent();
356
- isolate->GetHeapStatistics(&heap);
357
- adjustment = heap.heap_size_limit() - isolate.GetInitialHeapSizeLimit();
358
- externally_allocated_size = isolate.GetExtraAllocatedMemory();
359
- }
360
-
361
- auto Phase3() -> Local<Value> final {
362
- Isolate* isolate = Isolate::GetCurrent();
363
- Local<Context> context = isolate->GetCurrentContext();
364
- Local<Object> ret = Object::New(isolate);
365
- auto& strings = StringTable::Get();
366
- Unmaybe(ret->Set(context, strings.total_heap_size, Number::New(isolate, heap.total_heap_size())));
367
- Unmaybe(ret->Set(context, strings.total_heap_size_executable, Number::New(isolate, heap.total_heap_size_executable())));
368
- Unmaybe(ret->Set(context, strings.total_physical_size, Number::New(isolate, heap.total_physical_size())));
369
- Unmaybe(ret->Set(context, strings.total_available_size, Number::New(isolate, static_cast<double>(heap.total_available_size()) - adjustment)));
370
- Unmaybe(ret->Set(context, strings.used_heap_size, Number::New(isolate, heap.used_heap_size())));
371
- Unmaybe(ret->Set(context, strings.heap_size_limit, Number::New(isolate, static_cast<double>(heap.heap_size_limit()) - adjustment)));
372
- Unmaybe(ret->Set(context, strings.malloced_memory, Number::New(isolate, heap.malloced_memory())));
373
- Unmaybe(ret->Set(context, strings.peak_malloced_memory, Number::New(isolate, heap.peak_malloced_memory())));
374
- Unmaybe(ret->Set(context, strings.does_zap_garbage, Number::New(isolate, heap.does_zap_garbage())));
375
- Unmaybe(ret->Set(context, strings.externally_allocated_size, Number::New(isolate, externally_allocated_size)));
376
- return ret;
377
- }
378
- };
379
- template <int async>
380
- auto IsolateHandle::GetHeapStatistics() -> Local<Value> {
381
- return ThreePhaseTask::Run<async, HeapStatRunner>(*isolate, 0);
382
- }
383
-
384
- /**
385
- * Timers
386
- */
387
- auto IsolateHandle::GetCpuTime() -> Local<Value> {
388
- auto env = this->isolate->GetIsolate();
389
- if (!env) {
390
- throw RuntimeGenericError("Isolate is disposed");
391
- }
392
- uint64_t time = env->GetCpuTime().count();
393
- return HandleCast<Local<BigInt>>(time);
394
- }
395
-
396
- auto IsolateHandle::GetWallTime() -> Local<Value> {
397
- auto env = this->isolate->GetIsolate();
398
- if (!env) {
399
- throw RuntimeGenericError("Isolate is disposed");
400
- }
401
- uint64_t time = env->GetWallTime().count();
402
- return HandleCast<Local<BigInt>>(time);
403
- }
404
-
405
- auto IsolateHandle::StartCpuProfiler(v8::Local<v8::String> title) -> Local<Value> {
406
- auto env = this->isolate->GetIsolate();
407
-
408
- if (!env) {
409
- throw RuntimeGenericError("Isolate is disposed");
410
- }
411
-
412
- Isolate* iso = Isolate::GetCurrent();
413
- v8::String::Utf8Value str(iso, title);
414
- const char* title_ = *str;
415
-
416
- env->GetCpuProfileManager()->StartProfiling(title_);
417
-
418
- return HandleCast<Local<Boolean>>(true);
419
- }
420
-
421
- template <int async>
422
- auto IsolateHandle::StopCpuProfiler(v8::Local<v8::String> title) -> Local<Value> {
423
- auto env = this->isolate->GetIsolate();
424
-
425
- if (!env) {
426
- throw RuntimeGenericError("Isolate is disposed");
427
- }
428
-
429
- Isolate* iso = Isolate::GetCurrent();
430
- v8::String::Utf8Value str(iso, title);
431
- const size_t len = strlen(*str);
432
-
433
- char* dest = (char*)std::malloc(len + 1);
434
-
435
- strcpy(dest, *str);
436
-
437
- return ThreePhaseTask::Run<async, StopCpuProfileRunner>(*isolate, dest);
438
- }
439
-
440
- /**
441
- * Reference count
442
- */
443
- auto IsolateHandle::GetReferenceCount() -> Local<Value> {
444
- auto env = this->isolate->GetIsolate();
445
- if (!env) {
446
- throw RuntimeGenericError("Isolate is disposed");
447
- }
448
- return Number::New(Isolate::GetCurrent(), env->GetRemotesCount());
449
- }
450
-
451
- /**
452
- * Simple disposal checker
453
- */
454
- auto IsolateHandle::IsDisposedGetter() -> Local<Value> {
455
- return Boolean::New(Isolate::GetCurrent(), !isolate->GetIsolate());
456
- }
457
-
458
- /**
459
- * Create a snapshot from some code and return it as an external ArrayBuffer
460
- */
461
- static auto SerializeInternalFieldsCallback(Local<Object> /*holder*/, int /*index*/, void* /*data*/) -> StartupData {
462
- return {nullptr, 0};
463
- }
464
-
465
- auto IsolateHandle::CreateSnapshot(ArrayRange script_handles, MaybeLocal<String> warmup_handle) -> Local<Value> {
466
-
467
- // Simple platform delegate and task queue
468
- using TaskDeque = lockable_t<std::deque<std::unique_ptr<v8::Task>>>;
469
- class SnapshotPlatformDelegate :
470
- public node::IsolatePlatformDelegate, public TaskRunner,
471
- public std::enable_shared_from_this<SnapshotPlatformDelegate> {
472
-
473
- public:
474
- explicit SnapshotPlatformDelegate(TaskDeque& tasks) : tasks{tasks} {}
475
-
476
- // v8 will continually post delayed tasks so we cut it off when work is done
477
- void DoneWithWork() {
478
- done = true;
479
- }
480
-
481
- // Methods for IsolatePlatformDelegate
482
- auto GetForegroundTaskRunner() -> std::shared_ptr<v8::TaskRunner> final {
483
- return shared_from_this();
484
- }
485
- auto IdleTasksEnabled() -> bool final {
486
- return false;
487
- }
488
-
489
- // Methods for v8::TaskRunner
490
- void PostTaskImpl(std::unique_ptr<v8::Task> task, const v8::SourceLocation& /*location*/) final {
491
- tasks.write()->push_back(std::move(task));
492
- }
493
- void PostDelayedTaskImpl(std::unique_ptr<v8::Task> task, double /*delay_in_seconds*/, const v8::SourceLocation& location) final {
494
- if (!done) {
495
- #if V8_AT_LEAST(13, 3, 241)
496
- PostTask(std::move(task), location);
497
- #else
498
- PostTask(std::move(task));
499
- #endif
500
- }
501
- }
502
- void PostNonNestableTaskImpl(std::unique_ptr<v8::Task> task, const v8::SourceLocation& location) final {
503
- #if V8_AT_LEAST(13, 3, 241)
504
- PostTask(std::move(task), location);
505
- #else
506
- PostTask(std::move(task));
507
- #endif
508
- }
509
-
510
- private:
511
- lockable_t<std::deque<std::unique_ptr<v8::Task>>>& tasks;
512
- bool done = false;
513
- };
514
-
515
- TaskDeque tasks;
516
- auto delegate = std::make_shared<SnapshotPlatformDelegate>(tasks);
517
-
518
- // Copy embed scripts and warmup script from outer isolate
519
- std::vector<std::pair<ExternalCopyString, ScriptOriginHolder>> scripts;
520
- Isolate* isolate = Isolate::GetCurrent();
521
- Local<Context> context = isolate->GetCurrentContext();
522
- scripts.reserve(std::distance(script_handles.begin(), script_handles.end()));
523
- for (auto value : script_handles) {
524
- auto script_handle = HandleCast<Local<Object>>(value);
525
- Local<Value> script = Unmaybe(script_handle.As<Object>()->Get(context, StringTable::Get().code));
526
- if (!script->IsString()) {
527
- throw RuntimeTypeError("`code` property is required");
528
- }
529
- scripts.emplace_back(ExternalCopyString{script.As<String>()}, ScriptOriginHolder{script_handle});
530
- }
531
- ExternalCopyString warmup_script;
532
- if (!warmup_handle.IsEmpty()) {
533
- warmup_script = ExternalCopyString{warmup_handle.ToLocalChecked().As<String>()};
534
- }
535
-
536
- // Create the snapshot
537
- StartupData snapshot {};
538
- unique_ptr<const char[]> snapshot_data_ptr;
539
- shared_ptr<ExternalCopy> error;
540
- {
541
- Isolate* isolate;
542
- isolate = Isolate::Allocate();
543
- PlatformDelegate::RegisterIsolate(isolate, delegate.get());
544
- SnapshotCreator snapshot_creator{isolate};
545
- {
546
- Locker locker(isolate);
547
- Isolate::Scope isolate_scope(isolate);
548
- HandleScope handle_scope(isolate);
549
- Local<Context> context = Context::New(isolate);
550
- snapshot_creator.SetDefaultContext(context, {&SerializeInternalFieldsCallback, nullptr});
551
- FunctorRunners::RunCatchExternal(context, [&]() {
552
- HandleScope handle_scope(isolate);
553
- Local<Context> context_dirty = Context::New(isolate);
554
- for (auto& script : scripts) {
555
- Local<String> code = script.first.CopyInto().As<String>();
556
- ScriptOrigin script_origin = ScriptOrigin{script.second};
557
- ScriptCompiler::Source source{code, script_origin};
558
- Local<UnboundScript> unbound_script;
559
- {
560
- Context::Scope context_scope{context};
561
- Local<Script> compiled_script = RunWithAnnotatedErrors(
562
- [&context, &source]() { return Unmaybe(ScriptCompiler::Compile(context, &source, ScriptCompiler::kNoCompileOptions)); }
563
- );
564
- Unmaybe(compiled_script->Run(context));
565
- unbound_script = compiled_script->GetUnboundScript();
566
- }
567
- if (warmup_script) {
568
- Context::Scope context_scope{context_dirty};
569
- Unmaybe(unbound_script->BindToCurrentContext()->Run(context_dirty));
570
- }
571
- }
572
- if (warmup_script) {
573
- Context::Scope context_scope{context_dirty};
574
- MaybeLocal<Object> tmp;
575
- ScriptOriginHolder script_origin{tmp};
576
- ScriptCompiler::Source source{warmup_script.CopyInto().As<String>(), ScriptOrigin{script_origin}};
577
- RunWithAnnotatedErrors([&context_dirty, &source]() {
578
- Unmaybe(Unmaybe(ScriptCompiler::Compile(context_dirty, &source, ScriptCompiler::kNoCompileOptions))->Run(context_dirty));
579
- });
580
- }
581
- }, [ &error ](unique_ptr<ExternalCopy> error_inner) {
582
- error = std::move(error_inner);
583
- });
584
- isolate->ContextDisposedNotification(false);
585
-
586
- // Run all queued tasks
587
- delegate->DoneWithWork();
588
- while (true) {
589
- auto task = [&]() -> std::unique_ptr<v8::Task> {
590
- auto lock = tasks.write();
591
- if (lock->empty()) {
592
- return nullptr;
593
- }
594
- auto task = std::move(lock->front());
595
- lock->pop_front();
596
- return task;
597
- }();
598
- if (task) {
599
- task->Run();
600
- } else {
601
- break;
602
- }
603
- }
604
- }
605
- // nb: Snapshot must be created even in the error case, because `~SnapshotCreator` will crash if
606
- // you don't
607
- snapshot = snapshot_creator.CreateBlob(SnapshotCreator::FunctionCodeHandling::kKeep);
608
- snapshot_data_ptr.reset(snapshot.data);
609
- PlatformDelegate::UnregisterIsolate(isolate);
610
- }
611
-
612
- // Export to outer scope
613
- if (error) {
614
- Isolate::GetCurrent()->ThrowException(error->CopyInto());
615
- return Undefined(Isolate::GetCurrent());
616
- } else if (snapshot.raw_size == 0) {
617
- throw RuntimeGenericError("Failure creating snapshot");
618
- }
619
- auto buffer = std::make_shared<ExternalCopyArrayBuffer>((void*)snapshot.data, snapshot.raw_size);
620
- return ClassHandle::NewInstance<ExternalCopyHandle>(buffer);
621
- }
622
-
623
- } // namespace ivm
@@ -1,47 +0,0 @@
1
- #pragma once
2
- #include "isolate/generic/array.h"
3
- #include "transferable.h"
4
- #include <v8.h>
5
- #include <memory>
6
-
7
- namespace ivm {
8
-
9
- /**
10
- * Reference to a v8 isolate
11
- */
12
- class IsolateHandle : public TransferableHandle {
13
- private:
14
- std::shared_ptr<IsolateHolder> isolate;
15
-
16
- class IsolateHandleTransferable : public Transferable {
17
- private:
18
- std::shared_ptr<IsolateHolder> isolate;
19
- public:
20
- explicit IsolateHandleTransferable(std::shared_ptr<IsolateHolder> isolate);
21
- auto TransferIn() -> v8::Local<v8::Value> final;
22
- };
23
-
24
- public:
25
- explicit IsolateHandle(std::shared_ptr<IsolateHolder> isolate);
26
- static auto Definition() -> v8::Local<v8::FunctionTemplate>;
27
- static auto New(v8::MaybeLocal<v8::Object> maybe_options) -> std::unique_ptr<ClassHandle>;
28
- auto TransferOut() -> std::unique_ptr<Transferable> final;
29
-
30
- template <int async> auto CreateContext(v8::MaybeLocal<v8::Object> maybe_options) -> v8::Local<v8::Value>;
31
- template <int async> auto CompileScript(v8::Local<v8::String> code_handle, v8::MaybeLocal<v8::Object> maybe_options) -> v8::Local<v8::Value>;
32
- template <int async> auto CompileModule(v8::Local<v8::String> code_handle, v8::MaybeLocal<v8::Object> maybe_options) -> v8::Local<v8::Value>;
33
-
34
- auto CreateInspectorSession() -> v8::Local<v8::Value>;
35
- auto Dispose() -> v8::Local<v8::Value>;
36
- template <int async> auto GetHeapStatistics() -> v8::Local<v8::Value>;
37
- auto GetCpuTime() -> v8::Local<v8::Value>;
38
- auto GetWallTime() -> v8::Local<v8::Value>;
39
- auto StartCpuProfiler(v8::Local<v8::String> title) -> v8::Local<v8::Value>;
40
- template <int async> auto StopCpuProfiler(v8::Local<v8::String> title) -> v8::Local<v8::Value>;
41
-
42
- auto GetReferenceCount() -> v8::Local<v8::Value>;
43
- auto IsDisposedGetter() -> v8::Local<v8::Value>;
44
- static auto CreateSnapshot(ArrayRange script_handles, v8::MaybeLocal<v8::String> warmup_handle) -> v8::Local<v8::Value>;
45
- };
46
-
47
- } // namespace ivm