Skip to content

Commit 497df82

Browse files
anonrigRafaelGSS
authored andcommitted
src: add ability to overload fast api functions
PR-URL: #48993 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent e5b0dfa commit 497df82

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/util.cc

+47
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,53 @@ void SetFastMethodNoSideEffect(Isolate* isolate,
482482
that->Set(name_string, t);
483483
}
484484

485+
void SetFastMethod(Isolate* isolate,
486+
Local<Template> that,
487+
const std::string_view name,
488+
v8::FunctionCallback slow_callback,
489+
const v8::MemorySpan<const v8::CFunction>& methods) {
490+
Local<v8::FunctionTemplate> t = FunctionTemplate::NewWithCFunctionOverloads(
491+
isolate,
492+
slow_callback,
493+
Local<Value>(),
494+
Local<v8::Signature>(),
495+
0,
496+
v8::ConstructorBehavior::kThrow,
497+
v8::SideEffectType::kHasSideEffect,
498+
methods);
499+
500+
// kInternalized strings are created in the old space.
501+
const v8::NewStringType type = v8::NewStringType::kInternalized;
502+
Local<v8::String> name_string =
503+
v8::String::NewFromUtf8(isolate, name.data(), type, name.size())
504+
.ToLocalChecked();
505+
that->Set(name_string, t);
506+
}
507+
508+
void SetFastMethodNoSideEffect(
509+
Isolate* isolate,
510+
Local<Template> that,
511+
const std::string_view name,
512+
v8::FunctionCallback slow_callback,
513+
const v8::MemorySpan<const v8::CFunction>& methods) {
514+
Local<v8::FunctionTemplate> t = FunctionTemplate::NewWithCFunctionOverloads(
515+
isolate,
516+
slow_callback,
517+
Local<Value>(),
518+
Local<v8::Signature>(),
519+
0,
520+
v8::ConstructorBehavior::kThrow,
521+
v8::SideEffectType::kHasNoSideEffect,
522+
methods);
523+
524+
// kInternalized strings are created in the old space.
525+
const v8::NewStringType type = v8::NewStringType::kInternalized;
526+
Local<v8::String> name_string =
527+
v8::String::NewFromUtf8(isolate, name.data(), type, name.size())
528+
.ToLocalChecked();
529+
that->Set(name_string, t);
530+
}
531+
485532
void SetMethodNoSideEffect(Local<v8::Context> context,
486533
Local<v8::Object> that,
487534
const std::string_view name,

src/util.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,11 @@ void SetFastMethod(v8::Local<v8::Context> context,
890890
const std::string_view name,
891891
v8::FunctionCallback slow_callback,
892892
const v8::CFunction* c_function);
893+
void SetFastMethod(v8::Isolate* isolate,
894+
v8::Local<v8::Template> that,
895+
const std::string_view name,
896+
v8::FunctionCallback slow_callback,
897+
const v8::MemorySpan<const v8::CFunction>& methods);
893898
void SetFastMethodNoSideEffect(v8::Isolate* isolate,
894899
v8::Local<v8::Template> that,
895900
const std::string_view name,
@@ -900,7 +905,12 @@ void SetFastMethodNoSideEffect(v8::Local<v8::Context> context,
900905
const std::string_view name,
901906
v8::FunctionCallback slow_callback,
902907
const v8::CFunction* c_function);
903-
908+
void SetFastMethodNoSideEffect(
909+
v8::Isolate* isolate,
910+
v8::Local<v8::Template> that,
911+
const std::string_view name,
912+
v8::FunctionCallback slow_callback,
913+
const v8::MemorySpan<const v8::CFunction>& methods);
904914
void SetProtoMethod(v8::Isolate* isolate,
905915
v8::Local<v8::FunctionTemplate> that,
906916
const std::string_view name,

0 commit comments

Comments
 (0)