libv8-node 21.7.2.0-arm64-darwin → 22.5.1.0-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/libv8/node/version.rb +3 -3
  3. data/vendor/v8/arm64-darwin/libv8/obj/libv8_monolith.a +0 -0
  4. data/vendor/v8/include/cppgc/internal/api-constants.h +1 -1
  5. data/vendor/v8/include/cppgc/type-traits.h +25 -4
  6. data/vendor/v8/include/v8-array-buffer.h +6 -0
  7. data/vendor/v8/include/v8-callbacks.h +6 -12
  8. data/vendor/v8/include/v8-container.h +54 -0
  9. data/vendor/v8/include/v8-context.h +51 -22
  10. data/vendor/v8/include/v8-embedder-heap.h +19 -3
  11. data/vendor/v8/include/v8-embedder-state-scope.h +2 -1
  12. data/vendor/v8/include/v8-exception.h +15 -9
  13. data/vendor/v8/include/v8-fast-api-calls.h +35 -26
  14. data/vendor/v8/include/v8-forward.h +1 -0
  15. data/vendor/v8/include/v8-function-callback.h +129 -20
  16. data/vendor/v8/include/v8-handle-base.h +32 -80
  17. data/vendor/v8/include/v8-inspector.h +16 -24
  18. data/vendor/v8/include/v8-internal.h +472 -65
  19. data/vendor/v8/include/v8-isolate.h +86 -51
  20. data/vendor/v8/include/v8-local-handle.h +257 -31
  21. data/vendor/v8/include/v8-memory-span.h +157 -2
  22. data/vendor/v8/include/v8-message.h +22 -3
  23. data/vendor/v8/include/v8-metrics.h +1 -0
  24. data/vendor/v8/include/v8-object.h +29 -10
  25. data/vendor/v8/include/v8-persistent-handle.h +5 -3
  26. data/vendor/v8/include/v8-platform.h +81 -44
  27. data/vendor/v8/include/v8-script.h +61 -11
  28. data/vendor/v8/include/v8-snapshot.h +94 -23
  29. data/vendor/v8/include/v8-statistics.h +10 -24
  30. data/vendor/v8/include/v8-template.h +410 -131
  31. data/vendor/v8/include/v8-traced-handle.h +81 -46
  32. data/vendor/v8/include/v8-typed-array.h +115 -7
  33. data/vendor/v8/include/v8-util.h +13 -12
  34. data/vendor/v8/include/v8-value.h +92 -4
  35. data/vendor/v8/include/v8-version.h +4 -4
  36. data/vendor/v8/include/v8config.h +35 -10
  37. metadata +3 -3
@@ -8,8 +8,10 @@
8
8
  #include <stddef.h>
9
9
 
10
10
  #include <type_traits>
11
+ #include <vector>
11
12
 
12
13
  #include "v8-handle-base.h" // NOLINT(build/include_directory)
14
+ #include "v8-internal.h" // NOLINT(build/include_directory)
13
15
 
14
16
  namespace v8 {
15
17
 
@@ -17,6 +19,8 @@ template <class T>
17
19
  class LocalBase;
18
20
  template <class T>
19
21
  class Local;
22
+ template <class T>
23
+ class LocalVector;
20
24
  template <class F>
21
25
  class MaybeLocal;
22
26
 
@@ -58,6 +62,7 @@ class ReturnValue;
58
62
  class String;
59
63
  template <class F>
60
64
  class Traced;
65
+ class TypecheckWitness;
61
66
  class Utils;
62
67
 
63
68
  namespace debug {
@@ -67,6 +72,8 @@ class ConsoleCallArguments;
67
72
  namespace internal {
68
73
  template <typename T>
69
74
  class CustomArguments;
75
+ template <typename T>
76
+ class LocalUnchecked;
70
77
  class SamplingHeapProfiler;
71
78
  } // namespace internal
72
79
 
@@ -129,6 +136,9 @@ class V8_EXPORT V8_NODISCARD HandleScope {
129
136
  internal::Isolate* i_isolate_;
130
137
  internal::Address* prev_next_;
131
138
  internal::Address* prev_limit_;
139
+ #ifdef V8_ENABLE_CHECKS
140
+ int scope_level_ = 0;
141
+ #endif
132
142
 
133
143
  // LocalBase<T>::New uses CreateHandle with an Isolate* parameter.
134
144
  template <typename T>
@@ -149,7 +159,7 @@ class V8_EXPORT V8_NODISCARD HandleScope {
149
159
  #ifdef V8_ENABLE_DIRECT_LOCAL
150
160
 
151
161
  template <typename T>
152
- class LocalBase : public DirectHandleBase {
162
+ class LocalBase : public api_internal::DirectHandleBase {
153
163
  protected:
154
164
  template <class F>
155
165
  friend class Local;
@@ -178,7 +188,7 @@ class LocalBase : public DirectHandleBase {
178
188
  #else // !V8_ENABLE_DIRECT_LOCAL
179
189
 
180
190
  template <typename T>
181
- class LocalBase : public IndirectHandleBase {
191
+ class LocalBase : public api_internal::IndirectHandleBase {
182
192
  protected:
183
193
  template <class F>
184
194
  friend class Local;
@@ -239,7 +249,13 @@ class LocalBase : public IndirectHandleBase {
239
249
  * to these values as to their handles.
240
250
  */
241
251
  template <class T>
242
- class Local : public LocalBase<T> {
252
+ class V8_TRIVIAL_ABI Local : public LocalBase<T>,
253
+ #ifdef V8_ENABLE_LOCAL_OFF_STACK_CHECK
254
+ public api_internal::StackAllocated<true>
255
+ #else
256
+ public api_internal::StackAllocated<false>
257
+ #endif
258
+ {
243
259
  public:
244
260
  V8_INLINE Local() = default;
245
261
 
@@ -320,17 +336,17 @@ class Local : public LocalBase<T> {
320
336
  * the original handle is destroyed/disposed.
321
337
  */
322
338
  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that) {
323
- return New(isolate, that.template value<T>());
339
+ return New(isolate, that.template value<T, true>());
324
340
  }
325
341
 
326
342
  V8_INLINE static Local<T> New(Isolate* isolate,
327
343
  const PersistentBase<T>& that) {
328
- return New(isolate, that.template value<T>());
344
+ return New(isolate, that.template value<T, true>());
329
345
  }
330
346
 
331
347
  V8_INLINE static Local<T> New(Isolate* isolate,
332
348
  const BasicTracedReference<T>& that) {
333
- return New(isolate, that.template value<T>());
349
+ return New(isolate, that.template value<T, true>());
334
350
  }
335
351
 
336
352
  private:
@@ -363,6 +379,7 @@ class Local : public LocalBase<T> {
363
379
  friend Local<Boolean> False(Isolate* isolate);
364
380
  friend class HandleScope;
365
381
  friend class EscapableHandleScope;
382
+ friend class InternalEscapableScope;
366
383
  template <class F1, class F2, class F3>
367
384
  friend class PersistentValueMapBase;
368
385
  template <class F1, class F2>
@@ -374,6 +391,12 @@ class Local : public LocalBase<T> {
374
391
  friend class internal::SamplingHeapProfiler;
375
392
  friend class internal::HandleHelper;
376
393
  friend class debug::ConsoleCallArguments;
394
+ friend class internal::LocalUnchecked<T>;
395
+
396
+ explicit Local(no_checking_tag do_not_check)
397
+ : LocalBase<T>(), StackAllocated(do_not_check) {}
398
+ explicit Local(const Local<T>& other, no_checking_tag do_not_check)
399
+ : LocalBase<T>(other), StackAllocated(do_not_check) {}
377
400
 
378
401
  V8_INLINE explicit Local<T>(const LocalBase<T>& other)
379
402
  : LocalBase<T>(other) {}
@@ -383,6 +406,8 @@ class Local : public LocalBase<T> {
383
406
  }
384
407
 
385
408
  #ifdef V8_ENABLE_DIRECT_LOCAL
409
+ friend class TypecheckWitness;
410
+
386
411
  V8_INLINE static Local<T> FromAddress(internal::Address ptr) {
387
412
  return Local<T>(LocalBase<T>(ptr));
388
413
  }
@@ -403,6 +428,174 @@ class Local : public LocalBase<T> {
403
428
  }
404
429
  };
405
430
 
431
+ namespace internal {
432
+ // A local variant that is suitable for off-stack allocation.
433
+ // Used internally by LocalVector<T>. Not to be used directly!
434
+ template <typename T>
435
+ class V8_TRIVIAL_ABI LocalUnchecked : public Local<T> {
436
+ public:
437
+ LocalUnchecked() : Local<T>(Local<T>::do_not_check) {}
438
+
439
+ #if defined(V8_ENABLE_LOCAL_OFF_STACK_CHECK) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
440
+ // In this case, the check is also enforced in the copy constructor and we
441
+ // need to suppress it.
442
+ LocalUnchecked(const LocalUnchecked& other)
443
+ : Local<T>(other, Local<T>::do_not_check) {}
444
+ LocalUnchecked& operator=(const LocalUnchecked&) = default;
445
+ #endif
446
+
447
+ // Implicit conversion from Local.
448
+ LocalUnchecked(const Local<T>& other) // NOLINT(runtime/explicit)
449
+ : Local<T>(other, Local<T>::do_not_check) {}
450
+ };
451
+
452
+ #ifdef V8_ENABLE_DIRECT_LOCAL
453
+ // Off-stack allocated direct locals must be registered as strong roots.
454
+ // For off-stack indirect locals, this is not necessary.
455
+
456
+ template <typename T>
457
+ class StrongRootAllocator<LocalUnchecked<T>> : public StrongRootAllocatorBase {
458
+ public:
459
+ using value_type = LocalUnchecked<T>;
460
+ static_assert(std::is_standard_layout_v<value_type>);
461
+ static_assert(sizeof(value_type) == sizeof(Address));
462
+
463
+ explicit StrongRootAllocator(Heap* heap) : StrongRootAllocatorBase(heap) {}
464
+ explicit StrongRootAllocator(v8::Isolate* isolate)
465
+ : StrongRootAllocatorBase(isolate) {}
466
+ template <typename U>
467
+ StrongRootAllocator(const StrongRootAllocator<U>& other) noexcept
468
+ : StrongRootAllocatorBase(other) {}
469
+
470
+ value_type* allocate(size_t n) {
471
+ return reinterpret_cast<value_type*>(allocate_impl(n));
472
+ }
473
+ void deallocate(value_type* p, size_t n) noexcept {
474
+ return deallocate_impl(reinterpret_cast<Address*>(p), n);
475
+ }
476
+ };
477
+ #endif // V8_ENABLE_DIRECT_LOCAL
478
+ } // namespace internal
479
+
480
+ template <typename T>
481
+ class LocalVector {
482
+ private:
483
+ using element_type = internal::LocalUnchecked<T>;
484
+
485
+ #ifdef V8_ENABLE_DIRECT_LOCAL
486
+ using allocator_type = internal::StrongRootAllocator<element_type>;
487
+
488
+ static allocator_type make_allocator(Isolate* isolate) noexcept {
489
+ return allocator_type(isolate);
490
+ }
491
+ #else
492
+ using allocator_type = std::allocator<element_type>;
493
+
494
+ static allocator_type make_allocator(Isolate* isolate) noexcept {
495
+ return allocator_type();
496
+ }
497
+ #endif // V8_ENABLE_DIRECT_LOCAL
498
+
499
+ using vector_type = std::vector<element_type, allocator_type>;
500
+
501
+ public:
502
+ using value_type = Local<T>;
503
+ using reference = value_type&;
504
+ using const_reference = const value_type&;
505
+ using size_type = size_t;
506
+ using difference_type = ptrdiff_t;
507
+ using iterator =
508
+ internal::WrappedIterator<typename vector_type::iterator, Local<T>>;
509
+ using const_iterator =
510
+ internal::WrappedIterator<typename vector_type::const_iterator,
511
+ const Local<T>>;
512
+
513
+ explicit LocalVector(Isolate* isolate) : backing_(make_allocator(isolate)) {}
514
+ LocalVector(Isolate* isolate, size_t n)
515
+ : backing_(n, make_allocator(isolate)) {}
516
+ explicit LocalVector(Isolate* isolate, std::initializer_list<Local<T>> init)
517
+ : backing_(make_allocator(isolate)) {
518
+ if (init.size() == 0) return;
519
+ backing_.reserve(init.size());
520
+ backing_.insert(backing_.end(), init.begin(), init.end());
521
+ }
522
+
523
+ iterator begin() noexcept { return iterator(backing_.begin()); }
524
+ const_iterator begin() const noexcept {
525
+ return const_iterator(backing_.begin());
526
+ }
527
+ iterator end() noexcept { return iterator(backing_.end()); }
528
+ const_iterator end() const noexcept { return const_iterator(backing_.end()); }
529
+
530
+ size_t size() const noexcept { return backing_.size(); }
531
+ bool empty() const noexcept { return backing_.empty(); }
532
+ void reserve(size_t n) { backing_.reserve(n); }
533
+ void shrink_to_fit() { backing_.shrink_to_fit(); }
534
+
535
+ Local<T>& operator[](size_t n) { return backing_[n]; }
536
+ const Local<T>& operator[](size_t n) const { return backing_[n]; }
537
+
538
+ Local<T>& at(size_t n) { return backing_.at(n); }
539
+ const Local<T>& at(size_t n) const { return backing_.at(n); }
540
+
541
+ Local<T>& front() { return backing_.front(); }
542
+ const Local<T>& front() const { return backing_.front(); }
543
+ Local<T>& back() { return backing_.back(); }
544
+ const Local<T>& back() const { return backing_.back(); }
545
+
546
+ Local<T>* data() noexcept { return backing_.data(); }
547
+ const Local<T>* data() const noexcept { return backing_.data(); }
548
+
549
+ iterator insert(const_iterator pos, const Local<T>& value) {
550
+ return iterator(backing_.insert(pos.base(), value));
551
+ }
552
+
553
+ template <typename InputIt>
554
+ iterator insert(const_iterator pos, InputIt first, InputIt last) {
555
+ return iterator(backing_.insert(pos.base(), first, last));
556
+ }
557
+
558
+ iterator insert(const_iterator pos, std::initializer_list<Local<T>> init) {
559
+ return iterator(backing_.insert(pos.base(), init.begin(), init.end()));
560
+ }
561
+
562
+ LocalVector<T>& operator=(std::initializer_list<Local<T>> init) {
563
+ backing_.clear();
564
+ backing_.insert(backing_.end(), init.begin(), init.end());
565
+ return *this;
566
+ }
567
+
568
+ void push_back(const Local<T>& x) { backing_.push_back(x); }
569
+ void pop_back() { backing_.pop_back(); }
570
+ void emplace_back(const Local<T>& x) { backing_.emplace_back(x); }
571
+
572
+ void clear() noexcept { backing_.clear(); }
573
+ void resize(size_t n) { backing_.resize(n); }
574
+ void swap(LocalVector<T>& other) { backing_.swap(other.backing_); }
575
+
576
+ friend bool operator==(const LocalVector<T>& x, const LocalVector<T>& y) {
577
+ return x.backing_ == y.backing_;
578
+ }
579
+ friend bool operator!=(const LocalVector<T>& x, const LocalVector<T>& y) {
580
+ return x.backing_ != y.backing_;
581
+ }
582
+ friend bool operator<(const LocalVector<T>& x, const LocalVector<T>& y) {
583
+ return x.backing_ < y.backing_;
584
+ }
585
+ friend bool operator>(const LocalVector<T>& x, const LocalVector<T>& y) {
586
+ return x.backing_ > y.backing_;
587
+ }
588
+ friend bool operator<=(const LocalVector<T>& x, const LocalVector<T>& y) {
589
+ return x.backing_ <= y.backing_;
590
+ }
591
+ friend bool operator>=(const LocalVector<T>& x, const LocalVector<T>& y) {
592
+ return x.backing_ >= y.backing_;
593
+ }
594
+
595
+ private:
596
+ vector_type backing_;
597
+ };
598
+
406
599
  #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
407
600
  // Handle is an alias for Local for historical reasons.
408
601
  template <class T>
@@ -456,29 +649,79 @@ class MaybeLocal {
456
649
  return IsEmpty() ? default_value : Local<S>(local_);
457
650
  }
458
651
 
652
+ /**
653
+ * Cast a handle to a subclass, e.g. MaybeLocal<Value> to MaybeLocal<Object>.
654
+ * This is only valid if the handle actually refers to a value of the target
655
+ * type.
656
+ */
657
+ template <class S>
658
+ V8_INLINE static MaybeLocal<T> Cast(MaybeLocal<S> that) {
659
+ #ifdef V8_ENABLE_CHECKS
660
+ // If we're going to perform the type check then we have to check
661
+ // that the handle isn't empty before doing the checked cast.
662
+ if (that.IsEmpty()) return MaybeLocal<T>();
663
+ T::Cast(that.local_.template value<S>());
664
+ #endif
665
+ return MaybeLocal<T>(that.local_);
666
+ }
667
+
668
+ /**
669
+ * Calling this is equivalent to MaybeLocal<S>::Cast().
670
+ * In particular, this is only valid if the handle actually refers to a value
671
+ * of the target type.
672
+ */
673
+ template <class S>
674
+ V8_INLINE MaybeLocal<S> As() const {
675
+ return MaybeLocal<S>::Cast(*this);
676
+ }
677
+
459
678
  private:
460
679
  Local<T> local_;
680
+
681
+ template <typename S>
682
+ friend class MaybeLocal;
461
683
  };
462
684
 
463
685
  /**
464
686
  * A HandleScope which first allocates a handle in the current scope
465
687
  * which will be later filled with the escape value.
466
688
  */
467
- class V8_EXPORT V8_NODISCARD EscapableHandleScope : public HandleScope {
689
+ class V8_EXPORT V8_NODISCARD EscapableHandleScopeBase : public HandleScope {
468
690
  public:
469
- explicit EscapableHandleScope(Isolate* isolate);
470
- V8_INLINE ~EscapableHandleScope() = default;
691
+ explicit EscapableHandleScopeBase(Isolate* isolate);
692
+ V8_INLINE ~EscapableHandleScopeBase() = default;
693
+
694
+ EscapableHandleScopeBase(const EscapableHandleScopeBase&) = delete;
695
+ void operator=(const EscapableHandleScopeBase&) = delete;
696
+ void* operator new(size_t size) = delete;
697
+ void* operator new[](size_t size) = delete;
698
+ void operator delete(void*, size_t) = delete;
699
+ void operator delete[](void*, size_t) = delete;
471
700
 
701
+ protected:
472
702
  /**
473
703
  * Pushes the value into the previous scope and returns a handle to it.
474
704
  * Cannot be called twice.
475
705
  */
706
+ internal::Address* EscapeSlot(internal::Address* escape_value);
707
+
708
+ private:
709
+ internal::Address* escape_slot_;
710
+ };
711
+
712
+ class V8_EXPORT V8_NODISCARD EscapableHandleScope
713
+ : public EscapableHandleScopeBase {
714
+ public:
715
+ explicit EscapableHandleScope(Isolate* isolate)
716
+ : EscapableHandleScopeBase(isolate) {}
717
+ V8_INLINE ~EscapableHandleScope() = default;
476
718
  template <class T>
477
719
  V8_INLINE Local<T> Escape(Local<T> value) {
478
720
  #ifdef V8_ENABLE_DIRECT_LOCAL
479
721
  return value;
480
722
  #else
481
- return Local<T>::FromSlot(Escape(value.slot()));
723
+ if (value.IsEmpty()) return value;
724
+ return Local<T>::FromSlot(EscapeSlot(value.slot()));
482
725
  #endif
483
726
  }
484
727
 
@@ -486,20 +729,6 @@ class V8_EXPORT V8_NODISCARD EscapableHandleScope : public HandleScope {
486
729
  V8_INLINE MaybeLocal<T> EscapeMaybe(MaybeLocal<T> value) {
487
730
  return Escape(value.FromMaybe(Local<T>()));
488
731
  }
489
-
490
- EscapableHandleScope(const EscapableHandleScope&) = delete;
491
- void operator=(const EscapableHandleScope&) = delete;
492
-
493
- private:
494
- // Declaring operator new and delete as deleted is not spec compliant.
495
- // Therefore declare them private instead to disable dynamic alloc
496
- void* operator new(size_t size);
497
- void* operator new[](size_t size);
498
- void operator delete(void*, size_t);
499
- void operator delete[](void*, size_t);
500
-
501
- internal::Address* Escape(internal::Address* escape_value);
502
- internal::Address* escape_slot_;
503
732
  };
504
733
 
505
734
  /**
@@ -514,15 +743,12 @@ class V8_EXPORT V8_NODISCARD SealHandleScope {
514
743
 
515
744
  SealHandleScope(const SealHandleScope&) = delete;
516
745
  void operator=(const SealHandleScope&) = delete;
746
+ void* operator new(size_t size) = delete;
747
+ void* operator new[](size_t size) = delete;
748
+ void operator delete(void*, size_t) = delete;
749
+ void operator delete[](void*, size_t) = delete;
517
750
 
518
751
  private:
519
- // Declaring operator new and delete as deleted is not spec compliant.
520
- // Therefore declare them private instead to disable dynamic alloc
521
- void* operator new(size_t size);
522
- void* operator new[](size_t size);
523
- void operator delete(void*, size_t);
524
- void operator delete[](void*, size_t);
525
-
526
752
  internal::Isolate* const i_isolate_;
527
753
  internal::Address* prev_limit_;
528
754
  int prev_sealed_level_;
@@ -7,12 +7,16 @@
7
7
 
8
8
  #include <stddef.h>
9
9
 
10
+ #include <array>
11
+ #include <iterator>
12
+ #include <type_traits>
13
+
10
14
  #include "v8config.h" // NOLINT(build/include_directory)
11
15
 
12
16
  namespace v8 {
13
17
 
14
18
  /**
15
- * Points to an unowned continous buffer holding a known number of elements.
19
+ * Points to an unowned contiguous buffer holding a known number of elements.
16
20
  *
17
21
  * This is similar to std::span (under consideration for C++20), but does not
18
22
  * require advanced C++ support. In the (far) future, this may be replaced with
@@ -23,21 +27,172 @@ namespace v8 {
23
27
  */
24
28
  template <typename T>
25
29
  class V8_EXPORT MemorySpan {
30
+ private:
31
+ /** Some C++ machinery, brought from the future. */
32
+ template <typename From, typename To>
33
+ using is_array_convertible = std::is_convertible<From (*)[], To (*)[]>;
34
+ template <typename From, typename To>
35
+ static constexpr bool is_array_convertible_v =
36
+ is_array_convertible<From, To>::value;
37
+
38
+ template <typename It>
39
+ using iter_reference_t = decltype(*std::declval<It&>());
40
+
41
+ template <typename It, typename = void>
42
+ struct is_compatible_iterator : std::false_type {};
43
+ template <typename It>
44
+ struct is_compatible_iterator<
45
+ It,
46
+ std::void_t<
47
+ std::is_base_of<std::random_access_iterator_tag,
48
+ typename std::iterator_traits<It>::iterator_category>,
49
+ is_array_convertible<std::remove_reference_t<iter_reference_t<It>>,
50
+ T>>> : std::true_type {};
51
+ template <typename It>
52
+ static constexpr bool is_compatible_iterator_v =
53
+ is_compatible_iterator<It>::value;
54
+
55
+ template <typename U>
56
+ static constexpr U* to_address(U* p) noexcept {
57
+ return p;
58
+ }
59
+
60
+ template <typename It,
61
+ typename = std::void_t<decltype(std::declval<It&>().operator->())>>
62
+ static constexpr auto to_address(It it) noexcept {
63
+ return it.operator->();
64
+ }
65
+
26
66
  public:
27
67
  /** The default constructor creates an empty span. */
28
68
  constexpr MemorySpan() = default;
29
69
 
30
- constexpr MemorySpan(T* data, size_t size) : data_(data), size_(size) {}
70
+ /** Constructor from nullptr and count, for backwards compatibility.
71
+ * This is not compatible with C++20 std::span.
72
+ */
73
+ constexpr MemorySpan(std::nullptr_t, size_t) {}
74
+
75
+ /** Constructor from "iterator" and count. */
76
+ template <typename Iterator,
77
+ std::enable_if_t<is_compatible_iterator_v<Iterator>, bool> = true>
78
+ constexpr MemorySpan(Iterator first,
79
+ size_t count) // NOLINT(runtime/explicit)
80
+ : data_(to_address(first)), size_(count) {}
81
+
82
+ /** Constructor from two "iterators". */
83
+ template <typename Iterator,
84
+ std::enable_if_t<is_compatible_iterator_v<Iterator> &&
85
+ !std::is_convertible_v<Iterator, size_t>,
86
+ bool> = true>
87
+ constexpr MemorySpan(Iterator first,
88
+ Iterator last) // NOLINT(runtime/explicit)
89
+ : data_(to_address(first)), size_(last - first) {}
90
+
91
+ /** Implicit conversion from C-style array. */
92
+ template <size_t N>
93
+ constexpr MemorySpan(T (&a)[N]) noexcept // NOLINT(runtime/explicit)
94
+ : data_(a), size_(N) {}
95
+
96
+ /** Implicit conversion from std::array. */
97
+ template <typename U, size_t N,
98
+ std::enable_if_t<is_array_convertible_v<U, T>, bool> = true>
99
+ constexpr MemorySpan(
100
+ std::array<U, N>& a) noexcept // NOLINT(runtime/explicit)
101
+ : data_(a.data()), size_{N} {}
102
+
103
+ /** Implicit conversion from const std::array. */
104
+ template <typename U, size_t N,
105
+ std::enable_if_t<is_array_convertible_v<const U, T>, bool> = true>
106
+ constexpr MemorySpan(
107
+ const std::array<U, N>& a) noexcept // NOLINT(runtime/explicit)
108
+ : data_(a.data()), size_{N} {}
31
109
 
32
110
  /** Returns a pointer to the beginning of the buffer. */
33
111
  constexpr T* data() const { return data_; }
34
112
  /** Returns the number of elements that the buffer holds. */
35
113
  constexpr size_t size() const { return size_; }
36
114
 
115
+ constexpr T& operator[](size_t i) const { return data_[i]; }
116
+
117
+ /** Returns true if the buffer is empty. */
118
+ constexpr bool empty() const { return size() == 0; }
119
+
120
+ class Iterator {
121
+ public:
122
+ using iterator_category = std::forward_iterator_tag;
123
+ using value_type = T;
124
+ using difference_type = std::ptrdiff_t;
125
+ using pointer = value_type*;
126
+ using reference = value_type&;
127
+
128
+ T& operator*() const { return *ptr_; }
129
+ T* operator->() const { return ptr_; }
130
+
131
+ bool operator==(Iterator other) const { return ptr_ == other.ptr_; }
132
+ bool operator!=(Iterator other) const { return !(*this == other); }
133
+
134
+ Iterator& operator++() {
135
+ ++ptr_;
136
+ return *this;
137
+ }
138
+
139
+ Iterator operator++(int) {
140
+ Iterator temp(*this);
141
+ ++(*this);
142
+ return temp;
143
+ }
144
+
145
+ private:
146
+ friend class MemorySpan<T>;
147
+
148
+ explicit Iterator(T* ptr) : ptr_(ptr) {}
149
+
150
+ T* ptr_ = nullptr;
151
+ };
152
+
153
+ Iterator begin() const { return Iterator(data_); }
154
+ Iterator end() const { return Iterator(data_ + size_); }
155
+
37
156
  private:
38
157
  T* data_ = nullptr;
39
158
  size_t size_ = 0;
40
159
  };
41
160
 
161
+ /**
162
+ * Helper function template to create an array of fixed length, initialized by
163
+ * the provided initializer list, without explicitly specifying the array size,
164
+ * e.g.
165
+ *
166
+ * auto arr = v8::to_array<Local<String>>({v8_str("one"), v8_str("two")});
167
+ *
168
+ * In the future, this may be replaced with or aliased to std::to_array (under
169
+ * consideration for C++20).
170
+ */
171
+
172
+ namespace detail {
173
+ template <class T, std::size_t N, std::size_t... I>
174
+ constexpr std::array<std::remove_cv_t<T>, N> to_array_lvalue_impl(
175
+ T (&a)[N], std::index_sequence<I...>) {
176
+ return {{a[I]...}};
177
+ }
178
+
179
+ template <class T, std::size_t N, std::size_t... I>
180
+ constexpr std::array<std::remove_cv_t<T>, N> to_array_rvalue_impl(
181
+ T (&&a)[N], std::index_sequence<I...>) {
182
+ return {{std::move(a[I])...}};
183
+ }
184
+ } // namespace detail
185
+
186
+ template <class T, std::size_t N>
187
+ constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N]) {
188
+ return detail::to_array_lvalue_impl(a, std::make_index_sequence<N>{});
189
+ }
190
+
191
+ template <class T, std::size_t N>
192
+ constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&&a)[N]) {
193
+ return detail::to_array_rvalue_impl(std::move(a),
194
+ std::make_index_sequence<N>{});
195
+ }
196
+
42
197
  } // namespace v8
43
198
  #endif // INCLUDE_V8_MEMORY_SPAN_H_
@@ -61,6 +61,7 @@ class ScriptOriginOptions {
61
61
  */
62
62
  class V8_EXPORT ScriptOrigin {
63
63
  public:
64
+ V8_DEPRECATE_SOON("Use constructor without the isolate.")
64
65
  V8_INLINE ScriptOrigin(Isolate* isolate, Local<Value> resource_name,
65
66
  int resource_line_offset = 0,
66
67
  int resource_column_offset = 0,
@@ -70,8 +71,27 @@ class V8_EXPORT ScriptOrigin {
70
71
  bool resource_is_opaque = false, bool is_wasm = false,
71
72
  bool is_module = false,
72
73
  Local<Data> host_defined_options = Local<Data>())
73
- : v8_isolate_(isolate),
74
- resource_name_(resource_name),
74
+ : resource_name_(resource_name),
75
+ resource_line_offset_(resource_line_offset),
76
+ resource_column_offset_(resource_column_offset),
77
+ options_(resource_is_shared_cross_origin, resource_is_opaque, is_wasm,
78
+ is_module),
79
+ script_id_(script_id),
80
+ source_map_url_(source_map_url),
81
+ host_defined_options_(host_defined_options) {
82
+ VerifyHostDefinedOptions();
83
+ }
84
+
85
+ V8_INLINE ScriptOrigin(Local<Value> resource_name,
86
+ int resource_line_offset = 0,
87
+ int resource_column_offset = 0,
88
+ bool resource_is_shared_cross_origin = false,
89
+ int script_id = -1,
90
+ Local<Value> source_map_url = Local<Value>(),
91
+ bool resource_is_opaque = false, bool is_wasm = false,
92
+ bool is_module = false,
93
+ Local<Data> host_defined_options = Local<Data>())
94
+ : resource_name_(resource_name),
75
95
  resource_line_offset_(resource_line_offset),
76
96
  resource_column_offset_(resource_column_offset),
77
97
  options_(resource_is_shared_cross_origin, resource_is_opaque, is_wasm,
@@ -92,7 +112,6 @@ class V8_EXPORT ScriptOrigin {
92
112
 
93
113
  private:
94
114
  void VerifyHostDefinedOptions() const;
95
- Isolate* v8_isolate_;
96
115
  Local<Value> resource_name_;
97
116
  int resource_line_offset_;
98
117
  int resource_column_offset_;
@@ -55,6 +55,7 @@ struct GarbageCollectionFullCycle {
55
55
  double efficiency_cpp_in_bytes_per_us = -1.0;
56
56
  double main_thread_efficiency_in_bytes_per_us = -1.0;
57
57
  double main_thread_efficiency_cpp_in_bytes_per_us = -1.0;
58
+ int64_t incremental_marking_start_stop_wall_clock_duration_in_us = -1;
58
59
  };
59
60
 
60
61
  struct GarbageCollectionFullMainThreadIncrementalMark {