libv8-node 16.19.0.1-aarch64-linux-musl → 17.9.1.1-aarch64-linux-musl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/lib/libv8/node/version.rb +3 -3
  3. data/vendor/v8/aarch64-linux-musl/libv8/obj/libv8_monolith.a +0 -0
  4. data/vendor/v8/include/cppgc/allocation.h +11 -5
  5. data/vendor/v8/include/cppgc/cross-thread-persistent.h +78 -26
  6. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +2 -2
  7. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +2 -0
  8. data/vendor/v8/include/cppgc/internal/gc-info.h +90 -10
  9. data/vendor/v8/include/cppgc/internal/name-trait.h +11 -0
  10. data/vendor/v8/include/cppgc/internal/persistent-node.h +44 -12
  11. data/vendor/v8/include/cppgc/internal/pointer-policies.h +22 -11
  12. data/vendor/v8/include/cppgc/internal/write-barrier.h +9 -1
  13. data/vendor/v8/include/cppgc/persistent.h +1 -1
  14. data/vendor/v8/include/cppgc/prefinalizer.h +1 -1
  15. data/vendor/v8/include/v8-array-buffer.h +433 -0
  16. data/vendor/v8/include/v8-callbacks.h +377 -0
  17. data/vendor/v8/include/v8-container.h +129 -0
  18. data/vendor/v8/include/v8-context.h +418 -0
  19. data/vendor/v8/include/v8-cppgc.h +5 -2
  20. data/vendor/v8/include/v8-data.h +65 -0
  21. data/vendor/v8/include/v8-date.h +43 -0
  22. data/vendor/v8/include/v8-debug.h +151 -0
  23. data/vendor/v8/include/v8-embedder-heap.h +238 -0
  24. data/vendor/v8/include/v8-exception.h +224 -0
  25. data/vendor/v8/include/v8-extension.h +62 -0
  26. data/vendor/v8/include/v8-external.h +37 -0
  27. data/vendor/v8/include/v8-fast-api-calls.h +63 -11
  28. data/vendor/v8/include/v8-forward.h +81 -0
  29. data/vendor/v8/include/v8-function-callback.h +475 -0
  30. data/vendor/v8/include/v8-function.h +122 -0
  31. data/vendor/v8/include/v8-initialization.h +282 -0
  32. data/vendor/v8/include/v8-inspector.h +11 -21
  33. data/vendor/v8/include/v8-internal.h +85 -22
  34. data/vendor/v8/include/v8-isolate.h +1662 -0
  35. data/vendor/v8/include/v8-json.h +47 -0
  36. data/vendor/v8/include/v8-local-handle.h +459 -0
  37. data/vendor/v8/include/v8-locker.h +148 -0
  38. data/vendor/v8/include/v8-maybe.h +137 -0
  39. data/vendor/v8/include/v8-memory-span.h +43 -0
  40. data/vendor/v8/include/v8-message.h +241 -0
  41. data/vendor/v8/include/v8-metrics.h +37 -1
  42. data/vendor/v8/include/v8-microtask-queue.h +152 -0
  43. data/vendor/v8/include/v8-microtask.h +28 -0
  44. data/vendor/v8/include/v8-object.h +770 -0
  45. data/vendor/v8/include/v8-persistent-handle.h +590 -0
  46. data/vendor/v8/include/v8-platform.h +41 -17
  47. data/vendor/v8/include/v8-primitive-object.h +118 -0
  48. data/vendor/v8/include/v8-primitive.h +858 -0
  49. data/vendor/v8/include/v8-profiler.h +10 -11
  50. data/vendor/v8/include/v8-promise.h +174 -0
  51. data/vendor/v8/include/v8-proxy.h +50 -0
  52. data/vendor/v8/include/v8-regexp.h +105 -0
  53. data/vendor/v8/include/v8-script.h +771 -0
  54. data/vendor/v8/include/v8-snapshot.h +198 -0
  55. data/vendor/v8/include/v8-statistics.h +215 -0
  56. data/vendor/v8/include/v8-template.h +1052 -0
  57. data/vendor/v8/include/v8-traced-handle.h +605 -0
  58. data/vendor/v8/include/v8-typed-array.h +282 -0
  59. data/vendor/v8/include/v8-unwinder-state.h +4 -3
  60. data/vendor/v8/include/v8-unwinder.h +129 -0
  61. data/vendor/v8/include/v8-util.h +7 -1
  62. data/vendor/v8/include/v8-value-serializer.h +249 -0
  63. data/vendor/v8/include/v8-value.h +526 -0
  64. data/vendor/v8/include/v8-version.h +3 -3
  65. data/vendor/v8/include/v8-wasm.h +245 -0
  66. data/vendor/v8/include/v8-weak-callback-info.h +73 -0
  67. data/vendor/v8/include/v8.h +41 -12604
  68. metadata +43 -1
