libv8-node 16.10.0.0-x86_64-linux → 18.8.0.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8-node/paths.rb +5 -1
  3. data/lib/libv8/node/version.rb +3 -3
  4. data/vendor/v8/include/cppgc/allocation.h +100 -22
  5. data/vendor/v8/include/cppgc/cross-thread-persistent.h +114 -33
  6. data/vendor/v8/include/cppgc/default-platform.h +2 -10
  7. data/vendor/v8/include/cppgc/explicit-management.h +22 -4
  8. data/vendor/v8/include/cppgc/garbage-collected.h +15 -26
  9. data/vendor/v8/include/cppgc/heap-consistency.h +30 -0
  10. data/vendor/v8/include/cppgc/heap-state.h +12 -0
  11. data/vendor/v8/include/cppgc/heap.h +7 -2
  12. data/vendor/v8/include/cppgc/internal/api-constants.h +8 -0
  13. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +25 -14
  14. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +4 -1
  15. data/vendor/v8/include/cppgc/internal/gc-info.h +90 -10
  16. data/vendor/v8/include/cppgc/internal/logging.h +3 -3
  17. data/vendor/v8/include/cppgc/internal/name-trait.h +11 -0
  18. data/vendor/v8/include/cppgc/internal/persistent-node.h +73 -29
  19. data/vendor/v8/include/cppgc/internal/pointer-policies.h +26 -15
  20. data/vendor/v8/include/cppgc/internal/write-barrier.h +62 -23
  21. data/vendor/v8/include/cppgc/liveness-broker.h +4 -1
  22. data/vendor/v8/include/cppgc/member.h +7 -2
  23. data/vendor/v8/include/cppgc/persistent.h +38 -33
  24. data/vendor/v8/include/cppgc/platform.h +4 -1
  25. data/vendor/v8/include/cppgc/prefinalizer.h +35 -12
  26. data/vendor/v8/include/cppgc/testing.h +9 -2
  27. data/vendor/v8/include/cppgc/type-traits.h +6 -13
  28. data/vendor/v8/include/cppgc/visitor.h +9 -7
  29. data/vendor/v8/include/libplatform/libplatform.h +0 -11
  30. data/vendor/v8/include/libplatform/v8-tracing.h +0 -1
  31. data/vendor/v8/include/v8-array-buffer.h +445 -0
  32. data/vendor/v8/include/v8-callbacks.h +397 -0
  33. data/vendor/v8/include/v8-container.h +129 -0
  34. data/vendor/v8/include/v8-context.h +407 -0
  35. data/vendor/v8/include/v8-cppgc.h +21 -128
  36. data/vendor/v8/include/v8-data.h +80 -0
  37. data/vendor/v8/include/v8-date.h +43 -0
  38. data/vendor/v8/include/v8-debug.h +168 -0
  39. data/vendor/v8/include/v8-embedder-heap.h +218 -0
  40. data/vendor/v8/include/v8-embedder-state-scope.h +51 -0
  41. data/vendor/v8/include/v8-exception.h +217 -0
  42. data/vendor/v8/include/v8-extension.h +62 -0
  43. data/vendor/v8/include/v8-external.h +37 -0
  44. data/vendor/v8/include/v8-fast-api-calls.h +172 -24
  45. data/vendor/v8/include/v8-forward.h +81 -0
  46. data/vendor/v8/include/v8-function-callback.h +475 -0
  47. data/vendor/v8/include/v8-function.h +125 -0
  48. data/vendor/v8/include/v8-initialization.h +315 -0
  49. data/vendor/v8/include/v8-inspector.h +56 -28
  50. data/vendor/v8/include/v8-internal.h +217 -55
  51. data/vendor/v8/include/v8-isolate.h +1709 -0
  52. data/vendor/v8/include/v8-json.h +47 -0
  53. data/vendor/v8/include/v8-local-handle.h +455 -0
  54. data/vendor/v8/include/v8-locker.h +149 -0
  55. data/vendor/v8/include/v8-maybe.h +137 -0
  56. data/vendor/v8/include/v8-memory-span.h +43 -0
  57. data/vendor/v8/include/v8-message.h +216 -0
  58. data/vendor/v8/include/v8-metrics.h +69 -16
  59. data/vendor/v8/include/v8-microtask-queue.h +152 -0
  60. data/vendor/v8/include/v8-microtask.h +28 -0
  61. data/vendor/v8/include/v8-object.h +775 -0
  62. data/vendor/v8/include/v8-persistent-handle.h +590 -0
  63. data/vendor/v8/include/v8-platform.h +400 -17
  64. data/vendor/v8/include/v8-primitive-object.h +118 -0
  65. data/vendor/v8/include/v8-primitive.h +866 -0
  66. data/vendor/v8/include/v8-profiler.h +88 -13
  67. data/vendor/v8/include/v8-promise.h +174 -0
  68. data/vendor/v8/include/v8-proxy.h +50 -0
  69. data/vendor/v8/include/v8-regexp.h +105 -0
  70. data/vendor/v8/include/v8-script.h +747 -0
  71. data/vendor/v8/include/v8-snapshot.h +196 -0
  72. data/vendor/v8/include/v8-statistics.h +217 -0
  73. data/vendor/v8/include/v8-template.h +1079 -0
  74. data/vendor/v8/include/v8-traced-handle.h +420 -0
  75. data/vendor/v8/include/v8-typed-array.h +282 -0
  76. data/vendor/v8/include/v8-unwinder-state.h +4 -3
  77. data/vendor/v8/include/v8-unwinder.h +132 -0
  78. data/vendor/v8/include/v8-util.h +7 -1
  79. data/vendor/v8/include/v8-value-serializer-version.h +1 -1
  80. data/vendor/v8/include/v8-value-serializer.h +279 -0
  81. data/vendor/v8/include/v8-value.h +526 -0
  82. data/vendor/v8/include/v8-version.h +4 -4
  83. data/vendor/v8/include/v8-wasm.h +257 -0
  84. data/vendor/v8/include/v8-weak-callback-info.h +87 -0
  85. data/vendor/v8/include/v8.h +41 -12601
  86. data/vendor/v8/include/v8config.h +102 -12
  87. data/vendor/v8/x86_64-linux/libv8/obj/libv8_monolith.a +0 -0
  88. metadata +47 -5
  89. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +0 -30
