Skip to content

Commit 2952cc5

Browse files
joyeecheungtargos
authored andcommitted
src: add per-isolate SetFastMethod and Set[Fast]MethodNoSideEffect
PR-URL: #47768 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent 811b43c commit 2952cc5

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/util.cc

+55
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,25 @@ void SetMethod(v8::Isolate* isolate,
392392
that->Set(name_string, t);
393393
}
394394

395+
void SetFastMethod(Isolate* isolate,
396+
Local<Template> that,
397+
const char* name,
398+
v8::FunctionCallback slow_callback,
399+
const v8::CFunction* c_function) {
400+
Local<v8::FunctionTemplate> t =
401+
NewFunctionTemplate(isolate,
402+
slow_callback,
403+
Local<v8::Signature>(),
404+
v8::ConstructorBehavior::kThrow,
405+
v8::SideEffectType::kHasSideEffect,
406+
c_function);
407+
// kInternalized strings are created in the old space.
408+
const v8::NewStringType type = v8::NewStringType::kInternalized;
409+
Local<v8::String> name_string =
410+
v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked();
411+
that->Set(name_string, t);
412+
}
413+
395414
void SetFastMethod(Local<v8::Context> context,
396415
Local<v8::Object> that,
397416
const char* name,
@@ -434,6 +453,25 @@ void SetFastMethodNoSideEffect(Local<v8::Context> context,
434453
that->Set(context, name_string, function).Check();
435454
}
436455

456+
void SetFastMethodNoSideEffect(Isolate* isolate,
457+
Local<Template> that,
458+
const char* name,
459+
v8::FunctionCallback slow_callback,
460+
const v8::CFunction* c_function) {
461+
Local<v8::FunctionTemplate> t =
462+
NewFunctionTemplate(isolate,
463+
slow_callback,
464+
Local<v8::Signature>(),
465+
v8::ConstructorBehavior::kThrow,
466+
v8::SideEffectType::kHasNoSideEffect,
467+
c_function);
468+
// kInternalized strings are created in the old space.
469+
const v8::NewStringType type = v8::NewStringType::kInternalized;
470+
Local<v8::String> name_string =
471+
v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked();
472+
that->Set(name_string, t);
473+
}
474+
437475
void SetMethodNoSideEffect(Local<v8::Context> context,
438476
Local<v8::Object> that,
439477
const char* name,
@@ -455,6 +493,23 @@ void SetMethodNoSideEffect(Local<v8::Context> context,
455493
function->SetName(name_string); // NODE_SET_METHOD() compatibility.
456494
}
457495

496+
void SetMethodNoSideEffect(Isolate* isolate,
497+
Local<v8::Template> that,
498+
const char* name,
499+
v8::FunctionCallback callback) {
500+
Local<v8::FunctionTemplate> t =
501+
NewFunctionTemplate(isolate,
502+
callback,
503+
Local<v8::Signature>(),
504+
v8::ConstructorBehavior::kThrow,
505+
v8::SideEffectType::kHasNoSideEffect);
506+
// kInternalized strings are created in the old space.
507+
const v8::NewStringType type = v8::NewStringType::kInternalized;
508+
Local<v8::String> name_string =
509+
v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked();
510+
that->Set(name_string, t);
511+
}
512+
458513
void SetProtoMethod(v8::Isolate* isolate,
459514
Local<v8::FunctionTemplate> that,
460515
const char* name,

src/util.h

+14
Original file line numberDiff line numberDiff line change
@@ -888,11 +888,21 @@ void SetMethod(v8::Isolate* isolate,
888888
const char* name,
889889
v8::FunctionCallback callback);
890890

891+
void SetFastMethod(v8::Isolate* isolate,
892+
v8::Local<v8::Template> that,
893+
const char* name,
894+
v8::FunctionCallback slow_callback,
895+
const v8::CFunction* c_function);
891896
void SetFastMethod(v8::Local<v8::Context> context,
892897
v8::Local<v8::Object> that,
893898
const char* name,
894899
v8::FunctionCallback slow_callback,
895900
const v8::CFunction* c_function);
901+
void SetFastMethodNoSideEffect(v8::Isolate* isolate,
902+
v8::Local<v8::Template> that,
903+
const char* name,
904+
v8::FunctionCallback slow_callback,
905+
const v8::CFunction* c_function);
896906
void SetFastMethodNoSideEffect(v8::Local<v8::Context> context,
897907
v8::Local<v8::Object> that,
898908
const char* name,
@@ -918,6 +928,10 @@ void SetProtoMethodNoSideEffect(v8::Isolate* isolate,
918928
v8::Local<v8::FunctionTemplate> that,
919929
const char* name,
920930
v8::FunctionCallback callback);
931+
void SetMethodNoSideEffect(v8::Isolate* isolate,
932+
v8::Local<v8::Template> that,
933+
const char* name,
934+
v8::FunctionCallback callback);
921935

922936
enum class SetConstructorFunctionFlag {
923937
NONE,

0 commit comments

Comments
 (0)