libv8-node 21.7.2.0-aarch64-linux-musl → 24.12.0.0-aarch64-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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8-node/location.rb +3 -5
  3. data/ext/libv8-node/paths.rb +2 -0
  4. data/lib/libv8/node/version.rb +7 -4
  5. data/lib/libv8/node.rb +2 -0
  6. data/lib/libv8-node.rb +2 -0
  7. data/vendor/v8/aarch64-linux-musl/libv8/obj/libv8_monolith.a +0 -0
  8. data/vendor/v8/include/cppgc/allocation.h +11 -13
  9. data/vendor/v8/include/cppgc/default-platform.h +3 -2
  10. data/vendor/v8/include/cppgc/garbage-collected.h +8 -0
  11. data/vendor/v8/include/cppgc/heap-consistency.h +1 -1
  12. data/vendor/v8/include/cppgc/heap-statistics.h +2 -0
  13. data/vendor/v8/include/cppgc/internal/api-constants.h +2 -14
  14. data/vendor/v8/include/cppgc/internal/base-page-handle.h +2 -4
  15. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +0 -4
  16. data/vendor/v8/include/cppgc/internal/caged-heap.h +0 -4
  17. data/vendor/v8/include/cppgc/internal/compiler-specific.h +9 -1
  18. data/vendor/v8/include/cppgc/internal/conditional-stack-allocated.h +41 -0
  19. data/vendor/v8/include/cppgc/internal/gc-info.h +12 -10
  20. data/vendor/v8/include/cppgc/internal/logging.h +3 -3
  21. data/vendor/v8/include/cppgc/internal/member-storage.h +69 -20
  22. data/vendor/v8/include/cppgc/internal/name-trait.h +5 -1
  23. data/vendor/v8/include/cppgc/internal/persistent-node.h +8 -3
  24. data/vendor/v8/include/cppgc/internal/pointer-policies.h +48 -11
  25. data/vendor/v8/include/cppgc/macros.h +21 -0
  26. data/vendor/v8/include/cppgc/member.h +70 -36
  27. data/vendor/v8/include/cppgc/name-provider.h +10 -0
  28. data/vendor/v8/include/cppgc/platform.h +11 -0
  29. data/vendor/v8/include/cppgc/type-traits.h +26 -4
  30. data/vendor/v8/include/cppgc/visitor.h +25 -1
  31. data/vendor/v8/include/libplatform/libplatform-export.h +2 -2
  32. data/vendor/v8/include/libplatform/v8-tracing.h +0 -1
  33. data/vendor/v8/include/v8-array-buffer.h +149 -46
  34. data/vendor/v8/include/v8-callbacks.h +100 -43
  35. data/vendor/v8/include/v8-container.h +54 -0
  36. data/vendor/v8/include/v8-context.h +92 -30
  37. data/vendor/v8/include/v8-cppgc.h +5 -56
  38. data/vendor/v8/include/v8-data.h +5 -0
  39. data/vendor/v8/include/v8-date.h +9 -0
  40. data/vendor/v8/include/v8-debug.h +11 -0
  41. data/vendor/v8/include/v8-embedder-heap.h +8 -20
  42. data/vendor/v8/include/v8-embedder-state-scope.h +2 -1
  43. data/vendor/v8/include/v8-exception.h +87 -9
  44. data/vendor/v8/include/v8-external-memory-accounter.h +60 -0
  45. data/vendor/v8/include/v8-fast-api-calls.h +67 -223
  46. data/vendor/v8/include/v8-forward.h +1 -0
  47. data/vendor/v8/include/v8-function-callback.h +296 -75
  48. data/vendor/v8/include/v8-function.h +11 -3
  49. data/vendor/v8/include/v8-handle-base.h +52 -82
  50. data/vendor/v8/include/v8-initialization.h +26 -1
  51. data/vendor/v8/include/v8-inspector.h +26 -27
  52. data/vendor/v8/include/v8-internal.h +960 -230
  53. data/vendor/v8/include/v8-isolate.h +347 -226
  54. data/vendor/v8/include/v8-local-handle.h +307 -55
  55. data/vendor/v8/include/v8-maybe.h +2 -1
  56. data/vendor/v8/include/v8-memory-span.h +284 -4
  57. data/vendor/v8/include/v8-message.h +11 -5
  58. data/vendor/v8/include/v8-metrics.h +15 -0
  59. data/vendor/v8/include/v8-microtask-queue.h +0 -5
  60. data/vendor/v8/include/v8-object.h +314 -41
  61. data/vendor/v8/include/v8-persistent-handle.h +29 -39
  62. data/vendor/v8/include/v8-platform.h +135 -77
  63. data/vendor/v8/include/v8-primitive.h +223 -5
  64. data/vendor/v8/include/v8-profiler.h +51 -2
  65. data/vendor/v8/include/v8-promise.h +2 -2
  66. data/vendor/v8/include/v8-proxy.h +0 -1
  67. data/vendor/v8/include/v8-regexp.h +0 -1
  68. data/vendor/v8/include/v8-sandbox.h +173 -0
  69. data/vendor/v8/include/v8-script.h +125 -27
  70. data/vendor/v8/include/v8-snapshot.h +130 -23
  71. data/vendor/v8/include/v8-source-location.h +6 -1
  72. data/vendor/v8/include/v8-statistics.h +10 -24
  73. data/vendor/v8/include/v8-template.h +320 -193
  74. data/vendor/v8/include/v8-trace-categories.h +23 -0
  75. data/vendor/v8/include/v8-traced-handle.h +99 -76
  76. data/vendor/v8/include/v8-typed-array.h +111 -7
  77. data/vendor/v8/include/v8-unwinder-state.h +2 -3
  78. data/vendor/v8/include/v8-unwinder.h +2 -1
  79. data/vendor/v8/include/v8-util.h +10 -125
  80. data/vendor/v8/include/v8-value-serializer-version.h +3 -3
  81. data/vendor/v8/include/v8-value.h +113 -6
  82. data/vendor/v8/include/v8-version.h +3 -3
  83. data/vendor/v8/include/v8-wasm.h +27 -0
  84. data/vendor/v8/include/v8-weak-callback-info.h +20 -12
  85. data/vendor/v8/include/v8.h +3 -3
  86. data/vendor/v8/include/v8config.h +116 -53
  87. metadata +55 -12
  88. data/vendor/v8/include/cppgc/ephemeron-pair.h +0 -30
