Skip to content

Commit 7fb32b4

Browse files
joyeecheungdanielleadams
authored andcommitted
src: add SetFastMethodNoSideEffect()
The original SetFastMethod() uses v8::SideEffectType::kHasNoSideEffect by default, which is different from SetMethod(). Follow the previous convention and add a new SetFastMethodNoSideEffect() instead. PR-URL: #46619 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent fe318dd commit 7fb32b4

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/node_process_methods.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,9 @@ v8::CFunction BindingData::fast_bigint_(v8::CFunction::Make(FastBigInt));
476476

477477
void BindingData::AddMethods() {
478478
Local<Context> ctx = env()->context();
479-
SetFastMethod(ctx, object(), "hrtime", SlowNumber, &fast_number_);
480-
SetFastMethod(ctx, object(), "hrtimeBigInt", SlowBigInt, &fast_bigint_);
479+
SetFastMethodNoSideEffect(ctx, object(), "hrtime", SlowNumber, &fast_number_);
480+
SetFastMethodNoSideEffect(
481+
ctx, object(), "hrtimeBigInt", SlowBigInt, &fast_bigint_);
481482
}
482483

483484
void BindingData::RegisterExternalReferences(

src/util.cc

+21
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,27 @@ void SetFastMethod(Local<v8::Context> context,
362362
v8::FunctionCallback slow_callback,
363363
const v8::CFunction* c_function) {
364364
Isolate* isolate = context->GetIsolate();
365+
Local<v8::Function> function =
366+
NewFunctionTemplate(isolate,
367+
slow_callback,
368+
Local<v8::Signature>(),
369+
v8::ConstructorBehavior::kThrow,
370+
v8::SideEffectType::kHasSideEffect,
371+
c_function)
372+
->GetFunction(context)
373+
.ToLocalChecked();
374+
const v8::NewStringType type = v8::NewStringType::kInternalized;
375+
Local<v8::String> name_string =
376+
v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked();
377+
that->Set(context, name_string, function).Check();
378+
}
379+
380+
void SetFastMethodNoSideEffect(Local<v8::Context> context,
381+
Local<v8::Object> that,
382+
const char* name,
383+
v8::FunctionCallback slow_callback,
384+
const v8::CFunction* c_function) {
385+
Isolate* isolate = context->GetIsolate();
365386
Local<v8::Function> function =
366387
NewFunctionTemplate(isolate,
367388
slow_callback,

src/util.h

+5
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,11 @@ void SetFastMethod(v8::Local<v8::Context> context,
886886
const char* name,
887887
v8::FunctionCallback slow_callback,
888888
const v8::CFunction* c_function);
889+
void SetFastMethodNoSideEffect(v8::Local<v8::Context> context,
890+
v8::Local<v8::Object> that,
891+
const char* name,
892+
v8::FunctionCallback slow_callback,
893+
const v8::CFunction* c_function);
889894

890895
void SetProtoMethod(v8::Isolate* isolate,
891896
v8::Local<v8::FunctionTemplate> that,

0 commit comments

Comments
 (0)