@@ -0,0 +1,282 @@
1
+ // Copyright 2021 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_V8_TYPED_ARRAY_H_
6
+ #define INCLUDE_V8_TYPED_ARRAY_H_
7
+
8
+ #include "v8-array-buffer.h" // NOLINT(build/include_directory)
9
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
10
+ #include "v8config.h" // NOLINT(build/include_directory)
11
+
12
+ namespace v8 {
13
+
14
+ class SharedArrayBuffer;
15
+
16
+ /**
17
+ * A base class for an instance of TypedArray series of constructors
18
+ * (ES6 draft 15.13.6).
19
+ */
20
+ class V8_EXPORT TypedArray : public ArrayBufferView {
21
+ public:
22
+ /*
23
+ * The largest typed array size that can be constructed using New.
24
+ */
25
+ static constexpr size_t kMaxLength =
26
+ internal::kApiSystemPointerSize == 4
27
+ ? internal::kSmiMaxValue
28
+ : static_cast<size_t>(uint64_t{1} << 32);
29
+
30
+ /**
31
+ * Number of elements in this typed array
32
+ * (e.g. for Int16Array, |ByteLength|/2).
33
+ */
34
+ size_t Length();
35
+
36
+ V8_INLINE static TypedArray* Cast(Value* value) {
37
+ #ifdef V8_ENABLE_CHECKS
38
+ CheckCast(value);
39
+ #endif
40
+ return static_cast<TypedArray*>(value);
41
+ }
42
+
43
+ private:
44
+ TypedArray();
45
+ static void CheckCast(Value* obj);
46
+ };
47
+
48
+ /**
49
+ * An instance of Uint8Array constructor (ES6 draft 15.13.6).
50
+ */
51
+ class V8_EXPORT Uint8Array : public TypedArray {
52
+ public:
53
+ static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
54
+ size_t byte_offset, size_t length);
55
+ static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
56
+ size_t byte_offset, size_t length);
57
+ V8_INLINE static Uint8Array* Cast(Value* value) {
58
+ #ifdef V8_ENABLE_CHECKS
59
+ CheckCast(value);
60
+ #endif
61
+ return static_cast<Uint8Array*>(value);
62
+ }
63
+
64
+ private:
65
+ Uint8Array();
66
+ static void CheckCast(Value* obj);
67
+ };
68
+
69
+ /**
70
+ * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
71
+ */
72
+ class V8_EXPORT Uint8ClampedArray : public TypedArray {
73
+ public:
74
+ static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
75
+ size_t byte_offset, size_t length);
76
+ static Local<Uint8ClampedArray> New(
77
+ Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
78
+ size_t length);
79
+ V8_INLINE static Uint8ClampedArray* Cast(Value* value) {
80
+ #ifdef V8_ENABLE_CHECKS
81
+ CheckCast(value);
82
+ #endif
83
+ return static_cast<Uint8ClampedArray*>(value);
84
+ }
85
+
86
+ private:
87
+ Uint8ClampedArray();
88
+ static void CheckCast(Value* obj);
89
+ };
90
+
91
+ /**
92
+ * An instance of Int8Array constructor (ES6 draft 15.13.6).
93
+ */
94
+ class V8_EXPORT Int8Array : public TypedArray {
95
+ public:
96
+ static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
97
+ size_t byte_offset, size_t length);
98
+ static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
99
+ size_t byte_offset, size_t length);
100
+ V8_INLINE static Int8Array* Cast(Value* value) {
101
+ #ifdef V8_ENABLE_CHECKS
102
+ CheckCast(value);
103
+ #endif
104
+ return static_cast<Int8Array*>(value);
105
+ }
106
+
107
+ private:
108
+ Int8Array();
109
+ static void CheckCast(Value* obj);
110
+ };
111
+
112
+ /**
113
+ * An instance of Uint16Array constructor (ES6 draft 15.13.6).
114
+ */
115
+ class V8_EXPORT Uint16Array : public TypedArray {
116
+ public:
117
+ static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
118
+ size_t byte_offset, size_t length);
119
+ static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
120
+ size_t byte_offset, size_t length);
121
+ V8_INLINE static Uint16Array* Cast(Value* value) {
122
+ #ifdef V8_ENABLE_CHECKS
123
+ CheckCast(value);
124
+ #endif
125
+ return static_cast<Uint16Array*>(value);
126
+ }
127
+
128
+ private:
129
+ Uint16Array();
130
+ static void CheckCast(Value* obj);
131
+ };
132
+
133
+ /**
134
+ * An instance of Int16Array constructor (ES6 draft 15.13.6).
135
+ */
136
+ class V8_EXPORT Int16Array : public TypedArray {
137
+ public:
138
+ static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
139
+ size_t byte_offset, size_t length);
140
+ static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
141
+ size_t byte_offset, size_t length);
142
+ V8_INLINE static Int16Array* Cast(Value* value) {
143
+ #ifdef V8_ENABLE_CHECKS
144
+ CheckCast(value);
145
+ #endif
146
+ return static_cast<Int16Array*>(value);
147
+ }
148
+
149
+ private:
150
+ Int16Array();
151
+ static void CheckCast(Value* obj);
152
+ };
153
+
154
+ /**
155
+ * An instance of Uint32Array constructor (ES6 draft 15.13.6).
156
+ */
157
+ class V8_EXPORT Uint32Array : public TypedArray {
158
+ public:
159
+ static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
160
+ size_t byte_offset, size_t length);
161
+ static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
162
+ size_t byte_offset, size_t length);
163
+ V8_INLINE static Uint32Array* Cast(Value* value) {
164
+ #ifdef V8_ENABLE_CHECKS
165
+ CheckCast(value);
166
+ #endif
167
+ return static_cast<Uint32Array*>(value);
168
+ }
169
+
170
+ private:
171
+ Uint32Array();
172
+ static void CheckCast(Value* obj);
173
+ };
174
+
175
+ /**
176
+ * An instance of Int32Array constructor (ES6 draft 15.13.6).
177
+ */
178
+ class V8_EXPORT Int32Array : public TypedArray {
179
+ public:
180
+ static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
181
+ size_t byte_offset, size_t length);
182
+ static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
183
+ size_t byte_offset, size_t length);
184
+ V8_INLINE static Int32Array* Cast(Value* value) {
185
+ #ifdef V8_ENABLE_CHECKS
186
+ CheckCast(value);
187
+ #endif
188
+ return static_cast<Int32Array*>(value);
189
+ }
190
+
191
+ private:
192
+ Int32Array();
193
+ static void CheckCast(Value* obj);
194
+ };
195
+
196
+ /**
197
+ * An instance of Float32Array constructor (ES6 draft 15.13.6).
198
+ */
199
+ class V8_EXPORT Float32Array : public TypedArray {
200
+ public:
201
+ static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
202
+ size_t byte_offset, size_t length);
203
+ static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
204
+ size_t byte_offset, size_t length);
205
+ V8_INLINE static Float32Array* Cast(Value* value) {
206
+ #ifdef V8_ENABLE_CHECKS
207
+ CheckCast(value);
208
+ #endif
209
+ return static_cast<Float32Array*>(value);
210
+ }
211
+
212
+ private:
213
+ Float32Array();
214
+ static void CheckCast(Value* obj);
215
+ };
216
+
217
+ /**
218
+ * An instance of Float64Array constructor (ES6 draft 15.13.6).
219
+ */
220
+ class V8_EXPORT Float64Array : public TypedArray {
221
+ public:
222
+ static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
223
+ size_t byte_offset, size_t length);
224
+ static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
225
+ size_t byte_offset, size_t length);
226
+ V8_INLINE static Float64Array* Cast(Value* value) {
227
+ #ifdef V8_ENABLE_CHECKS
228
+ CheckCast(value);
229
+ #endif
230
+ return static_cast<Float64Array*>(value);
231
+ }
232
+
233
+ private:
234
+ Float64Array();
235
+ static void CheckCast(Value* obj);
236
+ };
237
+
238
+ /**
239
+ * An instance of BigInt64Array constructor.
240
+ */
241
+ class V8_EXPORT BigInt64Array : public TypedArray {
242
+ public:
243
+ static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
244
+ size_t byte_offset, size_t length);
245
+ static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
246
+ size_t byte_offset, size_t length);
247
+ V8_INLINE static BigInt64Array* Cast(Value* value) {
248
+ #ifdef V8_ENABLE_CHECKS
249
+ CheckCast(value);
250
+ #endif
251
+ return static_cast<BigInt64Array*>(value);
252
+ }
253
+
254
+ private:
255
+ BigInt64Array();
256
+ static void CheckCast(Value* obj);
257
+ };
258
+
259
+ /**
260
+ * An instance of BigUint64Array constructor.
261
+ */
262
+ class V8_EXPORT BigUint64Array : public TypedArray {
263
+ public:
264
+ static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
265
+ size_t byte_offset, size_t length);
266
+ static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
267
+ size_t byte_offset, size_t length);
268
+ V8_INLINE static BigUint64Array* Cast(Value* value) {
269
+ #ifdef V8_ENABLE_CHECKS
270
+ CheckCast(value);
271
+ #endif
272
+ return static_cast<BigUint64Array*>(value);
273
+ }
274
+
275
+ private:
276
+ BigUint64Array();
277
+ static void CheckCast(Value* obj);
278
+ };
279
+
280
+ } // namespace v8
281
+
282
+ #endif // INCLUDE_V8_TYPED_ARRAY_H_
@@ -17,9 +17,10 @@ struct CalleeSavedRegisters {
17
17
  void* arm_r9;
18
18
  void* arm_r10;
19
19
  };
