19#define CHECK_SELF_OR_THROW_FAST_OPTIONS(return_value) \
21 HandleScope handle_scope(options.isolate); \
22 options.isolate->ThrowError( \
23 "This method is not defined on objects inheriting from FastCAPI."); \
24 return return_value; \
27#define CHECK_SELF_OR_THROW_FAST(return_value) \
29 receiver->GetIsolate()->ThrowError( \
30 "This method is not defined on objects inheriting from FastCAPI."); \
31 return return_value; \
34#define CHECK_SELF_OR_THROW_SLOW() \
36 info.GetIsolate()->ThrowError( \
37 "This method is not defined on objects inheriting from FastCAPI."); \
43 static FastCApiObject& instance();
45#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
46 static AnyCType ThrowNoFallbackFastCallbackPatch(AnyCType
receiver) {
48 ThrowNoFallbackFastCallback(
receiver.object_value);
54 static int ThrowNoFallbackFastCallback(Local<Object>
receiver) {
55 FastCApiObject* self = UnwrapObject(
receiver);
57 self = &FastCApiObject::instance();
59 self->fast_call_count_++;
64 isolate->ThrowError(
"Exception from fast callback");
68 static void ThrowFallbackSlowCallback(
69 const FunctionCallbackInfo<Value>& info) {
71 FastCApiObject* self = UnwrapObject(info.This());
73 self->slow_call_count_++;
75 info.GetIsolate()->ThrowError(
"Exception from slow callback");
78#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
79 static AnyCType CopyStringFastCallbackPatch(AnyCType
receiver,
80 AnyCType source, AnyCType out,
83 CopyStringFastCallback(
receiver.object_value, *source.string_value,
84 out.object_value, *options.options_value);
89 static void CopyStringFastCallback(Local<Object>
receiver,
90 const FastOneByteString& source,
92 FastApiCallbackOptions& options) {
93 FastCApiObject* self = UnwrapObject(
receiver);
94 self->fast_call_count_++;
96 HandleScope handle_scope(options.isolate);
97 if (!out->IsUint8Array()) {
98 options.isolate->ThrowError(
99 "Invalid parameter, the second parameter has to be a a Uint8Array.");
102 Local<Uint8Array> array = out.As<Uint8Array>();
103 if (array->Length() < source.length) {
104 options.isolate->ThrowError(
105 "Invalid parameter, destination array is too small.");
109 reinterpret_cast<uint8_t*
>(out.As<Uint8Array>()->Buffer()->Data());
110 memcpy(memory, source.data, source.length);
113 static void CopyStringSlowCallback(
const FunctionCallbackInfo<Value>& info) {
114 FastCApiObject* self = UnwrapObject(info.This());
116 self->slow_call_count_++;
118#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
119 static AnyCType AddAllFastCallbackPatch(AnyCType
receiver,
120 AnyCType arg_i32, AnyCType arg_u32,
121 AnyCType arg_i64, AnyCType arg_u64,
122 AnyCType arg_f32, AnyCType arg_f64,
125 ret.double_value = AddAllFastCallback(
126 receiver.object_value, arg_i32.int32_value, arg_u32.uint32_value,
127 arg_i64.int64_value, arg_u64.uint64_value, arg_f32.float_value,
128 arg_f64.double_value, *options.options_value);
133 static double AddAllFastCallback(Local<Object>
receiver, int32_t arg_i32,
134 uint32_t arg_u32, int64_t arg_i64,
135 uint64_t arg_u64,
float arg_f32,
137 FastApiCallbackOptions& options) {
138 FastCApiObject* self = UnwrapObject(
receiver);
140 self->fast_call_count_++;
142 return static_cast<double>(arg_i32) +
static_cast<double>(arg_u32) +
143 static_cast<double>(arg_i64) +
static_cast<double>(arg_u64) +
144 static_cast<double>(arg_f32) + arg_f64;
147#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
148 static AnyCType AddAllFastCallbackNoOptionsPatch(
149 AnyCType
receiver, AnyCType arg_i32, AnyCType arg_u32, AnyCType arg_i64,
150 AnyCType arg_u64, AnyCType arg_f32, AnyCType arg_f64) {
152 ret.double_value = AddAllFastCallbackNoOptions(
153 receiver.object_value, arg_i32.int32_value, arg_u32.uint32_value,
154 arg_i64.int64_value, arg_u64.uint64_value, arg_f32.float_value,
155 arg_f64.double_value);
159 static double AddAllFastCallbackNoOptions(Local<Object>
receiver,
160 int32_t arg_i32, uint32_t arg_u32,
161 int64_t arg_i64, uint64_t arg_u64,
162 float arg_f32,
double arg_f64) {
163 FastCApiObject* self = UnwrapObject(
receiver);
165 self = &FastCApiObject::instance();
167 self->fast_call_count_++;
169 return static_cast<double>(arg_i32) +
static_cast<double>(arg_u32) +
170 static_cast<double>(arg_i64) +
static_cast<double>(arg_u64) +
171 static_cast<double>(arg_f32) + arg_f64;
174 static void AddAllSlowCallback(
const FunctionCallbackInfo<Value>& info) {
175 Isolate* isolate = info.GetIsolate();
177 FastCApiObject* self = UnwrapObject(info.This());
179 self->slow_call_count_++;
181 HandleScope handle_scope(isolate);
184 if (info.Length() > 0 && info[0]->IsNumber()) {
185 sum += info[0]->Int32Value(isolate->GetCurrentContext()).FromJust();
187 if (info.Length() > 1 && info[1]->IsNumber()) {
188 sum += info[1]->Uint32Value(isolate->GetCurrentContext()).FromJust();
190 if (info.Length() > 2 && info[2]->IsNumber()) {
191 sum += info[2]->IntegerValue(isolate->GetCurrentContext()).FromJust();
193 if (info.Length() > 3 && info[3]->IsNumber()) {
194 sum += info[3]->IntegerValue(isolate->GetCurrentContext()).FromJust();
196 if (info.Length() > 4 && info[4]->IsNumber()) {
197 sum += info[4]->NumberValue(isolate->GetCurrentContext()).FromJust();
199 sum += std::numeric_limits<double>::quiet_NaN();
201 if (info.Length() > 5 && info[5]->IsNumber()) {
202 sum += info[5]->NumberValue(isolate->GetCurrentContext()).FromJust();
204 sum += std::numeric_limits<double>::quiet_NaN();
207 info.GetReturnValue().Set(
Number::New(isolate, sum));
210#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
213 typedef int32_t Type;
215#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
216 static AnyCType AddAllSequenceFastCallbackPatch(AnyCType
receiver,
220#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
221 ret.double_value = AddAllSequenceFastCallback(
222 receiver.object_value, seq_arg.sequence_value, *options.options_value);
224 ret.int32_value = AddAllSequenceFastCallback(
225 receiver.object_value, seq_arg.sequence_value, *options.options_value);
231 static Type AddAllSequenceJSArrayHelper(
v8::Isolate* isolate,
232 Local<Array> seq_arg) {
234 uint32_t length = seq_arg->Length();
237 "Invalid length of array, must be between 0 and 1024.");
243 seq_arg->Get(isolate->GetCurrentContext(),
245 if (maybe_element.
IsEmpty())
return sum;
248 if (element->IsNumber()) {
249 double value = element->ToNumber(isolate->GetCurrentContext())
253 }
else if (element->IsUndefined()) {
256 isolate->ThrowError(
"unexpected element type in JSArray");
263 static Type AddAllSequenceFastCallback(Local<Object>
receiver,
264 Local<Object> seq_arg,
265 FastApiCallbackOptions& options) {
266 if (seq_arg->IsUint32Array()) {
267 return AddAllTypedArrayFastCallback<uint32_t>(
receiver, seq_arg, options);
270 FastCApiObject* self = UnwrapObject(
receiver);
272 self->fast_call_count_++;
274 HandleScope handle_scope(options.isolate);
275 if (!seq_arg->IsArray()) {
276 options.isolate->ThrowError(
277 "This method expects an array as a first argument.");
280 Local<Array> array = seq_arg.As<Array>();
281 uint32_t length = array->Length();
284 "Invalid length of array, must be between 0 and 1024.");
292 return AddAllSequenceJSArrayHelper(
receiver->GetIsolate(), array);
304 static void AddAllSequenceSlowCallback(
305 const FunctionCallbackInfo<Value>& info) {
307 Isolate* isolate = info.GetIsolate();
309 FastCApiObject* self = UnwrapObject(info.This());
312 HandleScope handle_scope(isolate);
314 if (info.Length() < 1) {
315 self->slow_call_count_++;
316 isolate->ThrowError(
"This method expects at least 1 arguments.");
319 if (info[0]->IsTypedArray()) {
320 AddAllTypedArraySlowCallback(info);
323 if (info[0]->IsNumber()) {
324 AddAllSlowCallback(info);
327 self->slow_call_count_++;
328 if (info[0]->IsUndefined()) {
329 Type dummy_result = 0;
330 info.GetReturnValue().Set(
Number::New(isolate, dummy_result));
333 if (!info[0]->IsArray()) {
334 isolate->ThrowError(
"This method expects an array as a first argument.");
337 Local<Array> seq_arg = info[0].As<Array>();
338 Type sum = AddAllSequenceJSArrayHelper(isolate, seq_arg);
340 info.GetReturnValue().Set(
Number::New(isolate, sum));
342#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
344 template <
typename T>
345 static AnyCType AddAllTypedArrayFastCallbackPatch(AnyCType
receiver,
346 AnyCType typed_array_arg,
349#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
350 ret.double_value = AddAllTypedArrayFastCallback<T>(
351 receiver.object_value, typed_array_arg.object_value,
352 *options.options_value);
354 ret.int32_value = AddAllTypedArrayFastCallback<T>(
355 receiver.object_value, typed_array_arg.object_value,
356 *options.options_value);
361 template <
typename T>
362 static Type AddAllTypedArrayFastCallback(Local<Object>
receiver,
363 Local<Value> typed_array_arg,
364 FastApiCallbackOptions& options) {
365 FastCApiObject* self = UnwrapObject(
receiver);
367 self->fast_call_count_++;
369 HandleScope handle_scope(options.isolate);
370 if (!typed_array_arg->IsTypedArray()) {
371 options.isolate->ThrowError(
372 "This method expects a TypedArray as a first argument.");
375 T* memory =
reinterpret_cast<T*
>(
376 typed_array_arg.As<TypedArray>()->Buffer()->Data());
377 size_t length = typed_array_arg.As<TypedArray>()->ByteLength() /
sizeof(
T);
380 sum +=
static_cast<double>(memory[
i]);
382 return static_cast<Type
>(sum);
385 static void AddAllTypedArraySlowCallback(
386 const FunctionCallbackInfo<Value>& info) {
388 Isolate* isolate = info.GetIsolate();
390 FastCApiObject* self = UnwrapObject(info.This());
392 self->slow_call_count_++;
394 HandleScope handle_scope(isolate);
396 if (info.Length() < 1) {
397 isolate->ThrowError(
"This method expects at least 1 arguments.");
400 if (!info[0]->IsTypedArray()) {
402 "This method expects a TypedArray as a second argument.");
406 Local<TypedArray> typed_array_arg = info[0].As<TypedArray>();
407 size_t length = typed_array_arg->Length();
409 void* data = typed_array_arg->Buffer()->GetBackingStore()->Data();
410 if (typed_array_arg->IsUint8Array() || typed_array_arg->IsInt32Array() ||
411 typed_array_arg->IsUint32Array() ||
412 typed_array_arg->IsBigInt64Array() ||
413 typed_array_arg->IsBigUint64Array()) {
416 if (typed_array_arg->IsUint8Array()) {
417 sum +=
static_cast<uint8_t*
>(
data)[
i];
418 }
else if (typed_array_arg->IsInt32Array()) {
419 sum +=
static_cast<int32_t*
>(
data)[
i];
420 }
else if (typed_array_arg->IsUint32Array()) {
421 sum +=
static_cast<uint32_t*
>(
data)[
i];
422 }
else if (typed_array_arg->IsBigInt64Array()) {
423 sum +=
static_cast<int64_t*
>(
data)[
i];
424 }
else if (typed_array_arg->IsBigUint64Array()) {
425 sum +=
static_cast<uint64_t*
>(
data)[
i];
428 info.GetReturnValue().Set(
Number::New(isolate, sum));
429 }
else if (typed_array_arg->IsFloat32Array() ||
430 typed_array_arg->IsFloat64Array()) {
433 if (typed_array_arg->IsFloat32Array()) {
434 sum +=
static_cast<float*
>(
data)[
i];
435 }
else if (typed_array_arg->IsFloat64Array()) {
436 sum +=
static_cast<double*
>(
data)[
i];
439 info.GetReturnValue().Set(
Number::New(isolate, sum));
441 isolate->ThrowError(
"TypedArray type is not supported.");
446#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
447 static AnyCType Add32BitIntFastCallbackPatch(AnyCType
receiver,
453 Add32BitIntFastCallback(
receiver.object_value, arg_i32.int32_value,
454 arg_u32.uint32_value, *options.options_value);
460 int32_t arg_i32, uint32_t arg_u32,
461 FastApiCallbackOptions& options) {
462 FastCApiObject* self = UnwrapObject(
receiver);
464 self->fast_call_count_++;
466 return arg_i32 + arg_u32;
468 static void Add32BitIntSlowCallback(
const FunctionCallbackInfo<Value>& info) {
470 Isolate* isolate = info.GetIsolate();
472 FastCApiObject* self = UnwrapObject(info.This());
474 self->slow_call_count_++;
476 HandleScope handle_scope(isolate);
479 if (info.Length() > 0 && info[0]->IsNumber()) {
480 sum += info[0]->Int32Value(isolate->GetCurrentContext()).FromJust();
482 if (info.Length() > 1 && info[1]->IsNumber()) {
483 sum += info[1]->Uint32Value(isolate->GetCurrentContext()).FromJust();
486 info.GetReturnValue().Set(
Number::New(isolate, sum));
489#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
490 static AnyCType AddAll32BitIntFastCallback_8ArgsPatch(
491 AnyCType
receiver, AnyCType arg1_i32, AnyCType arg2_i32,
492 AnyCType arg3_i32, AnyCType arg4_u32, AnyCType arg5_u32,
493 AnyCType arg6_u32, AnyCType arg7_u32, AnyCType arg8_u32,
496 ret.int32_value = AddAll32BitIntFastCallback_8Args(
497 receiver.object_value, arg1_i32.int32_value, arg2_i32.int32_value,
498 arg3_i32.int32_value, arg4_u32.uint32_value, arg5_u32.uint32_value,
499 arg6_u32.uint32_value, arg7_u32.uint32_value, arg8_u32.uint32_value,
500 *options.options_value);
503 static AnyCType AddAll32BitIntFastCallback_6ArgsPatch(
504 AnyCType
receiver, AnyCType arg1_i32, AnyCType arg2_i32,
505 AnyCType arg3_i32, AnyCType arg4_u32, AnyCType arg5_u32,
506 AnyCType arg6_u32, AnyCType options) {
508 ret.int32_value = AddAll32BitIntFastCallback_6Args(
509 receiver.object_value, arg1_i32.int32_value, arg2_i32.int32_value,
510 arg3_i32.int32_value, arg4_u32.uint32_value, arg5_u32.uint32_value,
511 arg6_u32.uint32_value, *options.options_value);
514 static AnyCType AddAll32BitIntFastCallback_5ArgsPatch(
515 AnyCType
receiver, AnyCType arg1_i32, AnyCType arg2_i32,
516 AnyCType arg3_i32, AnyCType arg4_u32, AnyCType arg5_u32,
519 arg6.uint32_value = 0;
520 return AddAll32BitIntFastCallback_6ArgsPatch(
receiver, arg1_i32, arg2_i32,
521 arg3_i32, arg4_u32, arg5_u32,
526 static int AddAll32BitIntFastCallback_8Args(
527 Local<Object>
receiver, int32_t arg1_i32, int32_t arg2_i32,
528 int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32, uint32_t arg6_u32,
529 uint32_t arg7_u32, uint32_t arg8_u32, FastApiCallbackOptions& options) {
530 FastCApiObject* self = UnwrapObject(
receiver);
532 self->fast_call_count_++;
534 int64_t
result =
static_cast<int64_t
>(arg1_i32) + arg2_i32 + arg3_i32 +
535 arg4_u32 + arg5_u32 + arg6_u32 + arg7_u32 + arg8_u32;
536 if (
result > INT_MAX)
return INT_MAX;
537 if (
result < INT_MIN)
return INT_MIN;
538 return static_cast<int>(
result);
540 static int AddAll32BitIntFastCallback_6Args(
541 Local<Object>
receiver, int32_t arg1_i32, int32_t arg2_i32,
542 int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32, uint32_t arg6_u32,
543 FastApiCallbackOptions& options) {
544 FastCApiObject* self = UnwrapObject(
receiver);
546 self->fast_call_count_++;
548 int64_t
result =
static_cast<int64_t
>(arg1_i32) + arg2_i32 + arg3_i32 +
549 arg4_u32 + arg5_u32 + arg6_u32;
550 if (
result > INT_MAX)
return INT_MAX;
551 if (
result < INT_MIN)
return INT_MIN;
552 return static_cast<int>(
result);
554 static int AddAll32BitIntFastCallback_5Args(
555 Local<Object>
receiver, int32_t arg1_i32, int32_t arg2_i32,
556 int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32,
557 FastApiCallbackOptions& options) {
558 return AddAll32BitIntFastCallback_6Args(
559 receiver, arg1_i32, arg2_i32, arg3_i32, arg4_u32, arg5_u32, 0, options);
561 static void AddAll32BitIntSlowCallback(
562 const FunctionCallbackInfo<Value>& info) {
564 Isolate* isolate = info.GetIsolate();
566 FastCApiObject* self = UnwrapObject(info.This());
568 self->slow_call_count_++;
570 HandleScope handle_scope(isolate);
572 Local<Context> context = isolate->GetCurrentContext();
574 if (info.Length() > 0 && info[0]->IsNumber()) {
575 sum += info[0]->Int32Value(context).FromJust();
577 if (info.Length() > 1 && info[1]->IsNumber()) {
578 sum += info[1]->Int32Value(context).FromJust();
580 if (info.Length() > 2 && info[2]->IsNumber()) {
581 sum += info[2]->Int32Value(context).FromJust();
583 if (info.Length() > 3 && info[3]->IsNumber()) {
584 sum += info[3]->Uint32Value(context).FromJust();
586 if (info.Length() > 4 && info[4]->IsNumber()) {
587 sum += info[4]->Uint32Value(context).FromJust();
589 if (info.Length() > 5 && info[5]->IsNumber()) {
590 sum += info[5]->Uint32Value(context).FromJust();
592 if (info.Length() > 7 && info[6]->IsNumber() && info[7]->IsNumber()) {
596 sum += info[6]->Uint32Value(context).FromJust();
597 sum += info[7]->Uint32Value(context).FromJust();
600 info.GetReturnValue().Set(
Number::New(isolate, sum));
603#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
604 template <v8::CTypeInfo::Flags flags>
605 static AnyCType AddAllAnnotateFastCallbackPatch(
606 AnyCType
receiver, AnyCType arg_i32, AnyCType arg_u32, AnyCType arg_i64,
607 AnyCType arg_u64, AnyCType options) {
609 ret.double_value = AddAllAnnotateFastCallback<flags>(
610 receiver.object_value, arg_i32.int32_value, arg_u32.uint32_value,
611 arg_i64.int64_value, arg_u64.uint64_value, *options.options_value);
616 template <v8::CTypeInfo::Flags flags>
617 static double AddAllAnnotateFastCallback(Local<Object>
receiver,
618 int32_t arg_i32, uint32_t arg_u32,
619 int64_t arg_i64, uint64_t arg_u64,
620 FastApiCallbackOptions& options) {
621 FastCApiObject* self = UnwrapObject(
receiver);
623 self->fast_call_count_++;
625 return static_cast<double>(arg_i32) +
static_cast<double>(arg_u32) +
626 static_cast<double>(arg_i64) +
static_cast<double>(arg_u64);
629 static void AddAllAnnotateSlowCallback(
630 const FunctionCallbackInfo<Value>& info) {
632 Isolate* isolate = info.GetIsolate();
634 FastCApiObject* self = UnwrapObject(info.This());
636 self->slow_call_count_++;
638 HandleScope handle_scope(isolate);
641 if (info.Length() > 1 && info[1]->IsNumber()) {
642 sum += info[1]->Int32Value(isolate->GetCurrentContext()).FromJust();
644 if (info.Length() > 2 && info[2]->IsNumber()) {
645 sum += info[2]->Uint32Value(isolate->GetCurrentContext()).FromJust();
647 if (info.Length() > 3 && info[3]->IsNumber()) {
648 sum += info[3]->IntegerValue(isolate->GetCurrentContext()).FromJust();
650 if (info.Length() > 4 && info[4]->IsNumber()) {
651 sum += info[4]->IntegerValue(isolate->GetCurrentContext()).FromJust();
654 info.GetReturnValue().Set(
Number::New(isolate, sum));
657#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
658 static AnyCType EnforceRangeCompareI32Patch(AnyCType
receiver,
660 AnyCType checked_arg,
663 ret.bool_value = EnforceRangeCompare<int32_t>(
664 receiver.object_value, real_arg.double_value, checked_arg.int32_value,
665 *options.options_value);
668 static AnyCType EnforceRangeCompareU32Patch(AnyCType
receiver,
670 AnyCType checked_arg,
673 ret.bool_value = EnforceRangeCompare<uint32_t>(
674 receiver.object_value, real_arg.double_value, checked_arg.uint32_value,
675 *options.options_value);
678 static AnyCType EnforceRangeCompareI64Patch(AnyCType
receiver,
680 AnyCType checked_arg,
683 ret.bool_value = EnforceRangeCompare<int64_t>(
684 receiver.object_value, real_arg.double_value, checked_arg.int64_value,
685 *options.options_value);
688 static AnyCType EnforceRangeCompareU64Patch(AnyCType
receiver,
690 AnyCType checked_arg,
693 ret.bool_value = EnforceRangeCompare<uint64_t>(
694 receiver.object_value, real_arg.double_value, checked_arg.uint64_value,
695 *options.options_value);
700 template <
typename IntegerT>
701 static bool EnforceRangeCompare(Local<Object>
receiver,
double real_arg,
702 IntegerT checked_arg,
703 FastApiCallbackOptions& options) {
704 FastCApiObject* self = UnwrapObject(
receiver);
706 self->fast_call_count_++;
708 if (!base::IsValueInRangeForNumericType<IntegerT>(real_arg)) {
711 return static_cast<IntegerT
>(real_arg) == checked_arg;
714 template <
typename IntegerT>
715 static void EnforceRangeCompareSlowCallback(
716 const FunctionCallbackInfo<Value>& info) {
718 Isolate* isolate = info.GetIsolate();
720 FastCApiObject* self = UnwrapObject(info.This());
722 self->slow_call_count_++;
724 HandleScope handle_scope(isolate);
727 if (info.Length() > 0 && info[0]->IsNumber()) {
728 real_arg = info[0]->NumberValue(isolate->GetCurrentContext()).FromJust();
733 bool in_range = base::IsValueInRangeForNumericType<IntegerT>(real_arg);
735 IntegerT checked_arg = 0;
736 if (info.Length() > 1 && info[1]->IsNumber()) {
737 double checked_arg_as_double =
738 info[1]->NumberValue(isolate->GetCurrentContext()).FromJust();
739 if (base::IsValueInRangeForNumericType<IntegerT>(
740 checked_arg_as_double)) {
741 checked_arg =
static_cast<IntegerT
>(checked_arg_as_double);
744 info.GetReturnValue().Set(
static_cast<IntegerT
>(real_arg) == checked_arg);
746 info.GetIsolate()->ThrowError(
"Argument out of range.");
750#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
751 static AnyCType ClampCompareI32Patch(AnyCType
receiver, AnyCType in_range,
752 AnyCType real_arg, AnyCType checked_arg,
755 ret.double_value = ClampCompare<int32_t>(
756 receiver.object_value, in_range.bool_value, real_arg.double_value,
757 checked_arg.int32_value, *options.options_value);
760 static AnyCType ClampCompareU32Patch(AnyCType
receiver, AnyCType in_range,
761 AnyCType real_arg, AnyCType checked_arg,
764 ret.double_value = ClampCompare<uint32_t>(
765 receiver.object_value, in_range.bool_value, real_arg.double_value,
766 checked_arg.uint32_value, *options.options_value);
769 static AnyCType ClampCompareI64Patch(AnyCType
receiver, AnyCType in_range,
770 AnyCType real_arg, AnyCType checked_arg,
773 ret.double_value = ClampCompare<int64_t>(
774 receiver.object_value, in_range.bool_value, real_arg.double_value,
775 checked_arg.int64_value, *options.options_value);
778 static AnyCType ClampCompareU64Patch(AnyCType
receiver, AnyCType in_range,
779 AnyCType real_arg, AnyCType checked_arg,
782 ret.double_value = ClampCompare<uint64_t>(
783 receiver.object_value, in_range.bool_value, real_arg.double_value,
784 checked_arg.uint64_value, *options.options_value);
789 template <
typename IntegerT>
790 static double ClampCompareCompute(
bool in_range,
double real_arg,
791 IntegerT checked_arg) {
793 return static_cast<double>(checked_arg);
796 IntegerT lower_bound = std::numeric_limits<IntegerT>::min();
797 IntegerT upper_bound = std::numeric_limits<IntegerT>::max();
804 CHECK(!std::isnan(real_arg));
805 if (real_arg <
static_cast<double>(lower_bound)) {
807 }
else if (real_arg >
static_cast<double>(upper_bound)) {
810 FATAL(
"Expected value to be out of range.");
812 }
else if (!std::isnan(real_arg)) {
813 if (real_arg != checked_arg) {
815 double diff = std::fabs(real_arg - checked_arg);
820 }
else if (checked_arg % 2 == 1) {
826 CHECK_EQ(
static_cast<IntegerT
>(real_arg), checked_arg);
832 template <
typename IntegerT>
833 static double ClampCompare(Local<Object>
receiver,
bool in_range,
834 double real_arg, IntegerT checked_arg,
835 FastApiCallbackOptions& options) {
836 FastCApiObject* self = UnwrapObject(
receiver);
838 self->fast_call_count_++;
840 double result = ClampCompareCompute(in_range, real_arg, checked_arg);
841 return static_cast<double>(
result);
844 template <
typename IntegerT>
845 static void ClampCompareSlowCallback(
846 const FunctionCallbackInfo<Value>& info) {
848 Isolate* isolate = info.GetIsolate();
850 FastCApiObject* self = UnwrapObject(info.This());
852 self->slow_call_count_++;
855 if (info.Length() > 1 && info[1]->IsNumber()) {
856 real_arg = info[1]->NumberValue(isolate->GetCurrentContext()).FromJust();
858 double checked_arg_dbl = std::numeric_limits<double>::max();
859 if (info.Length() > 2 && info[2]->IsNumber()) {
860 checked_arg_dbl = info[2].As<Number>()->Value();
863 info[0]->IsBoolean() && info[0]->BooleanValue(isolate) &&
864 base::IsValueInRangeForNumericType<IntegerT>(real_arg) &&
865 base::IsValueInRangeForNumericType<IntegerT>(checked_arg_dbl);
867 IntegerT checked_arg = std::numeric_limits<IntegerT>::max();
869 if (checked_arg_dbl != std::numeric_limits<double>::max()) {
870 checked_arg =
static_cast<IntegerT
>(checked_arg_dbl);
872 double result = ClampCompareCompute(in_range, real_arg, checked_arg);
875 IntegerT clamped = std::numeric_limits<IntegerT>::max();
876 if (std::isnan(checked_arg_dbl) || std::isnan(real_arg)) {
879 IntegerT lower_bound = std::numeric_limits<IntegerT>::min();
880 IntegerT upper_bound = std::numeric_limits<IntegerT>::max();
888 clamped = std::clamp(real_arg,
static_cast<double>(lower_bound),
889 static_cast<double>(upper_bound));
891 info.GetReturnValue().Set(
Number::New(isolate, clamped));
897 FastApiCallbackOptions& options) {
898 FastCApiObject* self = UnwrapObject(
receiver);
901 self->fast_call_count_++;
903 if (!arg->IsObject()) {
906 Local<Object>
object = arg.
As<Object>();
907 if (!IsValidApiObject(
object))
return false;
909 Isolate* isolate = options.isolate;
910 HandleScope handle_scope(isolate);
913 ->IsLeafTemplateForApiObject(
object);
916 static void IsFastCApiObjectSlowCallback(
917 const FunctionCallbackInfo<Value>& info) {
919 Isolate* isolate = info.GetIsolate();
921 FastCApiObject* self = UnwrapObject(info.This());
923 self->slow_call_count_++;
925 HandleScope handle_scope(isolate);
928 if (info.Length() < 1) {
929 info.GetIsolate()->ThrowError(
930 "is_valid_api_object should be called with an argument");
933 if (info[0]->IsObject()) {
934 Local<Object>
object = info[0].As<Object>();
935 if (!IsValidApiObject(
object)) {
940 ->IsLeafTemplateForApiObject(
object);
944 info.GetReturnValue().Set(
result);
947 static bool TestWasmMemoryFastCallback(Local<Object>
receiver,
949 FastApiCallbackOptions& options) {
950 FastCApiObject* self = UnwrapObject(
receiver);
952 self->fast_call_count_++;
963 if (!
receiver->Get(context, mem_string).ToLocal(&mem)) {
965 "wasm_memory was used when the WebAssembly.Memory was not set on the "
971 reinterpret_cast<uint8_t*
>(wasm_memory->Buffer()->Data())[address] = 42;
976 static void TestWasmMemorySlowCallback(
977 const FunctionCallbackInfo<Value>& info) {
979 FastCApiObject* self = UnwrapObject(info.This());
981 self->slow_call_count_++;
983 info.GetIsolate()->ThrowError(
"should be unreachable from wasm");
986 static void AssertIsExternal(
const FunctionCallbackInfo<Value>& info) {
988 FastCApiObject* self = UnwrapObject(info.This());
991 Local<Value> value = info[0];
993 if (!value->IsExternal()) {
994 info.GetIsolate()->ThrowError(
"Did not get an external.");
998 static void* GetPointerFastCallback(Local<Object>
receiver,
999 FastApiCallbackOptions& options) {
1000 FastCApiObject* self = UnwrapObject(
receiver);
1002 self->fast_call_count_++;
1007 return static_cast<void*
>(self);
1010 static void GetPointerSlowCallback(
const FunctionCallbackInfo<Value>& info) {
1012 Isolate* isolate = info.GetIsolate();
1013 FastCApiObject* self = UnwrapObject(info.This());
1015 self->slow_call_count_++;
1018 info.GetReturnValue().Set(
v8::Null(isolate));
1021 info.GetReturnValue().Set(
External::New(isolate,
static_cast<void*
>(self)));
1024 static void* GetNullPointerFastCallback(Local<Object>
receiver,
1025 FastApiCallbackOptions& options) {
1026 FastCApiObject* self = UnwrapObject(
receiver);
1028 self->fast_call_count_++;
1033 static void GetNullPointerSlowCallback(
1034 const FunctionCallbackInfo<Value>& info) {
1036 Isolate* isolate = info.GetIsolate();
1037 FastCApiObject* self = UnwrapObject(info.This());
1039 self->slow_call_count_++;
1041 info.GetReturnValue().Set(
v8::Null(isolate));
1044 static void* PassPointerFastCallback(Local<Object>
receiver,
void* pointer,
1045 FastApiCallbackOptions& options) {
1046 FastCApiObject* self = UnwrapObject(
receiver);
1048 self->fast_call_count_++;
1053 static void PassPointerSlowCallback(
const FunctionCallbackInfo<Value>& info) {
1055 FastCApiObject* self = UnwrapObject(info.This());
1057 self->slow_call_count_++;
1059 if (info.Length() != 1) {
1060 info.GetIsolate()->ThrowError(
1061 "Invalid number of arguments, expected one.");
1065 Local<Value> maybe_external = info[0].As<Value>();
1067 if (maybe_external->IsNull()) {
1068 info.GetReturnValue().Set(maybe_external);
1071 if (!maybe_external->IsExternal()) {
1072 info.GetIsolate()->ThrowError(
"Did not get an external.");
1076 Local<External> external = info[0].As<External>();
1078 info.GetReturnValue().Set(external);
1081 static bool ComparePointersFastCallback(Local<Object>
receiver,
1082 void* pointer_a,
void* pointer_b,
1083 FastApiCallbackOptions& options) {
1084 FastCApiObject* self = UnwrapObject(
receiver);
1086 self->fast_call_count_++;
1088 return pointer_a == pointer_b;
1091 static void ComparePointersSlowCallback(
1092 const FunctionCallbackInfo<Value>& info) {
1094 FastCApiObject* self = UnwrapObject(info.This());
1096 self->slow_call_count_++;
1098 if (info.Length() != 2) {
1099 info.GetIsolate()->ThrowError(
1100 "Invalid number of arguments, expected two.");
1104 Local<Value> value_a = info[0];
1105 Local<Value> value_b = info[1];
1108 if (value_a->IsNull()) {
1109 pointer_a =
nullptr;
1110 }
else if (value_a->IsExternal()) {
1111 pointer_a = value_a.As<External>()->Value();
1113 info.GetIsolate()->ThrowError(
1114 "Did not get an external as first parameter.");
1119 if (value_b->IsNull()) {
1120 pointer_b =
nullptr;
1121 }
else if (value_b->IsExternal()) {
1122 pointer_b = value_b.As<External>()->Value();
1124 info.GetIsolate()->ThrowError(
1125 "Did not get an external as second parameter.");
1129 info.GetReturnValue().Set(pointer_a == pointer_b);
1132 static int64_t sumInt64FastCallback(Local<Object>
receiver, int64_t a,
1134 FastApiCallbackOptions& options) {
1135 FastCApiObject* self = UnwrapObject(
receiver);
1137 self->fast_call_count_++;
1142 template <
typename T>
1143 static bool Convert(
double value, T* out_result) {
1144 if (!base::IsValueInRangeForNumericType<T>(value))
return false;
1145 *out_result =
static_cast<T
>(
value);
1149 static void sumInt64AsNumberSlowCallback(
1150 const FunctionCallbackInfo<Value>& info) {
1151 Isolate* isolate = info.GetIsolate();
1152 FastCApiObject* self = UnwrapObject(info.This());
1154 self->slow_call_count_++;
1156 if (info.Length() != 2) {
1157 info.GetIsolate()->ThrowError(
1158 "Invalid number of arguments, expected two.");
1162 Local<Value> value_a = info[0];
1163 Local<Value> value_b = info[1];
1165 if (!value_a->IsNumber()) {
1166 info.GetIsolate()->ThrowError(
"Did not get a number as first parameter.");
1170 if (!Convert(value_a.As<Number>()->Value(), &a)) {
1171 info.GetIsolate()->ThrowError(
"First number is out of int64_t range.");
1175 if (!value_b->IsNumber()) {
1176 info.GetIsolate()->ThrowError(
1177 "Did not get a number as second parameter.");
1181 if (!Convert(value_b.As<Number>()->Value(), &b)) {
1182 info.GetIsolate()->ThrowError(
"Second number is out of int64_t range.");
1186 info.GetReturnValue().Set(
Number::New(isolate,
static_cast<double>(a + b)));
1189 static void sumInt64AsBigIntSlowCallback(
1190 const FunctionCallbackInfo<Value>& info) {
1191 Isolate* isolate = info.GetIsolate();
1192 FastCApiObject* self = UnwrapObject(info.This());
1194 self->slow_call_count_++;
1196 if (info.Length() != 2) {
1197 info.GetIsolate()->ThrowError(
1198 "Invalid number of arguments, expected two.");
1202 Local<Value> value_a = info[0];
1203 Local<Value> value_b = info[1];
1206 if (value_a->IsBigInt()) {
1207 a =
static_cast<int64_t
>(value_a.As<BigInt>()->Int64Value());
1209 info.GetIsolate()->ThrowError(
"Did not get a BigInt as first parameter.");
1214 if (value_b->IsBigInt()) {
1215 b =
static_cast<int64_t
>(value_b.As<BigInt>()->Int64Value());
1217 info.GetIsolate()->ThrowError(
1218 "Did not get a BigInt as second parameter.");
1222 info.GetReturnValue().Set(
BigInt::New(isolate, a + b));
1225 static uint64_t sumUint64FastCallback(Local<Object>
receiver, uint64_t a,
1227 FastApiCallbackOptions& options) {
1228 FastCApiObject* self = UnwrapObject(
receiver);
1230 self->fast_call_count_++;
1235 CHECK_GT(self->fast_call_count_, 0);
1239 static void sumUint64AsNumberSlowCallback(
1240 const FunctionCallbackInfo<Value>& info) {
1241 Isolate* isolate = info.GetIsolate();
1242 FastCApiObject* self = UnwrapObject(info.This());
1244 self->slow_call_count_++;
1246 if (info.Length() != 2) {
1247 info.GetIsolate()->ThrowError(
1248 "Invalid number of arguments, expected two.");
1252 Local<Value> value_a = info[0];
1253 Local<Value> value_b = info[1];
1255 if (!value_a->IsNumber()) {
1256 info.GetIsolate()->ThrowError(
"Did not get a number as first parameter.");
1260 if (!Convert(value_a.As<Number>()->Value(), &a)) {
1261 info.GetIsolate()->ThrowError(
"First number is out of uint64_t range.");
1265 if (!value_b->IsNumber()) {
1266 info.GetIsolate()->ThrowError(
1267 "Did not get a number as second parameter.");
1271 if (!Convert(value_b.As<Number>()->Value(), &b)) {
1272 info.GetIsolate()->ThrowError(
"Second number is out of uint64_t range.");
1276 info.GetReturnValue().Set(
Number::New(isolate,
static_cast<double>(a + b)));
1279 static void sumUint64AsBigIntSlowCallback(
1280 const FunctionCallbackInfo<Value>& info) {
1281 Isolate* isolate = info.GetIsolate();
1282 FastCApiObject* self = UnwrapObject(info.This());
1284 self->slow_call_count_++;
1286 if (info.Length() != 2) {
1287 info.GetIsolate()->ThrowError(
1288 "Invalid number of arguments, expected two.");
1292 Local<Value> value_a = info[0];
1293 Local<Value> value_b = info[1];
1296 if (value_a->IsBigInt()) {
1297 a =
static_cast<uint64_t
>(value_a.As<BigInt>()->Uint64Value());
1299 info.GetIsolate()->ThrowError(
"Did not get a BigInt as first parameter.");
1304 if (value_b->IsBigInt()) {
1305 b =
static_cast<uint64_t
>(value_b.As<BigInt>()->Uint64Value());
1307 info.GetIsolate()->ThrowError(
1308 "Did not get a BigInt as second parameter.");
1315 static void AttributeGetterSlowCallback(
1316 const FunctionCallbackInfo<Value>& info) {
1317 FastCApiObject* self = UnwrapObject(info.This());
1318 self->slow_call_count_++;
1319 info.GetReturnValue().Set(self->attribute_value_);
1322 static int AttributeGetterFastCallback(Local<Object>
receiver,
1323 FastApiCallbackOptions& options) {
1324 FastCApiObject* self = UnwrapObject(
receiver);
1326 self->fast_call_count_++;
1327 return self->attribute_value_;
1330#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1331 static AnyCType AttributeGetterFastCallbackPatch(AnyCType
receiver,
1334 ret.int32_value = AttributeGetterFastCallback(
receiver.object_value,
1335 *options.options_value);
1340 static void AttributeSetterSlowCallback(
1341 const FunctionCallbackInfo<Value>& info) {
1342 FastCApiObject* self = UnwrapObject(info.This());
1343 self->slow_call_count_++;
1344 if (info.Length() < 1 || !info[0]->IsNumber()) {
1345 info.GetIsolate()->ThrowError(
1346 "The attribute requires a number as a new value");
1350 info[0]->NumberValue(info.GetIsolate()->GetCurrentContext()).FromJust();
1351 if (!base::IsValueInRangeForNumericType<int>(double_val)) {
1352 info.GetIsolate()->ThrowError(
1353 "New value of attribute is not within int32 range");
1356 self->attribute_value_ =
static_cast<int>(double_val);
1359 static void AttributeSetterFastCallback(Local<Object>
receiver, int32_t value,
1360 FastApiCallbackOptions& options) {
1361 FastCApiObject* self = UnwrapObject(
receiver);
1363 self->fast_call_count_++;
1364 self->attribute_value_ =
value;
1367#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1368 static void AttributeSetterFastCallbackPatch(AnyCType
receiver,
1371 AttributeSetterFastCallback(
receiver.object_value, value.int32_value,
1372 *options.options_value);
1376 static void FastCallCount(
const FunctionCallbackInfo<Value>& info) {
1377 FastCApiObject* self = UnwrapObject(info.This());
1379 info.GetReturnValue().Set(
1380 Number::New(info.GetIsolate(), self->fast_call_count()));
1382 static void SlowCallCount(
const FunctionCallbackInfo<Value>& info) {
1384 FastCApiObject* self = UnwrapObject(info.This());
1386 info.GetReturnValue().Set(
1387 Number::New(info.GetIsolate(), self->slow_call_count()));
1389 static void ResetCounts(
const FunctionCallbackInfo<Value>& info) {
1391 FastCApiObject* self = UnwrapObject(info.This());
1393 self->reset_counts();
1394 info.GetReturnValue().Set(
Undefined(info.GetIsolate()));
1396 static void SupportsFPParams(
const FunctionCallbackInfo<Value>& info) {
1398 FastCApiObject* self = UnwrapObject(info.This());
1400 info.GetReturnValue().Set(self->supports_fp_params_);
1403 int fast_call_count()
const {
return fast_call_count_; }
1404 int slow_call_count()
const {
return slow_call_count_; }
1405 void reset_counts() {
1406 fast_call_count_ = 0;
1407 slow_call_count_ = 0;
1410 static const int kV8WrapperObjectIndex = 1;
1413 static bool IsValidApiObject(Local<Object>
object) {
1414 if (object->IsInt32())
return false;
1415 auto instance_type = i::Internals::GetInstanceType(
1417 return (
base::IsInRange(instance_type, i::Internals::kFirstJSApiObjectType,
1418 i::Internals::kLastJSApiObjectType) ||
1419 instance_type == i::Internals::kJSSpecialApiObjectType);
1421 static FastCApiObject* UnwrapObject(Local<Object>
object) {
1422 if (!IsValidApiObject(
object)) {
1425 if (object->InternalFieldCount() <= kV8WrapperObjectIndex) {
1428 FastCApiObject* wrapped =
reinterpret_cast<FastCApiObject*
>(
1429 object->GetAlignedPointerFromInternalField(kV8WrapperObjectIndex));
1434 int fast_call_count_ = 0, slow_call_count_ = 0;
1435 int attribute_value_ = 0;
1436#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
1437 bool supports_fp_params_ =
true;
1439 bool supports_fp_params_ =
false;
1443#undef CHECK_SELF_OR_THROW_SLOW
1444#undef CHECK_SELF_OR_THROW_FAST
1445#undef CHECK_SELF_OR_THROW_FAST_OPTIONS
1449thread_local FastCApiObject kFastCApiObject;
1453FastCApiObject& FastCApiObject::instance() {
return kFastCApiObject; }
1457 if (!info.IsConstructCall()) {
1458 info.GetIsolate()->ThrowError(
1459 "FastCAPI helper must be constructed with new.");
1463 api_object->SetAlignedPointerInInternalField(
1464 FastCApiObject::kV8WrapperObjectIndex,
1465 reinterpret_cast<void*
>(&kFastCApiObject));
1466 api_object->SetAccessorProperty(
1469 ->GetFunction(api_object->GetCreationContext(info.GetIsolate())
1482 FastCApiObject::ThrowNoFallbackFastCallbackPatch));
1483 api_obj_ctor->PrototypeTemplate()->Set(
1484 isolate,
"throw_no_fallback",
1486 isolate, FastCApiObject::ThrowFallbackSlowCallback,
Local<Value>(),
1492 FastCApiObject::CopyStringFastCallbackPatch));
1493 api_obj_ctor->PrototypeTemplate()->Set(
1494 isolate,
"copy_string",
1502 FastCApiObject::AddAllFastCallbackPatch));
1503 api_obj_ctor->PrototypeTemplate()->Set(
1512 FastCApiObject::AttributeSetterFastCallback));
1515 FastCApiObject::AttributeGetterFastCallback));
1517 api_obj_ctor->PrototypeTemplate()->SetAccessorProperty(
1520 isolate, FastCApiObject::AttributeGetterSlowCallback,
1524 isolate, FastCApiObject::AttributeSetterSlowCallback,
1531 FastCApiObject::AddAllSequenceFastCallbackPatch));
1532 api_obj_ctor->PrototypeTemplate()->Set(
1533 isolate,
"add_all_sequence",
1535 isolate, FastCApiObject::AddAllSequenceSlowCallback,
Local<Value>(),
1540 FastCApiObject::AddAllTypedArrayFastCallback<uint8_t>
1542 FastCApiObject::AddAllTypedArrayFastCallbackPatch<uint8_t>));
1544 api_obj_ctor->PrototypeTemplate()->Set(
1545 isolate,
"add_all_uint8_typed_array",
1547 isolate, FastCApiObject::AddAllTypedArraySlowCallback,
1552 FastCApiObject::AddAllTypedArrayFastCallback<int32_t>
1554 FastCApiObject::AddAllTypedArrayFastCallbackPatch<int32_t>));
1556 api_obj_ctor->PrototypeTemplate()->Set(
1557 isolate,
"add_all_int32_typed_array",
1559 isolate, FastCApiObject::AddAllTypedArraySlowCallback,
1564 FastCApiObject::AddAllTypedArrayFastCallback<int64_t>
1566 FastCApiObject::AddAllTypedArrayFastCallbackPatch<int64_t>));
1567 api_obj_ctor->PrototypeTemplate()->Set(
1568 isolate,
"add_all_int64_typed_array",
1570 isolate, FastCApiObject::AddAllTypedArraySlowCallback,
1575 FastCApiObject::AddAllTypedArrayFastCallback<uint64_t>
1577 FastCApiObject::AddAllTypedArrayFastCallbackPatch<uint64_t>));
1578 api_obj_ctor->PrototypeTemplate()->Set(
1579 isolate,
"add_all_uint64_typed_array",
1581 isolate, FastCApiObject::AddAllTypedArraySlowCallback,
1584 &add_all_uint64_typed_array_c_func));
1587 FastCApiObject::AddAllTypedArrayFastCallback<uint32_t>
1589 FastCApiObject::AddAllTypedArrayFastCallbackPatch<uint32_t>));
1590 api_obj_ctor->PrototypeTemplate()->Set(
1591 isolate,
"add_all_uint32_typed_array",
1593 isolate, FastCApiObject::AddAllTypedArraySlowCallback,
1596 &add_all_uint32_typed_array_c_func));
1600 FastCApiObject::AddAllTypedArrayFastCallbackPatch<float>));
1601 api_obj_ctor->PrototypeTemplate()->Set(
1602 isolate,
"add_all_float32_typed_array",
1604 isolate, FastCApiObject::AddAllTypedArraySlowCallback,
1607 &add_all_float32_typed_array_c_func));
1611 FastCApiObject::AddAllFastCallbackNoOptionsPatch),
1613 api_obj_ctor->PrototypeTemplate()->Set(
1614 isolate,
"add_all_no_options",
1616 isolate, FastCApiObject::AddAllSlowCallback,
Local<Value>(),
1621 FastCApiObject::AddAllTypedArrayFastCallback<double>
1623 FastCApiObject::AddAllTypedArrayFastCallbackPatch<double>));
1624 api_obj_ctor->PrototypeTemplate()->Set(
1625 isolate,
"add_all_float64_typed_array",
1627 isolate, FastCApiObject::AddAllTypedArraySlowCallback,
1630 &add_all_float64_typed_array_c_func));
1634 add_all_no_options_c_func,
1636 api_obj_ctor->PrototypeTemplate()->Set(
1637 isolate,
"add_all_overload",
1639 isolate, FastCApiObject::AddAllSequenceSlowCallback,
Local<Value>(),
1645 FastCApiObject::AddAll32BitIntFastCallback_8ArgsPatch));
1648 FastCApiObject::AddAll32BitIntFastCallback_6ArgsPatch));
1651 FastCApiObject::AddAll32BitIntFastCallback_5ArgsPatch));
1652 const CFunction c_function_overloads[] = {add_all_32bit_int_6args_c_func,
1653 add_all_32bit_int_5args_c_func};
1655 api_obj_ctor->PrototypeTemplate()->Set(
1656 isolate,
"overloaded_add_all_32bit_int",
1658 isolate, FastCApiObject::AddAll32BitIntSlowCallback,
Local<Value>(),
1662 api_obj_ctor->PrototypeTemplate()->Set(
1663 isolate,
"overloaded_add_all_8args",
1665 isolate, FastCApiObject::AddAll32BitIntSlowCallback,
Local<Value>(),
1669 api_obj_ctor->PrototypeTemplate()->Set(
1670 isolate,
"overloaded_add_all_32bit_int_no_sig",
1672 isolate, FastCApiObject::AddAll32BitIntSlowCallback,
Local<Value>(),
1678 FastCApiObject::Add32BitIntFastCallbackPatch));
1679 api_obj_ctor->PrototypeTemplate()->Set(
1680 isolate,
"add_32bit_int",
1682 isolate, FastCApiObject::Add32BitIntSlowCallback,
Local<Value>(),
1687 FastCApiObject::AddAllAnnotateFastCallback<
1691 api_obj_ctor->PrototypeTemplate()->Set(
1692 isolate,
"add_all_annotate_enforce_range",
1694 isolate, FastCApiObject::AddAllAnnotateSlowCallback,
Local<Value>(),
1700 CFunction enforce_range_compare_i32_c_func =
1702 .
Fn(FastCApiObject::EnforceRangeCompare<int32_t>)
1704#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1705 .Patch(FastCApiObject::EnforceRangeCompareI32Patch)
1708 api_obj_ctor->PrototypeTemplate()->Set(
1709 isolate,
"enforce_range_compare_i32",
1711 isolate, FastCApiObject::EnforceRangeCompareSlowCallback<int32_t>,
1715 CFunction enforce_range_compare_u32_c_func =
1717 .
Fn(FastCApiObject::EnforceRangeCompare<uint32_t>)
1719#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1720 .Patch(FastCApiObject::EnforceRangeCompareU32Patch)
1723 api_obj_ctor->PrototypeTemplate()->Set(
1724 isolate,
"enforce_range_compare_u32",
1726 isolate, FastCApiObject::EnforceRangeCompareSlowCallback<uint32_t>,
1730 CFunction enforce_range_compare_i64_c_func =
1732 .
Fn(FastCApiObject::EnforceRangeCompare<int64_t>)
1734#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1735 .Patch(FastCApiObject::EnforceRangeCompareI64Patch)
1738 api_obj_ctor->PrototypeTemplate()->Set(
1739 isolate,
"enforce_range_compare_i64",
1741 isolate, FastCApiObject::EnforceRangeCompareSlowCallback<int64_t>,
1745 CFunction enforce_range_compare_u64_c_func =
1747 .
Fn(FastCApiObject::EnforceRangeCompare<uint64_t>)
1749#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1750 .Patch(FastCApiObject::EnforceRangeCompareU64Patch)
1753 api_obj_ctor->PrototypeTemplate()->Set(
1754 isolate,
"enforce_range_compare_u64",
1756 isolate, FastCApiObject::EnforceRangeCompareSlowCallback<uint64_t>,
1764 .
Fn(FastCApiObject::ClampCompare<int32_t>)
1766#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1767 .Patch(FastCApiObject::ClampCompareI32Patch)
1770 api_obj_ctor->PrototypeTemplate()->Set(
1771 isolate,
"clamp_compare_i32",
1773 isolate, FastCApiObject::ClampCompareSlowCallback<int32_t>,
1779 .
Fn(FastCApiObject::ClampCompare<uint32_t>)
1781#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1782 .Patch(FastCApiObject::ClampCompareU32Patch)
1785 api_obj_ctor->PrototypeTemplate()->Set(
1786 isolate,
"clamp_compare_u32",
1788 isolate, FastCApiObject::ClampCompareSlowCallback<uint32_t>,
1794 .
Fn(FastCApiObject::ClampCompare<int64_t>)
1796#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1797 .Patch(FastCApiObject::ClampCompareI64Patch)
1800 api_obj_ctor->PrototypeTemplate()->Set(
1801 isolate,
"clamp_compare_i64",
1803 isolate, FastCApiObject::ClampCompareSlowCallback<int64_t>,
1809 .
Fn(FastCApiObject::ClampCompare<uint64_t>)
1811#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1812 .Patch(FastCApiObject::ClampCompareU64Patch)
1815 api_obj_ctor->PrototypeTemplate()->Set(
1816 isolate,
"clamp_compare_u64",
1818 isolate, FastCApiObject::ClampCompareSlowCallback<uint64_t>,
1824 api_obj_ctor->PrototypeTemplate()->Set(
1825 isolate,
"is_fast_c_api_object",
1827 isolate, FastCApiObject::IsFastCApiObjectSlowCallback,
1833 api_obj_ctor->PrototypeTemplate()->Set(
1834 isolate,
"test_wasm_memory",
1836 isolate, FastCApiObject::TestWasmMemorySlowCallback,
Local<Value>(),
1840 api_obj_ctor->PrototypeTemplate()->Set(
1841 isolate,
"assert_is_external",
1849 api_obj_ctor->PrototypeTemplate()->Set(
1850 isolate,
"get_pointer",
1852 isolate, FastCApiObject::GetPointerSlowCallback,
Local<Value>(),
1857 api_obj_ctor->PrototypeTemplate()->Set(
1858 isolate,
"get_null_pointer",
1860 isolate, FastCApiObject::GetNullPointerSlowCallback,
Local<Value>(),
1865 api_obj_ctor->PrototypeTemplate()->Set(
1866 isolate,
"pass_pointer",
1868 isolate, FastCApiObject::PassPointerSlowCallback,
Local<Value>(),
1873 api_obj_ctor->PrototypeTemplate()->Set(
1874 isolate,
"compare_pointers",
1876 isolate, FastCApiObject::ComparePointersSlowCallback,
1881 api_obj_ctor->PrototypeTemplate()->Set(
1882 isolate,
"sum_int64_as_number",
1884 isolate, FastCApiObject::sumInt64AsNumberSlowCallback,
1889 .
Fn(FastCApiObject::sumInt64FastCallback)
1891 api_obj_ctor->PrototypeTemplate()->Set(
1892 isolate,
"sum_int64_as_bigint",
1894 isolate, FastCApiObject::sumInt64AsBigIntSlowCallback,
1899 api_obj_ctor->PrototypeTemplate()->Set(
1900 isolate,
"sum_uint64_as_number",
1902 isolate, FastCApiObject::sumUint64AsNumberSlowCallback,
1907 .
Fn(FastCApiObject::sumUint64FastCallback)
1909 api_obj_ctor->PrototypeTemplate()->Set(
1910 isolate,
"sum_uint64_as_bigint",
1912 isolate, FastCApiObject::sumUint64AsBigIntSlowCallback,
1916 api_obj_ctor->PrototypeTemplate()->Set(
1917 isolate,
"fast_call_count",
1919 isolate, FastCApiObject::FastCallCount,
Local<Value>(), signature,
1921 api_obj_ctor->PrototypeTemplate()->Set(
1922 isolate,
"slow_call_count",
1924 isolate, FastCApiObject::SlowCallCount,
Local<Value>(), signature,
1926 api_obj_ctor->PrototypeTemplate()->Set(
1927 isolate,
"reset_counts",
1932 CFunction add_all_32bit_int_5args_enforce_range_c_func =
1934 .
Fn(FastCApiObject::AddAll32BitIntFastCallback_5Args)
1936 .Arg<5, v8::CTypeInfo::Flags::kEnforceRangeBit>()
1937#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1938 .Patch(FastCApiObject::AddAll32BitIntFastCallback_5ArgsPatch)
1941 api_obj_ctor->PrototypeTemplate()->Set(
1942 isolate,
"add_all_5args_enforce_range",
1944 isolate, FastCApiObject::AddAll32BitIntSlowCallback,
Local<Value>(),
1947 &add_all_32bit_int_5args_enforce_range_c_func));
1949 api_obj_ctor->InstanceTemplate()->SetInternalFieldCount(
1950 FastCApiObject::kV8WrapperObjectIndex + 1);
1952 return api_obj_ctor;
1956 if (!info.IsConstructCall()) {
1957 info.GetIsolate()->ThrowError(
1958 "LeafInterfaceType helper must be constructed with new.");
1966 leaf_object_ctor->SetClassName(
1968 return leaf_object_ctor;
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
static Local< BigInt > New(Isolate *isolate, int64_t value)
static Local< BigInt > NewFromUnsigned(Isolate *isolate, uint64_t value)
static CFunction Make(F *func, CFunctionInfo::Int64Representation int64_rep=CFunctionInfo::Int64Representation::kNumber)
static constexpr CTypeInfo Build()
constexpr Identifier GetId() const
static Local< External > New(Isolate *isolate, void *value)
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=nullptr, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect, const CFunction *c_function=nullptr, uint16_t instance_type=0, uint16_t allowed_receiver_instance_type_range_start=0, uint16_t allowed_receiver_instance_type_range_end=0)
static Local< FunctionTemplate > NewWithCFunctionOverloads(Isolate *isolate, FunctionCallback callback=nullptr, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect, const MemorySpan< const CFunction > &c_function_overloads={})
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
static Isolate * GetCurrent()
V8_INLINE Local< S > As() const
V8_INLINE Local< T > ToLocalChecked()
V8_INLINE bool IsEmpty() const
static Local< Number > New(Isolate *isolate, double value)
static PerIsolateData * Get(Isolate *isolate)
Local< FunctionTemplate > GetTestApiObjectCtor() const
void SetTestApiObjectCtor(Local< FunctionTemplate > ctor)
static Local< FunctionTemplate > CreateLeafInterfaceTypeTemplate(Isolate *isolate)
static Local< FunctionTemplate > CreateTestFastCApiTemplate(Isolate *isolate)
static Local< Signature > New(Isolate *isolate, Local< FunctionTemplate > receiver=Local< FunctionTemplate >())
static V8_WARN_UNUSED_RESULT Local< String > NewFromUtf8Literal(Isolate *isolate, const char(&literal)[N], NewStringType type=NewStringType::kNormal)
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=NewStringType::kNormal, int length=-1)
constexpr auto Fn(R(*fn)(Args...))
static V8_INLINE Address ValueAsAddress(const T *value)
#define V8_IF_USE_SIMULATOR(V)
#define CHECK_SELF_OR_THROW_SLOW()
#define CHECK_SELF_OR_THROW_FAST_OPTIONS(return_value)
std::optional< TNode< JSArray > > a
ZoneVector< RpoNumber > & result
constexpr bool IsInRange(T value, U lower_limit, U higher_limit)
constexpr double kMaxSafeInteger
bool V8_EXPORT ValidateCallbackInfo(const FunctionCallbackInfo< void > &info)
V8_EXPORT_PRIVATE FlagValues v8_flags
constexpr double kMinSafeInteger
V8_INLINE Local< Primitive > Null(Isolate *isolate)
internal::CFunctionBuilder CFunctionBuilder
V8_INLINE Local< Primitive > Undefined(Isolate *isolate)
void CreateLeafInterfaceObject(const FunctionCallbackInfo< Value > &info)
void CreateFastCAPIObject(const FunctionCallbackInfo< Value > &info)
bool V8_EXPORT TryToCopyAndConvertArrayToCppBuffer(Local< Array > src, T *dst, uint32_t max_length)
#define CHECK_GT(lhs, rhs)
#define CHECK_LE(lhs, rhs)
#define CHECK_NOT_NULL(val)
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
std::unique_ptr< ValueMirror > value