libv8-node 21.7.2.0-aarch64-linux-musl → 24.12.0.0-aarch64-linux-musl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8-node/location.rb +3 -5
  3. data/ext/libv8-node/paths.rb +2 -0
  4. data/lib/libv8/node/version.rb +7 -4
  5. data/lib/libv8/node.rb +2 -0
  6. data/lib/libv8-node.rb +2 -0
  7. data/vendor/v8/aarch64-linux-musl/libv8/obj/libv8_monolith.a +0 -0
  8. data/vendor/v8/include/cppgc/allocation.h +11 -13
  9. data/vendor/v8/include/cppgc/default-platform.h +3 -2
  10. data/vendor/v8/include/cppgc/garbage-collected.h +8 -0
  11. data/vendor/v8/include/cppgc/heap-consistency.h +1 -1
  12. data/vendor/v8/include/cppgc/heap-statistics.h +2 -0
  13. data/vendor/v8/include/cppgc/internal/api-constants.h +2 -14
  14. data/vendor/v8/include/cppgc/internal/base-page-handle.h +2 -4
  15. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +0 -4
  16. data/vendor/v8/include/cppgc/internal/caged-heap.h +0 -4
  17. data/vendor/v8/include/cppgc/internal/compiler-specific.h +9 -1
  18. data/vendor/v8/include/cppgc/internal/conditional-stack-allocated.h +41 -0
  19. data/vendor/v8/include/cppgc/internal/gc-info.h +12 -10
  20. data/vendor/v8/include/cppgc/internal/logging.h +3 -3
  21. data/vendor/v8/include/cppgc/internal/member-storage.h +69 -20
  22. data/vendor/v8/include/cppgc/internal/name-trait.h +5 -1
  23. data/vendor/v8/include/cppgc/internal/persistent-node.h +8 -3
  24. data/vendor/v8/include/cppgc/internal/pointer-policies.h +48 -11
  25. data/vendor/v8/include/cppgc/macros.h +21 -0
  26. data/vendor/v8/include/cppgc/member.h +70 -36
  27. data/vendor/v8/include/cppgc/name-provider.h +10 -0
  28. data/vendor/v8/include/cppgc/platform.h +11 -0
  29. data/vendor/v8/include/cppgc/type-traits.h +26 -4
  30. data/vendor/v8/include/cppgc/visitor.h +25 -1
  31. data/vendor/v8/include/libplatform/libplatform-export.h +2 -2
  32. data/vendor/v8/include/libplatform/v8-tracing.h +0 -1
  33. data/vendor/v8/include/v8-array-buffer.h +149 -46
  34. data/vendor/v8/include/v8-callbacks.h +100 -43
  35. data/vendor/v8/include/v8-container.h +54 -0
  36. data/vendor/v8/include/v8-context.h +92 -30
  37. data/vendor/v8/include/v8-cppgc.h +5 -56
  38. data/vendor/v8/include/v8-data.h +5 -0
  39. data/vendor/v8/include/v8-date.h +9 -0
  40. data/vendor/v8/include/v8-debug.h +11 -0
  41. data/vendor/v8/include/v8-embedder-heap.h +8 -20
  42. data/vendor/v8/include/v8-embedder-state-scope.h +2 -1
  43. data/vendor/v8/include/v8-exception.h +87 -9
  44. data/vendor/v8/include/v8-external-memory-accounter.h +60 -0
  45. data/vendor/v8/include/v8-fast-api-calls.h +67 -223
  46. data/vendor/v8/include/v8-forward.h +1 -0
  47. data/vendor/v8/include/v8-function-callback.h +296 -75
  48. data/vendor/v8/include/v8-function.h +11 -3
  49. data/vendor/v8/include/v8-handle-base.h +52 -82
  50. data/vendor/v8/include/v8-initialization.h +26 -1
  51. data/vendor/v8/include/v8-inspector.h +26 -27
  52. data/vendor/v8/include/v8-internal.h +960 -230
  53. data/vendor/v8/include/v8-isolate.h +347 -226
  54. data/vendor/v8/include/v8-local-handle.h +307 -55
  55. data/vendor/v8/include/v8-maybe.h +2 -1
  56. data/vendor/v8/include/v8-memory-span.h +284 -4
  57. data/vendor/v8/include/v8-message.h +11 -5
  58. data/vendor/v8/include/v8-metrics.h +15 -0
  59. data/vendor/v8/include/v8-microtask-queue.h +0 -5
  60. data/vendor/v8/include/v8-object.h +314 -41
  61. data/vendor/v8/include/v8-persistent-handle.h +29 -39
  62. data/vendor/v8/include/v8-platform.h +135 -77
  63. data/vendor/v8/include/v8-primitive.h +223 -5
  64. data/vendor/v8/include/v8-profiler.h +51 -2
  65. data/vendor/v8/include/v8-promise.h +2 -2
  66. data/vendor/v8/include/v8-proxy.h +0 -1
  67. data/vendor/v8/include/v8-regexp.h +0 -1
  68. data/vendor/v8/include/v8-sandbox.h +173 -0
  69. data/vendor/v8/include/v8-script.h +125 -27
  70. data/vendor/v8/include/v8-snapshot.h +130 -23
  71. data/vendor/v8/include/v8-source-location.h +6 -1
  72. data/vendor/v8/include/v8-statistics.h +10 -24
  73. data/vendor/v8/include/v8-template.h +320 -193
  74. data/vendor/v8/include/v8-trace-categories.h +23 -0
  75. data/vendor/v8/include/v8-traced-handle.h +99 -76
  76. data/vendor/v8/include/v8-typed-array.h +111 -7
  77. data/vendor/v8/include/v8-unwinder-state.h +2 -3
  78. data/vendor/v8/include/v8-unwinder.h +2 -1
  79. data/vendor/v8/include/v8-util.h +10 -125
  80. data/vendor/v8/include/v8-value-serializer-version.h +3 -3
  81. data/vendor/v8/include/v8-value.h +113 -6
  82. data/vendor/v8/include/v8-version.h +3 -3
  83. data/vendor/v8/include/v8-wasm.h +27 -0
  84. data/vendor/v8/include/v8-weak-callback-info.h +20 -12
  85. data/vendor/v8/include/v8.h +3 -3
  86. data/vendor/v8/include/v8config.h +116 -53
  87. metadata +55 -12
  88. data/vendor/v8/include/cppgc/ephemeron-pair.h +0 -30
