Skip to content

Commit

Permalink
src: add ability to overload fast api functions
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Aug 1, 2023
1 parent 8f0f17e commit 9df9c71
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,52 @@ void SetFastMethodNoSideEffect(Isolate* isolate,
that->Set(name_string, t);
}

void SetFastMethodOverloads(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 SetFastMethodNoSideEffectOverloads(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,
Expand Down
11 changes: 10 additions & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 SetFastMethodOverloads(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,
Expand All @@ -900,7 +905,11 @@ void SetFastMethodNoSideEffect(v8::Local<v8::Context> context,
const std::string_view name,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function);

void SetFastMethodNoSideEffectOverloads(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,
Expand Down

0 comments on commit 9df9c71

Please sign in to comment.