@@ -1218,7 +1218,7 @@ static Local<FunctionTemplate> FunctionTemplateNew(
12181218 bool do_not_cache,
12191219 v8::Local<Private> cached_property_name = v8::Local<Private>(),
12201220 SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
1221- const std::vector <const CFunction* >& c_function_overloads = {}) {
1221+ const MemorySpan <const CFunction>& c_function_overloads = {}) {
12221222 i::Handle<i::Struct> struct_obj = isolate->factory ()->NewStruct (
12231223 i::FUNCTION_TEMPLATE_INFO_TYPE, i::AllocationType::kOld );
12241224 i::Handle<i::FunctionTemplateInfo> obj =
@@ -1260,20 +1260,15 @@ Local<FunctionTemplate> FunctionTemplate::New(
12601260 return FunctionTemplateNew (
12611261 i_isolate, callback, data, signature, length, behavior, false ,
12621262 Local<Private>(), side_effect_type,
1263- c_function ? std::vector <const CFunction* >{c_function}
1264- : std::vector <const CFunction* >{});
1263+ c_function ? MemorySpan <const CFunction>{c_function, 1 }
1264+ : MemorySpan <const CFunction>{});
12651265}
12661266
12671267Local<FunctionTemplate> FunctionTemplate::NewWithCFunctionOverloads (
12681268 Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
12691269 v8::Local<Signature> signature, int length, ConstructorBehavior behavior,
12701270 SideEffectType side_effect_type,
1271- const std::vector<const CFunction*>& c_function_overloads) {
1272- // Multiple overloads not supported yet.
1273- Utils::ApiCheck (c_function_overloads.size () == 1 ,
1274- " v8::FunctionTemplate::NewWithCFunctionOverloads" ,
1275- " Function overloads not supported yet." );
1276-
1271+ const MemorySpan<const CFunction>& c_function_overloads) {
12771272 i::Isolate* i_isolate = reinterpret_cast <i::Isolate*>(isolate);
12781273 LOG_API (i_isolate, FunctionTemplate, New);
12791274 ENTER_V8_NO_SCRIPT_NO_EXCEPTION (i_isolate);
@@ -1313,7 +1308,7 @@ Local<AccessorSignature> AccessorSignature::New(
13131308void FunctionTemplate::SetCallHandler (
13141309 FunctionCallback callback, v8::Local<Value> data,
13151310 SideEffectType side_effect_type,
1316- const std::vector <const CFunction* >& c_function_overloads) {
1311+ const MemorySpan <const CFunction>& c_function_overloads) {
13171312 auto info = Utils::OpenHandle (this );
13181313 EnsureNotPublished (info, " v8::FunctionTemplate::SetCallHandler" );
13191314 i::Isolate* isolate = info->GetIsolate ();
@@ -1327,22 +1322,28 @@ void FunctionTemplate::SetCallHandler(
13271322 data = v8::Undefined (reinterpret_cast <v8::Isolate*>(isolate));
13281323 }
13291324 obj->set_data (*Utils::OpenHandle (*data));
1330- // Blink passes CFunction's constructed with the default constructor
1331- // for non-fast calls, so we should check the address too.
1332- if (!c_function_overloads.empty ()) {
1333- // Multiple overloads not supported yet.
1334- Utils::ApiCheck (c_function_overloads.size () == 1 ,
1335- " v8::FunctionTemplate::SetCallHandler" ,
1336- " Function overloads not supported yet." );
1337- const CFunction* c_function = c_function_overloads[0 ];
1338- if (c_function != nullptr && c_function->GetAddress ()) {
1339- i::FunctionTemplateInfo::SetCFunction (
1340- isolate, info,
1341- i::handle (*FromCData (isolate, c_function->GetAddress ()), isolate));
1342- i::FunctionTemplateInfo::SetCSignature (
1343- isolate, info,
1344- i::handle (*FromCData (isolate, c_function->GetTypeInfo ()), isolate));
1325+ if (c_function_overloads.size () > 0 ) {
1326+ // Stores the data for a sequence of CFunction overloads into a single
1327+ // FixedArray, as [address_0, signature_0, ... address_n-1, signature_n-1].
1328+ i::Handle<i::FixedArray> function_overloads =
1329+ isolate->factory ()->NewFixedArray (static_cast <int >(
1330+ c_function_overloads.size () *
1331+ i::FunctionTemplateInfo::kFunctionOverloadEntrySize ));
1332+ int function_count = static_cast <int >(c_function_overloads.size ());
1333+ for (int i = 0 ; i < function_count; i++) {
1334+ const CFunction& c_function = c_function_overloads.data ()[i];
1335+ i::Handle<i::Object> address =
1336+ FromCData (isolate, c_function.GetAddress ());
1337+ function_overloads->set (
1338+ i::FunctionTemplateInfo::kFunctionOverloadEntrySize * i, *address);
1339+ i::Handle<i::Object> signature =
1340+ FromCData (isolate, c_function.GetTypeInfo ());
1341+ function_overloads->set (
1342+ i::FunctionTemplateInfo::kFunctionOverloadEntrySize * i + 1 ,
1343+ *signature);
13451344 }
1345+ i::FunctionTemplateInfo::SetCFunctionOverloads (isolate, info,
1346+ function_overloads);
13461347 }
13471348 info->set_call_code (*obj, kReleaseStore );
13481349}
0 commit comments