Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d3a15f1

Browse files
committedMar 6, 2023
fix: 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 00981ea commit d3a15f1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
 

‎src/histogram.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ 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(), target, "Histogram",
344+
GetConstructorTemplate(env),
345+
SetConstructorFunctionFlag::NONE);
345346
}
346347

347348
BaseObjectPtr<BaseObject> HistogramBase::HistogramTransferData::Deserialize(
@@ -367,6 +368,7 @@ Local<FunctionTemplate> IntervalHistogram::GetConstructorTemplate(
367368
Isolate* isolate = env->isolate();
368369
tmpl = NewFunctionTemplate(isolate, nullptr);
369370
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
371+
tmpl->SetClassName(OneByteString(isolate, "Histogram"));
370372
tmpl->InstanceTemplate()->SetInternalFieldCount(
371373
HistogramBase::kInternalFieldCount);
372374
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(context, target, "JSTransferable", t,
1500+
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)
Please sign in to comment.