@@ -5,10 +5,12 @@
5
5
  #ifndef INCLUDE_V8_OBJECT_H_
6
6
  #define INCLUDE_V8_OBJECT_H_
7
7
 
8
+ #include "v8-internal.h" // NOLINT(build/include_directory)
8
9
  #include "v8-local-handle.h" // NOLINT(build/include_directory)
9
10
  #include "v8-maybe.h" // NOLINT(build/include_directory)
10
11
  #include "v8-persistent-handle.h" // NOLINT(build/include_directory)
11
12
  #include "v8-primitive.h" // NOLINT(build/include_directory)
13
+ #include "v8-sandbox.h" // NOLINT(build/include_directory)
12
14
  #include "v8-traced-handle.h" // NOLINT(build/include_directory)
13
15
  #include "v8-value.h" // NOLINT(build/include_directory)
14
16
  #include "v8config.h" // NOLINT(build/include_directory)
@@ -146,18 +148,13 @@ enum PropertyAttribute {
146
148
  };
147
149
 
148
150
  /**
149
- * Accessor[Getter|Setter] are used as callback functions when
150
- * setting|getting a particular property. See Object and ObjectTemplate's
151
- * method SetAccessor.
151
+ * Accessor[Getter|Setter] are used as callback functions when setting|getting
152
+ * a particular data property. See Object::SetNativeDataProperty and
153
+ * ObjectTemplate::SetNativeDataProperty methods.
152
154
  */
153
- using AccessorGetterCallback =
154
- void (*)(Local<String> property, const PropertyCallbackInfo<Value>& info);
155
155
  using AccessorNameGetterCallback =
156
156
  void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
157
157
 
158
- using AccessorSetterCallback = void (*)(Local<String> property,
159
- Local<Value> value,
160
- const PropertyCallbackInfo<void>& info);
161
158
  using AccessorNameSetterCallback =
162
159
  void (*)(Local<Name> property, Local<Value> value,
163
160
  const PropertyCallbackInfo<void>& info);
@@ -170,12 +167,11 @@ using AccessorNameSetterCallback =
170
167
  * the kind of cross-context access that should be allowed.
171
168
  *
172
169
  */
173
- enum AccessControl {
174
- DEFAULT = 0,
175
- ALL_CAN_READ = 1,
176
- ALL_CAN_WRITE = 1 << 1,
177
- PROHIBITS_OVERWRITING V8_ENUM_DEPRECATE_SOON("unused") = 1 << 2
178
- };
170
+ enum V8_DEPRECATE_SOON(
171
+ "This enum is no longer used and will be removed in V8 12.9.")
172
+ AccessControl {
173
+ DEFAULT V8_ENUM_DEPRECATE_SOON("not used") = 0,
174
+ };
179
175
 
