mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49408 ## Motivation Modernising the RN codebase to allow for modern Flow tooling to process it. ## This diff - Migrates Utilities/deepFreezeAndThrowOnMutationInDev.js, Utilities/defineLazyObjectProperty.js, Utilities/DeviceInfo.js & Utilities/FeatureDetection.js to use the export syntax. - Updates deep-imports of files that were migrated to a single export default to use `.default` - Updates the current iteration of API snapshots (intended). Changelog: [General][Breaking] - Deep imports to `Utilities/deepFreezeAndThrowOnMutationInDev`, `Utilities/defineLazyObjectProperty`, `Utilities/DeviceInfo` or `Utilities/FeatureDetection` with `require` syntax may need to be appended with '.default'. Reviewed By: huntie Differential Revision: D69602536 fbshipit-source-id: 7ec06995a1d244b95d4f970551955d9e6013de13
30 lines
984 B
JavaScript
30 lines
984 B
JavaScript
/**
|
|
* 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
|
|
* @format
|
|
*/
|
|
|
|
/**
|
|
* @return whether or not a @param {function} f is provided natively by calling
|
|
* `toString` and check if the result includes `[native code]` in it.
|
|
*
|
|
* Note that a polyfill can technically fake this behavior but few does it.
|
|
* Therefore, this is usually good enough for our purpose.
|
|
*/
|
|
export function isNativeFunction(f: Function): boolean {
|
|
return typeof f === 'function' && f.toString().indexOf('[native code]') > -1;
|
|
}
|
|
|
|
/**
|
|
* @return whether or not the constructor of @param {object} o is an native
|
|
* function named with @param {string} expectedName.
|
|
*/
|
|
export function hasNativeConstructor(o: Object, expectedName: string): boolean {
|
|
const con = Object.getPrototypeOf(o).constructor;
|
|
return con.name === expectedName && isNativeFunction(con);
|
|
}
|