Skip to content

Conversation

@bheemreddy-samsara
Copy link
Contributor

Description

Adds Object.hasOwn polyfill to the runtime package for JSC (JavaScriptCore) compatibility.

JSC doesn't support Object.hasOwn (ES2022). This causes runtime errors when @vitest/expect v4.x initializes:

Object.hasOwn is not a function. (In 'Object.hasOwn(globalThis, MATCHERS_OBJECT)', 'Object.hasOwn' is undefined)

Related Issue

Fixes #52

Context

The error originates from @vitest/expect/dist/index.js:674:

if (!Object.hasOwn(globalThis, MATCHERS_OBJECT)) {

This was previously misattributed to Hermes (#51), but Hermes has supported Object.hasOwn in recent versions. The issue specifically affects JSC runtime, which is used when Hermes is disabled or on certain platform configurations.

Since react-native-harness targets React Native (which may use JSC) and depends on @vitest/expect v4.x, the polyfill belongs in the harness runtime rather than requiring every consumer to add it.

The polyfill is minimal and standards-compliant:

if (typeof Object.hasOwn !== 'function') {
  Object.hasOwn = (obj: object, prop: PropertyKey): boolean =>
    Object.prototype.hasOwnProperty.call(obj, prop);
}

Testing

  • Tested on iOS simulator with JSC runtime
  • Harness tests pass after adding this polyfill

References

JSC (JavaScriptCore) doesn't support Object.hasOwn (ES2022). This causes
runtime errors when @vitest/expect v4.x initializes.

The polyfill is loaded before any other runtime code to ensure
Object.hasOwn is available when @vitest/expect initializes.
@vercel
Copy link

vercel bot commented Jan 9, 2026

@bheemreddy-samsara is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

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.

Runtime crashes on JSC: Object.hasOwn is not a function

1 participant