libv8-node 22.7.0.4-x86_64-darwin → 23.6.1.0-x86_64-darwin
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.
- checksums.yaml +4 -4
- data/lib/libv8/node/version.rb +3 -3
- data/vendor/v8/include/cppgc/allocation.h +10 -11
- data/vendor/v8/include/cppgc/garbage-collected.h +8 -0
- data/vendor/v8/include/cppgc/heap-statistics.h +2 -0
- data/vendor/v8/include/cppgc/internal/api-constants.h +6 -1
- data/vendor/v8/include/cppgc/internal/compiler-specific.h +9 -1
- data/vendor/v8/include/cppgc/internal/gc-info.h +12 -10
- data/vendor/v8/include/cppgc/internal/member-storage.h +6 -0
- data/vendor/v8/include/cppgc/internal/name-trait.h +5 -1
- data/vendor/v8/include/cppgc/name-provider.h +7 -0
- data/vendor/v8/include/v8-array-buffer.h +44 -24
- data/vendor/v8/include/v8-callbacks.h +10 -5
- data/vendor/v8/include/v8-context.h +41 -9
- data/vendor/v8/include/v8-cppgc.h +3 -55
- data/vendor/v8/include/v8-date.h +9 -0
- data/vendor/v8/include/v8-embedder-heap.h +4 -1
- data/vendor/v8/include/v8-exception.h +70 -0
- data/vendor/v8/include/v8-fast-api-calls.h +31 -38
- data/vendor/v8/include/v8-function-callback.h +203 -62
- data/vendor/v8/include/v8-function.h +4 -3
- data/vendor/v8/include/v8-handle-base.h +2 -2
- data/vendor/v8/include/v8-initialization.h +18 -1
- data/vendor/v8/include/v8-inspector.h +6 -3
- data/vendor/v8/include/v8-internal.h +303 -58
- data/vendor/v8/include/v8-isolate.h +58 -39
- data/vendor/v8/include/v8-local-handle.h +18 -19
- data/vendor/v8/include/v8-message.h +0 -21
- data/vendor/v8/include/v8-metrics.h +4 -0
- data/vendor/v8/include/v8-microtask-queue.h +0 -5
- data/vendor/v8/include/v8-object.h +284 -35
- data/vendor/v8/include/v8-persistent-handle.h +0 -19
- data/vendor/v8/include/v8-platform.h +21 -35
- data/vendor/v8/include/v8-primitive.h +92 -1
- data/vendor/v8/include/v8-profiler.h +38 -1
- data/vendor/v8/include/v8-promise.h +2 -2
- data/vendor/v8/include/v8-sandbox.h +173 -0
- data/vendor/v8/include/v8-script.h +44 -14
- data/vendor/v8/include/v8-snapshot.h +38 -2
- data/vendor/v8/include/v8-template.h +105 -263
- data/vendor/v8/include/v8-traced-handle.h +4 -15
- data/vendor/v8/include/v8-unwinder.h +2 -1
- data/vendor/v8/include/v8-util.h +1 -117
- data/vendor/v8/include/v8-value.h +3 -2
- data/vendor/v8/include/v8-version.h +3 -3
- data/vendor/v8/include/v8-wasm.h +3 -0
- data/vendor/v8/include/v8config.h +51 -7
- data/vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a +0 -0
- metadata +4 -3
@@ -223,6 +223,12 @@ class V8_EXPORT String : public Name {
|
|
223
223
|
*/
|
224
224
|
bool IsExternalOneByte() const;
|
225
225
|
|
226
|
+
/**
|
227
|
+
* Returns the internalized string. See `NewStringType::kInternalized` for
|
228
|
+
* details on internalized strings.
|
229
|
+
*/
|
230
|
+
Local<String> InternalizeString(Isolate* isolate);
|
231
|
+
|
226
232
|
class V8_EXPORT ExternalStringResourceBase {
|
227
233
|
public:
|
228
234
|
virtual ~ExternalStringResourceBase() = default;
|
@@ -382,6 +388,8 @@ class V8_EXPORT String : public Name {
|
|
382
388
|
* regardless of the encoding, otherwise return NULL. The encoding of the
|
383
389
|
* string is returned in encoding_out.
|
384
390
|
*/
|
391
|
+
V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
|
392
|
+
v8::Isolate* isolate, Encoding* encoding_out) const;
|
385
393
|
V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
|
386
394
|
Encoding* encoding_out) const;
|
387
395
|
|
@@ -507,10 +515,15 @@ class V8_EXPORT String : public Name {
|
|
507
515
|
* (e.g. due to an exception in the toString() method of the object)
|
508
516
|
* then the length() method returns 0 and the * operator returns
|
509
517
|
* NULL.
|
518
|
+
*
|
519
|
+
* WARNING: This will unconditionally copy the contents of the JavaScript
|
520
|
+
* string, and should be avoided in situations where performance is a concern.
|
521
|
+
* Consider using WriteUtf8() instead.
|
510
522
|
*/
|
511
523
|
class V8_EXPORT Utf8Value {
|
512
524
|
public:
|
513
|
-
Utf8Value(Isolate* isolate, Local<v8::Value> obj
|
525
|
+
Utf8Value(Isolate* isolate, Local<v8::Value> obj,
|
526
|
+
WriteOptions options = REPLACE_INVALID_UTF8);
|
514
527
|
~Utf8Value();
|
515
528
|
char* operator*() { return str_; }
|
516
529
|
const char* operator*() const { return str_; }
|
@@ -527,12 +540,19 @@ class V8_EXPORT String : public Name {
|
|
527
540
|
|
528
541
|
/**
|
529
542
|
* Converts an object to a two-byte (UTF-16-encoded) string.
|
543
|
+
*
|
530
544
|
* If conversion to a string fails (eg. due to an exception in the toString()
|
531
545
|
* method of the object) then the length() method returns 0 and the * operator
|
532
546
|
* returns NULL.
|
547
|
+
*
|
548
|
+
* WARNING: This will unconditionally copy the contents of the JavaScript
|
549
|
+
* string, and should be avoided in situations where performance is a concern.
|
533
550
|
*/
|
534
551
|
class V8_EXPORT Value {
|
535
552
|
public:
|
553
|
+
V8_DEPRECATE_SOON(
|
554
|
+
"Prefer using String::ValueView if you can, or string->Write to a "
|
555
|
+
"buffer if you cannot.")
|
536
556
|
Value(Isolate* isolate, Local<v8::Value> obj);
|
537
557
|
~Value();
|
538
558
|
uint16_t* operator*() { return str_; }
|
@@ -548,6 +568,55 @@ class V8_EXPORT String : public Name {
|
|
548
568
|
int length_;
|
549
569
|
};
|
550
570
|
|
571
|
+
/**
|
572
|
+
* Returns a view onto a string's contents.
|
573
|
+
*
|
574
|
+
* WARNING: This does not copy the string's contents, and will therefore be
|
575
|
+
* invalidated if the GC can move the string while the ValueView is alive. It
|
576
|
+
* is therefore required that no GC or allocation can happen while there is an
|
577
|
+
* active ValueView. This requirement may be relaxed in the future.
|
578
|
+
*
|
579
|
+
* V8 strings are either encoded as one-byte or two-bytes per character.
|
580
|
+
*/
|
581
|
+
class V8_EXPORT ValueView {
|
582
|
+
public:
|
583
|
+
ValueView(Isolate* isolate, Local<v8::String> str);
|
584
|
+
~ValueView();
|
585
|
+
const uint8_t* data8() const {
|
586
|
+
#if V8_ENABLE_CHECKS
|
587
|
+
CheckOneByte(true);
|
588
|
+
#endif
|
589
|
+
return data8_;
|
590
|
+
}
|
591
|
+
const uint16_t* data16() const {
|
592
|
+
#if V8_ENABLE_CHECKS
|
593
|
+
CheckOneByte(false);
|
594
|
+
#endif
|
595
|
+
return data16_;
|
596
|
+
}
|
597
|
+
int length() const { return length_; }
|
598
|
+
bool is_one_byte() const { return is_one_byte_; }
|
599
|
+
|
600
|
+
// Disallow copying and assigning.
|
601
|
+
ValueView(const ValueView&) = delete;
|
602
|
+
void operator=(const ValueView&) = delete;
|
603
|
+
|
604
|
+
private:
|
605
|
+
void CheckOneByte(bool is_one_byte) const;
|
606
|
+
|
607
|
+
Local<v8::String> flat_str_;
|
608
|
+
union {
|
609
|
+
const uint8_t* data8_;
|
610
|
+
const uint16_t* data16_;
|
611
|
+
};
|
612
|
+
int length_;
|
613
|
+
bool is_one_byte_;
|
614
|
+
// Avoid exposing the internal DisallowGarbageCollection scope.
|
615
|
+
alignas(internal::Internals::
|
616
|
+
kDisallowGarbageCollectionAlign) char no_gc_debug_scope_
|
617
|
+
[internal::Internals::kDisallowGarbageCollectionSize];
|
618
|
+
};
|
619
|
+
|
551
620
|
private:
|
552
621
|
void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
|
553
622
|
Encoding encoding) const;
|
@@ -811,6 +880,28 @@ String::ExternalStringResource* String::GetExternalStringResource() const {
|
|
811
880
|
return result;
|
812
881
|
}
|
813
882
|
|
883
|
+
String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
|
884
|
+
v8::Isolate* isolate, String::Encoding* encoding_out) const {
|
885
|
+
using A = internal::Address;
|
886
|
+
using I = internal::Internals;
|
887
|
+
A obj = internal::ValueHelper::ValueAsAddress(this);
|
888
|
+
int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
|
889
|
+
*encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
|
890
|
+
ExternalStringResourceBase* resource;
|
891
|
+
if (type == I::kExternalOneByteRepresentationTag ||
|
892
|
+
type == I::kExternalTwoByteRepresentationTag) {
|
893
|
+
A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
|
894
|
+
isolate, obj, I::kStringResourceOffset);
|
895
|
+
resource = reinterpret_cast<ExternalStringResourceBase*>(value);
|
896
|
+
} else {
|
897
|
+
resource = GetExternalStringResourceBaseSlow(encoding_out);
|
898
|
+
}
|
899
|
+
#ifdef V8_ENABLE_CHECKS
|
900
|
+
VerifyExternalStringResourceBase(resource, *encoding_out);
|
901
|
+
#endif
|
902
|
+
return resource;
|
903
|
+
}
|
904
|
+
|
814
905
|
String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
|
815
906
|
String::Encoding* encoding_out) const {
|
816
907
|
using A = internal::Address;
|
@@ -899,9 +899,28 @@ class V8_EXPORT EmbedderGraph {
|
|
899
899
|
/**
|
900
900
|
* Returns a node corresponding to the given V8 value. Ownership is not
|
901
901
|
* transferred. The result pointer is valid while the graph is alive.
|
902
|
+
*
|
903
|
+
* For now the variant that takes v8::Data is not marked as abstract for
|
904
|
+
* compatibility, but embedders who subclass EmbedderGraph are expected to
|
905
|
+
* implement it. Then in the implementation of the variant that takes
|
906
|
+
* v8::Value, they can simply forward the call to the one that takes
|
907
|
+
* v8::Local<v8::Data>.
|
902
908
|
*/
|
903
909
|
virtual Node* V8Node(const v8::Local<v8::Value>& value) = 0;
|
904
910
|
|
911
|
+
/**
|
912
|
+
* Returns a node corresponding to the given V8 value. Ownership is not
|
913
|
+
* transferred. The result pointer is valid while the graph is alive.
|
914
|
+
*
|
915
|
+
* For API compatibility, this default implementation just checks that the
|
916
|
+
* data is a v8::Value and forward it to the variant that takes v8::Value,
|
917
|
+
* which is currently required to be implemented. In the future we'll remove
|
918
|
+
* the v8::Value variant, and make this variant that takes v8::Data abstract
|
919
|
+
* instead. If the embedder subclasses v8::EmbedderGraph and also use
|
920
|
+
* v8::TracedReference<v8::Data>, they must override this variant.
|
921
|
+
*/
|
922
|
+
virtual Node* V8Node(const v8::Local<v8::Data>& value);
|
923
|
+
|
905
924
|
/**
|
906
925
|
* Adds the given node to the graph and takes ownership of the node.
|
907
926
|
* Returns a raw pointer to the node that is valid while the graph is alive.
|
@@ -956,7 +975,7 @@ class V8_EXPORT HeapProfiler {
|
|
956
975
|
|
957
976
|
/**
|
958
977
|
* Callback function invoked during heap snapshot generation to retrieve
|
959
|
-
* the detachedness state of
|
978
|
+
* the detachedness state of a JS object referenced by a TracedReference.
|
960
979
|
*
|
961
980
|
* The callback takes Local<Value> as parameter to allow the embedder to
|
962
981
|
* unpack the TracedReference into a Local and reuse that Local for different
|
@@ -1090,6 +1109,12 @@ class V8_EXPORT HeapProfiler {
|
|
1090
1109
|
ObjectNameResolver* global_object_name_resolver = nullptr,
|
1091
1110
|
bool hide_internals = true, bool capture_numeric_value = false);
|
1092
1111
|
|
1112
|
+
/**
|
1113
|
+
* Obtains list of Detached JS Wrapper Objects. This functon calls garbage
|
1114
|
+
* collection, then iterates over traced handles in the isolate
|
1115
|
+
*/
|
1116
|
+
std::vector<v8::Local<v8::Value>> GetDetachedJSWrapperObjects();
|
1117
|
+
|
1093
1118
|
/**
|
1094
1119
|
* Starts tracking of heap objects population statistics. After calling
|
1095
1120
|
* this method, all heap objects relocations done by the garbage collector
|
@@ -1179,6 +1204,18 @@ class V8_EXPORT HeapProfiler {
|
|
1179
1204
|
|
1180
1205
|
void SetGetDetachednessCallback(GetDetachednessCallback callback, void* data);
|
1181
1206
|
|
1207
|
+
/**
|
1208
|
+
* Returns whether the heap profiler is currently taking a snapshot.
|
1209
|
+
*/
|
1210
|
+
bool IsTakingSnapshot();
|
1211
|
+
|
1212
|
+
/**
|
1213
|
+
* Allocates a copy of the provided string within the heap snapshot generator
|
1214
|
+
* and returns a pointer to the copy. May only be called during heap snapshot
|
1215
|
+
* generation.
|
1216
|
+
*/
|
1217
|
+
const char* CopyNameForHeapSnapshot(const char* name);
|
1218
|
+
|
1182
1219
|
/**
|
1183
1220
|
* Default value of persistent handle class ID. Must not be used to
|
1184
1221
|
* define a class. Can be used to reset a class of a persistent
|
@@ -14,7 +14,7 @@ namespace v8 {
|
|
14
14
|
class Context;
|
15
15
|
|
16
16
|
#ifndef V8_PROMISE_INTERNAL_FIELD_COUNT
|
17
|
-
//
|
17
|
+
// Defined using gn arg `v8_promise_internal_field_count`.
|
18
18
|
#define V8_PROMISE_INTERNAL_FIELD_COUNT 0
|
19
19
|
#endif
|
20
20
|
|
@@ -115,7 +115,7 @@ class V8_EXPORT Promise : public Object {
|
|
115
115
|
return static_cast<Promise*>(value);
|
116
116
|
}
|
117
117
|
|
118
|
-
static
|
118
|
+
static constexpr int kEmbedderFieldCount = V8_PROMISE_INTERNAL_FIELD_COUNT;
|
119
119
|
|
120
120
|
private:
|
121
121
|
Promise();
|
@@ -0,0 +1,173 @@
|
|
1
|
+
// Copyright 2024 the V8 project authors. All rights reserved.
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
3
|
+
// found in the LICENSE file.
|
4
|
+
|
5
|
+
#ifndef INCLUDE_V8_SANDBOX_H_
|
6
|
+
#define INCLUDE_V8_SANDBOX_H_
|
7
|
+
|
8
|
+
#include <cstdint>
|
9
|
+
|
10
|
+
#include "v8-internal.h" // NOLINT(build/include_directory)
|
11
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
12
|
+
|
13
|
+
namespace v8 {
|
14
|
+
|
15
|
+
/**
|
16
|
+
* A pointer tag used for wrapping and unwrapping `CppHeap` pointers as used
|
17
|
+
* with JS API wrapper objects that rely on `v8::Object::Wrap()` and
|
18
|
+
* `v8::Object::Unwrap()`.
|
19
|
+
*
|
20
|
+
* The CppHeapPointers use a range-based type checking scheme, where on access
|
21
|
+
* to a pointer, the actual type of the pointer is checked to be within a
|
22
|
+
* specified range of types. This allows supporting type hierarchies, where a
|
23
|
+
* type check for a supertype must succeed for any subtype.
|
24
|
+
*
|
25
|
+
* The tag is currently in practice limited to 15 bits since it needs to fit
|
26
|
+
* together with a marking bit into the unused parts of a pointer (the top 16
|
27
|
+
* bits).
|
28
|
+
*/
|
29
|
+
enum class CppHeapPointerTag : uint16_t {
|
30
|
+
kFirstTag = 0,
|
31
|
+
kNullTag = 0,
|
32
|
+
|
33
|
+
/**
|
34
|
+
* The lower type ids are reserved for the embedder to assign. For that, the
|
35
|
+
* main requirement is that all (transitive) child classes of a given parent
|
36
|
+
* class have type ids in the same range, and that there are no unrelated
|
37
|
+
* types in that range. For example, given the following type hierarchy:
|
38
|
+
*
|
39
|
+
* A F
|
40
|
+
* / \
|
41
|
+
* B E
|
42
|
+
* / \
|
43
|
+
* C D
|
44
|
+
*
|
45
|
+
* a potential type id assignment that satistifes these requirements is
|
46
|
+
* {C: 0, D: 1, B: 2, A: 3, E: 4, F: 5}. With that, the type check for type A
|
47
|
+
* would check for the range [0, 4], while the check for B would check range
|
48
|
+
* [0, 2], and for F it would simply check [5, 5].
|
49
|
+
*
|
50
|
+
* In addition, there is an option for performance tweaks: if the size of the
|
51
|
+
* type range corresponding to a supertype is a power of two and starts at a
|
52
|
+
* power of two (e.g. [0x100, 0x13f]), then the compiler can often optimize
|
53
|
+
* the type check to use even fewer instructions (essentially replace a AND +
|
54
|
+
* SUB with a single AND).
|
55
|
+
*/
|
56
|
+
|
57
|
+
kDefaultTag = 0x7000,
|
58
|
+
|
59
|
+
kZappedEntryTag = 0x7ffd,
|
60
|
+
kEvacuationEntryTag = 0x7ffe,
|
61
|
+
kFreeEntryTag = 0x7fff,
|
62
|
+
// The tags are limited to 15 bits, so the last tag is 0x7fff.
|
63
|
+
kLastTag = 0x7fff,
|
64
|
+
};
|
65
|
+
|
66
|
+
// Convenience struct to represent tag ranges. This is used for type checks
|
67
|
+
// against supertypes, which cover a range of types (their subtypes).
|
68
|
+
// Both the lower- and the upper bound are inclusive. In other words, this
|
69
|
+
// struct represents the range [lower_bound, upper_bound].
|
70
|
+
struct CppHeapPointerTagRange {
|
71
|
+
constexpr CppHeapPointerTagRange(CppHeapPointerTag lower,
|
72
|
+
CppHeapPointerTag upper)
|
73
|
+
: lower_bound(lower), upper_bound(upper) {}
|
74
|
+
CppHeapPointerTag lower_bound;
|
75
|
+
CppHeapPointerTag upper_bound;
|
76
|
+
|
77
|
+
// Check whether the tag of the given CppHeapPointerTable entry is within
|
78
|
+
// this range. This method encodes implementation details of the
|
79
|
+
// CppHeapPointerTable, which is necessary as it is used by
|
80
|
+
// ReadCppHeapPointerField below.
|
81
|
+
// Returns true if the check is successful and the tag of the given entry is
|
82
|
+
// within this range, false otherwise.
|
83
|
+
bool CheckTagOf(uint64_t entry) {
|
84
|
+
// Note: the cast to uint32_t is important here. Otherwise, the uint16_t's
|
85
|
+
// would be promoted to int in the range check below, which would result in
|
86
|
+
// undefined behavior (signed integer undeflow) if the actual value is less
|
87
|
+
// than the lower bound. Then, the compiler would take advantage of the
|
88
|
+
// undefined behavior and turn the range check into a simple
|
89
|
+
// `actual_tag <= last_tag` comparison, which is incorrect.
|
90
|
+
uint32_t actual_tag = static_cast<uint16_t>(entry);
|
91
|
+
// The actual_tag is shifted to the left by one and contains the marking
|
92
|
+
// bit in the LSB. To ignore that during the type check, simply add one to
|
93
|
+
// the (shifted) range.
|
94
|
+
constexpr int kTagShift = internal::kCppHeapPointerTagShift;
|
95
|
+
uint32_t first_tag = static_cast<uint32_t>(lower_bound) << kTagShift;
|
96
|
+
uint32_t last_tag = (static_cast<uint32_t>(upper_bound) << kTagShift) + 1;
|
97
|
+
return actual_tag >= first_tag && actual_tag <= last_tag;
|
98
|
+
}
|
99
|
+
};
|
100
|
+
|
101
|
+
constexpr CppHeapPointerTagRange kAnyCppHeapPointer(
|
102
|
+
CppHeapPointerTag::kFirstTag, CppHeapPointerTag::kLastTag);
|
103
|
+
|
104
|
+
class SandboxHardwareSupport {
|
105
|
+
public:
|
106
|
+
/**
|
107
|
+
* Initialize sandbox hardware support. This needs to be called before
|
108
|
+
* creating any thread that might access sandbox memory since it sets up
|
109
|
+
* hardware permissions to the memory that will be inherited on clone.
|
110
|
+
*/
|
111
|
+
V8_EXPORT static void InitializeBeforeThreadCreation();
|
112
|
+
};
|
113
|
+
|
114
|
+
namespace internal {
|
115
|
+
|
116
|
+
#ifdef V8_COMPRESS_POINTERS
|
117
|
+
V8_INLINE static Address* GetCppHeapPointerTableBase(v8::Isolate* isolate) {
|
118
|
+
Address addr = reinterpret_cast<Address>(isolate) +
|
119
|
+
Internals::kIsolateCppHeapPointerTableOffset +
|
120
|
+
Internals::kExternalPointerTableBasePointerOffset;
|
121
|
+
return *reinterpret_cast<Address**>(addr);
|
122
|
+
}
|
123
|
+
#endif // V8_COMPRESS_POINTERS
|
124
|
+
|
125
|
+
template <typename T>
|
126
|
+
V8_INLINE static T* ReadCppHeapPointerField(v8::Isolate* isolate,
|
127
|
+
Address heap_object_ptr, int offset,
|
128
|
+
CppHeapPointerTagRange tag_range) {
|
129
|
+
#ifdef V8_COMPRESS_POINTERS
|
130
|
+
// See src/sandbox/cppheap-pointer-table-inl.h. Logic duplicated here so
|
131
|
+
// it can be inlined and doesn't require an additional call.
|
132
|
+
const CppHeapPointerHandle handle =
|
133
|
+
Internals::ReadRawField<CppHeapPointerHandle>(heap_object_ptr, offset);
|
134
|
+
const uint32_t index = handle >> kExternalPointerIndexShift;
|
135
|
+
const Address* table = GetCppHeapPointerTableBase(isolate);
|
136
|
+
const std::atomic<Address>* ptr =
|
137
|
+
reinterpret_cast<const std::atomic<Address>*>(&table[index]);
|
138
|
+
Address entry = std::atomic_load_explicit(ptr, std::memory_order_relaxed);
|
139
|
+
|
140
|
+
Address pointer = entry;
|
141
|
+
if (V8_LIKELY(tag_range.CheckTagOf(entry))) {
|
142
|
+
pointer = entry >> kCppHeapPointerPayloadShift;
|
143
|
+
} else {
|
144
|
+
// If the type check failed, we simply return nullptr here. That way:
|
145
|
+
// 1. The null handle always results in nullptr being returned here, which
|
146
|
+
// is a desired property. Otherwise, we would need an explicit check for
|
147
|
+
// the null handle above, and therefore an additional branch. This
|
148
|
+
// works because the 0th entry of the table always contains nullptr
|
149
|
+
// tagged with the null tag (i.e. an all-zeros entry). As such,
|
150
|
+
// regardless of whether the type check succeeds, the result will
|
151
|
+
// always be nullptr.
|
152
|
+
// 2. The returned pointer is guaranteed to crash even on platforms with
|
153
|
+
// top byte ignore (TBI), such as Arm64. The alternative would be to
|
154
|
+
// simply return the original entry with the left-shifted payload.
|
155
|
+
// However, due to TBI, an access to that may not always result in a
|
156
|
+
// crash (specifically, if the second most significant byte happens to
|
157
|
+
// be zero). In addition, there shouldn't be a difference on Arm64
|
158
|
+
// between returning nullptr or the original entry, since it will
|
159
|
+
// simply compile to a `csel x0, x8, xzr, lo` instead of a
|
160
|
+
// `csel x0, x10, x8, lo` instruction.
|
161
|
+
pointer = 0;
|
162
|
+
}
|
163
|
+
return reinterpret_cast<T*>(pointer);
|
164
|
+
#else // !V8_COMPRESS_POINTERS
|
165
|
+
return reinterpret_cast<T*>(
|
166
|
+
Internals::ReadRawField<Address>(heap_object_ptr, offset));
|
167
|
+
#endif // !V8_COMPRESS_POINTERS
|
168
|
+
}
|
169
|
+
|
170
|
+
} // namespace internal
|
171
|
+
} // namespace v8
|
172
|
+
|
173
|
+
#endif // INCLUDE_V8_SANDBOX_H_
|
@@ -210,7 +210,7 @@ class V8_EXPORT Module : public Data {
|
|
210
210
|
|
211
211
|
using ResolveModuleCallback = MaybeLocal<Module> (*)(
|
212
212
|
Local<Context> context, Local<String> specifier,
|
213
|
-
Local<FixedArray>
|
213
|
+
Local<FixedArray> import_attributes, Local<Module> referrer);
|
214
214
|
|
215
215
|
/**
|
216
216
|
* Instantiates the module and its dependencies.
|
@@ -322,6 +322,14 @@ class V8_EXPORT Module : public Data {
|
|
322
322
|
static void CheckCast(Data* obj);
|
323
323
|
};
|
324
324
|
|
325
|
+
class V8_EXPORT CompileHintsCollector : public Data {
|
326
|
+
public:
|
327
|
+
/**
|
328
|
+
* Returns the positions of lazy functions which were compiled and executed.
|
329
|
+
*/
|
330
|
+
std::vector<int> GetCompileHints(Isolate* isolate) const;
|
331
|
+
};
|
332
|
+
|
325
333
|
/**
|
326
334
|
* A compiled JavaScript script, tied to a Context which was active when the
|
327
335
|
* script was compiled.
|
@@ -359,7 +367,15 @@ class V8_EXPORT Script : public Data {
|
|
359
367
|
* If the script was compiled, returns the positions of lazy functions which
|
360
368
|
* were eventually compiled and executed.
|
361
369
|
*/
|
370
|
+
V8_DEPRECATE_SOON("Use GetCompileHintsCollector instead")
|
362
371
|
std::vector<int> GetProducedCompileHints() const;
|
372
|
+
|
373
|
+
/**
|
374
|
+
* Get a compile hints collector object which we can use later for retrieving
|
375
|
+
* compile hints (= positions of lazy functions which were compiled and
|
376
|
+
* executed).
|
377
|
+
*/
|
378
|
+
Local<CompileHintsCollector> GetCompileHintsCollector() const;
|
363
379
|
};
|
364
380
|
|
365
381
|
enum class ScriptType { kClassic, kModule };
|
@@ -640,12 +656,33 @@ class V8_EXPORT ScriptCompiler {
|
|
640
656
|
|
641
657
|
enum CompileOptions {
|
642
658
|
kNoCompileOptions = 0,
|
643
|
-
kConsumeCodeCache,
|
644
|
-
kEagerCompile,
|
645
|
-
kProduceCompileHints,
|
646
|
-
kConsumeCompileHints
|
659
|
+
kConsumeCodeCache = 1 << 0,
|
660
|
+
kEagerCompile = 1 << 1,
|
661
|
+
kProduceCompileHints = 1 << 2,
|
662
|
+
kConsumeCompileHints = 1 << 3,
|
663
|
+
kFollowCompileHintsMagicComment = 1 << 4,
|
647
664
|
};
|
648
665
|
|
666
|
+
static inline bool CompileOptionsIsValid(CompileOptions compile_options) {
|
667
|
+
// kConsumeCodeCache is mutually exclusive with all other flag bits.
|
668
|
+
if ((compile_options & kConsumeCodeCache) &&
|
669
|
+
compile_options != kConsumeCodeCache) {
|
670
|
+
return false;
|
671
|
+
}
|
672
|
+
// kEagerCompile is mutually exclusive with all other flag bits.
|
673
|
+
if ((compile_options & kEagerCompile) && compile_options != kEagerCompile) {
|
674
|
+
return false;
|
675
|
+
}
|
676
|
+
// We don't currently support producing and consuming compile hints at the
|
677
|
+
// same time.
|
678
|
+
constexpr int produce_and_consume = CompileOptions::kProduceCompileHints |
|
679
|
+
CompileOptions::kConsumeCompileHints;
|
680
|
+
if ((compile_options & produce_and_consume) == produce_and_consume) {
|
681
|
+
return false;
|
682
|
+
}
|
683
|
+
return true;
|
684
|
+
}
|
685
|
+
|
649
686
|
/**
|
650
687
|
* The reason for which we are not requesting or providing a code cache.
|
651
688
|
*/
|
@@ -722,6 +759,8 @@ class V8_EXPORT ScriptCompiler {
|
|
722
759
|
|
723
760
|
static ConsumeCodeCacheTask* StartConsumingCodeCache(
|
724
761
|
Isolate* isolate, std::unique_ptr<CachedData> source);
|
762
|
+
static ConsumeCodeCacheTask* StartConsumingCodeCacheOnBackground(
|
763
|
+
Isolate* isolate, std::unique_ptr<CachedData> source);
|
725
764
|
|
726
765
|
/**
|
727
766
|
* Compiles a streamed script (bound to current context).
|
@@ -787,15 +826,6 @@ class V8_EXPORT ScriptCompiler {
|
|
787
826
|
* It is possible to specify multiple context extensions (obj in the above
|
788
827
|
* example).
|
789
828
|
*/
|
790
|
-
V8_DEPRECATED("Use CompileFunction")
|
791
|
-
static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
|
792
|
-
Local<Context> context, Source* source, size_t arguments_count,
|
793
|
-
Local<String> arguments[], size_t context_extension_count,
|
794
|
-
Local<Object> context_extensions[],
|
795
|
-
CompileOptions options = kNoCompileOptions,
|
796
|
-
NoCacheReason no_cache_reason = kNoCacheNoReason,
|
797
|
-
Local<ScriptOrModule>* script_or_module_out = nullptr);
|
798
|
-
|
799
829
|
static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunction(
|
800
830
|
Local<Context> context, Source* source, size_t arguments_count = 0,
|
801
831
|
Local<String> arguments[] = nullptr, size_t context_extension_count = 0,
|
@@ -68,6 +68,22 @@ struct SerializeContextDataCallback {
|
|
68
68
|
void* data;
|
69
69
|
};
|
70
70
|
|
71
|
+
/**
|
72
|
+
* Similar to `SerializeInternalFieldsCallback`, but is used exclusively to
|
73
|
+
* serialize API wrappers. The pointers for API wrappers always point into the
|
74
|
+
* CppHeap.
|
75
|
+
*/
|
76
|
+
struct SerializeAPIWrapperCallback {
|
77
|
+
using CallbackFunction = StartupData (*)(Local<Object> holder,
|
78
|
+
void* cpp_heap_pointer, void* data);
|
79
|
+
explicit SerializeAPIWrapperCallback(CallbackFunction function = nullptr,
|
80
|
+
void* data = nullptr)
|
81
|
+
: callback(function), data(data) {}
|
82
|
+
|
83
|
+
CallbackFunction callback;
|
84
|
+
void* data;
|
85
|
+
};
|
86
|
+
|
71
87
|
/**
|
72
88
|
* Callback and supporting data used to implement embedder logic to deserialize
|
73
89
|
* internal fields of v8::Objects.
|
@@ -97,6 +113,17 @@ struct DeserializeContextDataCallback {
|
|
97
113
|
void* data;
|
98
114
|
};
|
99
115
|
|
116
|
+
struct DeserializeAPIWrapperCallback {
|
117
|
+
using CallbackFunction = void (*)(Local<Object> holder, StartupData payload,
|
118
|
+
void* data);
|
119
|
+
explicit DeserializeAPIWrapperCallback(CallbackFunction function = nullptr,
|
120
|
+
void* data = nullptr)
|
121
|
+
: callback(function), data(data) {}
|
122
|
+
|
123
|
+
CallbackFunction callback;
|
124
|
+
void* data;
|
125
|
+
};
|
126
|
+
|
100
127
|
/**
|
101
128
|
* Helper class to create a snapshot data blob.
|
102
129
|
*
|
@@ -187,13 +214,17 @@ class V8_EXPORT SnapshotCreator {
|
|
187
214
|
* context embedder data set by
|
188
215
|
* v8::Context::SetAlignedPointerInEmbedderData().
|
189
216
|
*
|
217
|
+
* \param api_wrapper_serializer An optional callback used to serialize API
|
218
|
+
* wrapper references set via `v8::Object::Wrap()`.
|
190
219
|
*/
|
191
220
|
void SetDefaultContext(
|
192
221
|
Local<Context> context,
|
193
222
|
SerializeInternalFieldsCallback internal_fields_serializer =
|
194
223
|
SerializeInternalFieldsCallback(),
|
195
224
|
SerializeContextDataCallback context_data_serializer =
|
196
|
-
SerializeContextDataCallback()
|
225
|
+
SerializeContextDataCallback(),
|
226
|
+
SerializeAPIWrapperCallback api_wrapper_serializer =
|
227
|
+
SerializeAPIWrapperCallback());
|
197
228
|
|
198
229
|
/**
|
199
230
|
* Add additional context to be included in the snapshot blob.
|
@@ -204,12 +235,17 @@ class V8_EXPORT SnapshotCreator {
|
|
204
235
|
*
|
205
236
|
* \param context_data_serializer Similar to context_data_serializer
|
206
237
|
* in SetDefaultContext() but only applies to the context being added.
|
238
|
+
*
|
239
|
+
* \param api_wrapper_serializer Similar to api_wrapper_serializer
|
240
|
+
* in SetDefaultContext() but only applies to the context being added.
|
207
241
|
*/
|
208
242
|
size_t AddContext(Local<Context> context,
|
209
243
|
SerializeInternalFieldsCallback internal_fields_serializer =
|
210
244
|
SerializeInternalFieldsCallback(),
|
211
245
|
SerializeContextDataCallback context_data_serializer =
|
212
|
-
SerializeContextDataCallback()
|
246
|
+
SerializeContextDataCallback(),
|
247
|
+
SerializeAPIWrapperCallback api_wrapper_serializer =
|
248
|
+
SerializeAPIWrapperCallback());
|
213
249
|
|
214
250
|
/**
|
215
251
|
* Attach arbitrary V8::Data to the context snapshot, which can be retrieved
|