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

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 (138) hide show
  1. package/README.md +7 -0
  2. package/include/node/cppgc/allocation.h +308 -0
  3. package/include/node/cppgc/common.h +28 -0
  4. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  5. package/include/node/cppgc/custom-space.h +97 -0
  6. package/include/node/cppgc/default-platform.h +68 -0
  7. package/include/node/cppgc/explicit-management.h +100 -0
  8. package/include/node/cppgc/garbage-collected.h +114 -0
  9. package/include/node/cppgc/heap-consistency.h +309 -0
  10. package/include/node/cppgc/heap-handle.h +48 -0
  11. package/include/node/cppgc/heap-state.h +82 -0
  12. package/include/node/cppgc/heap-statistics.h +126 -0
  13. package/include/node/cppgc/heap.h +202 -0
  14. package/include/node/cppgc/internal/api-constants.h +75 -0
  15. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  16. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  17. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  18. package/include/node/cppgc/internal/caged-heap.h +64 -0
  19. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  20. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  21. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  22. package/include/node/cppgc/internal/gc-info.h +150 -0
  23. package/include/node/cppgc/internal/logging.h +50 -0
  24. package/include/node/cppgc/internal/member-storage.h +305 -0
  25. package/include/node/cppgc/internal/name-trait.h +141 -0
  26. package/include/node/cppgc/internal/persistent-node.h +219 -0
  27. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  28. package/include/node/cppgc/internal/write-barrier.h +487 -0
  29. package/include/node/cppgc/liveness-broker.h +78 -0
  30. package/include/node/cppgc/macros.h +56 -0
  31. package/include/node/cppgc/member.h +669 -0
  32. package/include/node/cppgc/name-provider.h +75 -0
  33. package/include/node/cppgc/object-size-trait.h +58 -0
  34. package/include/node/cppgc/persistent.h +376 -0
  35. package/include/node/cppgc/platform.h +174 -0
  36. package/include/node/cppgc/prefinalizer.h +75 -0
  37. package/include/node/cppgc/process-heap-statistics.h +36 -0
  38. package/include/node/cppgc/sentinel-pointer.h +39 -0
  39. package/include/node/cppgc/source-location.h +16 -0
  40. package/include/node/cppgc/tagged-member.h +114 -0
  41. package/include/node/cppgc/testing.h +106 -0
  42. package/include/node/cppgc/trace-trait.h +127 -0
  43. package/include/node/cppgc/type-traits.h +272 -0
  44. package/include/node/cppgc/visitor.h +534 -0
  45. package/include/node/js_native_api.h +634 -0
  46. package/include/node/js_native_api_types.h +244 -0
  47. package/include/node/libplatform/libplatform-export.h +29 -0
  48. package/include/node/libplatform/libplatform.h +112 -0
  49. package/include/node/libplatform/v8-tracing.h +343 -0
  50. package/include/node/node.h +1744 -0
  51. package/include/node/node_api.h +265 -0
  52. package/include/node/node_api_types.h +58 -0
  53. package/include/node/node_buffer.h +94 -0
  54. package/include/node/node_object_wrap.h +145 -0
  55. package/include/node/node_version.h +116 -0
  56. package/include/node/uv/aix.h +32 -0
  57. package/include/node/uv/bsd.h +34 -0
  58. package/include/node/uv/darwin.h +61 -0
  59. package/include/node/uv/errno.h +483 -0
  60. package/include/node/uv/linux.h +34 -0
  61. package/include/node/uv/os390.h +33 -0
  62. package/include/node/uv/posix.h +31 -0
  63. package/include/node/uv/sunos.h +44 -0
  64. package/include/node/uv/threadpool.h +37 -0
  65. package/include/node/uv/tree.h +521 -0
  66. package/include/node/uv/unix.h +509 -0
  67. package/include/node/uv/version.h +43 -0
  68. package/include/node/uv/win.h +698 -0
  69. package/include/node/uv.h +1994 -0
  70. package/include/node/v8-array-buffer.h +646 -0
  71. package/include/node/v8-callbacks.h +533 -0
  72. package/include/node/v8-container.h +183 -0
  73. package/include/node/v8-context.h +580 -0
  74. package/include/node/v8-cpp-heap-external.h +56 -0
  75. package/include/node/v8-cppgc.h +194 -0
  76. package/include/node/v8-data.h +96 -0
  77. package/include/node/v8-date.h +57 -0
  78. package/include/node/v8-debug.h +210 -0
  79. package/include/node/v8-embedder-heap.h +54 -0
  80. package/include/node/v8-embedder-state-scope.h +52 -0
  81. package/include/node/v8-exception.h +298 -0
  82. package/include/node/v8-extension.h +60 -0
  83. package/include/node/v8-external-memory-accounter.h +60 -0
  84. package/include/node/v8-external.h +73 -0
  85. package/include/node/v8-fast-api-calls.h +784 -0
  86. package/include/node/v8-forward.h +82 -0
  87. package/include/node/v8-function-callback.h +708 -0
  88. package/include/node/v8-function.h +148 -0
  89. package/include/node/v8-handle-base.h +155 -0
  90. package/include/node/v8-initialization.h +343 -0
  91. package/include/node/v8-inspector-protocol.h +13 -0
  92. package/include/node/v8-inspector.h +458 -0
  93. package/include/node/v8-internal.h +1827 -0
  94. package/include/node/v8-isolate.h +1925 -0
  95. package/include/node/v8-json.h +54 -0
  96. package/include/node/v8-local-handle.h +884 -0
  97. package/include/node/v8-locker.h +138 -0
  98. package/include/node/v8-maybe.h +185 -0
  99. package/include/node/v8-memory-span.h +273 -0
  100. package/include/node/v8-message.h +215 -0
  101. package/include/node/v8-metrics.h +273 -0
  102. package/include/node/v8-microtask-queue.h +152 -0
  103. package/include/node/v8-microtask.h +28 -0
  104. package/include/node/v8-object.h +1134 -0
  105. package/include/node/v8-persistent-handle.h +556 -0
  106. package/include/node/v8-platform.h +1552 -0
  107. package/include/node/v8-primitive-object.h +118 -0
  108. package/include/node/v8-primitive.h +1056 -0
  109. package/include/node/v8-profiler.h +1401 -0
  110. package/include/node/v8-promise.h +185 -0
  111. package/include/node/v8-proxy.h +49 -0
  112. package/include/node/v8-regexp.h +105 -0
  113. package/include/node/v8-sandbox.h +170 -0
  114. package/include/node/v8-script.h +996 -0
  115. package/include/node/v8-snapshot.h +302 -0
  116. package/include/node/v8-source-location.h +91 -0
  117. package/include/node/v8-statistics.h +246 -0
  118. package/include/node/v8-template.h +1096 -0
  119. package/include/node/v8-trace-categories.h +28 -0
  120. package/include/node/v8-traced-handle.h +420 -0
  121. package/include/node/v8-typed-array.h +386 -0
  122. package/include/node/v8-unwinder-state.h +30 -0
  123. package/include/node/v8-unwinder.h +146 -0
  124. package/include/node/v8-util.h +549 -0
  125. package/include/node/v8-value-serializer-version.h +24 -0
  126. package/include/node/v8-value-serializer.h +316 -0
  127. package/include/node/v8-value.h +674 -0
  128. package/include/node/v8-version-string.h +38 -0
  129. package/include/node/v8-version.h +20 -0
  130. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  131. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  132. package/include/node/v8-wasm.h +325 -0
  133. package/include/node/v8-weak-callback-info.h +88 -0
  134. package/include/node/v8.h +88 -0
  135. package/include/node/v8config.h +1077 -0
  136. package/lib/libc++_shared.so +0 -0
  137. package/lib/libnode.so +4 -0
  138. package/package.json +23 -3
