src: add ability to overload fast api functions

PR-URL: https://github.com/nodejs/node/pull/48993
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Yagiz Nizipli
2023-08-01 17:52:12 -04:00
committed by Node.js GitHub Bot
parent 82e4ca109e
commit 4cf30df026
2 changed files with 58 additions and 1 deletions

View File

@@ -482,6 +482,53 @@ void SetFastMethodNoSideEffect(Isolate* isolate,
that->Set(name_string, t);
}
void SetFastMethod(Isolate* isolate,
Local<Template> that,
const std::string_view name,
v8::FunctionCallback slow_callback,
const v8::MemorySpan<const v8::CFunction>& methods) {
Local<v8::FunctionTemplate> t = FunctionTemplate::NewWithCFunctionOverloads(
isolate,
slow_callback,
Local<Value>(),
Local<v8::Signature>(),
0,
v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasSideEffect,
methods);
// kInternalized strings are created in the old space.
const v8::NewStringType type = v8::NewStringType::kInternalized;
Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate, name.data(), type, name.size())
.ToLocalChecked();
that->Set(name_string, t);
}
void SetFastMethodNoSideEffect(
Isolate* isolate,
Local<Template> that,
const std::string_view name,
v8::FunctionCallback slow_callback,
const v8::MemorySpan<const v8::CFunction>& methods) {
Local<v8::FunctionTemplate> t = FunctionTemplate::NewWithCFunctionOverloads(
isolate,
slow_callback,
Local<Value>(),
Local<v8::Signature>(),
0,
v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasNoSideEffect,
methods);
// kInternalized strings are created in the old space.
const v8::NewStringType type = v8::NewStringType::kInternalized;
Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate, name.data(), type, name.size())
.ToLocalChecked();
that->Set(name_string, t);
}
void SetMethodNoSideEffect(Local<v8::Context> context,
Local<v8::Object> that,
const std::string_view name,

View File

@@ -890,6 +890,11 @@ void SetFastMethod(v8::Local<v8::Context> context,
const std::string_view name,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function);
void SetFastMethod(v8::Isolate* isolate,
v8::Local<v8::Template> that,
const std::string_view name,
v8::FunctionCallback slow_callback,
const v8::MemorySpan<const v8::CFunction>& methods);
void SetFastMethodNoSideEffect(v8::Isolate* isolate,
v8::Local<v8::Template> that,
const std::string_view name,
@@ -900,7 +905,12 @@ void SetFastMethodNoSideEffect(v8::Local<v8::Context> context,
const std::string_view name,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function);
void SetFastMethodNoSideEffect(
v8::Isolate* isolate,
v8::Local<v8::Template> that,
const std::string_view name,
v8::FunctionCallback slow_callback,
const v8::MemorySpan<const v8::CFunction>& methods);
void SetProtoMethod(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> that,
const std::string_view name,