Skip to content

Replace a few more raw references with kj::Ptr in standard.c++ - #6949

Open
jasnell wants to merge 1 commit into
mainfrom
jasnell/standard-kj-ptr
Open

Replace a few more raw references with kj::Ptr in standard.c++#6949
jasnell wants to merge 1 commit into
mainfrom
jasnell/standard-kj-ptr

Conversation

@jasnell

@jasnell jasnell commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: James M Snell <jsnell@cloudflare.com>
@jasnell
jasnell requested review from a team as code owners August 10, 2026 15:29
@ask-bonk

ask-bonk Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

I've completed a thorough review of this PR. Let me summarize my analysis:

What the PR does: Replaces raw C++ references (Controller&, ReadableStreamJsController&) with kj::Ptr<T> in the streams standard.c++ file. This adds kj::PtrTarget as a base class to ReadableStreamJsController and converts several T& fields/parameters to kj::Ptr<T>.

Key findings:

  1. Pattern consistency: This follows the exact same pattern already established by ReadableStreamInternalController which also uses public ReadableStreamController, public kj::PtrTarget (internal.h:41). The tryPipeLock(addPtrToThis()) pattern mirrors internal.c++:2483.

  2. Safety improvement: The onConsumerWantsData pattern change from ReadableStreamJsController& owner = s.owner; to auto owner = s.owner; (copy of kj::Ptr) is a legitimate safety improvement. The old code saved a raw reference to s.owner before calling into callbacks that could destroy this. With kj::Ptr, debug builds will assert if the target is destroyed while the Ptr is still alive, making the invariant "owner outlives us" explicitly checkable.

  3. PipeLocked::inner change: Changing from Controller& inner to kj::Ptr<Controller> inner is safe - the comment correctly documents that PipeLocked lives in the controller's own lock state machine, so the pointer is always valid.

  4. ReadableState::owner change: The kj::Ptr<ReadableStreamJsController> owner field correctly represents the non-owning back-pointer to the controller. The kj::mv() calls on kj::Ptr parameters are idiomatic.

  5. Multiple inheritance: No diamond problem - ReadableStreamController does not inherit from kj::PtrTarget.

  6. No behavioral changes: This is purely a mechanical refactor of internal pointer representations. No API surface changes, no compat flag needed.

No actionable issues found.

LGTM

github run

@codspeed-hq

This comment was marked as low quality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant