Skip to content

Commit 37947e7

Browse files
committed
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.
1 parent 9dfd039 commit 37947e7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/histogram.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ void HistogramBase::Initialize(IsolateData* isolate_data,
346346
SetConstructorFunction(isolate_data->isolate(),
347347
target,
348348
"Histogram",
349-
GetConstructorTemplate(isolate_data));
349+
GetConstructorTemplate(isolate_data),
350+
SetConstructorFunctionFlag::NONE);
350351
}
351352

352353
BaseObjectPtr<BaseObject> HistogramBase::HistogramTransferData::Deserialize(
@@ -372,6 +373,7 @@ Local<FunctionTemplate> IntervalHistogram::GetConstructorTemplate(
372373
Isolate* isolate = env->isolate();
373374
tmpl = NewFunctionTemplate(isolate, nullptr);
374375
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
376+
tmpl->SetClassName(OneByteString(isolate, "Histogram"));
375377
tmpl->InstanceTemplate()->SetInternalFieldCount(
376378
HistogramBase::kInternalFieldCount);
377379
SetProtoMethodNoSideEffect(isolate, tmpl, "count", GetCount);

src/node_messaging.cc

+5-2
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)