libv8-node 20.12.1.0-arm64-darwin → 22.5.1.0-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/libv8/node/version.rb +3 -3
- data/vendor/v8/arm64-darwin/libv8/obj/libv8_monolith.a +0 -0
- data/vendor/v8/include/cppgc/internal/api-constants.h +24 -5
- data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +16 -6
- data/vendor/v8/include/cppgc/internal/caged-heap.h +12 -5
- data/vendor/v8/include/cppgc/internal/gc-info.h +82 -91
- data/vendor/v8/include/cppgc/internal/member-storage.h +16 -8
- data/vendor/v8/include/cppgc/member.h +25 -0
- data/vendor/v8/include/cppgc/persistent.h +4 -0
- data/vendor/v8/include/cppgc/platform.h +6 -1
- data/vendor/v8/include/cppgc/sentinel-pointer.h +7 -0
- data/vendor/v8/include/cppgc/source-location.h +2 -78
- data/vendor/v8/include/cppgc/trace-trait.h +8 -0
- data/vendor/v8/include/cppgc/type-traits.h +25 -4
- data/vendor/v8/include/cppgc/visitor.h +82 -4
- data/vendor/v8/include/libplatform/libplatform.h +7 -1
- data/vendor/v8/include/v8-array-buffer.h +6 -0
- data/vendor/v8/include/v8-callbacks.h +57 -19
- data/vendor/v8/include/v8-container.h +54 -0
- data/vendor/v8/include/v8-context.h +58 -32
- data/vendor/v8/include/v8-embedder-heap.h +31 -3
- data/vendor/v8/include/v8-embedder-state-scope.h +2 -1
- data/vendor/v8/include/v8-exception.h +15 -9
- data/vendor/v8/include/v8-fast-api-calls.h +58 -31
- data/vendor/v8/include/v8-forward.h +1 -0
- data/vendor/v8/include/v8-function-callback.h +135 -30
- data/vendor/v8/include/v8-function.h +6 -0
- data/vendor/v8/include/v8-handle-base.h +137 -0
- data/vendor/v8/include/v8-inspector.h +35 -13
- data/vendor/v8/include/v8-internal.h +510 -71
- data/vendor/v8/include/v8-isolate.h +176 -100
- data/vendor/v8/include/v8-local-handle.h +383 -112
- data/vendor/v8/include/v8-memory-span.h +157 -2
- data/vendor/v8/include/v8-message.h +22 -3
- data/vendor/v8/include/v8-metrics.h +1 -0
- data/vendor/v8/include/v8-object.h +98 -77
- data/vendor/v8/include/v8-persistent-handle.h +68 -90
- data/vendor/v8/include/v8-platform.h +191 -23
- data/vendor/v8/include/v8-primitive.h +12 -8
- data/vendor/v8/include/v8-profiler.h +16 -2
- data/vendor/v8/include/v8-script.h +88 -14
- data/vendor/v8/include/v8-snapshot.h +96 -22
- data/vendor/v8/include/v8-source-location.h +92 -0
- data/vendor/v8/include/v8-statistics.h +31 -10
- data/vendor/v8/include/v8-template.h +410 -131
- data/vendor/v8/include/v8-traced-handle.h +108 -90
- data/vendor/v8/include/v8-typed-array.h +115 -7
- data/vendor/v8/include/v8-unwinder.h +1 -1
- data/vendor/v8/include/v8-util.h +23 -20
- data/vendor/v8/include/v8-value-serializer.h +14 -0
- data/vendor/v8/include/v8-value.h +105 -3
- data/vendor/v8/include/v8-version.h +4 -4
- data/vendor/v8/include/v8config.h +54 -20
- metadata +5 -3
@@ -128,13 +128,13 @@ struct IsSubclassOfBasicMemberTemplate {
|
|
128
128
|
private:
|
129
129
|
template <typename T, typename CheckingPolicy, typename StorageType>
|
130
130
|
static std::true_type SubclassCheck(
|
131
|
-
BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
|
132
|
-
|
131
|
+
const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
|
132
|
+
StorageType>*);
|
133
133
|
static std::false_type SubclassCheck(...);
|
134
134
|
|
135
135
|
public:
|
136
|
-
static constexpr bool value =
|
137
|
-
|
136
|
+
static constexpr bool value = decltype(SubclassCheck(
|
137
|
+
std::declval<std::decay_t<BasicMemberCandidate>*>()))::value;
|
138
138
|
};
|
139
139
|
|
140
140
|
template <typename T,
|
@@ -180,6 +180,14 @@ constexpr bool IsStrictlyBaseOfV =
|
|
180
180
|
std::is_base_of_v<std::decay_t<B>, std::decay_t<D>> &&
|
181
181
|
!IsDecayedSameV<B, D>;
|
182
182
|
|
183
|
+
template <typename T>
|
184
|
+
constexpr bool IsAnyMemberTypeV = false;
|
185
|
+
|
186
|
+
template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
|
187
|
+
typename CheckingPolicy, typename StorageType>
|
188
|
+
constexpr bool IsAnyMemberTypeV<internal::BasicMember<
|
189
|
+
T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy, StorageType>> = true;
|
190
|
+
|
183
191
|
} // namespace internal
|
184
192
|
|
185
193
|
/**
|
@@ -245,6 +253,19 @@ constexpr bool IsWeakV = internal::IsWeak<T>::value;
|
|
245
253
|
template <typename T>
|
246
254
|
constexpr bool IsCompleteV = internal::IsComplete<T>::value;
|
247
255
|
|
256
|
+
/**
|
257
|
+
* Value is true for member types `Member<T>` and `WeakMember<T>`.
|
258
|
+
*/
|
259
|
+
template <typename T>
|
260
|
+
constexpr bool IsMemberOrWeakMemberTypeV =
|
261
|
+
IsMemberTypeV<T> || IsWeakMemberTypeV<T>;
|
262
|
+
|
263
|
+
/**
|
264
|
+
* Value is true for any member type.
|
265
|
+
*/
|
266
|
+
template <typename T>
|
267
|
+
constexpr bool IsAnyMemberTypeV = internal::IsAnyMemberTypeV<std::decay_t<T>>;
|
268
|
+
|
248
269
|
} // namespace cppgc
|
249
270
|
|
250
271
|
#endif // INCLUDE_CPPGC_TYPE_TRAITS_H_
|
@@ -5,10 +5,13 @@
|
|
5
5
|
#ifndef INCLUDE_CPPGC_VISITOR_H_
|
6
6
|
#define INCLUDE_CPPGC_VISITOR_H_
|
7
7
|
|
8
|
+
#include <type_traits>
|
9
|
+
|
8
10
|
#include "cppgc/custom-space.h"
|
9
11
|
#include "cppgc/ephemeron-pair.h"
|
10
12
|
#include "cppgc/garbage-collected.h"
|
11
13
|
#include "cppgc/internal/logging.h"
|
14
|
+
#include "cppgc/internal/member-storage.h"
|
12
15
|
#include "cppgc/internal/pointer-policies.h"
|
13
16
|
#include "cppgc/liveness-broker.h"
|
14
17
|
#include "cppgc/member.h"
|
@@ -113,6 +116,30 @@ class V8_EXPORT Visitor {
|
|
113
116
|
}
|
114
117
|
#endif // defined(CPPGC_POINTER_COMPRESSION)
|
115
118
|
|
119
|
+
template <typename T>
|
120
|
+
void TraceMultiple(const subtle::UncompressedMember<T>* start, size_t len) {
|
121
|
+
static_assert(sizeof(T), "Pointee type must be fully defined.");
|
122
|
+
static_assert(internal::IsGarbageCollectedOrMixinType<T>::value,
|
123
|
+
"T must be GarbageCollected or GarbageCollectedMixin type");
|
124
|
+
VisitMultipleUncompressedMember(start, len,
|
125
|
+
&TraceTrait<T>::GetTraceDescriptor);
|
126
|
+
}
|
127
|
+
|
128
|
+
template <typename T,
|
129
|
+
std::enable_if_t<!std::is_same_v<
|
130
|
+
Member<T>, subtle::UncompressedMember<T>>>* = nullptr>
|
131
|
+
void TraceMultiple(const Member<T>* start, size_t len) {
|
132
|
+
static_assert(sizeof(T), "Pointee type must be fully defined.");
|
133
|
+
static_assert(internal::IsGarbageCollectedOrMixinType<T>::value,
|
134
|
+
"T must be GarbageCollected or GarbageCollectedMixin type");
|
135
|
+
#if defined(CPPGC_POINTER_COMPRESSION)
|
136
|
+
static_assert(std::is_same_v<Member<T>, subtle::CompressedMember<T>>,
|
137
|
+
"Member and CompressedMember must be the same.");
|
138
|
+
VisitMultipleCompressedMember(start, len,
|
139
|
+
&TraceTrait<T>::GetTraceDescriptor);
|
140
|
+
#endif // defined(CPPGC_POINTER_COMPRESSION)
|
141
|
+
}
|
142
|
+
|
116
143
|
/**
|
117
144
|
* Trace method for inlined objects that are not allocated themselves but
|
118
145
|
* otherwise follow managed heap layout and have a Trace() method.
|
@@ -131,6 +158,26 @@ class V8_EXPORT Visitor {
|
|
131
158
|
TraceTrait<T>::Trace(this, &object);
|
132
159
|
}
|
133
160
|
|
161
|
+
template <typename T>
|
162
|
+
void TraceMultiple(const T* start, size_t len) {
|
163
|
+
#if V8_ENABLE_CHECKS
|
164
|
+
// This object is embedded in potentially multiple nested objects. The
|
165
|
+
// outermost object must not be in construction as such objects are (a) not
|
166
|
+
// processed immediately, and (b) only processed conservatively if not
|
167
|
+
// otherwise possible.
|
168
|
+
CheckObjectNotInConstruction(start);
|
169
|
+
#endif // V8_ENABLE_CHECKS
|
170
|
+
for (size_t i = 0; i < len; ++i) {
|
171
|
+
const T* object = &start[i];
|
172
|
+
if constexpr (std::is_polymorphic_v<T>) {
|
173
|
+
// The object's vtable may be uninitialized in which case the object is
|
174
|
+
// not traced.
|
175
|
+
if (*reinterpret_cast<const uintptr_t*>(object) == 0) continue;
|
176
|
+
}
|
177
|
+
TraceTrait<T>::Trace(this, object);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
134
181
|
/**
|
135
182
|
* Registers a weak callback method on the object of type T. See
|
136
183
|
* LivenessBroker for an usage example.
|
@@ -314,6 +361,39 @@ class V8_EXPORT Visitor {
|
|
314
361
|
WeakCallback callback, const void* data) {}
|
315
362
|
virtual void HandleMovableReference(const void**) {}
|
316
363
|
|
364
|
+
virtual void VisitMultipleUncompressedMember(
|
365
|
+
const void* start, size_t len,
|
366
|
+
TraceDescriptorCallback get_trace_descriptor) {
|
367
|
+
// Default implementation merely delegates to Visit().
|
368
|
+
const char* it = static_cast<const char*>(start);
|
369
|
+
const char* end = it + len * internal::kSizeOfUncompressedMember;
|
370
|
+
for (; it < end; it += internal::kSizeOfUncompressedMember) {
|
371
|
+
const auto* current = reinterpret_cast<const internal::RawPointer*>(it);
|
372
|
+
const void* object = current->LoadAtomic();
|
373
|
+
if (!object) continue;
|
374
|
+
|
375
|
+
Visit(object, get_trace_descriptor(object));
|
376
|
+
}
|
377
|
+
}
|
378
|
+
|
379
|
+
#if defined(CPPGC_POINTER_COMPRESSION)
|
380
|
+
virtual void VisitMultipleCompressedMember(
|
381
|
+
const void* start, size_t len,
|
382
|
+
TraceDescriptorCallback get_trace_descriptor) {
|
383
|
+
// Default implementation merely delegates to Visit().
|
384
|
+
const char* it = static_cast<const char*>(start);
|
385
|
+
const char* end = it + len * internal::kSizeofCompressedMember;
|
386
|
+
for (; it < end; it += internal::kSizeofCompressedMember) {
|
387
|
+
const auto* current =
|
388
|
+
reinterpret_cast<const internal::CompressedPointer*>(it);
|
389
|
+
const void* object = current->LoadAtomic();
|
390
|
+
if (!object) continue;
|
391
|
+
|
392
|
+
Visit(object, get_trace_descriptor(object));
|
393
|
+
}
|
394
|
+
}
|
395
|
+
#endif // defined(CPPGC_POINTER_COMPRESSION)
|
396
|
+
|
317
397
|
private:
|
318
398
|
template <typename T, void (T::*method)(const LivenessBroker&)>
|
319
399
|
static void WeakCallbackMethodDelegate(const LivenessBroker& info,
|
@@ -326,8 +406,7 @@ class V8_EXPORT Visitor {
|
|
326
406
|
template <typename PointerType>
|
327
407
|
static void HandleWeak(const LivenessBroker& info, const void* object) {
|
328
408
|
const PointerType* weak = static_cast<const PointerType*>(object);
|
329
|
-
|
330
|
-
if (!info.IsHeapObjectAlive(raw_ptr)) {
|
409
|
+
if (!info.IsHeapObjectAlive(weak->GetFromGC())) {
|
331
410
|
weak->ClearFromGC();
|
332
411
|
}
|
333
412
|
}
|
@@ -413,8 +492,7 @@ class V8_EXPORT RootVisitor {
|
|
413
492
|
template <typename PointerType>
|
414
493
|
static void HandleWeak(const LivenessBroker& info, const void* object) {
|
415
494
|
const PointerType* weak = static_cast<const PointerType*>(object);
|
416
|
-
|
417
|
-
if (!info.IsHeapObjectAlive(raw_ptr)) {
|
495
|
+
if (!info.IsHeapObjectAlive(weak->GetFromGC())) {
|
418
496
|
weak->ClearFromGC();
|
419
497
|
}
|
420
498
|
}
|
@@ -23,6 +23,8 @@ enum class MessageLoopBehavior : bool {
|
|
23
23
|
kWaitForWork = true
|
24
24
|
};
|
25
25
|
|
26
|
+
enum class PriorityMode : bool { kDontApply, kApply };
|
27
|
+
|
26
28
|
/**
|
27
29
|
* Returns a new instance of the default v8::Platform implementation.
|
28
30
|
*
|
@@ -35,13 +37,17 @@ enum class MessageLoopBehavior : bool {
|
|
35
37
|
* calling v8::platform::RunIdleTasks to process the idle tasks.
|
36
38
|
* If |tracing_controller| is nullptr, the default platform will create a
|
37
39
|
* v8::platform::TracingController instance and use it.
|
40
|
+
* If |priority_mode| is PriorityMode::kApply, the default platform will use
|
41
|
+
* multiple task queues executed by threads different system-level priorities
|
42
|
+
* (where available) to schedule tasks.
|
38
43
|
*/
|
39
44
|
V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
|
40
45
|
int thread_pool_size = 0,
|
41
46
|
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
|
42
47
|
InProcessStackDumping in_process_stack_dumping =
|
43
48
|
InProcessStackDumping::kDisabled,
|
44
|
-
std::unique_ptr<v8::TracingController> tracing_controller = {}
|
49
|
+
std::unique_ptr<v8::TracingController> tracing_controller = {},
|
50
|
+
PriorityMode priority_mode = PriorityMode::kDontApply);
|
45
51
|
|
46
52
|
/**
|
47
53
|
* The same as NewDefaultPlatform but disables the worker thread pool.
|
@@ -318,6 +318,12 @@ class V8_EXPORT ArrayBuffer : public Object {
|
|
318
318
|
*/
|
319
319
|
std::shared_ptr<BackingStore> GetBackingStore();
|
320
320
|
|
321
|
+
/**
|
322
|
+
* More efficient shortcut for
|
323
|
+
* GetBackingStore()->IsResizableByUserJavaScript().
|
324
|
+
*/
|
325
|
+
bool IsResizableByUserJavaScript() const;
|
326
|
+
|
321
327
|
/**
|
322
328
|
* More efficient shortcut for GetBackingStore()->Data(). The returned pointer
|
323
329
|
* is valid as long as the ArrayBuffer is alive.
|
@@ -147,14 +147,18 @@ using JitCodeEventHandler = void (*)(const JitCodeEvent* event);
|
|
147
147
|
* the callback functions, you therefore cannot manipulate objects (set or
|
148
148
|
* delete properties for example) since it is possible such operations will
|
149
149
|
* result in the allocation of objects.
|
150
|
+
* TODO(v8:12612): Deprecate kGCTypeMinorMarkSweep after updating blink.
|
150
151
|
*/
|
151
152
|
enum GCType {
|
152
153
|
kGCTypeScavenge = 1 << 0,
|
153
|
-
|
154
|
+
kGCTypeMinorMarkSweep = 1 << 1,
|
155
|
+
kGCTypeMinorMarkCompact V8_DEPRECATE_SOON(
|
156
|
+
"Use kGCTypeMinorMarkSweep instead of kGCTypeMinorMarkCompact.") =
|
157
|
+
kGCTypeMinorMarkSweep,
|
154
158
|
kGCTypeMarkSweepCompact = 1 << 2,
|
155
159
|
kGCTypeIncrementalMarking = 1 << 3,
|
156
160
|
kGCTypeProcessWeakCallbacks = 1 << 4,
|
157
|
-
kGCTypeAll = kGCTypeScavenge |
|
161
|
+
kGCTypeAll = kGCTypeScavenge | kGCTypeMinorMarkSweep |
|
158
162
|
kGCTypeMarkSweepCompact | kGCTypeIncrementalMarking |
|
159
163
|
kGCTypeProcessWeakCallbacks
|
160
164
|
};
|
@@ -323,20 +327,20 @@ using WasmAsyncResolvePromiseCallback = void (*)(
|
|
323
327
|
using WasmLoadSourceMapCallback = Local<String> (*)(Isolate* isolate,
|
324
328
|
const char* name);
|
325
329
|
|
326
|
-
// --- Callback for checking if WebAssembly
|
327
|
-
using
|
328
|
-
|
329
|
-
// --- Callback for checking if WebAssembly exceptions are enabled ---
|
330
|
-
using WasmExceptionsEnabledCallback = bool (*)(Local<Context> context);
|
331
|
-
|
332
|
-
// --- Callback for checking if WebAssembly GC is enabled ---
|
333
|
-
// If the callback returns true, it will also enable Wasm stringrefs.
|
334
|
-
using WasmGCEnabledCallback = bool (*)(Local<Context> context);
|
330
|
+
// --- Callback for checking if WebAssembly imported strings are enabled ---
|
331
|
+
using WasmImportedStringsEnabledCallback = bool (*)(Local<Context> context);
|
335
332
|
|
336
333
|
// --- Callback for checking if the SharedArrayBuffer constructor is enabled ---
|
337
334
|
using SharedArrayBufferConstructorEnabledCallback =
|
338
335
|
bool (*)(Local<Context> context);
|
339
336
|
|
337
|
+
// --- Callback for checking if the compile hints magic comments are enabled ---
|
338
|
+
using JavaScriptCompileHintsMagicEnabledCallback =
|
339
|
+
bool (*)(Local<Context> context);
|
340
|
+
|
341
|
+
// --- Callback for checking if WebAssembly JSPI is enabled ---
|
342
|
+
using WasmJSPIEnabledCallback = bool (*)(Local<Context> context);
|
343
|
+
|
340
344
|
/**
|
341
345
|
* HostImportModuleDynamicallyCallback is called when we
|
342
346
|
* require the embedder to load a module. This is used as part of the dynamic
|
@@ -347,11 +351,11 @@ using SharedArrayBufferConstructorEnabledCallback =
|
|
347
351
|
*
|
348
352
|
* The specifier is the name of the module that should be imported.
|
349
353
|
*
|
350
|
-
* The
|
354
|
+
* The import_attributes are import attributes for this request in the form:
|
351
355
|
* [key1, value1, key2, value2, ...] where the keys and values are of type
|
352
356
|
* v8::String. Note, unlike the FixedArray passed to ResolveModuleCallback and
|
353
357
|
* returned from ModuleRequest::GetImportAssertions(), this array does not
|
354
|
-
* contain the source Locations of the
|
358
|
+
* contain the source Locations of the attributes.
|
355
359
|
*
|
356
360
|
* The embedder must compile, instantiate, evaluate the Module, and
|
357
361
|
* obtain its namespace object.
|
@@ -363,15 +367,10 @@ using SharedArrayBufferConstructorEnabledCallback =
|
|
363
367
|
* fails (e.g. due to stack overflow), the embedder must propagate
|
364
368
|
* that exception by returning an empty MaybeLocal.
|
365
369
|
*/
|
366
|
-
using HostImportModuleDynamicallyWithImportAssertionsCallback =
|
367
|
-
MaybeLocal<Promise> (*)(Local<Context> context,
|
368
|
-
Local<ScriptOrModule> referrer,
|
369
|
-
Local<String> specifier,
|
370
|
-
Local<FixedArray> import_assertions);
|
371
370
|
using HostImportModuleDynamicallyCallback = MaybeLocal<Promise> (*)(
|
372
371
|
Local<Context> context, Local<Data> host_defined_options,
|
373
372
|
Local<Value> resource_name, Local<String> specifier,
|
374
|
-
Local<FixedArray>
|
373
|
+
Local<FixedArray> import_attributes);
|
375
374
|
|
376
375
|
/**
|
377
376
|
* Callback for requesting a compile hint for a function from the embedder. The
|
@@ -419,6 +418,45 @@ using PrepareStackTraceCallback = MaybeLocal<Value> (*)(Local<Context> context,
|
|
419
418
|
Local<Value> error,
|
420
419
|
Local<Array> sites);
|
421
420
|
|
421
|
+
#if defined(V8_OS_WIN)
|
422
|
+
/**
|
423
|
+
* Callback to selectively enable ETW tracing based on the document URL.
|
424
|
+
* Implemented by the embedder, it should never call back into V8.
|
425
|
+
*
|
426
|
+
* Windows allows passing additional data to the ETW EnableCallback:
|
427
|
+
* https://learn.microsoft.com/en-us/windows/win32/api/evntprov/nc-evntprov-penablecallback
|
428
|
+
*
|
429
|
+
* This data can be configured in a WPR (Windows Performance Recorder)
|
430
|
+
* profile, adding a CustomFilter to an EventProvider like the following:
|
431
|
+
*
|
432
|
+
* <EventProvider Id=".." Name="57277741-3638-4A4B-BDBA-0AC6E45DA56C" Level="5">
|
433
|
+
* <CustomFilter Type="0x80000000" Value="AQABAAAAAAA..." />
|
434
|
+
* </EventProvider>
|
435
|
+
*
|
436
|
+
* Where:
|
437
|
+
* - Name="57277741-3638-4A4B-BDBA-0AC6E45DA56C" is the GUID of the V8
|
438
|
+
* ETW provider, (see src/libplatform/etw/etw-provider-win.h),
|
439
|
+
* - Type="0x80000000" is EVENT_FILTER_TYPE_SCHEMATIZED,
|
440
|
+
* - Value="AQABAAAAAA..." is a base64-encoded byte array that is
|
441
|
+
* base64-decoded by Windows and passed to the ETW enable callback in
|
442
|
+
* the 'PEVENT_FILTER_DESCRIPTOR FilterData' argument; see:
|
443
|
+
* https://learn.microsoft.com/en-us/windows/win32/api/evntprov/ns-evntprov-event_filter_descriptor.
|
444
|
+
*
|
445
|
+
* This array contains a struct EVENT_FILTER_HEADER followed by a
|
446
|
+
* variable length payload, and as payload we pass a string in JSON format,
|
447
|
+
* with a list of regular expressions that should match the document URL
|
448
|
+
* in order to enable ETW tracing:
|
449
|
+
* {
|
450
|
+
* "version": "1.0",
|
451
|
+
* "filtered_urls": [
|
452
|
+
* "https:\/\/.*\.chromium\.org\/.*", "https://v8.dev/";, "..."
|
453
|
+
* ]
|
454
|
+
* }
|
455
|
+
*/
|
456
|
+
using FilterETWSessionByURLCallback =
|
457
|
+
bool (*)(Local<Context> context, const std::string& etw_filter_payload);
|
458
|
+
#endif // V8_OS_WIN
|
459
|
+
|
422
460
|
} // namespace v8
|
423
461
|
|
424
462
|
#endif // INCLUDE_V8_ISOLATE_CALLBACKS_H_
|
@@ -8,6 +8,8 @@
|
|
8
8
|
#include <stddef.h>
|
9
9
|
#include <stdint.h>
|
10
10
|
|
11
|
+
#include <functional>
|
12
|
+
|
11
13
|
#include "v8-local-handle.h" // NOLINT(build/include_directory)
|
12
14
|
#include "v8-object.h" // NOLINT(build/include_directory)
|
13
15
|
#include "v8config.h" // NOLINT(build/include_directory)
|
@@ -43,6 +45,58 @@ class V8_EXPORT Array : public Object {
|
|
43
45
|
return static_cast<Array*>(value);
|
44
46
|
}
|
45
47
|
|
48
|
+
/**
|
49
|
+
* Creates a JavaScript array from a provided callback.
|
50
|
+
*
|
51
|
+
* \param context The v8::Context to create the array in.
|
52
|
+
* \param length The length of the array to be created.
|
53
|
+
* \param next_value_callback The callback that is invoked to retrieve
|
54
|
+
* elements for the array. The embedder can signal that the array
|
55
|
+
* initialization should be aborted by throwing an exception and returning
|
56
|
+
* an empty MaybeLocal.
|
57
|
+
* \returns The v8::Array if all elements were constructed successfully and an
|
58
|
+
* empty MaybeLocal otherwise.
|
59
|
+
*/
|
60
|
+
static MaybeLocal<Array> New(
|
61
|
+
Local<Context> context, size_t length,
|
62
|
+
std::function<MaybeLocal<v8::Value>()> next_value_callback);
|
63
|
+
|
64
|
+
enum class CallbackResult {
|
65
|
+
kException,
|
66
|
+
kBreak,
|
67
|
+
kContinue,
|
68
|
+
};
|
69
|
+
using IterationCallback = CallbackResult (*)(uint32_t index,
|
70
|
+
Local<Value> element,
|
71
|
+
void* data);
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Calls {callback} for every element of this array, passing {callback_data}
|
75
|
+
* as its {data} parameter.
|
76
|
+
* This function will typically be faster than calling {Get()} repeatedly.
|
77
|
+
* As a consequence of being optimized for low overhead, the provided
|
78
|
+
* callback must adhere to the following restrictions:
|
79
|
+
* - It must not allocate any V8 objects and continue iterating; it may
|
80
|
+
* allocate (e.g. an error message/object) and then immediately terminate
|
81
|
+
* the iteration.
|
82
|
+
* - It must not modify the array being iterated.
|
83
|
+
* - It must not call back into V8 (unless it can guarantee that such a
|
84
|
+
* call does not violate the above restrictions, which is difficult).
|
85
|
+
* - The {Local<Value> element} must not "escape", i.e. must not be assigned
|
86
|
+
* to any other {Local}. Creating a {Global} from it, or updating a
|
87
|
+
* v8::TypecheckWitness with it, is safe.
|
88
|
+
* These restrictions may be lifted in the future if use cases arise that
|
89
|
+
* justify a slower but more robust implementation.
|
90
|
+
*
|
91
|
+
* Returns {Nothing} on exception; use a {TryCatch} to catch and handle this
|
92
|
+
* exception.
|
93
|
+
* When the {callback} returns {kException}, iteration is terminated
|
94
|
+
* immediately, returning {Nothing}. By returning {kBreak}, the callback
|
95
|
+
* can request non-exceptional early termination of the iteration.
|
96
|
+
*/
|
97
|
+
Maybe<void> Iterate(Local<Context> context, IterationCallback callback,
|
98
|
+
void* callback_data);
|
99
|
+
|
46
100
|
private:
|
47
101
|
Array();
|
48
102
|
static void CheckCast(Value* obj);
|
@@ -84,6 +84,29 @@ class V8_EXPORT Context : public Data {
|
|
84
84
|
* created by a previous call to Context::New with the same global
|
85
85
|
* template. The state of the global object will be completely reset
|
86
86
|
* and only object identify will remain.
|
87
|
+
*
|
88
|
+
* \param internal_fields_deserializer An optional callback used
|
89
|
+
* to deserialize fields set by
|
90
|
+
* v8::Object::SetAlignedPointerInInternalField() in wrapper objects
|
91
|
+
* from the default context snapshot. It should match the
|
92
|
+
* SerializeInternalFieldsCallback() used by
|
93
|
+
* v8::SnapshotCreator::SetDefaultContext() when the default context
|
94
|
+
* snapshot is created. It does not need to be configured if the default
|
95
|
+
* context snapshot contains no wrapper objects with pointer internal
|
96
|
+
* fields, or if no custom startup snapshot is configured
|
97
|
+
* in the v8::CreateParams used to create the isolate.
|
98
|
+
*
|
99
|
+
* \param microtask_queue An optional microtask queue used to manage
|
100
|
+
* the microtasks created in this context. If not set the per-isolate
|
101
|
+
* default microtask queue would be used.
|
102
|
+
*
|
103
|
+
* \param context_data_deserializer An optional callback used
|
104
|
+
* to deserialize embedder data set by
|
105
|
+
* v8::Context::SetAlignedPointerInEmbedderData() in the default
|
106
|
+
* context from the default context snapshot. It does not need to be
|
107
|
+
* configured if the default context snapshot contains no pointer embedder
|
108
|
+
* data, or if no custom startup snapshot is configured in the
|
109
|
+
* v8::CreateParams used to create the isolate.
|
87
110
|
*/
|
88
111
|
static Local<Context> New(
|
89
112
|
Isolate* isolate, ExtensionConfiguration* extensions = nullptr,
|
@@ -91,7 +114,9 @@ class V8_EXPORT Context : public Data {
|
|
91
114
|
MaybeLocal<Value> global_object = MaybeLocal<Value>(),
|
92
115
|
DeserializeInternalFieldsCallback internal_fields_deserializer =
|
93
116
|
DeserializeInternalFieldsCallback(),
|
94
|
-
MicrotaskQueue* microtask_queue = nullptr
|
117
|
+
MicrotaskQueue* microtask_queue = nullptr,
|
118
|
+
DeserializeContextDataCallback context_data_deserializer =
|
119
|
+
DeserializeContextDataCallback());
|
95
120
|
|
96
121
|
/**
|
97
122
|
* Create a new context from a (non-default) context snapshot. There
|
@@ -103,21 +128,37 @@ class V8_EXPORT Context : public Data {
|
|
103
128
|
* \param context_snapshot_index The index of the context snapshot to
|
104
129
|
* deserialize from. Use v8::Context::New for the default snapshot.
|
105
130
|
*
|
106
|
-
* \param
|
107
|
-
*
|
108
|
-
*
|
131
|
+
* \param internal_fields_deserializer An optional callback used
|
132
|
+
* to deserialize fields set by
|
133
|
+
* v8::Object::SetAlignedPointerInInternalField() in wrapper objects
|
134
|
+
* from the default context snapshot. It does not need to be
|
135
|
+
* configured if there are no wrapper objects with no internal
|
136
|
+
* pointer fields in the default context snapshot or if no startup
|
137
|
+
* snapshot is configured when the isolate is created.
|
109
138
|
*
|
110
139
|
* \param extensions See v8::Context::New.
|
111
140
|
*
|
112
141
|
* \param global_object See v8::Context::New.
|
142
|
+
*
|
143
|
+
* \param internal_fields_deserializer Similar to
|
144
|
+
* internal_fields_deserializer in v8::Context::New but applies to
|
145
|
+
* the context specified by the context_snapshot_index.
|
146
|
+
*
|
147
|
+
* \param microtask_queue See v8::Context::New.
|
148
|
+
*
|
149
|
+
* \param context_data_deserializer Similar to
|
150
|
+
* context_data_deserializer in v8::Context::New but applies to
|
151
|
+
* the context specified by the context_snapshot_index.
|
113
152
|
*/
|
114
153
|
static MaybeLocal<Context> FromSnapshot(
|
115
154
|
Isolate* isolate, size_t context_snapshot_index,
|
116
|
-
DeserializeInternalFieldsCallback
|
155
|
+
DeserializeInternalFieldsCallback internal_fields_deserializer =
|
117
156
|
DeserializeInternalFieldsCallback(),
|
118
157
|
ExtensionConfiguration* extensions = nullptr,
|
119
158
|
MaybeLocal<Value> global_object = MaybeLocal<Value>(),
|
120
|
-
MicrotaskQueue* microtask_queue = nullptr
|
159
|
+
MicrotaskQueue* microtask_queue = nullptr,
|
160
|
+
DeserializeContextDataCallback context_data_deserializer =
|
161
|
+
DeserializeContextDataCallback());
|
121
162
|
|
122
163
|
/**
|
123
164
|
* Returns an global object that isn't backed by an actual context.
|
@@ -182,7 +223,7 @@ class V8_EXPORT Context : public Data {
|
|
182
223
|
* parameter. Returns true if the operation completed successfully.
|
183
224
|
*/
|
184
225
|
virtual bool FreezeEmbedderObjectAndGetChildren(
|
185
|
-
Local<Object> obj,
|
226
|
+
Local<Object> obj, LocalVector<Object>& children_out) = 0;
|
186
227
|
};
|
187
228
|
|
188
229
|
/**
|
@@ -309,18 +350,6 @@ class V8_EXPORT Context : public Data {
|
|
309
350
|
Local<Context> context);
|
310
351
|
void SetAbortScriptExecution(AbortScriptExecutionCallback callback);
|
311
352
|
|
312
|
-
/**
|
313
|
-
* Returns the value that was set or restored by
|
314
|
-
* SetContinuationPreservedEmbedderData(), if any.
|
315
|
-
*/
|
316
|
-
Local<Value> GetContinuationPreservedEmbedderData() const;
|
317
|
-
|
318
|
-
/**
|
319
|
-
* Sets a value that will be stored on continuations and reset while the
|
320
|
-
* continuation runs.
|
321
|
-
*/
|
322
|
-
void SetContinuationPreservedEmbedderData(Local<Value> context);
|
323
|
-
|
324
353
|
/**
|
325
354
|
* Set or clear hooks to be invoked for promise lifecycle operations.
|
326
355
|
* To clear a hook, set it to an empty v8::Function. Each function will
|
@@ -395,7 +424,7 @@ Local<Value> Context::GetEmbedderData(int index) {
|
|
395
424
|
#ifndef V8_ENABLE_CHECKS
|
396
425
|
using A = internal::Address;
|
397
426
|
using I = internal::Internals;
|
398
|
-
A ctx =
|
427
|
+
A ctx = internal::ValueHelper::ValueAsAddress(this);
|
399
428
|
A embedder_data =
|
400
429
|
I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
|
401
430
|
int value_offset =
|
@@ -407,15 +436,9 @@ Local<Value> Context::GetEmbedderData(int index) {
|
|
407
436
|
value = I::DecompressTaggedField(embedder_data, static_cast<uint32_t>(value));
|
408
437
|
#endif
|
409
438
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
internal::Isolate* isolate = internal::IsolateFromNeverReadOnlySpaceObject(
|
414
|
-
*reinterpret_cast<A*>(this));
|
415
|
-
A* result = HandleScope::CreateHandle(isolate, value);
|
416
|
-
return Local<Value>(reinterpret_cast<Value*>(result));
|
417
|
-
#endif
|
418
|
-
|
439
|
+
auto isolate = reinterpret_cast<v8::Isolate*>(
|
440
|
+
internal::IsolateFromNeverReadOnlySpaceObject(ctx));
|
441
|
+
return Local<Value>::New(isolate, value);
|
419
442
|
#else
|
420
443
|
return SlowGetEmbedderData(index);
|
421
444
|
#endif
|
@@ -442,9 +465,12 @@ void* Context::GetAlignedPointerFromEmbedderData(int index) {
|
|
442
465
|
|
443
466
|
template <class T>
|
444
467
|
MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) {
|
445
|
-
|
446
|
-
|
447
|
-
|
468
|
+
if (auto slot = GetDataFromSnapshotOnce(index); slot) {
|
469
|
+
internal::PerformCastCheck(
|
470
|
+
internal::ValueHelper::SlotAsValue<T, false>(slot));
|
471
|
+
return Local<T>::FromSlot(slot);
|
472
|
+
}
|
473
|
+
return {};
|
448
474
|
}
|
449
475
|
|
450
476
|
Context* Context::Cast(v8::Data* data) {
|
@@ -9,6 +9,9 @@
|
|
9
9
|
#include "v8config.h" // NOLINT(build/include_directory)
|
10
10
|
|
11
11
|
namespace v8 {
|
12
|
+
namespace internal {
|
13
|
+
class TracedHandles;
|
14
|
+
} // namespace internal
|
12
15
|
|
13
16
|
class Isolate;
|
14
17
|
class Value;
|
@@ -18,8 +21,17 @@ class Value;
|
|
18
21
|
*/
|
19
22
|
class V8_EXPORT EmbedderRootsHandler {
|
20
23
|
public:
|
24
|
+
enum class RootHandling {
|
25
|
+
kQueryEmbedderForNonDroppableReferences,
|
26
|
+
kDontQueryEmbedderForAnyReference,
|
27
|
+
};
|
28
|
+
|
21
29
|
virtual ~EmbedderRootsHandler() = default;
|
22
30
|
|
31
|
+
EmbedderRootsHandler() = default;
|
32
|
+
explicit EmbedderRootsHandler(RootHandling default_traced_reference_handling)
|
33
|
+
: default_traced_reference_handling_(default_traced_reference_handling) {}
|
34
|
+
|
23
35
|
/**
|
24
36
|
* Returns true if the |TracedReference| handle should be considered as root
|
25
37
|
* for the currently running non-tracing garbage collection and false
|
@@ -31,9 +43,9 @@ class V8_EXPORT EmbedderRootsHandler {
|
|
31
43
|
* |TracedReference|.
|
32
44
|
*
|
33
45
|
* Note that the `handle` is different from the handle that the embedder holds
|
34
|
-
* for retaining the object.
|
35
|
-
*
|
36
|
-
*
|
46
|
+
* for retaining the object.
|
47
|
+
*
|
48
|
+
* The concrete implementations must be thread-safe.
|
37
49
|
*/
|
38
50
|
virtual bool IsRoot(const v8::TracedReference<v8::Value>& handle) = 0;
|
39
51
|
|
@@ -47,6 +59,22 @@ class V8_EXPORT EmbedderRootsHandler {
|
|
47
59
|
* handle via the object or class id.
|
48
60
|
*/
|
49
61
|
virtual void ResetRoot(const v8::TracedReference<v8::Value>& handle) = 0;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Similar to |ResetRoot()|, but opportunistic. The function is called in
|
65
|
+
* parallel for different handles and as such must be thread-safe. In case,
|
66
|
+
* |false| is returned, |ResetRoot()| will be recalled for the same handle.
|
67
|
+
*/
|
68
|
+
virtual bool TryResetRoot(const v8::TracedReference<v8::Value>& handle) {
|
69
|
+
ResetRoot(handle);
|
70
|
+
return true;
|
71
|
+
}
|
72
|
+
|
73
|
+
private:
|
74
|
+
const RootHandling default_traced_reference_handling_ =
|
75
|
+
RootHandling::kQueryEmbedderForNonDroppableReferences;
|
76
|
+
|
77
|
+
friend class internal::TracedHandles;
|
50
78
|
};
|
51
79
|
|
52
80
|
} // namespace v8
|
@@ -7,12 +7,13 @@
|
|
7
7
|
|
8
8
|
#include <memory>
|
9
9
|
|
10
|
-
#include "v8-context.h" // NOLINT(build/include_directory)
|
11
10
|
#include "v8-internal.h" // NOLINT(build/include_directory)
|
12
11
|
#include "v8-local-handle.h" // NOLINT(build/include_directory)
|
13
12
|
|
14
13
|
namespace v8 {
|
15
14
|
|
15
|
+
class Context;
|
16
|
+
|
16
17
|
namespace internal {
|
17
18
|
class EmbedderState;
|
18
19
|
} // namespace internal
|