mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
## Summary - Fixed segmentation fault when calling `toContainAnyKeys`, `toContainKeys`, and `toContainAllKeys` on non-object values (null, undefined, numbers, strings, etc.) - Added proper validation to check if value is an object before calling `hasOwnPropertyValue` or `keys()` - Added comprehensive test coverage for edge cases ## Problem The matchers were crashing with a segmentation fault when called with non-object values because: 1. `toContainAnyKeys` and `toContainKeys` were calling `hasOwnPropertyValue` without checking if the value is an object first 2. `toContainAllKeys` was calling `keys()` without checking if the value is an object first 3. The `hasOwnPropertyValue` function documentation explicitly states: "If the object is not an object, it will crash. **You must check if the object is an object before calling this function.**" ## Solution - Added `value.isObject()` check in `toContainAnyKeys` before attempting to check for properties - Fixed `toContainKeys` by replacing the `toBoolean()` check with `isObject()` check - Fixed `toContainAllKeys` by adding proper object validation before calling `keys()` - For non-objects with empty expected arrays, the matchers return true (matching jest-extended behavior) ## Test plan - [x] Added comprehensive test coverage in `test/js/bun/test/expect.test.js` - [x] Tests cover: null, undefined, numbers, strings, booleans, symbols, BigInt, arrays, functions - [x] All existing jest-extended tests continue to pass - [x] Debug build compiles and all tests pass 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>