libv8-node 22.7.0.4-aarch64-linux → 24.1.0.0-aarch64-linux

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/aarch64-linux/libv8/obj/libv8_monolith.a +0 -0
  4. data/vendor/v8/include/cppgc/allocation.h +11 -13
  5. data/vendor/v8/include/cppgc/default-platform.h +3 -2
  6. data/vendor/v8/include/cppgc/garbage-collected.h +8 -0
  7. data/vendor/v8/include/cppgc/heap-consistency.h +1 -1
  8. data/vendor/v8/include/cppgc/heap-statistics.h +2 -0
  9. data/vendor/v8/include/cppgc/internal/api-constants.h +2 -14
  10. data/vendor/v8/include/cppgc/internal/base-page-handle.h +2 -4
  11. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +0 -4
  12. data/vendor/v8/include/cppgc/internal/caged-heap.h +0 -4
  13. data/vendor/v8/include/cppgc/internal/compiler-specific.h +9 -1
  14. data/vendor/v8/include/cppgc/internal/conditional-stack-allocated.h +41 -0
  15. data/vendor/v8/include/cppgc/internal/gc-info.h +12 -10
  16. data/vendor/v8/include/cppgc/internal/logging.h +3 -3
  17. data/vendor/v8/include/cppgc/internal/member-storage.h +69 -20
  18. data/vendor/v8/include/cppgc/internal/name-trait.h +5 -1
  19. data/vendor/v8/include/cppgc/internal/persistent-node.h +8 -3
  20. data/vendor/v8/include/cppgc/internal/pointer-policies.h +48 -11
  21. data/vendor/v8/include/cppgc/macros.h +21 -0
  22. data/vendor/v8/include/cppgc/member.h +70 -36
  23. data/vendor/v8/include/cppgc/name-provider.h +10 -0
  24. data/vendor/v8/include/cppgc/platform.h +11 -0
  25. data/vendor/v8/include/cppgc/type-traits.h +1 -0
  26. data/vendor/v8/include/cppgc/visitor.h +25 -1
  27. data/vendor/v8/include/libplatform/libplatform-export.h +2 -2
  28. data/vendor/v8/include/libplatform/v8-tracing.h +0 -1
  29. data/vendor/v8/include/v8-array-buffer.h +143 -46
  30. data/vendor/v8/include/v8-callbacks.h +94 -31
  31. data/vendor/v8/include/v8-context.h +48 -15
  32. data/vendor/v8/include/v8-cppgc.h +5 -56
  33. data/vendor/v8/include/v8-data.h +5 -0
  34. data/vendor/v8/include/v8-date.h +9 -0
  35. data/vendor/v8/include/v8-debug.h +11 -0
  36. data/vendor/v8/include/v8-embedder-heap.h +1 -29
  37. data/vendor/v8/include/v8-exception.h +72 -0
  38. data/vendor/v8/include/v8-external-memory-accounter.h +60 -0
  39. data/vendor/v8/include/v8-fast-api-calls.h +41 -206
  40. data/vendor/v8/include/v8-function-callback.h +190 -78
  41. data/vendor/v8/include/v8-function.h +11 -3
  42. data/vendor/v8/include/v8-handle-base.h +20 -2
  43. data/vendor/v8/include/v8-initialization.h +26 -1
  44. data/vendor/v8/include/v8-inspector.h +10 -3
  45. data/vendor/v8/include/v8-internal.h +638 -315
  46. data/vendor/v8/include/v8-isolate.h +275 -189
  47. data/vendor/v8/include/v8-local-handle.h +69 -42
  48. data/vendor/v8/include/v8-maybe.h +2 -1
  49. data/vendor/v8/include/v8-memory-span.h +149 -24
  50. data/vendor/v8/include/v8-message.h +9 -22
  51. data/vendor/v8/include/v8-metrics.h +14 -0
  52. data/vendor/v8/include/v8-microtask-queue.h +0 -5
  53. data/vendor/v8/include/v8-object.h +291 -37
  54. data/vendor/v8/include/v8-persistent-handle.h +17 -36
  55. data/vendor/v8/include/v8-platform.h +66 -45
  56. data/vendor/v8/include/v8-primitive.h +221 -5
  57. data/vendor/v8/include/v8-profiler.h +51 -2
  58. data/vendor/v8/include/v8-promise.h +2 -2
  59. data/vendor/v8/include/v8-proxy.h +0 -1
  60. data/vendor/v8/include/v8-regexp.h +0 -1
  61. data/vendor/v8/include/v8-sandbox.h +173 -0
  62. data/vendor/v8/include/v8-script.h +65 -17
  63. data/vendor/v8/include/v8-snapshot.h +38 -2
  64. data/vendor/v8/include/v8-source-location.h +6 -1
  65. data/vendor/v8/include/v8-template.h +111 -263
  66. data/vendor/v8/include/v8-trace-categories.h +23 -0
  67. data/vendor/v8/include/v8-traced-handle.h +20 -32
  68. data/vendor/v8/include/v8-typed-array.h +6 -10
  69. data/vendor/v8/include/v8-unwinder-state.h +2 -3
  70. data/vendor/v8/include/v8-unwinder.h +2 -1
  71. data/vendor/v8/include/v8-util.h +1 -117
  72. data/vendor/v8/include/v8-value-serializer-version.h +3 -3
  73. data/vendor/v8/include/v8-value.h +21 -2
  74. data/vendor/v8/include/v8-version.h +4 -4
  75. data/vendor/v8/include/v8-wasm.h +27 -0
  76. data/vendor/v8/include/v8-weak-callback-info.h +20 -12
  77. data/vendor/v8/include/v8.h +3 -3
  78. data/vendor/v8/include/v8config.h +83 -45
  79. metadata +6 -3
  80. 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)
