From bfc49a2718999b6b62addfa25f0e5979139ece72 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 6 Mar 2023 17:09:54 +0100 Subject: [PATCH] src: prevent changing FunctionTemplateInfo after publish Refs https://chromium-review.googlesource.com/c/v8/v8/+/2718147 Fixes an issue where Node.js tries to call SetClassName on a FunctionTemplate twice in some cases. The above CL made it so that V8 CHECKs when this occurs. It is fixed by ensuring SetClassName is only called once. --- src/histogram.cc | 6 ++++-- src/node_messaging.cc | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/histogram.cc b/src/histogram.cc index 3a3228ddc9eb6b..175a67840348ca 100644 --- a/src/histogram.cc +++ b/src/histogram.cc @@ -340,8 +340,9 @@ void HistogramBase::RegisterExternalReferences( } void HistogramBase::Initialize(Environment* env, Local target) { - SetConstructorFunction( - env->context(), target, "Histogram", GetConstructorTemplate(env)); + SetConstructorFunction(env->context(), target, "Histogram", + GetConstructorTemplate(env), + SetConstructorFunctionFlag::NONE); } BaseObjectPtr HistogramBase::HistogramTransferData::Deserialize( @@ -367,6 +368,7 @@ Local IntervalHistogram::GetConstructorTemplate( Isolate* isolate = env->isolate(); tmpl = NewFunctionTemplate(isolate, nullptr); tmpl->Inherit(HandleWrap::GetConstructorTemplate(env)); + tmpl->SetClassName(OneByteString(isolate, "Histogram")); tmpl->InstanceTemplate()->SetInternalFieldCount( HistogramBase::kInternalFieldCount); SetProtoMethodNoSideEffect(isolate, tmpl, "count", GetCount); diff --git a/src/node_messaging.cc b/src/node_messaging.cc index ae9720a3359ced..b92dd2416d8f69 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -1495,13 +1495,16 @@ static void InitMessaging(Local target, t->Inherit(BaseObject::GetConstructorTemplate(env)); t->InstanceTemplate()->SetInternalFieldCount( JSTransferable::kInternalFieldCount); - SetConstructorFunction(context, target, "JSTransferable", t); + t->SetClassName(OneByteString(isolate, "JSTransferable")); + SetConstructorFunction(context, target, "JSTransferable", t, + SetConstructorFunctionFlag::NONE); } SetConstructorFunction(context, target, env->message_port_constructor_string(), - GetMessagePortConstructorTemplate(env)); + GetMessagePortConstructorTemplate(env), + SetConstructorFunctionFlag::NONE); // These are not methods on the MessagePort prototype, because // the browser equivalents do not provide them.