Skip to content

Commit

Permalink
src: add SetFastMethodNoSideEffect()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
joyeecheung authored and danielleadams committed Apr 5, 2023
1 parent fe318dd commit 7fb32b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ v8::CFunction BindingData::fast_bigint_(v8::CFunction::Make(FastBigInt));

void BindingData::AddMethods() {
Local<Context> 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(
Expand Down
21 changes: 21 additions & 0 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,27 @@ void SetFastMethod(Local<v8::Context> context,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function) {
Isolate* isolate = context->GetIsolate();
Local<v8::Function> function =
NewFunctionTemplate(isolate,
slow_callback,
Local<v8::Signature>(),
v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasSideEffect,
c_function)
->GetFunction(context)
.ToLocalChecked();
const v8::NewStringType type = v8::NewStringType::kInternalized;
Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked();
that->Set(context, name_string, function).Check();
}

void SetFastMethodNoSideEffect(Local<v8::Context> context,
Local<v8::Object> that,
const char* name,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function) {
Isolate* isolate = context->GetIsolate();
Local<v8::Function> function =
NewFunctionTemplate(isolate,
slow_callback,
Expand Down
5 changes: 5 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,11 @@ void SetFastMethod(v8::Local<v8::Context> context,
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,
v8::FunctionCallback slow_callback,
const v8::CFunction* c_function);

void SetProtoMethod(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> that,
Expand Down

0 comments on commit 7fb32b4

Please sign in to comment.