Skip to content

Commit 146b613

Browse files
authored
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 <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a437bb9 commit 146b613

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
@@ -345,7 +345,8 @@ void HistogramBase::Initialize(IsolateData* isolate_data,
345345
SetConstructorFunction(isolate_data->isolate(),
346346
target,
347347
"Histogram",
348-
GetConstructorTemplate(isolate_data));
348+
GetConstructorTemplate(isolate_data),
349+
SetConstructorFunctionFlag::NONE);
349350
}
350351

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

src/node_messaging.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -1496,13 +1496,16 @@ static void InitMessaging(Local<Object> target,
14961496
NewFunctionTemplate(isolate, JSTransferable::New);
14971497
t->InstanceTemplate()->SetInternalFieldCount(
14981498
JSTransferable::kInternalFieldCount);
1499-
SetConstructorFunction(context, target, "JSTransferable", t);
1499+
t->SetClassName(OneByteString(isolate, "JSTransferable"));
1500+
SetConstructorFunction(
1501+
context, target, "JSTransferable", t, SetConstructorFunctionFlag::NONE);
15001502
}
15011503

15021504
SetConstructorFunction(context,
15031505
target,
15041506
env->message_port_constructor_string(),
1505-
GetMessagePortConstructorTemplate(env));
1507+
GetMessagePortConstructorTemplate(env),
1508+
SetConstructorFunctionFlag::NONE);
15061509

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

0 commit comments

Comments
 (0)