diff --git a/Libraries/Core/setUpGlobals.js b/Libraries/Core/setUpGlobals.js index 4d740807dd156d..8ddff03bc66e78 100644 --- a/Libraries/Core/setUpGlobals.js +++ b/Libraries/Core/setUpGlobals.js @@ -15,18 +15,21 @@ * You can use this module directly, or just require InitializeCore. */ if (global.window === undefined) { - // $FlowFixMe[cannot-write] + // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it. global.window = global; } if (global.self === undefined) { - // $FlowFixMe[cannot-write] + // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it. global.self = global; } // Set up process +// $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it. global.process = global.process || {}; +// $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it. global.process.env = global.process.env || {}; if (!global.process.env.NODE_ENV) { + // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it. global.process.env.NODE_ENV = __DEV__ ? 'development' : 'production'; } diff --git a/Libraries/Core/setUpNavigator.js b/Libraries/Core/setUpNavigator.js index 1dbe429aaea2a8..bcf2cbd597b5fb 100644 --- a/Libraries/Core/setUpNavigator.js +++ b/Libraries/Core/setUpNavigator.js @@ -12,10 +12,11 @@ const {polyfillObjectProperty} = require('../Utilities/PolyfillFunctions'); -let navigator = global.navigator; +const navigator = global.navigator; if (navigator === undefined) { - global.navigator = navigator = {}; + // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it. + global.navigator = {product: 'ReactNative'}; +} else { + // see https://github.com/facebook/react-native/issues/10881 + polyfillObjectProperty(navigator, 'product', () => 'ReactNative'); } - -// see https://github.com/facebook/react-native/issues/10881 -polyfillObjectProperty(navigator, 'product', () => 'ReactNative'); diff --git a/Libraries/Core/setUpPerformance.js b/Libraries/Core/setUpPerformance.js index c007370c6bb4f8..ef12f6c9ae1580 100644 --- a/Libraries/Core/setUpPerformance.js +++ b/Libraries/Core/setUpPerformance.js @@ -17,6 +17,7 @@ if (!global.performance) { * https://developer.mozilla.org/en-US/docs/Web/API/Performance/now */ if (typeof global.performance.now !== 'function') { + // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it. global.performance.now = function () { const performanceNow = global.nativePerformanceNow || Date.now; return performanceNow(); diff --git a/Libraries/Core/setUpWebPerformance.js b/Libraries/Core/setUpWebPerformance.js index 13475773d29dfc..333c5c57c1b03c 100644 --- a/Libraries/Core/setUpWebPerformance.js +++ b/Libraries/Core/setUpWebPerformance.js @@ -12,5 +12,6 @@ import Performance from '../WebPerformance/Performance'; // TODO: Replace setUpPerformance with this once the WebPerformance API is stable (T143070419) export default function setUpPerformance() { + // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it. global.performance = new Performance(); } diff --git a/flow/global.js b/flow/global.js index ee60a57fdb03cc..63624ca3d2dc16 100644 --- a/flow/global.js +++ b/flow/global.js @@ -19,8 +19,19 @@ declare var global: { // setUpGlobals +window: typeof global, +self: typeof global, + +process: { + +env: { + +NODE_ENV: 'development' | 'production', + }, + +argv?: $ReadOnlyArray, + }, - // setXHR + // setUpPerformance + +performance: { + +now: () => number, + }, + + // setUpXHR +XMLHttpRequest: typeof XMLHttpRequest, +FormData: typeof FormData, +fetch: typeof fetch, @@ -39,17 +50,27 @@ declare var global: { // setUpAlert +alert: typeof alert, + // setUpNavigator + +navigator: { + +product: 'ReactNative', + +appName?: ?string, + ... + }, + // setUpTimers - +clearInterval: typeof clearInterval, - +clearTimeout: typeof clearTimeout, +setInterval: typeof setInterval, + +clearInterval: typeof clearInterval, +setTimeout: typeof setTimeout, + +clearTimeout: typeof clearTimeout, +requestAnimationFrame: typeof requestAnimationFrame, +cancelAnimationFrame: typeof cancelAnimationFrame, +requestIdleCallback: typeof requestIdleCallback, +cancelIdleCallback: typeof cancelIdleCallback, - +setTimeout: typeof setTimeout, +queueMicrotask: typeof queueMicrotask, + +setImmediate: typeof setImmediate, + +clearImmediate: typeof clearImmediate, + + // Polyfills +console: typeof console, // JavaScript environments specific