Skip to content

Commit ad5f42d

Browse files
joyeecheungtargos
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 <yagiz@nizipli.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d3d76c3 commit ad5f42d

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/node_process_methods.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,9 @@ v8::CFunction BindingData::fast_bigint_(v8::CFunction::Make(FastBigInt));
481481

482482
void BindingData::AddMethods() {
483483
Local<Context> ctx = env()->context();
484-
SetFastMethod(ctx, object(), "hrtime", SlowNumber, &fast_number_);
485-
SetFastMethod(ctx, object(), "hrtimeBigInt", SlowBigInt, &fast_bigint_);
484+
SetFastMethodNoSideEffect(ctx, object(), "hrtime", SlowNumber, &fast_number_);
485+
SetFastMethodNoSideEffect(
486+
ctx, object(), "hrtimeBigInt", SlowBigInt, &fast_bigint_);
486487
}
487488

488489
void BindingData::RegisterExternalReferences(

src/util.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,27 @@ void SetFastMethod(Local<v8::Context> context,
398398
v8::FunctionCallback slow_callback,
399399
const v8::CFunction* c_function) {
400400
Isolate* isolate = context->GetIsolate();
401+
Local<v8::Function> function =
402+
NewFunctionTemplate(isolate,
403+
slow_callback,
404+
Local<v8::Signature>(),
405+
v8::ConstructorBehavior::kThrow,
406+
v8::SideEffectType::kHasSideEffect,
407+
c_function)
408+
->GetFunction(context)
409+
.ToLocalChecked();
410+
const v8::NewStringType type = v8::NewStringType::kInternalized;
411+
Local<v8::String> name_string =
412+
v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked();
413+
that->Set(context, name_string, function).Check();
414+
}
415+
416+
void SetFastMethodNoSideEffect(Local<v8::Context> context,
417+
Local<v8::Object> that,
418+
const char* name,
419+
v8::FunctionCallback slow_callback,
420+
const v8::CFunction* c_function) {
421+
Isolate* isolate = context->GetIsolate();
401422
Local<v8::Function> function =
402423
NewFunctionTemplate(isolate,
403424
slow_callback,

src/util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,11 @@ void SetFastMethod(v8::Local<v8::Context> context,
897897
const char* name,
898898
v8::FunctionCallback slow_callback,
899899
const v8::CFunction* c_function);
900+
void SetFastMethodNoSideEffect(v8::Local<v8::Context> context,
901+
v8::Local<v8::Object> that,
902+
const char* name,
903+
v8::FunctionCallback slow_callback,
904+
const v8::CFunction* c_function);
900905

901906
void SetProtoMethod(v8::Isolate* isolate,
902907
v8::Local<v8::FunctionTemplate> that,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy