5#ifndef INCLUDE_V8_FUNCTION_CALLBACK_H_
6#define INCLUDE_V8_FUNCTION_CALLBACK_H_
26class FunctionCallbackArguments;
27class PropertyCallbackArguments;
32class ConsoleCallArguments;
45 static_assert(std::is_base_of_v<T, S>,
"type check");
93 template <
class F,
class G,
class H>
106 static constexpr int kIsolateValueIndex = -2;
112
113
114
115
116
123
124
125
143 friend class debug::ConsoleCallArguments;
149 static constexpr int kUnusedIndex = 0;
150 static constexpr int kIsolateIndex = 1;
151 static constexpr int kContextIndex = 2;
152 static constexpr int kReturnValueIndex = 3;
153 static constexpr int kTargetIndex = 4;
154 static constexpr int kNewTargetIndex = 5;
155 static constexpr int kArgsLength = 6;
157 static constexpr int kArgsLengthWithReceiver = kArgsLength + 1;
161 static constexpr int kImplicitArgsOffset = 0;
162 static constexpr int kValuesOffset =
164 static constexpr int kLengthOffset =
167 static constexpr int kThisValuesIndex = -1;
183
184
185
190
191
195
196
197
198
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
245
246
247
248
249
250
251
252
254 "V8 will stop providing access to hidden prototype (i.e. "
255 "JSGlobalObject). Use HolderV2() instead. \n"
256 "DO NOT try to workaround this by accessing JSGlobalObject via "
257 "v8::Object::GetPrototype() - it'll be deprecated soon too. \n"
258 "See http://crbug.com/333672197. ")
262
263
264
265
266
267
271
272
273
274
275
276
277
281
282
283
284
285
286
290 template <
typename U>
292 friend class MacroAssembler;
297 static constexpr int kPropertyKeyIndex = 0;
298 static constexpr int kShouldThrowOnErrorIndex = 1;
299 static constexpr int kHolderIndex = 2;
300 static constexpr int kIsolateIndex = 3;
301 static constexpr int kHolderV2Index = 4;
302 static constexpr int kReturnValueIndex = 5;
303 static constexpr int kDataIndex = 6;
304 static constexpr int kThisIndex = 7;
305 static constexpr int kArgsLength = 8;
309 PropertyCallbackInfo() =
default;
324 using I = internal::Internals;
329 *value_ = I::DecompressTaggedField(*value_, I::CompressTagged(value));
338 static_assert(std::is_base_of_v<T, S>,
"type check");
342 SetInternal(handle.ptr());
349 static_assert(std::is_base_of_v<T, S>,
"type check");
350#ifdef V8_ENABLE_CHECKS
351 internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
353 SetInternal(handle.ptr());
359 static_assert(std::is_base_of_v<T, S>,
"type check");
363 SetInternal(handle.ptr());
370 static_assert(std::is_base_of_v<T, S>,
"type check");
371#ifdef V8_ENABLE_CHECKS
372 internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
374 SetInternal(handle.ptr());
381#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
382 static constexpr bool is_allowed_void =
false;
383 static_assert(!std::is_void_v<T>,
384 "ReturnValue<void>::Set(const Local<S>) is deprecated. "
385 "Do nothing to indicate that the operation succeeded or use "
386 "SetFalse() to indicate that the operation failed (don't "
387 "forget to handle info.ShouldThrowOnError()). "
388 "See http://crbug.com/348660658 for details.");
390 static constexpr bool is_allowed_void = std::is_void_v<T>;
392 static_assert(is_allowed_void || std::is_base_of_v<T, S>,
"type check");
395 }
else if constexpr (is_allowed_void) {
400 SetInternal(handle.ptr());
408#ifdef V8_IMMINENT_DEPRECATION_WARNINGS
409 static constexpr bool is_allowed_void =
false;
410 static_assert(!std::is_void_v<T>,
411 "ReturnValue<void>::SetNonEmpty(const Local<S>) is deprecated. "
412 "Do nothing to indicate that the operation succeeded or use "
413 "SetFalse() to indicate that the operation failed (don't "
414 "forget to handle info.ShouldThrowOnError()). "
415 "See http://crbug.com/348660658 for details.");
417 static constexpr bool is_allowed_void = std::is_void_v<T>;
419 static_assert(is_allowed_void || std::is_base_of_v<T, S>,
"type check");
420#ifdef V8_ENABLE_CHECKS
421 internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
423 if constexpr (is_allowed_void) {
428 SetInternal(handle.ptr());
434 static_assert(std::is_base_of_v<T,
Number>,
"type check");
440 static_assert(std::is_base_of_v<T,
Integer>,
"type check");
442 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::min()));
443 static_assert(I::IsValidSmi(std::numeric_limits<int16_t>::max()));
444 SetInternal(I::IntegralToSmi(i));
449 static_assert(std::is_base_of_v<T,
Integer>,
"type check");
450 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
451 SetInternal(*result);
459 static_assert(std::is_base_of_v<T,
Integer>,
"type check");
460 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
461 SetInternal(*result);
469 static_assert(std::is_base_of_v<T,
Integer>,
"type check");
471 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
472 static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
473 SetInternal(I::IntegralToSmi(i));
478 static_assert(std::is_base_of_v<T,
Integer>,
"type check");
479 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
480 SetInternal(*result);
488 static_assert(std::is_base_of_v<T,
Integer>,
"type check");
489 if (
const auto result = internal::Internals::TryIntegralToSmi(i)) {
490 SetInternal(*result);
498 static_assert(std::is_void_v<T> || std::is_base_of_v<T,
Boolean>,
502#ifdef V8_ENABLE_CHECKS
503 internal::PerformCastCheck(
504 internal::ValueHelper::SlotAsValue<Value,
true>(value_));
506 SetInternal(value ? I::StaticReadOnlyRoot::kTrueValue
507 : I::StaticReadOnlyRoot::kFalseValue);
522 if constexpr (std::is_same_v<
void, T> || std::is_same_v<
v8::
Boolean, T>) {
524 }
else if constexpr (std::is_same_v<
v8::
Integer, T>) {
525 SetInternal(I::IntegralToSmi(0));
527 static_assert(std::is_same_v<
v8::
Value, T> || std::is_same_v<
v8::
Array, T>);
529 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
538 static_assert(std::is_base_of_v<T,
Primitive>,
"type check");
541#ifdef V8_ENABLE_CHECKS
542 internal::PerformCastCheck(
543 internal::ValueHelper::SlotAsValue<Value,
true>(value_));
545 SetInternal(I::StaticReadOnlyRoot::kNullValue);
553 static_assert(std::is_base_of_v<T,
Primitive>,
"type check");
556#ifdef V8_ENABLE_CHECKS
557 internal::PerformCastCheck(
558 internal::ValueHelper::SlotAsValue<Value,
true>(value_));
560 SetInternal(I::StaticReadOnlyRoot::kUndefinedValue);
568 static_assert(std::is_void_v<T> || std::is_base_of_v<T,
Boolean>,
572#ifdef V8_ENABLE_CHECKS
573 internal::PerformCastCheck(
574 internal::ValueHelper::SlotAsValue<Value,
true>(value_));
576 SetInternal(I::StaticReadOnlyRoot::kFalseValue);
584 static_assert(std::is_base_of_v<T,
String>,
"type check");
587#ifdef V8_ENABLE_CHECKS
588 internal::PerformCastCheck(
589 internal::ValueHelper::SlotAsValue<Value,
true>(value_));
591 SetInternal(I::StaticReadOnlyRoot::kEmptyString);
599 return *
reinterpret_cast<
Isolate**>(&value_[kIsolateValueIndex]);
604 return Local<Value>::New(GetIsolate(),
605 internal::ValueHelper::SlotAsValue<Value>(value_));
611 static_assert(
sizeof(S) < 0,
"incompilable to prevent inadvertent misuse");
618 : implicit_args_(implicit_args), values_(values), length_(length) {}
623 if (i < 0 || Length() <= i)
return Undefined(GetIsolate());
624 return Local<Value>::FromSlot(values_ + i);
630 return Local<Object>::FromSlot(values_ + kThisValuesIndex);
635 return Local<Value>::FromSlot(&implicit_args_[kNewTargetIndex]);
640 auto target = Local<v8::Data>::FromSlot(&implicit_args_[kTargetIndex]);
646 return *
reinterpret_cast<
Isolate**>(&implicit_args_[kIsolateIndex]);
651 return ReturnValue<T>(&implicit_args_[kReturnValueIndex]);
656 return !NewTarget()->IsUndefined();
661 return static_cast<
int>(length_);
666 return *
reinterpret_cast<
Isolate**>(&args_[kIsolateIndex]);
671 return Local<Value>::FromSlot(&args_[kDataIndex]);
676 return Local<Object>::FromSlot(&args_[kThisIndex]);
681 return Local<Object>::FromSlot(&args_[kHolderIndex]);
695 args_[kHolderV2Index] =
696 api_internal::ConvertToJSGlobalProxyIfNecessary(args_[kHolderIndex]);
698 return Local<Object>::FromSlot(&args_[kHolderV2Index]);
709 if (args_[kShouldThrowOnErrorIndex] !=
711 return args_[kShouldThrowOnErrorIndex] != I::IntegralToSmi(I
::kDontThrow);
friend class BasicTracedReference
V8_INLINE ReturnValue< T > GetReturnValue() const
V8_INLINE bool IsConstructCall() const
V8_INLINE Local< Object > This() const
V8_INLINE Isolate * GetIsolate() const
V8_INLINE Local< Value > Data() const
V8_INLINE int Length() const
V8_INLINE Local< Value > NewTarget() const
V8_INLINE Local< Value > operator[](int i) const
friend void internal::PrintFunctionCallbackInfo(void *)
static Local< Integer > New(Isolate *isolate, int32_t value)
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
friend class internal::CustomArguments
static Local< Number > New(Isolate *isolate, double value)
V8_INLINE ReturnValue< T > GetReturnValue() const
V8_INLINE Local< Object > This() const
V8_INLINE Isolate * GetIsolate() const
V8_INLINE Local< Value > Data() const
V8_INLINE bool ShouldThrowOnError() const
friend void internal::PrintPropertyCallbackInfo(void *)
V8_INLINE Local< Object > HolderV2() const
friend class PersistentValueMapBase
V8_INLINE ReturnValue(const ReturnValue< S > &that)
V8_INLINE Isolate * GetIsolate() const
V8_INLINE void SetFalse()
V8_INLINE void SetNonEmpty(const Local< S > handle)
V8_INLINE void Set(int16_t i)
V8_INLINE void Set(const BasicTracedReference< S > &handle)
friend class FunctionCallbackInfo
V8_INLINE void SetUndefined()
V8_INLINE void Set(uint16_t i)
V8_INLINE void SetNonEmpty(const Global< S > &handle)
V8_INLINE void Set(const Global< S > &handle)
V8_INLINE void Set(int32_t i)
V8_INLINE void SetEmptyString()
V8_INLINE void SetNonEmpty(const BasicTracedReference< S > &handle)
V8_INLINE void Set(bool value)
V8_INLINE void Set(const Local< S > handle)
V8_INLINE void Set(uint64_t i)
V8_INLINE void Set(uint32_t i)
V8_INLINE void Set(S *whatever)
V8_INLINE void Set(int64_t i)
V8_INLINE void Set(double i)
V8_INLINE Local< Value > Get() const
static const int kTrueValueRootIndex
static const int kInferShouldThrowMode
static const int kFalseValueRootIndex
static const int kNullValueRootIndex
static const int kDontThrow
static const int kEmptyStringRootIndex
static const int kUndefinedValueRootIndex
static V8_INLINE constexpr bool HasHeapObjectTag(Address value)
static V8_INLINE Address GetRoot(v8::Isolate *isolate, int index)
V8_EXPORT v8::Local< v8::Value > GetFunctionTemplateData(v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
const int kApiSystemPointerSize
V8_DEPRECATE_SOON("Use GetCurrentIsolate() instead, which is guaranteed to return the same " "isolate since https://crrev.com/c/6458560.") V8_EXPORT internal V8_EXPORT bool ShouldThrowOnError(internal::Isolate *isolate)
#define V8_STATIC_ROOTS_BOOL
#define V8_DEPRECATED(message)
#define V8_UNLIKELY(condition)