@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,509 +0,0 @@
1
- #include "external_copy.h"
2
- #include "error.h"
3
- #include "serializer.h"
4
- #include "./string.h"
5
-
6
- #include "isolate/allocator.h"
7
- #include "isolate/environment.h"
8
- #include "isolate/functor_runners.h"
9
- #include "isolate/util.h"
10
- #include "isolate/v8_version.h"
11
-
12
- #include <algorithm>
13
- #include <cstring>
14
-
15
- using namespace v8;
16
-
17
- namespace ivm {
18
- namespace {
19
-
20
- /**
21
- * This is used for Number (several C++ types), or Boolean.
22
- */
23
- template <class Type>
24
- struct ExternalCopyTemplateCtor {
25
- template <class Native>
26
- static auto New(Isolate* isolate, Native value) -> Local<Value> {
27
- return Type::New(isolate, value);
28
- }
29
- };
30
-
31
- template <>
32
- struct ExternalCopyTemplateCtor<Uint32> {
33
- static auto New(Isolate* isolate, uint32_t value) -> Local<Value> {
34
- return Uint32::NewFromUnsigned(isolate, value);
35
- }
36
- };
37
-
38
- template <class Type, class Native>
39
- class ExternalCopyTemplate : public ExternalCopy {
40
- public:
41
- explicit ExternalCopyTemplate(Local<Value> value) :
42
- ExternalCopy{sizeof(ExternalCopyTemplate)},
43
- value{value.As<Type>()->Value()} {}
44
-
45
- auto CopyInto(bool /*transfer_in*/ = false) -> Local<Value> final {
46
- return ExternalCopyTemplateCtor<Type>::New(Isolate::GetCurrent(), value);
47
- }
48
-
49
- private:
50
- const Native value;
51
- };
52
-
53
- /**
54
- * BigInt data
55
- */
56
- struct ExternalCopyBigInt : public ExternalCopy {
57
- public:
58
- explicit ExternalCopyBigInt(Local<BigInt> value) {
59
- int word_count = value->WordCount();
60
- words.resize(word_count);
61
- value->ToWordsArray(&sign_bit, &word_count, words.data());
62
- }
63
-
64
- auto CopyInto(bool /*transfer_in*/ = false) -> Local<Value> final {
65
- return Unmaybe(BigInt::NewFromWords(
66
- Isolate::GetCurrent()->GetCurrentContext(), sign_bit, words.size(), words.data()));
67
- }
68
-
69
- private:
70
- int sign_bit = 0;
71
- std::vector<uint64_t> words;
72
- };
73
-
74
- /**
75
- * null and undefined
76
- */
77
- class ExternalCopyNull : public ExternalCopy {
78
- public:
79
- auto CopyInto(bool /*transfer_in*/ = false) -> Local<Value> final {
80
- return Null(Isolate::GetCurrent());
81
- }
82
- };
83
-
84
- class ExternalCopyUndefined : public ExternalCopy {
85
- public:
86
- auto CopyInto(bool /*transfer_in*/ = false) -> v8::Local<v8::Value> final {
87
- return Undefined(Isolate::GetCurrent());
88
- }
89
- };
90
-
91
- // Global size counter
92
- std::atomic<size_t> total_allocated_size {0};
93
-
94
- } // anonymous namespace
95
-
96
- /**
97
- * ExternalCopy implementation
98
- */
99
- ExternalCopy::ExternalCopy(int size) : size{size} {
100
- total_allocated_size += size;
101
- }
102
-
103
- ExternalCopy::ExternalCopy(ExternalCopy&& that) noexcept : size{std::exchange(that.size, 0)} {}
104
-
105
- ExternalCopy::~ExternalCopy() {
106
- total_allocated_size -= size;
107
- }
108
-
109
- auto ExternalCopy::operator= (ExternalCopy&& that) noexcept -> ExternalCopy& {
110
- size = std::exchange(that.size, 0);
111
- return *this;
112
- }
113
-
114
- auto ExternalCopy::Copy(Local<Value> value, bool transfer_out, ArrayRange transfer_list)
115
- -> std::unique_ptr<ExternalCopy> {
116
- std::unique_ptr<ExternalCopy> copy = CopyIfPrimitive(value);
117
- if (copy) {
118
- return copy;
119
- } else if (value->IsArrayBuffer()) {
120
- Local<ArrayBuffer> array_buffer = Local<ArrayBuffer>::Cast(value);
121
- if (!transfer_out) {
122
- transfer_out = std::find(transfer_list.begin(), transfer_list.end(), array_buffer) != transfer_list.end();
123
- }
124
- if (transfer_out) {
125
- return ExternalCopyArrayBuffer::Transfer(array_buffer);
126
- } else {
127
- return std::make_unique<ExternalCopyArrayBuffer>(array_buffer);
128
- }
129
- } else if (value->IsSharedArrayBuffer()) {
130
- return std::make_unique<ExternalCopySharedArrayBuffer>(value.As<SharedArrayBuffer>());
131
- } else if (value->IsArrayBufferView()) {
132
- Local<ArrayBufferView> view = value.As<ArrayBufferView>();
133
- using ViewType = ExternalCopyArrayBufferView::ViewType;
134
- ViewType type;
135
- if (view->IsUint8Array()) {
136
- type = ViewType::Uint8;
137
- } else if (view->IsUint8ClampedArray()) {
138
- type = ViewType::Uint8Clamped;
139
- } else if (view->IsInt8Array()) {
140
- type = ViewType::Int8;
141
- } else if (view->IsUint16Array()) {
142
- type = ViewType::Uint16;
143
- } else if (view->IsInt16Array()) {
144
- type = ViewType::Int16;
145
- } else if (view->IsUint32Array()) {
146
- type = ViewType::Uint32;
147
- } else if (view->IsInt32Array()) {
148
- type = ViewType::Int32;
149
- } else if (view->IsFloat32Array()) {
150
- type = ViewType::Float32;
151
- } else if (view->IsFloat64Array()) {
152
- type = ViewType::Float64;
153
- } else if (view->IsBigInt64Array()) {
154
- type = ViewType::BigInt64;
155
- } else if (view->IsBigUint64Array()) {
156
- type = ViewType::BigUint64;
157
- } else if (view->IsDataView()) {
158
- type = ViewType::DataView;
159
- } else {
160
- assert(false);
161
- }
162
-
163
- // Sometimes TypedArrays don't actually have a real buffer allocated for them. The call to
164
- // `Buffer()` below will force v8 to attempt to create a buffer if it doesn't exist, and if
165
- // there is an allocation failure it will crash the process.
166
- if (!view->HasBuffer()) {
167
- auto* allocator = IsolateEnvironment::GetCurrent().GetLimitedAllocator();
168
- if (allocator != nullptr && !allocator->Check(view->ByteLength())) {
169
- throw RuntimeRangeError("Array buffer allocation failed");
170
- }
171
- }
172
-
173
- // `Buffer()` returns a Local<ArrayBuffer> but it may be a Local<SharedArrayBuffer>
174
- Local<Object> tmp = view->Buffer();
175
- if (tmp->IsArrayBuffer()) {
176
- Local<ArrayBuffer> array_buffer = tmp.As<ArrayBuffer>();
177
- if (!transfer_out) {
178
- transfer_out = std::find(transfer_list.begin(), transfer_list.end(), array_buffer) != transfer_list.end();
179
- }
180
- // Grab byte_offset and byte_length before the transfer because "neutering" the array buffer will null these out
181
- size_t byte_offset = view->ByteOffset();
182
- size_t byte_length = view->ByteLength();
183
- std::unique_ptr<ExternalCopyArrayBuffer> external_buffer;
184
- if (transfer_out) {
185
- external_buffer = ExternalCopyArrayBuffer::Transfer(array_buffer);
186
- } else {
187
- external_buffer = std::make_unique<ExternalCopyArrayBuffer>(array_buffer);
188
- }
189
- return std::make_unique<ExternalCopyArrayBufferView>(std::move(external_buffer), type, byte_offset, byte_length);
190
- } else {
191
- assert(tmp->IsSharedArrayBuffer());
192
- Local<SharedArrayBuffer> array_buffer = tmp.As<SharedArrayBuffer>();
193
- return std::make_unique<ExternalCopyArrayBufferView>(std::make_unique<ExternalCopySharedArrayBuffer>(array_buffer), type, view->ByteOffset(), view->ByteLength());
194
- }
195
- } else if (value->IsObject()) {
196
- return std::make_unique<ExternalCopySerialized>(value.As<Object>(), transfer_list);
197
- } else {
198
- throw RuntimeTypeError("Unsupported type");
199
- }
200
- }
201
-
202
- namespace {
203
- auto CopyIfPrimitiveImpl(Local<Value> value) -> std::unique_ptr<ExternalCopy> {
204
- if (value->IsString()) {
205
- return std::make_unique<ExternalCopyString>(value.As<String>());
206
- } else if (value->IsNumber()) {
207
- if (value->IsUint32()) {
208
- return std::make_unique<ExternalCopyTemplate<Uint32, uint32_t>>(value);
209
- } else if (value->IsInt32()) {
210
- return std::make_unique<ExternalCopyTemplate<Int32, int32_t>>(value);
211
- } else {
212
- // This handles Infinity, -Infinity, NaN
213
- return std::make_unique<ExternalCopyTemplate<Number, double>>(value);
214
- }
215
- } else if (value->IsBigInt()) {
216
- return std::make_unique<ExternalCopyBigInt>(value.As<BigInt>());
217
- } else if (value->IsBoolean()) {
218
- return std::make_unique<ExternalCopyTemplate<Boolean, bool>>(value);
219
- } else if (value->IsNull()) {
220
- return std::make_unique<ExternalCopyNull>();
221
- } else if (value->IsUndefined()) {
222
- return std::make_unique<ExternalCopyUndefined>();
223
- }
224
- return {};
225
- }
226
- }
227
-
228
- auto ExternalCopy::CopyIfPrimitive(Local<Value> value) -> std::unique_ptr<ExternalCopy> {
229
- if (!value->IsObject()) {
230
- return CopyIfPrimitiveImpl(value);
231
- }
232
- return {};
233
- }
234
-
235
- auto ExternalCopy::CopyThrownValue(Local<Value> value) -> std::unique_ptr<ExternalCopy> {
236
- if (value->IsObject()) {
237
-
238
- // Detect which subclass of Error was thrown (no better way to do this??)
239
- Isolate* isolate = Isolate::GetCurrent();
240
- Local<Object> object = Local<Object>::Cast(value);
241
- std::string name = *String::Utf8Value{isolate, object->GetConstructorName()};
242
- auto error_type = ExternalCopyError::ErrorType::CustomError;
243
- if (name == "Error") {
244
- error_type = ExternalCopyError::ErrorType::Error;
245
- } else if (name == "RangeError") {
246
- error_type = ExternalCopyError::ErrorType::RangeError;
247
- } else if (name == "ReferenceError") {
248
- error_type = ExternalCopyError::ErrorType::ReferenceError;
249
- } else if (name == "SyntaxError") {
250
- error_type = ExternalCopyError::ErrorType::SyntaxError;
251
- } else if (name == "TypeError") {
252
- error_type = ExternalCopyError::ErrorType::TypeError;
253
- }
254
-
255
- // Get error properties
256
- Local<Context> context = isolate->GetCurrentContext();
257
- TryCatch try_catch{isolate};
258
- auto get_property = [&](Local<Object> object, const char* key) {
259
- try {
260
- Local<Value> value = Unmaybe(object->Get(context, v8_string(key)));
261
- if (!value->IsUndefined()) {
262
- return ExternalCopyString{Unmaybe(value->ToString(context))};
263
- }
264
- } catch (const RuntimeError& cc_err) {
265
- try_catch.Reset();
266
- }
267
- return ExternalCopyString{};
268
- };
269
- ExternalCopyString message_copy = get_property(object, "message");
270
- ExternalCopyString stack_copy = get_property(object, "stack");
271
-
272
- // Return external error copy if this looked like an error
273
- if (error_type != ExternalCopyError::ErrorType::CustomError || message_copy || stack_copy) {
274
- ExternalCopyString name_copy;
275
- if (!message_copy) {
276
- message_copy = ExternalCopyString{""};
277
- }
278
- if (error_type == ExternalCopyError::ErrorType::CustomError) {
279
- name_copy = get_property(object, "name");
280
- }
281
- return std::make_unique<ExternalCopyError>(error_type, std::move(name_copy), std::move(message_copy), std::move(stack_copy));
282
- }
283
- }
284
- auto primitive_value = CopyIfPrimitiveImpl(value);
285
- if (primitive_value) {
286
- return primitive_value;
287
- }
288
- return std::make_unique<ExternalCopyError>(
289
- ExternalCopyError::ErrorType::Error,
290
- "An object was thrown from supplied code within isolated-vm, but that object was not an instance of `Error`."
291
- );
292
- }
293
-
294
- auto ExternalCopy::CopyIntoCheckHeap(bool transfer_in) -> Local<Value> {
295
- IsolateEnvironment::HeapCheck heap_check{IsolateEnvironment::GetCurrent()};
296
- auto value = CopyInto(transfer_in);
297
- heap_check.Epilogue();
298
- return value;
299
- }
300
-
301
- auto ExternalCopy::TotalExternalSize() -> int {
302
- return total_allocated_size;
303
- }
304
-
305
- void ExternalCopy::UpdateSize(int size) {
306
- total_allocated_size -= this->size - size;
307
- this->size = size;
308
- }
309
-
310
- /**
311
- * ExternalCopyError implementation
312
- */
313
- ExternalCopyError::ExternalCopyError(
314
- ErrorType error_type,
315
- ExternalCopyString name,
316
- ExternalCopyString message,
317
- ExternalCopyString stack
318
- ) :
319
- error_type{error_type},
320
- name{std::move(name)},
321
- message{std::move(message)},
322
- stack{std::move(stack)} {}
323
-
324
- ExternalCopyError::ExternalCopyError(ErrorType error_type, const char* message, const std::string& stack) :
325
- ExternalCopy{sizeof(ExternalCopyError)},
326
- error_type{error_type},
327
- message{ExternalCopyString{message}},
328
- stack{stack.empty() ? ExternalCopyString{} : ExternalCopyString{stack}} {}
329
-
330
- auto ExternalCopyError::CopyInto(bool /*transfer_in*/) -> Local<Value> {
331
-
332
- // First make the exception w/ correct + message
333
- Local<Context> context = Isolate::GetCurrent()->GetCurrentContext();
334
- Local<String> message = Local<String>::Cast(this->message.CopyInto(false));
335
- Local<Value> handle;
336
- switch (error_type) {
337
- default:
338
- handle = Exception::Error(message);
339
- if (name) {
340
- Unmaybe(handle.As<Object>()->DefineOwnProperty(context, StringTable::Get().name, name.CopyInto(), PropertyAttribute::DontEnum));
341
- }
342
- break;
343
- case ErrorType::RangeError:
344
- handle = Exception::RangeError(message);
345
- break;
346
- case ErrorType::ReferenceError:
347
- handle = Exception::ReferenceError(message);
348
- break;
349
- case ErrorType::SyntaxError:
350
- handle = Exception::SyntaxError(message);
351
- break;
352
- case ErrorType::TypeError:
353
- handle = Exception::TypeError(message);
354
- break;
355
- }
356
-
357
- // Now add stack information
358
- if (this->stack) {
359
- Local<String> stack = Local<String>::Cast(this->stack.CopyInto(false));
360
- Unmaybe(Local<Object>::Cast(handle)->Set(context, StringTable::Get().stack, stack));
361
- }
362
- return handle;
363
- }
364
-
365
- /**
366
- * ExternalCopyAnyBuffer implementation
367
- */
368
- namespace {
369
- void Detach(Local<ArrayBuffer> handle) {
370
- handle->Detach();
371
- }
372
- auto IsDetachable(Local<ArrayBuffer> handle) {
373
- return handle->IsDetachable();
374
- }
375
- } // anonymous namespace
376
-
377
-
378
-
379
- /**
380
- * ExternalCopyArrayBuffer implementation
381
- */
382
- ExternalCopyArrayBuffer::ExternalCopyArrayBuffer(const void* data, size_t length) :
383
- ExternalCopyAnyBuffer{ArrayBuffer::NewBackingStore(
384
- std::malloc(length), length,
385
- [](void* data, size_t /*length*/, void* /*param*/) { std::free(data); },
386
- nullptr)}
387
- {
388
- std::memcpy((*backing_store.read())->Data(), data, length);
389
- }
390
-
391
- ExternalCopyArrayBuffer::ExternalCopyArrayBuffer(Local<ArrayBuffer> handle) :
392
- ExternalCopyArrayBuffer{
393
- handle->GetBackingStore()->Data(),
394
- handle->ByteLength()
395
- } {}
396
-
397
- auto ExternalCopyArrayBuffer::Transfer(Local<ArrayBuffer> handle) -> std::unique_ptr<ExternalCopyArrayBuffer> {
398
- if (!IsDetachable(handle)) {
399
- throw RuntimeGenericError("Array buffer is invalid");
400
- }
401
- auto backing_store = handle->GetBackingStore();
402
- Detach(handle);
403
- return std::make_unique<ExternalCopyArrayBuffer>(std::move(backing_store));
404
- }
405
-
406
- auto ExternalCopyArrayBuffer::CopyInto(bool transfer_in) -> Local<Value> {
407
- if (transfer_in) {
408
- auto backing_store = std::exchange(*this->backing_store.write(), {});
409
- if (!backing_store) {
410
- throw RuntimeGenericError("Array buffer is invalid");
411
- }
412
- UpdateSize(0);
413
- size_t size = backing_store->ByteLength();
414
- auto handle = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
415
- auto* allocator = IsolateEnvironment::GetCurrent().GetLimitedAllocator();
416
- if (allocator != nullptr) {
417
- allocator->Track(handle, size);
418
- }
419
- return handle;
420
- } else {
421
- auto* allocator = IsolateEnvironment::GetCurrent().GetLimitedAllocator();
422
- auto backing_store = *this->backing_store.read();
423
- if (!backing_store) {
424
- throw RuntimeGenericError("Array buffer is invalid");
425
- }
426
- auto size = backing_store->ByteLength();
427
- if (allocator != nullptr && !allocator->Check(size)) {
428
- // ArrayBuffer::New will crash the process if there is an allocation failure, so we check
429
- // here.
430
- throw RuntimeRangeError("Array buffer allocation failed");
431
- }
432
- auto handle = ArrayBuffer::New(Isolate::GetCurrent(), size);
433
- auto* data = handle->GetBackingStore()->Data();
434
- std::memcpy(data, backing_store->Data(), size);
435
- return handle;
436
- }
437
- }
438
-
439
- /**
440
- * ExternalCopySharedArrayBuffer implementation
441
- */
442
- ExternalCopySharedArrayBuffer::ExternalCopySharedArrayBuffer(Local<SharedArrayBuffer> handle) :
443
- ExternalCopyAnyBuffer{handle->GetBackingStore()} {}
444
-
445
- auto ExternalCopySharedArrayBuffer::CopyInto(bool /*transfer_in*/) -> Local<Value> {
446
- auto backing_store = *this->backing_store.read();
447
- size_t size = backing_store->ByteLength();
448
- auto handle = SharedArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
449
- auto* allocator = IsolateEnvironment::GetCurrent().GetLimitedAllocator();
450
- if (allocator != nullptr) {
451
- allocator->Track(handle, size);
452
- }
453
- return handle;
454
- }
455
-
456
- /**
457
- * ExternalCopyArrayBufferView implementation
458
- */
459
- ExternalCopyArrayBufferView::ExternalCopyArrayBufferView(
460
- std::unique_ptr<ExternalCopyAnyBuffer> buffer,
461
- ViewType type, size_t byte_offset, size_t byte_length
462
- ) :
463
- ExternalCopy(sizeof(ExternalCopyArrayBufferView)),
464
- buffer(std::move(buffer)),
465
- type(type),
466
- byte_offset(byte_offset), byte_length(byte_length) {}
467
-
468
- template <typename T>
469
- auto NewTypedArrayView(Local<T> buffer, ExternalCopyArrayBufferView::ViewType type, size_t byte_offset, size_t byte_length) -> Local<Value> {
470
- switch (type) {
471
- case ExternalCopyArrayBufferView::ViewType::Uint8:
472
- return Uint8Array::New(buffer, byte_offset, byte_length >> 0);
473
- case ExternalCopyArrayBufferView::ViewType::Uint8Clamped:
474
- return Uint8ClampedArray::New(buffer, byte_offset, byte_length >> 0);
475
- case ExternalCopyArrayBufferView::ViewType::Int8:
476
- return Int8Array::New(buffer, byte_offset, byte_length >> 0);
477
- case ExternalCopyArrayBufferView::ViewType::Uint16:
478
- return Uint16Array::New(buffer, byte_offset, byte_length >> 1);
479
- case ExternalCopyArrayBufferView::ViewType::Int16:
480
- return Int16Array::New(buffer, byte_offset, byte_length >> 1);
481
- case ExternalCopyArrayBufferView::ViewType::Uint32:
482
- return Uint32Array::New(buffer, byte_offset, byte_length >> 2);
483
- case ExternalCopyArrayBufferView::ViewType::Int32:
484
- return Int32Array::New(buffer, byte_offset, byte_length >> 2);
485
- case ExternalCopyArrayBufferView::ViewType::Float32:
486
- return Float32Array::New(buffer, byte_offset, byte_length >> 2);
487
- case ExternalCopyArrayBufferView::ViewType::Float64:
488
- return Float64Array::New(buffer, byte_offset, byte_length >> 3);
489
- case ExternalCopyArrayBufferView::ViewType::BigInt64:
490
- return BigInt64Array::New(buffer, byte_offset, byte_length >> 3);
491
- case ExternalCopyArrayBufferView::ViewType::BigUint64:
492
- return BigUint64Array::New(buffer, byte_offset, byte_length >> 3);
493
- case ExternalCopyArrayBufferView::ViewType::DataView:
494
- return DataView::New(buffer, byte_offset, byte_length);
495
- default:
496
- throw std::exception();
497
- }
498
- }
499
-
500
- auto ExternalCopyArrayBufferView::CopyInto(bool transfer_in) -> Local<Value> {
501
- Local<Value> buffer = this->buffer->CopyInto(transfer_in);
502
- if (buffer->IsArrayBuffer()) {
503
- return NewTypedArrayView(buffer.As<ArrayBuffer>(), type, byte_offset, byte_length);
504
- } else {
505
- return NewTypedArrayView(buffer.As<SharedArrayBuffer>(), type, byte_offset, byte_length);
506
- }
507
- }
508
-
509
- } // namespace ivm
@@ -1,117 +0,0 @@
1
- #pragma once
2
- #include <v8.h>
3
- #include <atomic>
4
- #include <cstdint>
5
- #include <cstdlib>
6
- #include <memory>
7
- #include <vector>
8
-
9
- #include "isolate/generic/array.h"
10
- #include "isolate/allocator.h"
11
- #include "isolate/transferable.h"
12
- #include "isolate/util.h"
13
- #include "lib/lockable.h"
14
-
15
- namespace ivm {
16
-
17
- using handle_vector_t = std::vector<v8::Local<v8::Value>>;
18
- using transferable_vector_t = std::vector<std::unique_ptr<Transferable>>;
19
- using array_buffer_vector_t = std::vector<std::unique_ptr<class ExternalCopyArrayBuffer>>;
20
- using shared_buffer_vector_t = std::vector<std::unique_ptr<class ExternalCopySharedArrayBuffer>>;
21
-
22
- class ExternalCopy : public Transferable {
23
- public:
24
- ExternalCopy() = default;
25
- ExternalCopy(const ExternalCopy&) = delete;
26
- auto operator= (const ExternalCopy&) = delete;
27
- ~ExternalCopy() override;
28
-
29
- /**
30
- * `Copy` may throw a v8 exception if JSON.stringify(value) throws
31
- */
32
- static auto Copy(
33
- v8::Local<v8::Value> value,
34
- bool transfer_out = false,
35
- ArrayRange transfer_list = {}
36
- ) -> std::unique_ptr<ExternalCopy>;
37
-
38
- /**
39
- * If you give this a primitive v8::Value (except Symbol) it will return a ExternalCopy for you.
40
- * Otherwise it returns nullptr. This is used to automatically move simple values between
41
- * isolates where it is possible to do so perfectly.
42
- */
43
- static auto CopyIfPrimitive(v8::Local<v8::Value> value) -> std::unique_ptr<ExternalCopy>;
44
- static auto CopyThrownValue(v8::Local<v8::Value> value) -> std::unique_ptr<ExternalCopy>;
45
-
46
- static auto TotalExternalSize() -> int;
47
-
48
- auto CopyIntoCheckHeap(bool transfer_in = false) -> v8::Local<v8::Value>;
49
- virtual auto CopyInto(bool transfer_in = false) -> v8::Local<v8::Value> = 0;
50
- auto Size() const -> int { return size; }
51
- auto TransferIn() -> v8::Local<v8::Value> final { return CopyIntoCheckHeap(); }
52
-
53
- protected:
54
- explicit ExternalCopy(int size);
55
- ExternalCopy(ExternalCopy&& that) noexcept;
56
- auto operator= (ExternalCopy&& that) noexcept -> ExternalCopy&;
57
-
58
- void UpdateSize(int size);
59
-
60
- private:
61
- int size = 0;
62
- };
63
-
64
- /**
65
- * Base class for ArrayBuffer and SharedArrayBuffer
66
- */
67
- class ExternalCopyAnyBuffer : public ExternalCopy {
68
- public:
69
- explicit ExternalCopyAnyBuffer(std::shared_ptr<v8::BackingStore> backing_store) :
70
- backing_store{std::move(backing_store)} {}
71
- auto Acquire() const -> std::shared_ptr<v8::BackingStore> { return *backing_store.read(); }
72
-
73
- protected:
74
- lockable_t<std::shared_ptr<v8::BackingStore>> backing_store;
75
- };
76
-
77
- /**
78
- * ArrayBuffer instances
79
- */
80
- class ExternalCopyArrayBuffer : public ExternalCopyAnyBuffer {
81
- public:
82
- using ExternalCopyAnyBuffer::ExternalCopyAnyBuffer;
83
- ExternalCopyArrayBuffer(const void* data, size_t length);
84
- explicit ExternalCopyArrayBuffer(v8::Local<v8::ArrayBuffer> handle);
85
-
86
- static auto Transfer(v8::Local<v8::ArrayBuffer> handle) -> std::unique_ptr<ExternalCopyArrayBuffer>;
87
- auto CopyInto(bool transfer_in = false) -> v8::Local<v8::Value> final;
88
- };
89
-
90
- /**
91
- * SharedArrayBuffer instances
92
- */
93
- class ExternalCopySharedArrayBuffer : public ExternalCopyAnyBuffer {
94
- public:
95
- explicit ExternalCopySharedArrayBuffer(v8::Local<v8::SharedArrayBuffer> handle);
96
-
97
- auto CopyInto(bool transfer_in = false) -> v8::Local<v8::Value> final;
98
- };
99
-
100
- /**
101
- * All types of TypedArray views w/ underlying buffer handle
102
- */
103
- class ExternalCopyArrayBufferView : public ExternalCopy {
104
- public:
105
- enum class ViewType { Uint8, Uint8Clamped, Int8, Uint16, Int16, Uint32, Int32, Float32, Float64, BigInt64, BigUint64, DataView };
106
-
107
- private:
108
- std::unique_ptr<ExternalCopyAnyBuffer> buffer;
109
- ViewType type;
110
- size_t byte_offset, byte_length;
111
-
112
- public:
113
- ExternalCopyArrayBufferView(std::unique_ptr<ExternalCopyAnyBuffer> buffer, ViewType type, size_t byte_offset, size_t byte_length);
114
- auto CopyInto(bool transfer_in = false) -> v8::Local<v8::Value> final;
115
- };
116
-
117
- } // namespace ivm