@downdraft/native-mobile-android-arm64 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/include/node/cppgc/allocation.h +308 -0
  2. package/include/node/cppgc/common.h +28 -0
  3. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  4. package/include/node/cppgc/custom-space.h +97 -0
  5. package/include/node/cppgc/default-platform.h +68 -0
  6. package/include/node/cppgc/explicit-management.h +100 -0
  7. package/include/node/cppgc/garbage-collected.h +114 -0
  8. package/include/node/cppgc/heap-consistency.h +309 -0
  9. package/include/node/cppgc/heap-handle.h +48 -0
  10. package/include/node/cppgc/heap-state.h +82 -0
  11. package/include/node/cppgc/heap-statistics.h +126 -0
  12. package/include/node/cppgc/heap.h +202 -0
  13. package/include/node/cppgc/internal/api-constants.h +75 -0
  14. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  15. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  16. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  17. package/include/node/cppgc/internal/caged-heap.h +64 -0
  18. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  19. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  20. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  21. package/include/node/cppgc/internal/gc-info.h +150 -0
  22. package/include/node/cppgc/internal/logging.h +50 -0
  23. package/include/node/cppgc/internal/member-storage.h +305 -0
  24. package/include/node/cppgc/internal/name-trait.h +141 -0
  25. package/include/node/cppgc/internal/persistent-node.h +219 -0
  26. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  27. package/include/node/cppgc/internal/write-barrier.h +487 -0
  28. package/include/node/cppgc/liveness-broker.h +78 -0
  29. package/include/node/cppgc/macros.h +56 -0
  30. package/include/node/cppgc/member.h +669 -0
  31. package/include/node/cppgc/name-provider.h +75 -0
  32. package/include/node/cppgc/object-size-trait.h +58 -0
  33. package/include/node/cppgc/persistent.h +376 -0
  34. package/include/node/cppgc/platform.h +174 -0
  35. package/include/node/cppgc/prefinalizer.h +75 -0
  36. package/include/node/cppgc/process-heap-statistics.h +36 -0
  37. package/include/node/cppgc/sentinel-pointer.h +39 -0
  38. package/include/node/cppgc/source-location.h +16 -0
  39. package/include/node/cppgc/tagged-member.h +114 -0
  40. package/include/node/cppgc/testing.h +106 -0
  41. package/include/node/cppgc/trace-trait.h +127 -0
  42. package/include/node/cppgc/type-traits.h +272 -0
  43. package/include/node/cppgc/visitor.h +534 -0
  44. package/include/node/js_native_api.h +634 -0
  45. package/include/node/js_native_api_types.h +244 -0
  46. package/include/node/libplatform/libplatform-export.h +29 -0
  47. package/include/node/libplatform/libplatform.h +112 -0
  48. package/include/node/libplatform/v8-tracing.h +343 -0
  49. package/include/node/node.h +1744 -0
  50. package/include/node/node_api.h +265 -0
  51. package/include/node/node_api_types.h +58 -0
  52. package/include/node/node_buffer.h +94 -0
  53. package/include/node/node_object_wrap.h +145 -0
  54. package/include/node/node_version.h +116 -0
  55. package/include/node/uv/aix.h +32 -0
  56. package/include/node/uv/bsd.h +34 -0
  57. package/include/node/uv/darwin.h +61 -0
  58. package/include/node/uv/errno.h +483 -0
  59. package/include/node/uv/linux.h +34 -0
  60. package/include/node/uv/os390.h +33 -0
  61. package/include/node/uv/posix.h +31 -0
  62. package/include/node/uv/sunos.h +44 -0
  63. package/include/node/uv/threadpool.h +37 -0
  64. package/include/node/uv/tree.h +521 -0
  65. package/include/node/uv/unix.h +509 -0
  66. package/include/node/uv/version.h +43 -0
  67. package/include/node/uv/win.h +698 -0
  68. package/include/node/uv.h +1994 -0
  69. package/include/node/v8-array-buffer.h +646 -0
  70. package/include/node/v8-callbacks.h +533 -0
  71. package/include/node/v8-container.h +183 -0
  72. package/include/node/v8-context.h +580 -0
  73. package/include/node/v8-cpp-heap-external.h +56 -0
  74. package/include/node/v8-cppgc.h +194 -0
  75. package/include/node/v8-data.h +96 -0
  76. package/include/node/v8-date.h +57 -0
  77. package/include/node/v8-debug.h +210 -0
  78. package/include/node/v8-embedder-heap.h +54 -0
  79. package/include/node/v8-embedder-state-scope.h +52 -0
  80. package/include/node/v8-exception.h +298 -0
  81. package/include/node/v8-extension.h +60 -0
  82. package/include/node/v8-external-memory-accounter.h +60 -0
  83. package/include/node/v8-external.h +73 -0
  84. package/include/node/v8-fast-api-calls.h +784 -0
  85. package/include/node/v8-forward.h +82 -0
  86. package/include/node/v8-function-callback.h +708 -0
  87. package/include/node/v8-function.h +148 -0
  88. package/include/node/v8-handle-base.h +155 -0
  89. package/include/node/v8-initialization.h +343 -0
  90. package/include/node/v8-inspector-protocol.h +13 -0
  91. package/include/node/v8-inspector.h +458 -0
  92. package/include/node/v8-internal.h +1827 -0
  93. package/include/node/v8-isolate.h +1925 -0
  94. package/include/node/v8-json.h +54 -0
  95. package/include/node/v8-local-handle.h +884 -0
  96. package/include/node/v8-locker.h +138 -0
  97. package/include/node/v8-maybe.h +185 -0
  98. package/include/node/v8-memory-span.h +273 -0
  99. package/include/node/v8-message.h +215 -0
  100. package/include/node/v8-metrics.h +273 -0
  101. package/include/node/v8-microtask-queue.h +152 -0
  102. package/include/node/v8-microtask.h +28 -0
  103. package/include/node/v8-object.h +1134 -0
  104. package/include/node/v8-persistent-handle.h +556 -0
  105. package/include/node/v8-platform.h +1552 -0
  106. package/include/node/v8-primitive-object.h +118 -0
  107. package/include/node/v8-primitive.h +1056 -0
  108. package/include/node/v8-profiler.h +1401 -0
  109. package/include/node/v8-promise.h +185 -0
  110. package/include/node/v8-proxy.h +49 -0
  111. package/include/node/v8-regexp.h +105 -0
  112. package/include/node/v8-sandbox.h +170 -0
  113. package/include/node/v8-script.h +996 -0
  114. package/include/node/v8-snapshot.h +302 -0
  115. package/include/node/v8-source-location.h +91 -0
  116. package/include/node/v8-statistics.h +246 -0
  117. package/include/node/v8-template.h +1096 -0
  118. package/include/node/v8-trace-categories.h +28 -0
  119. package/include/node/v8-traced-handle.h +420 -0
  120. package/include/node/v8-typed-array.h +386 -0
  121. package/include/node/v8-unwinder-state.h +30 -0
  122. package/include/node/v8-unwinder.h +146 -0
  123. package/include/node/v8-util.h +549 -0
  124. package/include/node/v8-value-serializer-version.h +24 -0
  125. package/include/node/v8-value-serializer.h +316 -0
  126. package/include/node/v8-value.h +674 -0
  127. package/include/node/v8-version-string.h +38 -0
  128. package/include/node/v8-version.h +20 -0
  129. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  130. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  131. package/include/node/v8-wasm.h +325 -0
  132. package/include/node/v8-weak-callback-info.h +88 -0
  133. package/include/node/v8.h +88 -0
  134. package/include/node/v8config.h +1077 -0
  135. package/lib/libc++_shared.so +0 -0
  136. package/lib/libnode.so +4 -0
  137. package/package.json +23 -3