180
176
  /**
181
177
  * Property filter bits. They can be or'ed to build a composite filter.
@@ -242,6 +238,9 @@ class V8_EXPORT Object : public Value {
242
238
  */
243
239
  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
244
240
  Local<Value> key, Local<Value> value);
241
+ V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
242
+ Local<Value> key, Local<Value> value,
243
+ MaybeLocal<Object> receiver);
245
244
 
246
245
  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
247
246
  Local<Value> value);
@@ -297,6 +296,9 @@ class V8_EXPORT Object : public Value {
297
296
 
298
297
  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
299
298
  Local<Value> key);
299
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
300
+ Local<Value> key,
301
+ MaybeLocal<Object> receiver);
300
302
 
301
303
  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
302
304
  uint32_t index);
@@ -343,21 +345,12 @@ class V8_EXPORT Object : public Value {
343
345
  uint32_t index);
344
346
 
345
347
  /**
346
- * Note: SideEffectType affects the getter only, not the setter.
348
+ * Sets an accessor property like Template::SetAccessorProperty, but
349
+ * this method sets on this object directly.
347
350
  */
348
- V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
349
- Local<Context> context, Local<Name> name,
350
- AccessorNameGetterCallback getter,
351
- AccessorNameSetterCallback setter = nullptr,
352
- MaybeLocal<Value> data = MaybeLocal<Value>(),
353
- AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
354
- SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
355
- SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
356
-
357
351
  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
358
352
  Local<Function> setter = Local<Function>(),
359
- PropertyAttribute attributes = None,
360
- AccessControl settings = DEFAULT);
353
+ PropertyAttribute attributes = None);
361
354
 
362
355
  /**
363
356
  * Sets a native data property like Template::SetNativeDataProperty, but
@@ -434,16 +427,41 @@ class V8_EXPORT Object : public Value {
434
427
  * be skipped by __proto__ and it does not consult the security
435
428
  * handler.
436
429
  */
430
+ V8_DEPRECATE_SOON(
431
+ "V8 will stop providing access to hidden prototype (i.e. "
432
+ "JSGlobalObject). Use GetPrototypeV2() instead. "
433
+ "See http://crbug.com/333672197.")
437
434
  Local<Value> GetPrototype();
438
435
 
436
+ /**
437
+ * Get the prototype object (same as getting __proto__ property). This does
438
+ * not consult the security handler.
439
+ * TODO(333672197): rename back to GetPrototype() once the old version goes
440
+ * through the deprecation process and is removed.
441
+ */
442
+ Local<Value> GetPrototypeV2();
443
+
439
444
  /**
440
445
  * Set the prototype object. This does not skip objects marked to
441
446
  * be skipped by __proto__ and it does not consult the security
442
447
  * handler.
443
448
  */
449
+ V8_DEPRECATE_SOON(
450
+ "V8 will stop providing access to hidden prototype (i.e. "
451
+ "JSGlobalObject). Use SetPrototypeV2() instead. "
452
+ "See http://crbug.com/333672197.")
444
453
  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
445
454
  Local<Value> prototype);
446
455
 
456
+ /**
457
+ * Set the prototype object (same as setting __proto__ property). This does
458
+ * does not consult the security handler.
459
+ * TODO(333672197): rename back to SetPrototype() once the old version goes
460
+ * through the deprecation process and is removed.
461
+ */
462
+ V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototypeV2(Local<Context> context,
463
+ Local<Value> prototype);
464
+
447
465
  /**
448
466
  * Finds an instance of the given function template in the prototype
449
467
  * chain.
@@ -504,6 +522,8 @@ class V8_EXPORT Object : public Value {
504
522
  * leads to undefined behavior.
505
523
  */
506
524
  V8_INLINE void* GetAlignedPointerFromInternalField(int index);
525
+ V8_INLINE void* GetAlignedPointerFromInternalField(v8::Isolate* isolate,
526
+ int index);
507
527
 
508
528
  /** Same as above, but works for PersistentBase. */
