Skip to content

Commit 97b7092

Browse files
fix(runtime): add Object.hasOwn polyfill for Hermes compatibility
Hermes (React Native's default JS engine) doesn't support Object.hasOwn (ES2022). This causes runtime errors when @vitest/expect v4.x initializes because it uses Object.hasOwn internally. Error without fix: ``` Object.hasOwn is not a function. (In 'Object.hasOwn(globalThis, MATCHERS_OBJECT)', 'Object.hasOwn' is undefined) ``` Add polyfill in runtime package that loads before @vitest/expect. Tracking: facebook/hermes#1875
1 parent 14ccacc commit 97b7092

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

packages/runtime/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Polyfills must be imported first to ensure compatibility with Hermes
2+
import './polyfills.js';
13
import './globals.d.ts';
24

35
export { UI as ReactNativeHarness } from './ui/index.js';

packages/runtime/src/polyfills.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Polyfills for Hermes JavaScript engine compatibility.
3+
*
4+
* Hermes (React Native's default JS engine) doesn't support all ES2022+ features.
5+
* This file provides polyfills for features used by harness dependencies.
6+
*/
7+
8+
/**
9+
* Object.hasOwn (ES2022)
10+
* Used by @vitest/expect v4.x for property checking.
11+
* @see https://github.com/facebook/hermes/issues/1875
12+
*/
13+
if (typeof Object.hasOwn !== 'function') {
14+
Object.hasOwn = (obj: object, prop: PropertyKey): boolean =>
15+
Object.prototype.hasOwnProperty.call(obj, prop);
16+
}

0 commit comments

Comments
 (0)