20
- #elif V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_ARM64 || \
21
- V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC || \
22
- V8_TARGET_ARCH_PPC64 || V8_TARGET_ARCH_RISCV64 || V8_TARGET_ARCH_S390
20
+ #elif V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_ARM64 || \
21
+ V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC || \
22
+ V8_TARGET_ARCH_PPC64 || V8_TARGET_ARCH_RISCV64 || V8_TARGET_ARCH_S390 || \
23
+ V8_TARGET_ARCH_LOONG64
23
24
  struct CalleeSavedRegisters {};
24
25
  #else
25
26
  #error Target architecture was not detected as supported by v8
@@ -0,0 +1,129 @@
1
+ // Copyright 2021 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_V8_UNWINDER_H_
6
+ #define INCLUDE_V8_UNWINDER_H_
7
+
8
+ #include <memory>
9
+
10
+ #include "v8config.h" // NOLINT(build/include_directory)
11
+
12
+ namespace v8 {
13
+ // Holds the callee saved registers needed for the stack unwinder. It is the
14
+ // empty struct if no registers are required. Implemented in
15
+ // include/v8-unwinder-state.h.
16
+ struct CalleeSavedRegisters;
17
+
18
+ // A RegisterState represents the current state of registers used
19
+ // by the sampling profiler API.
20
+ struct V8_EXPORT RegisterState {
21
+ RegisterState();
22
+ ~RegisterState();
23
+ RegisterState(const RegisterState& other);
24
+ RegisterState& operator=(const RegisterState& other);
25
+
26
+ void* pc; // Instruction pointer.
27
+ void* sp; // Stack pointer.
28
+ void* fp; // Frame pointer.
29
+ void* lr; // Link register (or nullptr on platforms without a link register).
30
+ // Callee saved registers (or null if no callee saved registers were stored)
31
+ std::unique_ptr<CalleeSavedRegisters> callee_saved;
32
+ };
33
+
34
+ // A StateTag represents a possible state of the VM.
35
+ enum StateTag {
36
+ JS,
37
+ GC,
38
+ PARSER,
39
+ BYTECODE_COMPILER,
40
+ COMPILER,
41
+ OTHER,
42
+ EXTERNAL,
43
+ ATOMICS_WAIT,
44
+ IDLE
45
+ };
46
+
47
+ // The output structure filled up by GetStackSample API function.
48
+ struct SampleInfo {
49
+ size_t frames_count; // Number of frames collected.
50
+ StateTag vm_state; // Current VM state.
51
+ void* external_callback_entry; // External callback address if VM is
52
+ // executing an external callback.
53
+ void* context; // Incumbent native context address.
54
+ };
55
+
56
+ struct MemoryRange {
57
+ const void* start = nullptr;
58
+ size_t length_in_bytes = 0;
59
+ };
60
+
61
+ struct JSEntryStub {
62
+ MemoryRange code;
63
+ };
64
+
65
+ struct JSEntryStubs {
66
+ JSEntryStub js_entry_stub;
67
+ JSEntryStub js_construct_entry_stub;
68
+ JSEntryStub js_run_microtasks_entry_stub;
69
+ };
70
+
71
+ /**
72
+ * Various helpers for skipping over V8 frames in a given stack.
73
+ *
74
+ * The unwinder API is only supported on the x64, ARM64 and ARM32 architectures.
75
+ */
76
+ class V8_EXPORT Unwinder {
77
+ public:
78
+ /**
79
+ * Attempt to unwind the stack to the most recent C++ frame. This function is
80
+ * signal-safe and does not access any V8 state and thus doesn't require an
81
+ * Isolate.
82
+ *
83
+ * The unwinder needs to know the location of the JS Entry Stub (a piece of
84
+ * code that is run when C++ code calls into generated JS code). This is used
85
+ * for edge cases where the current frame is being constructed or torn down
86
+ * when the stack sample occurs.
87
+ *
88
+ * The unwinder also needs the virtual memory range of all possible V8 code
89
+ * objects. There are two ranges required - the heap code range and the range
90
+ * for code embedded in the binary.
91
+ *
92
+ * Available on x64, ARM64 and ARM32.
93
+ *
94
+ * \param code_pages A list of all of the ranges in which V8 has allocated
95
+ * executable code. The caller should obtain this list by calling
96
+ * Isolate::CopyCodePages() during the same interrupt/thread suspension that
97
+ * captures the stack.
98
+ * \param register_state The current registers. This is an in-out param that
99
+ * will be overwritten with the register values after unwinding, on success.
100
+ * \param stack_base The resulting stack pointer and frame pointer values are
101
+ * bounds-checked against the stack_base and the original stack pointer value
102
+ * to ensure that they are valid locations in the given stack. If these values
103
+ * or any intermediate frame pointer values used during unwinding are ever out
104
+ * of these bounds, unwinding will fail.
105
+ *
106
+ * \return True on success.
107
+ */
108
+ static bool TryUnwindV8Frames(const JSEntryStubs& entry_stubs,
109
+ size_t code_pages_length,
110
+ const MemoryRange* code_pages,
111
+ RegisterState* register_state,
112
+ const void* stack_base);
113
+
114
+ /**
115
+ * Whether the PC is within the V8 code range represented by code_pages.
116
+ *
117
+ * If this returns false, then calling UnwindV8Frames() with the same PC
118
+ * and unwind_state will always fail. If it returns true, then unwinding may
119
+ * (but not necessarily) be successful.
120
+ *
121
+ * Available on x64, ARM64 and ARM32
122
+ */
123
+ static bool PCIsInV8(size_t code_pages_length, const MemoryRange* code_pages,
124
+ void* pc);
125
+ };
126
+
127
+ } // namespace v8
128
+
129
+ #endif // INCLUDE_V8_UNWINDER_H_
@@ -5,11 +5,14 @@
5
5
  #ifndef V8_UTIL_H_