509
529
  V8_INLINE static void* GetAlignedPointerFromInternalField(
@@ -529,7 +549,72 @@ class V8_EXPORT Object : public Value {
529
549
  void* values[]);
530
550
 
531
551
  /**
532
- * HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty().
552
+ * Unwraps a JS wrapper object.
553
+ *
554
+ * \param tag The tag for retrieving the wrappable instance. Must match the
555
+ * tag that has been used for a previous `Wrap()` operation.
556
+ * \param isolate The Isolate for the `wrapper` object.
557
+ * \param wrapper The JS wrapper object that should be unwrapped.
558
+ * \returns the C++ wrappable instance, or nullptr if the JS object has never
559
+ * been wrapped.
560
+ */
561
+ template <CppHeapPointerTag tag, typename T = void>
562
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
563
+ const v8::Local<v8::Object>& wrapper);
564
+ template <CppHeapPointerTag tag, typename T = void>
565
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
566
+ const PersistentBase<Object>& wrapper);
567
+ template <CppHeapPointerTag tag, typename T = void>
568
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
569
+ const BasicTracedReference<Object>& wrapper);
570
+
571
+ template <typename T = void>
572
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
573
+ const v8::Local<v8::Object>& wrapper,
574
+ CppHeapPointerTagRange tag_range);
575
+ template <typename T = void>
576
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
577
+ const PersistentBase<Object>& wrapper,
578
+ CppHeapPointerTagRange tag_range);
579
+ template <typename T = void>
580
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
581
+ const BasicTracedReference<Object>& wrapper,
582
+ CppHeapPointerTagRange tag_range);
583
+
584
+ /**
585
+ * Wraps a JS wrapper with a C++ instance.
586
+ *
587
+ * \param tag The pointer tag that should be used for storing this object.
588
+ * Future `Unwrap()` operations must provide a matching tag.
589
+ * \param isolate The Isolate for the `wrapper` object.
590
+ * \param wrapper The JS wrapper object.
591
+ * \param wrappable The C++ object instance that is wrapped by the JS object.
592
+ */
593
+ template <CppHeapPointerTag tag>
594
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
595
+ const v8::Local<v8::Object>& wrapper,
596
+ void* wrappable);
597
+ template <CppHeapPointerTag tag>
598
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
599
+ const PersistentBase<Object>& wrapper,
600
+ void* wrappable);
601
+ template <CppHeapPointerTag tag>
602
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
603
+ const BasicTracedReference<Object>& wrapper,
604
+ void* wrappable);
605
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
606
+ const v8::Local<v8::Object>& wrapper,
607
+ void* wrappable, CppHeapPointerTag tag);
608
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
609
+ const PersistentBase<Object>& wrapper,
610
+ void* wrappable, CppHeapPointerTag tag);
611
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
612
+ const BasicTracedReference<Object>& wrapper,
613
+ void* wrappable, CppHeapPointerTag tag);
614
+
615
+ /**
616
+ * HasOwnProperty() is like JavaScript's
617
+ * Object.prototype.hasOwnProperty().
533
618
  *
534
619
  * See also v8::Object::Has() and v8::Object::HasRealNamedProperty().
535
620
  */