191
197
  /**
192
198
  * Convenience allocator.
193
199
  *
194
200
  * When the sandbox is enabled, this allocator will allocate its backing
195
- * memory inside the sandbox. Otherwise, it will rely on malloc/free.
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
+
211
+ /**
212
+ * Convenience allocator.
213
+ *
214
+ * When the sandbox is enabled, this allocator will allocate its backing
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();
@@ -337,16 +384,29 @@ class V8_EXPORT ArrayBuffer : public Object {
337
384
  return static_cast<ArrayBuffer*>(value);
338
385
  }
339
386
 
340
- static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
341
- 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
342
401
 
343
402
  private:
344
403
  ArrayBuffer();
345
404
  static void CheckCast(Value* obj);
405
+ friend class TypedArray;
346
406
  };
347
407
 
348
408
  #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
349
- // The number of required internal fields can be defined by embedder.
409
+ // Defined using gn arg `v8_array_buffer_view_internal_field_count`.
350
410
  #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
351
411
  #endif
352
412
 
@@ -380,6 +440,16 @@ class V8_EXPORT ArrayBufferView : public Object {
380
440
  */
381
441
  size_t CopyContents(void* dest, size_t byte_length);
382
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
+
383
453
  /**
384
454
  * Returns true if ArrayBufferView's backing ArrayBuffer has already been
385
455
  * allocated.
@@ -393,10 +463,9 @@ class V8_EXPORT ArrayBufferView : public Object {
393
463
  return static_cast<ArrayBufferView*>(value);
394
464
  }
395
465
 
396
- static const int kInternalFieldCount =
397
- V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
398
- static const int kEmbedderFieldCount =
466
+ static constexpr int kInternalFieldCount =
399
467
  V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
468
+ static const int kEmbedderFieldCount = kInternalFieldCount;
400
469
 
401
470
  private:
402
471
  ArrayBufferView();
@@ -440,12 +509,27 @@ class V8_EXPORT SharedArrayBuffer : public Object {
440
509
  size_t MaxByteLength() const;
441
510
 
442
511
  /**
443
- * Create a new SharedArrayBuffer. Allocate |byte_length| bytes.
444
- * Allocated memory will be owned by a created SharedArrayBuffer and
445
- * will be deallocated when it is garbage-collected,
446
- * 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.
447
528
  */
