From 146b613941853aaa013d35d6a45724569ce29879 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 25 Apr 2023 11:12:45 +0200 Subject: [PATCH] src: prevent changing FunctionTemplateInfo after publish MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. PR-URL: https://github.com/nodejs/node/pull/46979 Reviewed-By: Ben Noordhuis Reviewed-By: Juan José Arboleda Reviewed-By: Minwoo Jung Reviewed-By: James M Snell --- src/histogram.cc | 4 +++- src/node_messaging.cc | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/histogram.cc b/src/histogram.cc index 5a2b1acf897647..3caa6e8248ce27 100644 --- a/src/histogram.cc +++ b/src/histogram.cc @@ -345,7 +345,8 @@ void HistogramBase::Initialize(IsolateData* isolate_data, SetConstructorFunction(isolate_data->isolate(), target, "Histogram", - GetConstructorTemplate(isolate_data)); + GetConstructorTemplate(isolate_data), + SetConstructorFunctionFlag::NONE); } BaseObjectPtr HistogramBase::HistogramTransferData::Deserialize( @@ -371,6 +372,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 b40868a1ceeff4..2d126d98441bad 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -1496,13 +1496,16 @@ static void InitMessaging(Local target, NewFunctionTemplate(isolate, JSTransferable::New); 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.