Skip to content

Commit

Permalink
src: add per-isolate SetFastMethod and Set[Fast]MethodNoSideEffect
Browse files Browse the repository at this point in the history
PR-URL: #47768
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
joyeecheung authored and targos committed May 12, 2023
1 parent 811b43c commit 2952cc5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,25 @@ void SetMethod(v8::Isolate* isolate,
that->Set(name_string, t);
}

void SetFastMethod(Isolate* isolate,
Local<Template> that,
const char* name,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function) {
Local<v8::FunctionTemplate> t =
NewFunctionTemplate(isolate,
slow_callback,
Local<v8::Signature>(),
v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasSideEffect,
c_function);
// 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, type).ToLocalChecked();
that->Set(name_string, t);
}

void SetFastMethod(Local<v8::Context> context,
Local<v8::Object> that,
const char* name,
Expand Down Expand Up @@ -434,6 +453,25 @@ void SetFastMethodNoSideEffect(Local<v8::Context> context,
that->Set(context, name_string, function).Check();
}

void SetFastMethodNoSideEffect(Isolate* isolate,
Local<Template> that,
const char* name,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function) {
Local<v8::FunctionTemplate> t =
NewFunctionTemplate(isolate,
slow_callback,
Local<v8::Signature>(),
v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasNoSideEffect,
c_function);
// 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, type).ToLocalChecked();
that->Set(name_string, t);
}

void SetMethodNoSideEffect(Local<v8::Context> context,
Local<v8::Object> that,
const char* name,
Expand All @@ -455,6 +493,23 @@ void SetMethodNoSideEffect(Local<v8::Context> context,
function->SetName(name_string); // NODE_SET_METHOD() compatibility.
}

void SetMethodNoSideEffect(Isolate* isolate,
Local<v8::Template> that,
const char* name,
v8::FunctionCallback callback) {
Local<v8::FunctionTemplate> t =
NewFunctionTemplate(isolate,
callback,
Local<v8::Signature>(),
v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasNoSideEffect);
// 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, type).ToLocalChecked();
that->Set(name_string, t);
}

void SetProtoMethod(v8::Isolate* isolate,
Local<v8::FunctionTemplate> that,
const char* name,
Expand Down
14 changes: 14 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,21 @@ void SetMethod(v8::Isolate* isolate,
const char* name,
v8::FunctionCallback callback);

void SetFastMethod(v8::Isolate* isolate,
v8::Local<v8::Template> that,
const char* name,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function);
void SetFastMethod(v8::Local<v8::Context> context,
v8::Local<v8::Object> that,
const char* name,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function);
void SetFastMethodNoSideEffect(v8::Isolate* isolate,
v8::Local<v8::Template> that,
const char* name,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function);
void SetFastMethodNoSideEffect(v8::Local<v8::Context> context,
v8::Local<v8::Object> that,
const char* name,
Expand All @@ -918,6 +928,10 @@ void SetProtoMethodNoSideEffect(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> that,
const char* name,
v8::FunctionCallback callback);
void SetMethodNoSideEffect(v8::Isolate* isolate,
v8::Local<v8::Template> that,
const char* name,
v8::FunctionCallback callback);

enum class SetConstructorFunctionFlag {
NONE,
Expand Down

0 comments on commit 2952cc5

Please sign in to comment.