@@ -0,0 +1,708 @@
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_FUNCTION_CALLBACK_H_
6
+ #define INCLUDE_V8_FUNCTION_CALLBACK_H_
7
+
8
+ #include <cstdint>
9
+ #include <limits>
10
+
11
+ #include "v8-internal.h" // NOLINT(build/include_directory)
12
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
13
+ #include "v8-primitive.h" // NOLINT(build/include_directory)
14
+ #include "v8config.h" // NOLINT(build/include_directory)
15
+
16
+ namespace v8 {
17
+
18
+ template <typename T>
19
+ class BasicTracedReference;
20
+ template <typename T>
21
+ class Global;
22
+ class Object;
23
+ class Value;
24
+
25
+ namespace internal {
26
+ class FunctionCallbackArguments;
27
+ class PropertyCallbackArguments;
28
+ class Builtins;
29
+ } // namespace internal
30
+
31
+ namespace debug {
32
+ class ConsoleCallArguments;
33
+ } // namespace debug
34
+
35
+ namespace api_internal {
36
+ V8_EXPORT v8::Local<v8::Value> GetFunctionTemplateData(
37
+ v8::Isolate* isolate, v8::Local<v8::Data> raw_target);
38
+ } // namespace api_internal
39
+
40
+ template <typename T>
41
+ class ReturnValue {
42
+ public:
43
+ template <class S>
44
+ V8_INLINE ReturnValue(const ReturnValue<S>& that) : value_(that.value_) {
45
+ static_assert(std::is_base_of_v<T, S>, "type check");
46
+ }
47
+ // Handle-based setters.
48
+ template <typename S>
49
+ V8_INLINE void Set(const Global<S>& handle);
50
+ template <typename S>
51
+ V8_INLINE void SetNonEmpty(const Global<S>& handle);
52
+ template <typename S>
53
+ V8_INLINE void Set(const BasicTracedReference<S>& handle);
54
+ template <typename S>
55
+ V8_INLINE void SetNonEmpty(const BasicTracedReference<S>& handle);
56
+ template <typename S>
57
+ V8_INLINE void Set(const Local<S> handle);
58
+ template <typename S>
59
+ V8_INLINE void SetNonEmpty(const Local<S> handle);
60
+
61
+ // Fast primitive number setters.
62
+ V8_INLINE void Set(bool value);
63
+ V8_INLINE void Set(double i);
64
+ V8_INLINE void Set(int16_t i);
65
+ V8_INLINE void Set(int32_t i);
66
+ V8_INLINE void Set(int64_t i);
67
+ V8_INLINE void Set(uint16_t i);
68
+ V8_INLINE void Set(uint32_t i);
69
+ V8_INLINE void Set(uint64_t i);
70
+
71
+ // Fast JS primitive setters.
72
+ V8_INLINE void SetNull();
73
+ V8_INLINE void SetUndefined();
74
+ V8_INLINE void SetFalse();
75
+ V8_INLINE void SetEmptyString();
76
+
77
+ // Convenience getter for the Isolate.
78
+ V8_INLINE Isolate* GetIsolate() const;
79
+
80
+ // Pointer setter: Uncompilable to prevent inadvertent misuse.
81
+ template <typename S>
82
+ V8_INLINE void Set(S* whatever);
83
+
84
+ // Getter. Creates a new Local<> so it comes with a certain performance
85
+ // hit. If the ReturnValue was not yet set, this will return the undefined
86
+ // value.
87
+ V8_INLINE Local<Value> Get() const;
88
+
89
+ private:
90
+ template <class F>
91
+ friend class ReturnValue;
92
+ template <class F>
93
+ friend class FunctionCallbackInfo;
94
+ template <class F>
95
+ friend class PropertyCallbackInfo;
96
+ template <class F, class G, class H>
97
+ friend class PersistentValueMapBase;
98
+ V8_INLINE void SetInternal(internal::Address value);
99
+ // Default value depends on <T>:
100
+ // - <void> -> true_value,
101
+ // - <v8::Boolean> -> true_value,
102
+ // - <v8::Integer> -> 0,
103
+ // - <v8::Value> -> undefined_value,
104
+ // - <v8::Array> -> undefined_value.
105
+ V8_INLINE void SetDefaultValue();
106
+ V8_INLINE explicit ReturnValue(internal::Address* slot);
107
+
108
+ // See FunctionCallbackInfo.
109
+ static constexpr int kIsolateValueIndex = -1;
110
+
111
+ internal::Address* value_;
112
+ };
113
+
114
+ /**
115
+ * The argument information given to function call callbacks. This
116
+ * class provides access to information about the context of the call,
117
+ * including the receiver, the number and values of arguments, and
118
+ * the holder of the function.
119
+ */
120
+ template <typename T>
121
+ class FunctionCallbackInfo {
122
+ public:
123
+ /** The number of available arguments. */
124
+ V8_INLINE int Length() const;
125
+ /**
126
+ * Accessor for the available arguments. Returns `undefined` if the index
127
+ * is out of bounds.
128
+ */
129
+ V8_INLINE Local<Value> operator[](int i) const;
130
+ /** Returns the receiver. This corresponds to the "this" value. */
131
+ V8_INLINE Local<Object> This() const;
132
+ /** For construct calls, this returns the "new.target" value. */
133
+ V8_INLINE Local<Value> NewTarget() const;
134
+ /** Indicates whether this is a regular call or a construct call. */
135
+ V8_INLINE bool IsConstructCall() const;
136
+ /** The data argument specified when creating the callback. */
137
+ V8_INLINE Local<Value> Data() const;
138
+ /** The current Isolate. */
139
+ V8_INLINE Isolate* GetIsolate() const;
140
+ /** The ReturnValue for the call. */
141
+ V8_INLINE ReturnValue<T> GetReturnValue() const;
142
+
143
+ private:
144
+ friend class internal::FunctionCallbackArguments;
145
+ friend class internal::CustomArguments<FunctionCallbackInfo>;
146
+ friend class debug::ConsoleCallArguments;
147
+ friend void internal::PrintFunctionCallbackInfo(void*);
148
+ using I = internal::Internals;
149
+
150
+ // Frame block, matches the layout of ApiCallbackExitFrame.
151
+ // See ApiCallbackExitFrameConstants.
152
+ enum {
153
+ //
154
+ // Optional frame arguments block (exists only for API_CONSTRUCT_EXIT
155
+ // frame).
156
+
157
+ // Frame arguments block.
158
+ kNewTargetIndex = -1,
159
+
160
+ //
161
+ // Mandatory part, exists for both API_CALLBACK_EXIT and API_CONSTRUCT_EXIT
162
+ // frames.
163
+ //
164
+
165
+ // Frame arguments block.
166
+ kArgcIndex,
167
+
168
+ // Regular ExitFrame structure.
169
+ kFrameSPIndex,
170
+ kFrameTypeIndex,
171
+ kFrameConstantPoolIndex, // Optional, see I::kFrameCPSlotCount.
172
+ kFrameFPIndex = kFrameConstantPoolIndex + I::kFrameCPSlotCount,
173
+ kFramePCIndex,
174
+
175
+ // Api arguments block, starts at kFirstArgumentIndex.
176
+ kFirstApiArgumentIndex,
177
+ kIsolateIndex = kFirstApiArgumentIndex,
178
+ kReturnValueIndex,
179
+ kContextIndex,
180
+ kTargetIndex,
181
+
182
+ // JS args block, starts at kFrameFirstImplicitArgsIndex.
183
+ kReceiverIndex,
184
+ kFirstJSArgumentIndex,
185
+
186
+ // Mandatory part includes receiver.
187
+ kArgsLength = kReceiverIndex + 1,
188
+ // Optional part size (exists only for API_CONSTRUCT_EXIT frame).
189
+ kOptionalArgsLength = 1,
190
+
191
+ // The length of just Api arguments part.
192
+ kApiArgsLength = kReceiverIndex - kFirstApiArgumentIndex,
193
+ };
194
+
195
+ static_assert(kArgcIndex == 0);
196
+ static_assert(ReturnValue<Value>::kIsolateValueIndex ==
197
+ kIsolateIndex - kReturnValueIndex);
198
+
199
+ internal::Address* address_of_first_argument() const {
200
+ return &values_[kFirstJSArgumentIndex];
201
+ }
202
+
203
+ V8_INLINE FunctionCallbackInfo() = default;
204
+
205
+ // FunctionCallbackInfo object provides a view of the stack area where the
206
+ // data is stored and thus it's not supposed to be copyable/movable.
207
+ FunctionCallbackInfo(const FunctionCallbackInfo&) = delete;
208
+ FunctionCallbackInfo& operator=(const FunctionCallbackInfo&) = delete;
209
+ FunctionCallbackInfo(FunctionCallbackInfo&&) = delete;
210
+ FunctionCallbackInfo& operator=(FunctionCallbackInfo&&) = delete;
211
+
212
+ // Declare as mutable to let GC modify the contents of the slots even though
213
+ // it's not possible to change values via this class.
214
+ // Define the array size as 1 to make it clear that we are going to access
215
+ // it out-of-bounds from both sides anyway.
216
+ mutable internal::Address values_[1];
217
+ };
218
+
219
+ /**
220
+ * The information passed to a property callback about the context
221
+ * of the property access.
222
+ */
223
+ template <typename T>
224
+ class PropertyCallbackInfo {
225
+ public:
226
+ /**
227
+ * \return The isolate of the property access.
228
+ */
229
+ V8_INLINE Isolate* GetIsolate() const;
230
+
231
+ /**
232
+ * \return The data set in the configuration, i.e., in
233
+ * `NamedPropertyHandlerConfiguration` or
234
+ * `IndexedPropertyHandlerConfiguration.`
235
+ */
236
+ V8_INLINE Local<Value> Data() const;
237
+
238
+ /**
239
+ * \return The object in the prototype chain of the receiver that has the
240
+ * interceptor. Suppose you have `x` and its prototype is `y`, and `y`
241
+ * has an interceptor. Then `info.This()` is `x` and `info.Holder()` is `y`.
242
+ * In case the property is installed on the global object the Holder()
243
+ * would return the global proxy.
244
+ * TODO(http://crbug.com/333672197): rename back to Holder().
245
+ */
246
+ V8_INLINE Local<Object> HolderV2() const;
247
+
248
+ /**
249
+ * \return The return value of the callback.
250
+ * Can be changed by calling Set().
251
+ * \code
252
+ * info.GetReturnValue().Set(...)
253
+ * \endcode
254
+ *
255
+ */
256
+ V8_INLINE ReturnValue<T> GetReturnValue() const;
257
+
258
+ /**
259
+ * For [[Set]], [[DefineOwnProperty]] and [[Delete]] operations (i.e.
260
+ * for setter/definer/deleter callbacks) indicates whether TypeError
261
+ * should be thrown upon operation failure. The callback should throw
262
+ * TypeError only if it's necessary to provide more details than a default
263
+ * error thrown by V8 contains in this case.
264
+ *
265
+ * \return True if the intercepted function should throw if an error occurs.
266
+ * Usually, `true` corresponds to `'use strict'` execution mode.
267
+ *
268
+ * \note Always `false` when the operation was initiated by respecive
269
+ * `Reflect` call (i.e. `Reflect.set()`, `Reflect.defineProperty()` and
270
+ * `Reflect.deleteProperty()`).
271
+ */
272
+ V8_INLINE bool ShouldThrowOnError() const;
273
+
274
+ private:
275
+ template <typename U>
276
+ friend class PropertyCallbackInfo;
277
+ friend class MacroAssembler;
278
+ friend class internal::PropertyCallbackArguments;
279
+ friend class internal::CustomArguments<PropertyCallbackInfo>;
280
+ friend void internal::PrintPropertyCallbackInfo(void*);
281
+ using I = internal::Internals;
282
+
283
+ // ShouldThrowOnError() can return true only for setter/definer/deleter
284
+ // callbacks which match [[Set]]/[[DefineOwnProperty]]/[[Delete]]
285
+ // operations. We detect these operations by return value type - they
286
+ // all return boolean value, even though setter/deleter callbacks are
287
+ // still using v8::PropertyCallbackInfo<void>.
288
+ // TODO(https://crbug.com/348660658): cleanup this, once the callbacks are
289
+ // migrated to a new return type.
290
+ static constexpr bool HasShouldThrowOnError() {
291
+ return std::is_same_v<T, v8::Boolean> || std::is_same_v<T, void>;
292
+ }
293
+
294
+ // Indicates whether this is a named accessor/interceptor callback call
295
+ // or an indexed one.
296
+ V8_INLINE bool IsNamed() const;
297
+
298
+ // Frame block, matches the layout of ApiAccessorExitFrame.
299
+ // See ApiAccessorExitFrameConstants.
300
+ enum {
301
+ // Frame arguments block.
302
+ kPropertyKeyIndex,
303
+
304
+ // Regular ExitFrame structure.
305
+ kFrameSPIndex,
306
+ kFrameTypeIndex,
307
+ kFrameConstantPoolIndex, // Optional, see I::kFrameCPSlotCount.
308
+ kFrameFPIndex = kFrameConstantPoolIndex + I::kFrameCPSlotCount,
309
+ kFramePCIndex,
310
+
311
+ // Other arguments block, starts at kFirstArgumentIndex.
312
+ kFirstApiArgumentIndex,
313
+ kIsolateIndex = kFirstApiArgumentIndex,
314
+ kReturnValueIndex,
315
+ kCallbackInfoIndex,
316
+ kHolderIndex,
317
+
318
+ //
319
+ // Optional part, used only by setter/definer/deleter callbacks.
320
+ //
321
+ kFirstOptionalArgument,
322
+ kShouldThrowOnErrorIndex = kFirstOptionalArgument,
323
+
324
+ // Used as value handle storage when called via CallApiSetter builtin.
325
+ kValueIndex,
326
+
327
+ kFullArgsLength,
328
+ kMandatoryArgsLength = kFirstOptionalArgument,
329
+ kOptionalArgsLength = kFullArgsLength - kFirstOptionalArgument,
330
+
331
+ // Various lengths of just Api arguments part.
332
+ kMandatoryApiArgsLength = kMandatoryArgsLength - kFirstApiArgumentIndex,
333
+ kFullApiArgsLength = kFullArgsLength - kFirstApiArgumentIndex,
334
+ };
335
+
336
+ // PropertyCallbackInfo object provides a view of the stack area where the
337
+ // data is stored and thus it's not supposed to be copyable/movable.
338
+ PropertyCallbackInfo(const PropertyCallbackInfo&) = delete;
339
+ PropertyCallbackInfo& operator=(const PropertyCallbackInfo&) = delete;
340
+ PropertyCallbackInfo(PropertyCallbackInfo&&) = delete;
341
+ PropertyCallbackInfo& operator=(PropertyCallbackInfo&&) = delete;
342
+
343
+ PropertyCallbackInfo() = default;
344
+
345
+ // Declare as mutable to let GC modify the contents of the slots even though
346
+ // it's not possible to change values via this class.
347
+ // Define the array size as 1 to make it clear that we are going to access
348
+ // it out-of-bounds anyway.
349
+ mutable internal::Address args_[1];
350
+ };
351
+
352
+ using FunctionCallback = void (*)(const FunctionCallbackInfo<Value>& info);
353
+
354
+ // --- Implementation ---
355
+
356
+ template <typename T>
357
+ ReturnValue<T>::ReturnValue(internal::Address* slot) : value_(slot) {}
358
+
359
+ template <typename T>
360
+ void ReturnValue<T>::SetInternal(internal::Address value) {
361
+ #if V8_STATIC_ROOTS_BOOL
362
+ using I = internal::Internals;
363
+ // Ensure that the upper 32-bits are not modified. Compiler should be
364
+ // able to optimize this to a store of a lower 32-bits of the value.
365
+ // This is fine since the callback can return only JavaScript values which
366
+ // are either Smis or heap objects allocated in the main cage.
367
+ *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
368
+ #else
369
+ *value_ = value;
370
+ #endif // V8_STATIC_ROOTS_BOOL
371
+ }
372
+
373
+ template <typename T>
374
+ template <typename S>
375
+ void ReturnValue<T>::Set(const Global<S>& handle) {
376
+ static_assert(std::is_base_of_v<T, S>, "type check");
377
+ if (V8_UNLIKELY(handle.IsEmpty())) {
378
+ SetDefaultValue();
379
+ } else {
380
+ SetInternal(handle.ptr());
381
+ }
382
+ }
383
+
384
+ template <typename T>
385
+ template <typename S>
386
+ void ReturnValue<T>::SetNonEmpty(const Global<S>& handle) {
387
+ static_assert(std::is_base_of_v<T, S>, "type check");
388
+ #ifdef V8_ENABLE_CHECKS
389
+ internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
390
+ #endif // V8_ENABLE_CHECKS
391
+ SetInternal(handle.ptr());
392
+ }
393
+
394
+ template <typename T>
395
+ template <typename S>
396
+ void ReturnValue<T>::Set(const BasicTracedReference<S>& handle) {
397
+ static_assert(std::is_base_of_v<T, S>, "type check");
398
+ if (V8_UNLIKELY(handle.IsEmpty())) {
399
+ SetDefaultValue();
400
+ } else {
401
+ SetInternal(handle.ptr());
402
+ }
403
+ }
404
+
405
+ template <typename T>
406
+ template <typename S>
407
+ void ReturnValue<T>::SetNonEmpty(const BasicTracedReference<S>& handle) {
408
+ static_assert(std::is_base_of_v<T, S>, "type check");
409
+ #ifdef V8_ENABLE_CHECKS
410
+ internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
411
+ #endif // V8_ENABLE_CHECKS
412
+ SetInternal(handle.ptr());
413
+ }
414
+
415
+ template <typename T>
416
+ template <typename S>
417
+ void ReturnValue<T>::Set(const Local<S> handle) {
418
+ static_assert(std::is_base_of_v<T, S>, "type check");
419
+ if (V8_UNLIKELY(handle.IsEmpty())) {
420
+ SetDefaultValue();
421
+ } else {
422
+ SetInternal(handle.ptr());
423
+ }
424
+ }
425
+
426
+ template <typename T>
427
+ template <typename S>
428
+ void ReturnValue<T>::SetNonEmpty(const Local<S> handle) {
429
+ static_assert(std::is_base_of_v<T, S>, "type check");
430
+ #ifdef V8_ENABLE_CHECKS
431
+ internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
432
+ #endif // V8_ENABLE_CHECKS
433
+ SetInternal(handle.ptr());
434
+ }
435
+
436
+ template <typename T>
437
+ void ReturnValue<T>::Set(double i) {
438
+ static_assert(std::is_base_of_v<T, Number>, "type check");
439
+ SetNonEmpty(Number::New(GetIsolate(), i));
440
+ }
441
+
442
+ template <typename T>
443
+ void ReturnValue<T>::Set(int16_t i) {
444
+ static_assert(std::is_base_of_v<T, Integer>, "type check");
445
+ using I = internal::Internals;
446
+ static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
447
+ static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
448
+ SetInternal(I::IntegralToSmi(i));
449
+ }
450
+
451
+ template <typename T>
452
+ void ReturnValue<T>::Set(int32_t i) {
453
+ static_assert(std::is_base_of_v<T, Integer>, "type check");
454
+ if (const auto result = internal::Internals::TryIntegralToSmi(i)) {
455
+ SetInternal(*result);
456
+ return;
457
+ }
458
+ SetNonEmpty(Integer::New(GetIsolate(), i));
459
+ }
460
+
461
+ template <typename T>
462
+ void ReturnValue<T>::Set(int64_t i) {
463
+ static_assert(std::is_base_of_v<T, Integer>, "type check");
464
+ if (const auto result = internal::Internals::TryIntegralToSmi(i)) {
465
+ SetInternal(*result);
466
+ return;
467
+ }
468
+ SetNonEmpty(Number::New(GetIsolate(), static_cast<double>(i)));
469
+ }
470
+
471
+ template <typename T>
472
+ void ReturnValue<T>::Set(uint16_t i) {
473
+ static_assert(std::is_base_of_v<T, Integer>, "type check");
474
+ using I = internal::Internals;
475
+ static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
476
+ static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
477
+ SetInternal(I::IntegralToSmi(i));
478
+ }
479
+
480
+ template <typename T>
481
+ void ReturnValue<T>::Set(uint32_t i) {
482
+ static_assert(std::is_base_of_v<T, Integer>, "type check");
483
+ if (const auto result = internal::Internals::TryIntegralToSmi(i)) {
484
+ SetInternal(*result);
485
+ return;
486
+ }
487
+ SetNonEmpty(Integer::NewFromUnsigned(GetIsolate(), i));
488
+ }
489
+
490
+ template <typename T>
491
+ void ReturnValue<T>::Set(uint64_t i) {
492
+ static_assert(std::is_base_of_v<T, Integer>, "type check");
493
+ if (const auto result = internal::Internals::TryIntegralToSmi(i)) {
494
+ SetInternal(*result);
495
+ return;
496
+ }
497
+ SetNonEmpty(Number::New(GetIsolate(), static_cast<double>(i)));
498
+ }
499
+
500
+ template <typename T>
501
+ void ReturnValue<T>::Set(bool value) {
502
+ static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
503
+ "type check");
504
+ using I = internal::Internals;
505
+ #if V8_STATIC_ROOTS_BOOL
506
+ #ifdef V8_ENABLE_CHECKS
507
+ internal::PerformCastCheck(
508
+ internal::ValueHelper::SlotAsValue<Value, true>(value_));
509
+ #endif // V8_ENABLE_CHECKS
510
+ SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
511
+ : I::StaticReadOnlyRoot::kFalseValue);
512
+ #else
513
+ int root_index;
514
+ if (value) {
515
+ root_index = I::kTrueValueRootIndex;
516
+ } else {
517
+ root_index = I::kFalseValueRootIndex;
518
+ }
519
+ *value_ = I::GetRoot(GetIsolate(), root_index);
520
+ #endif // V8_STATIC_ROOTS_BOOL
521
+ }
522
+
523
+ template <typename T>
524
+ void ReturnValue<T>::SetDefaultValue() {
525
+ using I = internal::Internals;
526
+ if constexpr (std::is_same_v<void, T> || std::is_same_v<v8::Boolean, T>) {
527
+ Set(true);
528
+ } else if constexpr (std::is_same_v<v8::Integer, T>) {
529
+ SetInternal(I::IntegralToSmi(0));
530
+ } else {
531
+ static_assert(std::is_same_v<v8::Value, T> || std::is_same_v<v8::Array, T>);
532
+ #if V8_STATIC_ROOTS_BOOL
533
+ SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
534
+ #else
535
+ *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
536
+ #endif // V8_STATIC_ROOTS_BOOL
537
+ }
538
+ }
539
+
540
+ template <typename T>
541
+ void ReturnValue<T>::SetNull() {
542
+ static_assert(std::is_base_of_v<T, Primitive>, "type check");
543
+ using I = internal::Internals;
544
+ #if V8_STATIC_ROOTS_BOOL
545
+ #ifdef V8_ENABLE_CHECKS
546
+ internal::PerformCastCheck(
547
+ internal::ValueHelper::SlotAsValue<Value, true>(value_));
548
+ #endif // V8_ENABLE_CHECKS
549
+ SetInternal(I::StaticReadOnlyRoot::kNullValue);
550
+ #else
551
+ *value_ = I::GetRoot(GetIsolate(), I::kNullValueRootIndex);
552
+ #endif // V8_STATIC_ROOTS_BOOL
553
+ }
554
+
555
+ template <typename T>
556
+ void ReturnValue<T>::SetUndefined() {
557
+ static_assert(std::is_base_of_v<T, Primitive>, "type check");
558
+ using I = internal::Internals;
559
+ #if V8_STATIC_ROOTS_BOOL
560
+ #ifdef V8_ENABLE_CHECKS
561
+ internal::PerformCastCheck(
562
+ internal::ValueHelper::SlotAsValue<Value, true>(value_));
563
+ #endif // V8_ENABLE_CHECKS
564
+ SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
565
+ #else
566
+ *value_ = I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex);
567
+ #endif // V8_STATIC_ROOTS_BOOL
568
+ }
569
+
570
+ template <typename T>
571
+ void ReturnValue<T>::SetFalse() {
572
+ static_assert(std::is_void_v<T> || std::is_base_of_v<T, Boolean>,
573
+ "type check");
574
+ using I = internal::Internals;
575
+ #if V8_STATIC_ROOTS_BOOL
576
+ #ifdef V8_ENABLE_CHECKS
577
+ internal::PerformCastCheck(
578
+ internal::ValueHelper::SlotAsValue<Value, true>(value_));
579
+ #endif // V8_ENABLE_CHECKS
580
+ SetInternal(I::StaticReadOnlyRoot::kFalseValue);
581
+ #else
582
+ *value_ = I::GetRoot(GetIsolate(), I::kFalseValueRootIndex);
583
+ #endif // V8_STATIC_ROOTS_BOOL
584
+ }
585
+
586
+ template <typename T>
587
+ void ReturnValue<T>::SetEmptyString() {
588
+ static_assert(std::is_base_of_v<T, String>, "type check");
589
+ using I = internal::Internals;
590
+ #if V8_STATIC_ROOTS_BOOL
591
+ #ifdef V8_ENABLE_CHECKS
592
+ internal::PerformCastCheck(
593
+ internal::ValueHelper::SlotAsValue<Value, true>(value_));
594
+ #endif // V8_ENABLE_CHECKS
595
+ SetInternal(I::StaticReadOnlyRoot::kEmptyString);
596
+ #else
597
+ *value_ = I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
598
+ #endif // V8_STATIC_ROOTS_BOOL
599
+ }
600
+
601
+ template <typename T>
602
+ Isolate* ReturnValue<T>::GetIsolate() const {
603
+ return *reinterpret_cast<Isolate**>(&value_[kIsolateValueIndex]);
604
+ }
605
+
606
+ template <typename T>
607
+ Local<Value> ReturnValue<T>::Get() const {
608
+ return Local<Value>::New(GetIsolate(),
609
+ internal::ValueHelper::SlotAsValue<Value>(value_));
610
+ }
611
+
612
+ template <typename T>
613
+ template <typename S>
614
+ void ReturnValue<T>::Set(S* whatever) {
615
+ static_assert(sizeof(S) < 0, "incompilable to prevent inadvertent misuse");
616
+ }
617
+
618
+ template <typename T>
619
+ Local<Value> FunctionCallbackInfo<T>::operator[](int i) const {
620
+ if (i < 0 || Length() <= i) return Undefined(GetIsolate());
621
+ return Local<Value>::FromSlot(&values_[kFirstJSArgumentIndex + i]);
622
+ }
623
+
624
+ template <typename T>
625
+ Local<Object> FunctionCallbackInfo<T>::This() const {
626
+ return Local<Object>::FromSlot(&values_[kReceiverIndex]);
627
+ }
628
+
629
+ template <typename T>
630
+ Local<Value> FunctionCallbackInfo<T>::NewTarget() const {
631
+ if (IsConstructCall()) {
632
+ // Can't use &values_[kNewTargetIndex] because of "array index -1 is
633
+ // before the beginning of the array" error.
634
+ internal::Address* values = &values_[0];
635
+ return Local<Value>::FromSlot(values + kNewTargetIndex);
636
+ }
637
+ return Undefined(GetIsolate());
638
+ }
639
+
640
+ template <typename T>
641
+ Local<Value> FunctionCallbackInfo<T>::Data() const {
642
+ auto target = Local<v8::Data>::FromSlot(&values_[kTargetIndex]);
643
+ return api_internal::GetFunctionTemplateData(GetIsolate(), target);
644
+ }
645
+
646
+ template <typename T>
647
+ Isolate* FunctionCallbackInfo<T>::GetIsolate() const {
648
+ return reinterpret_cast<Isolate*>(values_[kIsolateIndex]);
649
+ }
650
+
651
+ template <typename T>
652
+ ReturnValue<T> FunctionCallbackInfo<T>::GetReturnValue() const {
653
+ return ReturnValue<T>(&values_[kReturnValueIndex]);
654
+ }
655
+
656
+ template <typename T>
657
+ bool FunctionCallbackInfo<T>::IsConstructCall() const {
658
+ return I::SmiValue(values_[kFrameTypeIndex]) == I::kFrameTypeApiConstructExit;
659
+ }
660
+
661
+ template <typename T>
662
+ int FunctionCallbackInfo<T>::Length() const {
663
+ return static_cast<int>(values_[kArgcIndex]);
664
+ }
665
+
666
+ template <typename T>
667
+ bool PropertyCallbackInfo<T>::IsNamed() const {
668
+ return I::SmiValue(args_[kFrameTypeIndex]) ==
669
+ I::kFrameTypeApiNamedAccessorExit;
670
+ }
671
+
672
+ template <typename T>
673
+ Isolate* PropertyCallbackInfo<T>::GetIsolate() const {
674
+ return *reinterpret_cast<Isolate**>(&args_[kIsolateIndex]);
675
+ }
676
+
677
+ template <typename T>
678
+ Local<Value> PropertyCallbackInfo<T>::Data() const {
679
+ internal::Address callback_info = args_[kCallbackInfoIndex];
680
+ internal::Address data =
681
+ I::ReadTaggedPointerField(callback_info, I::kCallbackInfoDataOffset);
682
+ return Local<Value>::New(GetIsolate(), data);
683
+ }
684
+
685
+ template <typename T>
686
+ Local<Object> PropertyCallbackInfo<T>::HolderV2() const {
687
+ return Local<Object>::FromSlot(&args_[kHolderIndex]);
688
+ }
689
+
690
+ template <typename T>
691
+ ReturnValue<T> PropertyCallbackInfo<T>::GetReturnValue() const {
692
+ return ReturnValue<T>(&args_[kReturnValueIndex]);
693
+ }
694
+
695
+ template <typename T>
696
+ bool PropertyCallbackInfo<T>::ShouldThrowOnError() const {
697
+ if constexpr (!HasShouldThrowOnError()) return false;
698
+ if (args_[kShouldThrowOnErrorIndex] !=
699
+ I::IntegralToSmi(I::kInferShouldThrowMode)) {
700
+ return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I::kDontThrow);
701
+ }
702
+ return v8::internal::ShouldThrowOnError(
703
+ reinterpret_cast<v8::internal::Isolate*>(GetIsolate()));
704
+ }
705
+
706
+ } // namespace v8
707
+
708
+ #endif // INCLUDE_V8_FUNCTION_CALLBACK_H_