libv8-node 22.7.0.4-x86_64-linux-musl → 24.1.0.0-x86_64-linux-musl

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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/lib/libv8/node/version.rb +3 -3
  3. data/vendor/v8/include/cppgc/allocation.h +11 -13
  4. data/vendor/v8/include/cppgc/default-platform.h +3 -2
  5. data/vendor/v8/include/cppgc/garbage-collected.h +8 -0
  6. data/vendor/v8/include/cppgc/heap-consistency.h +1 -1
  7. data/vendor/v8/include/cppgc/heap-statistics.h +2 -0
  8. data/vendor/v8/include/cppgc/internal/api-constants.h +2 -14
  9. data/vendor/v8/include/cppgc/internal/base-page-handle.h +2 -4
  10. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +0 -4
  11. data/vendor/v8/include/cppgc/internal/caged-heap.h +0 -4
  12. data/vendor/v8/include/cppgc/internal/compiler-specific.h +9 -1
  13. data/vendor/v8/include/cppgc/internal/conditional-stack-allocated.h +41 -0
  14. data/vendor/v8/include/cppgc/internal/gc-info.h +12 -10
  15. data/vendor/v8/include/cppgc/internal/logging.h +3 -3
  16. data/vendor/v8/include/cppgc/internal/member-storage.h +69 -20
  17. data/vendor/v8/include/cppgc/internal/name-trait.h +5 -1
  18. data/vendor/v8/include/cppgc/internal/persistent-node.h +8 -3
  19. data/vendor/v8/include/cppgc/internal/pointer-policies.h +48 -11
  20. data/vendor/v8/include/cppgc/macros.h +21 -0
  21. data/vendor/v8/include/cppgc/member.h +70 -36
  22. data/vendor/v8/include/cppgc/name-provider.h +10 -0
  23. data/vendor/v8/include/cppgc/platform.h +11 -0
  24. data/vendor/v8/include/cppgc/type-traits.h +1 -0
  25. data/vendor/v8/include/cppgc/visitor.h +25 -1
  26. data/vendor/v8/include/libplatform/libplatform-export.h +2 -2
  27. data/vendor/v8/include/libplatform/v8-tracing.h +0 -1
  28. data/vendor/v8/include/v8-array-buffer.h +143 -46
  29. data/vendor/v8/include/v8-callbacks.h +94 -31
  30. data/vendor/v8/include/v8-context.h +48 -15
  31. data/vendor/v8/include/v8-cppgc.h +5 -56
  32. data/vendor/v8/include/v8-data.h +5 -0
  33. data/vendor/v8/include/v8-date.h +9 -0
  34. data/vendor/v8/include/v8-debug.h +11 -0
  35. data/vendor/v8/include/v8-embedder-heap.h +1 -29
  36. data/vendor/v8/include/v8-exception.h +72 -0
  37. data/vendor/v8/include/v8-external-memory-accounter.h +60 -0
  38. data/vendor/v8/include/v8-fast-api-calls.h +41 -206
  39. data/vendor/v8/include/v8-function-callback.h +190 -78
  40. data/vendor/v8/include/v8-function.h +11 -3
  41. data/vendor/v8/include/v8-handle-base.h +20 -2
  42. data/vendor/v8/include/v8-initialization.h +26 -1
  43. data/vendor/v8/include/v8-inspector.h +10 -3
  44. data/vendor/v8/include/v8-internal.h +638 -315
  45. data/vendor/v8/include/v8-isolate.h +275 -189
  46. data/vendor/v8/include/v8-local-handle.h +69 -42
  47. data/vendor/v8/include/v8-maybe.h +2 -1
  48. data/vendor/v8/include/v8-memory-span.h +149 -24
  49. data/vendor/v8/include/v8-message.h +9 -22
  50. data/vendor/v8/include/v8-metrics.h +14 -0
  51. data/vendor/v8/include/v8-microtask-queue.h +0 -5
  52. data/vendor/v8/include/v8-object.h +291 -37
  53. data/vendor/v8/include/v8-persistent-handle.h +17 -36
  54. data/vendor/v8/include/v8-platform.h +66 -45
  55. data/vendor/v8/include/v8-primitive.h +221 -5
  56. data/vendor/v8/include/v8-profiler.h +51 -2
  57. data/vendor/v8/include/v8-promise.h +2 -2
  58. data/vendor/v8/include/v8-proxy.h +0 -1
  59. data/vendor/v8/include/v8-regexp.h +0 -1
  60. data/vendor/v8/include/v8-sandbox.h +173 -0
  61. data/vendor/v8/include/v8-script.h +65 -17
  62. data/vendor/v8/include/v8-snapshot.h +38 -2
  63. data/vendor/v8/include/v8-source-location.h +6 -1
  64. data/vendor/v8/include/v8-template.h +111 -263
  65. data/vendor/v8/include/v8-trace-categories.h +23 -0
  66. data/vendor/v8/include/v8-traced-handle.h +20 -32
  67. data/vendor/v8/include/v8-typed-array.h +6 -10
  68. data/vendor/v8/include/v8-unwinder-state.h +2 -3
  69. data/vendor/v8/include/v8-unwinder.h +2 -1
  70. data/vendor/v8/include/v8-util.h +1 -117
  71. data/vendor/v8/include/v8-value-serializer-version.h +3 -3
  72. data/vendor/v8/include/v8-value.h +21 -2
  73. data/vendor/v8/include/v8-version.h +4 -4
  74. data/vendor/v8/include/v8-wasm.h +27 -0
  75. data/vendor/v8/include/v8-weak-callback-info.h +20 -12
  76. data/vendor/v8/include/v8.h +3 -3
  77. data/vendor/v8/include/v8config.h +83 -45
  78. data/vendor/v8/x86_64-linux-musl/libv8/obj/libv8_monolith.a +0 -0
  79. metadata +6 -3
  80. data/vendor/v8/include/cppgc/ephemeron-pair.h +0 -30