@@ -10,19 +10,28 @@
10
10
  #include <memory>
11
11
 
12
12
  #include "v8-local-handle.h" // NOLINT(build/include_directory)
13
+ #include "v8-memory-span.h" // NOLINT(build/include_directory)
13
14
  #include "v8-object.h" // NOLINT(build/include_directory)
15
+ #include "v8-platform.h" // NOLINT(build/include_directory)
14
16
  #include "v8config.h" // NOLINT(build/include_directory)
15
17
 
16
18
  namespace v8 {
17
19
 
18
20
  class SharedArrayBuffer;
19
21
 
22
+ #if defined(V8_COMPRESS_POINTERS) && \
23
+ !defined(V8_COMPRESS_POINTERS_IN_SHARED_CAGE)
24
+ class IsolateGroup;
25
+ #endif
26
+
20
27
  #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
21
- // The number of required internal fields can be defined by embedder.
28
+ // Defined using gn arg `v8_array_buffer_internal_field_count`.
22
29
  #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
23
30
  #endif
24
31
 
25
32
  enum class ArrayBufferCreationMode { kInternalized, kExternalized };
33
+ enum class BackingStoreInitializationMode { kZeroInitialized, kUninitialized };
34
+ enum class BackingStoreOnFailureMode { kReturnNull, kOutOfMemory };
26
35
 
27
36
  /**
28
37
  * A wrapper around the backing store (i.e. the raw memory) of an array buffer.
@@ -82,15 +91,6 @@ class V8_EXPORT BackingStore : public v8::internal::BackingStoreBase {
82
91
  */
83
92
  void operator delete(void* ptr) { ::operator delete(ptr); }
84
93
 
85
- /**
86
- * Wrapper around ArrayBuffer::Allocator::Reallocate that preserves IsShared.
87
- * Assumes that the backing_store was allocated by the ArrayBuffer allocator
88
- * of the given isolate.
89
- */
90
- static std::unique_ptr<BackingStore> Reallocate(
91
- v8::Isolate* isolate, std::unique_ptr<BackingStore> backing_store,
92
- size_t byte_length);
93
-
94
94
  /**
95
95
  * This callback is used only if the memory block for a BackingStore cannot be
96
96
  * allocated with an ArrayBuffer::Allocator. In such cases the destructor of
@@ -168,18 +168,13 @@ class V8_EXPORT ArrayBuffer : public Object {
168
168
  virtual void Free(void* data, size_t length) = 0;
169
169
 
170
170
  /**
171
- * Reallocate the memory block of size |old_length| to a memory block of
172
- * size |new_length| by expanding, contracting, or copying the existing
173
- * memory block. If |new_length| > |old_length|, then the new part of
174
- * the memory must be initialized to zeros. Return nullptr if reallocation
175
- * is not successful.
176
- *
177
- * The caller guarantees that the memory block was previously allocated
178
- * using Allocate or AllocateUninitialized.
179
- *
180
- * The default implementation allocates a new block and copies data.
171
+ * Returns a size_t that determines the largest ArrayBuffer that can be
172
+ * allocated. Override if your Allocator is more restrictive than the
173
+ * default. Will only be called once, and the value returned will be
174
+ * cached.
175
+ * Should not return a value that is larger than kMaxByteLength.
181
176
  */
182
- virtual void* Reallocate(void* data, size_t old_length, size_t new_length);
177
+ virtual size_t MaxAllocationSize() const { return kMaxByteLength; }
183
178
 
184
179
  /**
185
180
  * ArrayBuffer allocation mode. kNormal is a malloc/free style allocation,
@@ -188,11 +183,37 @@ class V8_EXPORT ArrayBuffer : public Object {
188
183
  */
189
184
  enum class AllocationMode { kNormal, kReservation };
190
185
 
186
+ /**
187
+ * Returns page allocator used by this Allocator instance.
188
+ *
189
+ * When the sandbox used by Allocator it is expected that this returns
190
+ * sandbox's page allocator.
191
+ * Otherwise, it should return system page allocator.
192
+ */
193
+ virtual PageAllocator* GetPageAllocator() { return nullptr; }
194
+
195
+ #if defined(V8_COMPRESS_POINTERS) && \
196
+ !defined(V8_COMPRESS_POINTERS_IN_SHARED_CAGE)
197
+ /**
198
+ * Convenience allocator.
199
+ *
200
+ * When the sandbox is enabled, this allocator will allocate its backing
201
+ * memory inside the sandbox that belongs to passed isolate group.
202
+ * Otherwise, it will rely on malloc/free.
203
+ *
204
+ * Caller takes ownership, i.e. the returned object needs to be freed using
205
+ * |delete allocator| once it is no longer in use.
206
+ */
207
+ static Allocator* NewDefaultAllocator(const IsolateGroup& group);
208
+ #endif // defined(V8_COMPRESS_POINTERS) &&
209
+ // !defined(V8_COMPRESS_POINTERS_IN_SHARED_CAGE)
210
+
191
211
  /**
192
212
  * Convenience allocator.
193
213
  *
194
214
  * When the sandbox is enabled, this allocator will allocate its backing
195
- * memory inside the sandbox. Otherwise, it will rely on malloc/free.
215
+ * memory inside the default global sandbox. Otherwise, it will rely on
216
+ * malloc/free.
196
217
  *
197
218
  * Caller takes ownership, i.e. the returned object needs to be freed using
198
219
  * |delete allocator| once it is no longer in use.
@@ -211,12 +232,27 @@ class V8_EXPORT ArrayBuffer : public Object {
211
232
  size_t MaxByteLength() const;
212
233
 
213
234
  /**
214
- * Create a new ArrayBuffer. Allocate |byte_length| bytes.
235
+ * Attempt to create a new ArrayBuffer. Allocate |byte_length| bytes.
215
236
  * Allocated memory will be owned by a created ArrayBuffer and
216
237
  * will be deallocated when it is garbage-collected,
238
+ * unless the object is externalized. If allocation fails, the Maybe
239
+ * returned will be empty.
240
+ */
241
+ static MaybeLocal<ArrayBuffer> MaybeNew(
242
+ Isolate* isolate, size_t byte_length,
243
+ BackingStoreInitializationMode initialization_mode =
244
+ BackingStoreInitializationMode::kZeroInitialized);
245
+
246
+ /**
247
+ * Create a new ArrayBuffer. Allocate |byte_length| bytes, which are either
248
+ * zero-initialized or uninitialized. Allocated memory will be owned by a
249
+ * created ArrayBuffer and will be deallocated when it is garbage-collected,
217
250
  * unless the object is externalized.
218
251
  */
219
- static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
252
+ static Local<ArrayBuffer> New(
253
+ Isolate* isolate, size_t byte_length,
254
+ BackingStoreInitializationMode initialization_mode =
255
+ BackingStoreInitializationMode::kZeroInitialized);
220
256
 
221
257
  /**
222
258
  * Create a new ArrayBuffer with an existing backing store.
@@ -235,15 +271,26 @@ class V8_EXPORT ArrayBuffer : public Object {
235
271
 
236
272
  /**
237
273
  * Returns a new standalone BackingStore that is allocated using the array
238
- * buffer allocator of the isolate. The result can be later passed to
274
+ * buffer allocator of the isolate. The allocation can either be zero
275
+ * initialized, or uninitialized. The result can be later passed to
239
276
  * ArrayBuffer::New.
240
277
  *
241
278
  * If the allocator returns nullptr, then the function may cause GCs in the
242
- * given isolate and re-try the allocation. If GCs do not help, then the
279
+ * given isolate and re-try the allocation.
280
+ *
281
+ * If GCs do not help and on_failure is kOutOfMemory, then the
243
282
  * function will crash with an out-of-memory error.
283
+ *
284
+ * Otherwise if GCs do not help (or the allocation is too large for GCs to
285
+ * help) and on_failure is kReturnNull, then a null result is returned.
244
286
  */
245
- static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate,
246
- size_t byte_length);
287
+ static std::unique_ptr<BackingStore> NewBackingStore(
288
+ Isolate* isolate, size_t byte_length,
289
+ BackingStoreInitializationMode initialization_mode =
290
+ BackingStoreInitializationMode::kZeroInitialized,
291
+ BackingStoreOnFailureMode on_failure =
292
+ BackingStoreOnFailureMode::kOutOfMemory);
293
+
247
294
  /**
248
295
  * Returns a new standalone BackingStore that takes over the ownership of
249
296
  * the given buffer. The destructor of the BackingStore invokes the given
@@ -287,7 +334,7 @@ class V8_EXPORT ArrayBuffer : public Object {
287
334
  * preventing JavaScript from ever accessing underlying backing store.
288
335
  * ArrayBuffer should have been externalized and must be detachable.
289
336
  */
