diff --git a/packages/react-native/Libraries/ReactNative/__tests__/getNativeComponentAttributes-test.js b/packages/react-native/Libraries/ReactNative/__tests__/getNativeComponentAttributes-test.js index 5f4d6196476..5f23200fa7d 100644 --- a/packages/react-native/Libraries/ReactNative/__tests__/getNativeComponentAttributes-test.js +++ b/packages/react-native/Libraries/ReactNative/__tests__/getNativeComponentAttributes-test.js @@ -10,11 +10,13 @@ 'use strict'; +let mockDefaultEventTypes: {[string]: unknown} = {}; + jest.mock('../UIManager', () => ({ __esModule: true, default: { getConstants: () => ({ViewManagerNames: []}), - getDefaultEventTypes: () => ({}), + getDefaultEventTypes: () => mockDefaultEventTypes, getViewManagerConfig: name => name === 'TestView' ? { @@ -33,6 +35,10 @@ const getNativeComponentAttributes = require('../getNativeComponentAttributes').default; describe('getNativeComponentAttributes', () => { + beforeEach(() => { + mockDefaultEventTypes = {}; + }); + it('processes object font variation settings from native view configs', () => { const viewConfig = getNativeComponentAttributes('TestView'); @@ -46,4 +52,13 @@ describe('getNativeComponentAttributes', () => { }), ).toBe("'opsz' 17.25, 'wght' 552.5"); }); + + it('merges event types that shadow Object prototype properties', () => { + const hasOwnPropertyEvent = {registrationName: 'onHasOwnProperty'}; + mockDefaultEventTypes = {hasOwnProperty: hasOwnPropertyEvent}; + + const viewConfig = getNativeComponentAttributes('TestView'); + + expect(viewConfig.hasOwnProperty).toBe(hasOwnPropertyEvent); + }); }); diff --git a/packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js b/packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js index d42571f88d0..69b2486f09c 100644 --- a/packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js +++ b/packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js @@ -138,6 +138,9 @@ function attachDefaultEventTypes( } } +// $FlowFixMe[method-unbinding] +const hasOwnProperty = Object.prototype.hasOwnProperty; + // TODO: Figure out how to avoid all this runtime initialization cost. function merge( destination: ?ViewManagerConfig, @@ -151,12 +154,16 @@ function merge( } for (const key in source) { - if (!source.hasOwnProperty(key)) { + /* $FlowFixMe[invalid-this-arg] Error exposed after fixing this typing + * unsoundness in flow */ + if (!hasOwnProperty.call(source, key)) { continue; } let sourceValue = source[key]; - if (destination.hasOwnProperty(key)) { + /* $FlowFixMe[invalid-this-arg] Error exposed after fixing this typing + * unsoundness in flow */ + if (hasOwnProperty.call(destination, key)) { const destinationValue = destination[key]; if ( typeof sourceValue === 'object' &&