@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,1134 @@
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_OBJECT_H_
6
+ #define INCLUDE_V8_OBJECT_H_
7
+
8
+ #include "cppgc/garbage-collected.h"
9
+ #include "cppgc/name-provider.h"
10
+ #include "v8-internal.h" // NOLINT(build/include_directory)
11
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
12
+ #include "v8-maybe.h" // NOLINT(build/include_directory)
13
+ #include "v8-persistent-handle.h" // NOLINT(build/include_directory)
14
+ #include "v8-primitive.h" // NOLINT(build/include_directory)
15
+ #include "v8-sandbox.h" // NOLINT(build/include_directory)
16
+ #include "v8-traced-handle.h" // NOLINT(build/include_directory)
17
+ #include "v8-value.h" // NOLINT(build/include_directory)
18
+ #include "v8config.h" // NOLINT(build/include_directory)
19
+
20
+ namespace v8 {
21
+
22
+ class Array;
23
+ class Function;
24
+ class FunctionTemplate;
25
+ template <typename T>
26
+ class PropertyCallbackInfo;
27
+
28
+ /**
29
+ * A tag for embedder data. Objects with different C++ types should use
30
+ * different values of EmbedderDataTypeTag when written to embedder data. The
31
+ * allowed range is 0..V8_EMBEDDER_DATA_TAG_COUNT - 1. If this is not
32
+ * sufficient, V8_EMBEDDER_DATA_TAG_COUNT can be increased.
33
+ */
34
+ using EmbedderDataTypeTag = uint16_t;
35
+
36
+ constexpr EmbedderDataTypeTag kEmbedderDataTypeTagDefault = 0;
37
+
38
+ V8_EXPORT internal::ExternalPointerTag ToExternalPointerTag(
39
+ v8::EmbedderDataTypeTag api_tag);
40
+
41
+ /**
42
+ * A private symbol
43
+ *
44
+ * This is an experimental feature. Use at your own risk.
45
+ */
46
+ class V8_EXPORT Private : public Data {
47
+ public:
48
+ /**
49
+ * Returns the print name string of the private symbol, or undefined if none.
50
+ */
51
+ Local<Value> Name() const;
52
+
53
+ /**
54
+ * Create a private symbol. If name is not empty, it will be the description.
55
+ */
56
+ static Local<Private> New(Isolate* isolate,
57
+ Local<String> name = Local<String>());
58
+
59
+ /**
60
+ * Retrieve a global private symbol. If a symbol with this name has not
61
+ * been retrieved in the same isolate before, it is created.
62
+ * Note that private symbols created this way are never collected, so
63
+ * they should only be used for statically fixed properties.
64
+ * Also, there is only one global name space for the names used as keys.
65
+ * To minimize the potential for clashes, use qualified names as keys,
66
+ * e.g., "Class#property".
67
+ */
68
+ static Local<Private> ForApi(Isolate* isolate, Local<String> name);
69
+
70
+ V8_INLINE static Private* Cast(Data* data);
71
+
72
+ private:
73
+ Private();
74
+
75
+ static void CheckCast(Data* that);
76
+ };
77
+
78
+ /**
79
+ * An instance of a Property Descriptor, see Ecma-262 6.2.4.
80
+ *
81
+ * Properties in a descriptor are present or absent. If you do not set
82
+ * `enumerable`, `configurable`, and `writable`, they are absent. If `value`,
83
+ * `get`, or `set` are absent, but you must specify them in the constructor, use
84
+ * empty handles.
85
+ *
86
+ * Accessors `get` and `set` must be callable or undefined if they are present.
87
+ *
88
+ * \note Only query properties if they are present, i.e., call `x()` only if
89
+ * `has_x()` returns true.
90
+ *
91
+ * \code
92
+ * // var desc = {writable: false}
93
+ * v8::PropertyDescriptor d(Local<Value>()), false);
94
+ * d.value(); // error, value not set
95
+ * if (d.has_writable()) {
96
+ * d.writable(); // false
97
+ * }
98
+ *
99
+ * // var desc = {value: undefined}
100
+ * v8::PropertyDescriptor d(v8::Undefined(isolate));
101
+ *
102
+ * // var desc = {get: undefined}
103
+ * v8::PropertyDescriptor d(v8::Undefined(isolate), Local<Value>()));
104
+ * \endcode
105
+ */
106
+ class V8_EXPORT PropertyDescriptor {
107
+ public:
108
+ // GenericDescriptor
109
+ PropertyDescriptor();
110
+
111
+ // DataDescriptor
112
+ explicit PropertyDescriptor(Local<Value> value);
113
+
114
+ // DataDescriptor with writable property
115
+ PropertyDescriptor(Local<Value> value, bool writable);
116
+
117
+ // AccessorDescriptor
118
+ PropertyDescriptor(Local<Value> get, Local<Value> set);
119
+
120
+ ~PropertyDescriptor();
121
+
122
+ Local<Value> value() const;
123
+ bool has_value() const;
124
+
125
+ Local<Value> get() const;
126
+ bool has_get() const;
127
+ Local<Value> set() const;
128
+ bool has_set() const;
129
+
130
+ void set_enumerable(bool enumerable);
131
+ bool enumerable() const;
132
+ bool has_enumerable() const;
133
+
134
+ void set_configurable(bool configurable);
135
+ bool configurable() const;
136
+ bool has_configurable() const;
137
+
138
+ bool writable() const;
139
+ bool has_writable() const;
140
+
141
+ struct PrivateData;
142
+ PrivateData* get_private() const { return private_; }
143
+
144
+ PropertyDescriptor(const PropertyDescriptor&) = delete;
145
+ void operator=(const PropertyDescriptor&) = delete;
146
+
147
+ private:
148
+ PrivateData* private_;
149
+ };
150
+
151
+ /**
152
+ * PropertyAttribute.
153
+ */
154
+ enum PropertyAttribute {
155
+ /** None. **/
156
+ None = 0,
157
+ /** ReadOnly, i.e., not writable. **/
158
+ ReadOnly = 1 << 0,
159
+ /** DontEnum, i.e., not enumerable. **/
160
+ DontEnum = 1 << 1,
161
+ /** DontDelete, i.e., not configurable. **/
162
+ DontDelete = 1 << 2
163
+ };
164
+
165
+ /**
166
+ * This callback function is called when getting a particular data property
167
+ * (i.e. when performing [[Get]] operation).
168
+ *
169
+ * The callback returns the result by calling `info.GetReturnValue().Set(..)`.
170
+ *
171
+ * \param property The name of the property being requested.
172
+ * \param info Information about the intercepted request, such as
173
+ * isolate, object holding the property, return value. See
174
+ * `PropertyCallbackInfo`.
175
+ *
176
+ * See Object::SetNativeDataProperty and
177
+ * ObjectTemplate::SetNativeDataProperty methods.
178
+ */
179
+ using AccessorNameGetterCallback =
180
+ void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
181
+
182
+ /**
183
+ * This callback function is called when setting a particular data property
184
+ * (i.e. when performing [[Set]] operation).
185
+ *
186
+ * In case of operation failure the callback should
187
+ * - call `info.GetReturnValue().Set(false)`,
188
+ * - (optionally) upon operation failure and info.ShouldThrowOnError()
189
+ * is true (indicating execution in `'use strict'` mode) the callback can
190
+ * throw TypeError if the error message needs to include more details than
191
+ * a TypeError thrown by V8 in this case.
192
+ *
193
+ * \param property The name of the property being requested.
194
+ * \param info Information about the intercepted request, such as
195
+ * isolate, object holding the property, return value, or whether running in
196
+ * `'use strict'` mode. See `PropertyCallbackInfo`.
197
+ *
198
+ * See Object::SetNativeDataProperty and
199
+ * ObjectTemplate::SetNativeDataProperty methods.
200
+ */
201
+ using AccessorNameSetterCallback =
202
+ void (*)(Local<Name> property, Local<Value> value,
203
+ const PropertyCallbackInfo<void>& info);
204
+
205
+ /**
206
+ * Property filter bits. They can be or'ed to build a composite filter.
207
+ */
208
+ enum PropertyFilter {
209
+ ALL_PROPERTIES = 0,
210
+ ONLY_WRITABLE = 1,
211
+ ONLY_ENUMERABLE = 2,
212
+ ONLY_CONFIGURABLE = 4,
213
+ SKIP_STRINGS = 8,
214
+ SKIP_SYMBOLS = 16
215
+ };
216
+
217
+ /**
218
+ * Options for marking whether callbacks may trigger JS-observable side effects.
219
+ * Side-effect-free callbacks are allowlisted during debug evaluation with
220
+ * throwOnSideEffect. It applies when calling a Function, FunctionTemplate,
221
+ * or an Accessor callback. For Interceptors, please see
222
+ * PropertyHandlerFlags's kHasNoSideEffect.
223
+ * Callbacks that only cause side effects to the receiver are allowlisted if
224
+ * invoked on receiver objects that are created within the same debug-evaluate
225
+ * call, as these objects are temporary and the side effect does not escape.
226
+ */
227
+ enum class SideEffectType {
228
+ kHasSideEffect,
229
+ kHasNoSideEffect,
230
+ kHasSideEffectToReceiver
231
+ };
232
+
233
+ /**
234
+ * Keys/Properties filter enums:
235
+ *
236
+ * KeyCollectionMode limits the range of collected properties. kOwnOnly limits
237
+ * the collected properties to the given Object only. kIncludesPrototypes will
238
+ * include all keys of the objects's prototype chain as well.
239
+ */
240
+ enum class KeyCollectionMode { kOwnOnly, kIncludePrototypes };
241
+
242
+ /**
243
+ * kIncludesIndices allows for integer indices to be collected, while
244
+ * kSkipIndices will exclude integer indices from being collected.
245
+ */
246
+ enum class IndexFilter { kIncludeIndices, kSkipIndices };
247
+
248
+ /**
249
+ * kConvertToString will convert integer indices to strings.
250
+ * kKeepNumbers will return numbers for integer indices.
251
+ */
252
+ enum class KeyConversionMode { kConvertToString, kKeepNumbers, kNoNumbers };
253
+
254
+ /**
255
+ * Integrity level for objects.
256
+ */
257
+ enum class IntegrityLevel { kFrozen, kSealed };
258
+
259
+ /**
260
+ * A JavaScript object (ECMA-262, 4.3.3)
261
+ */
262
+ class V8_EXPORT Object : public Value {
263
+ public:
264
+ /**
265
+ * Set only return Just(true) or Empty(), so if it should never fail, use
266
+ * result.Check().
267
+ */
268
+ V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
269
+ Local<Value> key, Local<Value> value);
270
+ V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
271
+ Local<Value> key, Local<Value> value,
272
+ MaybeLocal<Object> receiver);
273
+
274
+ V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
275
+ Local<Value> value);
276
+
277
+ /**
278
+ * Implements CreateDataProperty(O, P, V), see
279
+ * https://tc39.es/ecma262/#sec-createdataproperty.
280
+ *
281
+ * Defines a configurable, writable, enumerable property with the given value
282
+ * on the object unless the property already exists and is not configurable
283
+ * or the object is not extensible.
284
+ *
285
+ * Returns true on success.
286
+ */
287
+ V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
288
+ Local<Name> key,
289
+ Local<Value> value);
290
+ V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
291
+ uint32_t index,
292
+ Local<Value> value);
293
+
294
+ /**
295
+ * Implements [[DefineOwnProperty]] for data property case, see
296
+ * https://tc39.es/ecma262/#table-essential-internal-methods.
297
+ *
298
+ * In general, CreateDataProperty will be faster, however, does not allow
299
+ * for specifying attributes.
300
+ *
301
+ * Returns true on success.
302
+ */
303
+ V8_WARN_UNUSED_RESULT Maybe<bool> DefineOwnProperty(
304
+ Local<Context> context, Local<Name> key, Local<Value> value,
305
+ PropertyAttribute attributes = None);
306
+
307
+ /**
308
+ * Implements Object.defineProperty(O, P, Attributes), see
309
+ * https://tc39.es/ecma262/#sec-object.defineproperty.
310
+ *
311
+ * The defineProperty function is used to add an own property or
312
+ * update the attributes of an existing own property of an object.
313
+ *
314
+ * Both data and accessor descriptors can be used.
315
+ *
316
+ * In general, CreateDataProperty is faster, however, does not allow
317
+ * for specifying attributes or an accessor descriptor.
318
+ *
319
+ * The PropertyDescriptor can change when redefining a property.
320
+ *
321
+ * Returns true on success.
322
+ */
323
+ V8_WARN_UNUSED_RESULT Maybe<bool> DefineProperty(
324
+ Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
325
+
326
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
327
+ Local<Value> key);
328
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
329
+ Local<Value> key,
330
+ MaybeLocal<Object> receiver);
331
+
332
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
333
+ uint32_t index);
334
+
335
+ /**
336
+ * Gets the property attributes of a property which can be None or
337
+ * any combination of ReadOnly, DontEnum and DontDelete. Returns
338
+ * None when the property doesn't exist.
339
+ *
340
+ * This method will be deprecated soon, since it doesn't provide a way
341
+ * to return "property does not exist" result. Use GetPropertyAttributes with
342
+ * PropertyAttribute* instead.
343
+ */
344
+ V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetPropertyAttributes(
345
+ Local<Context> context, Local<Value> key);
346
+ /**
347
+ * Gets the property attributes of a property which can be None or
348
+ * any combination of ReadOnly, DontEnum and DontDelete.
349
+ *
350
+ * Returns true and sets *out_attributes if the property exists, false if
351
+ * not or empty Maybe if an exception is thrown. In the latter two cases,
352
+ * the value of *out_attributes is not modified.
353
+ */
354
+ V8_WARN_UNUSED_RESULT Maybe<bool> GetPropertyAttributes(
355
+ Local<Context> context, Local<Value> key,
356
+ PropertyAttribute* out_attributes);
357
+
358
+ /**
359
+ * Implements Object.getOwnPropertyDescriptor(O, P), see
360
+ * https://tc39.es/ecma262/#sec-object.getownpropertydescriptor.
361
+ */
362
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetOwnPropertyDescriptor(
363
+ Local<Context> context, Local<Name> key);
364
+
365
+ /**
366
+ * Object::Has() calls the abstract operation HasProperty(O, P), see
367
+ * https://tc39.es/ecma262/#sec-hasproperty. Has() returns
368
+ * true, if the object has the property, either own or on the prototype chain.
369
+ * Interceptors, i.e., PropertyQueryCallbacks, are called if present.
370
+ *
371
+ * Has() has the same side effects as JavaScript's `variable in object`.
372
+ * For example, calling Has() on a revoked proxy will throw an exception.
373
+ *
374
+ * \note Has() converts the key to a name, which possibly calls back into
375
+ * JavaScript.
376
+ *
377
+ * See also v8::Object::HasOwnProperty() and
378
+ * v8::Object::HasRealNamedProperty().
379
+ */
380
+ V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
381
+ Local<Value> key);
382
+
383
+ V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
384
+ Local<Value> key);
385
+
386
+ V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
387
+
388
+ V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
389
+ uint32_t index);
390
+
391
+ /**
392
+ * Sets an accessor property like Template::SetAccessorProperty, but
393
+ * this method sets on this object directly.
394
+ */
395
+ void SetAccessorProperty(Local<Name> name, Local<Function> getter,
396
+ Local<Function> setter = Local<Function>(),
397
+ PropertyAttribute attributes = None);
398
+
399
+ /**
400
+ * Sets a native data property like Template::SetNativeDataProperty, but
401
+ * this method sets on this object directly.
402
+ */
403
+ V8_WARN_UNUSED_RESULT Maybe<bool> SetNativeDataProperty(
404
+ Local<Context> context, Local<Name> name,
405
+ AccessorNameGetterCallback getter,
406
+ AccessorNameSetterCallback setter = nullptr,
407
+ Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
408
+ SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
409
+ SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
410
+
411
+ /**
412
+ * Attempts to create a property with the given name which behaves like a data
413
+ * property, except that the provided getter is invoked (and provided with the
414
+ * data value) to supply its value the first time it is read. After the
415
+ * property is accessed once, it is replaced with an ordinary data property.
416
+ *
417
+ * Analogous to Template::SetLazyDataProperty.
418
+ */
419
+ V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty(
420
+ Local<Context> context, Local<Name> name,
421
+ AccessorNameGetterCallback getter, Local<Value> data = Local<Value>(),
422
+ PropertyAttribute attributes = None,
423
+ SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
424
+ SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
425
+
426
+ /**
427
+ * Functionality for private properties.
428
+ * This is an experimental feature, use at your own risk.
429
+ * Note: Private properties are not inherited. Do not rely on this, since it
430
+ * may change.
431
+ */
432
+ Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
433
+ Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
434
+ Local<Value> value);
435
+ Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
436
+ MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
437
+
438
+ /**
439
+ * Returns an array containing the names of the enumerable properties
440
+ * of this object, including properties from prototype objects. The
441
+ * array returned by this method contains the same values as would
442
+ * be enumerated by a for-in statement over this object.
443
+ */
444
+ V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
445
+ Local<Context> context);
446
+ V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
447
+ Local<Context> context, KeyCollectionMode mode,
448
+ PropertyFilter property_filter, IndexFilter index_filter,
449
+ KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
450
+
451
+ /**
452
+ * This function has the same functionality as GetPropertyNames but
453
+ * the returned array doesn't contain the names of properties from
454
+ * prototype objects.
455
+ */
456
+ V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
457
+ Local<Context> context);
458
+
459
+ /**
460
+ * Returns an array containing the names of the filtered properties
461
+ * of this object, including properties from prototype objects. The
462
+ * array returned by this method contains the same values as would
463
+ * be enumerated by a for-in statement over this object.
464
+ */
465
+ V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetOwnPropertyNames(
466
+ Local<Context> context, PropertyFilter filter,
467
+ KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
468
+
469
+ /**
470
+ * Get the prototype object (same as calling Object.getPrototypeOf(..)).
471
+ * This does not consult the security handler.
472
+ * TODO(http://crbug.com/333672197): rename back to GetPrototype().
473
+ */
474
+ Local<Value> GetPrototypeV2();
475
+
476
+ /**
477
+ * Set the prototype object (same as calling Object.setPrototypeOf(..)).
478
+ * This does not consult the security handler.
479
+ * TODO(http://crbug.com/333672197): rename back to SetPrototype().
480
+ */
481
+ V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototypeV2(Local<Context> context,
482
+ Local<Value> prototype);
483
+
484
+ /**
485
+ * Finds an instance of the given function template in the prototype
486
+ * chain.
487
+ */
488
+ Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
489
+
490
+ /**
491
+ * Call builtin Object.prototype.toString on this object.
492
+ * This is different from Value::ToString() that may call
493
+ * user-defined toString function. This one does not.
494
+ */
495
+ V8_WARN_UNUSED_RESULT MaybeLocal<String> ObjectProtoToString(
496
+ Local<Context> context);
497
+
498
+ /**
499
+ * Returns the name of the function invoked as a constructor for this object.
500
+ */
501
+ Local<String> GetConstructorName();
502
+
503
+ /**
504
+ * Sets the integrity level of the object.
505
+ */
506
+ Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
507
+
508
+ /** Gets the number of internal fields for this Object. */
509
+ int InternalFieldCount() const;
510
+
511
+ /** Same as above, but works for PersistentBase. */
512
+ V8_INLINE static int InternalFieldCount(
513
+ const PersistentBase<Object>& object) {
514
+ return object.template value<Object>()->InternalFieldCount();
515
+ }
516
+
517
+ /** Same as above, but works for BasicTracedReference. */
518
+ V8_INLINE static int InternalFieldCount(
519
+ const BasicTracedReference<Object>& object) {
520
+ return object.template value<Object>()->InternalFieldCount();
521
+ }
522
+
523
+ /**
524
+ * Gets the data from an internal field.
525
+ * To cast the return value into v8::Value subtypes, it needs to be
526
+ * casted to a v8::Value first. For example, to cast it into v8::External:
527
+ *
528
+ * object->GetInternalField(index).As<v8::Value>().As<v8::External>();
529
+ *
530
+ * The embedder should make sure that the internal field being retrieved
531
+ * using this method has already been set with SetInternalField() before.
532
+ **/
533
+ V8_INLINE Local<Data> GetInternalField(int index);
534
+
535
+ /** Sets the data in an internal field. */
536
+ void SetInternalField(int index, Local<Data> data);
537
+
538
+ /**
539
+ * Gets a 2-byte-aligned native pointer from an internal field. This field
540
+ * must have been set by SetAlignedPointerInInternalField, everything else
541
+ * leads to undefined behavior.
542
+ */
543
+ V8_INLINE void* GetAlignedPointerFromInternalField(int index,
544
+ EmbedderDataTypeTag tag);
545
+ V8_INLINE void* GetAlignedPointerFromInternalField(v8::Isolate* isolate,
546
+ int index,
547
+ EmbedderDataTypeTag tag);
548
+
549
+ /** Same as above, but works for PersistentBase. */
550
+ V8_INLINE static void* GetAlignedPointerFromInternalField(
551
+ const PersistentBase<Object>& object, int index,
552
+ EmbedderDataTypeTag tag) {
553
+ return object.template value<Object>()->GetAlignedPointerFromInternalField(
554
+ index, tag);
555
+ }
556
+
557
+ /** Same as above, but works for TracedReference. */
558
+ V8_INLINE static void* GetAlignedPointerFromInternalField(
559
+ const BasicTracedReference<Object>& object, int index,
560
+ EmbedderDataTypeTag tag) {
561
+ return object.template value<Object>()->GetAlignedPointerFromInternalField(
562
+ index, tag);
563
+ }
564
+
565
+ /**
566
+ * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such
567
+ * a field, GetAlignedPointerFromInternalField must be used, everything else
568
+ * leads to undefined behavior.
569
+ */
570
+ void SetAlignedPointerInInternalField(int index, void* value,
571
+ EmbedderDataTypeTag tag);
572
+
573
+ // Type information for a Wrappable object that got wrapped with
574
+ // `v8::Object::Wrap()`.
575
+ struct WrapperTypeInfo {
576
+ const int16_t type_id;
577
+ };
578
+
579
+ // v8::Object::Wrappable serves as the base class for all C++ objects that can
580
+ // be wrapped by a JavaScript object using `v8::Object::Wrap()`.
581
+ //
582
+ // Note that v8::Object::Wrappable` inherits from `NameProvider` and provides
583
+ // `GetWrapperTypeInfo` to allow subclasses to have smaller object sizes.
584
+ class Wrappable : public cppgc::GarbageCollected<Wrappable>,
585
+ public cppgc::NameProvider {
586
+ public:
587
+ virtual const WrapperTypeInfo* GetWrapperTypeInfo() const {
588
+ return nullptr;
589
+ }
590
+
591
+ const char* GetHumanReadableName() const override { return "internal"; }
592
+
593
+ virtual void Trace(cppgc::Visitor* visitor) const {}
594
+ };
595
+
596
+ /**
597
+ * Unwraps a JS wrapper object.
598
+ *
599
+ * \param tag The tag for retrieving the wrappable instance. Must match the
600
+ * tag that has been used for a previous `Wrap()` operation.
601
+ * \param isolate The Isolate for the `wrapper` object.
602
+ * \param wrapper The JS wrapper object that should be unwrapped.
603
+ * \returns the C++ wrappable instance, or nullptr if the JS object has never
604
+ * been wrapped.
605
+ */
606
+ template <CppHeapPointerTag tag, typename T = void>
607
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
608
+ const v8::Local<v8::Object>& wrapper);
609
+ template <CppHeapPointerTag tag, typename T = void>
610
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
611
+ const PersistentBase<Object>& wrapper);
612
+ template <CppHeapPointerTag tag, typename T = void>
613
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
614
+ const BasicTracedReference<Object>& wrapper);
615
+
616
+ template <typename T = void>
617
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
618
+ const v8::Local<v8::Object>& wrapper,
619
+ CppHeapPointerTagRange tag_range);
620
+ template <typename T = void>
621
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
622
+ const PersistentBase<Object>& wrapper,
623
+ CppHeapPointerTagRange tag_range);
624
+ template <typename T = void>
625
+ static V8_INLINE T* Unwrap(v8::Isolate* isolate,
626
+ const BasicTracedReference<Object>& wrapper,
627
+ CppHeapPointerTagRange tag_range);
628
+
629
+ /**
630
+ * Wraps a JS wrapper with a C++ instance.
631
+ *
632
+ * \param tag The pointer tag that should be used for storing this object.
633
+ * Future `Unwrap()` operations must provide a matching tag.
634
+ * \param isolate The Isolate for the `wrapper` object.
635
+ * \param wrapper The JS wrapper object.
636
+ * \param wrappable The C++ object instance that is wrapped by the JS object.
637
+ */
638
+ template <CppHeapPointerTag tag>
639
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
640
+ const v8::Local<v8::Object>& wrapper,
641
+ Wrappable* wrappable);
642
+ template <CppHeapPointerTag tag>
643
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
644
+ const PersistentBase<Object>& wrapper,
645
+ Wrappable* wrappable);
646
+ template <CppHeapPointerTag tag>
647
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
648
+ const BasicTracedReference<Object>& wrapper,
649
+ Wrappable* wrappable);
650
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
651
+ const v8::Local<v8::Object>& wrapper,
652
+ Wrappable* wrappable, CppHeapPointerTag tag);
653
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
654
+ const PersistentBase<Object>& wrapper,
655
+ Wrappable* wrappable, CppHeapPointerTag tag);
656
+ static V8_INLINE void Wrap(v8::Isolate* isolate,
657
+ const BasicTracedReference<Object>& wrapper,
658
+ Wrappable* wrappable, CppHeapPointerTag tag);
659
+
660
+ // Version of Wrap() function for v8::Context::Global() objects.
661
+ // Unlike the functions above it wraps both JSGlobalProxy and its hidden
662
+ // prototype (JSGlobalObject or remote object).
663
+ static void WrapGlobal(v8::Isolate* isolate,
664
+ const v8::Local<v8::Object>& wrapper,
665
+ Wrappable* wrappable, CppHeapPointerTag tag);
666
+
667
+ // Checks that wrappables set on JSGlobalProxy and its hidden prototype are
668
+ // the same.
669
+ static bool CheckGlobalWrappable(v8::Isolate* isolate,
670
+ const v8::Local<v8::Object>& wrapper,
671
+ CppHeapPointerTagRange tag_range);
672
+
673
+ /**
674
+ * HasOwnProperty() is like JavaScript's
675
+ * Object.prototype.hasOwnProperty().
676
+ *
677
+ * See also v8::Object::Has() and v8::Object::HasRealNamedProperty().
678
+ */
679
+ V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
680
+ Local<Name> key);
681
+ V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
682
+ uint32_t index);
683
+ /**
684
+ * Use HasRealNamedProperty() if you want to check if an object has an own
685
+ * property without causing side effects, i.e., without calling interceptors.
686
+ *
687
+ * This function is similar to v8::Object::HasOwnProperty(), but it does not
688
+ * call interceptors.
689
+ *
690
+ * \note Consider using non-masking interceptors, i.e., the interceptors are
691
+ * not called if the receiver has the real named property. See
692
+ * `v8::PropertyHandlerFlags::kNonMasking`.
693
+ *
694
+ * See also v8::Object::Has().
695
+ */
696
+ V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
697
+ Local<Name> key);
698
+ V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
699
+ Local<Context> context, uint32_t index);
700
+ V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
701
+ Local<Context> context, Local<Name> key);
702
+
703
+ /**
704
+ * If result.IsEmpty() no real property was located in the prototype chain.
705
+ * This means interceptors in the prototype chain are not called.
706
+ */
707
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
708
+ Local<Context> context, Local<Name> key);
709
+
710
+ /**
711
+ * Gets the property attributes of a real property in the prototype chain,
712
+ * which can be None or any combination of ReadOnly, DontEnum and DontDelete.
713
+ * Interceptors in the prototype chain are not called.
714
+ */
715
+ V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute>
716
+ GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
717
+ Local<Name> key);
718
+
719
+ /**
720
+ * If result.IsEmpty() no real property was located on the object or
721
+ * in the prototype chain.
722
+ * This means interceptors in the prototype chain are not called.
723
+ */
724
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedProperty(
725
+ Local<Context> context, Local<Name> key);
726
+
727
+ /**
728
+ * Gets the property attributes of a real property which can be
729
+ * None or any combination of ReadOnly, DontEnum and DontDelete.
730
+ * Interceptors in the prototype chain are not called.
731
+ */
732
+ V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
733
+ Local<Context> context, Local<Name> key);
734
+
735
+ /** Tests for a named lookup interceptor.*/
736
+ bool HasNamedLookupInterceptor() const;
737
+
738
+ /** Tests for an index lookup interceptor.*/
739
+ bool HasIndexedLookupInterceptor() const;
740
+
741
+ /**
742
+ * Returns the identity hash for this object. The current implementation
743
+ * uses a hidden property on the object to store the identity hash.
744
+ *
745
+ * The return value will never be 0. Also, it is not guaranteed to be
746
+ * unique.
747
+ */
748
+ int GetIdentityHash();
749
+
750
+ /**
751
+ * Clone this object with a fast but shallow copy. Values will point to the
752
+ * same values as the original object.
753
+ *
754
+ * Prefer using version with Isolate parameter.
755
+ */
756
+ Local<Object> Clone(v8::Isolate* isolate);
757
+ Local<Object> Clone();
758
+
759
+ /**
760
+ * Returns the context in which the object was created.
761
+ *
762
+ * Prefer using version with Isolate parameter.
763
+ */
764
+ MaybeLocal<Context> GetCreationContext(v8::Isolate* isolate);
765
+ V8_DEPRECATE_SOON("Use the version with the isolate argument.")
766
+ MaybeLocal<Context> GetCreationContext();
767
+
768
+ /**
769
+ * Shortcut for GetCreationContext(...).ToLocalChecked().
770
+ *
771
+ * Prefer using version with Isolate parameter.
772
+ **/
773
+ Local<Context> GetCreationContextChecked(v8::Isolate* isolate);
774
+ V8_DEPRECATE_SOON("Use the version with the isolate argument.")
775
+ Local<Context> GetCreationContextChecked();
776
+
777
+ /** Same as above, but works for Persistents */
778
+ V8_INLINE static MaybeLocal<Context> GetCreationContext(
779
+ v8::Isolate* isolate, const PersistentBase<Object>& object) {
780
+ return object.template value<Object>()->GetCreationContext(isolate);
781
+ }
782
+ V8_DEPRECATE_SOON("Use the version with the isolate argument.")
783
+ V8_INLINE static MaybeLocal<Context> GetCreationContext(
784
+ const PersistentBase<Object>& object);
785
+
786
+ /**
787
+ * Gets the context in which the object was created (see GetCreationContext())
788
+ * and if it's available reads respective embedder field value.
789
+ * If the context can't be obtained nullptr is returned.
790
+ * Basically it's a shortcut for
791
+ * obj->GetCreationContext().GetAlignedPointerFromEmbedderData(index)
792
+ * which doesn't create a handle for Context object on the way and doesn't
793
+ * try to expand the embedder data attached to the context.
794
+ * In case the Local<Context> is already available because of other reasons,
795
+ * it's fine to keep using Context::GetAlignedPointerFromEmbedderData().
796
+ *
797
+ * Prefer using version with Isolate parameter if you have an Isolate,
798
+ * otherwise use the other one.
799
+ *
800
+ * The type tag has to match the type tag used for storing the value in the
801
+ * embedder field.
802
+ * If type tags are not used in the embedder, the default value
803
+ * `kEmbedderDataTypeTagDefault` can be used.
804
+ */
805
+ void* GetAlignedPointerFromEmbedderDataInCreationContext(
806
+ v8::Isolate* isolate, int index, EmbedderDataTypeTag tag);
807
+ void* GetAlignedPointerFromEmbedderDataInCreationContext(
808
+ int index, EmbedderDataTypeTag tag);
809
+
810
+ /**
811
+ * Checks whether a callback is set by the
812
+ * ObjectTemplate::SetCallAsFunctionHandler method.
813
+ * When an Object is callable this method returns true.
814
+ */
815
+ bool IsCallable() const;
816
+
817
+ /**
818
+ * True if this object is a constructor.
819
+ */
820
+ bool IsConstructor() const;
821
+
822
+ /**
823
+ * Returns true if this object can be generally used to wrap object objects.
824
+ * This means that the object either follows the convention of using embedder
825
+ * fields to denote type/instance pointers or is using the Wrap()/Unwrap()
826
+ * APIs for the same purpose. Returns false otherwise.
827
+ *
828
+ * Note that there may be other objects that use embedder fields but are not
829
+ * used as API wrapper objects. E.g., v8::Promise may in certain configuration
830
+ * use embedder fields but promises are not generally supported as API
831
+ * wrappers. The method will return false in those cases.
832
+ */
833
+ bool IsApiWrapper() const;
834
+
835
+ /**
836
+ * True if this object was created from an object template which was marked
837
+ * as undetectable. See v8::ObjectTemplate::MarkAsUndetectable for more
838
+ * information.
839
+ */
840
+ bool IsUndetectable() const;
841
+
842
+ /**
843
+ * Call an Object as a function if a callback is set by the
844
+ * ObjectTemplate::SetCallAsFunctionHandler method.
845
+ */
846
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
847
+ Local<Value> recv,
848
+ int argc,
849
+ Local<Value> argv[]);
850
+
851
+ /**
852
+ * Call an Object as a constructor if a callback is set by the
853
+ * ObjectTemplate::SetCallAsFunctionHandler method.
854
+ * Note: This method behaves like the Function::NewInstance method.
855
+ */
856
+ V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsConstructor(
857
+ Local<Context> context, int argc, Local<Value> argv[]);
858
+
859
+ /**
860
+ * If this object is a Set, Map, WeakSet or WeakMap, this returns a
861
+ * representation of the elements of this object as an array.
862
+ * If this object is a SetIterator or MapIterator, this returns all
863
+ * elements of the underlying collection, starting at the iterator's current
864
+ * position.
865
+ * For other types, this will return an empty MaybeLocal<Array> (without
866
+ * scheduling an exception).
867
+ */
868
+ MaybeLocal<Array> PreviewEntries(bool* is_key_value);
869
+
870
+ static Local<Object> New(Isolate* isolate);
871
+
872
+ /**
873
+ * Creates a JavaScript object with the given properties, and
874
+ * a the given prototype_or_null (which can be any JavaScript
875
+ * value, and if it's null, the newly created object won't have
876
+ * a prototype at all). This is similar to Object.create().
877
+ * All properties will be created as enumerable, configurable
878
+ * and writable properties.
879
+ */
880
+ static Local<Object> New(Isolate* isolate, Local<Value> prototype_or_null,
881
+ Local<Name>* names, Local<Value>* values,
882
+ size_t length);
883
+
884
+ V8_INLINE static Object* Cast(Value* obj);
885
+
886
+ /**
887
+ * Support for TC39 "dynamic code brand checks" proposal.
888
+ *
889
+ * This API allows to query whether an object was constructed from a
890
+ * "code like" ObjectTemplate.
891
+ *
892
+ * See also: v8::ObjectTemplate::SetCodeLike
893
+ */
894
+ bool IsCodeLike(Isolate* isolate) const;
895
+
896
+ private:
897
+ static void* Unwrap(v8::Isolate* isolate, internal::Address wrapper_obj,
898
+ CppHeapPointerTagRange tag_range);
899
+ static void Wrap(v8::Isolate* isolate, internal::Address wrapper_obj,
900
+ CppHeapPointerTag tag, void* wrappable);
901
+
902
+ Object();
903
+ static void CheckCast(Value* obj);
904
+ Local<Data> SlowGetInternalField(int index);
905
+ void* SlowGetAlignedPointerFromInternalField(int index,
906
+ EmbedderDataTypeTag tag);
907
+ void* SlowGetAlignedPointerFromInternalField(v8::Isolate* isolate, int index,
908
+ EmbedderDataTypeTag tag);
909
+ };
910
+
911
+ // --- Implementation ---
912
+
913
+ Local<Data> Object::GetInternalField(int index) {
914
+ #ifndef V8_ENABLE_CHECKS
915
+ using A = internal::Address;
916
+ using I = internal::Internals;
917
+ A obj = internal::ValueHelper::ValueAsAddress(this);
918
+ // Fast path: If the object is a plain JSObject, which is the common case, we
919
+ // know where to find the internal fields and can return the value directly.
920
+ int instance_type = I::GetInstanceType(obj);
921
+ if (I::CanHaveInternalField(instance_type)) {
922
+ int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
923
+ (I::kEmbedderDataSlotSize * index);
924
+ A value = I::ReadRawField<A>(obj, offset);
925
+ #ifdef V8_COMPRESS_POINTERS
926
+ // We read the full pointer value and then decompress it in order to avoid
927
+ // dealing with potential endianness issues.
928
+ value = I::DecompressTaggedField(obj, static_cast<uint32_t>(value));
929
+ #endif
930
+
931
+ auto* isolate = I::GetCurrentIsolate();
932
+ return Local<Data>::New(isolate, value);
933
+ }
934
+ #endif
935
+ return SlowGetInternalField(index);
936
+ }
937
+
938
+ void* Object::GetAlignedPointerFromInternalField(v8::Isolate* isolate,
939
+ int index,
940
+ EmbedderDataTypeTag tag) {
941
+ #if !defined(V8_ENABLE_CHECKS)
942
+ using A = internal::Address;
943
+ using I = internal::Internals;
944
+ A obj = internal::ValueHelper::ValueAsAddress(this);
945
+ // Fast path: If the object is a plain JSObject, which is the common case, we
946
+ // know where to find the internal fields and can return the value directly.
947
+ auto instance_type = I::GetInstanceType(obj);
948
+ if (V8_LIKELY(I::CanHaveInternalField(instance_type))) {
949
+ int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
950
+ (I::kEmbedderDataSlotSize * index) +
951
+ I::kEmbedderDataSlotExternalPointerOffset;
952
+ A value = I::ReadExternalPointerField(isolate, obj, offset,
953
+ ToExternalPointerTag(tag));
954
+ return reinterpret_cast<void*>(value);
955
+ }
956
+ #endif
957
+ return SlowGetAlignedPointerFromInternalField(isolate, index, tag);
958
+ }
959
+
960
+ void* Object::GetAlignedPointerFromInternalField(int index,
961
+ EmbedderDataTypeTag tag) {
962
+ #if !defined(V8_ENABLE_CHECKS)
963
+ using A = internal::Address;
964
+ using I = internal::Internals;
965
+ A obj = internal::ValueHelper::ValueAsAddress(this);
966
+ // Fast path: If the object is a plain JSObject, which is the common case, we
967
+ // know where to find the internal fields and can return the value directly.
968
+ auto instance_type = I::GetInstanceType(obj);
969
+ if (V8_LIKELY(I::CanHaveInternalField(instance_type))) {
970
+ int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
971
+ (I::kEmbedderDataSlotSize * index) +
972
+ I::kEmbedderDataSlotExternalPointerOffset;
973
+ Isolate* isolate = I::GetCurrentIsolateForSandbox();
974
+ A value = I::ReadExternalPointerField(isolate, obj, offset,
975
+ ToExternalPointerTag(tag));
976
+ return reinterpret_cast<void*>(value);
977
+ }
978
+ #endif
979
+ return SlowGetAlignedPointerFromInternalField(index, tag);
980
+ }
981
+
982
+ // static
983
+ template <CppHeapPointerTag tag, typename T>
984
+ T* Object::Unwrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper) {
985
+ CppHeapPointerTagRange tag_range(tag, tag);
986
+ auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
987
+ #if !defined(V8_ENABLE_CHECKS)
988
+ return internal::ReadCppHeapPointerField<T>(
989
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
990
+ #else // defined(V8_ENABLE_CHECKS)
991
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
992
+ #endif // defined(V8_ENABLE_CHECKS)
993
+ }
994
+
995
+ // static
996
+ template <CppHeapPointerTag tag, typename T>
997
+ T* Object::Unwrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper) {
998
+ CppHeapPointerTagRange tag_range(tag, tag);
999
+ auto obj =
1000
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1001
+ #if !defined(V8_ENABLE_CHECKS)
1002
+ return internal::ReadCppHeapPointerField<T>(
1003
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1004
+ #else // defined(V8_ENABLE_CHECKS)
1005
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1006
+ #endif // defined(V8_ENABLE_CHECKS)
1007
+ }
1008
+
1009
+ // static
1010
+ template <CppHeapPointerTag tag, typename T>
1011
+ T* Object::Unwrap(v8::Isolate* isolate,
1012
+ const BasicTracedReference<Object>& wrapper) {
1013
+ CppHeapPointerTagRange tag_range(tag, tag);
1014
+ auto obj =
1015
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1016
+ #if !defined(V8_ENABLE_CHECKS)
1017
+ return internal::ReadCppHeapPointerField<T>(
1018
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1019
+ #else // defined(V8_ENABLE_CHECKS)
1020
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1021
+ #endif // defined(V8_ENABLE_CHECKS)
1022
+ }
1023
+
1024
+ // static
1025
+ template <typename T>
1026
+ T* Object::Unwrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1027
+ CppHeapPointerTagRange tag_range) {
1028
+ auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1029
+ #if !defined(V8_ENABLE_CHECKS)
1030
+ return internal::ReadCppHeapPointerField<T>(
1031
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1032
+ #else // defined(V8_ENABLE_CHECKS)
1033
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1034
+ #endif // defined(V8_ENABLE_CHECKS)
1035
+ }
1036
+
1037
+ // static
1038
+ template <typename T>
1039
+ T* Object::Unwrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper,
1040
+ CppHeapPointerTagRange tag_range) {
1041
+ auto obj =
1042
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1043
+ #if !defined(V8_ENABLE_CHECKS)
1044
+ return internal::ReadCppHeapPointerField<T>(
1045
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1046
+ #else // defined(V8_ENABLE_CHECKS)
1047
+
1048
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1049
+ #endif // defined(V8_ENABLE_CHECKS)
1050
+ }
1051
+
1052
+ // static
1053
+ template <typename T>
1054
+ T* Object::Unwrap(v8::Isolate* isolate,
1055
+ const BasicTracedReference<Object>& wrapper,
1056
+ CppHeapPointerTagRange tag_range) {
1057
+ auto obj =
1058
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1059
+ #if !defined(V8_ENABLE_CHECKS)
1060
+ return internal::ReadCppHeapPointerField<T>(
1061
+ isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1062
+ #else // defined(V8_ENABLE_CHECKS)
1063
+ return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1064
+ #endif // defined(V8_ENABLE_CHECKS)
1065
+ }
1066
+
1067
+ // static
1068
+ template <CppHeapPointerTag tag>
1069
+ void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1070
+ v8::Object::Wrappable* wrappable) {
1071
+ auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1072
+ Wrap(isolate, obj, tag, wrappable);
1073
+ }
1074
+
1075
+ // static
1076
+ template <CppHeapPointerTag tag>
1077
+ void Object::Wrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper,
1078
+ v8::Object::Wrappable* wrappable) {
1079
+ auto obj =
1080
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1081
+ Wrap(isolate, obj, tag, wrappable);
1082
+ }
1083
+
1084
+ // static
1085
+ template <CppHeapPointerTag tag>
1086
+ void Object::Wrap(v8::Isolate* isolate,
1087
+ const BasicTracedReference<Object>& wrapper,
1088
+ v8::Object::Wrappable* wrappable) {
1089
+ auto obj =
1090
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1091
+ Wrap(isolate, obj, tag, wrappable);
1092
+ }
1093
+
1094
+ // static
1095
+ void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1096
+ v8::Object::Wrappable* wrappable, CppHeapPointerTag tag) {
1097
+ auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1098
+ Wrap(isolate, obj, tag, wrappable);
1099
+ }
1100
+
1101
+ // static
1102
+ void Object::Wrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper,
1103
+ v8::Object::Wrappable* wrappable, CppHeapPointerTag tag) {
1104
+ auto obj =
1105
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1106
+ Wrap(isolate, obj, tag, wrappable);
1107
+ }
1108
+
1109
+ // static
1110
+ void Object::Wrap(v8::Isolate* isolate,
1111
+ const BasicTracedReference<Object>& wrapper,
1112
+ v8::Object::Wrappable* wrappable, CppHeapPointerTag tag) {
1113
+ auto obj =
1114
+ internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1115
+ Wrap(isolate, obj, tag, wrappable);
1116
+ }
1117
+
1118
+ Private* Private::Cast(Data* data) {
1119
+ #ifdef V8_ENABLE_CHECKS
1120
+ CheckCast(data);
1121
+ #endif
1122
+ return reinterpret_cast<Private*>(data);
1123
+ }
1124
+
1125
+ Object* Object::Cast(v8::Value* value) {
1126
+ #ifdef V8_ENABLE_CHECKS
1127
+ CheckCast(value);
1128
+ #endif
1129
+ return static_cast<Object*>(value);
1130
+ }
1131
+
1132
+ } // namespace v8
1133
+
1134
+ #endif // INCLUDE_V8_OBJECT_H_