448
- 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);
449
533
 
450
534
  /**
451
535
  * Create a new SharedArrayBuffer with an existing backing store.
@@ -464,15 +548,27 @@ class V8_EXPORT SharedArrayBuffer : public Object {
464
548
 
465
549
  /**
466
550
  * Returns a new standalone BackingStore that is allocated using the array
467
- * 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
468
553
  * SharedArrayBuffer::New.
469
554
  *
470
555
  * If the allocator returns nullptr, then the function may cause GCs in the
471
- * given isolate and re-try the allocation. If GCs do not help, then the
472
- * 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.
473
564
  */
474
- static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate,
475
- 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
+
476
572
  /**
477
573
  * Returns a new standalone BackingStore that takes over the ownership of
478
574
  * the given buffer. The destructor of the BackingStore invokes the given
@@ -506,7 +602,8 @@ class V8_EXPORT SharedArrayBuffer : public Object {
506
602
  return static_cast<SharedArrayBuffer*>(value);
507
603
  }
508
604
 
509
- static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
605
+ static constexpr int kInternalFieldCount =
606
+ V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
510
607
 
511
608
  private:
512
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
 
@@ -341,6 +335,14 @@ using JavaScriptCompileHintsMagicEnabledCallback =
341
335
  // --- Callback for checking if WebAssembly JSPI is enabled ---
342
336
  using WasmJSPIEnabledCallback = bool (*)(Local<Context> context);
343
337
 
338
+ /**
339
+ * Import phases in import requests.
340
+ */
341
+ enum class ModuleImportPhase {
342
+ kSource,
343
+ kEvaluation,
344
+ };
345
+
344
346
  /**
345
347
  * HostImportModuleDynamicallyCallback is called when we
346
348
  * require the embedder to load a module. This is used as part of the dynamic
@@ -354,7 +356,7 @@ using WasmJSPIEnabledCallback = bool (*)(Local<Context> context);
354
356
  * The import_attributes are import attributes for this request in the form:
355
357
  * [key1, value1, key2, value2, ...] where the keys and values are of type
356
358
  * v8::String. Note, unlike the FixedArray passed to ResolveModuleCallback and
357
- * returned from ModuleRequest::GetImportAssertions(), this array does not
359
+ * returned from ModuleRequest::GetImportAttributes(), this array does not
358
360
  * contain the source Locations of the attributes.
359
361
  *
360
362
  * The embedder must compile, instantiate, evaluate the Module, and
@@ -372,6 +374,47 @@ using HostImportModuleDynamicallyCallback = MaybeLocal<Promise> (*)(
372
374
  Local<Value> resource_name, Local<String> specifier,
373
375
  Local<FixedArray> import_attributes);
374
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);
417
+
375
418
  /**
376
419
  * Callback for requesting a compile hint for a function from the embedder. The
377
420
  * first parameter is the position of the function in source code and the second
@@ -407,6 +450,14 @@ using HostInitializeImportMetaObjectCallback = void (*)(Local<Context> context,
407
450
  using HostCreateShadowRealmContextCallback =
408
451
  MaybeLocal<Context> (*)(Local<Context> initiator_context);
409
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
+
410
461
  /**
411
462
  * PrepareStackTraceCallback is called when the stack property of an error is
412
463
  * first accessed. The return value will be used as the stack value. If this
@@ -447,14 +498,26 @@ using PrepareStackTraceCallback = MaybeLocal<Value> (*)(Local<Context> context,
447
498
  * with a list of regular expressions that should match the document URL
448
499
  * in order to enable ETW tracing:
449
500
  * {
450
- * "version": "1.0",
501
+ * "version": "2.0",
451
502
  * "filtered_urls": [
452
503
  * "https:\/\/.*\.chromium\.org\/.*", "https://v8.dev/";, "..."
453
- * ]
504
+ * ],
505
+ * "trace_interpreter_frames": true
454
506
  * }
455
507
  */
