Skip to content

Commit

Permalink
src: add ability to overload fast api functions
Browse files Browse the repository at this point in the history
PR-URL: #48993
Reviewed-By: Joyee Cheung <[email protected]>
  • Loading branch information
anonrig authored and RafaelGSS committed Aug 16, 2023
1 parent 6ffc59a commit 2af5250
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
47 changes: 47 additions & 0 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 11 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 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,
Expand All @@ -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,
Expand Down

0 comments on commit 2af5250

Please sign in to comment.