diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 06fd7313d7f01c..778e4cd9dd966e 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -481,8 +481,9 @@ v8::CFunction BindingData::fast_bigint_(v8::CFunction::Make(FastBigInt)); void BindingData::AddMethods() { Local ctx = env()->context(); - SetFastMethod(ctx, object(), "hrtime", SlowNumber, &fast_number_); - SetFastMethod(ctx, object(), "hrtimeBigInt", SlowBigInt, &fast_bigint_); + SetFastMethodNoSideEffect(ctx, object(), "hrtime", SlowNumber, &fast_number_); + SetFastMethodNoSideEffect( + ctx, object(), "hrtimeBigInt", SlowBigInt, &fast_bigint_); } void BindingData::RegisterExternalReferences( diff --git a/src/util.cc b/src/util.cc index 006eb068982d75..a50f780b73664f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -398,6 +398,27 @@ void SetFastMethod(Local context, v8::FunctionCallback slow_callback, const v8::CFunction* c_function) { Isolate* isolate = context->GetIsolate(); + Local function = + NewFunctionTemplate(isolate, + slow_callback, + Local(), + v8::ConstructorBehavior::kThrow, + v8::SideEffectType::kHasSideEffect, + c_function) + ->GetFunction(context) + .ToLocalChecked(); + const v8::NewStringType type = v8::NewStringType::kInternalized; + Local name_string = + v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked(); + that->Set(context, name_string, function).Check(); +} + +void SetFastMethodNoSideEffect(Local context, + Local that, + const char* name, + v8::FunctionCallback slow_callback, + const v8::CFunction* c_function) { + Isolate* isolate = context->GetIsolate(); Local function = NewFunctionTemplate(isolate, slow_callback, diff --git a/src/util.h b/src/util.h index 1d3c480b234c4c..9be4aef5686d3a 100644 --- a/src/util.h +++ b/src/util.h @@ -897,6 +897,11 @@ void SetFastMethod(v8::Local context, const char* name, v8::FunctionCallback slow_callback, const v8::CFunction* c_function); +void SetFastMethodNoSideEffect(v8::Local context, + v8::Local that, + const char* name, + v8::FunctionCallback slow_callback, + const v8::CFunction* c_function); void SetProtoMethod(v8::Isolate* isolate, v8::Local that,