@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,85 +0,0 @@
1
- #include "serializer.h"
2
- #include "isolate/allocator.h"
3
-
4
- using namespace v8;
5
- namespace ivm {
6
-
7
- /**
8
- * ExternalCopySerialized implementation
9
- */
10
- ExternalCopySerialized::ExternalCopySerialized(Local<Value> value, ArrayRange transfer_list) :
11
- BaseSerializer{[&](ValueSerializer& serializer, Local<Context> context) {
12
- // Mark ArrayBuffers as transferred, but don't actually transfer yet otherwise it will invalidate
13
- // array views before they are transferred
14
- int ii = 0;
15
- for (auto handle : transfer_list) {
16
- if (handle->IsArrayBuffer()) {
17
- serializer.TransferArrayBuffer(ii++, handle.As<ArrayBuffer>());
18
- } else {
19
- throw RuntimeTypeError("Non-ArrayBuffer passed in `transferList`");
20
- }
21
- }
22
-
23
- // Serialize object and save
24
- serializer.WriteHeader();
25
- Unmaybe(serializer.WriteValue(context, value));
26
- }} {
27
-
28
- // Transfer ArrayBuffers
29
- for (auto handle : transfer_list) {
30
- array_buffers.emplace_back(ExternalCopyArrayBuffer::Transfer(handle.As<ArrayBuffer>()));
31
- }
32
- }
33
-
34
- auto ExternalCopySerialized::CopyInto(bool transfer_in) -> Local<Value> {
35
- Local<Value> value;
36
-
37
- Deserialize([&](ValueDeserializer& deserializer, Local<Context> context) {
38
- // Transfer ArrayBuffers
39
- for (unsigned ii = 0; ii < array_buffers.size(); ++ii) {
40
- deserializer.TransferArrayBuffer(ii, array_buffers[ii]->CopyIntoCheckHeap(transfer_in).As<ArrayBuffer>());
41
- }
42
-
43
- // Deserialize object
44
- Unmaybe(deserializer.ReadHeader(context));
45
- return deserializer.ReadValue(context).ToLocal(&value);
46
- });
47
-
48
- return value;
49
- }
50
-
51
- /**
52
- * SerializedVector implementation
53
- */
54
- SerializedVector::SerializedVector(const v8::FunctionCallbackInfo<v8::Value>& info) :
55
- BaseSerializer([&](ValueSerializer& serializer, Local<Context> context) {
56
- int length = info.Length();
57
- serializer.WriteUint32(length);
58
- for (int ii = 0; ii < length; ++ii) {
59
- Unmaybe(serializer.WriteValue(context, info[ii]));
60
- }
61
- }) {}
62
-
63
- auto SerializedVector::CopyIntoAsVector() -> std::vector<Local<Value>> {
64
- std::vector<Local<Value>> result;
65
- Deserialize([&](ValueDeserializer& deserializer, Local<Context> context) {
66
- // Read length
67
- uint32_t length;
68
- Unmaybe(deserializer.ReadHeader(context));
69
- if (!deserializer.ReadUint32(&length)) {
70
- throw RuntimeGenericError("Invalid arguments payload");
71
- }
72
-
73
- // Read arguments
74
- result.resize(length);
75
- for (unsigned ii = 0; ii < length; ++ii) {
76
- if (!deserializer.ReadValue(context).ToLocal(&result[ii])) {
77
- return false;
78
- }
79
- }
80
- return true;
81
- });
82
- return result;
83
- }
84
-
85
- } // namespace ivm
@@ -1,136 +0,0 @@
1
- #pragma once
2
- #include "external_copy.h"
3
- #include "isolate/environment.h"
4
- #include <deque>
5
- #include <memory>
6
- #include <vector>
7
-
8
- namespace ivm {
9
- namespace detail {
10
-
11
- class SerializationDelegateBase {
12
- public:
13
- SerializationDelegateBase(
14
- std::deque<std::unique_ptr<Transferable>>& transferables,
15
- std::deque<v8::CompiledWasmModule>& wasm_modules
16
- ) : transferables{transferables}, wasm_modules{wasm_modules} {}
17
-
18
- protected:
19
- std::deque<std::unique_ptr<Transferable>>& transferables;
20
- std::deque<v8::CompiledWasmModule>& wasm_modules;
21
- };
22
-
23
- class SerializerDelegate : public SerializationDelegateBase, public v8::ValueSerializer::Delegate {
24
- public:
25
- using SerializationDelegateBase::SerializationDelegateBase;
26
-
27
- void SetSerializer(v8::ValueSerializer* serializer) { this->serializer = serializer; }
28
- void ThrowDataCloneError(v8::Local<v8::String> message) final;
29
-
30
- auto GetSharedArrayBufferId(
31
- v8::Isolate* isolate, v8::Local<v8::SharedArrayBuffer> shared_array_buffer) -> v8::Maybe<uint32_t> final;
32
- auto GetWasmModuleTransferId(
33
- v8::Isolate* isolate, v8::Local<v8::WasmModuleObject> module) -> v8::Maybe<uint32_t> final;
34
- auto WriteHostObject(v8::Isolate* isolate, v8::Local<v8::Object> object) -> v8::Maybe<bool> final;
35
-
36
- private:
37
- v8::ValueSerializer* serializer = nullptr;
38
- };
39
-
40
- class DeserializerDelegate : public SerializationDelegateBase, public v8::ValueDeserializer::Delegate {
41
- public:
42
- using SerializationDelegateBase::SerializationDelegateBase;
43
-
44
- void SetDeserializer(v8::ValueDeserializer* deserializer) { this->deserializer = deserializer; }
45
-
46
- auto GetSharedArrayBufferFromId(
47
- v8::Isolate* isolate, uint32_t clone_id) -> v8::MaybeLocal<v8::SharedArrayBuffer> final;
48
- auto GetWasmModuleFromId(
49
- v8::Isolate* isolate, uint32_t transfer_id) -> v8::MaybeLocal<v8::WasmModuleObject> final;
50
- auto ReadHostObject(v8::Isolate* isolate) -> v8::MaybeLocal<v8::Object> final;
51
-
52
- private:
53
- v8::ValueDeserializer* deserializer = nullptr;
54
- };
55
-
56
- } // namespace detail
57
-
58
- /**
59
- * Abstract serializer which manages boilerplate and lifecycle management of the serialized blob
60
- */
61
- class BaseSerializer {
62
- protected:
63
- template <class Fn>
64
- explicit BaseSerializer(Fn fn) {
65
- // Initialize serializer and delegate
66
- auto* isolate = v8::Isolate::GetCurrent();
67
- auto context = isolate->GetCurrentContext();
68
- detail::SerializerDelegate delegate{transferables, wasm_modules};
69
- v8::ValueSerializer serializer{isolate, &delegate};
70
- delegate.SetSerializer(&serializer);
71
-
72
- // Run serialization
73
- serializer.WriteHeader();
74
- fn(serializer, context);
75
-
76
- // Save to buffer
77
- auto serialized_data = serializer.Release();
78
- buffer = {serialized_data.first, std::free};
79
- size = serialized_data.second;
80
- }
81
-
82
- template <class Fn>
83
- auto Deserialize(Fn fn) {
84
- // Initialize deserializer and delegate
85
- auto* isolate = v8::Isolate::GetCurrent();
86
- auto context = isolate->GetCurrentContext();
87
- detail::DeserializerDelegate delegate{transferables, wasm_modules};
88
- v8::ValueDeserializer deserializer{isolate, buffer.get(), size, &delegate};
89
- delegate.SetDeserializer(&deserializer);
90
-
91
- // Watch for allocation errors
92
- auto* allocator = IsolateEnvironment::GetCurrent().GetLimitedAllocator();
93
- int failures = allocator == nullptr ? 0 : allocator->GetFailureCount();
94
- Unmaybe(deserializer.ReadHeader(context));
95
-
96
- // Run implementation
97
- if (!fn(deserializer, context)) {
98
- // ValueDeserializer throws an unhelpful message when it fails to allocate an ArrayBuffer, so
99
- // detect that case here and throw an appropriate message.
100
- if (allocator != nullptr && allocator->GetFailureCount() != failures) {
101
- throw RuntimeRangeError("Array buffer allocation failed");
102
- } else {
103
- throw RuntimeError();
104
- }
105
- }
106
- }
107
-
108
- private:
109
- std::unique_ptr<uint8_t, decltype(std::free)*> buffer = {nullptr, std::free};
110
- std::deque<std::unique_ptr<Transferable>> transferables;
111
- std::deque<v8::CompiledWasmModule> wasm_modules;
112
- size_t size;
113
- };
114
-
115
- /**
116
- * Single serialized value compatible with `Transferable`
117
- */
118
- class ExternalCopySerialized : public BaseSerializer, public ExternalCopy {
119
- public:
120
- ExternalCopySerialized(v8::Local<v8::Value> value, ArrayRange transfer_list);
121
- auto CopyInto(bool transfer_in = false) -> v8::Local<v8::Value> final;
122
-
123
- private:
124
- std::vector<std::unique_ptr<ExternalCopyArrayBuffer>> array_buffers;
125
- };
126
-
127
- class SerializedVector : public BaseSerializer {
128
- public:
129
- explicit SerializedVector(const v8::FunctionCallbackInfo<v8::Value>& info);
130
- auto CopyIntoAsVector() -> std::vector<v8::Local<v8::Value>>;
131
-
132
- private:
133
- std::vector<std::unique_ptr<ExternalCopyArrayBuffer>> array_buffers;
134
- };
135
-
136
- } // namespace ivm
@@ -1,73 +0,0 @@
1
- #include "serializer.h"
2
- #include "isolate/functor_runners.h"
3
- #include "module/transferable.h"
4
-
5
- /**
6
- * This file is compiled *without* runtime type information, which matches the nodejs binary and
7
- * allows the serializer delegates to resolve correctly.
8
- */
9
-
10
- using namespace v8;
11
-
12
- namespace ivm::detail {
13
-
14
- void SerializerDelegate::ThrowDataCloneError(Local<String> message) {
15
- Isolate::GetCurrent()->ThrowException(Exception::TypeError(message));
16
- }
17
-
18
- auto SerializerDelegate::GetSharedArrayBufferId(
19
- Isolate* /*isolate*/, Local<SharedArrayBuffer> shared_array_buffer) -> Maybe<uint32_t> {
20
- auto result = Nothing<uint32_t>();
21
- detail::RunBarrier([&]() {
22
- transferables.emplace_back(std::make_unique<ExternalCopySharedArrayBuffer>(shared_array_buffer));
23
- result = Just<uint32_t>(transferables.size() - 1);
24
- });
25
- return result;
26
- }
27
-
28
- auto SerializerDelegate::GetWasmModuleTransferId(
29
- Isolate* /*isolate*/, Local<WasmModuleObject> module) -> Maybe<uint32_t> {
30
- auto result = Just<uint32_t>(wasm_modules.size());
31
- wasm_modules.emplace_back(module->GetCompiledModule());
32
- return result;
33
- }
34
-
35
- auto SerializerDelegate::WriteHostObject(Isolate* /*isolate*/, Local<Object> object) -> Maybe<bool> {
36
- auto result = Nothing<bool>();
37
- detail::RunBarrier([&]() {
38
- serializer->WriteUint32(transferables.size());
39
- transferables.emplace_back(TransferOut(object));
40
- result = Just(true);
41
- });
42
- return result;
43
- }
44
-
45
- auto DeserializerDelegate::ReadHostObject(Isolate* /*isolate*/) -> MaybeLocal<Object> {
46
- MaybeLocal<Object> result;
47
- detail::RunBarrier([&]() {
48
- uint32_t ii;
49
- assert(deserializer->ReadUint32(&ii));
50
- result = transferables[ii]->TransferIn().As<Object>();
51
- });
52
- return result;
53
- }
54
-
55
- auto DeserializerDelegate::GetSharedArrayBufferFromId(
56
- Isolate* /*isolate*/, uint32_t clone_id) -> MaybeLocal<SharedArrayBuffer> {
57
- MaybeLocal<SharedArrayBuffer> result;
58
- detail::RunBarrier([&]() {
59
- result = transferables[clone_id]->TransferIn().As<SharedArrayBuffer>();
60
- });
61
- return result;
62
- }
63
-
64
- auto DeserializerDelegate::GetWasmModuleFromId(
65
- Isolate* isolate, uint32_t transfer_id) -> MaybeLocal<WasmModuleObject> {
66
- MaybeLocal<WasmModuleObject> result;
67
- detail::RunBarrier([&]() {
68
- result = WasmModuleObject::FromCompiledModule(isolate, wasm_modules[transfer_id]);
69
- });
70
- return result;
71
- }
72
-
73
- } // namespace ivm::detail
@@ -1,124 +0,0 @@
1
- #include "isolate/environment.h"
2
- #include "./string.h"
3
- #include <cstring>
4
-
5
- using namespace v8;
6
-
7
- namespace ivm {
8
- namespace {
9
-
10
- /**
11
- * Helper classes passed to v8 so we can reuse the same externally allocated memory for strings
12
- * between different isolates
13
- */
14
- class ExternalString final : public v8::String::ExternalStringResource {
15
- public:
16
- explicit ExternalString(std::shared_ptr<std::vector<char>> value) : value{std::move(value)} {
17
- IsolateEnvironment::GetCurrent().AdjustExtraAllocatedMemory(this->value->size());
18
- }
19
-
20
- ExternalString(const ExternalString&) = delete;
21
-
22
- ~ExternalString() final {
23
- auto* environment = Executor::GetCurrentEnvironment();
24
- if (environment != nullptr) {
25
- environment->AdjustExtraAllocatedMemory(-static_cast<int>(this->value->size()));
26
- }
27
- }
28
-
29
- auto operator= (const ExternalString&) = delete;
30
-
31
- auto data() const -> const uint16_t* final {
32
- return reinterpret_cast<uint16_t*>(value->data());
33
- }
34
-
35
- auto length() const -> size_t final {
36
- return value->size() >> 1;
37
- }
38
-
39
- private:
40
- std::shared_ptr<std::vector<char>> value;
41
- };
42
-
43
- class ExternalStringOneByte final : public v8::String::ExternalOneByteStringResource {
44
- public:
45
- explicit ExternalStringOneByte(std::shared_ptr<std::vector<char>> value) : value{std::move(value)} {
46
- IsolateEnvironment::GetCurrent().AdjustExtraAllocatedMemory(this->value->size());
47
- }
48
-
49
- ExternalStringOneByte(const ExternalStringOneByte&) = delete;
50
-
51
- ~ExternalStringOneByte() final {
52
- auto* environment = Executor::GetCurrentEnvironment();
53
- if (environment != nullptr) {
54
- environment->AdjustExtraAllocatedMemory(-static_cast<int>(this->value->size()));
55
- }
56
- }
57
-
58
- auto operator= (const ExternalStringOneByte&) = delete;
59
-
60
- auto data() const -> const char* final {
61
- return value->data();
62
- }
63
-
64
- auto length() const -> size_t final {
65
- return value->size();
66
- }
67
-
68
- private:
69
- std::shared_ptr<std::vector<char>> value;
70
- };
71
-
72
- } // anonymous namespace
73
-
74
- /**
75
- * ExternalCopyString implementation
76
- */
77
- ExternalCopyString::ExternalCopyString(Local<String> string) :
78
- ExternalCopy{static_cast<int>((string->Length() << (string->IsOneByte() ? 0 : 1)) + sizeof(ExternalCopyString))} {
79
- if (string->IsOneByte()) {
80
- one_byte = true;
81
- value = std::make_shared<std::vector<char>>(string->Length());
82
- string->WriteOneByte(
83
- Isolate::GetCurrent(),
84
- reinterpret_cast<uint8_t*>(value->data()), 0, -1, String::WriteOptions::NO_NULL_TERMINATION
85
- );
86
- } else {
87
- one_byte = false;
88
- value = std::make_shared<std::vector<char>>(string->Length() << 1);
89
- string->Write(
90
- Isolate::GetCurrent(),
91
- reinterpret_cast<uint16_t*>(value->data()), 0, -1, String::WriteOptions::NO_NULL_TERMINATION
92
- );
93
- }
94
- }
95
-
96
- ExternalCopyString::ExternalCopyString(const char* string) :
97
- value{std::make_shared<std::vector<char>>(string, string + strlen(string))}, one_byte{true} {}
98
-
99
- ExternalCopyString::ExternalCopyString(const std::string& string) :
100
- value{std::make_shared<std::vector<char>>(string.begin(), string.end())}, one_byte{true} {}
101
-
102
- auto ExternalCopyString::CopyInto(bool /*transfer_in*/) -> Local<Value> {
103
- if (value->size() < 1024) {
104
- // Strings under 1kb will be internal v8 strings. I didn't experiment with this at all, but it
105
- // seems self-evident that there's some byte length under which it doesn't make sense to create
106
- // an external string so I picked 1kb.
107
- if (one_byte) {
108
- return Unmaybe(String::NewFromOneByte(Isolate::GetCurrent(),
109
- reinterpret_cast<uint8_t*>(value->data()), NewStringType::kNormal, value->size()));
110
- } else {
111
- return Unmaybe(String::NewFromTwoByte(Isolate::GetCurrent(),
112
- reinterpret_cast<uint16_t*>(value->data()), NewStringType::kNormal, value->size() >> 1));
113
- }
114
- } else {
115
- // External strings can save memory and/or copies
116
- if (one_byte) {
117
- return Unmaybe(String::NewExternalOneByte(Isolate::GetCurrent(), new ExternalStringOneByte(value)));
118
- } else {
119
- return Unmaybe(String::NewExternalTwoByte(Isolate::GetCurrent(), new ExternalString(value)));
120
- }
121
- }
122
- }
123
-
124
- } // namespace ivm
@@ -1,28 +0,0 @@
1
- #pragma once
2
- #include "external_copy.h"
3
- #include <memory>
4
- #include <vector>
5
-
6
- namespace ivm {
7
-
8
- class ExternalCopyString final : public ExternalCopy {
9
- public:
10
- ExternalCopyString() = default;
11
- explicit ExternalCopyString(v8::Local<v8::String> string);
12
- explicit ExternalCopyString(const char* string);
13
- explicit ExternalCopyString(const std::string& string);
14
- ExternalCopyString(const ExternalCopyString&) = delete;
15
- ExternalCopyString(ExternalCopyString&& that) = default;
16
- ~ExternalCopyString() final = default;
17
- auto operator= (const ExternalCopyString&) -> ExternalCopyString& = delete;
18
- auto operator= (ExternalCopyString&& that) noexcept -> ExternalCopyString& = default;
19
-
20
- explicit operator bool() const { return static_cast<bool>(value); }
21
- auto CopyInto(bool transfer_in = false) -> v8::Local<v8::Value> final;
22
-
23
- private:
24
- std::shared_ptr<std::vector<char>> value;
25
- bool one_byte = false;
26
- };
27
-
28
- } // namespace ivm
@@ -1,30 +0,0 @@
1
- #pragma once
2
- #include <v8.h>
3
- #include <memory>
4
- #include "v8_version.h"
5
-
6
- namespace ivm {
7
-
8
- class LimitedAllocator : public v8::ArrayBuffer::Allocator {
9
- private:
10
- class IsolateEnvironment& env;
11
- size_t limit;
12
- size_t v8_heap;
13
- size_t next_check;
14
- int failures = 0;
15
-
16
- public:
17
- auto Check(size_t length) -> bool;
18
- explicit LimitedAllocator(class IsolateEnvironment& env, size_t limit);
19
- auto Allocate(size_t length) -> void* final;
20
- auto AllocateUninitialized(size_t length) -> void* final;
21
- void Free(void* data, size_t length) final;
22
-
23
- // This is used by ExternalCopy when an ArrayBuffer is transferred. The memory is not freed but
24
- // we should no longer count it against the isolate
25
- void AdjustAllocatedSize(ptrdiff_t length);
26
- auto GetFailureCount() const -> int;
27
- void Track(v8::Local<v8::Object> handle, size_t size);
28
- };
29
-
30
- } // namespace ivm
@@ -1,131 +0,0 @@
1
- #include "allocator.h"
2
- #include "environment.h"
3
- #include <cstdlib>
4
-
5
- using namespace v8;
6
-
7
- namespace ivm {
8
- namespace {
9
-
10
- class ExternalMemoryHandle {
11
- public:
12
- ExternalMemoryHandle(Local<Object> local_handle, size_t size) :
13
- handle{Isolate::GetCurrent(), local_handle}, size{size} {
14
- handle.SetWeak(reinterpret_cast<void*>(this), &WeakCallbackV8, WeakCallbackType::kParameter);
15
- IsolateEnvironment::GetCurrent().AddWeakCallback(&handle, WeakCallback, this);
16
- }
17
-
18
- ExternalMemoryHandle(const ExternalMemoryHandle&) = delete;
19
- auto operator=(const ExternalMemoryHandle&) = delete;
20
-
21
- ~ExternalMemoryHandle() {
22
- auto* allocator = IsolateEnvironment::GetCurrent().GetLimitedAllocator();
23
- if (allocator != nullptr) {
24
- allocator->AdjustAllocatedSize(-static_cast<ptrdiff_t>(size));
25
- }
26
- };
27
-
28
- private:
29
- static void WeakCallbackV8(const WeakCallbackInfo<void>& info) {
30
- WeakCallback(info.GetParameter());
31
- }
32
-
33
- static void WeakCallback(void* param) {
34
- auto* that = reinterpret_cast<ExternalMemoryHandle*>(param);
35
- IsolateEnvironment::GetCurrent().RemoveWeakCallback(&that->handle);
36
- that->handle.Reset();
37
- delete that;
38
- }
39
-
40
- v8::Persistent<v8::Value> handle;
41
- size_t size;
42
- };
43
-
44
- } // anonymous namespace
45
-
46
- /**
47
- * ArrayBuffer::Allocator that enforces memory limits. The v8 documentation specifically says
48
- * that it's unsafe to call back into v8 from this class but I took a look at
49
- * GetHeapStatistics() and I think it'll be ok.
50
- */
51
- auto LimitedAllocator::Check(const size_t length) -> bool {
52
- if (v8_heap + env.extra_allocated_memory + length > next_check) {
53
- HeapStatistics heap_statistics;
54
- Isolate* isolate = Isolate::GetCurrent();
55
- isolate->GetHeapStatistics(&heap_statistics);
56
- v8_heap = heap_statistics.used_heap_size();
57
- if (v8_heap + env.extra_allocated_memory + length > limit + env.misc_memory_size) {
58
- // This is might be dangerous but the tests pass soooo..
59
- isolate->LowMemoryNotification();
60
- isolate->GetHeapStatistics(&heap_statistics);
61
- v8_heap = heap_statistics.used_heap_size();
62
- if (v8_heap + env.extra_allocated_memory + length > limit + env.misc_memory_size) {
63
- return false;
64
- }
65
- }
66
- next_check = v8_heap + env.extra_allocated_memory + length + 1024 * 1024;
67
- }
68
- return v8_heap + env.extra_allocated_memory + length <= limit + env.misc_memory_size;
69
- }
70
-
71
- LimitedAllocator::LimitedAllocator(IsolateEnvironment& env, size_t limit) : env(env), limit(limit), v8_heap(1024 * 1024 * 4), next_check(1024 * 1024) {}
72
-
73
- auto LimitedAllocator::Allocate(size_t length) -> void* {
74
- if (Check(length)) {
75
- env.extra_allocated_memory += length;
76
- return std::calloc(length, 1);
77
- } else {
78
- ++failures;
79
- if (length <= 64) { // kMinAddedElementsCapacity * sizeof(uint32_t)
80
- // When a tiny TypedArray is created v8 will avoid calling the allocator and instead just use
81
- // the internal heap. This is all fine until someone wants a pointer to the underlying buffer,
82
- // in that case v8 will "materialize" an ArrayBuffer which does invoke this allocator. If the
83
- // allocator refuses to return a valid pointer it will result in a hard crash so we have no
84
- // choice but to let this allocation succeed. Luckily the amount of memory allocated is tiny
85
- // and will soon be freed because at the same time we terminate the isolate.
86
- env.extra_allocated_memory += length;
87
- env.Terminate();
88
- return std::calloc(length, 1);
89
- } else {
90
- // The places end up here are more graceful and will throw a RangeError
91
- return nullptr;
92
- }
93
- }
94
- }
95
-
96
- auto LimitedAllocator::AllocateUninitialized(size_t length) -> void* {
97
- if (Check(length)) {
98
- env.extra_allocated_memory += length;
99
- return std::malloc(length);
100
- } else {
101
- ++failures;
102
- if (length <= 64) {
103
- env.extra_allocated_memory += length;
104
- env.Terminate();
105
- return std::malloc(length);
106
- } else {
107
- return nullptr;
108
- }
109
- }
110
- }
111
-
112
- void LimitedAllocator::Free(void* data, size_t length) {
113
- env.extra_allocated_memory -= length;
114
- next_check -= length;
115
- std::free(data);
116
- }
117
-
118
- void LimitedAllocator::AdjustAllocatedSize(ptrdiff_t length) {
119
- env.extra_allocated_memory += length;
120
- }
121
-
122
- auto LimitedAllocator::GetFailureCount() const -> int {
123
- return failures;
124
- }
125
-
126
- void LimitedAllocator::Track(Local<Object> handle, size_t size) {
127
- new ExternalMemoryHandle{handle, size};
128
- AdjustAllocatedSize(size);
129
- }
130
-
131
- } // namespace ivm