xref: /third_party/node/deps/v8/src/d8/d8-test.cc (revision 1cb0ef41)
11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/d8/d8.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "include/v8-fast-api-calls.h"
81cb0ef41Sopenharmony_ci#include "include/v8-template.h"
91cb0ef41Sopenharmony_ci#include "src/api/api-inl.h"
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci// This file exposes a d8.test.fast_c_api object, which adds testing facility
121cb0ef41Sopenharmony_ci// for writing mjsunit tests that exercise fast API calls. The fast_c_api object
131cb0ef41Sopenharmony_ci// contains an `add_all` method with the following signature:
141cb0ef41Sopenharmony_ci// double add_all(bool /*should_fallback*/, int32_t, uint32_t,
151cb0ef41Sopenharmony_ci//   int64_t, uint64_t, float, double), that is wired as a "fast API" method.
161cb0ef41Sopenharmony_ci// The fast_c_api object also supports querying the number of fast/slow calls
171cb0ef41Sopenharmony_ci// and resetting these counters.
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci// Make sure to sync the following with src/compiler/globals.h.
201cb0ef41Sopenharmony_ci#if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_ARM64)
211cb0ef41Sopenharmony_ci#define V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
221cb0ef41Sopenharmony_ci#endif
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cinamespace v8 {
251cb0ef41Sopenharmony_cinamespace {
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci#define CHECK_SELF_OR_FALLBACK(return_value) \
281cb0ef41Sopenharmony_ci  if (!self) {                               \
291cb0ef41Sopenharmony_ci    options.fallback = 1;                    \
301cb0ef41Sopenharmony_ci    return return_value;                     \
311cb0ef41Sopenharmony_ci  }
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci#define CHECK_SELF_OR_THROW()                                               \
341cb0ef41Sopenharmony_ci  if (!self) {                                                              \
351cb0ef41Sopenharmony_ci    args.GetIsolate()->ThrowError(                                          \
361cb0ef41Sopenharmony_ci        "This method is not defined on objects inheriting from FastCAPI."); \
371cb0ef41Sopenharmony_ci    return;                                                                 \
381cb0ef41Sopenharmony_ci  }
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ciclass FastCApiObject {
411cb0ef41Sopenharmony_ci public:
421cb0ef41Sopenharmony_ci  static FastCApiObject& instance();
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
451cb0ef41Sopenharmony_ci  static AnyCType AddAllFastCallbackPatch(AnyCType receiver,
461cb0ef41Sopenharmony_ci                                          AnyCType should_fallback,
471cb0ef41Sopenharmony_ci                                          AnyCType arg_i32, AnyCType arg_u32,
481cb0ef41Sopenharmony_ci                                          AnyCType arg_i64, AnyCType arg_u64,
491cb0ef41Sopenharmony_ci                                          AnyCType arg_f32, AnyCType arg_f64,
501cb0ef41Sopenharmony_ci                                          AnyCType options) {
511cb0ef41Sopenharmony_ci    AnyCType ret;
521cb0ef41Sopenharmony_ci    ret.double_value = AddAllFastCallback(
531cb0ef41Sopenharmony_ci        receiver.object_value, should_fallback.bool_value, arg_i32.int32_value,
541cb0ef41Sopenharmony_ci        arg_u32.uint32_value, arg_i64.int64_value, arg_u64.uint64_value,
551cb0ef41Sopenharmony_ci        arg_f32.float_value, arg_f64.double_value, *options.options_value);
561cb0ef41Sopenharmony_ci    return ret;
571cb0ef41Sopenharmony_ci  }
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci#endif  //  V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
601cb0ef41Sopenharmony_ci  static double AddAllFastCallback(Local<Object> receiver, bool should_fallback,
611cb0ef41Sopenharmony_ci                                   int32_t arg_i32, uint32_t arg_u32,
621cb0ef41Sopenharmony_ci                                   int64_t arg_i64, uint64_t arg_u64,
631cb0ef41Sopenharmony_ci                                   float arg_f32, double arg_f64,
641cb0ef41Sopenharmony_ci                                   FastApiCallbackOptions& options) {
651cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(receiver);
661cb0ef41Sopenharmony_ci    CHECK_SELF_OR_FALLBACK(0);
671cb0ef41Sopenharmony_ci    self->fast_call_count_++;
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci    if (should_fallback) {
701cb0ef41Sopenharmony_ci      options.fallback = true;
711cb0ef41Sopenharmony_ci      return 0;
721cb0ef41Sopenharmony_ci    } else {
731cb0ef41Sopenharmony_ci      options.fallback = false;
741cb0ef41Sopenharmony_ci    }
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ci    return static_cast<double>(arg_i32) + static_cast<double>(arg_u32) +
771cb0ef41Sopenharmony_ci           static_cast<double>(arg_i64) + static_cast<double>(arg_u64) +
781cb0ef41Sopenharmony_ci           static_cast<double>(arg_f32) + arg_f64;
791cb0ef41Sopenharmony_ci  }
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
821cb0ef41Sopenharmony_ci  static AnyCType AddAllFastCallbackNoOptionsPatch(
831cb0ef41Sopenharmony_ci      AnyCType receiver, AnyCType should_fallback, AnyCType arg_i32,
841cb0ef41Sopenharmony_ci      AnyCType arg_u32, AnyCType arg_i64, AnyCType arg_u64, AnyCType arg_f32,
851cb0ef41Sopenharmony_ci      AnyCType arg_f64) {
861cb0ef41Sopenharmony_ci    AnyCType ret;
871cb0ef41Sopenharmony_ci    ret.double_value = AddAllFastCallbackNoOptions(
881cb0ef41Sopenharmony_ci        receiver.object_value, should_fallback.bool_value, arg_i32.int32_value,
891cb0ef41Sopenharmony_ci        arg_u32.uint32_value, arg_i64.int64_value, arg_u64.uint64_value,
901cb0ef41Sopenharmony_ci        arg_f32.float_value, arg_f64.double_value);
911cb0ef41Sopenharmony_ci    return ret;
921cb0ef41Sopenharmony_ci  }
931cb0ef41Sopenharmony_ci#endif  //  V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
941cb0ef41Sopenharmony_ci  static double AddAllFastCallbackNoOptions(Local<Object> receiver,
951cb0ef41Sopenharmony_ci                                            bool should_fallback,
961cb0ef41Sopenharmony_ci                                            int32_t arg_i32, uint32_t arg_u32,
971cb0ef41Sopenharmony_ci                                            int64_t arg_i64, uint64_t arg_u64,
981cb0ef41Sopenharmony_ci                                            float arg_f32, double arg_f64) {
991cb0ef41Sopenharmony_ci    FastCApiObject* self;
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ci    // For Wasm call, we don't pass FastCApiObject as the receiver, so we need
1021cb0ef41Sopenharmony_ci    // to retrieve the FastCApiObject instance from a static variable.
1031cb0ef41Sopenharmony_ci    if (Utils::OpenHandle(*receiver)->IsJSGlobalProxy() ||
1041cb0ef41Sopenharmony_ci        Utils::OpenHandle(*receiver)->IsUndefined()) {
1051cb0ef41Sopenharmony_ci      // Note: FastCApiObject::instance() returns the reference of an object
1061cb0ef41Sopenharmony_ci      // allocated in thread-local storage, its value cannot be stored in a
1071cb0ef41Sopenharmony_ci      // static variable here.
1081cb0ef41Sopenharmony_ci      self = &FastCApiObject::instance();
1091cb0ef41Sopenharmony_ci    } else {
1101cb0ef41Sopenharmony_ci      // Fuzzing code can call this function from JS; in this case the receiver
1111cb0ef41Sopenharmony_ci      // should be a FastCApiObject.
1121cb0ef41Sopenharmony_ci      self = UnwrapObject(receiver);
1131cb0ef41Sopenharmony_ci      CHECK_NOT_NULL(self);
1141cb0ef41Sopenharmony_ci    }
1151cb0ef41Sopenharmony_ci    self->fast_call_count_++;
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci    return static_cast<double>(arg_i32) + static_cast<double>(arg_u32) +
1181cb0ef41Sopenharmony_ci           static_cast<double>(arg_i64) + static_cast<double>(arg_u64) +
1191cb0ef41Sopenharmony_ci           static_cast<double>(arg_f32) + arg_f64;
1201cb0ef41Sopenharmony_ci  }
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci  static void AddAllSlowCallback(const FunctionCallbackInfo<Value>& args) {
1231cb0ef41Sopenharmony_ci    Isolate* isolate = args.GetIsolate();
1241cb0ef41Sopenharmony_ci
1251cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
1261cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
1271cb0ef41Sopenharmony_ci    self->slow_call_count_++;
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci    HandleScope handle_scope(isolate);
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ci    double sum = 0;
1321cb0ef41Sopenharmony_ci    if (args.Length() > 1 && args[1]->IsNumber()) {
1331cb0ef41Sopenharmony_ci      sum += args[1]->Int32Value(isolate->GetCurrentContext()).FromJust();
1341cb0ef41Sopenharmony_ci    }
1351cb0ef41Sopenharmony_ci    if (args.Length() > 2 && args[2]->IsNumber()) {
1361cb0ef41Sopenharmony_ci      sum += args[2]->Uint32Value(isolate->GetCurrentContext()).FromJust();
1371cb0ef41Sopenharmony_ci    }
1381cb0ef41Sopenharmony_ci    if (args.Length() > 3 && args[3]->IsNumber()) {
1391cb0ef41Sopenharmony_ci      sum += args[3]->IntegerValue(isolate->GetCurrentContext()).FromJust();
1401cb0ef41Sopenharmony_ci    }
1411cb0ef41Sopenharmony_ci    if (args.Length() > 4 && args[4]->IsNumber()) {
1421cb0ef41Sopenharmony_ci      sum += args[4]->IntegerValue(isolate->GetCurrentContext()).FromJust();
1431cb0ef41Sopenharmony_ci    }
1441cb0ef41Sopenharmony_ci    if (args.Length() > 5 && args[5]->IsNumber()) {
1451cb0ef41Sopenharmony_ci      sum += args[5]->NumberValue(isolate->GetCurrentContext()).FromJust();
1461cb0ef41Sopenharmony_ci    } else {
1471cb0ef41Sopenharmony_ci      sum += std::numeric_limits<double>::quiet_NaN();
1481cb0ef41Sopenharmony_ci    }
1491cb0ef41Sopenharmony_ci    if (args.Length() > 6 && args[6]->IsNumber()) {
1501cb0ef41Sopenharmony_ci      sum += args[6]->NumberValue(isolate->GetCurrentContext()).FromJust();
1511cb0ef41Sopenharmony_ci    } else {
1521cb0ef41Sopenharmony_ci      sum += std::numeric_limits<double>::quiet_NaN();
1531cb0ef41Sopenharmony_ci    }
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(Number::New(isolate, sum));
1561cb0ef41Sopenharmony_ci  }
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
1591cb0ef41Sopenharmony_ci  typedef double Type;
1601cb0ef41Sopenharmony_ci#else
1611cb0ef41Sopenharmony_ci  typedef int32_t Type;
1621cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
1631cb0ef41Sopenharmony_ci#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1641cb0ef41Sopenharmony_ci  static AnyCType AddAllSequenceFastCallbackPatch(AnyCType receiver,
1651cb0ef41Sopenharmony_ci                                                  AnyCType should_fallback,
1661cb0ef41Sopenharmony_ci                                                  AnyCType seq_arg,
1671cb0ef41Sopenharmony_ci                                                  AnyCType options) {
1681cb0ef41Sopenharmony_ci    AnyCType ret;
1691cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
1701cb0ef41Sopenharmony_ci    ret.double_value = AddAllSequenceFastCallback(
1711cb0ef41Sopenharmony_ci        receiver.object_value, should_fallback.bool_value,
1721cb0ef41Sopenharmony_ci        seq_arg.sequence_value, *options.options_value);
1731cb0ef41Sopenharmony_ci#else
1741cb0ef41Sopenharmony_ci    ret.int32_value = AddAllSequenceFastCallback(
1751cb0ef41Sopenharmony_ci        receiver.object_value, should_fallback.bool_value,
1761cb0ef41Sopenharmony_ci        seq_arg.sequence_value, *options.options_value);
1771cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
1781cb0ef41Sopenharmony_ci    return ret;
1791cb0ef41Sopenharmony_ci  }
1801cb0ef41Sopenharmony_ci#endif  //  V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
1811cb0ef41Sopenharmony_ci  static Type AddAllSequenceFastCallback(Local<Object> receiver,
1821cb0ef41Sopenharmony_ci                                         bool should_fallback,
1831cb0ef41Sopenharmony_ci                                         Local<Array> seq_arg,
1841cb0ef41Sopenharmony_ci                                         FastApiCallbackOptions& options) {
1851cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(receiver);
1861cb0ef41Sopenharmony_ci    CHECK_SELF_OR_FALLBACK(0);
1871cb0ef41Sopenharmony_ci    self->fast_call_count_++;
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_ci    if (should_fallback) {
1901cb0ef41Sopenharmony_ci      options.fallback = true;
1911cb0ef41Sopenharmony_ci      return 0;
1921cb0ef41Sopenharmony_ci    }
1931cb0ef41Sopenharmony_ci
1941cb0ef41Sopenharmony_ci    uint32_t length = seq_arg->Length();
1951cb0ef41Sopenharmony_ci    if (length > 1024) {
1961cb0ef41Sopenharmony_ci      options.fallback = true;
1971cb0ef41Sopenharmony_ci      return 0;
1981cb0ef41Sopenharmony_ci    }
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_ci    Type buffer[1024];
2011cb0ef41Sopenharmony_ci    bool result = TryToCopyAndConvertArrayToCppBuffer<
2021cb0ef41Sopenharmony_ci        CTypeInfoBuilder<Type>::Build().GetId(), Type>(seq_arg, buffer, 1024);
2031cb0ef41Sopenharmony_ci    if (!result) {
2041cb0ef41Sopenharmony_ci      options.fallback = true;
2051cb0ef41Sopenharmony_ci      return 0;
2061cb0ef41Sopenharmony_ci    }
2071cb0ef41Sopenharmony_ci    DCHECK_EQ(seq_arg->Length(), length);
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_ci    Type sum = 0;
2101cb0ef41Sopenharmony_ci    for (uint32_t i = 0; i < length; ++i) {
2111cb0ef41Sopenharmony_ci      sum += buffer[i];
2121cb0ef41Sopenharmony_ci    }
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci    return sum;
2151cb0ef41Sopenharmony_ci  }
2161cb0ef41Sopenharmony_ci  static void AddAllSequenceSlowCallback(
2171cb0ef41Sopenharmony_ci      const FunctionCallbackInfo<Value>& args) {
2181cb0ef41Sopenharmony_ci    Isolate* isolate = args.GetIsolate();
2191cb0ef41Sopenharmony_ci
2201cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
2211cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
2221cb0ef41Sopenharmony_ci
2231cb0ef41Sopenharmony_ci    HandleScope handle_scope(isolate);
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ci    if (args.Length() < 2) {
2261cb0ef41Sopenharmony_ci      self->slow_call_count_++;
2271cb0ef41Sopenharmony_ci      isolate->ThrowError("This method expects at least 2 arguments.");
2281cb0ef41Sopenharmony_ci      return;
2291cb0ef41Sopenharmony_ci    }
2301cb0ef41Sopenharmony_ci    if (args[1]->IsTypedArray()) {
2311cb0ef41Sopenharmony_ci      AddAllTypedArraySlowCallback(args);
2321cb0ef41Sopenharmony_ci      return;
2331cb0ef41Sopenharmony_ci    }
2341cb0ef41Sopenharmony_ci    self->slow_call_count_++;
2351cb0ef41Sopenharmony_ci    if (args[1]->IsUndefined()) {
2361cb0ef41Sopenharmony_ci      Type dummy_result = 0;
2371cb0ef41Sopenharmony_ci      args.GetReturnValue().Set(Number::New(isolate, dummy_result));
2381cb0ef41Sopenharmony_ci      return;
2391cb0ef41Sopenharmony_ci    }
2401cb0ef41Sopenharmony_ci    if (!args[1]->IsArray()) {
2411cb0ef41Sopenharmony_ci      isolate->ThrowError("This method expects an array as a second argument.");
2421cb0ef41Sopenharmony_ci      return;
2431cb0ef41Sopenharmony_ci    }
2441cb0ef41Sopenharmony_ci
2451cb0ef41Sopenharmony_ci    Local<Array> seq_arg = args[1].As<Array>();
2461cb0ef41Sopenharmony_ci    uint32_t length = seq_arg->Length();
2471cb0ef41Sopenharmony_ci    if (length > 1024) {
2481cb0ef41Sopenharmony_ci      isolate->ThrowError(
2491cb0ef41Sopenharmony_ci          "Invalid length of array, must be between 0 and 1024.");
2501cb0ef41Sopenharmony_ci      return;
2511cb0ef41Sopenharmony_ci    }
2521cb0ef41Sopenharmony_ci
2531cb0ef41Sopenharmony_ci    Type sum = 0;
2541cb0ef41Sopenharmony_ci    for (uint32_t i = 0; i < length; ++i) {
2551cb0ef41Sopenharmony_ci      v8::Local<v8::Value> element =
2561cb0ef41Sopenharmony_ci          seq_arg
2571cb0ef41Sopenharmony_ci              ->Get(isolate->GetCurrentContext(),
2581cb0ef41Sopenharmony_ci                    v8::Integer::NewFromUnsigned(isolate, i))
2591cb0ef41Sopenharmony_ci              .ToLocalChecked();
2601cb0ef41Sopenharmony_ci      if (element->IsNumber()) {
2611cb0ef41Sopenharmony_ci        double value = element->ToNumber(isolate->GetCurrentContext())
2621cb0ef41Sopenharmony_ci                           .ToLocalChecked()
2631cb0ef41Sopenharmony_ci                           ->Value();
2641cb0ef41Sopenharmony_ci        sum += value;
2651cb0ef41Sopenharmony_ci      } else if (element->IsUndefined()) {
2661cb0ef41Sopenharmony_ci        // Hole: ignore the element.
2671cb0ef41Sopenharmony_ci      } else {
2681cb0ef41Sopenharmony_ci        isolate->ThrowError("unexpected element type in JSArray");
2691cb0ef41Sopenharmony_ci        return;
2701cb0ef41Sopenharmony_ci      }
2711cb0ef41Sopenharmony_ci    }
2721cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(Number::New(isolate, sum));
2731cb0ef41Sopenharmony_ci  }
2741cb0ef41Sopenharmony_ci#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
2751cb0ef41Sopenharmony_ci  template <typename T>
2761cb0ef41Sopenharmony_ci  static const FastApiTypedArray<T>* AnyCTypeToTypedArray(AnyCType arg);
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_ci  template <>
2791cb0ef41Sopenharmony_ci  const FastApiTypedArray<int32_t>* AnyCTypeToTypedArray<int32_t>(
2801cb0ef41Sopenharmony_ci      AnyCType arg) {
2811cb0ef41Sopenharmony_ci    return arg.int32_ta_value;
2821cb0ef41Sopenharmony_ci  }
2831cb0ef41Sopenharmony_ci  template <>
2841cb0ef41Sopenharmony_ci  const FastApiTypedArray<uint32_t>* AnyCTypeToTypedArray<uint32_t>(
2851cb0ef41Sopenharmony_ci      AnyCType arg) {
2861cb0ef41Sopenharmony_ci    return arg.uint32_ta_value;
2871cb0ef41Sopenharmony_ci  }
2881cb0ef41Sopenharmony_ci  template <>
2891cb0ef41Sopenharmony_ci  const FastApiTypedArray<int64_t>* AnyCTypeToTypedArray<int64_t>(
2901cb0ef41Sopenharmony_ci      AnyCType arg) {
2911cb0ef41Sopenharmony_ci    return arg.int64_ta_value;
2921cb0ef41Sopenharmony_ci  }
2931cb0ef41Sopenharmony_ci  template <>
2941cb0ef41Sopenharmony_ci  const FastApiTypedArray<uint64_t>* AnyCTypeToTypedArray<uint64_t>(
2951cb0ef41Sopenharmony_ci      AnyCType arg) {
2961cb0ef41Sopenharmony_ci    return arg.uint64_ta_value;
2971cb0ef41Sopenharmony_ci  }
2981cb0ef41Sopenharmony_ci  template <>
2991cb0ef41Sopenharmony_ci  const FastApiTypedArray<float>* AnyCTypeToTypedArray<float>(AnyCType arg) {
3001cb0ef41Sopenharmony_ci    return arg.float_ta_value;
3011cb0ef41Sopenharmony_ci  }
3021cb0ef41Sopenharmony_ci  template <>
3031cb0ef41Sopenharmony_ci  const FastApiTypedArray<double>* AnyCTypeToTypedArray<double>(AnyCType arg) {
3041cb0ef41Sopenharmony_ci    return arg.double_ta_value;
3051cb0ef41Sopenharmony_ci  }
3061cb0ef41Sopenharmony_ci
3071cb0ef41Sopenharmony_ci  template <typename T>
3081cb0ef41Sopenharmony_ci  static AnyCType AddAllTypedArrayFastCallbackPatch(AnyCType receiver,
3091cb0ef41Sopenharmony_ci                                                    AnyCType should_fallback,
3101cb0ef41Sopenharmony_ci                                                    AnyCType typed_array_arg,
3111cb0ef41Sopenharmony_ci                                                    AnyCType options) {
3121cb0ef41Sopenharmony_ci    AnyCType ret;
3131cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
3141cb0ef41Sopenharmony_ci    ret.double_value = AddAllTypedArrayFastCallback(
3151cb0ef41Sopenharmony_ci        receiver.object_value, should_fallback.bool_value,
3161cb0ef41Sopenharmony_ci        *AnyCTypeToTypedArray<T>(typed_array_arg), *options.options_value);
3171cb0ef41Sopenharmony_ci#else
3181cb0ef41Sopenharmony_ci    ret.int32_value = AddAllTypedArrayFastCallback(
3191cb0ef41Sopenharmony_ci        receiver.object_value, should_fallback.bool_value,
3201cb0ef41Sopenharmony_ci        *AnyCTypeToTypedArray<T>(typed_array_arg), *options.options_value);
3211cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
3221cb0ef41Sopenharmony_ci    return ret;
3231cb0ef41Sopenharmony_ci  }
3241cb0ef41Sopenharmony_ci#endif  //  V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
3251cb0ef41Sopenharmony_ci  template <typename T>
3261cb0ef41Sopenharmony_ci  static Type AddAllTypedArrayFastCallback(
3271cb0ef41Sopenharmony_ci      Local<Object> receiver, bool should_fallback,
3281cb0ef41Sopenharmony_ci      const FastApiTypedArray<T>& typed_array_arg,
3291cb0ef41Sopenharmony_ci      FastApiCallbackOptions& options) {
3301cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(receiver);
3311cb0ef41Sopenharmony_ci    CHECK_SELF_OR_FALLBACK(0);
3321cb0ef41Sopenharmony_ci    self->fast_call_count_++;
3331cb0ef41Sopenharmony_ci
3341cb0ef41Sopenharmony_ci    if (should_fallback) {
3351cb0ef41Sopenharmony_ci      options.fallback = true;
3361cb0ef41Sopenharmony_ci      return 0;
3371cb0ef41Sopenharmony_ci    }
3381cb0ef41Sopenharmony_ci
3391cb0ef41Sopenharmony_ci    T sum = 0;
3401cb0ef41Sopenharmony_ci    for (unsigned i = 0; i < typed_array_arg.length(); ++i) {
3411cb0ef41Sopenharmony_ci      sum += typed_array_arg.get(i);
3421cb0ef41Sopenharmony_ci    }
3431cb0ef41Sopenharmony_ci    return static_cast<Type>(sum);
3441cb0ef41Sopenharmony_ci  }
3451cb0ef41Sopenharmony_ci  static void AddAllTypedArraySlowCallback(
3461cb0ef41Sopenharmony_ci      const FunctionCallbackInfo<Value>& args) {
3471cb0ef41Sopenharmony_ci    Isolate* isolate = args.GetIsolate();
3481cb0ef41Sopenharmony_ci
3491cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
3501cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
3511cb0ef41Sopenharmony_ci    self->slow_call_count_++;
3521cb0ef41Sopenharmony_ci
3531cb0ef41Sopenharmony_ci    HandleScope handle_scope(isolate);
3541cb0ef41Sopenharmony_ci
3551cb0ef41Sopenharmony_ci    if (args.Length() < 2) {
3561cb0ef41Sopenharmony_ci      isolate->ThrowError("This method expects at least 2 arguments.");
3571cb0ef41Sopenharmony_ci      return;
3581cb0ef41Sopenharmony_ci    }
3591cb0ef41Sopenharmony_ci    if (!args[1]->IsTypedArray()) {
3601cb0ef41Sopenharmony_ci      isolate->ThrowError(
3611cb0ef41Sopenharmony_ci          "This method expects a TypedArray as a second argument.");
3621cb0ef41Sopenharmony_ci      return;
3631cb0ef41Sopenharmony_ci    }
3641cb0ef41Sopenharmony_ci
3651cb0ef41Sopenharmony_ci    Local<TypedArray> typed_array_arg = args[1].As<TypedArray>();
3661cb0ef41Sopenharmony_ci    size_t length = typed_array_arg->Length();
3671cb0ef41Sopenharmony_ci
3681cb0ef41Sopenharmony_ci    void* data = typed_array_arg->Buffer()->GetBackingStore()->Data();
3691cb0ef41Sopenharmony_ci    if (typed_array_arg->IsInt32Array() || typed_array_arg->IsUint32Array() ||
3701cb0ef41Sopenharmony_ci        typed_array_arg->IsBigInt64Array() ||
3711cb0ef41Sopenharmony_ci        typed_array_arg->IsBigUint64Array()) {
3721cb0ef41Sopenharmony_ci      int64_t sum = 0;
3731cb0ef41Sopenharmony_ci      for (unsigned i = 0; i < length; ++i) {
3741cb0ef41Sopenharmony_ci        if (typed_array_arg->IsInt32Array()) {
3751cb0ef41Sopenharmony_ci          sum += static_cast<int32_t*>(data)[i];
3761cb0ef41Sopenharmony_ci        } else if (typed_array_arg->IsUint32Array()) {
3771cb0ef41Sopenharmony_ci          sum += static_cast<uint32_t*>(data)[i];
3781cb0ef41Sopenharmony_ci        } else if (typed_array_arg->IsBigInt64Array()) {
3791cb0ef41Sopenharmony_ci          sum += static_cast<int64_t*>(data)[i];
3801cb0ef41Sopenharmony_ci        } else if (typed_array_arg->IsBigUint64Array()) {
3811cb0ef41Sopenharmony_ci          sum += static_cast<uint64_t*>(data)[i];
3821cb0ef41Sopenharmony_ci        }
3831cb0ef41Sopenharmony_ci      }
3841cb0ef41Sopenharmony_ci      args.GetReturnValue().Set(Number::New(isolate, sum));
3851cb0ef41Sopenharmony_ci    } else if (typed_array_arg->IsFloat32Array() ||
3861cb0ef41Sopenharmony_ci               typed_array_arg->IsFloat64Array()) {
3871cb0ef41Sopenharmony_ci      double sum = 0;
3881cb0ef41Sopenharmony_ci      for (unsigned i = 0; i < length; ++i) {
3891cb0ef41Sopenharmony_ci        if (typed_array_arg->IsFloat32Array()) {
3901cb0ef41Sopenharmony_ci          sum += static_cast<float*>(data)[i];
3911cb0ef41Sopenharmony_ci        } else if (typed_array_arg->IsFloat64Array()) {
3921cb0ef41Sopenharmony_ci          sum += static_cast<double*>(data)[i];
3931cb0ef41Sopenharmony_ci        }
3941cb0ef41Sopenharmony_ci      }
3951cb0ef41Sopenharmony_ci      args.GetReturnValue().Set(Number::New(isolate, sum));
3961cb0ef41Sopenharmony_ci    } else {
3971cb0ef41Sopenharmony_ci      isolate->ThrowError("TypedArray type is not supported.");
3981cb0ef41Sopenharmony_ci      return;
3991cb0ef41Sopenharmony_ci    }
4001cb0ef41Sopenharmony_ci  }
4011cb0ef41Sopenharmony_ci
4021cb0ef41Sopenharmony_ci  static int32_t AddAllIntInvalidCallback(Local<Object> receiver,
4031cb0ef41Sopenharmony_ci                                          bool should_fallback, int32_t arg_i32,
4041cb0ef41Sopenharmony_ci                                          FastApiCallbackOptions& options) {
4051cb0ef41Sopenharmony_ci    // This should never be called
4061cb0ef41Sopenharmony_ci    UNREACHABLE();
4071cb0ef41Sopenharmony_ci  }
4081cb0ef41Sopenharmony_ci
4091cb0ef41Sopenharmony_ci#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
4101cb0ef41Sopenharmony_ci  static AnyCType Add32BitIntFastCallbackPatch(AnyCType receiver,
4111cb0ef41Sopenharmony_ci                                               AnyCType should_fallback,
4121cb0ef41Sopenharmony_ci                                               AnyCType arg_i32,
4131cb0ef41Sopenharmony_ci                                               AnyCType arg_u32,
4141cb0ef41Sopenharmony_ci                                               AnyCType options) {
4151cb0ef41Sopenharmony_ci    AnyCType ret;
4161cb0ef41Sopenharmony_ci    ret.int32_value = Add32BitIntFastCallback(
4171cb0ef41Sopenharmony_ci        receiver.object_value, should_fallback.bool_value, arg_i32.int32_value,
4181cb0ef41Sopenharmony_ci        arg_u32.uint32_value, *options.options_value);
4191cb0ef41Sopenharmony_ci    return ret;
4201cb0ef41Sopenharmony_ci  }
4211cb0ef41Sopenharmony_ci#endif  //  V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
4221cb0ef41Sopenharmony_ci
4231cb0ef41Sopenharmony_ci  static int Add32BitIntFastCallback(v8::Local<v8::Object> receiver,
4241cb0ef41Sopenharmony_ci                                     bool should_fallback, int32_t arg_i32,
4251cb0ef41Sopenharmony_ci                                     uint32_t arg_u32,
4261cb0ef41Sopenharmony_ci                                     FastApiCallbackOptions& options) {
4271cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(receiver);
4281cb0ef41Sopenharmony_ci    CHECK_SELF_OR_FALLBACK(0);
4291cb0ef41Sopenharmony_ci    self->fast_call_count_++;
4301cb0ef41Sopenharmony_ci
4311cb0ef41Sopenharmony_ci    if (should_fallback) {
4321cb0ef41Sopenharmony_ci      options.fallback = true;
4331cb0ef41Sopenharmony_ci      return 0;
4341cb0ef41Sopenharmony_ci    }
4351cb0ef41Sopenharmony_ci
4361cb0ef41Sopenharmony_ci    return arg_i32 + arg_u32;
4371cb0ef41Sopenharmony_ci  }
4381cb0ef41Sopenharmony_ci  static void Add32BitIntSlowCallback(const FunctionCallbackInfo<Value>& args) {
4391cb0ef41Sopenharmony_ci    Isolate* isolate = args.GetIsolate();
4401cb0ef41Sopenharmony_ci
4411cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
4421cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
4431cb0ef41Sopenharmony_ci    self->slow_call_count_++;
4441cb0ef41Sopenharmony_ci
4451cb0ef41Sopenharmony_ci    HandleScope handle_scope(isolate);
4461cb0ef41Sopenharmony_ci
4471cb0ef41Sopenharmony_ci    double sum = 0;
4481cb0ef41Sopenharmony_ci    if (args.Length() > 1 && args[1]->IsNumber()) {
4491cb0ef41Sopenharmony_ci      sum += args[1]->Int32Value(isolate->GetCurrentContext()).FromJust();
4501cb0ef41Sopenharmony_ci    }
4511cb0ef41Sopenharmony_ci    if (args.Length() > 2 && args[2]->IsNumber()) {
4521cb0ef41Sopenharmony_ci      sum += args[2]->Uint32Value(isolate->GetCurrentContext()).FromJust();
4531cb0ef41Sopenharmony_ci    }
4541cb0ef41Sopenharmony_ci
4551cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(Number::New(isolate, sum));
4561cb0ef41Sopenharmony_ci  }
4571cb0ef41Sopenharmony_ci
4581cb0ef41Sopenharmony_ci#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
4591cb0ef41Sopenharmony_ci  static AnyCType AddAll32BitIntFastCallback_8ArgsPatch(
4601cb0ef41Sopenharmony_ci      AnyCType receiver, AnyCType should_fallback, AnyCType arg1_i32,
4611cb0ef41Sopenharmony_ci      AnyCType arg2_i32, AnyCType arg3_i32, AnyCType arg4_u32,
4621cb0ef41Sopenharmony_ci      AnyCType arg5_u32, AnyCType arg6_u32, AnyCType arg7_u32,
4631cb0ef41Sopenharmony_ci      AnyCType arg8_u32, AnyCType options) {
4641cb0ef41Sopenharmony_ci    AnyCType ret;
4651cb0ef41Sopenharmony_ci    ret.int32_value = AddAll32BitIntFastCallback_8Args(
4661cb0ef41Sopenharmony_ci        receiver.object_value, should_fallback.bool_value, arg1_i32.int32_value,
4671cb0ef41Sopenharmony_ci        arg2_i32.int32_value, arg3_i32.int32_value, arg4_u32.uint32_value,
4681cb0ef41Sopenharmony_ci        arg5_u32.uint32_value, arg6_u32.uint32_value, arg7_u32.uint32_value,
4691cb0ef41Sopenharmony_ci        arg8_u32.uint32_value, *options.options_value);
4701cb0ef41Sopenharmony_ci    return ret;
4711cb0ef41Sopenharmony_ci  }
4721cb0ef41Sopenharmony_ci  static AnyCType AddAll32BitIntFastCallback_6ArgsPatch(
4731cb0ef41Sopenharmony_ci      AnyCType receiver, AnyCType should_fallback, AnyCType arg1_i32,
4741cb0ef41Sopenharmony_ci      AnyCType arg2_i32, AnyCType arg3_i32, AnyCType arg4_u32,
4751cb0ef41Sopenharmony_ci      AnyCType arg5_u32, AnyCType arg6_u32, AnyCType options) {
4761cb0ef41Sopenharmony_ci    AnyCType ret;
4771cb0ef41Sopenharmony_ci    ret.int32_value = AddAll32BitIntFastCallback_6Args(
4781cb0ef41Sopenharmony_ci        receiver.object_value, should_fallback.bool_value, arg1_i32.int32_value,
4791cb0ef41Sopenharmony_ci        arg2_i32.int32_value, arg3_i32.int32_value, arg4_u32.uint32_value,
4801cb0ef41Sopenharmony_ci        arg5_u32.uint32_value, arg6_u32.uint32_value, *options.options_value);
4811cb0ef41Sopenharmony_ci    return ret;
4821cb0ef41Sopenharmony_ci  }
4831cb0ef41Sopenharmony_ci  static AnyCType AddAll32BitIntFastCallback_5ArgsPatch(
4841cb0ef41Sopenharmony_ci      AnyCType receiver, AnyCType should_fallback, AnyCType arg1_i32,
4851cb0ef41Sopenharmony_ci      AnyCType arg2_i32, AnyCType arg3_i32, AnyCType arg4_u32,
4861cb0ef41Sopenharmony_ci      AnyCType arg5_u32, AnyCType options) {
4871cb0ef41Sopenharmony_ci    AnyCType arg6;
4881cb0ef41Sopenharmony_ci    arg6.uint32_value = 0;
4891cb0ef41Sopenharmony_ci    return AddAll32BitIntFastCallback_6ArgsPatch(
4901cb0ef41Sopenharmony_ci        receiver, should_fallback, arg1_i32, arg2_i32, arg3_i32, arg4_u32,
4911cb0ef41Sopenharmony_ci        arg5_u32, arg6, options);
4921cb0ef41Sopenharmony_ci  }
4931cb0ef41Sopenharmony_ci#endif  //  V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
4941cb0ef41Sopenharmony_ci
4951cb0ef41Sopenharmony_ci  static int AddAll32BitIntFastCallback_8Args(
4961cb0ef41Sopenharmony_ci      Local<Object> receiver, bool should_fallback, int32_t arg1_i32,
4971cb0ef41Sopenharmony_ci      int32_t arg2_i32, int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32,
4981cb0ef41Sopenharmony_ci      uint32_t arg6_u32, uint32_t arg7_u32, uint32_t arg8_u32,
4991cb0ef41Sopenharmony_ci      FastApiCallbackOptions& options) {
5001cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(receiver);
5011cb0ef41Sopenharmony_ci    CHECK_SELF_OR_FALLBACK(0);
5021cb0ef41Sopenharmony_ci    self->fast_call_count_++;
5031cb0ef41Sopenharmony_ci
5041cb0ef41Sopenharmony_ci    if (should_fallback) {
5051cb0ef41Sopenharmony_ci      options.fallback = true;
5061cb0ef41Sopenharmony_ci      return 0;
5071cb0ef41Sopenharmony_ci    }
5081cb0ef41Sopenharmony_ci
5091cb0ef41Sopenharmony_ci    int64_t result = static_cast<int64_t>(arg1_i32) + arg2_i32 + arg3_i32 +
5101cb0ef41Sopenharmony_ci                     arg4_u32 + arg5_u32 + arg6_u32 + arg7_u32 + arg8_u32;
5111cb0ef41Sopenharmony_ci    if (result > INT_MAX) return INT_MAX;
5121cb0ef41Sopenharmony_ci    if (result < INT_MIN) return INT_MIN;
5131cb0ef41Sopenharmony_ci    return static_cast<int>(result);
5141cb0ef41Sopenharmony_ci  }
5151cb0ef41Sopenharmony_ci  static int AddAll32BitIntFastCallback_6Args(
5161cb0ef41Sopenharmony_ci      Local<Object> receiver, bool should_fallback, int32_t arg1_i32,
5171cb0ef41Sopenharmony_ci      int32_t arg2_i32, int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32,
5181cb0ef41Sopenharmony_ci      uint32_t arg6_u32, FastApiCallbackOptions& options) {
5191cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(receiver);
5201cb0ef41Sopenharmony_ci    CHECK_SELF_OR_FALLBACK(0);
5211cb0ef41Sopenharmony_ci    self->fast_call_count_++;
5221cb0ef41Sopenharmony_ci
5231cb0ef41Sopenharmony_ci    if (should_fallback) {
5241cb0ef41Sopenharmony_ci      options.fallback = true;
5251cb0ef41Sopenharmony_ci      return 0;
5261cb0ef41Sopenharmony_ci    }
5271cb0ef41Sopenharmony_ci
5281cb0ef41Sopenharmony_ci    int64_t result = static_cast<int64_t>(arg1_i32) + arg2_i32 + arg3_i32 +
5291cb0ef41Sopenharmony_ci                     arg4_u32 + arg5_u32 + arg6_u32;
5301cb0ef41Sopenharmony_ci    if (result > INT_MAX) return INT_MAX;
5311cb0ef41Sopenharmony_ci    if (result < INT_MIN) return INT_MIN;
5321cb0ef41Sopenharmony_ci    return static_cast<int>(result);
5331cb0ef41Sopenharmony_ci  }
5341cb0ef41Sopenharmony_ci  static int AddAll32BitIntFastCallback_5Args(
5351cb0ef41Sopenharmony_ci      Local<Object> receiver, bool should_fallback, int32_t arg1_i32,
5361cb0ef41Sopenharmony_ci      int32_t arg2_i32, int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32,
5371cb0ef41Sopenharmony_ci      FastApiCallbackOptions& options) {
5381cb0ef41Sopenharmony_ci    return AddAll32BitIntFastCallback_6Args(receiver, should_fallback, arg1_i32,
5391cb0ef41Sopenharmony_ci                                            arg2_i32, arg3_i32, arg4_u32,
5401cb0ef41Sopenharmony_ci                                            arg5_u32, 0, options);
5411cb0ef41Sopenharmony_ci  }
5421cb0ef41Sopenharmony_ci  static void AddAll32BitIntSlowCallback(
5431cb0ef41Sopenharmony_ci      const FunctionCallbackInfo<Value>& args) {
5441cb0ef41Sopenharmony_ci    Isolate* isolate = args.GetIsolate();
5451cb0ef41Sopenharmony_ci
5461cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
5471cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
5481cb0ef41Sopenharmony_ci    self->slow_call_count_++;
5491cb0ef41Sopenharmony_ci
5501cb0ef41Sopenharmony_ci    HandleScope handle_scope(isolate);
5511cb0ef41Sopenharmony_ci
5521cb0ef41Sopenharmony_ci    Local<Context> context = isolate->GetCurrentContext();
5531cb0ef41Sopenharmony_ci    double sum = 0;
5541cb0ef41Sopenharmony_ci    if (args.Length() > 1 && args[1]->IsNumber()) {
5551cb0ef41Sopenharmony_ci      sum += args[1]->Int32Value(context).FromJust();
5561cb0ef41Sopenharmony_ci    }
5571cb0ef41Sopenharmony_ci    if (args.Length() > 2 && args[2]->IsNumber()) {
5581cb0ef41Sopenharmony_ci      sum += args[2]->Int32Value(context).FromJust();
5591cb0ef41Sopenharmony_ci    }
5601cb0ef41Sopenharmony_ci    if (args.Length() > 3 && args[3]->IsNumber()) {
5611cb0ef41Sopenharmony_ci      sum += args[3]->Int32Value(context).FromJust();
5621cb0ef41Sopenharmony_ci    }
5631cb0ef41Sopenharmony_ci    if (args.Length() > 4 && args[4]->IsNumber()) {
5641cb0ef41Sopenharmony_ci      sum += args[4]->Uint32Value(context).FromJust();
5651cb0ef41Sopenharmony_ci    }
5661cb0ef41Sopenharmony_ci    if (args.Length() > 5 && args[5]->IsNumber()) {
5671cb0ef41Sopenharmony_ci      sum += args[5]->Uint32Value(context).FromJust();
5681cb0ef41Sopenharmony_ci    }
5691cb0ef41Sopenharmony_ci    if (args.Length() > 6 && args[6]->IsNumber()) {
5701cb0ef41Sopenharmony_ci      sum += args[6]->Uint32Value(context).FromJust();
5711cb0ef41Sopenharmony_ci    }
5721cb0ef41Sopenharmony_ci    if (args.Length() > 7 && args[7]->IsNumber() && args[8]->IsNumber()) {
5731cb0ef41Sopenharmony_ci      sum += args[7]->Uint32Value(context).FromJust();
5741cb0ef41Sopenharmony_ci      sum += args[8]->Uint32Value(context).FromJust();
5751cb0ef41Sopenharmony_ci    }
5761cb0ef41Sopenharmony_ci
5771cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(Number::New(isolate, sum));
5781cb0ef41Sopenharmony_ci  }
5791cb0ef41Sopenharmony_ci
5801cb0ef41Sopenharmony_ci  static bool IsFastCApiObjectFastCallback(v8::Local<v8::Object> receiver,
5811cb0ef41Sopenharmony_ci                                           bool should_fallback,
5821cb0ef41Sopenharmony_ci                                           v8::Local<v8::Value> arg,
5831cb0ef41Sopenharmony_ci                                           FastApiCallbackOptions& options) {
5841cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(receiver);
5851cb0ef41Sopenharmony_ci    CHECK_SELF_OR_FALLBACK(false);
5861cb0ef41Sopenharmony_ci    self->fast_call_count_++;
5871cb0ef41Sopenharmony_ci
5881cb0ef41Sopenharmony_ci    if (should_fallback) {
5891cb0ef41Sopenharmony_ci      options.fallback = true;
5901cb0ef41Sopenharmony_ci      return false;
5911cb0ef41Sopenharmony_ci    }
5921cb0ef41Sopenharmony_ci
5931cb0ef41Sopenharmony_ci    if (!arg->IsObject()) {
5941cb0ef41Sopenharmony_ci      return false;
5951cb0ef41Sopenharmony_ci    }
5961cb0ef41Sopenharmony_ci    Local<Object> object = arg.As<Object>();
5971cb0ef41Sopenharmony_ci    if (!IsValidApiObject(object)) return false;
5981cb0ef41Sopenharmony_ci
5991cb0ef41Sopenharmony_ci    internal::Isolate* i_isolate =
6001cb0ef41Sopenharmony_ci        internal::IsolateFromNeverReadOnlySpaceObject(
6011cb0ef41Sopenharmony_ci            *reinterpret_cast<internal::Address*>(*object));
6021cb0ef41Sopenharmony_ci    CHECK_NOT_NULL(i_isolate);
6031cb0ef41Sopenharmony_ci    Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
6041cb0ef41Sopenharmony_ci    HandleScope handle_scope(isolate);
6051cb0ef41Sopenharmony_ci    return PerIsolateData::Get(isolate)
6061cb0ef41Sopenharmony_ci        ->GetTestApiObjectCtor()
6071cb0ef41Sopenharmony_ci        ->IsLeafTemplateForApiObject(object);
6081cb0ef41Sopenharmony_ci  }
6091cb0ef41Sopenharmony_ci  static void IsFastCApiObjectSlowCallback(
6101cb0ef41Sopenharmony_ci      const FunctionCallbackInfo<Value>& args) {
6111cb0ef41Sopenharmony_ci    Isolate* isolate = args.GetIsolate();
6121cb0ef41Sopenharmony_ci
6131cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
6141cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
6151cb0ef41Sopenharmony_ci    self->slow_call_count_++;
6161cb0ef41Sopenharmony_ci
6171cb0ef41Sopenharmony_ci    HandleScope handle_scope(isolate);
6181cb0ef41Sopenharmony_ci
6191cb0ef41Sopenharmony_ci    bool result = false;
6201cb0ef41Sopenharmony_ci    if (args.Length() < 2) {
6211cb0ef41Sopenharmony_ci      args.GetIsolate()->ThrowError(
6221cb0ef41Sopenharmony_ci          "is_valid_api_object should be called with 2 arguments");
6231cb0ef41Sopenharmony_ci      return;
6241cb0ef41Sopenharmony_ci    }
6251cb0ef41Sopenharmony_ci    if (args[1]->IsObject()) {
6261cb0ef41Sopenharmony_ci      Local<Object> object = args[1].As<Object>();
6271cb0ef41Sopenharmony_ci      if (!IsValidApiObject(object)) {
6281cb0ef41Sopenharmony_ci        result = false;
6291cb0ef41Sopenharmony_ci      } else {
6301cb0ef41Sopenharmony_ci        result = PerIsolateData::Get(args.GetIsolate())
6311cb0ef41Sopenharmony_ci                     ->GetTestApiObjectCtor()
6321cb0ef41Sopenharmony_ci                     ->IsLeafTemplateForApiObject(object);
6331cb0ef41Sopenharmony_ci      }
6341cb0ef41Sopenharmony_ci    }
6351cb0ef41Sopenharmony_ci
6361cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(Boolean::New(isolate, result));
6371cb0ef41Sopenharmony_ci  }
6381cb0ef41Sopenharmony_ci
6391cb0ef41Sopenharmony_ci  static void FastCallCount(const FunctionCallbackInfo<Value>& args) {
6401cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
6411cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
6421cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(
6431cb0ef41Sopenharmony_ci        Number::New(args.GetIsolate(), self->fast_call_count()));
6441cb0ef41Sopenharmony_ci  }
6451cb0ef41Sopenharmony_ci  static void SlowCallCount(const FunctionCallbackInfo<Value>& args) {
6461cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
6471cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
6481cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(
6491cb0ef41Sopenharmony_ci        Number::New(args.GetIsolate(), self->slow_call_count()));
6501cb0ef41Sopenharmony_ci  }
6511cb0ef41Sopenharmony_ci  static void ResetCounts(const FunctionCallbackInfo<Value>& args) {
6521cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
6531cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
6541cb0ef41Sopenharmony_ci    self->reset_counts();
6551cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(Undefined(args.GetIsolate()));
6561cb0ef41Sopenharmony_ci  }
6571cb0ef41Sopenharmony_ci  static void SupportsFPParams(const FunctionCallbackInfo<Value>& args) {
6581cb0ef41Sopenharmony_ci    FastCApiObject* self = UnwrapObject(args.This());
6591cb0ef41Sopenharmony_ci    CHECK_SELF_OR_THROW();
6601cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(self->supports_fp_params_);
6611cb0ef41Sopenharmony_ci  }
6621cb0ef41Sopenharmony_ci
6631cb0ef41Sopenharmony_ci  int fast_call_count() const { return fast_call_count_; }
6641cb0ef41Sopenharmony_ci  int slow_call_count() const { return slow_call_count_; }
6651cb0ef41Sopenharmony_ci  void reset_counts() {
6661cb0ef41Sopenharmony_ci    fast_call_count_ = 0;
6671cb0ef41Sopenharmony_ci    slow_call_count_ = 0;
6681cb0ef41Sopenharmony_ci  }
6691cb0ef41Sopenharmony_ci
6701cb0ef41Sopenharmony_ci  static const int kV8WrapperObjectIndex = 1;
6711cb0ef41Sopenharmony_ci
6721cb0ef41Sopenharmony_ci private:
6731cb0ef41Sopenharmony_ci  static bool IsValidApiObject(Local<Object> object) {
6741cb0ef41Sopenharmony_ci    i::Address addr = *reinterpret_cast<i::Address*>(*object);
6751cb0ef41Sopenharmony_ci    auto instance_type = i::Internals::GetInstanceType(addr);
6761cb0ef41Sopenharmony_ci    return (base::IsInRange(instance_type, i::Internals::kFirstJSApiObjectType,
6771cb0ef41Sopenharmony_ci                            i::Internals::kLastJSApiObjectType) ||
6781cb0ef41Sopenharmony_ci            instance_type == i::Internals::kJSSpecialApiObjectType);
6791cb0ef41Sopenharmony_ci  }
6801cb0ef41Sopenharmony_ci  static FastCApiObject* UnwrapObject(Local<Object> object) {
6811cb0ef41Sopenharmony_ci    if (!IsValidApiObject(object)) {
6821cb0ef41Sopenharmony_ci      return nullptr;
6831cb0ef41Sopenharmony_ci    }
6841cb0ef41Sopenharmony_ci    FastCApiObject* wrapped = reinterpret_cast<FastCApiObject*>(
6851cb0ef41Sopenharmony_ci        object->GetAlignedPointerFromInternalField(kV8WrapperObjectIndex));
6861cb0ef41Sopenharmony_ci    CHECK_NOT_NULL(wrapped);
6871cb0ef41Sopenharmony_ci    return wrapped;
6881cb0ef41Sopenharmony_ci  }
6891cb0ef41Sopenharmony_ci  int fast_call_count_ = 0, slow_call_count_ = 0;
6901cb0ef41Sopenharmony_ci#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
6911cb0ef41Sopenharmony_ci  bool supports_fp_params_ = true;
6921cb0ef41Sopenharmony_ci#else   // V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
6931cb0ef41Sopenharmony_ci  bool supports_fp_params_ = false;
6941cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
6951cb0ef41Sopenharmony_ci};
6961cb0ef41Sopenharmony_ci
6971cb0ef41Sopenharmony_ci#undef CHECK_SELF_OR_THROW
6981cb0ef41Sopenharmony_ci#undef CHECK_SELF_OR_FALLBACK
6991cb0ef41Sopenharmony_ci
7001cb0ef41Sopenharmony_ci// The object is statically initialized for simplicity, typically the embedder
7011cb0ef41Sopenharmony_ci// will take care of managing their C++ objects lifetime.
7021cb0ef41Sopenharmony_cithread_local FastCApiObject kFastCApiObject;
7031cb0ef41Sopenharmony_ci}  // namespace
7041cb0ef41Sopenharmony_ci
7051cb0ef41Sopenharmony_ci// static
7061cb0ef41Sopenharmony_ciFastCApiObject& FastCApiObject::instance() { return kFastCApiObject; }
7071cb0ef41Sopenharmony_ci
7081cb0ef41Sopenharmony_civoid CreateFastCAPIObject(const FunctionCallbackInfo<Value>& info) {
7091cb0ef41Sopenharmony_ci  if (!info.IsConstructCall()) {
7101cb0ef41Sopenharmony_ci    info.GetIsolate()->ThrowError(
7111cb0ef41Sopenharmony_ci        "FastCAPI helper must be constructed with new.");
7121cb0ef41Sopenharmony_ci    return;
7131cb0ef41Sopenharmony_ci  }
7141cb0ef41Sopenharmony_ci  Local<Object> api_object = info.Holder();
7151cb0ef41Sopenharmony_ci  api_object->SetAlignedPointerInInternalField(
7161cb0ef41Sopenharmony_ci      FastCApiObject::kV8WrapperObjectIndex,
7171cb0ef41Sopenharmony_ci      reinterpret_cast<void*>(&kFastCApiObject));
7181cb0ef41Sopenharmony_ci  api_object->SetAccessorProperty(
7191cb0ef41Sopenharmony_ci      String::NewFromUtf8Literal(info.GetIsolate(), "supports_fp_params"),
7201cb0ef41Sopenharmony_ci      FunctionTemplate::New(info.GetIsolate(), FastCApiObject::SupportsFPParams)
7211cb0ef41Sopenharmony_ci          ->GetFunction(api_object->GetCreationContext().ToLocalChecked())
7221cb0ef41Sopenharmony_ci          .ToLocalChecked());
7231cb0ef41Sopenharmony_ci}
7241cb0ef41Sopenharmony_ci
7251cb0ef41Sopenharmony_ciLocal<FunctionTemplate> Shell::CreateTestFastCApiTemplate(Isolate* isolate) {
7261cb0ef41Sopenharmony_ci  Local<FunctionTemplate> api_obj_ctor =
7271cb0ef41Sopenharmony_ci      FunctionTemplate::New(isolate, CreateFastCAPIObject);
7281cb0ef41Sopenharmony_ci  PerIsolateData::Get(isolate)->SetTestApiObjectCtor(api_obj_ctor);
7291cb0ef41Sopenharmony_ci  Local<Signature> signature = Signature::New(isolate, api_obj_ctor);
7301cb0ef41Sopenharmony_ci  {
7311cb0ef41Sopenharmony_ci    CFunction add_all_c_func =
7321cb0ef41Sopenharmony_ci        CFunction::Make(FastCApiObject::AddAllFastCallback V8_IF_USE_SIMULATOR(
7331cb0ef41Sopenharmony_ci            FastCApiObject::AddAllFastCallbackPatch));
7341cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
7351cb0ef41Sopenharmony_ci        isolate, "add_all",
7361cb0ef41Sopenharmony_ci        FunctionTemplate::New(isolate, FastCApiObject::AddAllSlowCallback,
7371cb0ef41Sopenharmony_ci                              Local<Value>(), signature, 1,
7381cb0ef41Sopenharmony_ci                              ConstructorBehavior::kThrow,
7391cb0ef41Sopenharmony_ci                              SideEffectType::kHasSideEffect, &add_all_c_func));
7401cb0ef41Sopenharmony_ci
7411cb0ef41Sopenharmony_ci    CFunction add_all_seq_c_func = CFunction::Make(
7421cb0ef41Sopenharmony_ci        FastCApiObject::AddAllSequenceFastCallback V8_IF_USE_SIMULATOR(
7431cb0ef41Sopenharmony_ci            FastCApiObject::AddAllSequenceFastCallbackPatch));
7441cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
7451cb0ef41Sopenharmony_ci        isolate, "add_all_sequence",
7461cb0ef41Sopenharmony_ci        FunctionTemplate::New(
7471cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllSequenceSlowCallback, Local<Value>(),
7481cb0ef41Sopenharmony_ci            signature, 1, ConstructorBehavior::kThrow,
7491cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, &add_all_seq_c_func));
7501cb0ef41Sopenharmony_ci
7511cb0ef41Sopenharmony_ci    CFunction add_all_int32_typed_array_c_func = CFunction::Make(
7521cb0ef41Sopenharmony_ci        FastCApiObject::AddAllTypedArrayFastCallback<int32_t>
7531cb0ef41Sopenharmony_ci            V8_IF_USE_SIMULATOR(
7541cb0ef41Sopenharmony_ci                FastCApiObject::AddAllTypedArrayFastCallbackPatch<int32_t>));
7551cb0ef41Sopenharmony_ci
7561cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
7571cb0ef41Sopenharmony_ci        isolate, "add_all_int32_typed_array",
7581cb0ef41Sopenharmony_ci        FunctionTemplate::New(
7591cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllTypedArraySlowCallback,
7601cb0ef41Sopenharmony_ci            Local<Value>(), signature, 1, ConstructorBehavior::kThrow,
7611cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, &add_all_int32_typed_array_c_func));
7621cb0ef41Sopenharmony_ci
7631cb0ef41Sopenharmony_ci    CFunction add_all_int64_typed_array_c_func = CFunction::Make(
7641cb0ef41Sopenharmony_ci        FastCApiObject::AddAllTypedArrayFastCallback<int64_t>
7651cb0ef41Sopenharmony_ci            V8_IF_USE_SIMULATOR(
7661cb0ef41Sopenharmony_ci                FastCApiObject::AddAllTypedArrayFastCallbackPatch<int64_t>));
7671cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
7681cb0ef41Sopenharmony_ci        isolate, "add_all_int64_typed_array",
7691cb0ef41Sopenharmony_ci        FunctionTemplate::New(
7701cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllTypedArraySlowCallback,
7711cb0ef41Sopenharmony_ci            Local<Value>(), signature, 1, ConstructorBehavior::kThrow,
7721cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, &add_all_int64_typed_array_c_func));
7731cb0ef41Sopenharmony_ci
7741cb0ef41Sopenharmony_ci    CFunction add_all_uint64_typed_array_c_func = CFunction::Make(
7751cb0ef41Sopenharmony_ci        FastCApiObject::AddAllTypedArrayFastCallback<uint64_t>
7761cb0ef41Sopenharmony_ci            V8_IF_USE_SIMULATOR(
7771cb0ef41Sopenharmony_ci                FastCApiObject::AddAllTypedArrayFastCallbackPatch<uint64_t>));
7781cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
7791cb0ef41Sopenharmony_ci        isolate, "add_all_uint64_typed_array",
7801cb0ef41Sopenharmony_ci        FunctionTemplate::New(
7811cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllTypedArraySlowCallback,
7821cb0ef41Sopenharmony_ci            Local<Value>(), signature, 1, ConstructorBehavior::kThrow,
7831cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect,
7841cb0ef41Sopenharmony_ci            &add_all_uint64_typed_array_c_func));
7851cb0ef41Sopenharmony_ci
7861cb0ef41Sopenharmony_ci    CFunction add_all_uint32_typed_array_c_func = CFunction::Make(
7871cb0ef41Sopenharmony_ci        FastCApiObject::AddAllTypedArrayFastCallback<uint32_t>
7881cb0ef41Sopenharmony_ci            V8_IF_USE_SIMULATOR(
7891cb0ef41Sopenharmony_ci                FastCApiObject::AddAllTypedArrayFastCallbackPatch<uint32_t>));
7901cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
7911cb0ef41Sopenharmony_ci        isolate, "add_all_uint32_typed_array",
7921cb0ef41Sopenharmony_ci        FunctionTemplate::New(
7931cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllTypedArraySlowCallback,
7941cb0ef41Sopenharmony_ci            Local<Value>(), signature, 1, ConstructorBehavior::kThrow,
7951cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect,
7961cb0ef41Sopenharmony_ci            &add_all_uint32_typed_array_c_func));
7971cb0ef41Sopenharmony_ci
7981cb0ef41Sopenharmony_ci    CFunction add_all_float32_typed_array_c_func = CFunction::Make(
7991cb0ef41Sopenharmony_ci        FastCApiObject::AddAllTypedArrayFastCallback<float> V8_IF_USE_SIMULATOR(
8001cb0ef41Sopenharmony_ci            FastCApiObject::AddAllTypedArrayFastCallbackPatch<float>));
8011cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
8021cb0ef41Sopenharmony_ci        isolate, "add_all_float32_typed_array",
8031cb0ef41Sopenharmony_ci        FunctionTemplate::New(
8041cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllTypedArraySlowCallback,
8051cb0ef41Sopenharmony_ci            Local<Value>(), signature, 1, ConstructorBehavior::kThrow,
8061cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect,
8071cb0ef41Sopenharmony_ci            &add_all_float32_typed_array_c_func));
8081cb0ef41Sopenharmony_ci
8091cb0ef41Sopenharmony_ci    CFunction add_all_float64_typed_array_c_func = CFunction::Make(
8101cb0ef41Sopenharmony_ci        FastCApiObject::AddAllTypedArrayFastCallback<double>
8111cb0ef41Sopenharmony_ci            V8_IF_USE_SIMULATOR(
8121cb0ef41Sopenharmony_ci                FastCApiObject::AddAllTypedArrayFastCallbackPatch<double>));
8131cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
8141cb0ef41Sopenharmony_ci        isolate, "add_all_float64_typed_array",
8151cb0ef41Sopenharmony_ci        FunctionTemplate::New(
8161cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllTypedArraySlowCallback,
8171cb0ef41Sopenharmony_ci            Local<Value>(), signature, 1, ConstructorBehavior::kThrow,
8181cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect,
8191cb0ef41Sopenharmony_ci            &add_all_float64_typed_array_c_func));
8201cb0ef41Sopenharmony_ci
8211cb0ef41Sopenharmony_ci    const CFunction add_all_overloads[] = {
8221cb0ef41Sopenharmony_ci        add_all_uint32_typed_array_c_func,
8231cb0ef41Sopenharmony_ci        add_all_seq_c_func,
8241cb0ef41Sopenharmony_ci    };
8251cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
8261cb0ef41Sopenharmony_ci        isolate, "add_all_overload",
8271cb0ef41Sopenharmony_ci        FunctionTemplate::NewWithCFunctionOverloads(
8281cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllSequenceSlowCallback, Local<Value>(),
8291cb0ef41Sopenharmony_ci            signature, 1, ConstructorBehavior::kThrow,
8301cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, {add_all_overloads, 2}));
8311cb0ef41Sopenharmony_ci
8321cb0ef41Sopenharmony_ci    CFunction add_all_int_invalid_func =
8331cb0ef41Sopenharmony_ci        CFunction::Make(FastCApiObject::AddAllIntInvalidCallback);
8341cb0ef41Sopenharmony_ci    const CFunction add_all_invalid_overloads[] = {
8351cb0ef41Sopenharmony_ci        add_all_int_invalid_func,
8361cb0ef41Sopenharmony_ci        add_all_seq_c_func,
8371cb0ef41Sopenharmony_ci    };
8381cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
8391cb0ef41Sopenharmony_ci        isolate, "add_all_invalid_overload",
8401cb0ef41Sopenharmony_ci        FunctionTemplate::NewWithCFunctionOverloads(
8411cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllSequenceSlowCallback, Local<Value>(),
8421cb0ef41Sopenharmony_ci            signature, 1, ConstructorBehavior::kThrow,
8431cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, {add_all_invalid_overloads, 2}));
8441cb0ef41Sopenharmony_ci
8451cb0ef41Sopenharmony_ci    CFunction add_all_32bit_int_8args_c_func = CFunction::Make(
8461cb0ef41Sopenharmony_ci        FastCApiObject::AddAll32BitIntFastCallback_8Args V8_IF_USE_SIMULATOR(
8471cb0ef41Sopenharmony_ci            FastCApiObject::AddAll32BitIntFastCallback_8ArgsPatch));
8481cb0ef41Sopenharmony_ci    CFunction add_all_32bit_int_6args_c_func = CFunction::Make(
8491cb0ef41Sopenharmony_ci        FastCApiObject::AddAll32BitIntFastCallback_6Args V8_IF_USE_SIMULATOR(
8501cb0ef41Sopenharmony_ci            FastCApiObject::AddAll32BitIntFastCallback_6ArgsPatch));
8511cb0ef41Sopenharmony_ci    CFunction add_all_32bit_int_5args_c_func = CFunction::Make(
8521cb0ef41Sopenharmony_ci        FastCApiObject::AddAll32BitIntFastCallback_5Args V8_IF_USE_SIMULATOR(
8531cb0ef41Sopenharmony_ci            FastCApiObject::AddAll32BitIntFastCallback_5ArgsPatch));
8541cb0ef41Sopenharmony_ci    const CFunction c_function_overloads[] = {add_all_32bit_int_6args_c_func,
8551cb0ef41Sopenharmony_ci                                              add_all_32bit_int_5args_c_func};
8561cb0ef41Sopenharmony_ci
8571cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
8581cb0ef41Sopenharmony_ci        isolate, "overloaded_add_all_32bit_int",
8591cb0ef41Sopenharmony_ci        FunctionTemplate::NewWithCFunctionOverloads(
8601cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAll32BitIntSlowCallback, Local<Value>(),
8611cb0ef41Sopenharmony_ci            signature, 1, ConstructorBehavior::kThrow,
8621cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, {c_function_overloads, 2}));
8631cb0ef41Sopenharmony_ci
8641cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
8651cb0ef41Sopenharmony_ci        isolate, "overloaded_add_all_8args",
8661cb0ef41Sopenharmony_ci        FunctionTemplate::New(
8671cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAll32BitIntSlowCallback, Local<Value>(),
8681cb0ef41Sopenharmony_ci            signature, 1, ConstructorBehavior::kThrow,
8691cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, &add_all_32bit_int_8args_c_func));
8701cb0ef41Sopenharmony_ci
8711cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
8721cb0ef41Sopenharmony_ci        isolate, "overloaded_add_all_32bit_int_no_sig",
8731cb0ef41Sopenharmony_ci        FunctionTemplate::NewWithCFunctionOverloads(
8741cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAll32BitIntSlowCallback, Local<Value>(),
8751cb0ef41Sopenharmony_ci            Local<Signature>(), 1, ConstructorBehavior::kThrow,
8761cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, {c_function_overloads, 2}));
8771cb0ef41Sopenharmony_ci
8781cb0ef41Sopenharmony_ci    CFunction add_all_no_options_c_func = CFunction::Make(
8791cb0ef41Sopenharmony_ci        FastCApiObject::AddAllFastCallbackNoOptions V8_IF_USE_SIMULATOR(
8801cb0ef41Sopenharmony_ci            FastCApiObject::AddAllFastCallbackNoOptionsPatch));
8811cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
8821cb0ef41Sopenharmony_ci        isolate, "add_all_no_options",
8831cb0ef41Sopenharmony_ci        FunctionTemplate::New(
8841cb0ef41Sopenharmony_ci            isolate, FastCApiObject::AddAllSlowCallback, Local<Value>(),
8851cb0ef41Sopenharmony_ci            Local<Signature>(), 1, ConstructorBehavior::kThrow,
8861cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, &add_all_no_options_c_func));
8871cb0ef41Sopenharmony_ci
8881cb0ef41Sopenharmony_ci    CFunction add_32bit_int_c_func = CFunction::Make(
8891cb0ef41Sopenharmony_ci        FastCApiObject::Add32BitIntFastCallback V8_IF_USE_SIMULATOR(
8901cb0ef41Sopenharmony_ci            FastCApiObject::Add32BitIntFastCallbackPatch));
8911cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
8921cb0ef41Sopenharmony_ci        isolate, "add_32bit_int",
8931cb0ef41Sopenharmony_ci        FunctionTemplate::New(
8941cb0ef41Sopenharmony_ci            isolate, FastCApiObject::Add32BitIntSlowCallback, Local<Value>(),
8951cb0ef41Sopenharmony_ci            signature, 1, ConstructorBehavior::kThrow,
8961cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, &add_32bit_int_c_func));
8971cb0ef41Sopenharmony_ci
8981cb0ef41Sopenharmony_ci    CFunction is_valid_api_object_c_func =
8991cb0ef41Sopenharmony_ci        CFunction::Make(FastCApiObject::IsFastCApiObjectFastCallback);
9001cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
9011cb0ef41Sopenharmony_ci        isolate, "is_fast_c_api_object",
9021cb0ef41Sopenharmony_ci        FunctionTemplate::New(
9031cb0ef41Sopenharmony_ci            isolate, FastCApiObject::IsFastCApiObjectSlowCallback,
9041cb0ef41Sopenharmony_ci            Local<Value>(), signature, 1, ConstructorBehavior::kThrow,
9051cb0ef41Sopenharmony_ci            SideEffectType::kHasSideEffect, &is_valid_api_object_c_func));
9061cb0ef41Sopenharmony_ci
9071cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
9081cb0ef41Sopenharmony_ci        isolate, "fast_call_count",
9091cb0ef41Sopenharmony_ci        FunctionTemplate::New(
9101cb0ef41Sopenharmony_ci            isolate, FastCApiObject::FastCallCount, Local<Value>(), signature,
9111cb0ef41Sopenharmony_ci            1, ConstructorBehavior::kThrow, SideEffectType::kHasNoSideEffect));
9121cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
9131cb0ef41Sopenharmony_ci        isolate, "slow_call_count",
9141cb0ef41Sopenharmony_ci        FunctionTemplate::New(
9151cb0ef41Sopenharmony_ci            isolate, FastCApiObject::SlowCallCount, Local<Value>(), signature,
9161cb0ef41Sopenharmony_ci            1, ConstructorBehavior::kThrow, SideEffectType::kHasNoSideEffect));
9171cb0ef41Sopenharmony_ci    api_obj_ctor->PrototypeTemplate()->Set(
9181cb0ef41Sopenharmony_ci        isolate, "reset_counts",
9191cb0ef41Sopenharmony_ci        FunctionTemplate::New(isolate, FastCApiObject::ResetCounts,
9201cb0ef41Sopenharmony_ci                              Local<Value>(), signature, 1,
9211cb0ef41Sopenharmony_ci                              ConstructorBehavior::kThrow));
9221cb0ef41Sopenharmony_ci  }
9231cb0ef41Sopenharmony_ci  api_obj_ctor->InstanceTemplate()->SetInternalFieldCount(
9241cb0ef41Sopenharmony_ci      FastCApiObject::kV8WrapperObjectIndex + 1);
9251cb0ef41Sopenharmony_ci
9261cb0ef41Sopenharmony_ci  return api_obj_ctor;
9271cb0ef41Sopenharmony_ci}
9281cb0ef41Sopenharmony_ci
9291cb0ef41Sopenharmony_civoid CreateLeafInterfaceObject(const FunctionCallbackInfo<Value>& info) {
9301cb0ef41Sopenharmony_ci  if (!info.IsConstructCall()) {
9311cb0ef41Sopenharmony_ci    info.GetIsolate()->ThrowError(
9321cb0ef41Sopenharmony_ci        "LeafInterfaceType helper must be constructed with new.");
9331cb0ef41Sopenharmony_ci  }
9341cb0ef41Sopenharmony_ci}
9351cb0ef41Sopenharmony_ci
9361cb0ef41Sopenharmony_ciLocal<FunctionTemplate> Shell::CreateLeafInterfaceTypeTemplate(
9371cb0ef41Sopenharmony_ci    Isolate* isolate) {
9381cb0ef41Sopenharmony_ci  Local<FunctionTemplate> leaf_object_ctor =
9391cb0ef41Sopenharmony_ci      FunctionTemplate::New(isolate, CreateLeafInterfaceObject);
9401cb0ef41Sopenharmony_ci  leaf_object_ctor->SetClassName(
9411cb0ef41Sopenharmony_ci      String::NewFromUtf8Literal(isolate, "LeafInterfaceType"));
9421cb0ef41Sopenharmony_ci  return leaf_object_ctor;
9431cb0ef41Sopenharmony_ci}
9441cb0ef41Sopenharmony_ci
9451cb0ef41Sopenharmony_ci}  // namespace v8
946