@@ -605,27 +690,40 @@ class V8_EXPORT Object : public Value {
605
690
  int GetIdentityHash();
606
691
 
607
692
  /**
608
- * Clone this object with a fast but shallow copy. Values will point
609
- * to the same values as the original object.
693
+ * Clone this object with a fast but shallow copy. Values will point to the
694
+ * same values as the original object.
695
+ *
696
+ * Prefer using version with Isolate parameter.
610
697
  */
611
- // TODO(dcarney): take an isolate and optionally bail out?
698
+ Local<Object> Clone(v8::Isolate* isolate);
612
699
  Local<Object> Clone();
613
700
 
614
701
  /**
615
702
  * Returns the context in which the object was created.
703
+ *
704
+ * Prefer using version with Isolate parameter.
616
705
  */
706
+ MaybeLocal<Context> GetCreationContext(v8::Isolate* isolate);
707
+ V8_DEPRECATE_SOON("Use the version with the isolate argument.")
617
708
  MaybeLocal<Context> GetCreationContext();
618
709
 
619
710
  /**
620
- * Shortcut for GetCreationContext().ToLocalChecked().
711
+ * Shortcut for GetCreationContext(...).ToLocalChecked().
712
+ *
713
+ * Prefer using version with Isolate parameter.
621
714
  **/
715
+ Local<Context> GetCreationContextChecked(v8::Isolate* isolate);
716
+ V8_DEPRECATE_SOON("Use the version with the isolate argument.")
622
717
  Local<Context> GetCreationContextChecked();
623
718
 
624
719
  /** Same as above, but works for Persistents */
625
720
  V8_INLINE static MaybeLocal<Context> GetCreationContext(
626
- const PersistentBase<Object>& object) {
627
- return object.template value<Object>()->GetCreationContext();
721
+ v8::Isolate* isolate, const PersistentBase<Object>& object) {
722
+ return object.template value<Object>()->GetCreationContext(isolate);
628
723
  }
724
+ V8_DEPRECATE_SOON("Use the version with the isolate argument.")
725
+ V8_INLINE static MaybeLocal<Context> GetCreationContext(
726
+ const PersistentBase<Object>& object);
629
727
 
630
728
  /**
631
729
  * Gets the context in which the object was created (see GetCreationContext())
@@ -637,7 +735,12 @@ class V8_EXPORT Object : public Value {
637
735
  * try to expand the embedder data attached to the context.
638
736
  * In case the Local<Context> is already available because of other reasons,
639
737
  * it's fine to keep using Context::GetAlignedPointerFromEmbedderData().
738
+ *
739
+ * Prefer using version with Isolate parameter if you have an Isolate,
740
+ * otherwise use the other one.
640
741
  */
742
+ void* GetAlignedPointerFromEmbedderDataInCreationContext(v8::Isolate* isolate,
743
+ int index);
641
744
  void* GetAlignedPointerFromEmbedderDataInCreationContext(int index);
642
745
 
643
746
  /**
@@ -653,11 +756,15 @@ class V8_EXPORT Object : public Value {
653
756
  bool IsConstructor() const;
654
757
 
655
758
  /**
656
- * True if this object can carry information relevant to the embedder in its
657
- * embedder fields, false otherwise. This is generally true for objects
658
- * constructed through function templates but also holds for other types where
659
- * V8 automatically adds internal fields at compile time, such as e.g.
660
- * v8::ArrayBuffer.
759
+ * Returns true if this object can be generally used to wrap object objects.
760
+ * This means that the object either follows the convention of using embedder
761
+ * fields to denote type/instance pointers or is using the Wrap()/Unwrap()
762
+ * APIs for the same purpose. Returns false otherwise.
763
+ *
764
+ * Note that there may be other objects that use embedder fields but are not
765
+ * used as API wrapper objects. E.g., v8::Promise may in certain configuration
766
+ * use embedder fields but promises are not generally supported as API
767
+ * wrappers. The method will return false in those cases.
661
768
  */
662
769
  bool IsApiWrapper() const;
663
770
 
@@ -732,10 +839,16 @@ class V8_EXPORT Object : public Value {
732
839
  bool IsCodeLike(Isolate* isolate) const;
733
840
 
734
841
  private:
842
+ static void* Unwrap(v8::Isolate* isolate, internal::Address wrapper_obj,
843
+ CppHeapPointerTagRange tag_range);
844
+ static void Wrap(v8::Isolate* isolate, internal::Address wrapper_obj,
845
+ CppHeapPointerTag tag, void* wrappable);
846
+
735
847
  Object();
736
848
  static void CheckCast(Value* obj);
737
849
  Local<Data> SlowGetInternalField(int index);
738
850
  void* SlowGetAlignedPointerFromInternalField(int index);
851
+ void* SlowGetAlignedPointerFromInternalField(v8::Isolate* isolate, int index);
739
852
  };
740
853
 
741
854
  // --- Implementation ---
@@ -749,7 +862,8 @@ Local<Data> Object::GetInternalField(int index) {
749
862
  // know where to find the internal fields and can return the value directly.
750
863
  int instance_type = I::GetInstanceType(obj);
751
864
  if (I::CanHaveInternalField(instance_type)) {
752
- int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
865
+ int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
866
+ (I::kEmbedderDataSlotSize * index);
753
867
  A value = I::ReadRawField<A>(obj, offset);
754
868
  #ifdef V8_COMPRESS_POINTERS
755
869
  // We read the full pointer value and then decompress it in order to avoid
@@ -765,6 +879,28 @@ Local<Data> Object::GetInternalField(int index) {
765
879
  return SlowGetInternalField(index);
766
880
  }
767
881
 
882
+ void* Object::GetAlignedPointerFromInternalField(v8::Isolate* isolate,
883
+ int index) {
884
+ #if !defined(V8_ENABLE_CHECKS)
885
+ using A = internal::Address;
886
+ using I = internal::Internals;
887
+ A obj = internal::ValueHelper::ValueAsAddress(this);
888
+ // Fast path: If the object is a plain JSObject, which is the common case, we
889
+ // know where to find the internal fields and can return the value directly.
890
+ auto instance_type = I::GetInstanceType(obj);
891
+ if (V8_LIKELY(I::CanHaveInternalField(instance_type))) {
892
+ int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
893
+ (I::kEmbedderDataSlotSize * index) +
894
+ I::kEmbedderDataSlotExternalPointerOffset;
895
+ A value =
896
+ I::ReadExternalPointerField<internal::kEmbedderDataSlotPayloadTag>(
897
+ isolate, obj, offset);
898
+ return reinterpret_cast<void*>(value);
899
+ }
900
+ #endif
901
+ return SlowGetAlignedPointerFromInternalField(isolate, index);
902
+ }
903
+
768
904
  void* Object::GetAlignedPointerFromInternalField(int index) {
769
905
  #if !defined(V8_ENABLE_CHECKS)
770
906
  using A = internal::Address;
@@ -773,8 +909,9 @@ void* Object::GetAlignedPointerFromInternalField(int index) {
773
909
  // Fast path: If the object is a plain JSObject, which is the common case, we
774
910
  // know where to find the internal fields and can return the value directly.
775
911
  auto instance_type = I::GetInstanceType(obj);
776
- if (I::CanHaveInternalField(instance_type)) {
777
- int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index) +
912
+ if (V8_LIKELY(I::CanHaveInternalField(instance_type))) {
913
+ int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
914
+ (I::kEmbedderDataSlotSize * index) +
778
915
  I::kEmbedderDataSlotExternalPointerOffset;
779
916
  Isolate* isolate = I::GetIsolateForSandbox(obj);
780
917
  A value =
@@ -786,6 +923,142 @@ void* Object::GetAlignedPointerFromInternalField(int index) {
786
923
  return SlowGetAlignedPointerFromInternalField(index);
787
924
  }
788
925
 
926
+ // static
927
+ template <CppHeapPointerTag tag, typename T>
928
+ T* Object::Unwrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper) {
929
+ CppHeapPointerTagRange tag_range(tag, tag);
930
+ auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
931
+ #if !defined(V8_ENABLE_CHECKS)
932
+ return internal::ReadCppHeapPointerField<T>(
933
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
934
+ #else // defined(V8_ENABLE_CHECKS)
935
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
936
+ #endif // defined(V8_ENABLE_CHECKS)
937
+ }
938
+
939
+ // static
940
+ template <CppHeapPointerTag tag, typename T>
941
+ T* Object::Unwrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper) {
942
+ CppHeapPointerTagRange tag_range(tag, tag);
943
+ auto obj =
944
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
945
+ #if !defined(V8_ENABLE_CHECKS)
946
+ return internal::ReadCppHeapPointerField<T>(
947
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
948
+ #else // defined(V8_ENABLE_CHECKS)
949
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
950
+ #endif // defined(V8_ENABLE_CHECKS)
951
+ }
952
+
953
+ // static
954
+ template <CppHeapPointerTag tag, typename T>
955
+ T* Object::Unwrap(v8::Isolate* isolate,
956
+ const BasicTracedReference<Object>& wrapper) {
957
+ CppHeapPointerTagRange tag_range(tag, tag);
958
+ auto obj =
959
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
960
+ #if !defined(V8_ENABLE_CHECKS)
961
+ return internal::ReadCppHeapPointerField<T>(
962
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
963
+ #else // defined(V8_ENABLE_CHECKS)
964
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
965
+ #endif // defined(V8_ENABLE_CHECKS)
966
+ }
967
+
968
+ // static
969
+ template <typename T>
970
+ T* Object::Unwrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
971
+ CppHeapPointerTagRange tag_range) {
972
+ auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
973
+ #if !defined(V8_ENABLE_CHECKS)
974
+ return internal::ReadCppHeapPointerField<T>(
975
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
976
+ #else // defined(V8_ENABLE_CHECKS)
977
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
978
+ #endif // defined(V8_ENABLE_CHECKS)
979
+ }
980
+
981
+ // static
982
+ template <typename T>
983
+ T* Object::Unwrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper,
984
+ CppHeapPointerTagRange tag_range) {
985
+ auto obj =
986
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
987
+ #if !defined(V8_ENABLE_CHECKS)
988
+ return internal::ReadCppHeapPointerField<T>(
989
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
990
+ #else // defined(V8_ENABLE_CHECKS)
991
+
992
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
993
+ #endif // defined(V8_ENABLE_CHECKS)
994
+ }
995
+
996
+ // static
997
+ template <typename T>
998
+ T* Object::Unwrap(v8::Isolate* isolate,
999
+ const BasicTracedReference<Object>& wrapper,
1000
+ CppHeapPointerTagRange tag_range) {
1001
+ auto obj =
1002
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1003
+ #if !defined(V8_ENABLE_CHECKS)
1004
+ return internal::ReadCppHeapPointerField<T>(
1005
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1006
+ #else // defined(V8_ENABLE_CHECKS)
1007
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1008
+ #endif // defined(V8_ENABLE_CHECKS)
1009
+ }
1010
+
1011
+ // static
1012
+ template <CppHeapPointerTag tag>
1013
+ void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1014
+ void* wrappable) {
1015
+ auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1016
+ Wrap(isolate, obj, tag, wrappable);
1017
+ }
1018
+
1019
+ // static
1020
+ template <CppHeapPointerTag tag>
1021
+ void Object::Wrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper,
1022
+ void* wrappable) {
1023
+ auto obj =
1024
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1025
+ Wrap(isolate, obj, tag, wrappable);
1026
+ }
1027
+
1028
+ // static
1029
+ template <CppHeapPointerTag tag>
1030
+ void Object::Wrap(v8::Isolate* isolate,
1031
+ const BasicTracedReference<Object>& wrapper,
1032
+ void* wrappable) {
1033
+ auto obj =
1034
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1035
+ Wrap(isolate, obj, tag, wrappable);
1036
+ }
1037
+
1038
+ // static
1039
+ void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1040
+ void* wrappable, CppHeapPointerTag tag) {
1041
+ auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1042
+ Wrap(isolate, obj, tag, wrappable);
1043
+ }
1044
+
1045
+ // static
1046
+ void Object::Wrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper,
1047
+ void* wrappable, CppHeapPointerTag tag) {
1048
+ auto obj =
1049
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1050
+ Wrap(isolate, obj, tag, wrappable);
1051
+ }
1052
+
1053
+ // static
1054
+ void Object::Wrap(v8::Isolate* isolate,
1055
+ const BasicTracedReference<Object>& wrapper, void* wrappable,
1056
+ CppHeapPointerTag tag) {
1057
+ auto obj =
1058
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1059
+ Wrap(isolate, obj, tag, wrappable);
1060
+ }
1061
+
789
1062
  Private* Private::Cast(Data* data) {
790
1063
  #ifdef V8_ENABLE_CHECKS
791
1064
  CheckCast(data);
@@ -15,8 +15,6 @@ namespace v8 {
15
15
  class Isolate;
16
16
  template <class K, class V, class T>
17
17
  class PersistentValueMapBase;
18
- template <class V, class T>
19
- class PersistentValueVector;
20
18
  template <class T>
21
19
  class Global;
22
20
  template <class T>
@@ -44,11 +42,15 @@ V8_EXPORT void MoveGlobalReference(internal::Address** from,
44
42
  * isolate.
45
43
  */
46
44
  template <class T>
47
- class Eternal : public IndirectHandleBase {
45
+ class Eternal : public api_internal::IndirectHandleBase {
48
46
  public:
49
47
  V8_INLINE Eternal() = default;
50
48
 
49
+ /**
50
+ * Constructor for handling automatic up casting.
51
+ */
51
52
  template <class S>
53
+ requires(std::is_base_of_v<T, S>)
52
54
  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) {
53
55
  Set(isolate, handle);
54
56
  }
@@ -61,8 +63,8 @@ class Eternal : public IndirectHandleBase {
61
63
  }
62
64
 
63
65
  template <class S>
66
+ requires(std::is_base_of_v<T, S>)
64
67
  void Set(Isolate* isolate, Local<S> handle) {
65
- static_assert(std::is_base_of<T, S>::value, "type check");
66
68
  slot() =
67
69
  api_internal::Eternalize(isolate, *handle.template UnsafeAs<Value>());
68
70
  }
@@ -88,7 +90,7 @@ V8_EXPORT void MakeWeak(internal::Address* location, void* data,
88
90
  *
89
91
  */
90
92
  template <class T>
91
- class PersistentBase : public IndirectHandleBase {
93
+ class PersistentBase : public api_internal::IndirectHandleBase {
92
94
  public:
93
95
  /**
94
96
  * If non-empty, destroy the underlying storage cell
@@ -204,8 +206,6 @@ class PersistentBase : public IndirectHandleBase {
204
206
  friend class ReturnValue;
205
207
  template <class F1, class F2, class F3>
206
208
  friend class PersistentValueMapBase;
207
- template <class F1, class F2>
208
- friend class PersistentValueVector;
209
209
  friend class Object;
210
210
  friend class internal::ValueHelper;
211
211
 
@@ -236,28 +236,15 @@ class NonCopyablePersistentTraits {
236
236
  }
237
237
  };
238
238
 
239
- /**
240
- * Helper class traits to allow copying and assignment of Persistent.
241
- * This will clone the contents of storage cell, but not any of the flags, etc.
242
- */
243
- template <class T>
244
- struct CopyablePersistentTraits {
245
- using CopyablePersistent = Persistent<T, CopyablePersistentTraits<T>>;
246
- static const bool kResetInDestructor = true;
247
- template <class S, class M>
248
- static V8_INLINE void Copy(const Persistent<S, M>& source,
249
- CopyablePersistent* dest) {
250
- // do nothing, just allow copy
251
- }
252
- };
253
-
254
239
  /**
255
240
  * A PersistentBase which allows copy and assignment.
256
241
  *
257
242
  * Copy, assignment and destructor behavior is controlled by the traits
258
243
  * class M.
259
244
  *
260
- * Note: Persistent class hierarchy is subject to future changes.
245
+ * CAVEAT: Persistent objects do not have proper destruction behavior by default
246
+ * and as such will leak the object without explicit clear. Consider using
247
+ * `v8::Global` instead which has proper destruction and move semantics.
261
248
  */
262
249
  template <class T, class M>
263
250
  class Persistent : public PersistentBase<T> {
@@ -268,28 +255,26 @@ class Persistent : public PersistentBase<T> {
268
255
  V8_INLINE Persistent() = default;
269
256
 
270
257
  /**
271
- * Construct a Persistent from a Local.
258
+ * Construct a Persistent from a Local with automatic up casting.
272
259
  * When the Local is non-empty, a new storage cell is created
273
260
  * pointing to the same object, and no flags are set.
274
261
  */
275
262
  template <class S>
263
+ requires(std::is_base_of_v<T, S>)
276
264
  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
277
265
  : PersistentBase<T>(
278
- PersistentBase<T>::New(isolate, that.template value<S>())) {
279
- static_assert(std::is_base_of<T, S>::value, "type check");
280
- }
266
+ PersistentBase<T>::New(isolate, that.template value<S>())) {}
281
267
 
282
268
  /**
283
- * Construct a Persistent from a Persistent.
269
+ * Construct a Persistent from a Persistent with automatic up casting.
284
270
  * When the Persistent is non-empty, a new storage cell is created
285
271
  * pointing to the same object, and no flags are set.
286
272
  */
287
273
  template <class S, class M2>
274
+ requires(std::is_base_of_v<T, S>)
288
275
  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
289
276
  : PersistentBase<T>(
290
- PersistentBase<T>::New(isolate, that.template value<S>())) {
291
- static_assert(std::is_base_of<T, S>::value, "type check");
292
- }
277
+ PersistentBase<T>::New(isolate, that.template value<S>())) {}
293
278
 
294
279
  /**
295
280
  * The copy constructors and assignment operator create a Persistent
@@ -369,28 +354,26 @@ class Global : public PersistentBase<T> {
369
354
  V8_INLINE Global() = default;
370
355
 
371
356
  /**
372
- * Construct a Global from a Local.
357
+ * Construct a Global from a Local with automatic up casting.
373
358
  * When the Local is non-empty, a new storage cell is created
374
359
  * pointing to the same object, and no flags are set.
375
360
  */
376
361
  template <class S>
362
+ requires(std::is_base_of_v<T, S>)
377
363
  V8_INLINE Global(Isolate* isolate, Local<S> that)
378
364
  : PersistentBase<T>(
379
- PersistentBase<T>::New(isolate, that.template value<S>())) {
380
- static_assert(std::is_base_of<T, S>::value, "type check");
381
- }
365
+ PersistentBase<T>::New(isolate, that.template value<S>())) {}
382
366
 
383
367
  /**
384
- * Construct a Global from a PersistentBase.
368
+ * Construct a Global from a PersistentBase with automatic up casting.
385
369
  * When the Persistent is non-empty, a new storage cell is created
386
370
  * pointing to the same object, and no flags are set.
387
371
  */
388
372
  template <class S>
373
+ requires(std::is_base_of_v<T, S>)
389
374
  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
390
375
  : PersistentBase<T>(
391
- PersistentBase<T>::New(isolate, that.template value<S>())) {
392
- static_assert(std::is_base_of<T, S>::value, "type check");
393
- }
376
+ PersistentBase<T>::New(isolate, that.template value<S>())) {}
394
377
 
395
378
  /**
396
379
  * Move constructor.
@@ -505,9 +488,16 @@ V8_INLINE void PersistentBase<T>::SetWeak(
505
488
  #if (__GNUC__ >= 8) && !defined(__clang__)
506
489
  #pragma GCC diagnostic push
507
490
  #pragma GCC diagnostic ignored "-Wcast-function-type"
491
+ #endif
492
+ #if __clang__
493
+ #pragma clang diagnostic push
494
+ #pragma clang diagnostic ignored "-Wcast-function-type"
508
495
  #endif
509
496
  api_internal::MakeWeak(this->slot(), parameter,
510
497
  reinterpret_cast<Callback>(callback), type);
498
+ #if __clang__
499
+ #pragma clang diagnostic pop
500
+ #endif
511
501
  #if (__GNUC__ >= 8) && !defined(__clang__)
512
502
  #pragma GCC diagnostic pop
513
503
  #endif