libv8 7.8.279.23.0beta1-x86_64-linux → 8.4.255.0.1-x86_64-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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8/location.rb +1 -1
  3. data/lib/libv8/version.rb +1 -1
  4. data/vendor/v8/include/cppgc/allocation.h +124 -0
  5. data/vendor/v8/include/cppgc/garbage-collected.h +192 -0
  6. data/vendor/v8/include/cppgc/heap.h +50 -0
  7. data/vendor/v8/include/cppgc/internal/accessors.h +26 -0
  8. data/vendor/v8/include/cppgc/internal/api-constants.h +44 -0
  9. data/vendor/v8/include/cppgc/internal/compiler-specific.h +26 -0
  10. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  11. data/vendor/v8/include/cppgc/internal/gc-info.h +43 -0
  12. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  13. data/vendor/v8/include/cppgc/internal/persistent-node.h +109 -0
  14. data/vendor/v8/include/cppgc/internal/pointer-policies.h +133 -0
  15. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +31 -0
  16. data/vendor/v8/include/cppgc/liveness-broker.h +50 -0
  17. data/vendor/v8/include/cppgc/macros.h +26 -0
  18. data/vendor/v8/include/cppgc/member.h +206 -0
  19. data/vendor/v8/include/cppgc/persistent.h +304 -0
  20. data/vendor/v8/include/cppgc/platform.h +31 -0
  21. data/vendor/v8/include/cppgc/prefinalizer.h +54 -0
  22. data/vendor/v8/include/cppgc/source-location.h +59 -0
  23. data/vendor/v8/include/cppgc/trace-trait.h +67 -0
  24. data/vendor/v8/include/cppgc/type-traits.h +109 -0
  25. data/vendor/v8/include/cppgc/visitor.h +137 -0
  26. data/vendor/v8/include/libplatform/libplatform.h +13 -10
  27. data/vendor/v8/include/libplatform/v8-tracing.h +36 -22
  28. data/vendor/v8/include/v8-fast-api-calls.h +412 -0
  29. data/vendor/v8/include/v8-inspector-protocol.h +4 -4
  30. data/vendor/v8/include/v8-inspector.h +57 -27
  31. data/vendor/v8/include/v8-internal.h +23 -21
  32. data/vendor/v8/include/v8-platform.h +164 -40
  33. data/vendor/v8/include/v8-profiler.h +27 -23
  34. data/vendor/v8/include/v8-util.h +1 -1
  35. data/vendor/v8/include/v8-version-string.h +1 -1
  36. data/vendor/v8/include/v8-version.h +4 -4
  37. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +1 -1
  38. data/vendor/v8/include/v8-wasm-trap-handler-win.h +1 -1
  39. data/vendor/v8/include/v8.h +1219 -484
  40. data/vendor/v8/include/v8config.h +105 -51
  41. data/vendor/v8/out.gn/libv8/obj/libv8_libbase.a +0 -0
  42. data/vendor/v8/out.gn/libv8/obj/libv8_libplatform.a +0 -0
  43. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  44. data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicui18n.a +0 -0
  45. data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicuuc.a +0 -0
  46. data/vendor/v8/out.gn/libv8/obj/third_party/zlib/google/libcompression_utils_portable.a +0 -0
  47. data/vendor/v8/out.gn/libv8/obj/third_party/zlib/libchrome_zlib.a +0 -0
  48. metadata +31 -9
  49. data/vendor/v8/include/v8-testing.h +0 -48
  50. data/vendor/v8/out.gn/libv8/obj/third_party/inspector_protocol/libbindings.a +0 -0
  51. data/vendor/v8/out.gn/libv8/obj/third_party/inspector_protocol/libencoding.a +0 -0
@@ -9,7 +9,7 @@
9
9
  * This set of documents provides reference material generated from the
10
10
  * V8 header file, include/v8.h.
11
11
  *
12
- * For other documentation see http://code.google.com/apis/v8/
12
+ * For other documentation see https://v8.dev/.
13
13
  */
14
14
 
15
15
  #ifndef INCLUDE_V8_H_
@@ -19,13 +19,14 @@
19
19
  #include <stdint.h>
20
20
  #include <stdio.h>
21
21
  #include <memory>
22
+ #include <string>
22
23
  #include <type_traits>
23
24
  #include <utility>
24
25
  #include <vector>
25
26
 
26
- #include "v8-internal.h" // NOLINT(build/include)
27
- #include "v8-version.h" // NOLINT(build/include)
28
- #include "v8config.h" // NOLINT(build/include)
27
+ #include "v8-internal.h" // NOLINT(build/include_directory)
28
+ #include "v8-version.h" // NOLINT(build/include_directory)
29
+ #include "v8config.h" // NOLINT(build/include_directory)
29
30
 
30
31
  // We reserve the V8_* prefix for macros defined in V8 public API and
31
32
  // assume there are no name conflicts with the embedder's code.
@@ -96,6 +97,10 @@ template <class T>
96
97
  class Global;
97
98
  template <class T>
98
99
  class TracedGlobal;
100
+ template <class T>
101
+ class TracedReference;
102
+ template <class T>
103
+ class TracedReferenceBase;
99
104
  template<class K, class V, class T> class PersistentValueMap;
100
105
  template <class K, class V, class T>
101
106
  class PersistentValueMapBase;
@@ -115,6 +120,8 @@ class EscapableHandleScope;
115
120
  template<typename T> class ReturnValue;
116
121
 
117
122
  namespace internal {
123
+ enum class ArgumentsType;
124
+ template <ArgumentsType>
118
125
  class Arguments;
119
126
  class DeferredHandles;
120
127
  class Heap;
@@ -144,11 +151,6 @@ class ConsoleCallArguments;
144
151
 
145
152
  // --- Handles ---
146
153
 
147
- #define TYPE_CHECK(T, S) \
148
- while (false) { \
149
- *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
150
- }
151
-
152
154
  /**
153
155
  * An object reference managed by the v8 garbage collector.
154
156
  *
@@ -192,7 +194,7 @@ class Local {
192
194
  * handles. For example, converting from a Local<String> to a
193
195
  * Local<Number>.
194
196
  */
195
- TYPE_CHECK(T, S);
197
+ static_assert(std::is_base_of<T, S>::value, "type check");
196
198
  }
197
199
 
198
200
  /**
@@ -211,9 +213,13 @@ class Local {
211
213
 
212
214
  /**
213
215
  * Checks whether two handles are the same.
214
- * Returns true if both are empty, or if the objects
215
- * to which they refer are identical.
216
- * The handles' references are not checked.
216
+ * Returns true if both are empty, or if the objects to which they refer
217
+ * are identical.
218
+ *
219
+ * If both handles refer to JS objects, this is the same as strict equality.
220
+ * For primitives, such as numbers or strings, a `false` return value does not
221
+ * indicate that the values aren't equal in the JavaScript sense.
222
+ * Use `Value::StrictEquals()` to check primitives for equality.
217
223
  */
218
224
  template <class S>
