Skip to content

Commit 9e9daef

Browse files
committed
Fix native component event property checks
1 parent 2fa055f commit 9e9daef

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

packages/react-native/Libraries/ReactNative/__tests__/getNativeComponentAttributes-test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
'use strict';
1212

13+
let mockDefaultEventTypes: {[string]: unknown} = {};
14+
1315
jest.mock('../UIManager', () => ({
1416
__esModule: true,
1517
default: {
1618
getConstants: () => ({ViewManagerNames: []}),
17-
getDefaultEventTypes: () => ({}),
19+
getDefaultEventTypes: () => mockDefaultEventTypes,
1820
getViewManagerConfig: name =>
1921
name === 'TestView'
2022
? {
@@ -33,6 +35,10 @@ const getNativeComponentAttributes =
3335
require('../getNativeComponentAttributes').default;
3436

3537
describe('getNativeComponentAttributes', () => {
38+
beforeEach(() => {
39+
mockDefaultEventTypes = {};
40+
});
41+
3642
it('processes object font variation settings from native view configs', () => {
3743
const viewConfig = getNativeComponentAttributes('TestView');
3844

@@ -46,4 +52,13 @@ describe('getNativeComponentAttributes', () => {
4652
}),
4753
).toBe("'opsz' 17.25, 'wght' 552.5");
4854
});
55+
56+
it('merges event types that shadow Object prototype properties', () => {
57+
const hasOwnPropertyEvent = {registrationName: 'onHasOwnProperty'};
58+
mockDefaultEventTypes = {hasOwnProperty: hasOwnPropertyEvent};
59+
60+
const viewConfig = getNativeComponentAttributes('TestView');
61+
62+
expect(viewConfig.hasOwnProperty).toBe(hasOwnPropertyEvent);
63+
});
4964
});

packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ function attachDefaultEventTypes(viewConfig: any) {
134134
}
135135
}
136136

137+
// $FlowFixMe[method-unbinding]
138+
const hasOwnProperty = Object.prototype.hasOwnProperty;
139+
137140
// TODO: Figure out how to avoid all this runtime initialization cost.
138141
function merge(destination: ?Object, source: ?Object): ?Object {
139142
if (!source) {
@@ -144,12 +147,12 @@ function merge(destination: ?Object, source: ?Object): ?Object {
144147
}
145148

146149
for (const key in source) {
147-
if (!source.hasOwnProperty(key)) {
150+
if (!hasOwnProperty.call(source, key)) {
148151
continue;
149152
}
150153

151154
let sourceValue = source[key];
152-
if (destination.hasOwnProperty(key)) {
155+
if (hasOwnProperty.call(destination, key)) {
153156
const destinationValue = destination[key];
154157
if (
155158
typeof sourceValue === 'object' &&

0 commit comments

Comments
 (0)