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
@@ -16,6 +16,7 @@
16
16
  #include "v8-data.h" // NOLINT(build/include_directory)
17
17
  #include "v8-local-handle.h" // NOLINT(build/include_directory)
18
18
  #include "v8-maybe.h" // NOLINT(build/include_directory)
19
+ #include "v8-memory-span.h" // NOLINT(build/include_directory)
19
20
  #include "v8-message.h" // NOLINT(build/include_directory)
20
21
  #include "v8config.h" // NOLINT(build/include_directory)
21
22
 
@@ -128,6 +129,11 @@ class V8_EXPORT ModuleRequest : public Data {
128
129
  */
129
130
  Local<String> GetSpecifier() const;
130
131
 
132
+ /**
133
+ * Returns the module import phase for this ModuleRequest.
134
+ */
135
+ ModuleImportPhase GetPhase() const;
136
+
131
137
  /**
132
138
  * Returns the source code offset of this module request.
133
139
  * Use Module::SourceOffsetToLocation to convert this to line/column numbers.
@@ -135,19 +141,24 @@ class V8_EXPORT ModuleRequest : public Data {
135
141
  int GetSourceOffset() const;
136
142
 
137
143
  /**
138
- * Contains the import assertions for this request in the form:
144
+ * Contains the import attributes for this request in the form:
139
145
  * [key1, value1, source_offset1, key2, value2, source_offset2, ...].
140
146
  * The keys and values are of type v8::String, and the source offsets are of
141
147
  * type Int32. Use Module::SourceOffsetToLocation to convert the source
142
148
  * offsets to Locations with line/column numbers.
143
149
  *
144
- * All assertions present in the module request will be supplied in this
150
+ * All attributes present in the module request will be supplied in this
145
151
  * list, regardless of whether they are supported by the host. Per
146
152
  * https://tc39.es/proposal-import-attributes/#sec-hostgetsupportedimportattributes,
147
- * hosts are expected to throw for assertions that they do not support (as
153
+ * hosts are expected to throw for attributes that they do not support (as
148
154
  * opposed to, for example, ignoring them).
149
155
  */
150
- Local<FixedArray> GetImportAssertions() const;
156
+ Local<FixedArray> GetImportAttributes() const;
157
+
158
+ V8_DEPRECATED("Use GetImportAttributes instead")
159
+ Local<FixedArray> GetImportAssertions() const {
160
+ return GetImportAttributes();
161
+ }
151
162
 
152
163
  V8_INLINE static ModuleRequest* Cast(Data* data);
153
164
 
@@ -204,7 +215,10 @@ class V8_EXPORT Module : public Data {
204
215
 
205
216
  using ResolveModuleCallback = MaybeLocal<Module> (*)(
206
217
  Local<Context> context, Local<String> specifier,
207
- Local<FixedArray> import_assertions, Local<Module> referrer);
218
+ Local<FixedArray> import_attributes, Local<Module> referrer);
219
+ using ResolveSourceCallback = MaybeLocal<Object> (*)(
220
+ Local<Context> context, Local<String> specifier,
221
+ Local<FixedArray> import_attributes, Local<Module> referrer);
208
222
 
209
223
  /**
210
224
  * Instantiates the module and its dependencies.
@@ -214,7 +228,8 @@ class V8_EXPORT Module : public Data {
214
228
  * exception is propagated.)
215
229
  */
216
230
  V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(
217
- Local<Context> context, ResolveModuleCallback callback);
231
+ Local<Context> context, ResolveModuleCallback module_callback,
232
+ ResolveSourceCallback source_callback = nullptr);
218
233
 
219
234
  /**
220
235
  * Evaluates the module and its dependencies.
@@ -258,6 +273,13 @@ class V8_EXPORT Module : public Data {
258
273
  */
259
274
  bool IsGraphAsync() const;
260
275
 
276
+ /**
277
+ * Returns whether this module is individually asynchronous (for example,
278
+ * if it's a Source Text Module Record containing a top-level await).
279
+ * See [[HasTLA]] in https://tc39.es/ecma262/#sec-cyclic-module-records
280
+ */
281
+ bool HasTopLevelAwait() const;
282
+
261
283
  /**
262
284
  * Returns whether the module is a SourceTextModule.
263
285
  */