6
6
  #define V8_UTIL_H_
7
7
 
8
- #include "v8.h" // NOLINT(build/include_directory)
9
8
  #include <assert.h>
9
+
10
10
  #include <map>
11
11
  #include <vector>
12
12
 
13
+ #include "v8-function-callback.h" // NOLINT(build/include_directory)
14
+ #include "v8-persistent-handle.h" // NOLINT(build/include_directory)
15
+
13
16
  /**
14
17
  * Support for Persistent containers.
15
18
  *
@@ -19,6 +22,9 @@
19
22
  */
20
23
  namespace v8 {
21
24
 
25
+ template <typename K, typename V, typename Traits>
26
+ class GlobalValueMap;
27
+
22
28
  typedef uintptr_t PersistentContainerValue;
23
29
  static const uintptr_t kPersistentContainerNotFound = 0;
24
30
  enum PersistentContainerCallbackType {
@@ -0,0 +1,249 @@
1
+ // Copyright 2021 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef INCLUDE_V8_VALUE_SERIALIZER_H_
6
+ #define INCLUDE_V8_VALUE_SERIALIZER_H_
7
+
8
+ #include <stddef.h>
9
+ #include <stdint.h>
10
+
11
+ #include <utility>
12
+
13
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
14
+ #include "v8-maybe.h" // NOLINT(build/include_directory)
15
+ #include "v8config.h" // NOLINT(build/include_directory)
16
+
17
+ namespace v8 {
18
+
19
+ class ArrayBuffer;
20
+ class Isolate;
21
+ class Object;
22
+ class SharedArrayBuffer;
23
+ class String;
24
+ class WasmModuleObject;
25
+ class Value;
26
+
27
+ namespace internal {
28
+ struct ScriptStreamingData;
29
+ } // namespace internal
30
+
31
+ /**
32
+ * Value serialization compatible with the HTML structured clone algorithm.
33
+ * The format is backward-compatible (i.e. safe to store to disk).
34
+ */
35
+ class V8_EXPORT ValueSerializer {
36
+ public:
37
+ class V8_EXPORT Delegate {
38
+ public:
39
+ virtual ~Delegate() = default;
40
+
41
+ /**
42
+ * Handles the case where a DataCloneError would be thrown in the structured
43
+ * clone spec. Other V8 embedders may throw some other appropriate exception
44
+ * type.
45
+ */
46
+ virtual void ThrowDataCloneError(Local<String> message) = 0;
47
+
48
+ /**
49
+ * The embedder overrides this method to write some kind of host object, if
50
+ * possible. If not, a suitable exception should be thrown and
51
+ * Nothing<bool>() returned.
52
+ */
53
+ virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
54
+
55
+ /**
56
+ * Called when the ValueSerializer is going to serialize a
57
+ * SharedArrayBuffer object. The embedder must return an ID for the
58
+ * object, using the same ID if this SharedArrayBuffer has already been
59
+ * serialized in this buffer. When deserializing, this ID will be passed to
60
+ * ValueDeserializer::GetSharedArrayBufferFromId as |clone_id|.
61
+ *
62
+ * If the object cannot be serialized, an
63
+ * exception should be thrown and Nothing<uint32_t>() returned.
64
+ */
65
+ virtual Maybe<uint32_t> GetSharedArrayBufferId(
66
+ Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
67
+
68
+ virtual Maybe<uint32_t> GetWasmModuleTransferId(
69
+ Isolate* isolate, Local<WasmModuleObject> module);
70
+ /**
71
+ * Allocates memory for the buffer of at least the size provided. The actual
72
+ * size (which may be greater or equal) is written to |actual_size|. If no
73
+ * buffer has been allocated yet, nullptr will be provided.
74
+ *
75
+ * If the memory cannot be allocated, nullptr should be returned.
76
+ * |actual_size| will be ignored. It is assumed that |old_buffer| is still
77
+ * valid in this case and has not been modified.
78
+ *
79
+ * The default implementation uses the stdlib's `realloc()` function.
80
+ */
81
+ virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
82
+ size_t* actual_size);
83
+
84
+ /**
85
+ * Frees a buffer allocated with |ReallocateBufferMemory|.
86
+ *
87
+ * The default implementation uses the stdlib's `free()` function.
88
+ */
89
+ virtual void FreeBufferMemory(void* buffer);
90
+ };
91
+
92
+ explicit ValueSerializer(Isolate* isolate);
93
+ ValueSerializer(Isolate* isolate, Delegate* delegate);
94
+ ~ValueSerializer();
95
+
96
+ /**
97
+ * Writes out a header, which includes the format version.
98
+ */
99
+ void WriteHeader();
100
+
101
+ /**
102
+ * Serializes a JavaScript value into the buffer.
103
+ */
104
+ V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context,
105
+ Local<Value> value);
106
+
107
+ /**
108
+ * Returns the stored data (allocated using the delegate's
109
+ * ReallocateBufferMemory) and its size. This serializer should not be used
110
+ * once the buffer is released. The contents are undefined if a previous write
111
+ * has failed. Ownership of the buffer is transferred to the caller.
112
+ */
113
+ V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
114
+
115
+ /**
116
+ * Marks an ArrayBuffer as havings its contents transferred out of band.
117
+ * Pass the corresponding ArrayBuffer in the deserializing context to
118
+ * ValueDeserializer::TransferArrayBuffer.
119
+ */
120
+ void TransferArrayBuffer(uint32_t transfer_id,
121
+ Local<ArrayBuffer> array_buffer);
122
+
123
+ /**
124
+ * Indicate whether to treat ArrayBufferView objects as host objects,
125
+ * i.e. pass them to Delegate::WriteHostObject. This should not be
126
+ * called when no Delegate was passed.
127
+ *
128
+ * The default is not to treat ArrayBufferViews as host objects.
129
+ */
130
+ void SetTreatArrayBufferViewsAsHostObjects(bool mode);
131
+
132
+ /**
133
+ * Write raw data in various common formats to the buffer.
134
+ * Note that integer types are written in base-128 varint format, not with a
135
+ * binary copy. For use during an override of Delegate::WriteHostObject.
136
+ */
137
+ void WriteUint32(uint32_t value);
138
+ void WriteUint64(uint64_t value);
139
+ void WriteDouble(double value);
140
+ void WriteRawBytes(const void* source, size_t length);
141
+
142
+ ValueSerializer(const ValueSerializer&) = delete;
143
+ void operator=(const ValueSerializer&) = delete;
144
+
145
+ private:
146
+ struct PrivateData;
147
+ PrivateData* private_;
148
+ };
149
+
150
+ /**
151
+ * Deserializes values from data written with ValueSerializer, or a compatible
152
+ * implementation.
153
+ */
154
+ class V8_EXPORT ValueDeserializer {
155
+ public:
156
+ class V8_EXPORT Delegate {
157
+ public:
158
+ virtual ~Delegate() = default;
159
+
160
+ /**
161
+ * The embedder overrides this method to read some kind of host object, if
162
+ * possible. If not, a suitable exception should be thrown and
163
+ * MaybeLocal<Object>() returned.
164
+ */
165
+ virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
166
+
167
+ /**
168
+ * Get a WasmModuleObject given a transfer_id previously provided
169
+ * by ValueSerializer::GetWasmModuleTransferId
170
+ */
171
+ virtual MaybeLocal<WasmModuleObject> GetWasmModuleFromId(
172
+ Isolate* isolate, uint32_t transfer_id);
173
+
174
+ /**
175
+ * Get a SharedArrayBuffer given a clone_id previously provided
176
+ * by ValueSerializer::GetSharedArrayBufferId
177
+ */
178
+ virtual MaybeLocal<SharedArrayBuffer> GetSharedArrayBufferFromId(
179
+ Isolate* isolate, uint32_t clone_id);
180
+ };
181
+
182
+ ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
183
+ ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
184
+ Delegate* delegate);
185
+ ~ValueDeserializer();
186
+
187
+ /**
188
+ * Reads and validates a header (including the format version).
189
+ * May, for example, reject an invalid or unsupported wire format.
190
+ */
191
+ V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
192
+
193
+ /**
194
+ * Deserializes a JavaScript value from the buffer.
195
+ */
196
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context);
197
+
198
+ /**
199
+ * Accepts the array buffer corresponding to the one passed previously to
200
+ * ValueSerializer::TransferArrayBuffer.
201
+ */
202
+ void TransferArrayBuffer(uint32_t transfer_id,
203
+ Local<ArrayBuffer> array_buffer);
204
+
205
+ /**
206
+ * Similar to TransferArrayBuffer, but for SharedArrayBuffer.
207
+ * The id is not necessarily in the same namespace as unshared ArrayBuffer
208
+ * objects.
209
+ */
210
+ void TransferSharedArrayBuffer(uint32_t id,
211
+ Local<SharedArrayBuffer> shared_array_buffer);
212
+
213
+ /**
214
+ * Must be called before ReadHeader to enable support for reading the legacy
215
+ * wire format (i.e., which predates this being shipped).
216
+ *
217
+ * Don't use this unless you need to read data written by previous versions of
218
+ * blink::ScriptValueSerializer.
219
+ */
220
+ void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
221
+
222
+ /**
223
+ * Reads the underlying wire format version. Likely mostly to be useful to
224
+ * legacy code reading old wire format versions. Must be called after
225
+ * ReadHeader.
226
+ */
227
+ uint32_t GetWireFormatVersion() const;
228
+
229
+ /**
230
+ * Reads raw data in various common formats to the buffer.
231
+ * Note that integer types are read in base-128 varint format, not with a
232
+ * binary copy. For use during an override of Delegate::ReadHostObject.
233
+ */
234
+ V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
235
+ V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
236
+ V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
237
+ V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
238
+
239
+ ValueDeserializer(const ValueDeserializer&) = delete;
240
+ void operator=(const ValueDeserializer&) = delete;
241
+
242
+ private:
243
+ struct PrivateData;
244
+ PrivateData* private_;
245
+ };
246
+
247
+ } // namespace v8
248
+
249
+ #endif // INCLUDE_V8_VALUE_SERIALIZER_H_