libv8-node 21.7.2.0-aarch64-linux → 22.7.0.1-aarch64-linux

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 +7 -4
  3. data/vendor/v8/aarch64-linux/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 +258 -33
  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 +2 -2
@@ -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,15 +391,22 @@ 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>;
377
395
 
378
- V8_INLINE explicit Local<T>(const LocalBase<T>& other)
379
- : LocalBase<T>(other) {}
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) {}
400
+
401
+ V8_INLINE explicit Local(const LocalBase<T>& other) : LocalBase<T>(other) {}
380
402
 
381
403
  V8_INLINE static Local<T> FromSlot(internal::Address* slot) {
382
404
  return Local<T>(LocalBase<T>::FromSlot(slot));
383
405
  }
384
406
 
385
407
  #ifdef V8_ENABLE_DIRECT_LOCAL
408
+ friend class TypecheckWitness;
409
+
386
410
  V8_INLINE static Local<T> FromAddress(internal::Address ptr) {
387
411
  return Local<T>(LocalBase<T>(ptr));
388
412
  }
@@ -403,6 +427,174 @@ class Local : public LocalBase<T> {
403
427
  }
404
428
  };
405
429
 
430
+ namespace internal {
431
+ // A local variant that is suitable for off-stack allocation.
432
+ // Used internally by LocalVector<T>. Not to be used directly!
433
+ template <typename T>
434
+ class V8_TRIVIAL_ABI LocalUnchecked : public Local<T> {
435
+ public:
436
+ LocalUnchecked() : Local<T>(Local<T>::do_not_check) {}
437
+
438
+ #if defined(V8_ENABLE_LOCAL_OFF_STACK_CHECK) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
439
+ // In this case, the check is also enforced in the copy constructor and we
440
+ // need to suppress it.
441
+ LocalUnchecked(const LocalUnchecked& other)
442
+ : Local<T>(other, Local<T>::do_not_check) {}
443
+ LocalUnchecked& operator=(const LocalUnchecked&) = default;
444
+ #endif
445
+
446
+ // Implicit conversion from Local.
447
+ LocalUnchecked(const Local<T>& other) // NOLINT(runtime/explicit)
448
+ : Local<T>(other, Local<T>::do_not_check) {}
449
+ };
450
+
451
+ #ifdef V8_ENABLE_DIRECT_LOCAL
452
+ // Off-stack allocated direct locals must be registered as strong roots.
453
+ // For off-stack indirect locals, this is not necessary.
454
+
455
+ template <typename T>
456
+ class StrongRootAllocator<LocalUnchecked<T>> : public StrongRootAllocatorBase {
457
+ public:
458
+ using value_type = LocalUnchecked<T>;
459
+ static_assert(std::is_standard_layout_v<value_type>);
460
+ static_assert(sizeof(value_type) == sizeof(Address));
461
+
462
+ explicit StrongRootAllocator(Heap* heap) : StrongRootAllocatorBase(heap) {}
463
+ explicit StrongRootAllocator(v8::Isolate* isolate)
464
+ : StrongRootAllocatorBase(isolate) {}
465
+ template <typename U>
466
+ StrongRootAllocator(const StrongRootAllocator<U>& other) noexcept
467
+ : StrongRootAllocatorBase(other) {}
468
+
469
+ value_type* allocate(size_t n) {
470
+ return reinterpret_cast<value_type*>(allocate_impl(n));
471
+ }
472
+ void deallocate(value_type* p, size_t n) noexcept {
473
+ return deallocate_impl(reinterpret_cast<Address*>(p), n);
474
+ }
475
+ };
476
+ #endif // V8_ENABLE_DIRECT_LOCAL
477
+ } // namespace internal
478
+
479
+ template <typename T>
480
+ class LocalVector {
481
+ private:
482
+ using element_type = internal::LocalUnchecked<T>;
483
+
484
+ #ifdef V8_ENABLE_DIRECT_LOCAL
485
+ using allocator_type = internal::StrongRootAllocator<element_type>;
486
+
487
+ static allocator_type make_allocator(Isolate* isolate) noexcept {
488
+ return allocator_type(isolate);
489
+ }
490
+ #else
491
+ using allocator_type = std::allocator<element_type>;
492
+
493
+ static allocator_type make_allocator(Isolate* isolate) noexcept {
494
+ return allocator_type();
495
+ }
496
+ #endif // V8_ENABLE_DIRECT_LOCAL
497
+
498
+ using vector_type = std::vector<element_type, allocator_type>;
499
+
500
+ public:
501
+ using value_type = Local<T>;
502
+ using reference = value_type&;
503
+ using const_reference = const value_type&;
504
+ using size_type = size_t;
505
+ using difference_type = ptrdiff_t;
506
+ using iterator =
507
+ internal::WrappedIterator<typename vector_type::iterator, Local<T>>;
508
+ using const_iterator =
509
+ internal::WrappedIterator<typename vector_type::const_iterator,
510
+ const Local<T>>;
511
+
512
+ explicit LocalVector(Isolate* isolate) : backing_(make_allocator(isolate)) {}
513
+ LocalVector(Isolate* isolate, size_t n)
514
+ : backing_(n, make_allocator(isolate)) {}
515
+ explicit LocalVector(Isolate* isolate, std::initializer_list<Local<T>> init)
516
+ : backing_(make_allocator(isolate)) {
517
+ if (init.size() == 0) return;
518
+ backing_.reserve(init.size());
519
+ backing_.insert(backing_.end(), init.begin(), init.end());
520
+ }
521
+
522
+ iterator begin() noexcept { return iterator(backing_.begin()); }
523
+ const_iterator begin() const noexcept {
524
+ return const_iterator(backing_.begin());
525
+ }
526
+ iterator end() noexcept { return iterator(backing_.end()); }
527
+ const_iterator end() const noexcept { return const_iterator(backing_.end()); }
528
+
529
+ size_t size() const noexcept { return backing_.size(); }
530
+ bool empty() const noexcept { return backing_.empty(); }
531
+ void reserve(size_t n) { backing_.reserve(n); }
532
+ void shrink_to_fit() { backing_.shrink_to_fit(); }
533
+
534
+ Local<T>& operator[](size_t n) { return backing_[n]; }
535
+ const Local<T>& operator[](size_t n) const { return backing_[n]; }
536
+
537
+ Local<T>& at(size_t n) { return backing_.at(n); }
538
+ const Local<T>& at(size_t n) const { return backing_.at(n); }
539
+
540
+ Local<T>& front() { return backing_.front(); }
541
+ const Local<T>& front() const { return backing_.front(); }
542
+ Local<T>& back() { return backing_.back(); }
543
+ const Local<T>& back() const { return backing_.back(); }
544
+
545
+ Local<T>* data() noexcept { return backing_.data(); }
546
+ const Local<T>* data() const noexcept { return backing_.data(); }
547
+
548
+ iterator insert(const_iterator pos, const Local<T>& value) {
549
+ return iterator(backing_.insert(pos.base(), value));
550
+ }
551
+
552
+ template <typename InputIt>
553
+ iterator insert(const_iterator pos, InputIt first, InputIt last) {
554
+ return iterator(backing_.insert(pos.base(), first, last));
555
+ }
556
+
557
+ iterator insert(const_iterator pos, std::initializer_list<Local<T>> init) {
558
+ return iterator(backing_.insert(pos.base(), init.begin(), init.end()));
559
+ }
560
+
561
+ LocalVector<T>& operator=(std::initializer_list<Local<T>> init) {
562
+ backing_.clear();
563
+ backing_.insert(backing_.end(), init.begin(), init.end());
564
+ return *this;
565
+ }
566
+
567
+ void push_back(const Local<T>& x) { backing_.push_back(x); }
568
+ void pop_back() { backing_.pop_back(); }
569
+ void emplace_back(const Local<T>& x) { backing_.emplace_back(x); }
570
+
571
+ void clear() noexcept { backing_.clear(); }
572
+ void resize(size_t n) { backing_.resize(n); }
573
+ void swap(LocalVector<T>& other) { backing_.swap(other.backing_); }
574
+
575
+ friend bool operator==(const LocalVector<T>& x, const LocalVector<T>& y) {
576
+ return x.backing_ == y.backing_;
577
+ }
578
+ friend bool operator!=(const LocalVector<T>& x, const LocalVector<T>& y) {
579
+ return x.backing_ != y.backing_;
580
+ }
581
+ friend bool operator<(const LocalVector<T>& x, const LocalVector<T>& y) {
582
+ return x.backing_ < y.backing_;
583
+ }
584
+ friend bool operator>(const LocalVector<T>& x, const LocalVector<T>& y) {
585
+ return x.backing_ > y.backing_;
586
+ }
587
+ friend bool operator<=(const LocalVector<T>& x, const LocalVector<T>& y) {
588
+ return x.backing_ <= y.backing_;
589
+ }
590
+ friend bool operator>=(const LocalVector<T>& x, const LocalVector<T>& y) {
591
+ return x.backing_ >= y.backing_;
592
+ }
593
+
594
+ private:
595
+ vector_type backing_;
596
+ };
597
+
406
598
  #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
