Skip to content

Commit 66ee1f1

Browse files
RaisinTentargos
authored andcommitted
src: register StreamBase while registering LibuvStreamWrap
This resolves this TODO - https://github.com/nodejs/node/blob/71071f896aa9696b5d36bb3bec1c7217e7420509/src/stream_wrap.cc#L111-L112. Signed-off-by: Darshan Sen <[email protected]> PR-URL: #43321 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2b55b60 commit 66ee1f1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/stream_base.cc

+5
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ void StreamBase::AddMethods(Environment* env, Local<FunctionTemplate> t) {
452452

453453
void StreamBase::RegisterExternalReferences(
454454
ExternalReferenceRegistry* registry) {
455+
// This function is called by a single thread during start up, so it is safe
456+
// to use a local static variable here.
457+
static bool is_registered = false;
458+
if (is_registered) return;
455459
registry->Register(GetFD);
456460
registry->Register(GetExternal);
457461
registry->Register(GetBytesRead);
@@ -471,6 +475,7 @@ void StreamBase::RegisterExternalReferences(
471475
registry->Register(
472476
BaseObject::InternalFieldSet<StreamBase::kOnReadFunctionField,
473477
&Value::IsFunction>);
478+
is_registered = true;
474479
}
475480

476481
void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) {

src/stream_wrap.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ void LibuvStreamWrap::RegisterExternalReferences(
108108
registry->Register(IsConstructCallCallback);
109109
registry->Register(GetWriteQueueSize);
110110
registry->Register(SetBlocking);
111-
// TODO(joyee): StreamBase::RegisterExternalReferences() is called somewhere
112-
// else but we may want to do it here too and guard it with a static flag.
111+
StreamBase::RegisterExternalReferences(registry);
113112
}
114113

115114
LibuvStreamWrap::LibuvStreamWrap(Environment* env,

0 commit comments

Comments
 (0)