508
+
456
509
  using FilterETWSessionByURLCallback =
457
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);
458
521
  #endif // V8_OS_WIN
459
522
 
460
523
  } // namespace v8
@@ -107,6 +107,10 @@ class V8_EXPORT Context : public Data {
107
107
  * configured if the default context snapshot contains no pointer embedder
108
108
  * data, or if no custom startup snapshot is configured in the
109
109
  * v8::CreateParams used to create the isolate.
110
+ *
111
+ * \param api_wrapper_deserializer An optional callback used to deserialize
112
+ * API wrapper objects that was initially set with v8::Object::Wrap() and then
113
+ * serialized using SerializeAPIWrapperCallback.
110
114
  */
111
115
  static Local<Context> New(
112
116
  Isolate* isolate, ExtensionConfiguration* extensions = nullptr,
@@ -116,17 +120,19 @@ class V8_EXPORT Context : public Data {
116
120
  DeserializeInternalFieldsCallback(),
117
121
  MicrotaskQueue* microtask_queue = nullptr,
118
122
  DeserializeContextDataCallback context_data_deserializer =
119
- DeserializeContextDataCallback());
123
+ DeserializeContextDataCallback(),
124
+ DeserializeAPIWrapperCallback api_wrapper_deserializer =
125
+ DeserializeAPIWrapperCallback());
120
126
 
121
127
  /**
122
128
  * Create a new context from a (non-default) context snapshot. There
123
129
  * is no way to provide a global object template since we do not create
124
130
  * a new global object from template, but we can reuse a global object.
125
131
  *
126
- * \param isolate See v8::Context::New.
132
+ * \param isolate See v8::Context::New().
127
133
  *
128
134
  * \param context_snapshot_index The index of the context snapshot to
129
- * deserialize from. Use v8::Context::New for the default snapshot.
135
+ * deserialize from. Use v8::Context::New() for the default snapshot.
130
136
  *
131
137
  * \param internal_fields_deserializer An optional callback used
132
138
  * to deserialize fields set by
@@ -136,19 +142,23 @@ class V8_EXPORT Context : public Data {
136
142
  * pointer fields in the default context snapshot or if no startup
137
143
  * snapshot is configured when the isolate is created.
138
144
  *
139
- * \param extensions See v8::Context::New.
145
+ * \param extensions See v8::Context::New().
140
146
  *
141
- * \param global_object See v8::Context::New.
147
+ * \param global_object See v8::Context::New().
142
148
  *
143
149
  * \param internal_fields_deserializer Similar to
144
- * internal_fields_deserializer in v8::Context::New but applies to
150
+ * internal_fields_deserializer in v8::Context::New() but applies to
145
151
  * the context specified by the context_snapshot_index.
146
152
  *
147
- * \param microtask_queue See v8::Context::New.
153
+ * \param microtask_queue See v8::Context::New().
148
154
  *
149
155
  * \param context_data_deserializer Similar to
150
- * context_data_deserializer in v8::Context::New but applies to
156
+ * context_data_deserializer in v8::Context::New() but applies to
151
157
  * the context specified by the context_snapshot_index.
158
+ *
159
+ *\param api_wrapper_deserializer Similar to api_wrapper_deserializer in
160
+ * v8::Context::New() but applies to the context specified by the
161
+ * context_snapshot_index.
152
162
  */
153
163
  static MaybeLocal<Context> FromSnapshot(
154
164
  Isolate* isolate, size_t context_snapshot_index,
@@ -158,7 +168,9 @@ class V8_EXPORT Context : public Data {
158
168
  MaybeLocal<Value> global_object = MaybeLocal<Value>(),
159
169
  MicrotaskQueue* microtask_queue = nullptr,
160
170
  DeserializeContextDataCallback context_data_deserializer =
161
- DeserializeContextDataCallback());
171
+ DeserializeContextDataCallback(),
172
+ DeserializeAPIWrapperCallback api_wrapper_deserializer =
173
+ DeserializeAPIWrapperCallback());
162
174
 
163
175
  /**
164
176
  * Returns an global object that isn't backed by an actual context.
@@ -290,6 +302,8 @@ class V8_EXPORT Context : public Data {
290
302
  * SetAlignedPointerInEmbedderData with the same index. Note that index 0
291
303
  * currently has a special meaning for Chrome's debugger.
292
304
  */
305
+ V8_INLINE void* GetAlignedPointerFromEmbedderData(Isolate* isolate,
306
+ int index);
293
307
  V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
294
308
 
295
309
  /**
@@ -306,7 +320,7 @@ class V8_EXPORT Context : public Data {
306
320
  * 'Function' constructor are used an exception will be thrown.
307
321
  *
308
322
  * If code generation from strings is not allowed the
309
- * V8::AllowCodeGenerationFromStrings callback will be invoked if
323
+ * V8::ModifyCodeGenerationFromStringsCallback callback will be invoked if
310
324
  * set before blocking the call to 'eval' or the 'Function'
311
325
  * constructor. If that callback returns true, the call will be
312
326
  * allowed, otherwise an exception will be thrown. If no callback is
@@ -413,7 +427,8 @@ class V8_EXPORT Context : public Data {
413
427
 
414
428
  static void CheckCast(Data* obj);
415
429
 
416
- internal::Address* GetDataFromSnapshotOnce(size_t index);
430
+ internal::ValueHelper::InternalRepresentationType GetDataFromSnapshotOnce(
431
+ size_t index);
417
432
  Local<Value> SlowGetEmbedderData(int index);
418
433
  void* SlowGetAlignedPointerFromEmbedderData(int index);
419
434
  };
@@ -444,6 +459,24 @@ Local<Value> Context::GetEmbedderData(int index) {
444
459
  #endif
445
460
  }
446
461
 
462
+ void* Context::GetAlignedPointerFromEmbedderData(Isolate* isolate, int index) {
463
+ #if !defined(V8_ENABLE_CHECKS)
464
+ using A = internal::Address;
465
+ using I = internal::Internals;
466
+ A ctx = internal::ValueHelper::ValueAsAddress(this);
467
+ A embedder_data =
468
+ I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
469
+ int value_offset = I::kEmbedderDataArrayHeaderSize +
470
+ (I::kEmbedderDataSlotSize * index) +
471
+ I::kEmbedderDataSlotExternalPointerOffset;
472
+ return reinterpret_cast<void*>(
473
+ I::ReadExternalPointerField<internal::kEmbedderDataSlotPayloadTag>(
474
+ isolate, embedder_data, value_offset));
475
+ #else
476
+ return SlowGetAlignedPointerFromEmbedderData(index);
477
+ #endif
478
+ }
479
+
447
480
  void* Context::GetAlignedPointerFromEmbedderData(int index) {
448
481
  #if !defined(V8_ENABLE_CHECKS)
449
482
  using A = internal::Address;
@@ -465,10 +498,10 @@ void* Context::GetAlignedPointerFromEmbedderData(int index) {
465
498
 
466
499
  template <class T>
467
500
  MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) {
468
- if (auto slot = GetDataFromSnapshotOnce(index); slot) {
469
- internal::PerformCastCheck(
470
- internal::ValueHelper::SlotAsValue<T, false>(slot));
471
- return Local<T>::FromSlot(slot);
501
+ if (auto repr = GetDataFromSnapshotOnce(index);
502
+ repr != internal::ValueHelper::kEmpty) {
503
+ internal::PerformCastCheck(internal::ValueHelper::ReprAsValue<T>(repr));
504
+ return Local<T>::FromRepr(repr);
472
505
  }
473
506
  return {};
474
507
  }