407
599
  // Handle is an alias for Local for historical reasons.
408
600
  template <class T>
@@ -456,29 +648,79 @@ class MaybeLocal {
456
648
  return IsEmpty() ? default_value : Local<S>(local_);
457
649
  }
458
650
 
651
+ /**
652
+ * Cast a handle to a subclass, e.g. MaybeLocal<Value> to MaybeLocal<Object>.
653
+ * This is only valid if the handle actually refers to a value of the target
654
+ * type.
655
+ */
656
+ template <class S>
657
+ V8_INLINE static MaybeLocal<T> Cast(MaybeLocal<S> that) {
658
+ #ifdef V8_ENABLE_CHECKS
659
+ // If we're going to perform the type check then we have to check
660
+ // that the handle isn't empty before doing the checked cast.
661
+ if (that.IsEmpty()) return MaybeLocal<T>();
662
+ T::Cast(that.local_.template value<S>());
663
+ #endif
664
+ return MaybeLocal<T>(that.local_);
665
+ }
666
+
667
+ /**
668
+ * Calling this is equivalent to MaybeLocal<S>::Cast().
669
+ * In particular, this is only valid if the handle actually refers to a value
670
+ * of the target type.
671
+ */
672
+ template <class S>
673
+ V8_INLINE MaybeLocal<S> As() const {
674
+ return MaybeLocal<S>::Cast(*this);
675
+ }
676
+
459
677
  private:
