Skip to content

Commit

Permalink
src: prevent changing FunctionTemplateInfo after publish
Browse files Browse the repository at this point in the history
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: nodejs#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>
  • Loading branch information
codebytere authored and MoLow committed Jul 6, 2023
1 parent 7283486 commit d0ad873
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/histogram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,11 @@ void HistogramBase::RegisterExternalReferences(
}

void HistogramBase::Initialize(Environment* env, Local<Object> target) {
SetConstructorFunction(
env->context(), target, "Histogram", GetConstructorTemplate(env));
SetConstructorFunction(env->context(),
target,
"Histogram",
GetConstructorTemplate(env),
SetConstructorFunctionFlag::NONE);
}

BaseObjectPtr<BaseObject> HistogramBase::HistogramTransferData::Deserialize(
Expand All @@ -367,6 +370,7 @@ Local<FunctionTemplate> 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);
Expand Down
7 changes: 5 additions & 2 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1495,13 +1495,16 @@ static void InitMessaging(Local<Object> target,
t->Inherit(BaseObject::GetConstructorTemplate(env));
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.
Expand Down

0 comments on commit d0ad873

Please sign in to comment.