Skip to content

Commit 4e28360

Browse files
fix(runtime): add Object.hasOwn polyfill for JSC compatibility (#53)
Adds Object.hasOwn polyfill to the runtime package for JSC (JavaScriptCore) compatibility.
1 parent 14ccacc commit 4e28360

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
__default__: prerelease
3+
---
4+
5+
Adds Object.hasOwn polyfill to the runtime package for JSC (JavaScriptCore) compatibility.

packages/runtime/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './polyfills.js';
12
import './globals.d.ts';
23

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

packages/runtime/src/polyfills.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Polyfills for ES2022+ features not supported by JSC (JavaScriptCore).
3+
*
4+
* JSC, used in React Native when Hermes is disabled, doesn't support
5+
* Object.hasOwn (ES2022). This causes runtime errors when @vitest/expect
6+
* v4.x initializes.
7+
*
8+
* This polyfill must be loaded before any code that uses Object.hasOwn.
9+
*/
10+
11+
if (typeof Object.hasOwn !== 'function') {
12+
Object.hasOwn = (obj: object, prop: PropertyKey): boolean =>
13+
Object.prototype.hasOwnProperty.call(obj, prop);
14+
}

0 commit comments

Comments
 (0)