diff --git a/packages/polyfills/Object.es8.js b/packages/polyfills/Object.es8.js deleted file mode 100644 index 4925f6e2dee071..00000000000000 --- a/packages/polyfills/Object.es8.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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. - * - * @format - * @polyfill - * @nolint - */ - -(function () { - 'use strict'; - - const hasOwnProperty = Object.prototype.hasOwnProperty; - - /** - * Returns an array of the given object's own enumerable entries. - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries - */ - if (typeof Object.entries !== 'function') { - Object.entries = function (object) { - // `null` and `undefined` values are not allowed. - if (object == null) { - throw new TypeError('Object.entries called on non-object'); - } - - const entries = []; - for (const key in object) { - if (hasOwnProperty.call(object, key)) { - entries.push([key, object[key]]); - } - } - return entries; - }; - } - - /** - * Returns an array of the given object's own enumerable entries. - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values - */ - if (typeof Object.values !== 'function') { - Object.values = function (object) { - // `null` and `undefined` values are not allowed. - if (object == null) { - throw new TypeError('Object.values called on non-object'); - } - - const values = []; - for (const key in object) { - if (hasOwnProperty.call(object, key)) { - values.push(object[key]); - } - } - return values; - }; - } -})(); diff --git a/packages/polyfills/__tests__/Object.es8-test.js b/packages/polyfills/__tests__/Object.es8-test.js deleted file mode 100644 index c53512f1756195..00000000000000 --- a/packages/polyfills/__tests__/Object.es8-test.js +++ /dev/null @@ -1,140 +0,0 @@ -/** - * 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. - * - * @format - * @oncall jsinfra - */ - -'use strict'; - -describe('Object (ES8)', () => { - beforeEach(() => { - delete Object.entries; - delete Object.values; - jest.resetModules(); - require('../Object.es8'); - }); - - describe('Object.entries', () => { - it('should have a length of 1', () => { - expect(Object.entries.length).toBe(1); - }); - - it('should check for type', () => { - expect(Object.entries.bind(null, null)).toThrow( - TypeError('Object.entries called on non-object'), - ); - expect(Object.entries.bind(null, undefined)).toThrow( - TypeError('Object.entries called on non-object'), - ); - expect(Object.entries.bind(null, [])).not.toThrow(); - expect(Object.entries.bind(null, () => {})).not.toThrow(); - expect(Object.entries.bind(null, {})).not.toThrow(); - expect(Object.entries.bind(null, 'abc')).not.toThrow(); - }); - - it('should return enumerable entries', () => { - const foo = Object.defineProperties( - {}, - { - x: {value: 10, enumerable: true}, - y: {value: 20}, - }, - ); - - expect(Object.entries(foo)).toEqual([['x', 10]]); - - const bar = {x: 10, y: 20}; - expect(Object.entries(bar)).toEqual([ - ['x', 10], - ['y', 20], - ]); - }); - - it('should work with proto-less objects', () => { - const foo = Object.create(null, { - x: {value: 10, enumerable: true}, - y: {value: 20}, - }); - - expect(Object.entries(foo)).toEqual([['x', 10]]); - }); - - it('should return only own entries', () => { - const foo = Object.create( - {z: 30}, - { - x: {value: 10, enumerable: true}, - y: {value: 20}, - }, - ); - - expect(Object.entries(foo)).toEqual([['x', 10]]); - }); - - it('should convert to object primitive string', () => { - expect(Object.entries('ab')).toEqual([ - ['0', 'a'], - ['1', 'b'], - ]); - }); - }); - - describe('Object.values', () => { - it('should have a length of 1', () => { - expect(Object.values.length).toBe(1); - }); - - it('should check for type', () => { - expect(Object.values.bind(null, null)).toThrow( - TypeError('Object.values called on non-object'), - ); - expect(Object.values.bind(null, [])).not.toThrow(); - expect(Object.values.bind(null, () => {})).not.toThrow(); - expect(Object.values.bind(null, {})).not.toThrow(); - }); - - it('should return enumerable values', () => { - const foo = Object.defineProperties( - {}, - { - x: {value: 10, enumerable: true}, - y: {value: 20}, - }, - ); - - expect(Object.values(foo)).toEqual([10]); - - const bar = {x: 10, y: 20}; - expect(Object.values(bar)).toEqual([10, 20]); - }); - - it('should work with proto-less objects', () => { - const foo = Object.create(null, { - x: {value: 10, enumerable: true}, - y: {value: 20}, - }); - - expect(Object.values(foo)).toEqual([10]); - }); - - it('should return only own values', () => { - const foo = Object.create( - {z: 30}, - { - x: {value: 10, enumerable: true}, - y: {value: 20}, - }, - ); - - expect(Object.values(foo)).toEqual([10]); - }); - - it('should convert to object primitive string', () => { - expect(Object.values('ab')).toEqual(['a', 'b']); - }); - }); -}); diff --git a/packages/polyfills/index.js b/packages/polyfills/index.js index 5979051ac30132..90aa1dc08343b3 100644 --- a/packages/polyfills/index.js +++ b/packages/polyfills/index.js @@ -12,5 +12,4 @@ module.exports = () => [ require.resolve('./console.js'), require.resolve('./error-guard.js'), - require.resolve('./Object.es8.js'), ]; diff --git a/packages/react-native/jest/setup.js b/packages/react-native/jest/setup.js index e98550f23fc783..db727255aaac8e 100644 --- a/packages/react-native/jest/setup.js +++ b/packages/react-native/jest/setup.js @@ -12,7 +12,6 @@ const MockNativeMethods = jest.requireActual('./MockNativeMethods'); const mockComponent = jest.requireActual('./mockComponent'); -jest.requireActual('@react-native/js-polyfills/Object.es8'); jest.requireActual('@react-native/js-polyfills/error-guard'); Object.defineProperties(global, {