Skip to content

Commit 9a85add

Browse files
codebyteredanielleadams
authored andcommitted
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. PR-URL: #46979 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2a3b99c commit 9a85add

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/histogram.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,11 @@ void HistogramBase::RegisterExternalReferences(
340340
}
341341

342342
void HistogramBase::Initialize(Environment* env, Local<Object> target) {
343-
SetConstructorFunction(
344-
env->context(), target, "Histogram", GetConstructorTemplate(env));
343+
SetConstructorFunction(env->context(),
344+
target,
345+
"Histogram",
346+
GetConstructorTemplate(env),
347+
SetConstructorFunctionFlag::NONE);
345348
}
346349

347350
BaseObjectPtr<BaseObject> HistogramBase::HistogramTransferData::Deserialize(
@@ -367,6 +370,7 @@ Local<FunctionTemplate> IntervalHistogram::GetConstructorTemplate(
367370
Isolate* isolate = env->isolate();
368371
tmpl = NewFunctionTemplate(isolate, nullptr);
369372
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
373+
tmpl->SetClassName(OneByteString(isolate, "Histogram"));
370374
tmpl->InstanceTemplate()->SetInternalFieldCount(
371375
HistogramBase::kInternalFieldCount);
372376
SetProtoMethodNoSideEffect(isolate, tmpl, "count", GetCount);

src/node_messaging.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,13 +1495,16 @@ static void InitMessaging(Local<Object> target,
14951495
t->Inherit(BaseObject::GetConstructorTemplate(env));
14961496
t->InstanceTemplate()->SetInternalFieldCount(
14971497
JSTransferable::kInternalFieldCount);
1498-
SetConstructorFunction(context, target, "JSTransferable", t);
1498+
t->SetClassName(OneByteString(isolate, "JSTransferable"));
1499+
SetConstructorFunction(
1500+
context, target, "JSTransferable", t, SetConstructorFunctionFlag::NONE);
14991501
}
15001502

15011503
SetConstructorFunction(context,
15021504
target,
15031505
env->message_port_constructor_string(),
1504-
GetMessagePortConstructorTemplate(env));
1506+
GetMessagePortConstructorTemplate(env),
1507+
SetConstructorFunctionFlag::NONE);
15051508

15061509
// These are not methods on the MessagePort prototype, because
15071510
// the browser equivalents do not provide them.

0 commit comments

Comments
 (0)