Skip to content

Migrate container from using BufferSource#6491

Merged
jasnell merged 1 commit intomainfrom
jasnell/no-buffersource-in-container
Apr 3, 2026
Merged

Migrate container from using BufferSource#6491
jasnell merged 1 commit intomainfrom
jasnell/no-buffersource-in-container

Conversation

@jasnell
Copy link
Copy Markdown
Collaborator

@jasnell jasnell commented Apr 2, 2026

Use the lighter weight Js* types

Use the lighter weight Js* types
@jasnell jasnell requested review from guybedford and npaun April 2, 2026 22:36
@jasnell jasnell requested review from a team as code owners April 2, 2026 22:36
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Apr 2, 2026

The lazy instance property uses a GetterCallback that calls the getter and converts the return value through the TypeWrapper. JsArrayBuffer (which extends JsBase<v8::ArrayBuffer>) should convert directly to a v8::Local<v8::Value> since it's a V8 handle wrapper. This is a straightforward conversion.

Let me also verify there are no GC visitability concerns — JsArrayBuffer is a V8 handle wrapper (not persistent), so it should be fine as a return type from a lazy property getter (it's created and returned, not stored).

Let me also check the ExecOutput class for any GC visit concerns with this change. Looking at the header — ExecOutput stores kj::Array<kj::byte> (C++ data), not JS objects. The getters create a new JsArrayBuffer on each call, which is correct for a lazy property (evaluated once, then cached by V8). Since BufferSource was previously returned (which contained a BackingStore that needed visiting), and JsArrayBuffer is a transient V8 local handle, the GC story is actually simpler now — no visitForGc needed for the return value.

This is a clean, straightforward migration. The changes:

  1. Remove the copyBytes helper function (no longer needed)
  2. Change return types from jsg::BufferSource to jsg::JsArrayBuffer
  3. Use jsg::JsArrayBuffer::create(js, data) which allocates and copies in one step

The semantics are preserved (data is copied into a new ArrayBuffer each call). The TypeScript override already declares readonly stdout: ArrayBuffer and readonly stderr: ArrayBuffer, which is consistent with JsArrayBuffer.

LGTM

github run

@jasnell jasnell merged commit 10eed5b into main Apr 3, 2026
25 checks passed
@jasnell jasnell deleted the jasnell/no-buffersource-in-container branch April 3, 2026 00:26
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.

2 participants