Repository navigation
Conversation
…ue shims Terminal.rs and bake_body.rs each had a private get_optional_value that reads a property and maps undefined or null to None. JSValue::get_optional already does that read; it only lacked a CoerceTo impl for a plain JSValue. Add the identity impl and call get_optional::<JSValue> and get_optional::<i32> at the 13 sites. Remove the reimplemented_helper baseline line for Terminal.rs.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 5 included reviews per hour; 0 remain after this review. WalkthroughChangesTyped optional access
Suggested reviewers: Merge Risk: ⚪ Minimal · up to This localized change centralizes optional JavaScript value handling and removes duplicate parsing helpers without a reported behavior change; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
LGTM — mechanical dedup that routes two local get_optional_value shims through the existing JSValue::get_optional::<T> by adding an identity CoerceTo for JSValue.
What was reviewed
- Traced
get_optional::<T>(JSValue.rs:1528) andget(JSValue.rs:1109): same two-step filter (missing/undefined → None, then null → None) as the deleted shims, soget_optional::<JSValue>is byte-for-byte equivalent. get_optional_i32→get_optional::<i32>: both end incoerce::<i32>, identical semantics.- Checked all 13 rewritten call sites in Terminal.rs and bake_body.rs — argument order and property names unchanged; baseline entry removal matches the deleted duplicate.
Extended reasoning...
Overview
This PR deduplicates two private helper functions. Terminal.rs had a JSValueTerminalExt trait with get_optional_value / get_optional_i32, and bake_body.rs had a free get_optional_value function. Both implemented the same read: get(global, name)?, filter undefined/null to None, otherwise return the value (or coerce to i32). The shared JSValue::get_optional::<T: CoerceTo> in bun_jsc already does exactly this composition but lacked a CoerceTo impl for JSValue itself. The PR adds a 3-line identity impl (coerce_from returns Ok(v)), rewires 13 call sites to get_optional::<JSValue> / get_optional::<i32>, deletes the shims, and removes the corresponding reimplemented_helper mordant baseline line.
Security risks
None. This is option-parsing plumbing with no change to what values are accepted, coerced, or rejected. No auth, crypto, path handling, or untrusted-input parsing behavior is touched.
Level of scrutiny
Low. I verified the equivalence claim directly against source: get (JSValue.rs:1109-1137) maps missing/ValueDeleted/undefined to None; get_optional (JSValue.rs:1528-1540) then filters is_undefined_or_null() and calls coerce::<T>. With the new identity CoerceTo for JSValue, get_optional::<JSValue> is precisely match get()? { Some(v) if !v.is_undefined_or_null() => Some(v), _ => None } — the deleted shim body. The i32 path already used the same coerce::<i32> the deleted get_optional_i32 called. The change is purely structural.
Other factors
The PR description states bun bd test test/js/bun/terminal/terminal.test.ts and bun bd test test/bake/dev/bundle.test.ts pass, and cargo dylint is clean against the edited baseline. The diff is small (~60 lines net removed), touches no lifecycle/refcount/GC code, and follows the repo's stated preference for extending shared helpers over per-crate shims. No prior review comments on the timeline.
|
Closing as stale: this PR conflicts with main, and its last commit is from 2026-08-24. The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR. |
Problem
Bun.Terminaloption parsing (src/runtime/api/bun/Terminal.rs) and the bake config parser (src/runtime/bake/bake_body.rs) each carry a privateget_optional_valueshim. Both read a property and mapundefinedornulltoNone. Their bodies are identical. mordant reports this asreimplemented_helperforTerminal.rs, accepted by the baseline line"reimplemented_helper:src/runtime/api/bun/Terminal.rs" = 1.bun_jscalready has this read asJSValue::get_optional::<T>. It only lacked aCoerceToimpl that hands the value back unchanged, so the two crates could not call it for a plainJSValue. The Terminal shim also duplicatedget_optional::<i32>asget_optional_i32.Fix
impl CoerceTo for JSValueinsrc/jsc/JSValue.rs.coerce_fromreturns the value.get_optional::<JSValue>is then the same read the shims did:get, thenNoneforundefinedornull.JSValueTerminalExttrait inTerminal.rsand theget_optional_valuefunction inbake_body.rs. The 13 call sites useget_optional::<JSValue>orget_optional::<i32>.JSValue::get_optionalhas the same two steps as the shims:getreturnsNonefor a missing property and forundefined, thenis_undefined_or_nullfiltersnull, thencoerce. Fori32the Terminal shim called the samecoerce::<i32>.cargo dylint --all -p bun_runtimeis clean against the edited baseline.bun bd test test/js/bun/terminal/terminal.test.tsandbun bd test test/bake/dev/bundle.test.tspass.Background
JSValue::get(global, name)returnsOk(None)when the property is missing orundefined,Ok(Some(v))otherwise, andErrwhen the getter throws.CoerceTois the dispatch trait behindJSValue::coerce::<T>().i32andi64implement it with ToNumber style conversions.get_optional::<T>composesget, thenullfilter, andcoerce::<T>.bun run rust:mordant.mordant-baseline.tomlrecords, per lint and file, how many findings are accepted.reimplemented_helperflags two functions in one crate with the same signature and body.