219
225
  V8_INLINE bool operator==(const Local<S>& that) const {
@@ -237,7 +243,11 @@ class Local {
237
243
  * Checks whether two handles are different.
238
244
  * Returns true if only one of the handles is empty, or if
239
245
  * the objects to which they refer are different.
240
- * The handles' references are not checked.
246
+ *
247
+ * If both handles refer to JS objects, this is the same as strict
248
+ * non-equality. For primitives, such as numbers or strings, a `true` return
249
+ * value does not indicate that the values aren't equal in the JavaScript
250
+ * sense. Use `Value::StrictEquals()` to check primitives for equality.
241
251
  */
242
252
  template <class S>
243
253
  V8_INLINE bool operator!=(const Local<S>& that) const {
@@ -281,7 +291,8 @@ class Local {
281
291
  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
282
292
  V8_INLINE static Local<T> New(Isolate* isolate,
283
293
  const PersistentBase<T>& that);
284
- V8_INLINE static Local<T> New(Isolate* isolate, const TracedGlobal<T>& that);
294
+ V8_INLINE static Local<T> New(Isolate* isolate,
295
+ const TracedReferenceBase<T>& that);
285
296
 
286
297
  private:
287
298
  friend class Utils;
@@ -311,7 +322,13 @@ class Local {
311
322
  template <class F>
312
323
  friend class ReturnValue;
313
324
  template <class F>
325
+ friend class Traced;
326
+ template <class F>
314
327
  friend class TracedGlobal;
328
+ template <class F>
329
+ friend class TracedReferenceBase;
330
+ template <class F>
331
+ friend class TracedReference;
315
332
 
316
333
  explicit V8_INLINE Local(T* that) : val_(that) {}
317
334
  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
@@ -343,7 +360,7 @@ class MaybeLocal {
343
360
  template <class S>
344
361
  V8_INLINE MaybeLocal(Local<S> that)
345
362
  : val_(reinterpret_cast<T*>(*that)) {
346
- TYPE_CHECK(T, S);
363
+ static_assert(std::is_base_of<T, S>::value, "type check");
347
364
  }
348
365
 
349
366
  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
@@ -512,11 +529,16 @@ template <class T> class PersistentBase {
512
529
  }
513
530
 
514
531
  /**
515
- * Install a finalization callback on this object.
516
- * NOTE: There is no guarantee as to *when* or even *if* the callback is
517
- * invoked. The invocation is performed solely on a best effort basis.
518
- * As always, GC-based finalization should *not* be relied upon for any
519
- * critical form of resource management!
532
+ * Install a finalization callback on this object.
533
+ * NOTE: There is no guarantee as to *when* or even *if* the callback is
534
+ * invoked. The invocation is performed solely on a best effort basis.
535
+ * As always, GC-based finalization should *not* be relied upon for any
536
+ * critical form of resource management!
537
+ *
538
+ * The callback is supposed to reset the handle. No further V8 API may be
539
+ * called in this callback. In case additional work involving V8 needs to be
540
+ * done, a second callback can be scheduled using
541
+ * WeakCallbackInfo<void>::SetSecondPassCallback.
520
542
  */
521
543
  template <typename P>
522
544
  V8_INLINE void SetWeak(P* parameter,
@@ -598,11 +620,8 @@ class NonCopyablePersistentTraits {
598
620
  template<class S, class M>
599
621
  V8_INLINE static void Copy(const Persistent<S, M>& source,
600
622
  NonCopyablePersistent* dest) {
601
- Uncompilable<Object>();
602
- }
603
- // TODO(dcarney): come up with a good compile error here.
604
- template<class O> V8_INLINE static void Uncompilable() {
605
- TYPE_CHECK(O, Primitive);
623
+ static_assert(sizeof(S) < 0,
624
+ "NonCopyablePersistentTraits::Copy is not instantiable");
606
625
  }
607
626
  };
608
627
 
@@ -645,7 +664,7 @@ template <class T, class M> class Persistent : public PersistentBase<T> {
645
664
  template <class S>
646
665
  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
647
666
  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
648
- TYPE_CHECK(T, S);
667
+ static_assert(std::is_base_of<T, S>::value, "type check");
649
668
  }
650
669
  /**
651
670
  * Construct a Persistent from a Persistent.
@@ -655,7 +674,7 @@ template <class T, class M> class Persistent : public PersistentBase<T> {
655
674
  template <class S, class M2>
656
675
  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
657
676
  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
658
- TYPE_CHECK(T, S);
677
+ static_assert(std::is_base_of<T, S>::value, "type check");
659
678
  }
660
679
  /**
661
680
  * The copy constructors and assignment operator create a Persistent
@@ -740,7 +759,7 @@ class Global : public PersistentBase<T> {
740
759
  template <class S>
741
760
  V8_INLINE Global(Isolate* isolate, Local<S> that)
742
761
  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
743
- TYPE_CHECK(T, S);
762
+ static_assert(std::is_base_of<T, S>::value, "type check");
744
763
  }
745
764
 
746
765
  /**
@@ -751,7 +770,7 @@ class Global : public PersistentBase<T> {
751
770
  template <class S>
752
771
  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
753
772
  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
754
- TYPE_CHECK(T, S);
773
+ static_assert(std::is_base_of<T, S>::value, "type check");
755
774
  }
756
775
 
757
776
  /**
@@ -792,22 +811,10 @@ template <class T>
792
811
  using UniquePersistent = Global<T>;
793
812
 
794
813
  /**
795
- * Trait specifying behavior of |TracedGlobal<T>|.
814
+ * Deprecated. Use |TracedReference<T>| instead.
796
815
  */
797
816
  template <typename T>
798
- struct TracedGlobalTrait {
799
- /**
800
- * Specifies whether |TracedGlobal<T>| should clear its handle on destruction.
801
- *
802
- * V8 will *not* clear the embedder-side memory of the handle. The embedder is
803
- * expected to report all |TracedGlobal<T>| handles through
804
- * |EmbedderHeapTracer| upon garabge collection.
805
- *
806
- * See |EmbedderHeapTracer::IsRootForNonTracingGC| for handling with
807
- * non-tracing GCs in V8.
808
- */
809
- static constexpr bool kRequiresExplicitDestruction = true;
810
- };
817
+ struct TracedGlobalTrait {};
811
818
 
812
819
  /**
813
820
  * A traced handle with copy and move semantics. The handle is to be used
@@ -820,15 +827,118 @@ struct TracedGlobalTrait {
820
827
  * |v8::EmbedderHeapTracer::IsRootForNonTracingGC()| whether the handle should
821
828
  * be treated as root or not.
822
829
  *
823
- * For destruction semantics see |TracedGlobalTrait<T>|.
830
+ * Note that the base class cannot be instantiated itself. Choose from
831
+ * - TracedGlobal
832
+ * - TracedReference
824
833
  */
825
834
  template <typename T>
826
- class TracedGlobal {
835
+ class TracedReferenceBase {
827
836
  public:
837
+ /**
838
+ * Returns true if this TracedReferenceBase is empty, i.e., has not been
839
+ * assigned an object.
840
+ */
841
+ bool IsEmpty() const { return val_ == nullptr; }
842
+
843
+ /**
844
+ * If non-empty, destroy the underlying storage cell. |IsEmpty| will return
845
+ * true after this call.
846
+ */
847
+ V8_INLINE void Reset();
848
+
849
+ /**
850
+ * Construct a Local<T> from this handle.
851
+ */
852
+ Local<T> Get(Isolate* isolate) const { return Local<T>::New(isolate, *this); }
853
+
854
+ template <class S>
855
+ V8_INLINE bool operator==(const TracedReferenceBase<S>& that) const {
856
+ internal::Address* a = reinterpret_cast<internal::Address*>(val_);
857
+ internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
858
+ if (a == nullptr) return b == nullptr;
859
+ if (b == nullptr) return false;
860
+ return *a == *b;
861
+ }
862
+
863
+ template <class S>
864
+ V8_INLINE bool operator==(const Local<S>& that) const {
865
+ internal::Address* a = reinterpret_cast<internal::Address*>(val_);
866
+ internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
867
+ if (a == nullptr) return b == nullptr;
868
+ if (b == nullptr) return false;
869
+ return *a == *b;
870
+ }
871
+
872
+ template <class S>
873
+ V8_INLINE bool operator!=(const TracedReferenceBase<S>& that) const {
874
+ return !operator==(that);
875
+ }
876
+
877
+ template <class S>
878
+ V8_INLINE bool operator!=(const Local<S>& that) const {
879
+ return !operator==(that);
880
+ }
881
+
882
+ /**
883
+ * Assigns a wrapper class ID to the handle.
884
+ */
885
+ V8_INLINE void SetWrapperClassId(uint16_t class_id);
886
+
887
+ /**
888
+ * Returns the class ID previously assigned to this handle or 0 if no class ID
889
+ * was previously assigned.
890
+ */
891
+ V8_INLINE uint16_t WrapperClassId() const;
892
+
893
+ template <class S>
894
+ V8_INLINE TracedReferenceBase<S>& As() const {
895
+ return reinterpret_cast<TracedReferenceBase<S>&>(
896
+ const_cast<TracedReferenceBase<T>&>(*this));
897
+ }
898
+
899
+ private:
900
+ enum DestructionMode { kWithDestructor, kWithoutDestructor };
901
+
902
+ /**
903
+ * An empty TracedReferenceBase without storage cell.
904
+ */
905
+ TracedReferenceBase() = default;
906
+
907
+ V8_INLINE static T* New(Isolate* isolate, T* that, void* slot,
908
+ DestructionMode destruction_mode);
909
+
910
+ T* val_ = nullptr;
911
+
912
+ friend class EmbedderHeapTracer;
913
+ template <typename F>
914
+ friend class Local;
915
+ friend class Object;
916
+ template <typename F>
917
+ friend class TracedGlobal;
918
+ template <typename F>
919
+ friend class TracedReference;
920
+ template <typename F>
921
+ friend class ReturnValue;
922
+ };
923
+
924
+ /**
925
+ * A traced handle with destructor that clears the handle. For more details see
926
+ * TracedReferenceBase.
927
+ */
928
+ template <typename T>
929
+ class TracedGlobal : public TracedReferenceBase<T> {
930
+ public:
931
+ using TracedReferenceBase<T>::Reset;
932
+
933
+ /**
934
+ * Destructor resetting the handle.
935
+ */
936
+ ~TracedGlobal() { this->Reset(); }
937
+
828
938
  /**
829
939
  * An empty TracedGlobal without storage cell.
830
940
  */
831
- TracedGlobal() = default;
941
+ TracedGlobal() : TracedReferenceBase<T>() {}
832
942
 
833
943
  /**
834
944
  * Construct a TracedGlobal from a Local.
@@ -837,9 +947,10 @@ class TracedGlobal {
837
947
  * pointing to the same object.
838
948
  */
839
949
  template <class S>
840
- TracedGlobal(Isolate* isolate, Local<S> that)
841
- : val_(New(isolate, *that, &val_)) {
842
- TYPE_CHECK(T, S);
950
+ TracedGlobal(Isolate* isolate, Local<S> that) : TracedReferenceBase<T>() {
951
+ this->val_ = this->New(isolate, that.val_, &this->val_,
952
+ TracedReferenceBase<T>::kWithDestructor);
953
+ static_assert(std::is_base_of<T, S>::value, "type check");
843
954
  }
844
955
 
845
956
  /**
@@ -904,18 +1015,6 @@ class TracedGlobal {
904
1015
  template <class S>
905
1016
  V8_INLINE TracedGlobal& operator=(const TracedGlobal<S>& rhs);
906
1017
 
907
- /**
908
- * Returns true if this TracedGlobal is empty, i.e., has not been assigned an
909
- * object.
910
- */
911
- bool IsEmpty() const { return val_ == nullptr; }
912
-
913
- /**
914
- * If non-empty, destroy the underlying storage cell. |IsEmpty| will return
915
- * true after this call.
916
- */
917
- V8_INLINE void Reset();
918
-
919
1018
  /**
920
1019
  * If non-empty, destroy the underlying storage cell and create a new one with
921
1020
  * the contents of other if other is non empty
@@ -923,103 +1022,132 @@ class TracedGlobal {
923
1022
  template <class S>
924
1023
  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
925
1024
 
926
- /**
927
- * Construct a Local<T> from this handle.
928
- */
929
- Local<T> Get(Isolate* isolate) const { return Local<T>::New(isolate, *this); }
930
-
931
1025
  template <class S>
932
1026
  V8_INLINE TracedGlobal<S>& As() const {
933
1027
  return reinterpret_cast<TracedGlobal<S>&>(
934
1028
  const_cast<TracedGlobal<T>&>(*this));
935
1029
  }
936
1030
 
937
- template <class S>
938
- V8_INLINE bool operator==(const TracedGlobal<S>& that) const {
939
- internal::Address* a = reinterpret_cast<internal::Address*>(**this);
940
- internal::Address* b = reinterpret_cast<internal::Address*>(*that);
941
- if (a == nullptr) return b == nullptr;
942
- if (b == nullptr) return false;
943
- return *a == *b;
944
- }
1031
+ /**
1032
+ * Adds a finalization callback to the handle. The type of this callback is
1033
+ * similar to WeakCallbackType::kInternalFields, i.e., it will pass the
1034
+ * parameter and the first two internal fields of the object.
1035
+ *
1036
+ * The callback is then supposed to reset the handle in the callback. No
1037
+ * further V8 API may be called in this callback. In case additional work
1038
+ * involving V8 needs to be done, a second callback can be scheduled using
1039
+ * WeakCallbackInfo<void>::SetSecondPassCallback.
1040
+ */
1041
+ V8_INLINE void SetFinalizationCallback(
1042
+ void* parameter, WeakCallbackInfo<void>::Callback callback);
1043
+ };
945
1044
 
1045
+ /**
1046
+ * A traced handle without destructor that clears the handle. The embedder needs
1047
+ * to ensure that the handle is not accessed once the V8 object has been
1048
+ * reclaimed. This can happen when the handle is not passed through the
1049
+ * EmbedderHeapTracer. For more details see TracedReferenceBase.
1050
+ *
1051
+ * The reference assumes the embedder has precise knowledge about references at
1052
+ * all times. In case V8 needs to separately handle on-stack references, the
1053
+ * embedder is required to set the stack start through
1054
+ * |EmbedderHeapTracer::SetStackStart|.
1055
+ */
1056
+ template <typename T>
1057
+ class TracedReference : public TracedReferenceBase<T> {
1058
+ public:
1059
+ using TracedReferenceBase<T>::Reset;
1060
+
1061
+ /**
1062
+ * An empty TracedReference without storage cell.
1063
+ */
1064
+ TracedReference() : TracedReferenceBase<T>() {}
1065
+
1066
+ /**
1067
+ * Construct a TracedReference from a Local.
1068
+ *
1069
+ * When the Local is non-empty, a new storage cell is created
1070
+ * pointing to the same object.
1071
+ */
946
1072
  template <class S>
947
- V8_INLINE bool operator==(const Local<S>& that) const {
948
- internal::Address* a = reinterpret_cast<internal::Address*>(**this);
949
- internal::Address* b = reinterpret_cast<internal::Address*>(*that);
950
- if (a == nullptr) return b == nullptr;
951
- if (b == nullptr) return false;
952
- return *a == *b;
1073
+ TracedReference(Isolate* isolate, Local<S> that) : TracedReferenceBase<T>() {
1074
+ this->val_ = this->New(isolate, that.val_, &this->val_,
1075
+ TracedReferenceBase<T>::kWithoutDestructor);
1076
+ static_assert(std::is_base_of<T, S>::value, "type check");
953
1077
  }
954
1078
 
955
- template <class S>
956
- V8_INLINE bool operator!=(const TracedGlobal<S>& that) const {
957
- return !operator==(that);
1079
+ /**
1080
+ * Move constructor initializing TracedReference from an
1081
+ * existing one.
1082
+ */
1083
+ V8_INLINE TracedReference(TracedReference&& other) {
1084
+ // Forward to operator=.
1085
+ *this = std::move(other);
958
1086
  }
959
1087
 
960
- template <class S>
961
- V8_INLINE bool operator!=(const Local<S>& that) const {
962
- return !operator==(that);
1088
+ /**
1089
+ * Move constructor initializing TracedReference from an
1090
+ * existing one.
1091
+ */
1092
+ template <typename S>
1093
+ V8_INLINE TracedReference(TracedReference<S>&& other) {
1094
+ // Forward to operator=.
1095
+ *this = std::move(other);
963
1096
  }
964
1097
 
965
1098
  /**
966
- * Assigns a wrapper class ID to the handle.
1099
+ * Copy constructor initializing TracedReference from an
1100
+ * existing one.
967
1101
  */
968
- V8_INLINE void SetWrapperClassId(uint16_t class_id);
1102
+ V8_INLINE TracedReference(const TracedReference& other) {
1103
+ // Forward to operator=;
1104
+ *this = other;
1105
+ }
969
1106
 
970
1107
  /**
971
- * Returns the class ID previously assigned to this handle or 0 if no class ID
972
- * was previously assigned.
1108
+ * Copy constructor initializing TracedReference from an
1109
+ * existing one.
973
1110
  */
974
- V8_INLINE uint16_t WrapperClassId() const;
1111
+ template <typename S>
1112
+ V8_INLINE TracedReference(const TracedReference<S>& other) {
1113
+ // Forward to operator=;
1114
+ *this = other;
1115
+ }
975
1116
 
976
1117
  /**
977
- * Adds a finalization callback to the handle. The type of this callback is
978
- * similar to WeakCallbackType::kInternalFields, i.e., it will pass the
979
- * parameter and the first two internal fields of the object.
980
- *
981
- * The callback is then supposed to reset the handle in the callback. No
982
- * further V8 API may be called in this callback. In case additional work
983
- * involving V8 needs to be done, a second callback can be scheduled using
984
- * WeakCallbackInfo<void>::SetSecondPassCallback.
1118
+ * Move assignment operator initializing TracedGlobal from an existing one.
985
1119
  */
986
- V8_INLINE void SetFinalizationCallback(
987
- void* parameter, WeakCallbackInfo<void>::Callback callback);
1120
+ V8_INLINE TracedReference& operator=(TracedReference&& rhs);
988
1121
 
989
- private:
990
- // Wrapping type used when clearing on destruction is required.
991
- struct WrappedForDestruction {
992
- T* value;
993
-
994
- explicit WrappedForDestruction(T* val) : value(val) {}
995
- ~WrappedForDestruction();
996
- operator T*() const { return value; }
997
- T* operator*() const { return value; }
998
- T* operator->() const { return value; }
999
- WrappedForDestruction& operator=(const WrappedForDestruction& other) {
1000
- value = other.value;
1001
- return *this;
1002
- }
1003
- WrappedForDestruction& operator=(T* val) {
1004
- value = val;
1005
- return *this;
1006
- }
1007
- };
1122
+ /**
1123
+ * Move assignment operator initializing TracedGlobal from an existing one.
1124
+ */
1125
+ template <class S>
1126
+ V8_INLINE TracedReference& operator=(TracedReference<S>&& rhs);
1008
1127
 
1009
- V8_INLINE static T* New(Isolate* isolate, T* that, void* slot);
1128
+ /**
1129
+ * Copy assignment operator initializing TracedGlobal from an existing one.
1130
+ */
1131
+ V8_INLINE TracedReference& operator=(const TracedReference& rhs);
1010
1132
 
1011
- T* operator*() const { return this->val_; }
1133
+ /**
1134
+ * Copy assignment operator initializing TracedGlobal from an existing one.
1135
+ */
1136
+ template <class S>
1137
+ V8_INLINE TracedReference& operator=(const TracedReference<S>& rhs);
1012
1138
 
1013
- typename std::conditional<
1014
- TracedGlobalTrait<TracedGlobal<T>>::kRequiresExplicitDestruction,
1015
- WrappedForDestruction, T*>::type val_{nullptr};
1139
+ /**
1140
+ * If non-empty, destroy the underlying storage cell and create a new one with
1141
+ * the contents of other if other is non empty
1142
+ */
1143
+ template <class S>
1144
+ V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
1016
1145
 
1017
- friend class EmbedderHeapTracer;
1018
- template <typename F>
1019
- friend class Local;
1020
- friend class Object;
1021
- template <typename F>
1022
- friend class ReturnValue;
1146
+ template <class S>
1147
+ V8_INLINE TracedReference<S>& As() const {
1148
+ return reinterpret_cast<TracedReference<S>&>(
1149
+ const_cast<TracedReference<T>&>(*this));
1150
+ }
1023
1151
  };
1024
1152
 
1025
1153
  /**
@@ -1153,9 +1281,8 @@ class V8_EXPORT SealHandleScope {
1153
1281
 
1154
1282
  // --- Special objects ---
1155
1283
 
1156
-
1157
1284
  /**
1158
- * The superclass of values and API object templates.
1285
+ * The superclass of objects that can reside on V8's heap.
1159
1286
  */
1160
1287
  class V8_EXPORT Data {
1161
1288
  private:
@@ -1302,7 +1429,7 @@ class V8_EXPORT UnboundScript {
1302
1429
  /**
1303
1430
  * A compiled JavaScript module, not yet tied to a Context.
1304
1431
  */
1305
- class V8_EXPORT UnboundModuleScript {
1432
+ class V8_EXPORT UnboundModuleScript : public Data {
1306
1433
  // Only used as a container for code caching.
1307
1434
  };
1308
1435
 
@@ -1325,7 +1452,7 @@ class V8_EXPORT Location {
1325
1452
  /**
1326
1453
  * A compiled JavaScript module.
1327
1454
  */
1328
- class V8_EXPORT Module {
1455
+ class V8_EXPORT Module : public Data {
1329
1456
  public:
1330
1457
  /**
1331
1458
  * The different states a module can be in.
@@ -1439,9 +1566,17 @@ class V8_EXPORT Module {
1439
1566
  /**
1440
1567
  * Set this module's exported value for the name export_name to the specified
1441
1568
  * export_value. This method must be called only on Modules created via
1442
- * CreateSyntheticModule. export_name must be one of the export_names that
1443
- * were passed in that CreateSyntheticModule call.
1444
- */
1569
+ * CreateSyntheticModule. An error will be thrown if export_name is not one
1570
+ * of the export_names that were passed in that CreateSyntheticModule call.
1571
+ * Returns Just(true) on success, Nothing<bool>() if an error was thrown.
1572
+ */
1573
+ V8_WARN_UNUSED_RESULT Maybe<bool> SetSyntheticModuleExport(
1574
+ Isolate* isolate, Local<String> export_name, Local<Value> export_value);
1575
+ V8_DEPRECATE_SOON(
1576
+ "Use the preceding SetSyntheticModuleExport with an Isolate parameter, "
1577
+ "instead of the one that follows. The former will throw a runtime "
1578
+ "error if called for an export that doesn't exist (as per spec); "
1579
+ "the latter will crash with a failed CHECK().")
1445
1580
  void SetSyntheticModuleExport(Local<String> export_name,
1446
1581
  Local<Value> export_value);
1447
1582
  };
@@ -1619,8 +1754,8 @@ class V8_EXPORT ScriptCompiler {
1619
1754
 
1620
1755
  V8_DEPRECATE_SOON(
1621
1756
  "This class takes ownership of source_stream, so use the constructor "
1622
- "taking a unique_ptr to make these semantics clearer",
1623
- StreamedSource(ExternalSourceStream* source_stream, Encoding encoding));
1757
+ "taking a unique_ptr to make these semantics clearer")
1758
+ StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1624
1759
  StreamedSource(std::unique_ptr<ExternalSourceStream> source_stream,
1625
1760
  Encoding encoding);
1626
1761
  ~StreamedSource();
@@ -1870,6 +2005,12 @@ class V8_EXPORT Message {
1870
2005
  */
1871
2006
  int GetEndPosition() const;
1872
2007
 
2008
+ /**
2009
+ * Returns the Wasm function index where the error occurred. Returns -1 if
2010
+ * message is not from a Wasm script.
2011
+ */
2012
+ int GetWasmFunctionIndex() const;
2013
+
1873
2014
  /**
1874
2015
  * Returns the error level of the message.
1875
2016
  */
@@ -1902,6 +2043,7 @@ class V8_EXPORT Message {
1902
2043
  static const int kNoLineNumberInfo = 0;
1903
2044
  static const int kNoColumnInfo = 0;
1904
2045
  static const int kNoScriptIdInfo = 0;
2046
+ static const int kNoWasmFunctionIndexInfo = -1;
1905
2047
  };
1906
2048
 
1907
2049
 
@@ -2036,6 +2178,7 @@ enum StateTag {
2036
2178
  COMPILER,
2037
2179
  OTHER,
2038
2180
  EXTERNAL,
2181
+ ATOMICS_WAIT,
2039
2182
  IDLE
2040
2183
  };
2041
2184
 
@@ -2071,6 +2214,14 @@ struct UnwindState {
2071
2214
  MemoryRange code_range;
2072
2215
  MemoryRange embedded_code_range;
2073
2216
  JSEntryStub js_entry_stub;
2217
+ JSEntryStub js_construct_entry_stub;
2218
+ JSEntryStub js_run_microtasks_entry_stub;
2219
+ };
2220
+
2221
+ struct JSEntryStubs {
2222
+ JSEntryStub js_entry_stub;
2223
+ JSEntryStub js_construct_entry_stub;
2224
+ JSEntryStub js_run_microtasks_entry_stub;
2074
2225
  };
2075
2226
 
2076
2227
  /**
@@ -2293,11 +2444,6 @@ class V8_EXPORT ValueDeserializer {
2293
2444
  */
2294
2445
  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
2295
2446
 
2296
- /**
2297
- * Expect inline wasm in the data stream (rather than in-memory transfer)
2298
- */
2299
- void SetExpectInlineWasm(bool allow_inline_wasm);
2300
-
2301
2447
  /**
2302
2448
  * Reads the underlying wire format version. Likely mostly to be useful to
2303
2449
  * legacy code reading old wire format versions. Must be called after
@@ -2335,12 +2481,16 @@ class V8_EXPORT Value : public Data {
2335
2481
  /**
2336
2482
  * Returns true if this value is the undefined value. See ECMA-262
2337
2483
  * 4.3.10.
2484
+ *
2485
+ * This is equivalent to `value === undefined` in JS.
2338
2486
  */
2339
2487
  V8_INLINE bool IsUndefined() const;
2340
2488
 
2341
2489
  /**
2342
2490
  * Returns true if this value is the null value. See ECMA-262
2343
2491
  * 4.3.11.
2492
+ *
2493
+ * This is equivalent to `value === null` in JS.
2344
2494
  */
2345
2495
  V8_INLINE bool IsNull() const;
2346
2496
 
@@ -2348,37 +2498,56 @@ class V8_EXPORT Value : public Data {
2348
2498
  * Returns true if this value is either the null or the undefined value.
2349
2499
  * See ECMA-262
2350
2500
  * 4.3.11. and 4.3.12
2501
+ *
2502
+ * This is equivalent to `value == null` in JS.
2351
2503
  */
2352
2504
  V8_INLINE bool IsNullOrUndefined() const;
2353
2505
 
2354
2506
  /**
2355
- * Returns true if this value is true.
2356
- */
2507
+ * Returns true if this value is true.
2508
+ *
2509
+ * This is not the same as `BooleanValue()`. The latter performs a
2510
+ * conversion to boolean, i.e. the result of `Boolean(value)` in JS, whereas
2511
+ * this checks `value === true`.
2512
+ */
2357
2513
  bool IsTrue() const;
2358
2514
 
2359
2515
  /**
2360
2516
  * Returns true if this value is false.
2517
+ *
2518
+ * This is not the same as `!BooleanValue()`. The latter performs a
2519
+ * conversion to boolean, i.e. the result of `!Boolean(value)` in JS, whereas
2520
+ * this checks `value === false`.
2361
2521
  */
2362
2522
  bool IsFalse() const;
2363
2523
 
2364
2524
  /**
2365
2525
  * Returns true if this value is a symbol or a string.
2526
+ *
2527
+ * This is equivalent to
2528
+ * `typeof value === 'string' || typeof value === 'symbol'` in JS.
2366
2529
  */
2367
2530
  bool IsName() const;
2368
2531
 
2369
2532
  /**
2370
2533
  * Returns true if this value is an instance of the String type.
2371
2534
  * See ECMA-262 8.4.
2535
+ *
2536
+ * This is equivalent to `typeof value === 'string'` in JS.
2372
2537
  */
2373
2538
  V8_INLINE bool IsString() const;
2374
2539
 
2375
2540
  /**
2376
2541
  * Returns true if this value is a symbol.
2542
+ *
2543
+ * This is equivalent to `typeof value === 'symbol'` in JS.
2377
2544
  */
2378
2545
  bool IsSymbol() const;
2379
2546
 
2380
2547
  /**
2381
2548
  * Returns true if this value is a function.
2549
+ *
2550
+ * This is equivalent to `typeof value === 'function'` in JS.
2382
2551
  */
2383
2552
  bool IsFunction() const;
2384
2553
 
@@ -2395,21 +2564,27 @@ class V8_EXPORT Value : public Data {
2395
2564
 
2396
2565
  /**
2397
2566
  * Returns true if this value is a bigint.
2567
+ *
2568
+ * This is equivalent to `typeof value === 'bigint'` in JS.
2398
2569
  */
2399
2570
  bool IsBigInt() const;
2400
2571
 
2401
2572
  /**
2402
2573
  * Returns true if this value is boolean.
2574
+ *
2575
+ * This is equivalent to `typeof value === 'boolean'` in JS.
2403
2576
  */
2404
2577
  bool IsBoolean() const;
2405
2578
 
2406
2579
  /**
2407
2580
  * Returns true if this value is a number.
2581
+ *
2582
+ * This is equivalent to `typeof value === 'number'` in JS.
2408
2583
  */
2409
2584
  bool IsNumber() const;
2410
2585
 
2411
2586
  /**
2412
- * Returns true if this value is external.
2587
+ * Returns true if this value is an `External` object.
2413
2588
  */
2414
2589
  bool IsExternal() const;
2415
2590
 
@@ -2595,7 +2770,6 @@ class V8_EXPORT Value : public Data {
2595
2770
 
2596
2771
  /**
2597
2772
  * Returns true if this value is a SharedArrayBuffer.
2598
- * This is an experimental feature.
2599
2773
  */
2600
2774
  bool IsSharedArrayBuffer() const;
2601
2775
 
@@ -2604,29 +2778,67 @@ class V8_EXPORT Value : public Data {
2604
2778
  */
2605
2779
  bool IsProxy() const;
2606
2780
 
2607
- bool IsWebAssemblyCompiledModule() const;
2781
+ /**
2782
+ * Returns true if this value is a WasmModuleObject.
2783
+ */
2784
+ bool IsWasmModuleObject() const;
2608
2785
 
2609
2786
  /**
2610
2787
  * Returns true if the value is a Module Namespace Object.
2611
2788
  */
2612
2789
  bool IsModuleNamespaceObject() const;
2613
2790
 
2791
+ /**
2792
+ * Perform the equivalent of `BigInt(value)` in JS.
2793
+ */
2614
2794
  V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt(
2615
2795
  Local<Context> context) const;
2796
+ /**
2797
+ * Perform the equivalent of `Number(value)` in JS.
2798
+ */
2616
2799
  V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
2617
2800
  Local<Context> context) const;
2801
+ /**
2802
+ * Perform the equivalent of `String(value)` in JS.
2803
+ */
2618
2804
  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
2619
2805
  Local<Context> context) const;
2806
+ /**
2807
+ * Provide a string representation of this value usable for debugging.
2808
+ * This operation has no observable side effects and will succeed
2809
+ * unless e.g. execution is being terminated.
2810
+ */
2620
2811
  V8_WARN_UNUSED_RESULT MaybeLocal<String> ToDetailString(
2621
2812
  Local<Context> context) const;
2813
+ /**
2814
+ * Perform the equivalent of `Object(value)` in JS.
2815
+ */
2622
2816
  V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
2623
2817
  Local<Context> context) const;
2818
+ /**
2819
+ * Perform the equivalent of `Number(value)` in JS and convert the result
2820
+ * to an integer. Negative values are rounded up, positive values are rounded
2821
+ * down. NaN is converted to 0. Infinite values yield undefined results.
2822
+ */
2624
2823
  V8_WARN_UNUSED_RESULT MaybeLocal<Integer> ToInteger(
2625
2824
  Local<Context> context) const;
2825
+ /**
2826
+ * Perform the equivalent of `Number(value)` in JS and convert the result
2827
+ * to an unsigned 32-bit integer by performing the steps in
2828
+ * https://tc39.es/ecma262/#sec-touint32.
2829
+ */
2626
2830
  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToUint32(
2627
2831
  Local<Context> context) const;
2832
+ /**
2833
+ * Perform the equivalent of `Number(value)` in JS and convert the result
2834
+ * to a signed 32-bit integer by performing the steps in
2835
+ * https://tc39.es/ecma262/#sec-toint32.
2836
+ */
2628
2837
  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
2629
2838
 
2839
+ /**
2840
+ * Perform the equivalent of `Boolean(value)` in JS. This can never fail.
2841
+ */
2630
2842
  Local<Boolean> ToBoolean(Isolate* isolate) const;
2631
2843
 
2632
2844
  /**
@@ -2636,13 +2848,18 @@ class V8_EXPORT Value : public Data {
2636
2848
  V8_WARN_UNUSED_RESULT MaybeLocal<Uint32> ToArrayIndex(
2637
2849
  Local<Context> context) const;
2638
2850
 
2851
+ /** Returns the equivalent of `ToBoolean()->Value()`. */
2639
2852
  bool BooleanValue(Isolate* isolate) const;
2640
2853
 
2854
+ /** Returns the equivalent of `ToNumber()->Value()`. */
2641
2855
  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2856
+ /** Returns the equivalent of `ToInteger()->Value()`. */
2642
2857
  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
2643
2858
  Local<Context> context) const;
2859
+ /** Returns the equivalent of `ToUint32()->Value()`. */
2644
2860
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
2645
2861
  Local<Context> context) const;
2862
+ /** Returns the equivalent of `ToInt32()->Value()`. */
2646
2863
  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2647
2864
 
2648
2865
  /** JS == */
@@ -2734,9 +2951,8 @@ enum class NewStringType {
2734
2951
  */
2735
2952
  class V8_EXPORT String : public Name {
2736
2953
  public:
2737
- static constexpr int kMaxLength = internal::kApiTaggedSize == 4
2738
- ? (1 << 28) - 16
2739
- : internal::kSmiMaxValue / 2 - 24;
2954
+ static constexpr int kMaxLength =
2955
+ internal::kApiSystemPointerSize == 4 ? (1 << 28) - 16 : (1 << 29) - 24;
2740
2956
 
2741
2957
  enum Encoding {
2742
2958
  UNKNOWN_ENCODING = 0x1,
@@ -2957,6 +3173,23 @@ class V8_EXPORT String : public Name {
2957
3173
 
2958
3174
  V8_INLINE static String* Cast(v8::Value* obj);
2959
3175
 
3176
+ /**
3177
+ * Allocates a new string from a UTF-8 literal. This is equivalent to calling
3178
+ * String::NewFromUtf(isolate, "...").ToLocalChecked(), but without the check
3179
+ * overhead.
3180
+ *
3181
+ * When called on a string literal containing '\0', the inferred length is the
3182
+ * length of the input array minus 1 (for the final '\0') and not the value
3183
+ * returned by strlen.
3184
+ **/
3185
+ template <int N>
3186
+ static V8_WARN_UNUSED_RESULT Local<String> NewFromUtf8Literal(
3187
+ Isolate* isolate, const char (&literal)[N],
3188
+ NewStringType type = NewStringType::kNormal) {
3189
+ static_assert(N <= kMaxLength, "String is too long");
3190
+ return NewFromUtf8Literal(isolate, literal, type, N - 1);
3191
+ }
3192
+
2960
3193
  /** Allocates a new string from UTF-8 data. Only returns an empty value when
2961
3194
  * length > kMaxLength. **/
2962
3195
  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
@@ -3091,9 +3324,20 @@ class V8_EXPORT String : public Name {
3091
3324
  ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
3092
3325
  String::Encoding* encoding_out) const;
3093
3326
 
3327
+ static Local<v8::String> NewFromUtf8Literal(Isolate* isolate,
3328
+ const char* literal,
3329
+ NewStringType type, int length);
3330
+
3094
3331
  static void CheckCast(v8::Value* obj);
3095
3332
  };
3096
3333
 
3334
+ // Zero-length string specialization (templated string size includes
3335
+ // terminator).
3336
+ template <>
3337
+ inline V8_WARN_UNUSED_RESULT Local<String> String::NewFromUtf8Literal(
3338
+ Isolate* isolate, const char (&literal)[1], NewStringType type) {
3339
+ return String::Empty(isolate);
3340
+ }
3097
3341
 
3098
3342
  /**
3099
3343
  * A JavaScript symbol (ECMA-262 edition 6)
@@ -3101,30 +3345,35 @@ class V8_EXPORT String : public Name {
3101
3345
  class V8_EXPORT Symbol : public Name {
3102
3346
  public:
3103
3347
  /**
3104
- * Returns the print name string of the symbol, or undefined if none.
3348
+ * Returns the description string of the symbol, or undefined if none.
3105
3349
  */
3106
- Local<Value> Name() const;
3350
+ Local<Value> Description() const;
3351
+
3352
+ V8_DEPRECATE_SOON("Use Symbol::Description()")
3353
+ Local<Value> Name() const { return Description(); }
3107
3354
 
3108
3355
  /**
3109
- * Create a symbol. If name is not empty, it will be used as the description.
3356
+ * Create a symbol. If description is not empty, it will be used as the
3357
+ * description.
3110
3358
  */
3111
3359
  static Local<Symbol> New(Isolate* isolate,
3112
- Local<String> name = Local<String>());
3360
+ Local<String> description = Local<String>());
3113
3361
 
3114
3362
  /**
3115
3363
  * Access global symbol registry.
3116
3364
  * Note that symbols created this way are never collected, so
3117
3365
  * they should only be used for statically fixed properties.
3118
- * Also, there is only one global name space for the names used as keys.
3366
+ * Also, there is only one global name space for the descriptions used as
3367
+ * keys.
3119
3368
  * To minimize the potential for clashes, use qualified names as keys.
3120
3369
  */
3121
- static Local<Symbol> For(Isolate *isolate, Local<String> name);
3370
+ static Local<Symbol> For(Isolate* isolate, Local<String> description);
3122
3371
 
3123
3372
  /**
3124
3373
  * Retrieve a global symbol. Similar to |For|, but using a separate
3125
3374
  * registry that is not accessible by (and cannot clash with) JavaScript code.
3126
3375
  */
3127
- static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
3376
+ static Local<Symbol> ForApi(Isolate* isolate, Local<String> description);
3128
3377
 
3129
3378
  // Well-known symbols
3130
3379
  static Local<Symbol> GetAsyncIterator(Isolate* isolate);
@@ -3396,7 +3645,7 @@ enum class IndexFilter { kIncludeIndices, kSkipIndices };
3396
3645
  * kConvertToString will convert integer indices to strings.
3397
3646
  * kKeepNumbers will return numbers for integer indices.
3398
3647
  */
3399
- enum class KeyConversionMode { kConvertToString, kKeepNumbers };
3648
+ enum class KeyConversionMode { kConvertToString, kKeepNumbers, kNoNumbers };
3400
3649
 
3401
3650
  /**
3402
3651
  * Integrity level for objects.
@@ -3640,8 +3889,9 @@ class V8_EXPORT Object : public Value {
3640
3889
  return object.val_->InternalFieldCount();
3641
3890
  }
3642
3891
 
3643
- /** Same as above, but works for TracedGlobal. */
3644
- V8_INLINE static int InternalFieldCount(const TracedGlobal<Object>& object) {
3892
+ /** Same as above, but works for TracedReferenceBase. */
3893
+ V8_INLINE static int InternalFieldCount(
3894
+ const TracedReferenceBase<Object>& object) {
3645
3895
  return object.val_->InternalFieldCount();
3646
3896
  }
3647
3897
 
@@ -3666,7 +3916,7 @@ class V8_EXPORT Object : public Value {
3666
3916
 
3667
3917
  /** Same as above, but works for TracedGlobal. */
3668
3918
  V8_INLINE static void* GetAlignedPointerFromInternalField(
3669
- const TracedGlobal<Object>& object, int index) {
3919
+ const TracedReferenceBase<Object>& object, int index) {
3670
3920
  return object.val_->GetAlignedPointerFromInternalField(index);
3671
3921
  }
3672
3922
 
@@ -3794,6 +4044,13 @@ class V8_EXPORT Object : public Value {
3794
4044
  */
3795
4045
  bool IsApiWrapper();
3796
4046
 
4047
+ /**
4048
+ * True if this object was created from an object template which was marked
4049
+ * as undetectable. See v8::ObjectTemplate::MarkAsUndetectable for more
4050
+ * information.
4051
+ */
4052
+ bool IsUndetectable();
4053
+
3797
4054
  /**
3798
4055
  * Call an Object as a function if a callback is set by the
3799
4056
  * ObjectTemplate::SetCallAsFunctionHandler method.
@@ -3950,13 +4207,13 @@ class ReturnValue {
3950
4207
  public:
3951
4208
  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3952
4209
  : value_(that.value_) {
3953
- TYPE_CHECK(T, S);
4210
+ static_assert(std::is_base_of<T, S>::value, "type check");
3954
4211
  }
3955
4212
  // Local setters
3956
4213
  template <typename S>
3957
4214
  V8_INLINE void Set(const Global<S>& handle);
3958
4215
  template <typename S>
3959
- V8_INLINE void Set(const TracedGlobal<S>& handle);
4216
+ V8_INLINE void Set(const TracedReferenceBase<S>& handle);
3960
4217
  template <typename S>
3961
4218
  V8_INLINE void Set(const Local<S> handle);
3962
4219
  // Fast primitive setters
@@ -4004,7 +4261,10 @@ class FunctionCallbackInfo {
4004
4261
  public:
4005
4262
  /** The number of available arguments. */
4006
4263
  V8_INLINE int Length() const;
4007
- /** Accessor for the available arguments. */
4264
+ /**
4265
+ * Accessor for the available arguments. Returns `undefined` if the index
4266
+ * is out of bounds.
4267
+ */
4008
4268
  V8_INLINE Local<Value> operator[](int i) const;
4009
4269
  /** Returns the receiver. This corresponds to the "this" value. */
4010
4270
  V8_INLINE Local<Object> This() const;
@@ -4512,46 +4772,14 @@ class V8_EXPORT CompiledWasmModule {
4512
4772
  // An instance of WebAssembly.Module.
4513
4773
  class V8_EXPORT WasmModuleObject : public Object {
4514
4774
  public:
4515
- /**
4516
- * An opaque, native heap object for transferring wasm modules. It
4517
- * supports move semantics, and does not support copy semantics.
4518
- * TODO(wasm): Merge this with CompiledWasmModule once code sharing is always
4519
- * enabled.
4520
- */
4521
- class TransferrableModule final {
4522
- public:
4523
- TransferrableModule(TransferrableModule&& src) = default;
4524
- TransferrableModule(const TransferrableModule& src) = delete;
4525
-
4526
- TransferrableModule& operator=(TransferrableModule&& src) = default;
4527
- TransferrableModule& operator=(const TransferrableModule& src) = delete;
4528
-
4529
- private:
4530
- typedef std::shared_ptr<internal::wasm::NativeModule> SharedModule;
4531
- friend class WasmModuleObject;
4532
- explicit TransferrableModule(SharedModule shared_module)
4533
- : shared_module_(std::move(shared_module)) {}
4534
- TransferrableModule(OwnedBuffer serialized, OwnedBuffer bytes)
4535
- : serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {}
4536
-
4537
- SharedModule shared_module_;
4538
- OwnedBuffer serialized_ = {nullptr, 0};
4539
- OwnedBuffer wire_bytes_ = {nullptr, 0};
4540
- };
4541
-
4542
- /**
4543
- * Get an in-memory, non-persistable, and context-independent (meaning,
4544
- * suitable for transfer to another Isolate and Context) representation
4545
- * of this wasm compiled module.
4546
- */
4547
- TransferrableModule GetTransferrableModule();
4775
+ WasmModuleObject() = delete;
4548
4776
 
4549
4777
  /**
4550
4778
  * Efficiently re-create a WasmModuleObject, without recompiling, from
4551
- * a TransferrableModule.
4779
+ * a CompiledWasmModule.
4552
4780
  */
4553
- static MaybeLocal<WasmModuleObject> FromTransferrableModule(
4554
- Isolate* isolate, const TransferrableModule&);
4781
+ static MaybeLocal<WasmModuleObject> FromCompiledModule(
4782
+ Isolate* isolate, const CompiledWasmModule&);
4555
4783
 
4556
4784
  /**
4557
4785
  * Get the compiled module for this module object. The compiled module can be
@@ -4559,27 +4787,9 @@ class V8_EXPORT WasmModuleObject : public Object {
4559
4787
  */
4560
4788
  CompiledWasmModule GetCompiledModule();
4561
4789
 
4562
- /**
4563
- * If possible, deserialize the module, otherwise compile it from the provided
4564
- * uncompiled bytes.
4565
- */
4566
- static MaybeLocal<WasmModuleObject> DeserializeOrCompile(
4567
- Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
4568
- MemorySpan<const uint8_t> wire_bytes);
4569
4790
  V8_INLINE static WasmModuleObject* Cast(Value* obj);
4570
4791
 
4571
4792
  private:
4572
- static MaybeLocal<WasmModuleObject> Deserialize(
4573
- Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
4574
- MemorySpan<const uint8_t> wire_bytes);
4575
- static MaybeLocal<WasmModuleObject> Compile(Isolate* isolate,
4576
- const uint8_t* start,
4577
- size_t length);
4578
- static MemorySpan<const uint8_t> AsReference(const OwnedBuffer& buff) {
4579
- return {buff.buffer.get(), buff.size};
4580
- }
4581
-
4582
- WasmModuleObject();
4583
4793
  static void CheckCast(Value* obj);
4584
4794
  };
4585
4795
 
@@ -4645,6 +4855,12 @@ class V8_EXPORT WasmStreaming final {
4645
4855
  */
4646
4856
  void SetClient(std::shared_ptr<Client> client);
4647
4857
 
4858
+ /*
4859
+ * Sets the UTF-8 encoded source URL for the {Script} object. This must be
4860
+ * called before {Finish}.
4861
+ */
4862
+ void SetUrl(const char* url, size_t length);
4863
+
4648
4864
  /**
4649
4865
  * Unpacks a {WasmStreaming} object wrapped in a {Managed} for the embedder.
4650
4866
  * Since the embedder is on the other side of the API, it cannot unpack the
@@ -4711,6 +4927,83 @@ class V8_EXPORT WasmModuleObjectBuilderStreaming final {
4711
4927
 
4712
4928
  enum class ArrayBufferCreationMode { kInternalized, kExternalized };
4713
4929
 
4930
+ /**
4931
+ * A wrapper around the backing store (i.e. the raw memory) of an array buffer.
4932
+ * See a document linked in http://crbug.com/v8/9908 for more information.
4933
+ *
4934
+ * The allocation and destruction of backing stores is generally managed by
4935
+ * V8. Clients should always use standard C++ memory ownership types (i.e.
4936
+ * std::unique_ptr and std::shared_ptr) to manage lifetimes of backing stores
4937
+ * properly, since V8 internal objects may alias backing stores.
4938
+ *
4939
+ * This object does not keep the underlying |ArrayBuffer::Allocator| alive by
4940
+ * default. Use Isolate::CreateParams::array_buffer_allocator_shared when
4941
+ * creating the Isolate to make it hold a reference to the allocator itself.
4942
+ */
4943
+ class V8_EXPORT BackingStore : public v8::internal::BackingStoreBase {
4944
+ public:
4945
+ ~BackingStore();
4946
+
4947
+ /**
4948
+ * Return a pointer to the beginning of the memory block for this backing
4949
+ * store. The pointer is only valid as long as this backing store object
4950
+ * lives.
4951
+ */
4952
+ void* Data() const;
4953
+
4954
+ /**
4955
+ * The length (in bytes) of this backing store.
4956
+ */
4957
+ size_t ByteLength() const;
4958
+
4959
+ /**
4960
+ * Indicates whether the backing store was created for an ArrayBuffer or
4961
+ * a SharedArrayBuffer.
4962
+ */
4963
+ bool IsShared() const;
4964
+
4965
+ /**
4966
+ * Wrapper around ArrayBuffer::Allocator::Reallocate that preserves IsShared.
4967
+ * Assumes that the backing_store was allocated by the ArrayBuffer allocator
4968
+ * of the given isolate.
4969
+ */
4970
+ static std::unique_ptr<BackingStore> Reallocate(
4971
+ v8::Isolate* isolate, std::unique_ptr<BackingStore> backing_store,
4972
+ size_t byte_length);
4973
+
4974
+ /**
4975
+ * This callback is used only if the memory block for a BackingStore cannot be
4976
+ * allocated with an ArrayBuffer::Allocator. In such cases the destructor of
4977
+ * the BackingStore invokes the callback to free the memory block.
4978
+ */
4979
+ using DeleterCallback = void (*)(void* data, size_t length,
4980
+ void* deleter_data);
4981
+
4982
+ /**
4983
+ * If the memory block of a BackingStore is static or is managed manually,
4984
+ * then this empty deleter along with nullptr deleter_data can be passed to
4985
+ * ArrayBuffer::NewBackingStore to indicate that.
4986
+ *
4987
+ * The manually managed case should be used with caution and only when it
4988
+ * is guaranteed that the memory block freeing happens after detaching its
4989
+ * ArrayBuffer.
4990
+ */
4991
+ static void EmptyDeleter(void* data, size_t length, void* deleter_data);
4992
+
4993
+ private:
4994
+ /**
4995
+ * See [Shared]ArrayBuffer::GetBackingStore and
4996
+ * [Shared]ArrayBuffer::NewBackingStore.
4997
+ */
4998
+ BackingStore();
4999
+ };
5000
+
5001
+ #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
5002
+ // Use v8::BackingStore::DeleterCallback instead.
5003
+ using BackingStoreDeleterCallback = void (*)(void* data, size_t length,
5004
+ void* deleter_data);
5005
+
5006
+ #endif
4714
5007
 
4715
5008
  /**
4716
5009
  * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
@@ -4737,13 +5030,13 @@ class V8_EXPORT ArrayBuffer : public Object {
4737
5030
  virtual ~Allocator() = default;
4738
5031
 
4739
5032
  /**
4740
- * Allocate |length| bytes. Return NULL if allocation is not successful.
5033
+ * Allocate |length| bytes. Return nullptr if allocation is not successful.
4741
5034
  * Memory should be initialized to zeroes.
4742
5035
  */
4743
5036
  virtual void* Allocate(size_t length) = 0;
4744
5037
 
4745
5038
  /**
4746
- * Allocate |length| bytes. Return NULL if allocation is not successful.
5039
+ * Allocate |length| bytes. Return nullptr if allocation is not successful.
4747
5040
  * Memory does not have to be initialized.
4748
5041
  */
4749
5042
  virtual void* AllocateUninitialized(size_t length) = 0;
@@ -4754,6 +5047,20 @@ class V8_EXPORT ArrayBuffer : public Object {
4754
5047
  */
4755
5048
  virtual void Free(void* data, size_t length) = 0;
4756
5049
 
5050
+ /**
5051
+ * Reallocate the memory block of size |old_length| to a memory block of
5052
+ * size |new_length| by expanding, contracting, or copying the existing
5053
+ * memory block. If |new_length| > |old_length|, then the new part of
5054
+ * the memory must be initialized to zeros. Return nullptr if reallocation
5055
+ * is not successful.
5056
+ *
5057
+ * The caller guarantees that the memory block was previously allocated
5058
+ * using Allocate or AllocateUninitialized.
5059
+ *
5060
+ * The default implementation allocates a new block and copies data.
5061
+ */
5062
+ virtual void* Reallocate(void* data, size_t old_length, size_t new_length);
5063
+
4757
5064
  /**
4758
5065
  * ArrayBuffer allocation mode. kNormal is a malloc/free style allocation,
4759
5066
  * while kReservation is for larger allocations with the ability to set
@@ -4843,14 +5150,58 @@ class V8_EXPORT ArrayBuffer : public Object {
4843
5150
  * |Allocator::Free| once all ArrayBuffers referencing it are collected by
4844
5151
  * the garbage collector.
4845
5152
  */
5153
+ V8_DEPRECATE_SOON(
5154
+ "Use the version that takes a BackingStore. "
5155
+ "See http://crbug.com/v8/9908.")
4846
5156
  static Local<ArrayBuffer> New(
4847
5157
  Isolate* isolate, void* data, size_t byte_length,
4848
5158
  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
4849
5159
 
5160
+ /**
5161
+ * Create a new ArrayBuffer with an existing backing store.
5162
+ * The created array keeps a reference to the backing store until the array
5163
+ * is garbage collected. Note that the IsExternal bit does not affect this
5164
+ * reference from the array to the backing store.
5165
+ *
5166
+ * In future IsExternal bit will be removed. Until then the bit is set as
5167
+ * follows. If the backing store does not own the underlying buffer, then
5168
+ * the array is created in externalized state. Otherwise, the array is created
5169
+ * in internalized state. In the latter case the array can be transitioned
5170
+ * to the externalized state using Externalize(backing_store).
5171
+ */
5172
+ static Local<ArrayBuffer> New(Isolate* isolate,
5173
+ std::shared_ptr<BackingStore> backing_store);
5174
+
5175
+ /**
5176
+ * Returns a new standalone BackingStore that is allocated using the array
5177
+ * buffer allocator of the isolate. The result can be later passed to
5178
+ * ArrayBuffer::New.
5179
+ *
5180
+ * If the allocator returns nullptr, then the function may cause GCs in the
5181
+ * given isolate and re-try the allocation. If GCs do not help, then the
5182
+ * function will crash with an out-of-memory error.
5183
+ */
5184
+ static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate,
5185
+ size_t byte_length);
5186
+ /**
5187
+ * Returns a new standalone BackingStore that takes over the ownership of
5188
+ * the given buffer. The destructor of the BackingStore invokes the given
5189
+ * deleter callback.
5190
+ *
5191
+ * The result can be later passed to ArrayBuffer::New. The raw pointer
5192
+ * to the buffer must not be passed again to any V8 API function.
5193
+ */
5194
+ static std::unique_ptr<BackingStore> NewBackingStore(
5195
+ void* data, size_t byte_length, v8::BackingStore::DeleterCallback deleter,
5196
+ void* deleter_data);
5197
+
4850
5198
  /**
4851
5199
  * Returns true if ArrayBuffer is externalized, that is, does not
4852
5200
  * own its memory block.
4853
5201
  */
5202
+ V8_DEPRECATE_SOON(
5203
+ "With v8::BackingStore externalized ArrayBuffers are "
5204
+ "the same as ordinary ArrayBuffers. See http://crbug.com/v8/9908.")
4854
5205
  bool IsExternal() const;
4855
5206
 
4856
5207
  /**
@@ -4858,12 +5209,6 @@ class V8_EXPORT ArrayBuffer : public Object {
4858
5209
  */
4859
5210
  bool IsDetachable() const;
4860
5211
 
4861
- // TODO(913887): fix the use of 'neuter' in the API.
4862
- V8_DEPRECATED("Use IsDetachable() instead.",
4863
- inline bool IsNeuterable() const) {
4864
- return IsDetachable();
4865
- }
4866
-
4867
5212
  /**
4868
5213
  * Detaches this ArrayBuffer and all its views (typed arrays).
4869
5214
  * Detaching sets the byte length of the buffer and all typed arrays to zero,
@@ -4872,9 +5217,6 @@ class V8_EXPORT ArrayBuffer : public Object {
4872
5217
  */
4873
5218
  void Detach();
4874
5219
 
4875
- // TODO(913887): fix the use of 'neuter' in the API.
4876
- V8_DEPRECATED("Use Detach() instead.", inline void Neuter()) { Detach(); }
4877
-
4878
5220
  /**
4879
5221
  * Make this ArrayBuffer external. The pointer to underlying memory block
4880
5222
  * and byte length are returned as |Contents| structure. After ArrayBuffer
@@ -4883,10 +5225,22 @@ class V8_EXPORT ArrayBuffer : public Object {
4883
5225
  *
4884
5226
  * The Data pointer of ArrayBuffer::Contents must be freed using the provided
4885
5227
  * deleter, which will call ArrayBuffer::Allocator::Free if the buffer
4886
- * was allocated with ArraryBuffer::Allocator::Allocate.
5228
+ * was allocated with ArrayBuffer::Allocator::Allocate.
4887
5229
  */
5230
+ V8_DEPRECATE_SOON(
5231
+ "Use GetBackingStore or Detach. See http://crbug.com/v8/9908.")
4888
5232
  Contents Externalize();
4889
5233
 
5234
+ /**
5235
+ * Marks this ArrayBuffer external given a witness that the embedder
5236
+ * has fetched the backing store using the new GetBackingStore() function.
5237
+ *
5238
+ * With the new lifetime management of backing stores there is no need for
5239
+ * externalizing, so this function exists only to make the transition easier.
5240
+ */
5241
+ V8_DEPRECATE_SOON("This will be removed together with IsExternal.")
5242
+ void Externalize(const std::shared_ptr<BackingStore>& backing_store);
5243
+
4890
5244
  /**
4891
5245
  * Get a pointer to the ArrayBuffer's underlying memory block without
4892
5246
  * externalizing it. If the ArrayBuffer is not externalized, this pointer
@@ -4895,8 +5249,19 @@ class V8_EXPORT ArrayBuffer : public Object {
4895
5249
  * The embedder should make sure to hold a strong reference to the
4896
5250
  * ArrayBuffer while accessing this pointer.
4897
5251
  */
5252
+ V8_DEPRECATE_SOON("Use GetBackingStore. See http://crbug.com/v8/9908.")
4898
5253
  Contents GetContents();
4899
5254
 
5255
+ /**
5256
+ * Get a shared pointer to the backing store of this array buffer. This
5257
+ * pointer coordinates the lifetime management of the internal storage
5258
+ * with any live ArrayBuffers on the heap, even across isolates. The embedder
5259
+ * should not attempt to manage lifetime of the storage through other means.
5260
+ *
5261
+ * This function replaces both Externalize() and GetContents().
5262
+ */
5263
+ std::shared_ptr<BackingStore> GetBackingStore();
5264
+
4900
5265
  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4901
5266
 
4902
5267
  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
@@ -4905,6 +5270,7 @@ class V8_EXPORT ArrayBuffer : public Object {
4905
5270
  private:
4906
5271
  ArrayBuffer();
4907
5272
  static void CheckCast(Value* obj);
5273
+ Contents GetContents(bool externalize);
4908
5274
  };
4909
5275
 
4910
5276
 
@@ -4972,7 +5338,9 @@ class V8_EXPORT TypedArray : public ArrayBufferView {
4972
5338
  /*
4973
5339
  * The largest typed array size that can be constructed using New.
4974
5340
  */
4975
- static constexpr size_t kMaxLength = internal::kSmiMaxValue;
5341
+ static constexpr size_t kMaxLength = internal::kApiSystemPointerSize == 4
5342
+ ? internal::kSmiMaxValue
5343
+ : 0xFFFFFFFF;
4976
5344
 
4977
5345
  /**
4978
5346
  * Number of elements in this typed array
@@ -5191,7 +5559,6 @@ class V8_EXPORT DataView : public ArrayBufferView {
5191
5559
 
5192
5560
  /**
5193
5561
  * An instance of the built-in SharedArrayBuffer constructor.
5194
- * This API is experimental and may change significantly.
5195
5562
  */
5196
5563
  class V8_EXPORT SharedArrayBuffer : public Object {
5197
5564
  public:
@@ -5203,8 +5570,6 @@ class V8_EXPORT SharedArrayBuffer : public Object {
5203
5570
  * The Data pointer of ArrayBuffer::Contents must be freed using the provided
5204
5571
  * deleter, which will call ArrayBuffer::Allocator::Free if the buffer
5205
5572
  * was allocated with ArraryBuffer::Allocator::Allocate.
5206
- *
5207
- * This API is experimental and may change significantly.
5208
5573
  */
5209
5574
  class V8_EXPORT Contents { // NOLINT
5210
5575
  public:
@@ -5267,24 +5632,69 @@ class V8_EXPORT SharedArrayBuffer : public Object {
5267
5632
  * specified. The memory block will not be reclaimed when a created
5268
5633
  * SharedArrayBuffer is garbage-collected.
5269
5634
  */
5635
+ V8_DEPRECATE_SOON(
5636
+ "Use the version that takes a BackingStore. "
5637
+ "See http://crbug.com/v8/9908.")
5270
5638
  static Local<SharedArrayBuffer> New(
5271
5639
  Isolate* isolate, void* data, size_t byte_length,
5272
5640
  ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
5273
5641
 
5642
+ /**
5643
+ * Create a new SharedArrayBuffer with an existing backing store.
5644
+ * The created array keeps a reference to the backing store until the array
5645
+ * is garbage collected. Note that the IsExternal bit does not affect this
5646
+ * reference from the array to the backing store.
5647
+ *
5648
+ * In future IsExternal bit will be removed. Until then the bit is set as
5649
+ * follows. If the backing store does not own the underlying buffer, then
5650
+ * the array is created in externalized state. Otherwise, the array is created
5651
+ * in internalized state. In the latter case the array can be transitioned
5652
+ * to the externalized state using Externalize(backing_store).
5653
+ */
5654
+ static Local<SharedArrayBuffer> New(
5655
+ Isolate* isolate, std::shared_ptr<BackingStore> backing_store);
5656
+
5657
+ /**
5658
+ * Returns a new standalone BackingStore that is allocated using the array
5659
+ * buffer allocator of the isolate. The result can be later passed to
5660
+ * SharedArrayBuffer::New.
5661
+ *
5662
+ * If the allocator returns nullptr, then the function may cause GCs in the
5663
+ * given isolate and re-try the allocation. If GCs do not help, then the
5664
+ * function will crash with an out-of-memory error.
5665
+ */
5666
+ static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate,
5667
+ size_t byte_length);
5668
+ /**
5669
+ * Returns a new standalone BackingStore that takes over the ownership of
5670
+ * the given buffer. The destructor of the BackingStore invokes the given
5671
+ * deleter callback.
5672
+ *
5673
+ * The result can be later passed to SharedArrayBuffer::New. The raw pointer
5674
+ * to the buffer must not be passed again to any V8 functions.
5675
+ */
5676
+ static std::unique_ptr<BackingStore> NewBackingStore(
5677
+ void* data, size_t byte_length, v8::BackingStore::DeleterCallback deleter,
5678
+ void* deleter_data);
5679
+
5274
5680
  /**
5275
5681
  * Create a new SharedArrayBuffer over an existing memory block. Propagate
5276
5682
  * flags to indicate whether the underlying buffer can be grown.
5277
5683
  */
5278
- V8_DEPRECATED("Use New method with data, and byte_length instead.",
5279
- static Local<SharedArrayBuffer> New(
5280
- Isolate* isolate, const SharedArrayBuffer::Contents&,
5281
- ArrayBufferCreationMode mode =
5282
- ArrayBufferCreationMode::kExternalized));
5684
+ V8_DEPRECATED(
5685
+ "Use the version that takes a BackingStore. "
5686
+ "See http://crbug.com/v8/9908.")
5687
+ static Local<SharedArrayBuffer> New(
5688
+ Isolate* isolate, const SharedArrayBuffer::Contents&,
5689
+ ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized);
5283
5690
 
5284
5691
  /**
5285
5692
  * Returns true if SharedArrayBuffer is externalized, that is, does not
5286
5693
  * own its memory block.
5287
5694
  */
5695
+ V8_DEPRECATE_SOON(
5696
+ "With v8::BackingStore externalized SharedArrayBuffers are the same "
5697
+ "as ordinary SharedArrayBuffers. See http://crbug.com/v8/9908.")
5288
5698
  bool IsExternal() const;
5289
5699
 
5290
5700
  /**
@@ -5299,8 +5709,20 @@ class V8_EXPORT SharedArrayBuffer : public Object {
5299
5709
  * v8::Isolate::CreateParams::array_buffer_allocator.
5300
5710
  *
5301
5711
  */
5712
+ V8_DEPRECATE_SOON(
5713
+ "Use GetBackingStore or Detach. See http://crbug.com/v8/9908.")
5302
5714
  Contents Externalize();
5303
5715
 
5716
+ /**
5717
+ * Marks this SharedArrayBuffer external given a witness that the embedder
5718
+ * has fetched the backing store using the new GetBackingStore() function.
5719
+ *
5720
+ * With the new lifetime management of backing stores there is no need for
5721
+ * externalizing, so this function exists only to make the transition easier.
5722
+ */
5723
+ V8_DEPRECATE_SOON("This will be removed together with IsExternal.")
5724
+ void Externalize(const std::shared_ptr<BackingStore>& backing_store);
5725
+
5304
5726
  /**
5305
5727
  * Get a pointer to the ArrayBuffer's underlying memory block without
5306
5728
  * externalizing it. If the ArrayBuffer is not externalized, this pointer
@@ -5313,8 +5735,19 @@ class V8_EXPORT SharedArrayBuffer : public Object {
5313
5735
  * by the allocator specified in
5314
5736
  * v8::Isolate::CreateParams::array_buffer_allocator.
5315
5737
  */
5738
+ V8_DEPRECATE_SOON("Use GetBackingStore. See http://crbug.com/v8/9908.")
5316
5739
  Contents GetContents();
5317
5740
 
5741
+ /**
5742
+ * Get a shared pointer to the backing store of this array buffer. This
5743
+ * pointer coordinates the lifetime management of the internal storage
5744
+ * with any live ArrayBuffers on the heap, even across isolates. The embedder
5745
+ * should not attempt to manage lifetime of the storage through other means.
5746
+ *
5747
+ * This function replaces both Externalize() and GetContents().
5748
+ */
5749
+ std::shared_ptr<BackingStore> GetBackingStore();
5750
+
5318
5751
  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
5319
5752
 
5320
5753
  static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
@@ -5322,6 +5755,7 @@ class V8_EXPORT SharedArrayBuffer : public Object {
5322
5755
  private:
5323
5756
  SharedArrayBuffer();
5324
5757
  static void CheckCast(Value* obj);
5758
+ Contents GetContents(bool externalize);
5325
5759
  };
5326
5760
 
5327
5761
 
@@ -5459,6 +5893,29 @@ class V8_EXPORT RegExp : public Object {
5459
5893
  Local<String> pattern,
5460
5894
  Flags flags);
5461
5895
 
5896
+ /**
5897
+ * Like New, but additionally specifies a backtrack limit. If the number of
5898
+ * backtracks done in one Exec call hits the limit, a match failure is
5899
+ * immediately returned.
5900
+ */
5901
+ static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> NewWithBacktrackLimit(
5902
+ Local<Context> context, Local<String> pattern, Flags flags,
5903
+ uint32_t backtrack_limit);
5904
+
5905
+ /**
5906
+ * Executes the current RegExp instance on the given subject string.
5907
+ * Equivalent to RegExp.prototype.exec as described in
5908
+ *
5909
+ * https://tc39.es/ecma262/#sec-regexp.prototype.exec
5910
+ *
5911
+ * On success, an Array containing the matched strings is returned. On
5912
+ * failure, returns Null.
5913
+ *
5914
+ * Note: modifies global context state, accessible e.g. through RegExp.input.
5915
+ */
5916
+ V8_WARN_UNUSED_RESULT MaybeLocal<Object> Exec(Local<Context> context,
5917
+ Local<String> subject);
5918
+
5462
5919
  /**
5463
5920
  * Returns the value of the source property: a string representing
5464
5921
  * the regular expression.
@@ -5476,33 +5933,6 @@ class V8_EXPORT RegExp : public Object {
5476
5933
  static void CheckCast(Value* obj);
5477
5934
  };
5478
5935
 
5479
- /**
5480
- * An instance of the built-in FinalizationGroup constructor.
5481
- *
5482
- * This API is experimental and may change significantly.
5483
- */
5484
- class V8_EXPORT FinalizationGroup : public Object {
5485
- public:
5486
- /**
5487
- * Runs the cleanup callback of the given FinalizationGroup.
5488
- *
5489
- * V8 will inform the embedder that there are finalizer callbacks be
5490
- * called through HostCleanupFinalizationGroupCallback.
5491
- *
5492
- * HostCleanupFinalizationGroupCallback should schedule a task to
5493
- * call FinalizationGroup::Cleanup() at some point in the
5494
- * future. It's the embedders responsiblity to make this call at a
5495
- * time which does not interrupt synchronous ECMAScript code
5496
- * execution.
5497
- *
5498
- * If the result is Nothing<bool> then an exception has
5499
- * occurred. Otherwise the result is |true| if the cleanup callback
5500
- * was called successfully. The result is never |false|.
5501
- */
5502
- static V8_WARN_UNUSED_RESULT Maybe<bool> Cleanup(
5503
- Local<FinalizationGroup> finalization_group);
5504
- };
5505
-
5506
5936
  /**
5507
5937
  * A JavaScript value that wraps a C++ void*. This type of value is mainly used
5508
5938
  * to associate C++ data structures with JavaScript objects.
@@ -5516,13 +5946,14 @@ class V8_EXPORT External : public Value {
5516
5946
  static void CheckCast(v8::Value* obj);
5517
5947
  };
5518
5948
 
5519
- #define V8_INTRINSICS_LIST(F) \
5520
- F(ArrayProto_entries, array_entries_iterator) \
5521
- F(ArrayProto_forEach, array_for_each_iterator) \
5522
- F(ArrayProto_keys, array_keys_iterator) \
5523
- F(ArrayProto_values, array_values_iterator) \
5524
- F(ErrorPrototype, initial_error_prototype) \
5525
- F(IteratorPrototype, initial_iterator_prototype)
5949
+ #define V8_INTRINSICS_LIST(F) \
5950
+ F(ArrayProto_entries, array_entries_iterator) \
5951
+ F(ArrayProto_forEach, array_for_each_iterator) \
5952
+ F(ArrayProto_keys, array_keys_iterator) \
5953
+ F(ArrayProto_values, array_values_iterator) \
5954
+ F(ErrorPrototype, initial_error_prototype) \
5955
+ F(IteratorPrototype, initial_iterator_prototype) \
5956
+ F(ObjProto_valueOf, object_value_of_function)
5526
5957
 
5527
5958
  enum Intrinsic {
5528
5959
  #define V8_DECL_INTRINSIC(name, iname) k##name,
@@ -5868,6 +6299,7 @@ typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5868
6299
  Local<Object> accessed_object,
5869
6300
  Local<Value> data);
5870
6301
 
6302
+ class CFunction;
5871
6303
  /**
5872
6304
  * A FunctionTemplate is used to create functions at runtime. There
5873
6305
  * can only be one function created from a FunctionTemplate in a
@@ -5903,11 +6335,12 @@ typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5903
6335
  * proto_t->Set(isolate, "proto_const", v8::Number::New(isolate, 2));
5904
6336
  *
5905
6337
  * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
5906
- * instance_t->SetAccessor(String::NewFromUtf8(isolate, "instance_accessor"),
5907
- * InstanceAccessorCallback);
6338
+ * instance_t->SetAccessor(
6339
+ String::NewFromUtf8Literal(isolate, "instance_accessor"),
6340
+ * InstanceAccessorCallback);
5908
6341
  * instance_t->SetHandler(
5909
6342
  * NamedPropertyHandlerConfiguration(PropertyHandlerCallback));
5910
- * instance_t->Set(String::NewFromUtf8(isolate, "instance_property"),
6343
+ * instance_t->Set(String::NewFromUtf8Literal(isolate, "instance_property"),
5911
6344
  * Number::New(isolate, 3));
5912
6345
  *
5913
6346
  * v8::Local<v8::Function> function = t->GetFunction();
@@ -5967,6 +6400,12 @@ typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5967
6400
  * child_instance.instance_accessor calls 'InstanceAccessorCallback'
5968
6401
  * child_instance.instance_property == 3;
5969
6402
  * \endcode
6403
+ *
6404
+ * The additional 'c_function' parameter refers to a fast API call, which
6405
+ * must not trigger GC or JavaScript execution, or call into V8 in other
6406
+ * ways. For more information how to define them, see
6407
+ * include/v8-fast-api-calls.h. Please note that this feature is still
6408
+ * experimental.
5970
6409
  */
5971
6410
  class V8_EXPORT FunctionTemplate : public Template {
5972
6411
  public:
@@ -5976,11 +6415,8 @@ class V8_EXPORT FunctionTemplate : public Template {
5976
6415
  Local<Value> data = Local<Value>(),
5977
6416
  Local<Signature> signature = Local<Signature>(), int length = 0,
5978
6417
  ConstructorBehavior behavior = ConstructorBehavior::kAllow,
5979
- SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
5980
-
5981
- /** Get a template included in the snapshot by index. */
5982
- static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5983
- size_t index);
6418
+ SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
6419
+ const CFunction* c_function = nullptr);
5984
6420
 
5985
6421
  /**
5986
6422
  * Creates a function template backed/cached by a private property.
@@ -6007,11 +6443,13 @@ class V8_EXPORT FunctionTemplate : public Template {
6007
6443
  /**
6008
6444
  * Set the call-handler callback for a FunctionTemplate. This
6009
6445
  * callback is called whenever the function created from this
6010
- * FunctionTemplate is called.
6446
+ * FunctionTemplate is called. The 'c_function' represents a fast
6447
+ * API call, see the comment above the class declaration.
6011
6448
  */
6012
6449
  void SetCallHandler(
6013
6450
  FunctionCallback callback, Local<Value> data = Local<Value>(),
6014
- SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
6451
+ SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
6452
+ const CFunction* c_function = nullptr);
6015
6453
 
6016
6454
  /** Set the predefined length property for the FunctionTemplate. */
6017
6455
  void SetLength(int length);
@@ -6269,10 +6707,6 @@ class V8_EXPORT ObjectTemplate : public Template {
6269
6707
  Isolate* isolate,
6270
6708
  Local<FunctionTemplate> constructor = Local<FunctionTemplate>());
6271
6709
 
6272
- /** Get a template included in the snapshot by index. */
6273
- static MaybeLocal<ObjectTemplate> FromSnapshot(Isolate* isolate,
6274
- size_t index);
6275
-
6276
6710
  /** Creates a new instance of this template.*/
6277
6711
  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
6278
6712
 
@@ -6646,34 +7080,26 @@ class V8_EXPORT ResourceConstraints {
6646
7080
  /**
6647
7081
  * Deprecated functions. Do not use in new code.
6648
7082
  */
6649
- V8_DEPRECATE_SOON("Use code_range_size_in_bytes.",
6650
- size_t code_range_size() const) {
6651
- return code_range_size_ / kMB;
6652
- }
6653
- V8_DEPRECATE_SOON("Use set_code_range_size_in_bytes.",
6654
- void set_code_range_size(size_t limit_in_mb)) {
7083
+ V8_DEPRECATE_SOON("Use code_range_size_in_bytes.")
7084
+ size_t code_range_size() const { return code_range_size_ / kMB; }
7085
+ V8_DEPRECATE_SOON("Use set_code_range_size_in_bytes.")
7086
+ void set_code_range_size(size_t limit_in_mb) {
6655
7087
  code_range_size_ = limit_in_mb * kMB;
6656
7088
  }
6657
- V8_DEPRECATE_SOON("Use max_young_generation_size_in_bytes.",
6658
- size_t max_semi_space_size_in_kb() const);
6659
- V8_DEPRECATE_SOON("Use set_max_young_generation_size_in_bytes.",
6660
- void set_max_semi_space_size_in_kb(size_t limit_in_kb));
6661
- V8_DEPRECATE_SOON("Use max_old_generation_size_in_bytes.",
6662
- size_t max_old_space_size() const) {
6663
- return max_old_generation_size_ / kMB;
6664
- }
6665
- V8_DEPRECATE_SOON("Use set_max_old_generation_size_in_bytes.",
6666
- void set_max_old_space_size(size_t limit_in_mb)) {
7089
+ V8_DEPRECATE_SOON("Use max_young_generation_size_in_bytes.")
7090
+ size_t max_semi_space_size_in_kb() const;
7091
+ V8_DEPRECATE_SOON("Use set_max_young_generation_size_in_bytes.")
7092
+ void set_max_semi_space_size_in_kb(size_t limit_in_kb);
7093
+ V8_DEPRECATE_SOON("Use max_old_generation_size_in_bytes.")
7094
+ size_t max_old_space_size() const { return max_old_generation_size_ / kMB; }
7095
+ V8_DEPRECATE_SOON("Use set_max_old_generation_size_in_bytes.")
7096
+ void set_max_old_space_size(size_t limit_in_mb) {
6667
7097
  max_old_generation_size_ = limit_in_mb * kMB;
6668
7098
  }
6669
- V8_DEPRECATE_SOON("Zone does not pool memory any more.",
6670
- size_t max_zone_pool_size() const) {
6671
- return max_zone_pool_size_;
6672
- }
6673
- V8_DEPRECATE_SOON("Zone does not pool memory any more.",
6674
- void set_max_zone_pool_size(size_t bytes)) {
6675
- max_zone_pool_size_ = bytes;
6676
- }
7099
+ V8_DEPRECATE_SOON("Zone does not pool memory any more.")
7100
+ size_t max_zone_pool_size() const { return max_zone_pool_size_; }
7101
+ V8_DEPRECATE_SOON("Zone does not pool memory any more.")
7102
+ void set_max_zone_pool_size(size_t bytes) { max_zone_pool_size_ = bytes; }
6677
7103
 
6678
7104
  private:
6679
7105
  static constexpr size_t kMB = 1048576u;
@@ -6713,6 +7139,9 @@ class V8_EXPORT Exception {
6713
7139
  static Local<Value> ReferenceError(Local<String> message);
6714
7140
  static Local<Value> SyntaxError(Local<String> message);
6715
7141
  static Local<Value> TypeError(Local<String> message);
7142
+ static Local<Value> WasmCompileError(Local<String> message);
7143
+ static Local<Value> WasmLinkError(Local<String> message);
7144
+ static Local<Value> WasmRuntimeError(Local<String> message);
6716
7145
  static Local<Value> Error(Local<String> message);
6717
7146
 
6718
7147
  /**
@@ -6747,6 +7176,7 @@ enum class CrashKeyId {
6747
7176
  kReadonlySpaceFirstPageAddress,
6748
7177
  kMapSpaceFirstPageAddress,
6749
7178
  kCodeSpaceFirstPageAddress,
7179
+ kDumpType,
6750
7180
  };
6751
7181
 
6752
7182
  typedef void (*AddCrashKeyCallback)(CrashKeyId id, const std::string& value);
@@ -6755,20 +7185,6 @@ typedef void (*AddCrashKeyCallback)(CrashKeyId id, const std::string& value);
6755
7185
  typedef void (*BeforeCallEnteredCallback)(Isolate*);
6756
7186
  typedef void (*CallCompletedCallback)(Isolate*);
6757
7187
 
6758
- /**
6759
- * HostCleanupFinalizationGroupCallback is called when we require the
6760
- * embedder to enqueue a task that would call
6761
- * FinalizationGroup::Cleanup().
6762
- *
6763
- * The FinalizationGroup is the one for which the embedder needs to
6764
- * call FinalizationGroup::Cleanup() on.
6765
- *
6766
- * The context provided is the one in which the FinalizationGroup was
6767
- * created in.
6768
- */
6769
- typedef void (*HostCleanupFinalizationGroupCallback)(
6770
- Local<Context> context, Local<FinalizationGroup> fg);
6771
-
6772
7188
  /**
6773
7189
  * HostImportModuleDynamicallyCallback is called when we require the
6774
7190
  * embedder to load a module. This is used as part of the dynamic
@@ -6866,15 +7282,15 @@ class PromiseRejectMessage {
6866
7282
  typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);
6867
7283
 
6868
7284
  // --- Microtasks Callbacks ---
6869
- V8_DEPRECATE_SOON("Use *WithData version.",
6870
- typedef void (*MicrotasksCompletedCallback)(Isolate*));
7285
+ V8_DEPRECATE_SOON("Use *WithData version.")
7286
+ typedef void (*MicrotasksCompletedCallback)(Isolate*);
6871
7287
  typedef void (*MicrotasksCompletedCallbackWithData)(Isolate*, void*);
6872
7288
  typedef void (*MicrotaskCallback)(void* data);
6873
7289
 
6874
-
6875
7290
  /**
6876
7291
  * Policy for running microtasks:
6877
- * - explicit: microtasks are invoked with Isolate::RunMicrotasks() method;
7292
+ * - explicit: microtasks are invoked with the
7293
+ * Isolate::PerformMicrotaskCheckpoint() method;
6878
7294
  * - scoped: microtasks invocation is controlled by MicrotasksScope objects;
6879
7295
  * - auto: microtasks are invoked when the script call depth decrements
6880
7296
  * to zero.
@@ -6965,7 +7381,7 @@ class V8_EXPORT MicrotaskQueue {
6965
7381
  };
6966
7382
 
6967
7383
  /**
6968
- * This scope is used to control microtasks when kScopeMicrotasksInvocation
7384
+ * This scope is used to control microtasks when MicrotasksPolicy::kScoped
6969
7385
  * is used on Isolate. In this mode every non-primitive call to V8 should be
6970
7386
  * done inside some MicrotasksScope.
6971
7387
  * Microtasks are executed when topmost MicrotasksScope marked as kRunMicrotasks
@@ -7020,8 +7436,23 @@ typedef void (*FailedAccessCheckCallback)(Local<Object> target,
7020
7436
  */
7021
7437
  typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context,
7022
7438
  Local<String> source);
7023
- typedef MaybeLocal<String> (*ModifyCodeGenerationFromStringsCallback)(
7024
- Local<Context> context, Local<Value> source);
7439
+
7440
+ struct ModifyCodeGenerationFromStringsResult {
7441
+ // If true, proceed with the codegen algorithm. Otherwise, block it.
7442
+ bool codegen_allowed = false;
7443
+ // Overwrite the original source with this string, if present.
7444
+ // Use the original source if empty.
7445
+ // This field is considered only if codegen_allowed is true.
7446
+ MaybeLocal<String> modified_source;
7447
+ };
7448
+
7449
+ /**
7450
+ * Callback to check if codegen is allowed from a source object, and convert
7451
+ * the source to string if necessary.See ModifyCodeGenerationFromStrings.
7452
+ */
7453
+ typedef ModifyCodeGenerationFromStringsResult (
7454
+ *ModifyCodeGenerationFromStringsCallback)(Local<Context> context,
7455
+ Local<Value> source);
7025
7456
 
7026
7457
  // --- WebAssembly compilation callbacks ---
7027
7458
  typedef bool (*ExtensionCallback)(const FunctionCallbackInfo<Value>&);
@@ -7039,7 +7470,7 @@ typedef void (*WasmStreamingCallback)(const FunctionCallbackInfo<Value>&);
7039
7470
  // --- Callback for checking if WebAssembly threads are enabled ---
7040
7471
  typedef bool (*WasmThreadsEnabledCallback)(Local<Context> context);
7041
7472
 
7042
- // --- Callback for loading source map file for WASM profiling support
7473
+ // --- Callback for loading source map file for Wasm profiling support
7043
7474
  typedef Local<String> (*WasmLoadSourceMapCallback)(Isolate* isolate,
7044
7475
  const char* name);
7045
7476
 
@@ -7099,10 +7530,33 @@ typedef void (*InterruptCallback)(Isolate* isolate, void* data);
7099
7530
  typedef size_t (*NearHeapLimitCallback)(void* data, size_t current_heap_limit,
7100
7531
  size_t initial_heap_limit);
7101
7532
 
7533
+ /**
7534
+ * Collection of shared per-process V8 memory information.
7535
+ *
7536
+ * Instances of this class can be passed to
7537
+ * v8::V8::GetSharedMemoryStatistics to get shared memory statistics from V8.
7538
+ */
7539
+ class V8_EXPORT SharedMemoryStatistics {
7540
+ public:
7541
+ SharedMemoryStatistics();
7542
+ size_t read_only_space_size() { return read_only_space_size_; }
7543
+ size_t read_only_space_used_size() { return read_only_space_used_size_; }
7544
+ size_t read_only_space_physical_size() {
7545
+ return read_only_space_physical_size_;
7546
+ }
7547
+
7548
+ private:
7549
+ size_t read_only_space_size_;
7550
+ size_t read_only_space_used_size_;
7551
+ size_t read_only_space_physical_size_;
7552
+
7553
+ friend class V8;
7554
+ };
7555
+
7102
7556
  /**
7103
7557
  * Collection of V8 heap information.
7104
7558
  *
7105
- * Instances of this class can be passed to v8::V8::HeapStatistics to
7559
+ * Instances of this class can be passed to v8::Isolate::GetHeapStatistics to
7106
7560
  * get heap statistics from V8.
7107
7561
  */
7108
7562
  class V8_EXPORT HeapStatistics {
@@ -7112,6 +7566,8 @@ class V8_EXPORT HeapStatistics {
7112
7566
  size_t total_heap_size_executable() { return total_heap_size_executable_; }
7113
7567
  size_t total_physical_size() { return total_physical_size_; }
7114
7568
  size_t total_available_size() { return total_available_size_; }
7569
+ size_t total_global_handles_size() { return total_global_handles_size_; }
7570
+ size_t used_global_handles_size() { return used_global_handles_size_; }
7115
7571
  size_t used_heap_size() { return used_heap_size_; }
7116
7572
  size_t heap_size_limit() { return heap_size_limit_; }
7117
7573
  size_t malloced_memory() { return malloced_memory_; }
@@ -7139,6 +7595,8 @@ class V8_EXPORT HeapStatistics {
7139
7595
  bool does_zap_garbage_;
7140
7596
  size_t number_of_native_contexts_;
7141
7597
  size_t number_of_detached_contexts_;
7598
+ size_t total_global_handles_size_;
7599
+ size_t used_global_handles_size_;
7142
7600
 
7143
7601
  friend class V8;
7144
7602
  friend class Isolate;
@@ -7258,6 +7716,20 @@ struct JitCodeEvent {
7258
7716
  PositionType position_type;
7259
7717
  };
7260
7718
 
7719
+ struct wasm_source_info_t {
7720
+ // Source file name.
7721
+ const char* filename;
7722
+ // Length of filename.
7723
+ size_t filename_size;
7724
+ // Line number table, which maps offsets of JITted code to line numbers of
7725
+ // source file.
7726
+ const line_info_t* line_number_table;
7727
+ // Number of entries in the line number table.
7728
+ size_t line_number_table_size;
7729
+ };
7730
+
7731
+ wasm_source_info_t* wasm_source_info;
7732
+
7261
7733
  union {
7262
7734
  // Only valid for CODE_ADDED.
7263
7735
  struct name_t name;
@@ -7376,7 +7848,8 @@ class V8_EXPORT EmbedderHeapTracer {
7376
7848
  class V8_EXPORT TracedGlobalHandleVisitor {
7377
7849
  public:
7378
7850
  virtual ~TracedGlobalHandleVisitor() = default;
7379
- virtual void VisitTracedGlobalHandle(const TracedGlobal<Value>& value) = 0;
7851
+ virtual void VisitTracedGlobalHandle(const TracedGlobal<Value>& handle) {}
7852
+ virtual void VisitTracedReference(const TracedReference<Value>& handle) {}
7380
7853
  };
7381
7854
 
7382
7855
  /**
@@ -7405,6 +7878,17 @@ class V8_EXPORT EmbedderHeapTracer {
7405
7878
  */
7406
7879
  void IterateTracedGlobalHandles(TracedGlobalHandleVisitor* visitor);
7407
7880
 
7881
+ /**
7882
+ * Called by the embedder to set the start of the stack which is e.g. used by
7883
+ * V8 to determine whether handles are used from stack or heap.
7884
+ */
7885
+ void SetStackStart(void* stack_start);
7886
+
7887
+ /**
7888
+ * Called by the embedder to notify V8 of an empty execution stack.
7889
+ */
7890
+ void NotifyEmptyEmbedderStack();
7891
+
7408
7892
  /**
7409
7893
  * Called by v8 to register internal fields of found wrappers.
7410
7894
  *
@@ -7414,13 +7898,12 @@ class V8_EXPORT EmbedderHeapTracer {
7414
7898
  virtual void RegisterV8References(
7415
7899
  const std::vector<std::pair<void*, void*> >& embedder_fields) = 0;
7416
7900
 
7417
- void RegisterEmbedderReference(const TracedGlobal<v8::Value>& ref);
7901
+ void RegisterEmbedderReference(const TracedReferenceBase<v8::Data>& ref);
7418
7902
 
7419
7903
  /**
7420
7904
  * Called at the beginning of a GC cycle.
7421
7905
  */
7422
- V8_DEPRECATED("Use version with flags.", virtual void TracePrologue()) {}
7423
- virtual void TracePrologue(TraceFlags flags);
7906
+ virtual void TracePrologue(TraceFlags flags) {}
7424
7907
 
7425
7908
  /**
7426
7909
  * Called to advance tracing in the embedder.
@@ -7447,9 +7930,7 @@ class V8_EXPORT EmbedderHeapTracer {
7447
7930
  * overriden to fill a |TraceSummary| that is used by V8 to schedule future
7448
7931
  * garbage collections.
7449
7932
  */
7450
- V8_DEPRECATE_SOON("Use version with parameter.",
7451
- virtual void TraceEpilogue()) {}
7452
- virtual void TraceEpilogue(TraceSummary* trace_summary);
7933
+ virtual void TraceEpilogue(TraceSummary* trace_summary) {}
7453
7934
 
7454
7935
  /**
7455
7936
  * Called upon entering the final marking pause. No more incremental marking
@@ -7475,32 +7956,31 @@ class V8_EXPORT EmbedderHeapTracer {
7475
7956
  *
7476
7957
  * If this returns false, then V8 may decide that the object referred to by
7477
7958
  * such a handle is reclaimed. In that case:
7478
- * - No action is required if handles are used with destructors.
7479
- * - When run without destructors (by specializing
7480
- * |TracedGlobalTrait::kRequiresExplicitDestruction|) V8 calls
7481
- * |ResetHandleInNonTracingGC|.
7959
+ * - No action is required if handles are used with destructors, i.e., by just
7960
+ * using |TracedGlobal|.
7961
+ * - When run without destructors, i.e., by using
7962
+ * |TracedReference|, V8 calls |ResetHandleInNonTracingGC|.
7482
7963
  *
7483
- * Note that the |handle| is different from the |TracedGlobal<T>| handle that
7484
- * the embedder holds for retaining the object. The embedder may use
7485
- * |TracedGlobal<T>::WrapperClassId()| to distinguish cases where it wants
7486
- * handles to be treated as roots from not being treated as roots.
7964
+ * Note that the |handle| is different from the handle that the embedder holds
7965
+ * for retaining the object. The embedder may use |WrapperClassId()| to
7966
+ * distinguish cases where it wants handles to be treated as roots from not
7967
+ * being treated as roots.
7487
7968
  */
7488
7969
  virtual bool IsRootForNonTracingGC(
7489
- const v8::TracedGlobal<v8::Value>& handle) {
7490
- return true;
7491
- }
7970
+ const v8::TracedReference<v8::Value>& handle);
7971
+ virtual bool IsRootForNonTracingGC(const v8::TracedGlobal<v8::Value>& handle);
7492
7972
 
7493
7973
  /**
7494
7974
  * Used in combination with |IsRootForNonTracingGC|. Called by V8 when an
7495
7975
  * object that is backed by a handle is reclaimed by a non-tracing garbage
7496
7976
  * collection. It is up to the embedder to reset the original handle.
7497
7977
  *
7498
- * Note that the |handle| is different from the |TracedGlobal<T>| handle that
7499
- * the embedder holds for retaining the object. It is up to the embedder to
7500
- * find the orignal |TracedGlobal<T>| handle via the object or class id.
7978
+ * Note that the |handle| is different from the handle that the embedder holds
7979
+ * for retaining the object. It is up to the embedder to find the original
7980
+ * handle via the object or class id.
7501
7981
  */
7502
7982
  virtual void ResetHandleInNonTracingGC(
7503
- const v8::TracedGlobal<v8::Value>& handle) {}
7983
+ const v8::TracedReference<v8::Value>& handle);
7504
7984
 
7505
7985
  /*
7506
7986
  * Called by the embedder to immediately perform a full garbage collection.
@@ -7567,6 +8047,66 @@ struct DeserializeInternalFieldsCallback {
7567
8047
  };
7568
8048
  typedef DeserializeInternalFieldsCallback DeserializeEmbedderFieldsCallback;
7569
8049
 
8050
+ /**
8051
+ * Controls how the default MeasureMemoryDelegate reports the result of
8052
+ * the memory measurement to JS. With kSummary only the total size is reported.
8053
+ * With kDetailed the result includes the size of each native context.
8054
+ */
8055
+ enum class MeasureMemoryMode { kSummary, kDetailed };
8056
+
8057
+ /**
8058
+ * Controls how promptly a memory measurement request is executed.
8059
+ * By default the measurement is folded with the next scheduled GC which may
8060
+ * happen after a while. The kEager starts increment GC right away and
8061
+ * is useful for testing.
8062
+ */
8063
+ enum class MeasureMemoryExecution { kDefault, kEager };
8064
+
8065
+ /**
8066
+ * The delegate is used in Isolate::MeasureMemory API.
8067
+ *
8068
+ * It specifies the contexts that need to be measured and gets called when
8069
+ * the measurement is completed to report the results.
8070
+ */
8071
+ class V8_EXPORT MeasureMemoryDelegate {
8072
+ public:
8073
+ virtual ~MeasureMemoryDelegate() = default;
8074
+
8075
+ /**
8076
+ * Returns true if the size of the given context needs to be measured.
8077
+ */
8078
+ virtual bool ShouldMeasure(Local<Context> context) = 0;
8079
+
8080
+ /**
8081
+ * This function is called when memory measurement finishes.
8082
+ *
8083
+ * \param context_sizes_in_bytes a vector of (context, size) pairs that
8084
+ * includes each context for which ShouldMeasure returned true and that
8085
+ * was not garbage collected while the memory measurement was in progress.
8086
+ *
8087
+ * \param unattributed_size_in_bytes total size of objects that were not
8088
+ * attributed to any context (i.e. are likely shared objects).
8089
+ */
8090
+ virtual void MeasurementComplete(
8091
+ const std::vector<std::pair<Local<Context>, size_t>>&
8092
+ context_sizes_in_bytes,
8093
+ size_t unattributed_size_in_bytes) = 0;
8094
+
8095
+ /**
8096
+ * Returns a default delegate that resolves the given promise when
8097
+ * the memory measurement completes.
8098
+ *
8099
+ * \param isolate the current isolate
8100
+ * \param context the current context
8101
+ * \param promise_resolver the promise resolver that is given the
8102
+ * result of the memory measurement.
8103
+ * \param mode the detail level of the result.
8104
+ */
8105
+ static std::unique_ptr<MeasureMemoryDelegate> Default(
8106
+ Isolate* isolate, Local<Context> context,
8107
+ Local<Promise::Resolver> promise_resolver, MeasureMemoryMode mode);
8108
+ };
8109
+
7570
8110
  /**
7571
8111
  * Isolate represents an isolated instance of the V8 engine. V8 isolates have
7572
8112
  * completely separate states. Objects from one isolate must not be used in
@@ -7588,9 +8128,12 @@ class V8_EXPORT Isolate {
7588
8128
  create_histogram_callback(nullptr),
7589
8129
  add_histogram_sample_callback(nullptr),
7590
8130
  array_buffer_allocator(nullptr),
8131
+ array_buffer_allocator_shared(),
7591
8132
  external_references(nullptr),
7592
8133
  allow_atomics_wait(true),
7593
- only_terminate_in_safe_scope(false) {}
8134
+ only_terminate_in_safe_scope(false),
8135
+ embedder_wrapper_type_index(-1),
8136
+ embedder_wrapper_object_index(-1) {}
7594
8137
 
7595
8138
  /**
7596
8139
  * Allows the host application to provide the address of a function that is
@@ -7627,8 +8170,14 @@ class V8_EXPORT Isolate {
7627
8170
  /**
7628
8171
  * The ArrayBuffer::Allocator to use for allocating and freeing the backing
7629
8172
  * store of ArrayBuffers.
8173
+ *
8174
+ * If the shared_ptr version is used, the Isolate instance and every
8175
+ * |BackingStore| allocated using this allocator hold a std::shared_ptr
8176
+ * to the allocator, in order to facilitate lifetime
8177
+ * management for the allocator instance.
7630
8178
  */
7631
8179
  ArrayBuffer::Allocator* array_buffer_allocator;
8180
+ std::shared_ptr<ArrayBuffer::Allocator> array_buffer_allocator_shared;
7632
8181
 
7633
8182
  /**
7634
8183
  * Specifies an optional nullptr-terminated array of raw addresses in the
@@ -7648,6 +8197,14 @@ class V8_EXPORT Isolate {
7648
8197
  * Termination is postponed when there is no active SafeForTerminationScope.
7649
8198
  */
7650
8199
  bool only_terminate_in_safe_scope;
8200
+
8201
+ /**
8202
+ * The following parameters describe the offsets for addressing type info
8203
+ * for wrapped API objects and are used by the fast C API
8204
+ * (for details see v8-fast-api-calls.h).
8205
+ */
8206
+ int embedder_wrapper_type_index;
8207
+ int embedder_wrapper_object_index;
7651
8208
  };
7652
8209
 
7653
8210
 
@@ -7720,8 +8277,8 @@ class V8_EXPORT Isolate {
7720
8277
  */
7721
8278
  class V8_EXPORT SuppressMicrotaskExecutionScope {
7722
8279
  public:
7723
- explicit SuppressMicrotaskExecutionScope(Isolate* isolate);
7724
- explicit SuppressMicrotaskExecutionScope(MicrotaskQueue* microtask_queue);
8280
+ explicit SuppressMicrotaskExecutionScope(
8281
+ Isolate* isolate, MicrotaskQueue* microtask_queue = nullptr);
7725
8282
  ~SuppressMicrotaskExecutionScope();
7726
8283
 
7727
8284
  // Prevent copying of Scope objects.
@@ -7845,11 +8402,38 @@ class V8_EXPORT Isolate {
7845
8402
  kOptimizedFunctionWithOneShotBytecode = 71,
7846
8403
  kRegExpMatchIsTrueishOnNonJSRegExp = 72,
7847
8404
  kRegExpMatchIsFalseishOnJSRegExp = 73,
7848
- kDateGetTimezoneOffset = 74,
8405
+ kDateGetTimezoneOffset = 74, // Unused.
7849
8406
  kStringNormalize = 75,
7850
8407
  kCallSiteAPIGetFunctionSloppyCall = 76,
7851
8408
  kCallSiteAPIGetThisSloppyCall = 77,
7852
8409
  kRegExpMatchAllWithNonGlobalRegExp = 78,
8410
+ kRegExpExecCalledOnSlowRegExp = 79,
8411
+ kRegExpReplaceCalledOnSlowRegExp = 80,
8412
+ kDisplayNames = 81,
8413
+ kSharedArrayBufferConstructed = 82,
8414
+ kArrayPrototypeHasElements = 83,
8415
+ kObjectPrototypeHasElements = 84,
8416
+ kNumberFormatStyleUnit = 85,
8417
+ kDateTimeFormatRange = 86,
8418
+ kDateTimeFormatDateTimeStyle = 87,
8419
+ kBreakIteratorTypeWord = 88,
8420
+ kBreakIteratorTypeLine = 89,
8421
+ kInvalidatedArrayBufferDetachingProtector = 90,
8422
+ kInvalidatedArrayConstructorProtector = 91,
8423
+ kInvalidatedArrayIteratorLookupChainProtector = 92,
8424
+ kInvalidatedArraySpeciesLookupChainProtector = 93,
8425
+ kInvalidatedIsConcatSpreadableLookupChainProtector = 94,
8426
+ kInvalidatedMapIteratorLookupChainProtector = 95,
8427
+ kInvalidatedNoElementsProtector = 96,
8428
+ kInvalidatedPromiseHookProtector = 97,
8429
+ kInvalidatedPromiseResolveLookupChainProtector = 98,
8430
+ kInvalidatedPromiseSpeciesLookupChainProtector = 99,
8431
+ kInvalidatedPromiseThenLookupChainProtector = 100,
8432
+ kInvalidatedRegExpSpeciesLookupChainProtector = 101,
8433
+ kInvalidatedSetIteratorLookupChainProtector = 102,
8434
+ kInvalidatedStringIteratorLookupChainProtector = 103,
8435
+ kInvalidatedStringLengthOverflowLookupChainProtector = 104,
8436
+ kInvalidatedTypedArraySpeciesLookupChainProtector = 105,
7853
8437
 
7854
8438
  // If you add new values here, you'll also need to update Chromium's:
7855
8439
  // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
@@ -7915,10 +8499,13 @@ class V8_EXPORT Isolate {
7915
8499
  * objects are originally built when a WeakRef is created or
7916
8500
  * successfully dereferenced.
7917
8501
  *
7918
- * The embedder is expected to call this when a synchronous sequence
7919
- * of ECMAScript execution completes. It's the embedders
7920
- * responsiblity to make this call at a time which does not
7921
- * interrupt synchronous ECMAScript code execution.
8502
+ * This is invoked automatically after microtasks are run. See
8503
+ * MicrotasksPolicy for when microtasks are run.
8504
+ *
8505
+ * This needs to be manually invoked only if the embedder is manually running
8506
+ * microtasks via a custom MicrotaskQueue class's PerformCheckpoint. In that
8507
+ * case, it is the embedder's responsibility to make this call at a time which
8508
+ * does not interrupt synchronous ECMAScript code execution.
7922
8509
  */
7923
8510
  void ClearKeptObjects();
7924
8511
 
@@ -7935,14 +8522,6 @@ class V8_EXPORT Isolate {
7935
8522
  void SetAbortOnUncaughtExceptionCallback(
7936
8523
  AbortOnUncaughtExceptionCallback callback);
7937
8524
 
7938
- /**
7939
- * This specifies the callback to be called when finalization groups
7940
- * are ready to be cleaned up and require FinalizationGroup::Cleanup()
7941
- * to be called in a future task.
7942
- */
7943
- void SetHostCleanupFinalizationGroupCallback(
7944
- HostCleanupFinalizationGroupCallback callback);
7945
-
7946
8525
  /**
7947
8526
  * This specifies the callback called by the upcoming dynamic
7948
8527
  * import() language feature to load modules.
@@ -8087,6 +8666,26 @@ class V8_EXPORT Isolate {
8087
8666
  */
8088
8667
  bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
8089
8668
 
8669
+ /**
8670
+ * This API is experimental and may change significantly.
8671
+ *
8672
+ * Enqueues a memory measurement request and invokes the delegate with the
8673
+ * results.
8674
+ *
8675
+ * \param delegate the delegate that defines which contexts to measure and
8676
+ * reports the results.
8677
+ *
8678
+ * \param execution promptness executing the memory measurement.
8679
+ * The kEager value is expected to be used only in tests.
8680
+ */
8681
+ bool MeasureMemory(
8682
+ std::unique_ptr<MeasureMemoryDelegate> delegate,
8683
+ MeasureMemoryExecution execution = MeasureMemoryExecution::kDefault);
8684
+
8685
+ V8_DEPRECATE_SOON("Use the version with a delegate")
8686
+ MaybeLocal<Promise> MeasureMemory(Local<Context> context,
8687
+ MeasureMemoryMode mode);
8688
+
8090
8689
  /**
8091
8690
  * Get a call stack sample from the isolate.
8092
8691
  * \param state Execution state.
@@ -8148,8 +8747,8 @@ class V8_EXPORT Isolate {
8148
8747
  Local<Context> GetCurrentContext();
8149
8748
 
8150
8749
  /** Returns the last context entered through V8's C++ API. */
8151
- V8_DEPRECATED("Use GetEnteredOrMicrotaskContext().",
8152
- Local<Context> GetEnteredContext());
8750
+ V8_DEPRECATED("Use GetEnteredOrMicrotaskContext().")
8751
+ Local<Context> GetEnteredContext();
8153
8752
 
8154
8753
  /**
8155
8754
  * Returns either the last context entered through V8's C++ API, or the
@@ -8423,10 +9022,18 @@ class V8_EXPORT Isolate {
8423
9022
  void SetPromiseRejectCallback(PromiseRejectCallback callback);
8424
9023
 
8425
9024
  /**
8426
- * Runs the default MicrotaskQueue until it gets empty.
8427
- * Any exceptions thrown by microtask callbacks are swallowed.
9025
+ * An alias for PerformMicrotaskCheckpoint.
9026
+ */
9027
+ V8_DEPRECATE_SOON("Use PerformMicrotaskCheckpoint.")
9028
+ void RunMicrotasks() { PerformMicrotaskCheckpoint(); }
9029
+
9030
+ /**
9031
+ * Runs the default MicrotaskQueue until it gets empty and perform other
9032
+ * microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that
9033
+ * the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask
9034
+ * callbacks are swallowed.
8428
9035
  */
8429
- void RunMicrotasks();
9036
+ void PerformMicrotaskCheckpoint();
8430
9037
 
8431
9038
  /**
8432
9039
  * Enqueues the callback to the default MicrotaskQueue
@@ -8461,18 +9068,16 @@ class V8_EXPORT Isolate {
8461
9068
  * Executing scripts inside the callback will not re-trigger microtasks and
8462
9069
  * the callback.
8463
9070
  */
8464
- V8_DEPRECATE_SOON("Use *WithData version.",
8465
- void AddMicrotasksCompletedCallback(
8466
- MicrotasksCompletedCallback callback));
9071
+ V8_DEPRECATE_SOON("Use *WithData version.")
9072
+ void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8467
9073
  void AddMicrotasksCompletedCallback(
8468
9074
  MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
8469
9075
 
8470
9076
  /**
8471
9077
  * Removes callback that was installed by AddMicrotasksCompletedCallback.
8472
9078
  */
8473
- V8_DEPRECATE_SOON("Use *WithData version.",
8474
- void RemoveMicrotasksCompletedCallback(
8475
- MicrotasksCompletedCallback callback));
9079
+ V8_DEPRECATE_SOON("Use *WithData version.")
9080
+ void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
8476
9081
  void RemoveMicrotasksCompletedCallback(
8477
9082
  MicrotasksCompletedCallbackWithData callback, void* data = nullptr);
8478
9083
 
@@ -8526,10 +9131,10 @@ class V8_EXPORT Isolate {
8526
9131
  void LowMemoryNotification();
8527
9132
 
8528
9133
  /**
8529
- * Optional notification that a context has been disposed. V8 uses
8530
- * these notifications to guide the GC heuristic. Returns the number
8531
- * of context disposals - including this one - since the last time
8532
- * V8 had a chance to clean up.
9134
+ * Optional notification that a context has been disposed. V8 uses these
9135
+ * notifications to guide the GC heuristic and cancel FinalizationRegistry
9136
+ * cleanup tasks. Returns the number of context disposals - including this one
9137
+ * - since the last time V8 had a chance to clean up.
8533
9138
  *
8534
9139
  * The optional parameter |dependant_context| specifies whether the disposed
8535
9140
  * context was depending on state from other contexts or not.
@@ -8642,8 +9247,32 @@ class V8_EXPORT Isolate {
8642
9247
  /**
8643
9248
  * Returns the UnwindState necessary for use with the Unwinder API.
8644
9249
  */
9250
+ // TODO(petermarshall): Remove this API.
9251
+ V8_DEPRECATED("Use entry_stubs + code_pages version.")
8645
9252
  UnwindState GetUnwindState();
8646
9253
 
9254
+ /**
9255
+ * Returns the JSEntryStubs necessary for use with the Unwinder API.
9256
+ */
9257
+ JSEntryStubs GetJSEntryStubs();
9258
+
9259
+ static constexpr size_t kMinCodePagesBufferSize = 32;
9260
+
9261
+ /**
9262
+ * Copies the code heap pages currently in use by V8 into |code_pages_out|.
9263
+ * |code_pages_out| must have at least kMinCodePagesBufferSize capacity and
9264
+ * must be empty.
9265
+ *
9266
+ * Signal-safe, does not allocate, does not access the V8 heap.
9267
+ * No code on the stack can rely on pages that might be missing.
9268
+ *
9269
+ * Returns the number of pages available to be copied, which might be greater
9270
+ * than |capacity|. In this case, only |capacity| pages will be copied into
9271
+ * |code_pages_out|. The caller should provide a bigger buffer on the next
9272
+ * call in order to get all available code pages, but this is not required.
9273
+ */
9274
+ size_t CopyCodePages(size_t capacity, MemoryRange* code_pages_out);
9275
+
8647
9276
  /** Set the callback to invoke in case of fatal errors. */
8648
9277
  void SetFatalErrorHandler(FatalErrorCallback that);
8649
9278
 
@@ -8679,6 +9308,9 @@ class V8_EXPORT Isolate {
8679
9308
  * Set the callback to invoke to check if code generation from
8680
9309
  * strings should be allowed.
8681
9310
  */
9311
+ V8_DEPRECATED(
9312
+ "Use Isolate::SetModifyCodeGenerationFromStringsCallback instead. "
9313
+ "See http://crbug.com/v8/10096.")
8682
9314
  void SetAllowCodeGenerationFromStringsCallback(
8683
9315
  AllowCodeGenerationFromStringsCallback callback);
8684
9316
  void SetModifyCodeGenerationFromStringsCallback(
@@ -8842,7 +9474,6 @@ class V8_EXPORT Isolate {
8842
9474
 
8843
9475
  internal::Address* GetDataFromSnapshotOnce(size_t index);
8844
9476
  void ReportExternalAllocationLimitReached();
8845
- void CheckMemoryPressure();
8846
9477
  };
8847
9478
 
8848
9479
  class V8_EXPORT StartupData {
@@ -8902,7 +9533,6 @@ class V8_EXPORT V8 {
8902
9533
  * handled entirely on the embedders' side.
8903
9534
  * - The call will abort if the data is invalid.
8904
9535
  */
8905
- static void SetNativesDataBlob(StartupData* startup_blob);
8906
9536
  static void SetSnapshotDataBlob(StartupData* startup_blob);
8907
9537
 
8908
9538
  /** Set the callback to invoke in case of Dcheck failures. */
@@ -8914,8 +9544,6 @@ class V8_EXPORT V8 {
8914
9544
  */
8915
9545
  static void SetFlagsFromString(const char* str);
8916
9546
  static void SetFlagsFromString(const char* str, size_t length);
8917
- V8_DEPRECATED("use size_t version",
8918
- static void SetFlagsFromString(const char* str, int length));
8919
9547
 
8920
9548
  /**
8921
9549
  * Sets V8 flags from the command line.
@@ -8931,7 +9559,12 @@ class V8_EXPORT V8 {
8931
9559
  * Initializes V8. This function needs to be called before the first Isolate
8932
9560
  * is created. It always returns true.
8933
9561
  */
8934
- static bool Initialize();
9562
+ V8_INLINE static bool Initialize() {
9563
+ const int kBuildConfiguration =
9564
+ (internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) |
9565
+ (internal::SmiValuesAre31Bits() ? k31BitSmis : 0);
9566
+ return Initialize(kBuildConfiguration);
9567
+ }
8935
9568
 
8936
9569
  /**
8937
9570
  * Allows the host application to provide a callback which can be used
@@ -8989,17 +9622,16 @@ class V8_EXPORT V8 {
8989
9622
  * V8 needs to be given those external files during startup. There are
8990
9623
  * three ways to do this:
8991
9624
  * - InitializeExternalStartupData(const char*)
8992
- * This will look in the given directory for files "natives_blob.bin"
8993
- * and "snapshot_blob.bin" - which is what the default build calls them.
8994
- * - InitializeExternalStartupData(const char*, const char*)
8995
- * As above, but will directly use the two given file names.
8996
- * - Call SetNativesDataBlob, SetNativesDataBlob.
8997
- * This will read the blobs from the given data structures and will
9625
+ * This will look in the given directory for the file "snapshot_blob.bin".
9626
+ * - InitializeExternalStartupDataFromFile(const char*)
9627
+ * As above, but will directly use the given file name.
9628
+ * - Call SetSnapshotDataBlob.
9629
+ * This will read the blobs from the given data structure and will
8998
9630
  * not perform any file IO.
8999
9631
  */
9000
9632
  static void InitializeExternalStartupData(const char* directory_path);
9001
- static void InitializeExternalStartupData(const char* natives_blob,
9002
- const char* snapshot_blob);
9633
+ static void InitializeExternalStartupDataFromFile(const char* snapshot_blob);
9634
+
9003
9635
  /**
9004
9636
  * Sets the v8::Platform to use. This should be invoked before V8 is
9005
9637
  * initialized.
@@ -9032,9 +9664,8 @@ class V8_EXPORT V8 {
9032
9664
  * \param context The third argument passed to the Linux signal handler, which
9033
9665
  * points to a ucontext_t structure.
9034
9666
  */
9035
- V8_DEPRECATE_SOON("Use TryHandleWebAssemblyTrapPosix",
9036
- static bool TryHandleSignal(int signal_number, void* info,
9037
- void* context));
9667
+ V8_DEPRECATE_SOON("Use TryHandleWebAssemblyTrapPosix")
9668
+ static bool TryHandleSignal(int signal_number, void* info, void* context);
9038
9669
  #endif // V8_OS_POSIX
9039
9670
 
9040
9671
  /**
@@ -9059,9 +9690,25 @@ class V8_EXPORT V8 {
9059
9690
  UnhandledExceptionCallback unhandled_exception_callback);
9060
9691
  #endif
9061
9692
 
9693
+ /**
9694
+ * Get statistics about the shared memory usage.
9695
+ */
9696
+ static void GetSharedMemoryStatistics(SharedMemoryStatistics* statistics);
9697
+
9062
9698
  private:
9063
9699
  V8();
9064
9700
 
9701
+ enum BuildConfigurationFeatures {
9702
+ kPointerCompression = 1 << 0,
9703
+ k31BitSmis = 1 << 1,
9704
+ };
9705
+
9706
+ /**
9707
+ * Checks that the embedder build configuration is compatible with
9708
+ * the V8 binary and if so initializes V8.
9709
+ */
9710
+ static bool Initialize(int build_config);
9711
+
9065
9712
  static internal::Address* GlobalizeReference(internal::Isolate* isolate,
9066
9713
  internal::Address* handle);
9067
9714
  static internal::Address* GlobalizeTracedReference(internal::Isolate* isolate,
@@ -9103,8 +9750,12 @@ class V8_EXPORT V8 {
9103
9750
  template <class T>
9104
9751
  friend class Maybe;
9105
9752
  template <class T>
9753
+ friend class TracedReferenceBase;
9754
+ template <class T>
9106
9755
  friend class TracedGlobal;
9107
9756
  template <class T>
9757
+ friend class TracedReference;
9758
+ template <class T>
9108
9759
  friend class WeakCallbackInfo;
9109
9760
  template <class T> friend class Eternal;
9110
9761
  template <class T> friend class PersistentBase;
@@ -9114,6 +9765,11 @@ class V8_EXPORT V8 {
9114
9765
 
9115
9766
  /**
9116
9767
  * Helper class to create a snapshot data blob.
9768
+ *
9769
+ * The Isolate used by a SnapshotCreator is owned by it, and will be entered
9770
+ * and exited by the constructor and destructor, respectively; The destructor
9771
+ * will also destroy the Isolate. Experimental language features, including
9772
+ * those available by default, are not available while creating a snapshot.
9117
9773
  */
9118
9774
  class V8_EXPORT SnapshotCreator {
9119
9775
  public:
@@ -9142,6 +9798,10 @@ class V8_EXPORT SnapshotCreator {
9142
9798
  SnapshotCreator(const intptr_t* external_references = nullptr,
9143
9799
  StartupData* existing_blob = nullptr);
9144
9800
 
9801
+ /**
9802
+ * Destroy the snapshot creator, and exit and dispose of the Isolate
9803
+ * associated with it.
9804
+ */
9145
9805
  ~SnapshotCreator();
9146
9806
 
9147
9807
  /**
@@ -9172,12 +9832,6 @@ class V8_EXPORT SnapshotCreator {
9172
9832
  SerializeInternalFieldsCallback callback =
9173
9833
  SerializeInternalFieldsCallback());
9174
9834
 
9175
- /**
9176
- * Add a template to be included in the snapshot blob.
9177
- * \returns the index of the template in the snapshot blob.
9178
- */
9179
- size_t AddTemplate(Local<Template> template_obj);
9180
-
9181
9835
  /**
9182
9836
  * Attach arbitrary V8::Data to the context snapshot, which can be retrieved
9183
9837
  * via Context::GetDataFromSnapshot after deserialization. This data does not
@@ -9398,9 +10052,17 @@ class V8_EXPORT TryCatch {
9398
10052
  Local<Value> Exception() const;
9399
10053
 
9400
10054
  /**
9401
- * Returns the .stack property of the thrown object. If no .stack
10055
+ * Returns the .stack property of an object. If no .stack
9402
10056
  * property is present an empty handle is returned.
9403
10057
  */
10058
+ V8_WARN_UNUSED_RESULT static MaybeLocal<Value> StackTrace(
10059
+ Local<Context> context, Local<Value> exception);
10060
+
10061
+ /**
10062
+ * Returns the .stack property of the thrown object. If no .stack property is
10063
+ * present or if this try/catch block has not caught an exception, an empty
10064
+ * handle is returned.
10065
+ */
9404
10066
  V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
9405
10067
  Local<Context> context) const;
9406
10068
 
@@ -9731,6 +10393,18 @@ class V8_EXPORT Context {
9731
10393
  Local<Context> context);
9732
10394
  void SetAbortScriptExecution(AbortScriptExecutionCallback callback);
9733
10395
 
10396
+ /**
10397
+ * Returns the value that was set or restored by
10398
+ * SetContinuationPreservedEmbedderData(), if any.
10399
+ */
10400
+ Local<Value> GetContinuationPreservedEmbedderData() const;
10401
+
10402
+ /**
10403
+ * Sets a value that will be stored on continuations and reset while the
10404
+ * continuation runs.
10405
+ */
10406
+ void SetContinuationPreservedEmbedderData(Local<Value> context);
10407
+
9734
10408
  /**
9735
10409
  * Stack-allocated class which sets the execution context for all
9736
10410
  * operations executed within a local scope.
@@ -9915,7 +10589,7 @@ class V8_EXPORT Locker {
9915
10589
  /**
9916
10590
  * Various helpers for skipping over V8 frames in a given stack.
9917
10591
  *
9918
- * The unwinder API is only supported on the x64 architecture.
10592
+ * The unwinder API is only supported on the x64, ARM64 and ARM32 architectures.
9919
10593
  */
9920
10594
  class V8_EXPORT Unwinder {
9921
10595
  public:
@@ -9947,10 +10621,26 @@ class V8_EXPORT Unwinder {
9947
10621
  *
9948
10622
  * \return True on success.
9949
10623
  */
10624
+ // TODO(petermarshall): Remove this API
10625
+ V8_DEPRECATED("Use entry_stubs + code_pages version.")
9950
10626
  static bool TryUnwindV8Frames(const UnwindState& unwind_state,
9951
10627
  RegisterState* register_state,
9952
10628
  const void* stack_base);
9953
10629
 
10630
+ /**
10631
+ * The same as above, but is available on x64, ARM64 and ARM32.
10632
+ *
10633
+ * \param code_pages A list of all of the ranges in which V8 has allocated
10634
+ * executable code. The caller should obtain this list by calling
10635
+ * Isolate::CopyCodePages() during the same interrupt/thread suspension that
10636
+ * captures the stack.
10637
+ */
10638
+ static bool TryUnwindV8Frames(const JSEntryStubs& entry_stubs,
10639
+ size_t code_pages_length,
10640
+ const MemoryRange* code_pages,
10641
+ RegisterState* register_state,
10642
+ const void* stack_base);
10643
+
9954
10644
  /**
9955
10645
  * Whether the PC is within the V8 code range represented by code_range or
9956
10646
  * embedded_code_range in |unwind_state|.
@@ -9959,7 +10649,16 @@ class V8_EXPORT Unwinder {
9959
10649
  * and unwind_state will always fail. If it returns true, then unwinding may
9960
10650
  * (but not necessarily) be successful.
9961
10651
  */
10652
+ // TODO(petermarshall): Remove this API
10653
+ V8_DEPRECATED("Use code_pages version.")
9962
10654
  static bool PCIsInV8(const UnwindState& unwind_state, void* pc);
10655
+
10656
+ /**
10657
+ * The same as above, but is available on x64, ARM64 and ARM32. See the
10658
+ * comment on TryUnwindV8Frames.
10659
+ */
10660
+ static bool PCIsInV8(size_t code_pages_length, const MemoryRange* code_pages,
10661
+ void* pc);
9963
10662
  };
9964
10663
 
9965
10664
  // --- Implementation ---
@@ -9975,7 +10674,7 @@ Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) {
9975
10674
  }
9976
10675
 
9977
10676
  template <class T>
9978
- Local<T> Local<T>::New(Isolate* isolate, const TracedGlobal<T>& that) {
10677
+ Local<T> Local<T>::New(Isolate* isolate, const TracedReferenceBase<T>& that) {
9979
10678
  return New(isolate, that.val_);
9980
10679
  }
9981
10680
 
@@ -9992,7 +10691,7 @@ Local<T> Local<T>::New(Isolate* isolate, T* that) {
9992
10691
  template<class T>
9993
10692
  template<class S>
9994
10693
  void Eternal<T>::Set(Isolate* isolate, Local<S> handle) {
9995
- TYPE_CHECK(T, S);
10694
+ static_assert(std::is_base_of<T, S>::value, "type check");
9996
10695
  val_ = reinterpret_cast<T*>(
9997
10696
  V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle)));
9998
10697
  }
@@ -10036,7 +10735,7 @@ T* PersistentBase<T>::New(Isolate* isolate, T* that) {
10036
10735
  template <class T, class M>
10037
10736
  template <class S, class M2>
10038
10737
  void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
10039
- TYPE_CHECK(T, S);
10738
+ static_assert(std::is_base_of<T, S>::value, "type check");
10040
10739
  this->Reset();
10041
10740
  if (that.IsEmpty()) return;
10042
10741
  internal::Address* p = reinterpret_cast<internal::Address*>(that.val_);
@@ -10064,7 +10763,7 @@ void PersistentBase<T>::Reset() {
10064
10763
  template <class T>
10065
10764
  template <class S>
10066
10765
  void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
10067
- TYPE_CHECK(T, S);
10766
+ static_assert(std::is_base_of<T, S>::value, "type check");
10068
10767
  Reset();
10069
10768
  if (other.IsEmpty()) return;
10070
10769
  this->val_ = New(isolate, other.val_);
@@ -10075,7 +10774,7 @@ template <class T>
10075
10774
  template <class S>
10076
10775
  void PersistentBase<T>::Reset(Isolate* isolate,
10077
10776
  const PersistentBase<S>& other) {
10078
- TYPE_CHECK(T, S);
10777
+ static_assert(std::is_base_of<T, S>::value, "type check");
10079
10778
  Reset();
10080
10779
  if (other.IsEmpty()) return;
10081
10780
  this->val_ = New(isolate, other.val_);
@@ -10141,7 +10840,7 @@ Global<T>::Global(Global&& other) : PersistentBase<T>(other.val_) {
10141
10840
  template <class T>
10142
10841
  template <class S>
10143
10842
  Global<T>& Global<T>::operator=(Global<S>&& rhs) {
10144
- TYPE_CHECK(T, S);
10843
+ static_assert(std::is_base_of<T, S>::value, "type check");
10145
10844
  if (this != &rhs) {
10146
10845
  this->Reset();
10147
10846
  if (rhs.val_ != nullptr) {
@@ -10156,42 +10855,37 @@ Global<T>& Global<T>::operator=(Global<S>&& rhs) {
10156
10855
  }
10157
10856
 
10158
10857
  template <class T>
10159
- TracedGlobal<T>::WrappedForDestruction::~WrappedForDestruction() {
10160
- if (value == nullptr) return;
10161
- V8::DisposeTracedGlobal(reinterpret_cast<internal::Address*>(value));
10162
- value = nullptr;
10163
- }
10164
-
10165
- template <class T>
10166
- T* TracedGlobal<T>::New(Isolate* isolate, T* that, void* slot) {
10858
+ T* TracedReferenceBase<T>::New(Isolate* isolate, T* that, void* slot,
10859
+ DestructionMode destruction_mode) {
10167
10860
  if (that == nullptr) return nullptr;
10168
10861
  internal::Address* p = reinterpret_cast<internal::Address*>(that);
10169
10862
  return reinterpret_cast<T*>(V8::GlobalizeTracedReference(
10170
10863
  reinterpret_cast<internal::Isolate*>(isolate), p,
10171
10864
  reinterpret_cast<internal::Address*>(slot),
10172
- TracedGlobalTrait<TracedGlobal<T>>::kRequiresExplicitDestruction));
10865
+ destruction_mode == kWithDestructor));
10173
10866
  }
10174
10867
 
10175
10868
  template <class T>
10176
- void TracedGlobal<T>::Reset() {
10869
+ void TracedReferenceBase<T>::Reset() {
10177
10870
  if (IsEmpty()) return;
10178
- V8::DisposeTracedGlobal(reinterpret_cast<internal::Address*>(**this));
10871
+ V8::DisposeTracedGlobal(reinterpret_cast<internal::Address*>(val_));
10179
10872
  val_ = nullptr;
10180
10873
  }
10181
10874
 
10182
10875
  template <class T>
10183
10876
  template <class S>
10184
10877
  void TracedGlobal<T>::Reset(Isolate* isolate, const Local<S>& other) {
10185
- TYPE_CHECK(T, S);
10878
+ static_assert(std::is_base_of<T, S>::value, "type check");
10186
10879
  Reset();
10187
10880
  if (other.IsEmpty()) return;
10188
- this->val_ = New(isolate, other.val_, &val_);
10881
+ this->val_ = this->New(isolate, other.val_, &this->val_,
10882
+ TracedReferenceBase<T>::kWithDestructor);
10189
10883
  }
10190
10884
 
10191
10885
  template <class T>
10192
10886
  template <class S>
10193
10887
  TracedGlobal<T>& TracedGlobal<T>::operator=(TracedGlobal<S>&& rhs) {
10194
- TYPE_CHECK(T, S);
10888
+ static_assert(std::is_base_of<T, S>::value, "type check");
10195
10889
  *this = std::move(rhs.template As<T>());
10196
10890
  return *this;
10197
10891
  }
@@ -10199,7 +10893,7 @@ TracedGlobal<T>& TracedGlobal<T>::operator=(TracedGlobal<S>&& rhs) {
10199
10893
  template <class T>
10200
10894
  template <class S>
10201
10895
  TracedGlobal<T>& TracedGlobal<T>::operator=(const TracedGlobal<S>& rhs) {
10202
- TYPE_CHECK(T, S);
10896
+ static_assert(std::is_base_of<T, S>::value, "type check");
10203
10897
  *this = rhs.template As<T>();
10204
10898
  return *this;
10205
10899
  }
@@ -10207,14 +10901,9 @@ TracedGlobal<T>& TracedGlobal<T>::operator=(const TracedGlobal<S>& rhs) {
10207
10901
  template <class T>
10208
10902
  TracedGlobal<T>& TracedGlobal<T>::operator=(TracedGlobal&& rhs) {
10209
10903
  if (this != &rhs) {
10210
- this->Reset();
10211
- if (rhs.val_ != nullptr) {
10212
- this->val_ = rhs.val_;
10213
10904
  V8::MoveTracedGlobalReference(
10214
10905
  reinterpret_cast<internal::Address**>(&rhs.val_),
10215
10906
  reinterpret_cast<internal::Address**>(&this->val_));
10216
- rhs.val_ = nullptr;
10217
- }
10218
10907
  }
10219
10908
  return *this;
10220
10909
  }
@@ -10233,19 +10922,69 @@ TracedGlobal<T>& TracedGlobal<T>::operator=(const TracedGlobal& rhs) {
10233
10922
  }
10234
10923
 
10235
10924
  template <class T>
10236
- void TracedGlobal<T>::SetWrapperClassId(uint16_t class_id) {
10925
+ template <class S>
10926
+ void TracedReference<T>::Reset(Isolate* isolate, const Local<S>& other) {
10927
+ static_assert(std::is_base_of<T, S>::value, "type check");
10928
+ Reset();
10929
+ if (other.IsEmpty()) return;
10930
+ this->val_ = this->New(isolate, other.val_, &this->val_,
10931
+ TracedReferenceBase<T>::kWithoutDestructor);
10932
+ }
10933
+
10934
+ template <class T>
10935
+ template <class S>
10936
+ TracedReference<T>& TracedReference<T>::operator=(TracedReference<S>&& rhs) {
10937
+ static_assert(std::is_base_of<T, S>::value, "type check");
10938
+ *this = std::move(rhs.template As<T>());
10939
+ return *this;
10940
+ }
10941
+
10942
+ template <class T>
10943
+ template <class S>
10944
+ TracedReference<T>& TracedReference<T>::operator=(
10945
+ const TracedReference<S>& rhs) {
10946
+ static_assert(std::is_base_of<T, S>::value, "type check");
10947
+ *this = rhs.template As<T>();
10948
+ return *this;
10949
+ }
10950
+
10951
+ template <class T>
10952
+ TracedReference<T>& TracedReference<T>::operator=(TracedReference&& rhs) {
10953
+ if (this != &rhs) {
10954
+ V8::MoveTracedGlobalReference(
10955
+ reinterpret_cast<internal::Address**>(&rhs.val_),
10956
+ reinterpret_cast<internal::Address**>(&this->val_));
10957
+ }
10958
+ return *this;
10959
+ }
10960
+
10961
+ template <class T>
10962
+ TracedReference<T>& TracedReference<T>::operator=(const TracedReference& rhs) {
10963
+ if (this != &rhs) {
10964
+ this->Reset();
10965
+ if (rhs.val_ != nullptr) {
10966
+ V8::CopyTracedGlobalReference(
10967
+ reinterpret_cast<const internal::Address* const*>(&rhs.val_),
10968
+ reinterpret_cast<internal::Address**>(&this->val_));
10969
+ }
10970
+ }
10971
+ return *this;
10972
+ }
10973
+
10974
+ template <class T>
10975
+ void TracedReferenceBase<T>::SetWrapperClassId(uint16_t class_id) {
10237
10976
  typedef internal::Internals I;
10238
10977
  if (IsEmpty()) return;
10239
- internal::Address* obj = reinterpret_cast<internal::Address*>(**this);
10978
+ internal::Address* obj = reinterpret_cast<internal::Address*>(val_);
10240
10979
  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
10241
10980
  *reinterpret_cast<uint16_t*>(addr) = class_id;
10242
10981
  }
10243
10982
 
10244
10983
  template <class T>
10245
- uint16_t TracedGlobal<T>::WrapperClassId() const {
10984
+ uint16_t TracedReferenceBase<T>::WrapperClassId() const {
10246
10985
  typedef internal::Internals I;
10247
10986
  if (IsEmpty()) return 0;
10248
- internal::Address* obj = reinterpret_cast<internal::Address*>(**this);
10987
+ internal::Address* obj = reinterpret_cast<internal::Address*>(val_);
10249
10988
  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
10250
10989
  return *reinterpret_cast<uint16_t*>(addr);
10251
10990
  }
@@ -10254,7 +10993,7 @@ template <class T>
10254
10993
  void TracedGlobal<T>::SetFinalizationCallback(
10255
10994
  void* parameter, typename WeakCallbackInfo<void>::Callback callback) {
10256
10995
  V8::SetFinalizationCallbackTraced(
10257
- reinterpret_cast<internal::Address*>(**this), parameter, callback);
10996
+ reinterpret_cast<internal::Address*>(this->val_), parameter, callback);
10258
10997
  }
10259
10998
 
10260
10999
  template <typename T>
@@ -10263,7 +11002,7 @@ ReturnValue<T>::ReturnValue(internal::Address* slot) : value_(slot) {}
10263
11002
  template <typename T>
10264
11003
  template <typename S>
10265
11004
  void ReturnValue<T>::Set(const Global<S>& handle) {
10266
- TYPE_CHECK(T, S);
11005
+ static_assert(std::is_base_of<T, S>::value, "type check");
10267
11006
  if (V8_UNLIKELY(handle.IsEmpty())) {
10268
11007
  *value_ = GetDefaultValue();
10269
11008
  } else {
@@ -10273,19 +11012,20 @@ void ReturnValue<T>::Set(const Global<S>& handle) {
10273
11012
 
10274
11013
  template <typename T>
10275
11014
  template <typename S>
10276
- void ReturnValue<T>::Set(const TracedGlobal<S>& handle) {
10277
- TYPE_CHECK(T, S);
11015
+ void ReturnValue<T>::Set(const TracedReferenceBase<S>& handle) {
11016
+ static_assert(std::is_base_of<T, S>::value, "type check");
10278
11017
  if (V8_UNLIKELY(handle.IsEmpty())) {
10279
11018
  *value_ = GetDefaultValue();
10280
11019
  } else {
10281
- *value_ = *reinterpret_cast<internal::Address*>(*handle);
11020
+ *value_ = *reinterpret_cast<internal::Address*>(handle.val_);
10282
11021
  }
10283
11022
  }
10284
11023
 
10285
11024
  template <typename T>
10286
11025
  template <typename S>
10287
11026
  void ReturnValue<T>::Set(const Local<S> handle) {
10288
- TYPE_CHECK(T, S);
11027
+ static_assert(std::is_void<T>::value || std::is_base_of<T, S>::value,
11028
+ "type check");
10289
11029
  if (V8_UNLIKELY(handle.IsEmpty())) {
10290
11030
  *value_ = GetDefaultValue();
10291
11031
  } else {
@@ -10295,13 +11035,13 @@ void ReturnValue<T>::Set(const Local<S> handle) {
10295
11035
 
10296
11036
  template<typename T>
10297
11037
  void ReturnValue<T>::Set(double i) {
10298
- TYPE_CHECK(T, Number);
11038
+ static_assert(std::is_base_of<T, Number>::value, "type check");
10299
11039
  Set(Number::New(GetIsolate(), i));
10300
11040
  }
10301
11041
 
10302
11042
  template<typename T>
10303
11043
  void ReturnValue<T>::Set(int32_t i) {
10304
- TYPE_CHECK(T, Integer);
11044
+ static_assert(std::is_base_of<T, Integer>::value, "type check");
10305
11045
  typedef internal::Internals I;
10306
11046
  if (V8_LIKELY(I::IsValidSmi(i))) {
10307
11047
  *value_ = I::IntToSmi(i);
@@ -10312,7 +11052,7 @@ void ReturnValue<T>::Set(int32_t i) {
10312
11052
 
10313
11053
  template<typename T>
10314
11054
  void ReturnValue<T>::Set(uint32_t i) {
10315
- TYPE_CHECK(T, Integer);
11055
+ static_assert(std::is_base_of<T, Integer>::value, "type check");
10316
11056
  // Can't simply use INT32_MAX here for whatever reason.
10317
11057
  bool fits_into_int32_t = (i & (1U << 31)) == 0;
10318
11058
  if (V8_LIKELY(fits_into_int32_t)) {
@@ -10324,7 +11064,7 @@ void ReturnValue<T>::Set(uint32_t i) {
10324
11064
 
10325
11065
  template<typename T>
10326
11066
  void ReturnValue<T>::Set(bool value) {
10327
- TYPE_CHECK(T, Boolean);
11067
+ static_assert(std::is_base_of<T, Boolean>::value, "type check");
10328
11068
  typedef internal::Internals I;
10329
11069
  int root_index;
10330
11070
  if (value) {
@@ -10337,21 +11077,21 @@ void ReturnValue<T>::Set(bool value) {
10337
11077
 
10338
11078
  template<typename T>
10339
11079
  void ReturnValue<T>::SetNull() {
10340
- TYPE_CHECK(T, Primitive);
11080
+ static_assert(std::is_base_of<T, Primitive>::value, "type check");
10341
11081
  typedef internal::Internals I;
10342
11082
  *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
10343
11083
  }
10344
11084
 
10345
11085
  template<typename T>
10346
11086
  void ReturnValue<T>::SetUndefined() {
10347
- TYPE_CHECK(T, Primitive);
11087
+ static_assert(std::is_base_of<T, Primitive>::value, "type check");
10348
11088
  typedef internal::Internals I;
10349
11089
  *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
10350
11090
  }
10351
11091
 
10352
11092
  template<typename T>
10353
11093
  void ReturnValue<T>::SetEmptyString() {
10354
- TYPE_CHECK(T, String);
11094
+ static_assert(std::is_base_of<T, String>::value, "type check");
10355
11095
  typedef internal::Internals I;
10356
11096
  *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
10357
11097
  }
@@ -10373,8 +11113,7 @@ Local<Value> ReturnValue<T>::Get() const {
10373
11113
  template <typename T>
10374
11114
  template <typename S>
10375
11115
  void ReturnValue<T>::Set(S* whatever) {
10376
- // Uncompilable to prevent inadvertent misuse.
10377
- TYPE_CHECK(S*, Primitive);
11116
+ static_assert(sizeof(S) < 0, "incompilable to prevent inadvertent misuse");
10378
11117
  }
10379
11118
 
10380
11119
  template <typename T>
@@ -10391,14 +11130,24 @@ FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Address* implicit_args,
10391
11130
 
10392
11131
  template<typename T>
10393
11132
  Local<Value> FunctionCallbackInfo<T>::operator[](int i) const {
11133
+ // values_ points to the first argument (not the receiver).
10394
11134
  if (i < 0 || length_ <= i) return Local<Value>(*Undefined(GetIsolate()));
11135
+ #ifdef V8_REVERSE_JSARGS
11136
+ return Local<Value>(reinterpret_cast<Value*>(values_ + i));
11137
+ #else
10395
11138
  return Local<Value>(reinterpret_cast<Value*>(values_ - i));
11139
+ #endif
10396
11140
  }
10397
11141
 
10398
11142
 
10399
11143
  template<typename T>
10400
11144
  Local<Object> FunctionCallbackInfo<T>::This() const {
11145
+ // values_ points to the first argument (not the receiver).
11146
+ #ifdef V8_REVERSE_JSARGS
11147
+ return Local<Object>(reinterpret_cast<Object*>(values_ - 1));
11148
+ #else
10401
11149
  return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
11150
+ #endif
10402
11151
  }
10403
11152
 
10404
11153
 
@@ -10569,7 +11318,7 @@ Local<Value> Object::GetInternalField(int index) {
10569
11318
  #ifdef V8_COMPRESS_POINTERS
10570
11319
  // We read the full pointer value and then decompress it in order to avoid
10571
11320
  // dealing with potential endiannes issues.
10572
- value = I::DecompressTaggedAnyField(obj, static_cast<int32_t>(value));
11321
+ value = I::DecompressTaggedAnyField(obj, static_cast<uint32_t>(value));
10573
11322
  #endif
10574
11323
  internal::Isolate* isolate =
10575
11324
  internal::IsolateFromNeverReadOnlySpaceObject(obj);
@@ -11162,14 +11911,13 @@ MaybeLocal<T> Isolate::GetDataFromSnapshotOnce(size_t index) {
11162
11911
  int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
11163
11912
  int64_t change_in_bytes) {
11164
11913
  typedef internal::Internals I;
11165
- constexpr int64_t kMemoryReducerActivationLimit = 32 * 1024 * 1024;
11166
11914
  int64_t* external_memory = reinterpret_cast<int64_t*>(
11167
11915
  reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset);
11168
11916
  int64_t* external_memory_limit = reinterpret_cast<int64_t*>(
11169
11917
  reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset);
11170
- int64_t* external_memory_at_last_mc =
11918
+ int64_t* external_memory_low_since_mc =
11171
11919
  reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
11172
- I::kExternalMemoryAtLastMarkCompactOffset);
11920
+ I::kExternalMemoryLowSinceMarkCompactOffset);
11173
11921
 
11174
11922
  // Embedders are weird: we see both over- and underflows here. Perform the
11175
11923
  // addition with unsigned types to avoid undefined behavior.
@@ -11178,23 +11926,14 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
11178
11926
  static_cast<uint64_t>(*external_memory));
11179
11927
  *external_memory = amount;
11180
11928
 
11181
- int64_t allocation_diff_since_last_mc =
11182
- static_cast<int64_t>(static_cast<uint64_t>(*external_memory) -
11183
- static_cast<uint64_t>(*external_memory_at_last_mc));
11184
- // Only check memory pressure and potentially trigger GC if the amount of
11185
- // external memory increased.
11186
- if (allocation_diff_since_last_mc > kMemoryReducerActivationLimit) {
11187
- CheckMemoryPressure();
11929
+ if (amount < *external_memory_low_since_mc) {
11930
+ *external_memory_low_since_mc = amount;
11931
+ *external_memory_limit = amount + I::kExternalAllocationSoftLimit;
11188
11932
  }
11189
11933
 
11190
- if (change_in_bytes < 0) {
11191
- const int64_t lower_limit =
11192
- static_cast<int64_t>(static_cast<uint64_t>(*external_memory_limit) +
11193
- static_cast<uint64_t>(change_in_bytes));
11194
- if (lower_limit > I::kExternalAllocationSoftLimit) {
11195
- *external_memory_limit = lower_limit;
11196
- }
11197
- } else if (change_in_bytes > 0 && amount > *external_memory_limit) {
11934
+ if (change_in_bytes <= 0) return *external_memory;
11935
+
11936
+ if (amount > *external_memory_limit) {
11198
11937
  ReportExternalAllocationLimitReached();
11199
11938
  }
11200
11939
  return *external_memory;
@@ -11214,7 +11953,7 @@ Local<Value> Context::GetEmbedderData(int index) {
11214
11953
  // We read the full pointer value and then decompress it in order to avoid
11215
11954
  // dealing with potential endiannes issues.
11216
11955
  value =
11217
- I::DecompressTaggedAnyField(embedder_data, static_cast<int32_t>(value));
11956
+ I::DecompressTaggedAnyField(embedder_data, static_cast<uint32_t>(value));
11218
11957
  #endif
11219
11958
  internal::Isolate* isolate = internal::IsolateFromNeverReadOnlySpaceObject(
11220
11959
  *reinterpret_cast<A*>(this));
@@ -11276,8 +12015,4 @@ size_t SnapshotCreator::AddData(Local<T> object) {
11276
12015
 
11277
12016
  } // namespace v8
11278
12017
 
11279
-
11280
- #undef TYPE_CHECK
11281
-
11282
-
11283
12018
  #endif // INCLUDE_V8_H_