@@ -0,0 +1,407 @@
1
+ // Copyright 2021 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_CONTEXT_H_
6
+ #define INCLUDE_V8_CONTEXT_H_
7
+
8
+ #include <stdint.h>
9
+
10
+ #include "v8-data.h" // NOLINT(build/include_directory)
11
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
12
+ #include "v8-snapshot.h" // NOLINT(build/include_directory)
13
+ #include "v8config.h" // NOLINT(build/include_directory)
14
+
15
+ namespace v8 {
16
+
17
+ class Function;
18
+ class MicrotaskQueue;
19
+ class Object;
20
+ class ObjectTemplate;
21
+ class Value;
22
+ class String;
23
+
24
+ /**
25
+ * A container for extension names.
26
+ */
27
+ class V8_EXPORT ExtensionConfiguration {
28
+ public:
29
+ ExtensionConfiguration() : name_count_(0), names_(nullptr) {}
30
+ ExtensionConfiguration(int name_count, const char* names[])
31
+ : name_count_(name_count), names_(names) {}
32
+
33
+ const char** begin() const { return &names_[0]; }
34
+ const char** end() const { return &names_[name_count_]; }
35
+
36
+ private:
37
+ const int name_count_;
38
+ const char** names_;
39
+ };
40
+
41
+ /**
42
+ * A sandboxed execution context with its own set of built-in objects
43
+ * and functions.
44
+ */
45
+ class V8_EXPORT Context : public Data {
46
+ public:
47
+ /**
48
+ * Returns the global proxy object.
49
+ *
50
+ * Global proxy object is a thin wrapper whose prototype points to actual
51
+ * context's global object with the properties like Object, etc. This is done
52
+ * that way for security reasons (for more details see
53
+ * https://wiki.mozilla.org/Gecko:SplitWindow).
54
+ *
55
+ * Please note that changes to global proxy object prototype most probably
56
+ * would break VM---v8 expects only global object as a prototype of global
57
+ * proxy object.
58
+ */
59
+ Local<Object> Global();
60
+
61
+ /**
62
+ * Detaches the global object from its context before
63
+ * the global object can be reused to create a new context.
64
+ */
65
+ void DetachGlobal();
66
+
67
+ /**
68
+ * Creates a new context and returns a handle to the newly allocated
69
+ * context.
70
+ *
71
+ * \param isolate The isolate in which to create the context.
72
+ *
73
+ * \param extensions An optional extension configuration containing
74
+ * the extensions to be installed in the newly created context.
75
+ *
76
+ * \param global_template An optional object template from which the
77
+ * global object for the newly created context will be created.
78
+ *
79
+ * \param global_object An optional global object to be reused for
80
+ * the newly created context. This global object must have been
81
+ * created by a previous call to Context::New with the same global
82
+ * template. The state of the global object will be completely reset
83
+ * and only object identify will remain.
84
+ */
85
+ static Local<Context> New(
86
+ Isolate* isolate, ExtensionConfiguration* extensions = nullptr,
87
+ MaybeLocal<ObjectTemplate> global_template = MaybeLocal<ObjectTemplate>(),
88
+ MaybeLocal<Value> global_object = MaybeLocal<Value>(),
89
+ DeserializeInternalFieldsCallback internal_fields_deserializer =
90
+ DeserializeInternalFieldsCallback(),
91
+ MicrotaskQueue* microtask_queue = nullptr);
92
+
93
+ /**
94
+ * Create a new context from a (non-default) context snapshot. There
95
+ * is no way to provide a global object template since we do not create
96
+ * a new global object from template, but we can reuse a global object.
97
+ *
98
+ * \param isolate See v8::Context::New.
99
+ *
100
+ * \param context_snapshot_index The index of the context snapshot to
101
+ * deserialize from. Use v8::Context::New for the default snapshot.
102
+ *
103
+ * \param embedder_fields_deserializer Optional callback to deserialize
104
+ * internal fields. It should match the SerializeInternalFieldCallback used
105
+ * to serialize.
106
+ *
107
+ * \param extensions See v8::Context::New.
108
+ *
109
+ * \param global_object See v8::Context::New.
110
+ */
111
+ static MaybeLocal<Context> FromSnapshot(
112
+ Isolate* isolate, size_t context_snapshot_index,
113
+ DeserializeInternalFieldsCallback embedder_fields_deserializer =
114
+ DeserializeInternalFieldsCallback(),
115
+ ExtensionConfiguration* extensions = nullptr,
116
+ MaybeLocal<Value> global_object = MaybeLocal<Value>(),
117
+ MicrotaskQueue* microtask_queue = nullptr);
118
+
119
+ /**
120
+ * Returns an global object that isn't backed by an actual context.
121
+ *
122
+ * The global template needs to have access checks with handlers installed.
123
+ * If an existing global object is passed in, the global object is detached
124
+ * from its context.
125
+ *
126
+ * Note that this is different from a detached context where all accesses to
127
+ * the global proxy will fail. Instead, the access check handlers are invoked.
128
+ *
129
+ * It is also not possible to detach an object returned by this method.
130
+ * Instead, the access check handlers need to return nothing to achieve the
131
+ * same effect.
132
+ *
133
+ * It is possible, however, to create a new context from the global object
134
+ * returned by this method.
135
+ */
136
+ static MaybeLocal<Object> NewRemoteContext(
137
+ Isolate* isolate, Local<ObjectTemplate> global_template,
138
+ MaybeLocal<Value> global_object = MaybeLocal<Value>());
139
+
140
+ /**
141
+ * Sets the security token for the context. To access an object in
142
+ * another context, the security tokens must match.
143
+ */
144
+ void SetSecurityToken(Local<Value> token);
145
+
146
+ /** Restores the security token to the default value. */
147
+ void UseDefaultSecurityToken();
148
+
149
+ /** Returns the security token of this context.*/
150
+ Local<Value> GetSecurityToken();
151
+
152
+ /**
153
+ * Enter this context. After entering a context, all code compiled
154
+ * and run is compiled and run in this context. If another context
155
+ * is already entered, this old context is saved so it can be
156
+ * restored when the new context is exited.
157
+ */
158
+ void Enter();
159
+
160
+ /**
161
+ * Exit this context. Exiting the current context restores the
162
+ * context that was in place when entering the current context.
163
+ */
164
+ void Exit();
165
+
166
+ /** Returns the isolate associated with a current context. */
167
+ Isolate* GetIsolate();
168
+
169
+ /** Returns the microtask queue associated with a current context. */
170
+ MicrotaskQueue* GetMicrotaskQueue();
171
+
172
+ /**
173
+ * The field at kDebugIdIndex used to be reserved for the inspector.
174
+ * It now serves no purpose.
175
+ */
176
+ enum EmbedderDataFields { kDebugIdIndex = 0 };
177
+
178
+ /**
179
+ * Return the number of fields allocated for embedder data.
180
+ */
181
+ uint32_t GetNumberOfEmbedderDataFields();
182
+
183
+ /**
184
+ * Gets the embedder data with the given index, which must have been set by a
185
+ * previous call to SetEmbedderData with the same index.
186
+ */
187
+ V8_INLINE Local<Value> GetEmbedderData(int index);
188
+
189
+ /**
190
+ * Gets the binding object used by V8 extras. Extra natives get a reference
191
+ * to this object and can use it to "export" functionality by adding
192
+ * properties. Extra natives can also "import" functionality by accessing
193
+ * properties added by the embedder using the V8 API.
194
+ */
195
+ Local<Object> GetExtrasBindingObject();
196
+
197
+ /**
198
+ * Sets the embedder data with the given index, growing the data as
199
+ * needed. Note that index 0 currently has a special meaning for Chrome's
200
+ * debugger.
201
+ */
202
+ void SetEmbedderData(int index, Local<Value> value);
203
+
204
+ /**
205
+ * Gets a 2-byte-aligned native pointer from the embedder data with the given
206
+ * index, which must have been set by a previous call to
207
+ * SetAlignedPointerInEmbedderData with the same index. Note that index 0
208
+ * currently has a special meaning for Chrome's debugger.
209
+ */
210
+ V8_INLINE void* GetAlignedPointerFromEmbedderData(int index);
211
+
212
+ /**
213
+ * Sets a 2-byte-aligned native pointer in the embedder data with the given
214
+ * index, growing the data as needed. Note that index 0 currently has a
215
+ * special meaning for Chrome's debugger.
216
+ */
217
+ void SetAlignedPointerInEmbedderData(int index, void* value);
218
+
219
+ /**
220
+ * Control whether code generation from strings is allowed. Calling
221
+ * this method with false will disable 'eval' and the 'Function'
222
+ * constructor for code running in this context. If 'eval' or the
223
+ * 'Function' constructor are used an exception will be thrown.
224
+ *
225
+ * If code generation from strings is not allowed the
226
+ * V8::AllowCodeGenerationFromStrings callback will be invoked if
227
+ * set before blocking the call to 'eval' or the 'Function'
228
+ * constructor. If that callback returns true, the call will be
229
+ * allowed, otherwise an exception will be thrown. If no callback is
230
+ * set an exception will be thrown.
231
+ */
232
+ void AllowCodeGenerationFromStrings(bool allow);
233
+
234
+ /**
235
+ * Returns true if code generation from strings is allowed for the context.
236
+ * For more details see AllowCodeGenerationFromStrings(bool) documentation.
237
+ */
238
+ bool IsCodeGenerationFromStringsAllowed() const;
239
+
240
+ /**
241
+ * Sets the error description for the exception that is thrown when
242
+ * code generation from strings is not allowed and 'eval' or the 'Function'
243
+ * constructor are called.
244
+ */
245
+ void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
246
+
247
+ /**
248
+ * Return data that was previously attached to the context snapshot via
249
+ * SnapshotCreator, and removes the reference to it.
250
+ * Repeated call with the same index returns an empty MaybeLocal.
251
+ */
252
+ template <class T>
253
+ V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
254
+
255
+ /**
256
+ * If callback is set, abort any attempt to execute JavaScript in this
257
+ * context, call the specified callback, and throw an exception.
258
+ * To unset abort, pass nullptr as callback.
259
+ */
260
+ using AbortScriptExecutionCallback = void (*)(Isolate* isolate,
261
+ Local<Context> context);
262
+ void SetAbortScriptExecution(AbortScriptExecutionCallback callback);
263
+
264
+ /**
265
+ * Returns the value that was set or restored by
266
+ * SetContinuationPreservedEmbedderData(), if any.
267
+ */
268
+ Local<Value> GetContinuationPreservedEmbedderData() const;
269
+
270
+ /**
271
+ * Sets a value that will be stored on continuations and reset while the
272
+ * continuation runs.
273
+ */
274
+ void SetContinuationPreservedEmbedderData(Local<Value> context);
275
+
276
+ /**
277
+ * Set or clear hooks to be invoked for promise lifecycle operations.
278
+ * To clear a hook, set it to an empty v8::Function. Each function will
279
+ * receive the observed promise as the first argument. If a chaining
280
+ * operation is used on a promise, the init will additionally receive
281
+ * the parent promise as the second argument.
282
+ */
283
+ void SetPromiseHooks(Local<Function> init_hook, Local<Function> before_hook,
284
+ Local<Function> after_hook,
285
+ Local<Function> resolve_hook);
286
+
287
+ /**
288
+ * Stack-allocated class which sets the execution context for all
289
+ * operations executed within a local scope.
290
+ */
291
+ class V8_NODISCARD Scope {
292
+ public:
293
+ explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
294
+ context_->Enter();
295
+ }
296
+ V8_INLINE ~Scope() { context_->Exit(); }
297
+
298
+ private:
299
+ Local<Context> context_;
300
+ };
301
+
302
+ /**
303
+ * Stack-allocated class to support the backup incumbent settings object
304
+ * stack.
305
+ * https://html.spec.whatwg.org/multipage/webappapis.html#backup-incumbent-settings-object-stack
306
+ */
307
+ class V8_EXPORT V8_NODISCARD BackupIncumbentScope final {
308
+ public:
309
+ /**
310
+ * |backup_incumbent_context| is pushed onto the backup incumbent settings
311
+ * object stack.
312
+ */
313
+ explicit BackupIncumbentScope(Local<Context> backup_incumbent_context);
314
+ ~BackupIncumbentScope();
315
+
316
+ private:
317
+ friend class internal::Isolate;
318
+
319
+ uintptr_t JSStackComparableAddressPrivate() const {
320
+ return js_stack_comparable_address_;
321
+ }
322
+
323
+ Local<Context> backup_incumbent_context_;
324
+ uintptr_t js_stack_comparable_address_ = 0;
325
+ const BackupIncumbentScope* prev_ = nullptr;
326
+ };
327
+
328
+ V8_INLINE static Context* Cast(Data* data);
329
+
330
+ private:
331
+ friend class Value;
332
+ friend class Script;
333
+ friend class Object;
334
+ friend class Function;
335
+
336
+ static void CheckCast(Data* obj);
337
+
338
+ internal::Address* GetDataFromSnapshotOnce(size_t index);
339
+ Local<Value> SlowGetEmbedderData(int index);
340
+ void* SlowGetAlignedPointerFromEmbedderData(int index);
341
+ };
342
+
343
+ // --- Implementation ---
344
+
345
+ Local<Value> Context::GetEmbedderData(int index) {
346
+ #ifndef V8_ENABLE_CHECKS
347
+ using A = internal::Address;
348
+ using I = internal::Internals;
349
+ A ctx = *reinterpret_cast<const A*>(this);
350
+ A embedder_data =
351
+ I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
352
+ int value_offset =
353
+ I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
354
+ A value = I::ReadRawField<A>(embedder_data, value_offset);
355
+ #ifdef V8_COMPRESS_POINTERS
356
+ // We read the full pointer value and then decompress it in order to avoid
357
+ // dealing with potential endiannes issues.
358
+ value =
359
+ I::DecompressTaggedAnyField(embedder_data, static_cast<uint32_t>(value));
360
+ #endif
361
+ internal::Isolate* isolate = internal::IsolateFromNeverReadOnlySpaceObject(
362
+ *reinterpret_cast<A*>(this));
363
+ A* result = HandleScope::CreateHandle(isolate, value);
364
+ return Local<Value>(reinterpret_cast<Value*>(result));
365
+ #else
366
+ return SlowGetEmbedderData(index);
367
+ #endif
368
+ }
369
+
370
+ void* Context::GetAlignedPointerFromEmbedderData(int index) {
371
+ #if !defined(V8_ENABLE_CHECKS)
372
+ using A = internal::Address;
373
+ using I = internal::Internals;
374
+ A ctx = *reinterpret_cast<const A*>(this);
375
+ A embedder_data =
376
+ I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
377
+ int value_offset =
378
+ I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
379
+ #ifdef V8_SANDBOXED_EXTERNAL_POINTERS
380
+ value_offset += I::kEmbedderDataSlotRawPayloadOffset;
381
+ #endif
382
+ internal::Isolate* isolate = I::GetIsolateForSandbox(ctx);
383
+ return reinterpret_cast<void*>(
384
+ I::ReadExternalPointerField(isolate, embedder_data, value_offset,
385
+ internal::kEmbedderDataSlotPayloadTag));
386
+ #else
387
+ return SlowGetAlignedPointerFromEmbedderData(index);
388
+ #endif
389
+ }
390
+
391
+ template <class T>
392
+ MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) {
393
+ T* data = reinterpret_cast<T*>(GetDataFromSnapshotOnce(index));
394
+ if (data) internal::PerformCastCheck(data);
395
+ return Local<T>(data);
396
+ }
397
+
398
+ Context* Context::Cast(v8::Data* data) {
399
+ #ifdef V8_ENABLE_CHECKS
400
+ CheckCast(data);
401
+ #endif
402
+ return static_cast<Context*>(data);
403
+ }
404
+
405
+ } // namespace v8
406
+
407
+ #endif // INCLUDE_V8_CONTEXT_H_
@@ -12,10 +12,10 @@
12
12
  #include "cppgc/common.h"