290
- V8_DEPRECATE_SOON(
337
+ V8_DEPRECATED(
291
338
  "Use the version which takes a key parameter (passing a null handle is "
292
339
  "ok).")
293
340
  void Detach();
@@ -318,6 +365,12 @@ class V8_EXPORT ArrayBuffer : public Object {
318
365
  */
319
366
  std::shared_ptr<BackingStore> GetBackingStore();
320
367
 
368
+ /**
369
+ * More efficient shortcut for
370
+ * GetBackingStore()->IsResizableByUserJavaScript().
371
+ */
372
+ bool IsResizableByUserJavaScript() const;
373
+
321
374
  /**
322
375
  * More efficient shortcut for GetBackingStore()->Data(). The returned pointer
323
376
  * is valid as long as the ArrayBuffer is alive.
@@ -331,16 +384,29 @@ class V8_EXPORT ArrayBuffer : public Object {
331
384
  return static_cast<ArrayBuffer*>(value);
332
385
  }
333
386
 
334
- static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
335
- static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
387
+ static constexpr int kInternalFieldCount =
388
+ V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
389
+ static constexpr int kEmbedderFieldCount = kInternalFieldCount;
390
+
391
+ #if V8_ENABLE_SANDBOX
392
+ static constexpr size_t kMaxByteLength =
393
+ internal::kMaxSafeBufferSizeForSandbox;
394
+ #elif V8_HOST_ARCH_32_BIT
395
+ static constexpr size_t kMaxByteLength = std::numeric_limits<int>::max();
396
+ #else
397
+ // The maximum safe integer (2^53 - 1).
398
+ static constexpr size_t kMaxByteLength =
399
+ static_cast<size_t>((uint64_t{1} << 53) - 1);
400
+ #endif
336
401
 
337
402
  private:
338
403
  ArrayBuffer();
339
404
  static void CheckCast(Value* obj);
405
+ friend class TypedArray;
340
406
  };
341
407
 
342
408
  #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
343
- // The number of required internal fields can be defined by embedder.
409
+ // Defined using gn arg `v8_array_buffer_view_internal_field_count`.
344
410
  #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
345
411
  #endif
346
412
 
@@ -374,6 +440,16 @@ class V8_EXPORT ArrayBufferView : public Object {
374
440
  */
375
441
  size_t CopyContents(void* dest, size_t byte_length);
376
442
 
443
+ /**
444
+ * Returns the contents of the ArrayBufferView's buffer as a MemorySpan. If
445
+ * the contents are on the V8 heap, they get copied into `storage`. Otherwise
446
+ * a view into the off-heap backing store is returned. The provided storage
447
+ * should be at least as large as the maximum on-heap size of a TypedArray,
448
+ * was defined in gn with `typed_array_max_size_in_heap`. The default value is
449
+ * 64 bytes.
450
+ */
451
+ v8::MemorySpan<uint8_t> GetContents(v8::MemorySpan<uint8_t> storage);
452
+
377
453
  /**
378
454
  * Returns true if ArrayBufferView's backing ArrayBuffer has already been
379
455
  * allocated.
@@ -387,10 +463,9 @@ class V8_EXPORT ArrayBufferView : public Object {
387
463
  return static_cast<ArrayBufferView*>(value);
388
464
  }
389
465
 
390
- static const int kInternalFieldCount =
391
- V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
392
- static const int kEmbedderFieldCount =
466
+ static constexpr int kInternalFieldCount =
393
467
  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
468
+ static const int kEmbedderFieldCount = kInternalFieldCount;
394
469
 
395
470
  private:
396
471
  ArrayBufferView();
@@ -434,12 +509,27 @@ class V8_EXPORT SharedArrayBuffer : public Object {
434
509
  size_t MaxByteLength() const;
435
510
 
436
511
  /**
437
- * Create a new SharedArrayBuffer. Allocate |byte_length| bytes.
438
- * Allocated memory will be owned by a created SharedArrayBuffer and
439
- * will be deallocated when it is garbage-collected,
440
- * unless the object is externalized.
512
+ * Create a new SharedArrayBuffer. Allocate |byte_length| bytes, which are
513
+ * either zero-initialized or uninitialized. Allocated memory will be owned by
514
+ * a created SharedArrayBuffer and will be deallocated when it is
515
+ * garbage-collected, unless the object is externalized.
516
+ */
517
+ static Local<SharedArrayBuffer> New(
518
+ Isolate* isolate, size_t byte_length,
519
+ BackingStoreInitializationMode initialization_mode =
520
+ BackingStoreInitializationMode::kZeroInitialized);
521
+
522
+ /**
523
+ * Create a new SharedArrayBuffer. Allocate |byte_length| bytes, which are
524
+ * either zero-initialized or uninitialized. Allocated memory will be owned by
525
+ * a created SharedArrayBuffer and will be deallocated when it is
526
+ * garbage-collected, unless the object is externalized. If allocation
527
+ * fails, the Maybe returned will be empty.
441
528
  */
442
- static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
529
+ static MaybeLocal<SharedArrayBuffer> MaybeNew(
530
+ Isolate* isolate, size_t byte_length,
531
+ BackingStoreInitializationMode initialization_mode =
532
+ BackingStoreInitializationMode::kZeroInitialized);
443
533
 
444
534
  /**
445
535
  * Create a new SharedArrayBuffer with an existing backing store.
@@ -458,15 +548,27 @@ class V8_EXPORT SharedArrayBuffer : public Object {
458
548
 
459
549
  /**
460
550
  * Returns a new standalone BackingStore that is allocated using the array
461
- * buffer allocator of the isolate. The result can be later passed to
551
+ * buffer allocator of the isolate. The allocation can either be zero
552
+ * initialized, or uninitialized. The result can be later passed to
462
553
  * SharedArrayBuffer::New.
463
554
  *
464
555
  * If the allocator returns nullptr, then the function may cause GCs in the
465
- * given isolate and re-try the allocation. If GCs do not help, then the
466
- * function will crash with an out-of-memory error.
556
+ * given isolate and re-try the allocation.
557
+ *
558
+ * If on_failure is kOutOfMemory and GCs do not help, then the function will
559
+ * crash with an out-of-memory error.
560
+ *
561
+ * Otherwise, if on_failure is kReturnNull and GCs do not help (or the
562
+ * byte_length is so large that the allocation cannot succeed), then a null
563
+ * result is returned.
467
564
  */
468
- static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate,
469
- size_t byte_length);
565
+ static std::unique_ptr<BackingStore> NewBackingStore(
566
+ Isolate* isolate, size_t byte_length,
567
+ BackingStoreInitializationMode initialization_mode =
568
+ BackingStoreInitializationMode::kZeroInitialized,
569
+ BackingStoreOnFailureMode on_failure =
570
+ BackingStoreOnFailureMode::kOutOfMemory);
571
+
470
572
  /**
471
573
  * Returns a new standalone BackingStore that takes over the ownership of
472
574
  * the given buffer. The destructor of the BackingStore invokes the given
@@ -500,7 +602,8 @@ class V8_EXPORT SharedArrayBuffer : public Object {
500
602
  return static_cast<SharedArrayBuffer*>(value);
501
603
  }
502
604
 
503
- static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
605
+ static constexpr int kInternalFieldCount =
606
+ V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
504
607
 
505
608
  private:
506
609
  SharedArrayBuffer();
@@ -129,7 +129,9 @@ struct JitCodeEvent {
129
129
  enum JitCodeEventOptions {
130
130
  kJitCodeEventDefault = 0,
131
131
  // Generate callbacks for already existent code.
132
- kJitCodeEventEnumExisting = 1
132
+ kJitCodeEventEnumExisting = 1,
133
+
134
+ kLastJitCodeEventOption = kJitCodeEventEnumExisting
133
135
  };
134
136
 
135
137
  /**
@@ -152,9 +154,6 @@ using JitCodeEventHandler = void (*)(const JitCodeEvent* event);
152
154
  enum GCType {
153
155
  kGCTypeScavenge = 1 << 0,
154
156
  kGCTypeMinorMarkSweep = 1 << 1,
155
- kGCTypeMinorMarkCompact V8_DEPRECATE_SOON(
156
- "Use kGCTypeMinorMarkSweep instead of kGCTypeMinorMarkCompact.") =
157
- kGCTypeMinorMarkSweep,
158
157
  kGCTypeMarkSweepCompact = 1 << 2,
159
158
  kGCTypeIncrementalMarking = 1 << 3,
160
159
  kGCTypeProcessWeakCallbacks = 1 << 4,
@@ -191,6 +190,9 @@ using GCCallback = void (*)(GCType type, GCCallbackFlags flags);
191
190
 
192
191
  using InterruptCallback = void (*)(Isolate* isolate, void* data);
193
192
 
193
+ using PrintCurrentStackTraceFilterCallback =
194
+ bool (*)(Isolate* isolate, Local<String> script_name);
195
+
194
196
  /**
195
197
  * This callback is invoked when the heap size is close to the heap limit and
196
198
  * V8 is likely to abort with out-of-memory error.
@@ -234,7 +236,7 @@ using MessageCallback = void (*)(Local<Message> message, Local<Value> data);
234
236
 
235
237
  // --- Tracing ---
236
238
 
237
- enum LogEventStatus : int { kStart = 0, kEnd = 1, kStamp = 2 };
239
+ enum LogEventStatus : int { kStart = 0, kEnd = 1, kLog = 2 };
238
240
  using LogEventCallback = void (*)(const char* name,
239
241
  int /* LogEventStatus */ status);
