@@ -1185,7 +1185,7 @@ void FunctionTemplate::SetPrototypeProviderTemplate(
11851185 Utils::OpenHandle (*prototype_provider);
11861186 Utils::ApiCheck (self->GetPrototypeTemplate ().IsUndefined (i_isolate),
11871187 " v8::FunctionTemplate::SetPrototypeProviderTemplate" ,
1188- " Protoype must be undefiend " );
1188+ " Protoype must be undefined " );
11891189 Utils::ApiCheck (self->GetParentTemplate ().IsUndefined (i_isolate),
11901190 " v8::FunctionTemplate::SetPrototypeProviderTemplate" ,
11911191 " Prototype provider must be empty" );
@@ -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 CFunction* c_function = nullptr ) {
1221+ const std::vector< 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 =
@@ -1243,7 +1243,7 @@ static Local<FunctionTemplate> FunctionTemplateNew(
12431243 }
12441244 if (callback != nullptr ) {
12451245 Utils::ToLocal (obj)->SetCallHandler (callback, data, side_effect_type,
1246- c_function );
1246+ c_function_overloads );
12471247 }
12481248 return Utils::ToLocal (obj);
12491249}
@@ -1257,10 +1257,29 @@ Local<FunctionTemplate> FunctionTemplate::New(
12571257 // function templates when the isolate is created for serialization.
12581258 LOG_API (i_isolate, FunctionTemplate, New);
12591259 ENTER_V8_NO_SCRIPT_NO_EXCEPTION (i_isolate);
1260- auto templ = FunctionTemplateNew (i_isolate, callback, data, signature, length,
1261- behavior, false , Local<Private>(),
1262- side_effect_type, c_function);
1263- return templ;
1260+ return FunctionTemplateNew (
1261+ i_isolate, callback, data, signature, length, behavior, false ,
1262+ Local<Private>(), side_effect_type,
1263+ c_function ? std::vector<const CFunction*>{c_function}
1264+ : std::vector<const CFunction*>{});
1265+ }
1266+
1267+ Local<FunctionTemplate> FunctionTemplate::NewWithCFunctionOverloads (
1268+ Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
1269+ v8::Local<Signature> signature, int length, ConstructorBehavior behavior,
1270+ 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+
1277+ i::Isolate* i_isolate = reinterpret_cast <i::Isolate*>(isolate);
1278+ LOG_API (i_isolate, FunctionTemplate, New);
1279+ ENTER_V8_NO_SCRIPT_NO_EXCEPTION (i_isolate);
1280+ return FunctionTemplateNew (i_isolate, callback, data, signature, length,
1281+ behavior, false , Local<Private>(),
1282+ side_effect_type, c_function_overloads);
12641283}
12651284
12661285Local<FunctionTemplate> FunctionTemplate::NewWithCache (
@@ -1291,10 +1310,10 @@ Local<AccessorSignature> AccessorSignature::New(
12911310 (obj)->setter (*foreign); \
12921311 } while (false )
12931312
1294- void FunctionTemplate::SetCallHandler (FunctionCallback callback,
1295- v8::Local<Value> data,
1296- SideEffectType side_effect_type,
1297- const CFunction* c_function ) {
1313+ void FunctionTemplate::SetCallHandler (
1314+ FunctionCallback callback, v8::Local<Value> data,
1315+ SideEffectType side_effect_type,
1316+ const std::vector< const CFunction*>& c_function_overloads ) {
12981317 auto info = Utils::OpenHandle (this );
12991318 EnsureNotPublished (info, " v8::FunctionTemplate::SetCallHandler" );
13001319 i::Isolate* isolate = info->GetIsolate ();
@@ -1310,13 +1329,20 @@ void FunctionTemplate::SetCallHandler(FunctionCallback callback,
13101329 obj->set_data (*Utils::OpenHandle (*data));
13111330 // Blink passes CFunction's constructed with the default constructor
13121331 // for non-fast calls, so we should check the address too.
1313- if (c_function != nullptr && c_function->GetAddress ()) {
1314- i::FunctionTemplateInfo::SetCFunction (
1315- isolate, info,
1316- i::handle (*FromCData (isolate, c_function->GetAddress ()), isolate));
1317- i::FunctionTemplateInfo::SetCSignature (
1318- isolate, info,
1319- i::handle (*FromCData (isolate, c_function->GetTypeInfo ()), isolate));
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));
1345+ }
13201346 }
13211347 info->set_call_code (*obj, kReleaseStore );
13221348}
0 commit comments