13
13
  #include "cppgc/custom-space.h"
14
14
  #include "cppgc/heap-statistics.h"
15
- #include "cppgc/internal/write-barrier.h"
16
15
  #include "cppgc/visitor.h"
17
- #include "v8-internal.h" // NOLINT(build/include_directory)
18
- #include "v8.h" // NOLINT(build/include_directory)
16
+ #include "v8-internal.h" // NOLINT(build/include_directory)
17
+ #include "v8-platform.h" // NOLINT(build/include_directory)
18
+ #include "v8-traced-handle.h" // NOLINT(build/include_directory)
19
19
 
20
20
  namespace cppgc {
21
21
  class AllocationHandle;
@@ -24,6 +24,8 @@ class HeapHandle;
24
24
 
25
25
  namespace v8 {
26
26
 
27
+ class Object;
28
+
27
29
  namespace internal {
28
30
  class CppHeap;
29
31
  } // namespace internal
@@ -145,6 +147,14 @@ class V8_EXPORT CppHeap {
145
147
  */
146
148
  void CollectGarbageForTesting(cppgc::EmbedderStackState stack_state);
147
149
 
150
+ /**
151
+ * Performs a stop-the-world minor garbage collection for testing purposes.
152
+ *
153
+ * \param stack_state The stack state to assume for the garbage collection.
154
+ */
155
+ void CollectGarbageInYoungGenerationForTesting(
156
+ cppgc::EmbedderStackState stack_state);
157
+
148
158
  private:
149
159
  CppHeap() = default;
150
160
 
@@ -154,6 +164,7 @@ class V8_EXPORT CppHeap {
154
164
  class JSVisitor : public cppgc::Visitor {
155
165
  public:
156
166
  explicit JSVisitor(cppgc::Visitor::Key key) : cppgc::Visitor(key) {}
167
+ ~JSVisitor() override = default;
157
168
 
158
169
  void Trace(const TracedReferenceBase& ref) {
159
170
  if (ref.IsEmptyThreadSafe()) return;
@@ -166,129 +177,6 @@ class JSVisitor : public cppgc::Visitor {
166
177
  virtual void Visit(const TracedReferenceBase& ref) {}
167
178
  };
168
179
 
169
- /**
170
- * **DO NOT USE: Use the appropriate managed types.**
171
- *
172
- * Consistency helpers that aid in maintaining a consistent internal state of
173
- * the garbage collector.
174
- */
175
- class V8_EXPORT JSHeapConsistency final {
176
- public:
177
- using WriteBarrierParams = cppgc::internal::WriteBarrier::Params;
178
- using WriteBarrierType = cppgc::internal::WriteBarrier::Type;
179
-
180
- /**
181
- * Gets the required write barrier type for a specific write.
182
- *
183
- * Note: Handling for C++ to JS references.
184
- *
185
- * \param ref The reference being written to.
186
- * \param params Parameters that may be used for actual write barrier calls.
187
- * Only filled if return value indicates that a write barrier is needed. The
188
- * contents of the `params` are an implementation detail.
189
- * \param callback Callback returning the corresponding heap handle. The
190
- * callback is only invoked if the heap cannot otherwise be figured out. The
191
- * callback must not allocate.
192
- * \returns whether a write barrier is needed and which barrier to invoke.
193
- */
194
- template <typename HeapHandleCallback>
195
- static V8_INLINE WriteBarrierType
196
- GetWriteBarrierType(const TracedReferenceBase& ref,
197
- WriteBarrierParams& params, HeapHandleCallback callback) {
198
- if (ref.IsEmpty()) return WriteBarrierType::kNone;
199
-
200
- if (V8_LIKELY(!cppgc::internal::WriteBarrier::
201
- IsAnyIncrementalOrConcurrentMarking())) {
202
- return cppgc::internal::WriteBarrier::Type::kNone;
203
- }
204
- cppgc::HeapHandle& handle = callback();
205
- if (!cppgc::subtle::HeapState::IsMarking(handle)) {
206
- return cppgc::internal::WriteBarrier::Type::kNone;
207
- }
208
- params.heap = &handle;
209
- #if V8_ENABLE_CHECKS
210
- params.type = cppgc::internal::WriteBarrier::Type::kMarking;
211
- #endif // !V8_ENABLE_CHECKS
212
- return cppgc::internal::WriteBarrier::Type::kMarking;
213
- }
214
-
215
- /**
216
- * Gets the required write barrier type for a specific write.
217
- *
218
- * Note: Handling for JS to C++ references.
219
- *
220
- * \param wrapper The wrapper that has been written into.
221
- * \param wrapper_index The wrapper index in `wrapper` that has been written
222
- * into.
223
- * \param wrappable The value that was written.
224
- * \param params Parameters that may be used for actual write barrier calls.
225
- * Only filled if return value indicates that a write barrier is needed. The
226
- * contents of the `params` are an implementation detail.
227
- * \param callback Callback returning the corresponding heap handle. The
228
- * callback is only invoked if the heap cannot otherwise be figured out. The
229
- * callback must not allocate.
230
- * \returns whether a write barrier is needed and which barrier to invoke.
231
- */
232
- template <typename HeapHandleCallback>
233
- static V8_INLINE WriteBarrierType GetWriteBarrierType(
234
- v8::Local<v8::Object>& wrapper, int wrapper_index, const void* wrappable,
235
- WriteBarrierParams& params, HeapHandleCallback callback) {
236
- #if V8_ENABLE_CHECKS
237
- CheckWrapper(wrapper, wrapper_index, wrappable);
238
- #endif // V8_ENABLE_CHECKS
239
- return cppgc::internal::WriteBarrier::
240
- GetWriteBarrierTypeForExternallyReferencedObject(wrappable, params,
241
- callback);
242
- }
243
-
244
- /**
245
- * Conservative Dijkstra-style write barrier that processes an object if it
246
- * has not yet been processed.
247
- *
248
- * \param params The parameters retrieved from `GetWriteBarrierType()`.
249
- * \param ref The reference being written to.
250
- */
251
- static V8_INLINE void DijkstraMarkingBarrier(const WriteBarrierParams& params,
252
- cppgc::HeapHandle& heap_handle,
253
- const TracedReferenceBase& ref) {
254
- cppgc::internal::WriteBarrier::CheckParams(WriteBarrierType::kMarking,
255
- params);
256
- DijkstraMarkingBarrierSlow(heap_handle, ref);
257
- }
258
-
259
- /**
260
- * Conservative Dijkstra-style write barrier that processes an object if it
261
- * has not yet been processed.
262
- *
263
- * \param params The parameters retrieved from `GetWriteBarrierType()`.
264
- * \param object The pointer to the object. May be an interior pointer to a
265
- * an interface of the actual object.
266
- */
267
- static V8_INLINE void DijkstraMarkingBarrier(const WriteBarrierParams& params,
268
- cppgc::HeapHandle& heap_handle,
269
- const void* object) {
270
- cppgc::internal::WriteBarrier::DijkstraMarkingBarrier(params, object);
271
- }
272
-
273
- /**
274
- * Generational barrier for maintaining consistency when running with multiple
275
- * generations.
276
- *
277
- * \param params The parameters retrieved from `GetWriteBarrierType()`.
278
- * \param ref The reference being written to.
279
- */
280
- static V8_INLINE void GenerationalBarrier(const WriteBarrierParams& params,
281
- const TracedReferenceBase& ref) {}
282
-
283
- private:
284
- JSHeapConsistency() = delete;
285
-
286
- static void CheckWrapper(v8::Local<v8::Object>&, int, const void*);
287
-
288
- static void DijkstraMarkingBarrierSlow(cppgc::HeapHandle&,
289
- const TracedReferenceBase& ref);
290
- };
291
-
292
180
  /**
293
181
  * Provided as input to `CppHeap::CollectCustomSpaceStatisticsAtLastGC()`.
294
182
  *
@@ -315,8 +203,13 @@ namespace cppgc {
315
203
 
316
204
  template <typename T>
317
205
  struct TraceTrait<v8::TracedReference<T>> {
318
- static void Trace(Visitor* visitor, const v8::TracedReference<T>* self) {
319
- static_cast<v8::JSVisitor*>(visitor)->Trace(*self);
206
+ static cppgc::TraceDescriptor GetTraceDescriptor(const void* self) {
207
+ return {nullptr, Trace};
208
+ }
209
+
210
+ static void Trace(Visitor* visitor, const void* self) {
211
+ static_cast<v8::JSVisitor*>(visitor)->Trace(
212
+ *static_cast<const v8::TracedReference<T>*>(self));
320
213
  }
321
214
  };
322
215
 
@@ -0,0 +1,80 @@
1
+ // Copyright 2021 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_DATA_H_
6
+ #define INCLUDE_V8_DATA_H_
7
+
8
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
9
+ #include "v8config.h" // NOLINT(build/include_directory)
10
+
11
+ namespace v8 {
12
+
13
+ class Context;
14
+
15
+ /**
16
+ * The superclass of objects that can reside on V8's heap.
17
+ */
18
+ class V8_EXPORT Data {
19
+ public:
20
+ /**
21
+ * Returns true if this data is a |v8::Value|.
22
+ */
23
+ bool IsValue() const;
24
+
25
+ /**
26
+ * Returns true if this data is a |v8::Module|.
27
+ */
28
+ bool IsModule() const;
29
+
30
+ /**
31
+ * Returns tru if this data is a |v8::FixedArray|
32
+ */
33
+ bool IsFixedArray() const;
34
+
35
+ /**
36
+ * Returns true if this data is a |v8::Private|.
37
+ */
38
+ bool IsPrivate() const;
39
+
40
+ /**
41
+ * Returns true if this data is a |v8::ObjectTemplate|.
42
+ */
43
+ bool IsObjectTemplate() const;
44
+
45
+ /**
46
+ * Returns true if this data is a |v8::FunctionTemplate|.
47
+ */
48
+ bool IsFunctionTemplate() const;
49
+
50
+ /**
51
+ * Returns true if this data is a |v8::Context|.
52
+ */
53
+ bool IsContext() const;
54
+
55
+ private:
56
+ Data();
57
+ };
58
+
59
+ /**
60
+ * A fixed-sized array with elements of type Data.
61
+ */
62
+ class V8_EXPORT FixedArray : public Data {
63
+ public:
64
+ int Length() const;
65
+ Local<Data> Get(Local<Context> context, int i) const;
66
+
67
+ V8_INLINE static FixedArray* Cast(Data* data) {
68
+ #ifdef V8_ENABLE_CHECKS
69
+ CheckCast(data);
70
+ #endif
71
+ return reinterpret_cast<FixedArray*>(data);
72
+ }
73
+
74
+ private:
75
+ static void CheckCast(Data* obj);
76
+ };
77
+
78
+ } // namespace v8
79
+
80
+ #endif // INCLUDE_V8_DATA_H_