diff --git a/packages/react-native/Libraries/ReactNative/AppRegistryImpl.js b/packages/react-native/Libraries/ReactNative/AppRegistryImpl.js index 33e0c84f3ba..f80b7e1669b 100644 --- a/packages/react-native/Libraries/ReactNative/AppRegistryImpl.js +++ b/packages/react-native/Libraries/ReactNative/AppRegistryImpl.js @@ -30,8 +30,8 @@ import invariant from 'invariant'; type TaskCanceller = () => void; type TaskCancelProvider = () => TaskCanceller; -const runnables: Runnables = {}; -const sections: Runnables = {}; +const runnables = Object.create(null) as any as Runnables; +const sections = Object.create(null) as any as Runnables; const taskProviders: Map = new Map(); const taskCancelProviders: Map = new Map(); let componentProviderInstrumentationHook: ComponentProviderInstrumentationHook = diff --git a/packages/react-native/Libraries/ReactNative/__tests__/AppRegistry-test.js b/packages/react-native/Libraries/ReactNative/__tests__/AppRegistry-test.js new file mode 100644 index 00000000000..08a152d4193 --- /dev/null +++ b/packages/react-native/Libraries/ReactNative/__tests__/AppRegistry-test.js @@ -0,0 +1,35 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + */ + +'use strict'; + +const AppRegistry = require('../AppRegistryImpl'); + +describe('AppRegistry', () => { + it('does not return inherited Object properties as registered apps', () => { + expect(AppRegistry.getRunnable('constructor')).toBeUndefined(); + }); + + it('registers app and section keys named __proto__', () => { + const app = jest.fn(); + const section = () => + function Section() { + return null; + }; + + AppRegistry.registerRunnable('__proto__', app); + AppRegistry.registerSection('__proto__', section); + + expect(AppRegistry.getRunnable('__proto__')).toBeInstanceOf(Function); + expect(AppRegistry.getAppKeys()).toContain('__proto__'); + expect(AppRegistry.getSectionKeys()).toContain('__proto__'); + expect(Object.keys(AppRegistry.getSections())).toContain('__proto__'); + }); +});