@@ -287,7 +309,7 @@ class V8_EXPORT Module : public Data {
287
309
  */
288
310
  static Local<Module> CreateSyntheticModule(
289
311
  Isolate* isolate, Local<String> module_name,
290
- const std::vector<Local<String>>& export_names,
312
+ const MemorySpan<const Local<String>>& export_names,
291
313
  SyntheticModuleEvaluationSteps evaluation_steps);
292
314
 
293
315
  /**
@@ -303,12 +325,12 @@ class V8_EXPORT Module : public Data {
303
325
  /**
304
326
  * Search the modules requested directly or indirectly by the module for
305
327
  * any top-level await that has not yet resolved. If there is any, the
306
- * returned vector contains a tuple of the unresolved module and a message
307
- * with the pending top-level await.
328
+ * returned pair of vectors (of equal size) contain the unresolved module
329
+ * and corresponding message with the pending top-level await.
308
330
  * An embedder may call this before exiting to improve error messages.
309
331
  */
310
- std::vector<std::tuple<Local<Module>, Local<Message>>>
311
- GetStalledTopLevelAwaitMessage(Isolate* isolate);
332
+ std::pair<LocalVector<Module>, LocalVector<Message>>
333
+ GetStalledTopLevelAwaitMessages(Isolate* isolate);
312
334
 
313
335
  V8_INLINE static Module* Cast(Data* data);
314
336
 
@@ -316,6 +338,14 @@ class V8_EXPORT Module : public Data {
316
338
  static void CheckCast(Data* obj);
317
339
  };
318
340
 
341
+ class V8_EXPORT CompileHintsCollector : public Data {
342
+ public:
343
+ /**
344
+ * Returns the positions of lazy functions which were compiled and executed.
345
+ */
346
+ std::vector<int> GetCompileHints(Isolate* isolate) const;
347
+ };
348
+
319
349
  /**
320
350
  * A compiled JavaScript script, tied to a Context which was active when the
321
351
  * script was compiled.
@@ -353,7 +383,15 @@ class V8_EXPORT Script : public Data {
353
383
  * If the script was compiled, returns the positions of lazy functions which
354
384
  * were eventually compiled and executed.
355
385
  */
386
+ V8_DEPRECATE_SOON("Use GetCompileHintsCollector instead")
356
387
  std::vector<int> GetProducedCompileHints() const;
388
+
389
+ /**
390
+ * Get a compile hints collector object which we can use later for retrieving
391
+ * compile hints (= positions of lazy functions which were compiled and
392
+ * executed).
393
+ */
394
+ Local<CompileHintsCollector> GetCompileHintsCollector() const;
357
395
  };
358
396
 
359
397
  enum class ScriptType { kClassic, kModule };
@@ -421,6 +459,33 @@ class V8_EXPORT ScriptCompiler {
421
459
  CachedData& operator=(const CachedData&) = delete;
422
460
  };
423
461
 
462
+ enum class InMemoryCacheResult {
463
+ // V8 did not attempt to find this script in its in-memory cache.
464
+ kNotAttempted,
465
+
466
+ // V8 found a previously compiled copy of this script in its in-memory
467
+ // cache. Any data generated by a streaming compilation or background
468
+ // deserialization was abandoned.
469
+ kHit,
470
+
471
+ // V8 didn't have any previously compiled data for this script.
472
+ kMiss,
473
+
474
+ // V8 had some previously compiled data for an identical script, but the
475
+ // data was incomplete.
476
+ kPartial,
477
+ };
478
+
479
+ // Details about what happened during a compilation.
480
+ struct CompilationDetails {
481
+ InMemoryCacheResult in_memory_cache_result =
482
+ InMemoryCacheResult::kNotAttempted;
483
+
484
+ static constexpr int64_t kTimeNotMeasured = -1;
485
+ int64_t foreground_time_in_microseconds = kTimeNotMeasured;
486
+ int64_t background_time_in_microseconds = kTimeNotMeasured;
487
+ };
488
+
424
489
  /**
425
490
  * Source code which can be then compiled to a UnboundScript or Script.
426
491
  */
