Skip to content

Conversation

@dylan-conway
Copy link
Member

What does this PR do?

blob.stream(undefined)

How did you verify your code works?

Added a test

@robobun
Copy link
Collaborator

robobun commented Nov 20, 2025

Updated 3:36 PM PT - Nov 20th, 2025

@autofix-ci[bot], your commit c09a1d2 has 6 failures in Build #32130 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 24900

That installs a local version of the PR into your bun-24900 executable, so you can run:

bun-24900 --bun

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

Walkthrough

The PR refactors Blob.stream() argument handling to use direct callframe access instead of manual slicing, adds validation for number type, updates numeric coercion logic, and adds test coverage for undefined/null parameter handling.

Changes

Cohort / File(s) Change Summary
Blob.stream() argument handling
src/bun.js/webcore/Blob.zig
Replaced manual argument extraction with direct callframe.argument(0) access; added null/undefined validation with type checking; updated numeric coercion to use recommended_chunk_size_value.toInt64()
Ban limits update
test/internal/ban-limits.json
Decreased .arguments_old( count from 265 to 264
Stream test coverage
test/js/web/streams/streams.test.js
Added test case verifying that Blob.stream(undefined) and Blob.stream(null) return ReadableStream without crashing

Possibly related PRs

Suggested reviewers

  • taylordotfish
  • zackradisic

Pre-merge checks

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: handling undefined chunkSize in Blob.prototype.stream().
Description check ✅ Passed The description follows the required template with both sections completed, though responses are very brief. What does this PR do? and How did you verify your code works? are both answered.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 28b950e and c09a1d2.

📒 Files selected for processing (3)
  • src/bun.js/webcore/Blob.zig (1 hunks)
  • test/internal/ban-limits.json (1 hunks)
  • test/js/web/streams/streams.test.js (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: cirospaciari
Repo: oven-sh/bun PR: 22946
File: test/js/sql/sql.test.ts:195-202
Timestamp: 2025-09-25T22:07:13.851Z
Learning: PR oven-sh/bun#22946: JSON/JSONB result parsing updates (e.g., returning parsed arrays instead of legacy strings) are out of scope for this PR; tests keep current expectations with a TODO. Handle parsing fixes in a separate PR.
📚 Learning: 2025-10-17T20:50:58.644Z
Learnt from: taylordotfish
Repo: oven-sh/bun PR: 23755
File: src/bun.js/api/bun/socket/Handlers.zig:154-159
Timestamp: 2025-10-17T20:50:58.644Z
Learning: In Bun socket configuration error messages (src/bun.js/api/bun/socket/Handlers.zig), use the user-facing JavaScript names "data" and "drain" instead of internal field names "onData" and "onWritable", as these are the names users see in the API according to SocketConfig.bindv2.ts.

Applied to files:

  • src/bun.js/webcore/Blob.zig
📚 Learning: 2025-09-26T01:10:04.233Z
Learnt from: nektro
Repo: oven-sh/bun PR: 22781
File: test/internal/ban-limits.json:25-26
Timestamp: 2025-09-26T01:10:04.233Z
Learning: The test/internal/ban-limits.json file contains accurate counts that are validated by tests - if the counts were incorrect, the associated tests would fail, so the values in this file reflect the actual current state of the codebase.

Applied to files:

  • test/internal/ban-limits.json
📚 Learning: 2025-10-01T21:49:27.862Z
Learnt from: taylordotfish
Repo: oven-sh/bun PR: 23169
File: src/bun.js/bindings/BunIDLConvert.h:29-42
Timestamp: 2025-10-01T21:49:27.862Z
Learning: In Bun's IDL bindings (src/bun.js/bindings/BunIDLConvert.h), IDLStrictNull intentionally treats both undefined and null as null (using isUndefinedOrNull()), matching WebKit's IDLNull & IDLNullable behavior. This is the correct implementation and should not be changed to only accept null.

Applied to files:

  • test/js/web/streams/streams.test.js
🔇 Additional comments (3)
test/internal/ban-limits.json (1)

7-7: Ban-limits decrement correctly reflects one fewer .arguments_old( usage

The updated count for ".arguments_old(" aligns with the removal of a callframe.arguments_old usage in Blob.getStream. Given this file is test-validated, this adjustment looks correct.
Based on learnings

src/bun.js/webcore/Blob.zig (1)

1973-1995: Updated getStream argument handling correctly fixes undefined/null chunkSize, with a minor behavior tightening

The new logic

  • Uses callframe.argument(0) plus isUndefinedOrNull() so that missing/undefined/null chunkSize all skip the block and keep recommended_chunk_size at 0, which matches existing blob.stream() behavior and fixes the crash for blob.stream(undefined|null).
  • Enforces isNumber() before converting, throwing "chunkSize must be a number" for non-number inputs. This is a deliberate tightening: previously, numeric-like values (e.g. "64") may have been coerced; now they will error instead.
  • Converts via recommended_chunk_size_value.toInt64(), truncates to i52, clamps at >= 0, then casts to SizeType = u52, which prevents negative sizes and keeps the value within the expected numeric domain.

Functionally this looks sound and consistent with the new test, but it does slightly change behavior for non-number inputs. Please confirm that rejecting non-number-but-coercible values for chunkSize is acceptable for Bun’s public API, and consider adding a brief note to docs/tests if this is an intentional tightening.

test/js/web/streams/streams.test.js (1)

1062-1068: New Blob.stream(undefined/null) test is appropriately targeted

The test cleanly verifies that blob.stream(undefined) and blob.stream(null) both construct a ReadableStream without crashing, complementing existing blob.stream() tests without over-constraining behavior. This is a good, focused regression test for the new argument-handling path.


Comment @coderabbitai help to get the list of available commands and usage tips.

@dylan-conway dylan-conway merged commit b72ba31 into main Nov 21, 2025
51 of 57 checks passed
@dylan-conway dylan-conway deleted the dylan/fix-blob-stream-undefined branch November 21, 2025 01:01
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.

4 participants