460
678
  Local<T> local_;
679
+
680
+ template <typename S>
681
+ friend class MaybeLocal;
461
682
  };
462
683
 
463
684
  /**
464
685
  * A HandleScope which first allocates a handle in the current scope
465
686
  * which will be later filled with the escape value.
466
687
  */
467
- class V8_EXPORT V8_NODISCARD EscapableHandleScope : public HandleScope {
688
+ class V8_EXPORT V8_NODISCARD EscapableHandleScopeBase : public HandleScope {
468
689
  public:
469
- explicit EscapableHandleScope(Isolate* isolate);
470
- V8_INLINE ~EscapableHandleScope() = default;
690
+ explicit EscapableHandleScopeBase(Isolate* isolate);
691
+ V8_INLINE ~EscapableHandleScopeBase() = default;
692
+
693
+ EscapableHandleScopeBase(const EscapableHandleScopeBase&) = delete;
694
+ void operator=(const EscapableHandleScopeBase&) = delete;
695
+ void* operator new(size_t size) = delete;
696
+ void* operator new[](size_t size) = delete;
697
+ void operator delete(void*, size_t) = delete;
698
+ void operator delete[](void*, size_t) = delete;
471
699
 
700
+ protected:
472
701
  /**
473
702
  * Pushes the value into the previous scope and returns a handle to it.
474
703
  * Cannot be called twice.
475
704
  */
705
+ internal::Address* EscapeSlot(internal::Address* escape_value);
706
+
707
+ private:
708
+ internal::Address* escape_slot_;
709
+ };
710
+
711
+ class V8_EXPORT V8_NODISCARD EscapableHandleScope
712
+ : public EscapableHandleScopeBase {
713
+ public:
714
+ explicit EscapableHandleScope(Isolate* isolate)
715
+ : EscapableHandleScopeBase(isolate) {}
716
+ V8_INLINE ~EscapableHandleScope() = default;
476
717
  template <class T>
477
718
  V8_INLINE Local<T> Escape(Local<T> value) {
478
719
  #ifdef V8_ENABLE_DIRECT_LOCAL
479
720
  return value;
480
721
  #else
481
- return Local<T>::FromSlot(Escape(value.slot()));
722
+ if (value.IsEmpty()) return value;
723
+ return Local<T>::FromSlot(EscapeSlot(value.slot()));
482
724
  #endif
483
725
  }
484
726
 
@@ -486,20 +728,6 @@ class V8_EXPORT V8_NODISCARD EscapableHandleScope : public HandleScope {
486
728
  V8_INLINE MaybeLocal<T> EscapeMaybe(MaybeLocal<T> value) {
487
729
  return Escape(value.FromMaybe(Local<T>()));
488
730
  }
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
731
  };
504
732
 
505
733
  /**
@@ -514,15 +742,12 @@ class V8_EXPORT V8_NODISCARD SealHandleScope {
514
742
 
515
743
  SealHandleScope(const SealHandleScope&) = delete;
516
744
  void operator=(const SealHandleScope&) = delete;
745
+ void* operator new(size_t size) = delete;
746
+ void* operator new[](size_t size) = delete;
747
+ void operator delete(void*, size_t) = delete;
748
+ void operator delete[](void*, size_t) = delete;
517
749
 
518
750
  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
751
  internal::Isolate* const i_isolate_;
527
752
  internal::Address* prev_limit_;
528
753
  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 {