@@ -14,7 +14,7 @@
14
14
  #include <string>
15
15
 
16
16
  #include "v8-source-location.h" // NOLINT(build/include_directory)
17
- #include "v8config.h" // NOLINT(build/include_directory)
17
+ #include "v8config.h" // NOLINT(build/include_directory)
18
18
 
19
19
  namespace v8 {
20
20
 
@@ -79,8 +79,9 @@ class TaskRunner {
79
79
  *
80
80
  * Embedders should override PostTaskImpl instead of this.
81
81
  */
82
- virtual void PostTask(std::unique_ptr<Task> task) {
83
- PostTaskImpl(std::move(task), SourceLocation::Current());
82
+ void PostTask(std::unique_ptr<Task> task,
83
+ const SourceLocation& location = SourceLocation::Current()) {
84
+ PostTaskImpl(std::move(task), location);
84
85
  }
85
86
 
86
87
  /**
@@ -100,8 +101,10 @@ class TaskRunner {
100
101
  *
101
102
  * Embedders should override PostNonNestableTaskImpl instead of this.
102
103
  */
103
- virtual void PostNonNestableTask(std::unique_ptr<Task> task) {
104
- PostNonNestableTaskImpl(std::move(task), SourceLocation::Current());
104
+ void PostNonNestableTask(
105
+ std::unique_ptr<Task> task,
106
+ const SourceLocation& location = SourceLocation::Current()) {
107
+ PostNonNestableTaskImpl(std::move(task), location);
105
108
  }
106
109
 
107
110
  /**
@@ -111,10 +114,10 @@ class TaskRunner {
111
114
  *
112
115
  * Embedders should override PostDelayedTaskImpl instead of this.
113
116
  */
114
- virtual void PostDelayedTask(std::unique_ptr<Task> task,
115
- double delay_in_seconds) {
116
- PostDelayedTaskImpl(std::move(task), delay_in_seconds,
117
- SourceLocation::Current());
117
+ void PostDelayedTask(
118
+ std::unique_ptr<Task> task, double delay_in_seconds,
119
+ const SourceLocation& location = SourceLocation::Current()) {
120
+ PostDelayedTaskImpl(std::move(task), delay_in_seconds, location);
118
121
  }
119
122
 
120
123
  /**
@@ -135,10 +138,10 @@ class TaskRunner {
135
138
  *
136
139
  * Embedders should override PostNonNestableDelayedTaskImpl instead of this.
137
140
  */
138
- virtual void PostNonNestableDelayedTask(std::unique_ptr<Task> task,
139
- double delay_in_seconds) {
140
- PostNonNestableDelayedTaskImpl(std::move(task), delay_in_seconds,
141
- SourceLocation::Current());
141
+ void PostNonNestableDelayedTask(
142
+ std::unique_ptr<Task> task, double delay_in_seconds,
143
+ const SourceLocation& location = SourceLocation::Current()) {
144
+ PostNonNestableDelayedTaskImpl(std::move(task), delay_in_seconds, location);
142
145
  }
143
146
 
144
147
  /**
@@ -151,8 +154,10 @@ class TaskRunner {
151
154
  *
152
155
  * Embedders should override PostIdleTaskImpl instead of this.
153
156
  */
154
- virtual void PostIdleTask(std::unique_ptr<IdleTask> task) {
155
- PostIdleTaskImpl(std::move(task), SourceLocation::Current());
157
+ void PostIdleTask(
158
+ std::unique_ptr<IdleTask> task,
159
+ const SourceLocation& location = SourceLocation::Current()) {
160
+ PostIdleTaskImpl(std::move(task), location);
156
161
  }
157
162
 
158
163
  /**
@@ -389,7 +394,7 @@ class TracingController {
389
394
 
390
395
  /**
391
396
  * Adds a trace event to the platform tracing system. These function calls are
392
- * usually the result of a TRACE_* macro from trace_event_common.h when
397
+ * usually the result of a TRACE_* macro from trace-event-no-perfetto.h when
393
398
  * tracing and the category of the particular trace are enabled. It is not
394
399
  * advisable to call these functions on their own; they are really only meant
395
400
  * to be used by the trace macros. The returned handle can be used by
@@ -547,6 +552,19 @@ class PageAllocator {
547
552
  */
548
553
  virtual bool DecommitPages(void* address, size_t size) = 0;
549
554
 
555
+ /**
556
+ * Block any modifications to the given mapping such as changing permissions
557
+ * or unmapping the pages on supported platforms.
558
+ * The address space reservation will exist until the process ends, but it's
559
+ * possible to release the memory using DiscardSystemPages. Note that this
560
+ * might require write permissions to the page as e.g. on Linux, mseal will
561
+ * block discarding sealed anonymous memory.
562
+ */
563
+ virtual bool SealPages(void* address, size_t length) {
564
+ // TODO(360048056): make it pure once it's implemented on Chromium side.
565
+ return false;
566
+ }
567
+
550
568
  /**
551
569
  * INTERNAL ONLY: This interface has not been stabilised and may change
552
570
  * without notice from one release to another without being deprecated first.
@@ -1021,18 +1039,6 @@ class VirtualAddressSpace {
1021
1039
  const PagePermissions max_page_permissions_;
1022
1040
  };
1023
1041
 
1024
- /**
1025
- * V8 Allocator used for allocating zone backings.
1026
- */
1027
- class ZoneBackingAllocator {
1028
- public:
1029
- using MallocFn = void* (*)(size_t);
1030
- using FreeFn = void (*)(void*);
1031
-
1032
- virtual MallocFn GetMallocFn() const { return ::malloc; }
1033
- virtual FreeFn GetFreeFn() const { return ::free; }
1034
- };
1035
-
1036
1042
  /**
1037
1043
  * Observer used by V8 to notify the embedder about entering/leaving sections
1038
1044
  * with high throughput of malloc/free operations.
@@ -1057,7 +1063,7 @@ class Platform {
1057
1063
  * Allows the embedder to manage memory page allocations.
1058
1064
  * Returning nullptr will cause V8 to use the default page allocator.
1059
1065
  */
1060
- virtual PageAllocator* GetPageAllocator() = 0;
1066
+ virtual PageAllocator* GetPageAllocator() { return nullptr; }
1061
1067
 
1062
1068
  /**
1063
1069
  * Allows the embedder to provide an allocator that uses per-thread memory
@@ -1069,14 +1075,6 @@ class Platform {
1069
1075
  return nullptr;
1070
1076
  }
1071
1077
 
1072
- /**
1073
- * Allows the embedder to specify a custom allocator used for zones.
1074
- */
1075
- virtual ZoneBackingAllocator* GetZoneBackingAllocator() {
1076
- static ZoneBackingAllocator default_allocator;
1077
- return &default_allocator;
1078
- }
1079
-
1080
1078
  /**
1081
1079
  * Enables the embedder to respond in cases where V8 can't allocate large
1082
1080
  * blocks of memory. V8 retries the failed allocation once after calling this
@@ -1100,11 +1098,8 @@ class Platform {
1100
1098
  * Returns a TaskRunner which can be used to post a task on the foreground.
1101
1099
  * The TaskRunner's NonNestableTasksEnabled() must be true. This function
1102
1100
  * should only be called from a foreground thread.
1103
- * TODO(chromium:1448758): Deprecate once |GetForegroundTaskRunner(Isolate*,
1104
- * TaskPriority)| is ready.
1105
1101
  */
1106
- virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
1107
- Isolate* isolate) {
1102
+ std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(Isolate* isolate) {
1108
1103
  return GetForegroundTaskRunner(isolate, TaskPriority::kUserBlocking);
1109
1104
  }
1110
1105
 
@@ -1112,18 +1107,16 @@ class Platform {
1112
1107
  * Returns a TaskRunner with a specific |priority| which can be used to post a
1113
1108
  * task on the foreground thread. The TaskRunner's NonNestableTasksEnabled()
1114
1109
  * must be true. This function should only be called from a foreground thread.
1115
- * TODO(chromium:1448758): Make pure virtual once embedders implement it.
1116
1110
  */
1117
1111
  virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
1118
- Isolate* isolate, TaskPriority priority) {
1119
- return nullptr;
1120
- }
1112
+ Isolate* isolate, TaskPriority priority) = 0;
1121
1113
 
1122
1114
  /**
1123
1115
  * Schedules a task to be invoked on a worker thread.
1124
1116
  * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1125
1117
  * CallOnWorkerThread().
1126
1118
  */
1119
+ V8_DEPRECATE_SOON("Use PostTaskOnWorkerThread instead.")
1127
1120
  void CallOnWorkerThread(
1128
1121
  std::unique_ptr<Task> task,
1129
1122
  const SourceLocation& location = SourceLocation::Current()) {
@@ -1137,6 +1130,7 @@ class Platform {
1137
1130
  * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1138
1131
  * CallBlockingTaskOnWorkerThread().
1139
1132
  */
1133
+ V8_DEPRECATE_SOON("Use PostTaskOnWorkerThread instead.")
1140
1134
  void CallBlockingTaskOnWorkerThread(
1141
1135
  std::unique_ptr<Task> task,
1142
1136
  const SourceLocation& location = SourceLocation::Current()) {
@@ -1151,6 +1145,7 @@ class Platform {
1151
1145
  * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1152
1146
  * CallLowPriorityTaskOnWorkerThread().
1153
1147
  */
1148
+ V8_DEPRECATE_SOON("Use PostTaskOnWorkerThread instead.")
1154
1149
  void CallLowPriorityTaskOnWorkerThread(
1155
1150
  std::unique_ptr<Task> task,
1156
1151
  const SourceLocation& location = SourceLocation::Current()) {
@@ -1166,6 +1161,7 @@ class Platform {
1166
1161
  * Embedders should override PostDelayedTaskOnWorkerThreadImpl() instead of
1167
1162
  * CallDelayedOnWorkerThread().
1168
1163
  */
1164
+ V8_DEPRECATE_SOON("Use PostDelayedTaskOnWorkerThread instead.")
1169
1165
  void CallDelayedOnWorkerThread(
1170
1166
  std::unique_ptr<Task> task, double delay_in_seconds,
1171
1167
  const SourceLocation& location = SourceLocation::Current()) {
@@ -1174,6 +1170,31 @@ class Platform {
1174
1170
  location);
1175
1171
  }
1176
1172
 
1173
+ /**
1174
+ * Schedules a task to be invoked on a worker thread.
1175
+ * Embedders should override PostTaskOnWorkerThreadImpl() instead of
1176
+ * PostTaskOnWorkerThread().
1177
+ */
1178
+ void PostTaskOnWorkerThread(
1179
+ TaskPriority priority, std::unique_ptr<Task> task,
1180
+ const SourceLocation& location = SourceLocation::Current()) {
1181
+ PostTaskOnWorkerThreadImpl(priority, std::move(task), location);
1182
+ }
1183
+
1184
+ /**
1185
+ * Schedules a task to be invoked on a worker thread after |delay_in_seconds|
1186
+ * expires.
1187
+ * Embedders should override PostDelayedTaskOnWorkerThreadImpl() instead of
1188
+ * PostDelayedTaskOnWorkerThread().
1189
+ */
1190
+ void PostDelayedTaskOnWorkerThread(
1191
+ TaskPriority priority, std::unique_ptr<Task> task,
1192
+ double delay_in_seconds,
1193
+ const SourceLocation& location = SourceLocation::Current()) {
1194
+ PostDelayedTaskOnWorkerThreadImpl(priority, std::move(task),
1195
+ delay_in_seconds, location);
1196
+ }
1197
+
1177
1198
  /**
1178
1199
  * Returns true if idle tasks are enabled for the given |isolate|.
1179
1200
  */
@@ -140,8 +140,14 @@ class V8_EXPORT String : public Name {
140
140
  * Returns the number of bytes in the UTF-8 encoded
141
141
  * representation of this string.
142
142
  */
143
+ V8_DEPRECATED("Use Utf8LengthV2 instead.")
143
144
  int Utf8Length(Isolate* isolate) const;
144
145
 
146
+ /**
147
+ * Returns the number of bytes needed for the Utf8 encoding of this string.
148
+ */
149
+ size_t Utf8LengthV2(Isolate* isolate) const;
150
+
145
151
  /**
146
152
  * Returns whether this string is known to contain only one byte data,
147
153
  * i.e. ISO-8859-1 code points.
@@ -194,15 +200,72 @@ class V8_EXPORT String : public Name {
194
200
  };
195
201
 
196
202
  // 16-bit character codes.
203
+ V8_DEPRECATED("Use WriteV2 instead.")
197
204
  int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
198
205
  int options = NO_OPTIONS) const;
199
206
  // One byte characters.
207
+ V8_DEPRECATED("Use WriteOneByteV2 instead.")
200
208
  int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
201
209
  int length = -1, int options = NO_OPTIONS) const;
202
210
  // UTF-8 encoded characters.
211
+ V8_DEPRECATED("Use WriteUtf8V2 instead.")
203
212
  int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
204
213
  int* nchars_ref = nullptr, int options = NO_OPTIONS) const;
205
214
 
215
+ struct WriteFlags {
216
+ enum {
217
+ kNone = 0,
218
+ // Indicates that the output string should be null-terminated. In that
219
+ // case, the output buffer must include sufficient space for the
220
+ // additional null character.
221
+ kNullTerminate = 1,
222
+ // Used by WriteUtf8 to replace orphan surrogate code units with the
223
+ // unicode replacement character. Needs to be set to guarantee valid UTF-8
224
+ // output.
225
+ kReplaceInvalidUtf8 = 2
226
+ };
227
+ };
228
+
229
+ /**
230
+ * Write the contents of the string to an external buffer.
231
+ *
232
+ * Copies length characters into the output buffer starting at offset. The
233
+ * output buffer must have sufficient space for all characters and the null
234
+ * terminator if null termination is requested through the flags.
235
+ *
236
+ * \param offset The position within the string at which copying begins.
237
+ * \param length The number of characters to copy from the string.
238
+ * \param buffer The buffer into which the string will be copied.
239
+ * \param flags Various flags that influence the behavior of this operation.
240
+ */
241
+ void WriteV2(Isolate* isolate, uint32_t offset, uint32_t length,
242
+ uint16_t* buffer, int flags = WriteFlags::kNone) const;
243
+ void WriteOneByteV2(Isolate* isolate, uint32_t offset, uint32_t length,
244
+ uint8_t* buffer, int flags = WriteFlags::kNone) const;
245
+
246
+ /**
247
+ * Encode the contents of the string as Utf8 into an external buffer.
248
+ *
249
+ * Encodes the characters of this string as Utf8 and writes them into the
250
+ * output buffer until either all characters were encoded or the buffer is
251
+ * full. Will not write partial UTF-8 sequences, preferring to stop before
252
+ * the end of the buffer. If null termination is requested, the output buffer
253
+ * will always be null terminated even if not all characters fit. In that
254
+ * case, the capacity must be at least one. The required size of the output
255
+ * buffer can be determined using Utf8Length().
256
+ *
257
+ * \param buffer The buffer into which the string will be written.
258
+ * \param capacity The number of bytes available in the output buffer.
259
+ * \param flags Various flags that influence the behavior of this operation.
260
+ * \param processed_characters_return The number of processed characters from
261
+ * the buffer.
262
+ * \return The number of bytes copied to the buffer including the null
263
+ * terminator (if written).
264
+ */
265
+ size_t WriteUtf8V2(Isolate* isolate, char* buffer, size_t capacity,
266
+ int flags = WriteFlags::kNone,
267
+ size_t* processed_characters_return = nullptr) const;
268
+
206
269
  /**
207
270
  * A zero length string.
208
271
  */
@@ -223,6 +286,12 @@ class V8_EXPORT String : public Name {
223
286
  */
224
287
  bool IsExternalOneByte() const;
225
288
 
289
+ /**
290
+ * Returns the internalized string. See `NewStringType::kInternalized` for
291
+ * details on internalized strings.
292
+ */
293
+ Local<String> InternalizeString(Isolate* isolate);
294
+
226
295
  class V8_EXPORT ExternalStringResourceBase {
227
296
  public:
228
297
  virtual ~ExternalStringResourceBase() = default;
@@ -234,6 +303,44 @@ class V8_EXPORT String : public Name {
234
303
  */
235
304
  virtual bool IsCacheable() const { return true; }
236
305
 
306
+ /**
307
+ * Internally V8 will call this Unaccount method when the external string
308
+ * resource should be unaccounted for. This method can be overridden in
309
+ * subclasses to control how allocated external bytes are accounted.
310
+ */
311
+ virtual void Unaccount(Isolate* isolate) {}
312
+
313
+ /**
314
+ * Returns an estimate of the memory occupied by this external string, to be
315
+ * used by V8 when producing a heap snapshot. If this function returns
316
+ * kDefaultMemoryEstimate, then V8 will estimate the external size based on
317
+ * the string length. This function should return only memory that is
318
+ * uniquely owned by this resource. If the resource has shared ownership of
319
+ * a secondary allocation, it can report that memory by implementing
320
+ * EstimateSharedMemoryUsage.
321
+ */
322
+ virtual size_t EstimateMemoryUsage() const {
323
+ return kDefaultMemoryEstimate;
324
+ }
325
+ static constexpr size_t kDefaultMemoryEstimate = static_cast<size_t>(-1);
326
+
327
+ class V8_EXPORT SharedMemoryUsageRecorder {
328
+ public:
329
+ /**
330
+ * Record that a shared allocation at the given location has the given
331
+ * size.
332
+ */
333
+ virtual void RecordSharedMemoryUsage(const void* location,
334
+ size_t size) = 0;
335
+ };
336
+
337
+ /**
338
+ * Estimates memory that this string resource may share with other string
339
+ * resources, to be used by V8 when producing a heap snapshot.
340
+ */
341
+ virtual void EstimateSharedMemoryUsage(
342
+ SharedMemoryUsageRecorder* recorder) const {}
343
+
237
344
  // Disallow copying and assigning.
238
345
  ExternalStringResourceBase(const ExternalStringResourceBase&) = delete;
239
346
  void operator=(const ExternalStringResourceBase&) = delete;
@@ -382,6 +489,8 @@ class V8_EXPORT String : public Name {
382
489
  * regardless of the encoding, otherwise return NULL. The encoding of the
383
490
  * string is returned in encoding_out.
384
491
  */
492
+ V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
493
+ v8::Isolate* isolate, Encoding* encoding_out) const;
385
494
  V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
386
495
  Encoding* encoding_out) const;
387
496
 
@@ -466,8 +575,20 @@ class V8_EXPORT String : public Name {
466
575
  * The string is not modified if the operation fails. See NewExternal for
467
576
  * information on the lifetime of the resource.
468
577
  */
578
+ V8_DEPRECATE_SOON("Use the version with the isolate argument instead.")
469
579
  bool MakeExternal(ExternalStringResource* resource);
470
580
 
581
+ /**
582
+ * Associate an external string resource with this string by transforming it
583
+ * in place so that existing references to this string in the JavaScript heap
584
+ * will use the external string resource. The external string resource's
585
+ * character contents need to be equivalent to this string.
586
+ * Returns true if the string has been changed to be an external string.
587
+ * The string is not modified if the operation fails. See NewExternal for
588
+ * information on the lifetime of the resource.
589
+ */
590
+ bool MakeExternal(Isolate* isolate, ExternalStringResource* resource);
591
+
471
592
  /**
472
593
  * Creates a new external string using the one-byte data defined in the given
473
594
  * resource. When the external string is no longer live on V8's heap the
@@ -488,8 +609,20 @@ class V8_EXPORT String : public Name {
488
609
  * The string is not modified if the operation fails. See NewExternal for
489
610
  * information on the lifetime of the resource.
490
611
  */
612
+ V8_DEPRECATE_SOON("Use the version with the isolate argument instead.")
491
613
  bool MakeExternal(ExternalOneByteStringResource* resource);
492
614
 
615
+ /**
616
+ * Associate an external string resource with this string by transforming it
617
+ * in place so that existing references to this string in the JavaScript heap
618
+ * will use the external string resource. The external string resource's
619
+ * character contents need to be equivalent to this string.
620
+ * Returns true if the string has been changed to be an external string.
621
+ * The string is not modified if the operation fails. See NewExternal for
622
+ * information on the lifetime of the resource.
623
+ */
624
+ bool MakeExternal(Isolate* isolate, ExternalOneByteStringResource* resource);
625
+
493
626
  /**
494
627
  * Returns true if this string can be made external, given the encoding for
495
628
  * the external string resource.
@@ -507,14 +640,19 @@ class V8_EXPORT String : public Name {
507
640
  * (e.g. due to an exception in the toString() method of the object)
508
641
  * then the length() method returns 0 and the * operator returns
509
642
  * NULL.
643
+ *
644
+ * WARNING: This will unconditionally copy the contents of the JavaScript
645
+ * string, and should be avoided in situations where performance is a concern.
646
+ * Consider using WriteUtf8() instead.
510
647
  */
511
648
  class V8_EXPORT Utf8Value {
512
649
  public:
513
- Utf8Value(Isolate* isolate, Local<v8::Value> obj);
650
+ Utf8Value(Isolate* isolate, Local<v8::Value> obj,
651
+ WriteOptions options = REPLACE_INVALID_UTF8);
514
652
  ~Utf8Value();
515
653
  char* operator*() { return str_; }
516
654
  const char* operator*() const { return str_; }
517
- int length() const { return length_; }
655
+ size_t length() const { return length_; }
518
656
 
519
657
  // Disallow copying and assigning.
520
658
  Utf8Value(const Utf8Value&) = delete;
@@ -522,22 +660,29 @@ class V8_EXPORT String : public Name {
522
660
 
523
661
  private:
524
662
  char* str_;
525
- int length_;
663
+ size_t length_;
526
664
  };
527
665
 
528
666
  /**
529
667
  * Converts an object to a two-byte (UTF-16-encoded) string.
668
+ *
530
669
  * If conversion to a string fails (eg. due to an exception in the toString()
531
670
  * method of the object) then the length() method returns 0 and the * operator
532
671
  * returns NULL.
672
+ *
673
+ * WARNING: This will unconditionally copy the contents of the JavaScript
674
+ * string, and should be avoided in situations where performance is a concern.
533
675
  */
534
676
  class V8_EXPORT Value {
535
677
  public:
678
+ V8_DEPRECATE_SOON(
679
+ "Prefer using String::ValueView if you can, or string->Write to a "
680
+ "buffer if you cannot.")
536
681
  Value(Isolate* isolate, Local<v8::Value> obj);
537
682
  ~Value();
538
683
  uint16_t* operator*() { return str_; }
539
684
  const uint16_t* operator*() const { return str_; }
540
- int length() const { return length_; }
685
+ uint32_t length() const { return length_; }
541
686
 
542
687
  // Disallow copying and assigning.
543
688
  Value(const Value&) = delete;
@@ -545,7 +690,56 @@ class V8_EXPORT String : public Name {
545
690
 
546
691
  private:
547
692
  uint16_t* str_;
548
- int length_;
693
+ uint32_t length_;
694
+ };
695
+
696
+ /**
697
+ * Returns a view onto a string's contents.
698
+ *
699
+ * WARNING: This does not copy the string's contents, and will therefore be
700
+ * invalidated if the GC can move the string while the ValueView is alive. It
701
+ * is therefore required that no GC or allocation can happen while there is an
702
+ * active ValueView. This requirement may be relaxed in the future.
703
+ *
704
+ * V8 strings are either encoded as one-byte or two-bytes per character.
705
+ */
706
+ class V8_EXPORT ValueView {
707
+ public:
708
+ ValueView(Isolate* isolate, Local<v8::String> str);
709
+ ~ValueView();
710
+ const uint8_t* data8() const {
711
+ #if V8_ENABLE_CHECKS
712
+ CheckOneByte(true);
713
+ #endif
714
+ return data8_;
715
+ }
716
+ const uint16_t* data16() const {
717
+ #if V8_ENABLE_CHECKS
718
+ CheckOneByte(false);
719
+ #endif
720
+ return data16_;
721
+ }
722
+ uint32_t length() const { return length_; }
723
+ bool is_one_byte() const { return is_one_byte_; }
724
+
725
+ // Disallow copying and assigning.
726
+ ValueView(const ValueView&) = delete;
727
+ void operator=(const ValueView&) = delete;
728
+
729
+ private:
730
+ void CheckOneByte(bool is_one_byte) const;
731
+
732
+ Local<v8::String> flat_str_;
733
+ union {
734
+ const uint8_t* data8_;
735
+ const uint16_t* data16_;
736
+ };
737
+ uint32_t length_;
738
+ bool is_one_byte_;
739
+ // Avoid exposing the internal DisallowGarbageCollection scope.
740
+ alignas(internal::Internals::
741
+ kDisallowGarbageCollectionAlign) char no_gc_debug_scope_
742
+ [internal::Internals::kDisallowGarbageCollectionSize];
549
743
  };
550
744
 
551
745
  private:
@@ -811,6 +1005,28 @@ String::ExternalStringResource* String::GetExternalStringResource() const {
811
1005
  return result;
812
1006
  }
813
1007
 
1008
+ String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
1009
+ v8::Isolate* isolate, String::Encoding* encoding_out) const {
1010
+ using A = internal::Address;
1011
+ using I = internal::Internals;
1012
+ A obj = internal::ValueHelper::ValueAsAddress(this);
1013
+ int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
1014
+ *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
1015
+ ExternalStringResourceBase* resource;
1016
+ if (type == I::kExternalOneByteRepresentationTag ||
1017
+ type == I::kExternalTwoByteRepresentationTag) {
1018
+ A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
1019
+ isolate, obj, I::kStringResourceOffset);
1020
+ resource = reinterpret_cast<ExternalStringResourceBase*>(value);
1021
+ } else {
1022
+ resource = GetExternalStringResourceBaseSlow(encoding_out);
1023
+ }
1024
+ #ifdef V8_ENABLE_CHECKS
1025
+ VerifyExternalStringResourceBase(resource, *encoding_out);
1026
+ #endif
1027
+ return resource;
1028
+ }
1029
+
814
1030
  String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
815
1031
  String::Encoding* encoding_out) const {
816
1032
  using A = internal::Address;
@@ -418,8 +418,11 @@ class V8_EXPORT CpuProfiler {
418
418
  * Synchronously collect current stack sample in all profilers attached to
419
419
  * the |isolate|. The call does not affect number of ticks recorded for
420
420
  * the current top node.
421
+ * |trace_id| is an optional identifier set to the collected sample.
422
+ * this is useful to associate the sample with a trace event.
421
423
  */
422
- static void CollectSample(Isolate* isolate);
424
+ static void CollectSample(
425
+ Isolate* isolate, const std::optional<uint64_t> trace_id = std::nullopt);
423
426
 
424
427
  /**
425
428
  * Disposes the CPU profiler object.
@@ -899,9 +902,28 @@ class V8_EXPORT EmbedderGraph {
899
902
  /**
900
903
  * Returns a node corresponding to the given V8 value. Ownership is not
901
904
  * transferred. The result pointer is valid while the graph is alive.
905
+ *
906
+ * For now the variant that takes v8::Data is not marked as abstract for
907
+ * compatibility, but embedders who subclass EmbedderGraph are expected to
908
+ * implement it. Then in the implementation of the variant that takes
909
+ * v8::Value, they can simply forward the call to the one that takes
910
+ * v8::Local<v8::Data>.
902
911
  */
903
912
  virtual Node* V8Node(const v8::Local<v8::Value>& value) = 0;
904
913
 
914
+ /**
915
+ * Returns a node corresponding to the given V8 value. Ownership is not
916
+ * transferred. The result pointer is valid while the graph is alive.
917
+ *
918
+ * For API compatibility, this default implementation just checks that the
919
+ * data is a v8::Value and forward it to the variant that takes v8::Value,
920
+ * which is currently required to be implemented. In the future we'll remove
921
+ * the v8::Value variant, and make this variant that takes v8::Data abstract
922
+ * instead. If the embedder subclasses v8::EmbedderGraph and also use
923
+ * v8::TracedReference<v8::Data>, they must override this variant.
924
+ */
925
+ virtual Node* V8Node(const v8::Local<v8::Data>& value);
926
+
905
927
  /**
906
928
  * Adds the given node to the graph and takes ownership of the node.
907
929
  * Returns a raw pointer to the node that is valid while the graph is alive.
@@ -918,6 +940,15 @@ class V8_EXPORT EmbedderGraph {
918
940
  */
919
941
  virtual void AddEdge(Node* from, Node* to, const char* name = nullptr) = 0;
920
942
 
943
+ /**
944
+ * Adds a count of bytes that are not associated with any particular Node.
945
+ * An embedder may use this to represent the size of nodes which were omitted
946
+ * from this EmbedderGraph despite being retained by the graph, or other
947
+ * overhead costs. This number will contribute to the total size in a heap
948
+ * snapshot, without being represented in the object graph.
949
+ */
950
+ virtual void AddNativeSize(size_t size) {}
951
+
921
952
  virtual ~EmbedderGraph() = default;
922
953
  };
923
954
 
@@ -956,7 +987,7 @@ class V8_EXPORT HeapProfiler {
956
987
 
957
988
  /**
958
989
  * Callback function invoked during heap snapshot generation to retrieve
959
- * the detachedness state of an object referenced by a TracedReference.
990
+ * the detachedness state of a JS object referenced by a TracedReference.
960
991
  *
961
992
  * The callback takes Local<Value> as parameter to allow the embedder to
962
993
  * unpack the TracedReference into a Local and reuse that Local for different
@@ -1090,6 +1121,12 @@ class V8_EXPORT HeapProfiler {
1090
1121
  ObjectNameResolver* global_object_name_resolver = nullptr,
1091
1122
  bool hide_internals = true, bool capture_numeric_value = false);
1092
1123
 
1124
+ /**
1125
+ * Obtains list of Detached JS Wrapper Objects. This functon calls garbage
1126
+ * collection, then iterates over traced handles in the isolate
1127
+ */
1128
+ std::vector<v8::Local<v8::Value>> GetDetachedJSWrapperObjects();
1129
+
1093
1130
  /**
1094
1131
  * Starts tracking of heap objects population statistics. After calling
1095
1132
  * this method, all heap objects relocations done by the garbage collector
@@ -1179,6 +1216,18 @@ class V8_EXPORT HeapProfiler {
1179
1216
 
1180
1217
  void SetGetDetachednessCallback(GetDetachednessCallback callback, void* data);
1181
1218
 
1219
+ /**
1220
+ * Returns whether the heap profiler is currently taking a snapshot.
1221
+ */
1222
+ bool IsTakingSnapshot();
1223
+
1224
+ /**
1225
+ * Allocates a copy of the provided string within the heap snapshot generator
1226
+ * and returns a pointer to the copy. May only be called during heap snapshot
1227
+ * generation.
1228
+ */
1229
+ const char* CopyNameForHeapSnapshot(const char* name);
1230
+
1182
1231
  /**
1183
1232
  * Default value of persistent handle class ID. Must not be used to
1184
1233
  * define a class. Can be used to reset a class of a persistent
@@ -14,7 +14,7 @@ namespace v8 {
14
14
  class Context;
15
15
 
16
16
  #ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
17
- // The number of required internal fields can be defined by embedder.
17
+ // Defined using gn arg `v8_promise_internal_field_count`.
18
18
  #define V8_PROMISE_INTERNAL_FIELD_COUNT 0
19
19
  #endif
20
20
 
@@ -115,7 +115,7 @@ class V8_EXPORT Promise : public Object {
115
115
  return static_cast<Promise*>(value);
116
116
  }
117
117
 
118
- static const int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
118
+ static constexpr int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
119
119
 
120
120
  private:
121
121
  Promise();
@@ -1,4 +1,3 @@
1
-
2
1
  // Copyright 2021 the V8 project authors. All rights reserved.
3
2
  // Use of this source code is governed by a BSD-style license that can be
4
3
  // found in the LICENSE file.