@@ -446,6 +511,8 @@ class V8_EXPORT ScriptCompiler {
446
511
 
447
512
  V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
448
513
 
514
+ V8_INLINE const CompilationDetails& GetCompilationDetails() const;
515
+
449
516
  private:
450
517
  friend class ScriptCompiler;
451
518
 
@@ -453,8 +520,8 @@ class V8_EXPORT ScriptCompiler {
453
520
 
454
521
  // Origin information
455
522
  Local<Value> resource_name;
456
- int resource_line_offset;
457
- int resource_column_offset;
523
+ int resource_line_offset = -1;
524
+ int resource_column_offset = -1;
458
525
  ScriptOriginOptions resource_options;
459
526
  Local<Value> source_map_url;
460
527
  Local<Data> host_defined_options;
@@ -468,6 +535,10 @@ class V8_EXPORT ScriptCompiler {
468
535
  // For requesting compile hints from the embedder.
469
536
  CompileHintCallback compile_hint_callback = nullptr;
470
537
  void* compile_hint_callback_data = nullptr;
538
+
539
+ // V8 writes this data and never reads it. It exists only to be informative
540
+ // to the embedder.
541
+ CompilationDetails compilation_details;
471
542
  };
472
543
 
473
544
  /**
@@ -522,8 +593,14 @@ class V8_EXPORT ScriptCompiler {
522
593
  StreamedSource(const StreamedSource&) = delete;
523
594
  StreamedSource& operator=(const StreamedSource&) = delete;
524
595
 
596
+ CompilationDetails& compilation_details() { return compilation_details_; }
597
+
525
598
  private:
526
599
  std::unique_ptr<internal::ScriptStreamingData> impl_;
600
+
601
+ // V8 writes this data and never reads it. It exists only to be informative
602
+ // to the embedder.
603
+ CompilationDetails compilation_details_;
527
604
  };
528
605
 
529
606
  /**
@@ -595,12 +672,34 @@ class V8_EXPORT ScriptCompiler {
595
672
 
596
673
  enum CompileOptions {
597
674
  kNoCompileOptions = 0,
598
- kConsumeCodeCache,
599
- kEagerCompile,
600
- kProduceCompileHints,
601
- kConsumeCompileHints
675
+ kConsumeCodeCache = 1 << 0,
676
+ kEagerCompile = 1 << 1,
677
+ kProduceCompileHints = 1 << 2,
678
+ kConsumeCompileHints = 1 << 3,
679
+ kFollowCompileHintsMagicComment = 1 << 4,
680
+ kFollowCompileHintsPerFunctionMagicComment = 1 << 5,
602
681
  };
603
682
 
683
+ static inline bool CompileOptionsIsValid(CompileOptions compile_options) {
684
+ // kConsumeCodeCache is mutually exclusive with all other flag bits.
685
+ if ((compile_options & kConsumeCodeCache) &&
686
+ compile_options != kConsumeCodeCache) {
687
+ return false;
688
+ }
689
+ // kEagerCompile is mutually exclusive with all other flag bits.
690
+ if ((compile_options & kEagerCompile) && compile_options != kEagerCompile) {
691
+ return false;
692
+ }
693
+ // We don't currently support producing and consuming compile hints at the
694
+ // same time.
695
+ constexpr int produce_and_consume = CompileOptions::kProduceCompileHints |
696
+ CompileOptions::kConsumeCompileHints;
697
+ if ((compile_options & produce_and_consume) == produce_and_consume) {
698
+ return false;
699
+ }
700
+ return true;
701
+ }
702
+
604
703
  /**
605
704
  * The reason for which we are not requesting or providing a code cache.
606
705
  */
@@ -619,7 +718,8 @@ class V8_EXPORT ScriptCompiler {
619
718
  kNoCacheBecausePacScript,
620
719
  kNoCacheBecauseInDocumentWrite,
621
720
  kNoCacheBecauseResourceWithNoCacheHandler,
622
- kNoCacheBecauseDeferredProduceCodeCache
721
+ kNoCacheBecauseDeferredProduceCodeCache,
722
+ kNoCacheBecauseStaticCodeCache,
623
723
  };
624
724
 
625
725
  /**
@@ -677,6 +777,8 @@ class V8_EXPORT ScriptCompiler {
677
777
 
678
778
  static ConsumeCodeCacheTask* StartConsumingCodeCache(
679
779
  Isolate* isolate, std::unique_ptr<CachedData> source);
780
+ static ConsumeCodeCacheTask* StartConsumingCodeCacheOnBackground(
781
+ Isolate* isolate, std::unique_ptr<CachedData> source);
680
782
 
681
783
  /**
682
784
  * Compiles a streamed script (bound to current context).
@@ -742,15 +844,6 @@ class V8_EXPORT ScriptCompiler {
742
844
  * It is possible to specify multiple context extensions (obj in the above
743
845
  * example).
744
846
  */
745
- V8_DEPRECATED("Use CompileFunction")
746
- static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
747
- Local<Context> context, Source* source, size_t arguments_count,
748
- Local<String> arguments[], size_t context_extension_count,
749
- Local<Object> context_extensions[],
750
- CompileOptions options = kNoCompileOptions,
751
- NoCacheReason no_cache_reason = kNoCacheNoReason,
752
- Local<ScriptOrModule>* script_or_module_out = nullptr);
753
-
754
847
  static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunction(
755
848
  Local<Context> context, Source* source, size_t arguments_count = 0,
756
849
  Local<String> arguments[] = nullptr, size_t context_extension_count = 0,
@@ -835,6 +928,11 @@ const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const {
835
928
  return resource_options;
836
929
  }
837
930
 
931
+ const ScriptCompiler::CompilationDetails&
932
+ ScriptCompiler::Source::GetCompilationDetails() const {
933
+ return compilation_details;
934
+ }
935
+
838
936
  ModuleRequest* ModuleRequest::Cast(Data* data) {
839
937
  #ifdef V8_ENABLE_CHECKS
840
938
  CheckCast(data);
@@ -6,6 +6,7 @@
6
6
  #define INCLUDE_V8_SNAPSHOT_H_
7
7
 
8
8
  #include "v8-internal.h" // NOLINT(build/include_directory)
9
+ #include "v8-isolate.h" // NOLINT(build/include_directory)
9
10
  #include "v8-local-handle.h" // NOLINT(build/include_directory)
10
11
  #include "v8config.h" // NOLINT(build/include_directory)
11
12
 
@@ -13,6 +14,10 @@ namespace v8 {
13
14
 
14
15
  class Object;
15
16
 
17
+ namespace internal {
18
+ class SnapshotCreatorImpl;
19
+ } // namespace internal
20
+
16
21
  class V8_EXPORT StartupData {
17
22
  public:
18
23
  /**
@@ -33,7 +38,7 @@ class V8_EXPORT StartupData {
33
38
 
34
39
  /**
35
40
  * Callback and supporting data used in SnapshotCreator to implement embedder
36
- * logic to serialize internal fields.
41
+ * logic to serialize internal fields of v8::Objects.
37
42
  * Internal fields that directly reference V8 objects are serialized without
38
43
  * calling this callback. Internal fields that contain aligned pointers are
39
44
  * serialized by this callback if it returns non-zero result. Otherwise it is
@@ -48,13 +53,40 @@ struct SerializeInternalFieldsCallback {
48
53
  CallbackFunction callback;
49
54
  void* data;
50
55
  };
51
- // Note that these fields are called "internal fields" in the API and called
52
- // "embedder fields" within V8.
53
- using SerializeEmbedderFieldsCallback = SerializeInternalFieldsCallback;
56
+
57
+ /**
58
+ * Similar to SerializeInternalFieldsCallback, but works with the embedder data
59
+ * in a v8::Context.
60
+ */
61
+ struct SerializeContextDataCallback {
62
+ using CallbackFunction = StartupData (*)(Local<Context> holder, int index,
63
+ void* data);
64
+ SerializeContextDataCallback(CallbackFunction function = nullptr,
65
+ void* data_arg = nullptr)
66
+ : callback(function), data(data_arg) {}
67
+ CallbackFunction callback;
68
+ void* data;
69
+ };
70
+
71
+ /**
72
+ * Similar to `SerializeInternalFieldsCallback`, but is used exclusively to
73
+ * serialize API wrappers. The pointers for API wrappers always point into the
74
+ * CppHeap.
75
+ */
76
+ struct SerializeAPIWrapperCallback {
77
+ using CallbackFunction = StartupData (*)(Local<Object> holder,
78
+ void* cpp_heap_pointer, void* data);
79
+ explicit SerializeAPIWrapperCallback(CallbackFunction function = nullptr,
80
+ void* data = nullptr)
81
+ : callback(function), data(data) {}
82
+
83
+ CallbackFunction callback;
84
+ void* data;
85
+ };
54
86
 
55
87
  /**
56
88
  * Callback and supporting data used to implement embedder logic to deserialize
57
- * internal fields.
89
+ * internal fields of v8::Objects.
58
90
  */
59
91
  struct DeserializeInternalFieldsCallback {
60
92
  using CallbackFunction = void (*)(Local<Object> holder, int index,
@@ -62,12 +94,35 @@ struct DeserializeInternalFieldsCallback {
62
94
  DeserializeInternalFieldsCallback(CallbackFunction function = nullptr,
63
95
  void* data_arg = nullptr)
64
96
  : callback(function), data(data_arg) {}
65
- void (*callback)(Local<Object> holder, int index, StartupData payload,
66
- void* data);
97
+
98
+ CallbackFunction callback;
67
99
  void* data;
68
100
  };
69
101
 
70
- using DeserializeEmbedderFieldsCallback = DeserializeInternalFieldsCallback;
102
+ /**
103
+ * Similar to DeserializeInternalFieldsCallback, but works with the embedder
104
+ * data in a v8::Context.
105
+ */
106
+ struct DeserializeContextDataCallback {
107
+ using CallbackFunction = void (*)(Local<Context> holder, int index,
108
+ StartupData payload, void* data);
109
+ DeserializeContextDataCallback(CallbackFunction function = nullptr,
110
+ void* data_arg = nullptr)
111
+ : callback(function), data(data_arg) {}
112
+ CallbackFunction callback;
113
+ void* data;
114
+ };
115
+
116
+ struct DeserializeAPIWrapperCallback {
117
+ using CallbackFunction = void (*)(Local<Object> holder, StartupData payload,
118
+ void* data);
119
+ explicit DeserializeAPIWrapperCallback(CallbackFunction function = nullptr,
120
+ void* data = nullptr)
121
+ : callback(function), data(data) {}
122
+
123
+ CallbackFunction callback;
124
+ void* data;
125
+ };
71
126
 
72
127
  /**
73
128
  * Helper class to create a snapshot data blob.
@@ -91,10 +146,11 @@ class V8_EXPORT SnapshotCreator {
91
146
  * \param owns_isolate whether this SnapshotCreator should call
92
147
  * v8::Isolate::Dispose() during its destructor.
93
148
  */
94
- SnapshotCreator(Isolate* isolate,
95
- const intptr_t* external_references = nullptr,
96
- const StartupData* existing_blob = nullptr,
97
- bool owns_isolate = true);
149
+ V8_DEPRECATE_SOON("Use the version that passes CreateParams instead.")
150
+ explicit SnapshotCreator(Isolate* isolate,
151
+ const intptr_t* external_references = nullptr,
152
+ const StartupData* existing_blob = nullptr,
153
+ bool owns_isolate = true);
98
154
 
99
155
  /**
100
156
  * Create and enter an isolate, and set it up for serialization.
@@ -104,8 +160,35 @@ class V8_EXPORT SnapshotCreator {
104
160
  * \param external_references a null-terminated array of external references
105
161
  * that must be equivalent to CreateParams::external_references.
106
162
  */
107
- SnapshotCreator(const intptr_t* external_references = nullptr,
108
- const StartupData* existing_blob = nullptr);
163
+ V8_DEPRECATE_SOON("Use the version that passes CreateParams instead.")
164
+ explicit SnapshotCreator(const intptr_t* external_references = nullptr,
165
+ const StartupData* existing_blob = nullptr);
166
+
167
+ /**
168
+ * Creates an Isolate for serialization and enters it. The creator fully owns
169
+ * the Isolate and will invoke `v8::Isolate::Dispose()` during destruction.
170
+ *
171
+ * \param params The parameters to initialize the Isolate for. Details:
172
+ * - `params.external_references` are expected to be a
173
+ * null-terminated array of external references.
174
+ * - `params.existing_blob` is an optional snapshot blob from
175
+ * which can be used to initialize the new blob.
176
+ */
177
+ explicit SnapshotCreator(const v8::Isolate::CreateParams& params);
178
+
179
+ /**
180
+ * Initializes an Isolate for serialization and enters it. The creator does
181
+ * not own the Isolate but merely initialize it properly.
182
+ *
183
+ * \param isolate The isolate that was allocated by `Isolate::Allocate()~.
184
+ * \param params The parameters to initialize the Isolate for. Details:
185
+ * - `params.external_references` are expected to be a
186
+ * null-terminated array of external references.
187
+ * - `params.existing_blob` is an optional snapshot blob from
188
+ * which can be used to initialize the new blob.
189
+ */
190
+ SnapshotCreator(v8::Isolate* isolate,
191
+ const v8::Isolate::CreateParams& params);
109
192
 
110
193
  /**
111
194
  * Destroy the snapshot creator, and exit and dispose of the Isolate
@@ -123,23 +206,46 @@ class V8_EXPORT SnapshotCreator {
123
206
  * The snapshot will not contain the global proxy, and we expect one or a
124
207
  * global object template to create one, to be provided upon deserialization.
125
208
  *
126
- * \param callback optional callback to serialize internal fields.
209
+ * \param internal_fields_serializer An optional callback used to serialize
210
+ * internal pointer fields set by
211
+ * v8::Object::SetAlignedPointerInInternalField().
212
+ *
213
+ * \param context_data_serializer An optional callback used to serialize
214
+ * context embedder data set by
215
+ * v8::Context::SetAlignedPointerInEmbedderData().
216
+ *
217
+ * \param api_wrapper_serializer An optional callback used to serialize API
218
+ * wrapper references set via `v8::Object::Wrap()`.
127
219
  */
128
- void SetDefaultContext(Local<Context> context,
129
- SerializeInternalFieldsCallback callback =
130
- SerializeInternalFieldsCallback());
220
+ void SetDefaultContext(
221
+ Local<Context> context,
222
+ SerializeInternalFieldsCallback internal_fields_serializer =
223
+ SerializeInternalFieldsCallback(),
224
+ SerializeContextDataCallback context_data_serializer =
225
+ SerializeContextDataCallback(),
226
+ SerializeAPIWrapperCallback api_wrapper_serializer =
227
+ SerializeAPIWrapperCallback());
131
228
 
132
229
  /**
133
230
  * Add additional context to be included in the snapshot blob.
134
231
  * The snapshot will include the global proxy.
135
232
  *
136
- * \param callback optional callback to serialize internal fields.
233
+ * \param internal_fields_serializer Similar to internal_fields_serializer
234
+ * in SetDefaultContext() but only applies to the context being added.
235
+ *
236
+ * \param context_data_serializer Similar to context_data_serializer
237
+ * in SetDefaultContext() but only applies to the context being added.
137
238
  *
138
- * \returns the index of the context in the snapshot blob.
239
+ * \param api_wrapper_serializer Similar to api_wrapper_serializer
240
+ * in SetDefaultContext() but only applies to the context being added.
139
241
  */
140
242
  size_t AddContext(Local<Context> context,
141
- SerializeInternalFieldsCallback callback =
142
- SerializeInternalFieldsCallback());
243
+ SerializeInternalFieldsCallback internal_fields_serializer =
244
+ SerializeInternalFieldsCallback(),
245
+ SerializeContextDataCallback context_data_serializer =
246
+ SerializeContextDataCallback(),
247
+ SerializeAPIWrapperCallback api_wrapper_serializer =
248
+ SerializeAPIWrapperCallback());
143
249
 
144
250
  /**
145
251
  * Attach arbitrary V8::Data to the context snapshot, which can be retrieved
@@ -177,7 +283,8 @@ class V8_EXPORT SnapshotCreator {
177
283
  size_t AddData(Local<Context> context, internal::Address object);
178
284
  size_t AddData(internal::Address object);
179
285
 
180
- void* data_;
286
+ internal::SnapshotCreatorImpl* impl_;
287
+ friend class internal::SnapshotCreatorImpl;
181
288
  };
182
289
 
183
290
  template <class T>
@@ -76,7 +76,12 @@ class V8_EXPORT SourceLocation final {
76
76
  *
77
77
  * \returns a human-readable string representing source location information.
78
78
  */
79
- std::string ToString() const;
79
+ std::string ToString() const {
80
+ if (!file_) {
81
+ return {};
82
+ }
83
+ return std::string(function_) + "@" + file_ + ":" + std::to_string(line_);
84
+ }
80
85
 
81
86
  private:
82
87
  constexpr SourceLocation(const char* function, const char* file, size_t line)
@@ -13,6 +13,7 @@
13
13
  #include <vector>
14
14
 
15
15
  #include "v8-local-handle.h" // NOLINT(build/include_directory)
16
+ #include "v8-memory-span.h" // NOLINT(build/include_directory)
16
17
  #include "v8-promise.h" // NOLINT(build/include_directory)
17
18
  #include "v8config.h" // NOLINT(build/include_directory)
18
19
 
@@ -60,42 +61,27 @@ class V8_EXPORT MeasureMemoryDelegate {
60
61
  */
61
62
  virtual bool ShouldMeasure(Local<Context> context) = 0;
62
63
 
63
- /**
64
- * This function is called when memory measurement finishes.
65
- *
66
- * \param context_sizes_in_bytes a vector of (context, size) pairs that
67
- * includes each context for which ShouldMeasure returned true and that
68
- * was not garbage collected while the memory measurement was in progress.
69
- *
70
- * \param unattributed_size_in_bytes total size of objects that were not
71
- * attributed to any context (i.e. are likely shared objects).
72
- */
73
- V8_DEPRECATE_SOON("Please use the version that takes a result struct")
74
- virtual void MeasurementComplete(
75
- const std::vector<std::pair<Local<Context>, size_t>>&
76
- context_sizes_in_bytes,
77
- size_t unattributed_size_in_bytes) {}
78
-
79
64
  /** Holds the result of a memory measurement request. */
80
65
  struct Result {
81
66
  /**
82
- * a vector of (context, size) pairs that includes each context for
83
- * which ShouldMeasure returned true and that was not garbage collected
84
- * while the memory measurement was in progress.
67
+ * Two spans of equal length: the first includes each context for which
68
+ * ShouldMeasure returned true and that was not garbage collected while
69
+ * the memory measurement was in progress; the second includes the size
70
+ * of the respective context.
85
71
  */
86
- const std::vector<std::pair<Local<Context>, size_t>>&
87
- context_sizes_in_bytes;
72
+ const MemorySpan<const Local<Context>>& contexts;
73
+ const MemorySpan<const size_t>& sizes_in_bytes;
88
74
 
89
75
  /**
90
- * total size of objects that were not attributed to any context (i.e. are
76
+ * Total size of objects that were not attributed to any context (i.e. are
91
77
  * likely shared objects).
92
78
  */
93
79
  size_t unattributed_size_in_bytes;
94
80
 
95
- /** total size of generated code for Wasm (shared across contexts). */
81
+ /** Total size of generated code for Wasm (shared across contexts). */
96
82
  size_t wasm_code_size_in_bytes;
97
83
 
98
- /** total size of Wasm metadata (except code; shared across contexts). */
84
+ /** Total size of Wasm metadata (except code; shared across contexts). */
99
85
  size_t wasm_metadata_size_in_bytes;
100
86
  };
101
87