diff --git a/src/histogram.cc b/src/histogram.cc index 3caa6e8248ce27..1bf540cc5fcfb6 100644 --- a/src/histogram.cc +++ b/src/histogram.cc @@ -4,10 +4,12 @@ #include "memory_tracker-inl.h" #include "node_errors.h" #include "node_external_reference.h" +#include "util.h" namespace node { using v8::BigInt; +using v8::Context; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Integer; @@ -40,6 +42,45 @@ HistogramImpl::HistogramImpl(const Histogram::Options& options) HistogramImpl::HistogramImpl(std::shared_ptr histogram) : histogram_(std::move(histogram)) {} +void HistogramImpl::AddMethods(Isolate* isolate, Local tmpl) { + SetProtoMethodNoSideEffect(isolate, tmpl, "countBigInt", GetCountBigInt); + SetProtoMethodNoSideEffect(isolate, tmpl, "exceedsBigInt", GetExceedsBigInt); + SetProtoMethodNoSideEffect(isolate, tmpl, "minBigInt", GetMinBigInt); + SetProtoMethodNoSideEffect(isolate, tmpl, "maxBigInt", GetMaxBigInt); + SetProtoMethodNoSideEffect(isolate, tmpl, "percentileBigInt", GetPercentileBigInt); + SetProtoMethodNoSideEffect(isolate, tmpl, "percentiles", GetPercentiles); + SetProtoMethodNoSideEffect(isolate, tmpl, "percentilesBigInt", GetPercentilesBigInt); + SetProtoMethodNoSideEffect(isolate, tmpl, "count", GetCount); + SetProtoMethodNoSideEffect(isolate, tmpl, "exceeds", GetExceeds); + SetProtoMethodNoSideEffect(isolate, tmpl, "min", GetMin); + SetProtoMethodNoSideEffect(isolate, tmpl, "max", GetMax); + SetProtoMethodNoSideEffect(isolate, tmpl, "mean", GetMean); + SetProtoMethodNoSideEffect(isolate, tmpl, "stddev", GetStddev); + SetProtoMethodNoSideEffect(isolate, tmpl, "percentile", GetPercentile); + SetProtoMethod(isolate, tmpl, "reset", DoReset); +} + +void HistogramImpl::RegisterExternalReferences(ExternalReferenceRegistry* registry) { + static bool is_registerd = false; + if (is_registerd) return; + registry->Register(GetCount); + registry->Register(GetCountBigInt); + registry->Register(GetExceeds); + registry->Register(GetExceedsBigInt); + registry->Register(GetMin); + registry->Register(GetMinBigInt); + registry->Register(GetMax); + registry->Register(GetMaxBigInt); + registry->Register(GetMean); + registry->Register(GetStddev); + registry->Register(GetPercentile); + registry->Register(GetPercentileBigInt); + registry->Register(GetPercentiles); + registry->Register(GetPercentilesBigInt); + registry->Register(DoReset); + is_registerd = true; +} + HistogramBase::HistogramBase( Environment* env, Local wrap, @@ -47,6 +88,8 @@ HistogramBase::HistogramBase( : BaseObject(env, wrap), HistogramImpl(options) { MakeWeak(); + wrap->SetAlignedPointerInInternalField(HistogramImpl::InternalFields::kImplField, + static_cast(this)); } HistogramBase::HistogramBase( @@ -56,139 +99,14 @@ HistogramBase::HistogramBase( : BaseObject(env, wrap), HistogramImpl(std::move(histogram)) { MakeWeak(); + wrap->SetAlignedPointerInInternalField(HistogramImpl::InternalFields::kImplField, + static_cast(this)); } void HistogramBase::MemoryInfo(MemoryTracker* tracker) const { tracker->TrackField("histogram", histogram()); } -void HistogramBase::GetCount(const v8::FunctionCallbackInfo& args) { - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - double value = static_cast((*histogram)->Count()); - args.GetReturnValue().Set(value); -} - -void HistogramBase::GetCountBigInt( - const v8::FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - args.GetReturnValue().Set( - BigInt::NewFromUnsigned(env->isolate(), (*histogram)->Count())); -} - -void HistogramBase::GetMin(const FunctionCallbackInfo& args) { - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - double value = static_cast((*histogram)->Min()); - args.GetReturnValue().Set(value); -} - -void HistogramBase::GetMinBigInt(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Min())); -} - -void HistogramBase::GetMax(const FunctionCallbackInfo& args) { - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - double value = static_cast((*histogram)->Max()); - args.GetReturnValue().Set(value); -} - -void HistogramBase::GetMaxBigInt(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - args.GetReturnValue().Set( - BigInt::New(env->isolate(), (*histogram)->Max())); -} - -void HistogramBase::GetMean(const FunctionCallbackInfo& args) { - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - args.GetReturnValue().Set((*histogram)->Mean()); -} - -void HistogramBase::GetExceeds(const FunctionCallbackInfo& args) { - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - double value = static_cast((*histogram)->Exceeds()); - args.GetReturnValue().Set(value); -} - -void HistogramBase::GetExceedsBigInt(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - args.GetReturnValue().Set( - BigInt::NewFromUnsigned(env->isolate(), (*histogram)->Exceeds())); -} - -void HistogramBase::GetStddev(const FunctionCallbackInfo& args) { - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - args.GetReturnValue().Set((*histogram)->Stddev()); -} - -void HistogramBase::GetPercentile(const FunctionCallbackInfo& args) { - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - CHECK(args[0]->IsNumber()); - double percentile = args[0].As()->Value(); - double value = static_cast((*histogram)->Percentile(percentile)); - args.GetReturnValue().Set(value); -} - -void HistogramBase::GetPercentileBigInt( - const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - CHECK(args[0]->IsNumber()); - double percentile = args[0].As()->Value(); - int64_t value = (*histogram)->Percentile(percentile); - args.GetReturnValue().Set(BigInt::New(env->isolate(), value)); -} - -void HistogramBase::GetPercentiles(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - CHECK(args[0]->IsMap()); - Local map = args[0].As(); - (*histogram)->Percentiles([map, env](double key, int64_t value) { - USE(map->Set( - env->context(), - Number::New(env->isolate(), key), - Number::New(env->isolate(), static_cast(value)))); - }); -} - -void HistogramBase::GetPercentilesBigInt( - const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - CHECK(args[0]->IsMap()); - Local map = args[0].As(); - (*histogram)->Percentiles([map, env](double key, int64_t value) { - USE(map->Set( - env->context(), - Number::New(env->isolate(), key), - BigInt::New(env->isolate(), value))); - }); -} - -void HistogramBase::DoReset(const FunctionCallbackInfo& args) { - HistogramBase* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - (*histogram)->Reset(); -} - void HistogramBase::RecordDelta(const FunctionCallbackInfo& args) { HistogramBase* histogram; ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); @@ -288,30 +206,12 @@ Local HistogramBase::GetConstructorTemplate( tmpl = NewFunctionTemplate(isolate, New); Local classname = FIXED_ONE_BYTE_STRING(isolate, "Histogram"); tmpl->SetClassName(classname); - - tmpl->InstanceTemplate()->SetInternalFieldCount( - HistogramBase::kInternalFieldCount); - SetProtoMethodNoSideEffect(isolate, tmpl, "count", GetCount); - SetProtoMethodNoSideEffect(isolate, tmpl, "countBigInt", GetCountBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "exceeds", GetExceeds); - SetProtoMethodNoSideEffect( - isolate, tmpl, "exceedsBigInt", GetExceedsBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "min", GetMin); - SetProtoMethodNoSideEffect(isolate, tmpl, "minBigInt", GetMinBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "max", GetMax); - SetProtoMethodNoSideEffect(isolate, tmpl, "maxBigInt", GetMaxBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "mean", GetMean); - SetProtoMethodNoSideEffect(isolate, tmpl, "stddev", GetStddev); - SetProtoMethodNoSideEffect(isolate, tmpl, "percentile", GetPercentile); - SetProtoMethodNoSideEffect( - isolate, tmpl, "percentileBigInt", GetPercentileBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "percentiles", GetPercentiles); - SetProtoMethodNoSideEffect( - isolate, tmpl, "percentilesBigInt", GetPercentilesBigInt); - SetProtoMethod(isolate, tmpl, "reset", DoReset); + auto instance = tmpl->InstanceTemplate(); + instance->SetInternalFieldCount(HistogramImpl::kInternalFieldCount); SetProtoMethod(isolate, tmpl, "record", Record); SetProtoMethod(isolate, tmpl, "recordDelta", RecordDelta); SetProtoMethod(isolate, tmpl, "add", Add); + HistogramImpl::AddMethods(isolate, tmpl); isolate_data->set_histogram_ctor_template(tmpl); } return tmpl; @@ -320,24 +220,10 @@ Local HistogramBase::GetConstructorTemplate( void HistogramBase::RegisterExternalReferences( ExternalReferenceRegistry* registry) { registry->Register(New); - registry->Register(GetCount); - registry->Register(GetCountBigInt); - registry->Register(GetExceeds); - registry->Register(GetExceedsBigInt); - registry->Register(GetMin); - registry->Register(GetMinBigInt); - registry->Register(GetMax); - registry->Register(GetMaxBigInt); - registry->Register(GetMean); - registry->Register(GetStddev); - registry->Register(GetPercentile); - registry->Register(GetPercentileBigInt); - registry->Register(GetPercentiles); - registry->Register(GetPercentilesBigInt); - registry->Register(DoReset); + registry->Register(Add); registry->Register(Record); registry->Register(RecordDelta); - registry->Register(Add); + HistogramImpl::RegisterExternalReferences(registry); } void HistogramBase::Initialize(IsolateData* isolate_data, @@ -351,7 +237,7 @@ void HistogramBase::Initialize(IsolateData* isolate_data, BaseObjectPtr HistogramBase::HistogramTransferData::Deserialize( Environment* env, - v8::Local context, + Local context, std::unique_ptr self) { return Create(env, std::move(histogram_)); } @@ -373,26 +259,8 @@ Local IntervalHistogram::GetConstructorTemplate( tmpl = NewFunctionTemplate(isolate, nullptr); tmpl->Inherit(HandleWrap::GetConstructorTemplate(env)); tmpl->SetClassName(OneByteString(isolate, "Histogram")); - tmpl->InstanceTemplate()->SetInternalFieldCount( - HistogramBase::kInternalFieldCount); - SetProtoMethodNoSideEffect(isolate, tmpl, "count", GetCount); - SetProtoMethodNoSideEffect(isolate, tmpl, "countBigInt", GetCountBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "exceeds", GetExceeds); - SetProtoMethodNoSideEffect( - isolate, tmpl, "exceedsBigInt", GetExceedsBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "min", GetMin); - SetProtoMethodNoSideEffect(isolate, tmpl, "minBigInt", GetMinBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "max", GetMax); - SetProtoMethodNoSideEffect(isolate, tmpl, "maxBigInt", GetMaxBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "mean", GetMean); - SetProtoMethodNoSideEffect(isolate, tmpl, "stddev", GetStddev); - SetProtoMethodNoSideEffect(isolate, tmpl, "percentile", GetPercentile); - SetProtoMethodNoSideEffect( - isolate, tmpl, "percentileBigInt", GetPercentileBigInt); - SetProtoMethodNoSideEffect(isolate, tmpl, "percentiles", GetPercentiles); - SetProtoMethodNoSideEffect( - isolate, tmpl, "percentilesBigInt", GetPercentilesBigInt); - SetProtoMethod(isolate, tmpl, "reset", DoReset); + tmpl->InstanceTemplate()->SetInternalFieldCount(HistogramImpl::kInternalFieldCount); + HistogramImpl::AddMethods(isolate, tmpl); SetProtoMethod(isolate, tmpl, "start", Start); SetProtoMethod(isolate, tmpl, "stop", Stop); env->set_intervalhistogram_constructor_template(tmpl); @@ -402,23 +270,9 @@ Local IntervalHistogram::GetConstructorTemplate( void IntervalHistogram::RegisterExternalReferences( ExternalReferenceRegistry* registry) { - registry->Register(GetCount); - registry->Register(GetCountBigInt); - registry->Register(GetExceeds); - registry->Register(GetExceedsBigInt); - registry->Register(GetMin); - registry->Register(GetMinBigInt); - registry->Register(GetMax); - registry->Register(GetMaxBigInt); - registry->Register(GetMean); - registry->Register(GetStddev); - registry->Register(GetPercentile); - registry->Register(GetPercentileBigInt); - registry->Register(GetPercentiles); - registry->Register(GetPercentilesBigInt); - registry->Register(DoReset); registry->Register(Start); registry->Register(Stop); + HistogramImpl::RegisterExternalReferences(registry); } IntervalHistogram::IntervalHistogram( @@ -437,6 +291,8 @@ IntervalHistogram::IntervalHistogram( interval_(interval), on_interval_(std::move(on_interval)) { MakeWeak(); + wrap->SetAlignedPointerInInternalField(HistogramImpl::InternalFields::kImplField, + static_cast(this)); uv_timer_init(env->event_loop(), &timer_); } @@ -501,103 +357,90 @@ void IntervalHistogram::Stop(const FunctionCallbackInfo& args) { histogram->OnStop(); } -void IntervalHistogram::GetCount(const FunctionCallbackInfo& args) { - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); +void HistogramImpl::GetCount(const FunctionCallbackInfo& args) { + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); double value = static_cast((*histogram)->Count()); args.GetReturnValue().Set(value); } -void IntervalHistogram::GetCountBigInt( - const v8::FunctionCallbackInfo& args) { +void HistogramImpl::GetCountBigInt( + const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); args.GetReturnValue().Set( BigInt::NewFromUnsigned(env->isolate(), (*histogram)->Count())); } -void IntervalHistogram::GetMin(const FunctionCallbackInfo& args) { - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); +void HistogramImpl::GetMin(const FunctionCallbackInfo& args) { + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); double value = static_cast((*histogram)->Min()); args.GetReturnValue().Set(value); } -void IntervalHistogram::GetMinBigInt(const FunctionCallbackInfo& args) { +void HistogramImpl::GetMinBigInt(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Min())); } -void IntervalHistogram::GetMax(const FunctionCallbackInfo& args) { - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); +void HistogramImpl::GetMax(const FunctionCallbackInfo& args) { + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); double value = static_cast((*histogram)->Max()); args.GetReturnValue().Set(value); } -void IntervalHistogram::GetMaxBigInt(const FunctionCallbackInfo& args) { +void HistogramImpl::GetMaxBigInt(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); - args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Min())); + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); + args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Max())); } -void IntervalHistogram::GetMean(const FunctionCallbackInfo& args) { - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); +void HistogramImpl::GetMean(const FunctionCallbackInfo& args) { + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); args.GetReturnValue().Set((*histogram)->Mean()); } -void IntervalHistogram::GetExceeds(const FunctionCallbackInfo& args) { - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); +void HistogramImpl::GetExceeds(const FunctionCallbackInfo& args) { + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); double value = static_cast((*histogram)->Exceeds()); args.GetReturnValue().Set(value); } -void IntervalHistogram::GetExceedsBigInt( +void HistogramImpl::GetExceedsBigInt( const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); args.GetReturnValue().Set( BigInt::New(env->isolate(), (*histogram)->Exceeds())); } -void IntervalHistogram::GetStddev(const FunctionCallbackInfo& args) { - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); +void HistogramImpl::GetStddev(const FunctionCallbackInfo& args) { + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); args.GetReturnValue().Set((*histogram)->Stddev()); } -void IntervalHistogram::GetPercentile(const FunctionCallbackInfo& args) { - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); +void HistogramImpl::GetPercentile(const FunctionCallbackInfo& args) { + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); CHECK(args[0]->IsNumber()); double percentile = args[0].As()->Value(); double value = static_cast((*histogram)->Percentile(percentile)); args.GetReturnValue().Set(value); } -void IntervalHistogram::GetPercentileBigInt( +void HistogramImpl::GetPercentileBigInt( const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); CHECK(args[0]->IsNumber()); double percentile = args[0].As()->Value(); int64_t value = (*histogram)->Percentile(percentile); args.GetReturnValue().Set(BigInt::New(env->isolate(), value)); } -void IntervalHistogram::GetPercentiles( +void HistogramImpl::GetPercentiles( const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); CHECK(args[0]->IsMap()); Local map = args[0].As(); (*histogram)->Percentiles([map, env](double key, int64_t value) { @@ -608,11 +451,10 @@ void IntervalHistogram::GetPercentiles( }); } -void IntervalHistogram::GetPercentilesBigInt( +void HistogramImpl::GetPercentilesBigInt( const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); CHECK(args[0]->IsMap()); Local map = args[0].As(); (*histogram)->Percentiles([map, env](double key, int64_t value) { @@ -623,12 +465,18 @@ void IntervalHistogram::GetPercentilesBigInt( }); } -void IntervalHistogram::DoReset(const FunctionCallbackInfo& args) { - IntervalHistogram* histogram; - ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); +void HistogramImpl::DoReset(const FunctionCallbackInfo& args) { + HistogramImpl* histogram = HistogramImpl::FromJSObject(args.Holder()); (*histogram)->Reset(); } +HistogramImpl* HistogramImpl::FromJSObject(Local value) { + auto obj = value.As(); + DCHECK_GE(obj->InternalFieldCount(), HistogramImpl::kInternalFieldCount); + return static_cast( + obj->GetAlignedPointerFromInternalField(HistogramImpl::kImplField)); +} + std::unique_ptr IntervalHistogram::CloneForMessaging() const { return std::make_unique(histogram()); diff --git a/src/histogram.h b/src/histogram.h index a637c1a2e4e348..87ed1a578964b1 100644 --- a/src/histogram.h +++ b/src/histogram.h @@ -69,6 +69,13 @@ class Histogram : public MemoryRetainer { class HistogramImpl { public: + + enum InternalFields { + kSlot = BaseObject::kSlot, + kImplField = BaseObject::kInternalFieldCount, + kInternalFieldCount + }; + explicit HistogramImpl( const Histogram::Options& options = Histogram::Options {}); explicit HistogramImpl(std::shared_ptr histogram); @@ -77,11 +84,37 @@ class HistogramImpl { const std::shared_ptr& histogram() const { return histogram_; } + static void DoReset(const v8::FunctionCallbackInfo& args); + static void GetCountBigInt(const v8::FunctionCallbackInfo& args); + static void GetMinBigInt(const v8::FunctionCallbackInfo& args); + static void GetMaxBigInt(const v8::FunctionCallbackInfo& args); + static void GetExceedsBigInt(const v8::FunctionCallbackInfo& args); + static void GetCount(const v8::FunctionCallbackInfo& args); + static void GetMin(const v8::FunctionCallbackInfo& args); + static void GetMax(const v8::FunctionCallbackInfo& args); + static void GetMean(const v8::FunctionCallbackInfo& args); + static void GetExceeds(const v8::FunctionCallbackInfo& args); + static void GetStddev(const v8::FunctionCallbackInfo& args); + static void GetPercentile( + const v8::FunctionCallbackInfo& args); + static void GetPercentileBigInt( + const v8::FunctionCallbackInfo& args); + static void GetPercentiles( + const v8::FunctionCallbackInfo& args); + static void GetPercentilesBigInt( + const v8::FunctionCallbackInfo& args); + + static void AddMethods(v8::Isolate* isolate, v8::Local tmpl); + + static void RegisterExternalReferences(ExternalReferenceRegistry* registry); + + static HistogramImpl* FromJSObject(v8::Local value); + private: std::shared_ptr histogram_; }; -class HistogramBase : public BaseObject, public HistogramImpl { +class HistogramBase final: public BaseObject, public HistogramImpl { public: static v8::Local GetConstructorTemplate( IsolateData* isolate_data); @@ -103,26 +136,6 @@ class HistogramBase : public BaseObject, public HistogramImpl { SET_MEMORY_INFO_NAME(HistogramBase) SET_SELF_SIZE(HistogramBase) - static void GetCountBigInt(const v8::FunctionCallbackInfo& args); - static void GetMinBigInt(const v8::FunctionCallbackInfo& args); - static void GetMaxBigInt(const v8::FunctionCallbackInfo& args); - static void GetExceedsBigInt(const v8::FunctionCallbackInfo& args); - - static void GetCount(const v8::FunctionCallbackInfo& args); - static void GetMin(const v8::FunctionCallbackInfo& args); - static void GetMax(const v8::FunctionCallbackInfo& args); - static void GetMean(const v8::FunctionCallbackInfo& args); - static void GetExceeds(const v8::FunctionCallbackInfo& args); - static void GetStddev(const v8::FunctionCallbackInfo& args); - static void GetPercentile( - const v8::FunctionCallbackInfo& args); - static void GetPercentileBigInt( - const v8::FunctionCallbackInfo& args); - static void GetPercentiles( - const v8::FunctionCallbackInfo& args); - static void GetPercentilesBigInt( - const v8::FunctionCallbackInfo& args); - static void DoReset(const v8::FunctionCallbackInfo& args); static void Record(const v8::FunctionCallbackInfo& args); static void RecordDelta(const v8::FunctionCallbackInfo& args); static void Add(const v8::FunctionCallbackInfo& args); @@ -164,7 +177,7 @@ class HistogramBase : public BaseObject, public HistogramImpl { }; }; -class IntervalHistogram : public HandleWrap, public HistogramImpl { +class IntervalHistogram final: public HandleWrap, public HistogramImpl { public: enum class StartFlags { NONE, @@ -190,26 +203,6 @@ class IntervalHistogram : public HandleWrap, public HistogramImpl { std::function on_interval, const Histogram::Options& options = Histogram::Options {}); - static void GetCountBigInt(const v8::FunctionCallbackInfo& args); - static void GetMinBigInt(const v8::FunctionCallbackInfo& args); - static void GetMaxBigInt(const v8::FunctionCallbackInfo& args); - static void GetExceedsBigInt(const v8::FunctionCallbackInfo& args); - - static void GetCount(const v8::FunctionCallbackInfo& args); - static void GetMin(const v8::FunctionCallbackInfo& args); - static void GetMax(const v8::FunctionCallbackInfo& args); - static void GetMean(const v8::FunctionCallbackInfo& args); - static void GetExceeds(const v8::FunctionCallbackInfo& args); - static void GetStddev(const v8::FunctionCallbackInfo& args); - static void GetPercentile( - const v8::FunctionCallbackInfo& args); - static void GetPercentileBigInt( - const v8::FunctionCallbackInfo& args); - static void GetPercentiles( - const v8::FunctionCallbackInfo& args); - static void GetPercentilesBigInt( - const v8::FunctionCallbackInfo& args); - static void DoReset(const v8::FunctionCallbackInfo& args); static void Start(const v8::FunctionCallbackInfo& args); static void Stop(const v8::FunctionCallbackInfo& args);