240
242
 
@@ -257,15 +259,7 @@ using AddCrashKeyCallback = void (*)(CrashKeyId id, const std::string& value);
257
259
  using BeforeCallEnteredCallback = void (*)(Isolate*);
258
260
  using CallCompletedCallback = void (*)(Isolate*);
259
261
 
260
- // --- AllowCodeGenerationFromStrings callbacks ---
261
-
262
- /**
263
- * Callback to check if code generation from strings is allowed. See
264
- * Context::AllowCodeGenerationFromStrings.
265
- */
266
- using AllowCodeGenerationFromStringsCallback = bool (*)(Local<Context> context,
267
- Local<String> source);
268
-
262
+ // --- Modify Code Generation From Strings Callback ---
269
263
  struct ModifyCodeGenerationFromStringsResult {
270
264
  // If true, proceed with the codegen algorithm. Otherwise, block it.
271
265
  bool codegen_allowed = false;
@@ -275,6 +269,20 @@ struct ModifyCodeGenerationFromStringsResult {
275
269
  MaybeLocal<String> modified_source;
276
270
  };
277
271
 
272
+ /**
273
+ * Callback to check if codegen is allowed from a source object, and convert
274
+ * the source to string if necessary. See: ModifyCodeGenerationFromStrings.
275
+ */
276
+ using ModifyCodeGenerationFromStringsCallback =
277
+ ModifyCodeGenerationFromStringsResult (*)(Local<Context> context,
278
+ Local<Value> source);
279
+ using ModifyCodeGenerationFromStringsCallback2 =
280
+ ModifyCodeGenerationFromStringsResult (*)(Local<Context> context,
281
+ Local<Value> source,
282
+ bool is_code_like);
283
+
284
+ // --- Failed Access Check Callback ---
285
+
278
286
  /**
279
287
  * Access type specification.
280
288
  */
@@ -286,23 +294,9 @@ enum AccessType {
286
294
  ACCESS_KEYS
287
295
  };
288
296
 
289
- // --- Failed Access Check Callback ---
290
-
291
297
  using FailedAccessCheckCallback = void (*)(Local<Object> target,
292
298
  AccessType type, Local<Value> data);
293
299
 
294
- /**
295
- * Callback to check if codegen is allowed from a source object, and convert
296
- * the source to string if necessary. See: ModifyCodeGenerationFromStrings.
297
- */
298
- using ModifyCodeGenerationFromStringsCallback =
299
- ModifyCodeGenerationFromStringsResult (*)(Local<Context> context,
300
- Local<Value> source);
301
- using ModifyCodeGenerationFromStringsCallback2 =
302
- ModifyCodeGenerationFromStringsResult (*)(Local<Context> context,
303
- Local<Value> source,
304
- bool is_code_like);
305
-
306
300
  // --- WebAssembly compilation callbacks ---
307
301
  using ExtensionCallback = bool (*)(const FunctionCallbackInfo<Value>&);
308
302
 
@@ -327,10 +321,6 @@ using WasmAsyncResolvePromiseCallback = void (*)(
327
321
  using WasmLoadSourceMapCallback = Local<String> (*)(Isolate* isolate,
328
322
  const char* name);
329
323
 
330
- // --- Callback for checking if WebAssembly GC is enabled ---
331
- // If the callback returns true, it will also enable Wasm stringrefs.
332
- using WasmGCEnabledCallback = bool (*)(Local<Context> context);
333
-
334
324
  // --- Callback for checking if WebAssembly imported strings are enabled ---
335
325
  using WasmImportedStringsEnabledCallback = bool (*)(Local<Context> context);
336
326
 
@@ -342,6 +332,17 @@ using SharedArrayBufferConstructorEnabledCallback =
342
332
  using JavaScriptCompileHintsMagicEnabledCallback =
343
333
  bool (*)(Local<Context> context);
344
334
 
335
+ // --- Callback for checking if WebAssembly JSPI is enabled ---
336
+ using WasmJSPIEnabledCallback = bool (*)(Local<Context> context);
337
+
338
+ /**
339
+ * Import phases in import requests.
340
+ */
341
+ enum class ModuleImportPhase {
342
+ kSource,
343
+ kEvaluation,
344
+ };
345
+
345
346
  /**
346
347
  * HostImportModuleDynamicallyCallback is called when we
347
348
  * require the embedder to load a module. This is used as part of the dynamic
@@ -352,11 +353,11 @@ using JavaScriptCompileHintsMagicEnabledCallback =
352
353
  *
353
354
  * The specifier is the name of the module that should be imported.
354
355
  *
355
- * The import_assertions are import assertions for this request in the form:
356
+ * The import_attributes are import attributes for this request in the form:
356
357
  * [key1, value1, key2, value2, ...] where the keys and values are of type
357
358
  * v8::String. Note, unlike the FixedArray passed to ResolveModuleCallback and
358
- * returned from ModuleRequest::GetImportAssertions(), this array does not
359
- * contain the source Locations of the assertions.
359
+ * returned from ModuleRequest::GetImportAttributes(), this array does not
360
+ * contain the source Locations of the attributes.
360
361
  *
361
362
  * The embedder must compile, instantiate, evaluate the Module, and
362
363
  * obtain its namespace object.
@@ -368,15 +369,51 @@ using JavaScriptCompileHintsMagicEnabledCallback =
368
369
  * fails (e.g. due to stack overflow), the embedder must propagate
369
370
  * that exception by returning an empty MaybeLocal.
370
371
  */
371
- using HostImportModuleDynamicallyWithImportAssertionsCallback =
372
- MaybeLocal<Promise> (*)(Local<Context> context,
373
- Local<ScriptOrModule> referrer,
374
- Local<String> specifier,
375
- Local<FixedArray> import_assertions);
376
372
  using HostImportModuleDynamicallyCallback = MaybeLocal<Promise> (*)(
377
373
  Local<Context> context, Local<Data> host_defined_options,
378
374
  Local<Value> resource_name, Local<String> specifier,
379
- Local<FixedArray> import_assertions);
375
+ Local<FixedArray> import_attributes);
376
+
377
+ /**
378
+ * HostImportModuleWithPhaseDynamicallyCallback is called when we
379
+ * require the embedder to load a module with a specific phase. This is used
380
+ * as part of the dynamic import syntax.
381
+ *
382
+ * The referrer contains metadata about the script/module that calls
383
+ * import.
384
+ *
385
+ * The specifier is the name of the module that should be imported.
386
+ *
387
+ * The phase is the phase of the import requested.
388
+ *
389
+ * The import_attributes are import attributes for this request in the form:
390
+ * [key1, value1, key2, value2, ...] where the keys and values are of type
391
+ * v8::String. Note, unlike the FixedArray passed to ResolveModuleCallback and
392
+ * returned from ModuleRequest::GetImportAttributes(), this array does not
393
+ * contain the source Locations of the attributes.
394
+ *
395
+ * The Promise returned from this function is forwarded to userland
396
+ * JavaScript. The embedder must resolve this promise according to the phase
397
+ * requested:
398
+ * - For ModuleImportPhase::kSource, the promise must be resolved with a
399
+ * compiled ModuleSource object, or rejected with a SyntaxError if the
400
+ * module does not support source representation.
401
+ * - For ModuleImportPhase::kEvaluation, the promise must be resolved with a
402
+ * ModuleNamespace object of a module that has been compiled, instantiated,
403
+ * and evaluated.
404
+ *
405
+ * In case of an exception, the embedder must reject this promise with the
406
+ * exception. If the promise creation itself fails (e.g. due to stack
407
+ * overflow), the embedder must propagate that exception by returning an empty
408
+ * MaybeLocal.
409
+ *
410
+ * This callback is still experimental and is only invoked for source phase
411
+ * imports.
412
+ */
413
+ using HostImportModuleWithPhaseDynamicallyCallback = MaybeLocal<Promise> (*)(
414
+ Local<Context> context, Local<Data> host_defined_options,
415
+ Local<Value> resource_name, Local<String> specifier,
416
+ ModuleImportPhase phase, Local<FixedArray> import_attributes);
380
417
 
381
418
  /**
382
419
  * Callback for requesting a compile hint for a function from the embedder. The
@@ -413,6 +450,14 @@ using HostInitializeImportMetaObjectCallback = void (*)(Local<Context> context,
413
450
  using HostCreateShadowRealmContextCallback =
414
451
  MaybeLocal<Context> (*)(Local<Context> initiator_context);
415
452
 
453
+ /**
454
+ * IsJSApiWrapperNativeErrorCallback is called on an JSApiWrapper object to
455
+ * determine if Error.isError should return true or false. For instance, in an
456
+ * HTML embedder, DOMExceptions return true when passed to Error.isError.
457
+ */
458
+ using IsJSApiWrapperNativeErrorCallback = bool (*)(Isolate* isolate,
459
+ Local<Object> obj);
460
+
416
461
  /**
417
462
  * PrepareStackTraceCallback is called when the stack property of an error is
418
463
  * first accessed. The return value will be used as the stack value. If this
@@ -453,14 +498,26 @@ using PrepareStackTraceCallback = MaybeLocal<Value> (*)(Local<Context> context,
453
498
  * with a list of regular expressions that should match the document URL
454
499
  * in order to enable ETW tracing:
455
500
  * {
456
- * "version": "1.0",
501
+ * "version": "2.0",
457
502
  * "filtered_urls": [
458
503
  * "https:\/\/.*\.chromium\.org\/.*", "https://v8.dev/";, "..."
459
- * ]
504
+ * ],
505
+ * "trace_interpreter_frames": true
460
506
  * }
461
507
  */
508
+
462
509
  using FilterETWSessionByURLCallback =
463
510
  bool (*)(Local<Context> context, const std::string& etw_filter_payload);
511
+
512
+ struct FilterETWSessionByURLResult {
513
+ // If true, enable ETW tracing for the current isolate.
514
+ bool enable_etw_tracing;
515
+
516
+ // If true, also enables ETW tracing for interpreter stack frames.
517
+ bool trace_interpreter_frames;
518
+ };
519
+ using FilterETWSessionByURL2Callback = FilterETWSessionByURLResult (*)(
520
+ Local<Context> context, const std::string& etw_filter_payload);
464
521
  #endif // V8_OS_WIN
465
522
 
466
523
  } // namespace v8
@@ -8,6 +8,8 @@
8
8
  #include <stddef.h>
9
9
  #include <stdint.h>
10
10
 
11
+ #include <functional>
12
+
11
13
  #include "v8-local-handle.h" // NOLINT(build/include_directory)
12
14
  #include "v8-object.h" // NOLINT(build/include_directory)
13
15
  #include "v8config.h" // NOLINT(build/include_directory)
@@ -43,6 +45,58 @@ class V8_EXPORT Array : public Object {
43
45
  return static_cast<Array*>(value);
44
46
  }
45
47
 
48
+ /**
49
+ * Creates a JavaScript array from a provided callback.
50
+ *
51
+ * \param context The v8::Context to create the array in.
52
+ * \param length The length of the array to be created.
53
+ * \param next_value_callback The callback that is invoked to retrieve
54
+ * elements for the array. The embedder can signal that the array
55
+ * initialization should be aborted by throwing an exception and returning
56
+ * an empty MaybeLocal.
57
+ * \returns The v8::Array if all elements were constructed successfully and an
58
+ * empty MaybeLocal otherwise.
59
+ */
60
+ static MaybeLocal<Array> New(
61
+ Local<Context> context, size_t length,
62
+ std::function<MaybeLocal<v8::Value>()> next_value_callback);
63
+
64
+ enum class CallbackResult {
65
+ kException,
66
+ kBreak,
67
+ kContinue,
68
+ };
69
+ using IterationCallback = CallbackResult (*)(uint32_t index,
70
+ Local<Value> element,
71
+ void* data);
72
+
73
+ /**
74
+ * Calls {callback} for every element of this array, passing {callback_data}
75
+ * as its {data} parameter.
76
+ * This function will typically be faster than calling {Get()} repeatedly.
77
+ * As a consequence of being optimized for low overhead, the provided
78
+ * callback must adhere to the following restrictions:
79
+ * - It must not allocate any V8 objects and continue iterating; it may
80
+ * allocate (e.g. an error message/object) and then immediately terminate
81
+ * the iteration.
82
+ * - It must not modify the array being iterated.
83
+ * - It must not call back into V8 (unless it can guarantee that such a
84
+ * call does not violate the above restrictions, which is difficult).
85
+ * - The {Local<Value> element} must not "escape", i.e. must not be assigned
86
+ * to any other {Local}. Creating a {Global} from it, or updating a
87
+ * v8::TypecheckWitness with it, is safe.
88
+ * These restrictions may be lifted in the future if use cases arise that
89
+ * justify a slower but more robust implementation.
90
+ *
91
+ * Returns {Nothing} on exception; use a {TryCatch} to catch and handle this
92
+ * exception.
93
+ * When the {callback} returns {kException}, iteration is terminated
94
+ * immediately, returning {Nothing}. By returning {kBreak}, the callback
95
+ * can request non-exceptional early termination of the iteration.
96
+ */
97
+ Maybe<void> Iterate(Local<Context> context, IterationCallback callback,
98
+ void* callback_data);
99
+
46
100
  private:
47
101
  Array();
48
102
  static void CheckCast(Value* obj);