@@ -0,0 +1,580 @@
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 <vector>
11
+
12
+ #include "v8-data.h" // NOLINT(build/include_directory)
13
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
14
+ #include "v8-maybe.h" // NOLINT(build/include_directory)
15
+ #include "v8-snapshot.h" // NOLINT(build/include_directory)
16
+ #include "v8config.h" // NOLINT(build/include_directory)
17
+
18
+ namespace v8 {
19
+
20
+ class Function;
21
+ class MicrotaskQueue;
22
+ class Object;
23
+ class ObjectTemplate;
24
+ class Value;
25
+ class String;
26
+
27
+ /**
28
+ * A container for extension names.
29
+ */
30
+ class V8_EXPORT ExtensionConfiguration {
31
+ public:
32
+ ExtensionConfiguration() : name_count_(0), names_(nullptr) {}
33
+ ExtensionConfiguration(int name_count, const char* names[])
34
+ : name_count_(name_count), names_(names) {}
35
+
36
+ const char** begin() const { return &names_[0]; }
37
+ const char** end() const { return &names_[name_count_]; }
38
+
39
+ private:
40
+ const int name_count_;
41
+ const char** names_;
42
+ };
43
+
44
+ /**
45
+ * A sandboxed execution context with its own set of built-in objects
46
+ * and functions.
47
+ */
48
+ class V8_EXPORT Context : public Data {
49
+ public:
50
+ /**
51
+ * Returns the global proxy object.
52
+ *
53
+ * Global proxy object is a thin wrapper whose prototype points to actual
54
+ * context's global object with the properties like Object, etc. This is done
55
+ * that way for security reasons (for more details see
56
+ * https://wiki.mozilla.org/Gecko:SplitWindow).
57
+ *
58
+ * Please note that changes to global proxy object prototype most probably
59
+ * would break VM---v8 expects only global object as a prototype of global
60
+ * proxy object.
61
+ */
62
+ Local<Object> Global();
63
+
64
+ /**
65
+ * Detaches the global object from its context before
66
+ * the global object can be reused to create a new context.
67
+ */
68
+ void DetachGlobal();
69
+
70
+ /**
71
+ * Creates a new context and returns a handle to the newly allocated
72
+ * context.
73
+ *
74
+ * \param isolate The isolate in which to create the context.
75
+ *
76
+ * \param extensions An optional extension configuration containing
77
+ * the extensions to be installed in the newly created context.
78
+ *
79
+ * \param global_template An optional object template from which the
80
+ * global object for the newly created context will be created.
81
+ *
82
+ * \param global_object An optional global object to be reused for
83
+ * the newly created context. This global object must have been
84
+ * created by a previous call to Context::New with the same global
85
+ * template. The state of the global object will be completely reset
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.
110
+ *
111
+ * \param api_wrapper_deserializer An optional callback used to deserialize
112
+ * API wrapper objects that was initially set with v8::Object::Wrap() and then
113
+ * serialized using SerializeAPIWrapperCallback.
114
+ */
115
+ static Local<Context> New(
116
+ Isolate* isolate, ExtensionConfiguration* extensions = nullptr,
117
+ MaybeLocal<ObjectTemplate> global_template = MaybeLocal<ObjectTemplate>(),
118
+ MaybeLocal<Value> global_object = MaybeLocal<Value>(),
119
+ DeserializeInternalFieldsCallback internal_fields_deserializer =
120
+ DeserializeInternalFieldsCallback(),
121
+ MicrotaskQueue* microtask_queue = nullptr,
122
+ DeserializeContextDataCallback context_data_deserializer =
123
+ DeserializeContextDataCallback(),
124
+ DeserializeAPIWrapperCallback api_wrapper_deserializer =
125
+ DeserializeAPIWrapperCallback());
126
+
127
+ /**
128
+ * Create a new context from a (non-default) context snapshot. There
129
+ * is no way to provide a global object template since we do not create
130
+ * a new global object from template, but we can reuse a global object.
131
+ *
132
+ * \param isolate See v8::Context::New().
133
+ *
134
+ * \param context_snapshot_index The index of the context snapshot to
135
+ * deserialize from. Use v8::Context::New() for the default snapshot.
136
+ *
137
+ * \param internal_fields_deserializer An optional callback used
138
+ * to deserialize fields set by
139
+ * v8::Object::SetAlignedPointerInInternalField() in wrapper objects
140
+ * from the default context snapshot. It does not need to be
141
+ * configured if there are no wrapper objects with no internal
142
+ * pointer fields in the default context snapshot or if no startup
143
+ * snapshot is configured when the isolate is created.
144
+ *
145
+ * \param extensions See v8::Context::New().
146
+ *
147
+ * \param global_object See v8::Context::New().
148
+ *
149
+ * \param internal_fields_deserializer Similar to
150
+ * internal_fields_deserializer in v8::Context::New() but applies to
151
+ * the context specified by the context_snapshot_index.
152
+ *
153
+ * \param microtask_queue See v8::Context::New().
154
+ *
155
+ * \param context_data_deserializer Similar to
156
+ * context_data_deserializer in v8::Context::New() but applies to
157
+ * the context specified by the context_snapshot_index.
158
+ *
159
+ *\param api_wrapper_deserializer Similar to api_wrapper_deserializer in
160
+ * v8::Context::New() but applies to the context specified by the
161
+ * context_snapshot_index.
162
+ */
163
+ static MaybeLocal<Context> FromSnapshot(
164
+ Isolate* isolate, size_t context_snapshot_index,
165
+ DeserializeInternalFieldsCallback internal_fields_deserializer =
166
+ DeserializeInternalFieldsCallback(),
167
+ ExtensionConfiguration* extensions = nullptr,
168
+ MaybeLocal<Value> global_object = MaybeLocal<Value>(),
169
+ MicrotaskQueue* microtask_queue = nullptr,
170
+ DeserializeContextDataCallback context_data_deserializer =
171
+ DeserializeContextDataCallback(),
172
+ DeserializeAPIWrapperCallback api_wrapper_deserializer =
173
+ DeserializeAPIWrapperCallback());
174
+
175
+ /**
176
+ * Returns an global object that isn't backed by an actual context.
177
+ *
178
+ * The global template needs to have access checks with handlers installed.
179
+ * If an existing global object is passed in, the global object is detached
180
+ * from its context.
181
+ *
182
+ * Note that this is different from a detached context where all accesses to
183
+ * the global proxy will fail. Instead, the access check handlers are invoked.
184
+ *
185
+ * It is also not possible to detach an object returned by this method.
186
+ * Instead, the access check handlers need to return nothing to achieve the
187
+ * same effect.
188
+ *
189
+ * It is possible, however, to create a new context from the global object
190
+ * returned by this method.
191
+ */
192
+ static MaybeLocal<Object> NewRemoteContext(
193
+ Isolate* isolate, Local<ObjectTemplate> global_template,
194
+ MaybeLocal<Value> global_object = MaybeLocal<Value>());
195
+
196
+ /**
197
+ * Sets the security token for the context. To access an object in
198
+ * another context, the security tokens must match.
199
+ */
200
+ void SetSecurityToken(Local<Value> token);
201
+
202
+ /** Restores the security token to the default value. */
203
+ void UseDefaultSecurityToken();
204
+
205
+ /** Returns the security token of this context.*/
206
+ Local<Value> GetSecurityToken();
207
+
208
+ /**
209
+ * Enter this context. After entering a context, all code compiled
210
+ * and run is compiled and run in this context. If another context
211
+ * is already entered, this old context is saved so it can be
212
+ * restored when the new context is exited.
213
+ */
214
+ void Enter();
215
+
216
+ /**
217
+ * Exit this context. Exiting the current context restores the
218
+ * context that was in place when entering the current context.
219
+ */
220
+ void Exit();
221
+
222
+ /**
223
+ * Delegate to help with Deep freezing embedder-specific objects (such as
224
+ * JSApiObjects) that can not be frozen natively.
225
+ */
226
+ class DeepFreezeDelegate {
227
+ public:
228
+ /**
229
+ * Performs embedder-specific operations to freeze the provided embedder
230
+ * object. The provided object *will* be frozen by DeepFreeze after this
231
+ * function returns, so only embedder-specific objects need to be frozen.
232
+ * This function *may not* create new JS objects or perform JS allocations.
233
+ * Any v8 objects reachable from the provided embedder object that should
234
+ * also be considered for freezing should be added to the children_out
235
+ * parameter. Returns true if the operation completed successfully.
236
+ */
237
+ virtual bool FreezeEmbedderObjectAndGetChildren(
238
+ Local<Object> obj, LocalVector<Object>& children_out) = 0;
239
+ };
240
+
241
+ /**
242
+ * Attempts to recursively freeze all objects reachable from this context.
243
+ * Some objects (generators, iterators, non-const closures) can not be frozen
244
+ * and will cause this method to throw an error. An optional delegate can be
245
+ * provided to help freeze embedder-specific objects.
246
+ *
247
+ * Freezing occurs in two steps:
248
+ * 1. "Marking" where we iterate through all objects reachable by this
249
+ * context, accumulating a list of objects that need to be frozen and
250
+ * looking for objects that can't be frozen. This step is separated because
251
+ * it is more efficient when we can assume there is no garbage collection.
252
+ * 2. "Freezing" where we go through the list of objects and freezing them.
253
+ * This effectively requires copying them so it may trigger garbage
254
+ * collection.
255
+ */
256
+ Maybe<void> DeepFreeze(DeepFreezeDelegate* delegate = nullptr);
257
+
258
+ /** Returns the microtask queue associated with a current context. */
259
+ MicrotaskQueue* GetMicrotaskQueue();
260
+
261
+ /** Sets the microtask queue associated with the current context. */
262
+ void SetMicrotaskQueue(MicrotaskQueue* queue);
263
+
264
+ /**
265
+ * The field at kDebugIdIndex used to be reserved for the inspector.
266
+ * It now serves no purpose.
267
+ */
268
+ enum EmbedderDataFields { kDebugIdIndex = 0 };
269
+
270
+ /**
271
+ * Return the number of fields allocated for embedder data.
272
+ */
273
+ uint32_t GetNumberOfEmbedderDataFields();
274
+
275
+ /**
276
+ * Gets the embedder data with the given index, which must have been set by a
277
+ * previous call to SetEmbedderData with the same index.
278
+ */
279
+ V8_INLINE Local<Data> GetEmbedderDataV2(int index);
280
+
281
+ /**
282
+ * Sets the embedder data with the given index, growing the data as
283
+ * needed. Note that index 0 currently has a special meaning for Chrome's
284
+ * debugger.
285
+ */
286
+ void SetEmbedderDataV2(int index, Local<Data> value);
287
+
288
+ /**
289
+ * Gets the embedder data with the given index, which must have been set by a
290
+ * previous call to SetEmbedderData with the same index.
291
+ */
292
+ V8_DEPRECATE_SOON("Use GetEmbedderDataV2 instead")
293
+ V8_INLINE Local<Value> GetEmbedderData(int index);
294
+
295
+ /**
296
+ * Gets the binding object used by V8 extras. Extra natives get a reference
297
+ * to this object and can use it to "export" functionality by adding
298
+ * properties. Extra natives can also "import" functionality by accessing
299
+ * properties added by the embedder using the V8 API.
300
+ */
301
+ Local<Object> GetExtrasBindingObject();
302
+
303
+ /**
304
+ * Sets the embedder data with the given index, growing the data as
305
+ * needed. Note that index 0 currently has a special meaning for Chrome's
306
+ * debugger.
307
+ */
308
+ V8_DEPRECATE_SOON("Use SetEmbedderDataV2 instead")
309
+ void SetEmbedderData(int index, Local<Value> value);
310
+
311
+ /**
312
+ * Gets a 2-byte-aligned native pointer from the embedder data with the given
313
+ * index, which must have been set by a previous call to
314
+ * SetAlignedPointerInEmbedderData with the same index. Note that index 0
315
+ * currently has a special meaning for Chrome's debugger.
316
+ */
317
+ V8_INLINE void* GetAlignedPointerFromEmbedderData(Isolate* isolate, int index,
318
+ EmbedderDataTypeTag tag);
319
+ V8_INLINE void* GetAlignedPointerFromEmbedderData(int index,
320
+ EmbedderDataTypeTag tag);
321
+
322
+ V8_DEPRECATED(
323
+ "Use GetAlignedPointerFromEmbedderData with EmbedderDataTypeTag "
324
+ "parameter instead.")
325
+ V8_INLINE void* GetAlignedPointerFromEmbedderData(Isolate* isolate,
326
+ int index) {
327
+ return GetAlignedPointerFromEmbedderData(isolate, index,
328
+ kEmbedderDataTypeTagDefault);
329
+ }
330
+
331
+ V8_DEPRECATED(
332
+ "Use GetAlignedPointerFromEmbedderData with EmbedderDataTypeTag "
333
+ "parameter instead.")
334
+ V8_INLINE void* GetAlignedPointerFromEmbedderData(int index) {
335
+ return GetAlignedPointerFromEmbedderData(index,
336
+ kEmbedderDataTypeTagDefault);
337
+ }
338
+
339
+ void SetAlignedPointerInEmbedderData(int index, void* value,
340
+ EmbedderDataTypeTag tag);
341
+
342
+ /**
343
+ * Sets a 2-byte-aligned native pointer in the embedder data with the given
344
+ * index, growing the data as needed. Note that index 0 currently has a
345
+ * special meaning for Chrome's debugger.
346
+ */
347
+ V8_DEPRECATED(
348
+ "Use SetAlignedPointerInEmbedderData with EmbedderDataTypeTag parameter "
349
+ "instead.")
350
+ void SetAlignedPointerInEmbedderData(int index, void* value) {
351
+ SetAlignedPointerInEmbedderData(index, value, kEmbedderDataTypeTagDefault);
352
+ }
353
+
354
+ /**
355
+ * Control whether code generation from strings is allowed. Calling
356
+ * this method with false will disable 'eval' and the 'Function'
357
+ * constructor for code running in this context. If 'eval' or the
358
+ * 'Function' constructor are used an exception will be thrown.
359
+ *
360
+ * If code generation from strings is not allowed the
361
+ * V8::ModifyCodeGenerationFromStringsCallback callback will be invoked if
362
+ * set before blocking the call to 'eval' or the 'Function'
363
+ * constructor. If that callback returns true, the call will be
364
+ * allowed, otherwise an exception will be thrown. If no callback is
365
+ * set an exception will be thrown.
366
+ */
367
+ void AllowCodeGenerationFromStrings(bool allow);
368
+
369
+ /**
370
+ * Returns true if code generation from strings is allowed for the context.
371
+ * For more details see AllowCodeGenerationFromStrings(bool) documentation.
372
+ */
373
+ bool IsCodeGenerationFromStringsAllowed() const;
374
+
375
+ /**
376
+ * Sets the error description for the exception that is thrown when
377
+ * code generation from strings is not allowed and 'eval' or the 'Function'
378
+ * constructor are called.
379
+ */
380
+ void SetErrorMessageForCodeGenerationFromStrings(Local<String> message);
381
+
382
+ /**
383
+ * Sets the error description for the exception that is thrown when
384
+ * wasm code generation is not allowed.
385
+ */
386
+ void SetErrorMessageForWasmCodeGeneration(Local<String> message);
387
+
388
+ /**
389
+ * Return data that was previously attached to the context snapshot via
390
+ * SnapshotCreator, and removes the reference to it.
391
+ * Repeated call with the same index returns an empty MaybeLocal.
392
+ */
393
+ template <class T>
394
+ V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce(size_t index);
395
+
396
+ /**
397
+ * If callback is set, abort any attempt to execute JavaScript in this
398
+ * context, call the specified callback, and throw an exception.
399
+ * To unset abort, pass nullptr as callback.
400
+ */
401
+ using AbortScriptExecutionCallback = void (*)(Isolate* isolate,
402
+ Local<Context> context);
403
+ void SetAbortScriptExecution(AbortScriptExecutionCallback callback);
404
+
405
+ /**
406
+ * Set or clear hooks to be invoked for promise lifecycle operations.
407
+ * To clear a hook, set it to an empty v8::Function. Each function will
408
+ * receive the observed promise as the first argument. If a chaining
409
+ * operation is used on a promise, the init will additionally receive
410
+ * the parent promise as the second argument.
411
+ */
412
+ void SetPromiseHooks(Local<Function> init_hook, Local<Function> before_hook,
413
+ Local<Function> after_hook,
414
+ Local<Function> resolve_hook);
415
+
416
+ bool HasTemplateLiteralObject(Local<Value> object);
417
+ /**
418
+ * Stack-allocated class which sets the execution context for all
419
+ * operations executed within a local scope.
420
+ */
421
+ class V8_NODISCARD Scope {
422
+ public:
423
+ explicit V8_INLINE Scope(Local<Context> context) : context_(context) {
424
+ context_->Enter();
425
+ }
426
+ V8_INLINE ~Scope() { context_->Exit(); }
427
+
428
+ private:
429
+ Local<Context> context_;
430
+ };
431
+
432
+ /**
433
+ * Stack-allocated class to support the backup incumbent settings object
434
+ * stack.
435
+ * https://html.spec.whatwg.org/multipage/webappapis.html#backup-incumbent-settings-object-stack
436
+ */
437
+ class V8_EXPORT V8_NODISCARD BackupIncumbentScope final {
438
+ public:
439
+ /**
440
+ * |backup_incumbent_context| is pushed onto the backup incumbent settings
441
+ * object stack.
442
+ */
443
+ explicit BackupIncumbentScope(Local<Context> backup_incumbent_context);
444
+ ~BackupIncumbentScope();
445
+
446
+ private:
447
+ friend class internal::Isolate;
448
+
449
+ uintptr_t JSStackComparableAddressPrivate() const {
450
+ return js_stack_comparable_address_;
451
+ }
452
+
453
+ Local<Context> backup_incumbent_context_;
454
+ uintptr_t js_stack_comparable_address_ = 0;
455
+ const BackupIncumbentScope* prev_ = nullptr;
456
+ };
457
+
458
+ V8_INLINE static Context* Cast(Data* data);
459
+
460
+ private:
461
+ friend class Value;
462
+ friend class Script;
463
+ friend class Object;
464
+ friend class Function;
465
+
466
+ static void CheckCast(Data* obj);
467
+
468
+ internal::ValueHelper::InternalRepresentationType GetDataFromSnapshotOnce(
469
+ size_t index);
470
+ Local<Value> SlowGetEmbedderData(int index);
471
+ Local<Data> SlowGetEmbedderDataV2(int index);
472
+ void* SlowGetAlignedPointerFromEmbedderData(int index,
473
+ EmbedderDataTypeTag tag);
474
+ };
475
+
476
+ // --- Implementation ---
477
+
478
+ Local<Value> Context::GetEmbedderData(int index) {
479
+ #ifndef V8_ENABLE_CHECKS
480
+ using A = internal::Address;
481
+ using I = internal::Internals;
482
+ A ctx = internal::ValueHelper::ValueAsAddress(this);
483
+ A embedder_data =
484
+ I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
485
+ int value_offset =
486
+ I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
487
+ A value = I::ReadRawField<A>(embedder_data, value_offset);
488
+ #ifdef V8_COMPRESS_POINTERS
489
+ // We read the full pointer value and then decompress it in order to avoid
490
+ // dealing with potential endianness issues.
491
+ value = I::DecompressTaggedField(embedder_data, static_cast<uint32_t>(value));
492
+ #endif
493
+
494
+ auto* isolate = I::GetCurrentIsolate();
495
+ return Local<Value>::New(isolate, value);
496
+ #else
497
+ return SlowGetEmbedderData(index);
498
+ #endif
499
+ }
500
+
501
+ V8_INLINE Local<Data> Context::GetEmbedderDataV2(int index) {
502
+ #ifndef V8_ENABLE_CHECKS
503
+ using A = internal::Address;
504
+ using I = internal::Internals;
505
+ A ctx = internal::ValueHelper::ValueAsAddress(this);
506
+ A embedder_data =
507
+ I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
508
+ int value_offset =
509
+ I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
510
+ A value = I::ReadRawField<A>(embedder_data, value_offset);
511
+ #ifdef V8_COMPRESS_POINTERS
512
+ // We read the full pointer value and then decompress it in order to avoid
513
+ // dealing with potential endianness issues.
514
+ value = I::DecompressTaggedField(embedder_data, static_cast<uint32_t>(value));
515
+ #endif
516
+
517
+ auto* isolate = I::GetCurrentIsolate();
518
+ return Local<Data>::New(isolate, value);
519
+ #else
520
+ return SlowGetEmbedderDataV2(index);
521
+ #endif
522
+ }
523
+
524
+ void* Context::GetAlignedPointerFromEmbedderData(Isolate* isolate, int index,
525
+ EmbedderDataTypeTag tag) {
526
+ #if !defined(V8_ENABLE_CHECKS)
527
+ using A = internal::Address;
528
+ using I = internal::Internals;
529
+ A ctx = internal::ValueHelper::ValueAsAddress(this);
530
+ A embedder_data =
531
+ I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
532
+ int value_offset = I::kEmbedderDataArrayHeaderSize +
533
+ (I::kEmbedderDataSlotSize * index) +
534
+ I::kEmbedderDataSlotExternalPointerOffset;
535
+ return reinterpret_cast<void*>(I::ReadExternalPointerField(
536
+ isolate, embedder_data, value_offset, ToExternalPointerTag(tag)));
537
+ #else
538
+ return SlowGetAlignedPointerFromEmbedderData(index, tag);
539
+ #endif
540
+ }
541
+
542
+ void* Context::GetAlignedPointerFromEmbedderData(int index,
543
+ EmbedderDataTypeTag tag) {
544
+ #if !defined(V8_ENABLE_CHECKS)
545
+ using A = internal::Address;
546
+ using I = internal::Internals;
547
+ A ctx = internal::ValueHelper::ValueAsAddress(this);
548
+ A embedder_data =
549
+ I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
550
+ int value_offset = I::kEmbedderDataArrayHeaderSize +
551
+ (I::kEmbedderDataSlotSize * index) +
552
+ I::kEmbedderDataSlotExternalPointerOffset;
553
+ Isolate* isolate = I::GetCurrentIsolateForSandbox();
554
+ return reinterpret_cast<void*>(I::ReadExternalPointerField(
555
+ isolate, embedder_data, value_offset, ToExternalPointerTag(tag)));
556
+ #else
557
+ return SlowGetAlignedPointerFromEmbedderData(index, tag);
558
+ #endif
559
+ }
560
+
561
+ template <class T>
562
+ MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) {
563
+ if (auto repr = GetDataFromSnapshotOnce(index);
564
+ repr != internal::ValueHelper::kEmpty) {
565
+ internal::PerformCastCheck(internal::ValueHelper::ReprAsValue<T>(repr));
566
+ return Local<T>::FromRepr(repr);
567
+ }
568
+ return {};
569
+ }
570
+
571
+ Context* Context::Cast(v8::Data* data) {
572
+ #ifdef V8_ENABLE_CHECKS
573
+ CheckCast(data);
574
+ #endif
575
+ return static_cast<Context*>(data);
576
+ }
577
+
578
+ } // namespace v8
579
+
580
+ #endif // INCLUDE_V8_CONTEXT_H_
@@ -0,0 +1,56 @@
1
+ // Copyright 2025 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_HEAP_EXTERNAL_H_
6
+ #define INCLUDE_V8_HEAP_EXTERNAL_H_
7
+
8
+ #include "cppgc/type-traits.h" // NOLINT(build/include_directory)
9
+ #include "v8-sandbox.h" // NOLINT(build/include_directory)
10
+ #include "v8-value.h" // NOLINT(build/include_directory)
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace v8 {
14
+
15
+ class Isolate;
16
+
17
+ /**
18
+ * A JavaScript value that wraps a `cppgc::GarbageCollected<T>` object allocated
19
+ * on the managed C++ heap (CppHeap). This type of value is mainly used to
20
+ * associate C++ data structures which aren't exposed to JavaScript with
21
+ * JavaScript objects.
22
+ */
23
+ class V8_EXPORT CppHeapExternal : public Data {
24
+ public:
25
+ template <typename T>
26
+ static Local<CppHeapExternal> New(Isolate* isolate, T* value,
27
+ CppHeapPointerTag tag) {
28
+ static_assert(cppgc::IsGarbageCollectedTypeV<T>,
29
+ "Object must be of type GarbageCollected.");
30
+ return NewImpl(isolate, value, tag);
31
+ }
32
+
33
+ V8_INLINE static CppHeapExternal* Cast(Data* data) {
34
+ #ifdef V8_ENABLE_CHECKS
35
+ CheckCast(data);
36
+ #endif
37
+ return static_cast<CppHeapExternal*>(data);
38
+ }
39
+
40
+ template <typename T>
41
+ T* Value(Isolate* isolate, CppHeapPointerTagRange tag_range) const {
42
+ static_assert(cppgc::IsGarbageCollectedTypeV<T>,
43
+ "Object must be of type GarbageCollected.");
44
+ return static_cast<T*>(ValueImpl(isolate, tag_range));
45
+ }
46
+
47
+ private:
48
+ static void CheckCast(v8::Data* obj);
49
+ static Local<CppHeapExternal> NewImpl(Isolate* isolate, void* value,
50
+ CppHeapPointerTag tag);
51
+ void* ValueImpl(Isolate*, CppHeapPointerTagRange tag_range) const;
52
+ };
53
+
54
+ } // namespace v8
55
+
56
+ #endif // INCLUDE_V8_HEAP_EXTERNAL_H_