|
28 | 28 | const startTime =
|
29 | 29 | global.nativePerformanceNow != null ? global.nativePerformanceNow() : null;
|
30 | 30 |
|
31 |
| -const {polyfillObjectProperty, polyfillGlobal} = require('PolyfillFunctions'); |
32 |
| - |
33 |
| -if (global.GLOBAL === undefined) { |
34 |
| - global.GLOBAL = global; |
35 |
| -} |
36 |
| - |
37 |
| -if (global.window === undefined) { |
38 |
| - global.window = global; |
39 |
| -} |
40 |
| - |
41 |
| -// Set up collections |
42 |
| -const _shouldPolyfillCollection = require('_shouldPolyfillES6Collection'); |
43 |
| -if (_shouldPolyfillCollection('Map')) { |
44 |
| - polyfillGlobal('Map', () => require('Map')); |
45 |
| -} |
46 |
| -if (_shouldPolyfillCollection('Set')) { |
47 |
| - polyfillGlobal('Set', () => require('Set')); |
48 |
| -} |
49 |
| - |
50 |
| -// Set up process |
51 |
| -global.process = global.process || {}; |
52 |
| -global.process.env = global.process.env || {}; |
53 |
| -if (!global.process.env.NODE_ENV) { |
54 |
| - global.process.env.NODE_ENV = __DEV__ ? 'development' : 'production'; |
55 |
| -} |
56 |
| - |
57 |
| -// Setup the Systrace profiling hooks if necessary |
58 |
| -if (global.__RCTProfileIsProfiling) { |
59 |
| - const Systrace = require('Systrace'); |
60 |
| - Systrace.installReactHook(); |
61 |
| - Systrace.setEnabled(true); |
62 |
| -} |
63 |
| - |
64 |
| -// Set up console |
65 |
| -const ExceptionsManager = require('ExceptionsManager'); |
66 |
| -ExceptionsManager.installConsoleErrorReporter(); |
67 |
| - |
68 |
| -// Set up error handler |
69 |
| -if (!global.__fbDisableExceptionsManager) { |
70 |
| - const handleError = (e, isFatal) => { |
71 |
| - try { |
72 |
| - ExceptionsManager.handleException(e, isFatal); |
73 |
| - } catch (ee) { |
74 |
| - console.log('Failed to print error: ', ee.message); |
75 |
| - throw e; |
76 |
| - } |
77 |
| - }; |
78 |
| - |
79 |
| - const ErrorUtils = require('ErrorUtils'); |
80 |
| - ErrorUtils.setGlobalHandler(handleError); |
81 |
| -} |
82 |
| - |
83 |
| -// Check for compatibility between the JS and native code |
84 |
| -const ReactNativeVersionCheck = require('ReactNativeVersionCheck'); |
85 |
| -ReactNativeVersionCheck.checkVersions(); |
86 |
| - |
87 |
| -// Set up Promise |
88 |
| -// The native Promise implementation throws the following error: |
89 |
| -// ERROR: Event loop not supported. |
90 |
| -polyfillGlobal('Promise', () => require('Promise')); |
91 |
| - |
92 |
| -// Set up regenerator. |
93 |
| -polyfillGlobal('regeneratorRuntime', () => { |
94 |
| - // The require just sets up the global, so make sure when we first |
95 |
| - // invoke it the global does not exist |
96 |
| - delete global.regeneratorRuntime; |
97 |
| - |
98 |
| - // regenerator-runtime/runtime exports the regeneratorRuntime object, so we |
99 |
| - // can return it safely. |
100 |
| - return require('regenerator-runtime/runtime'); |
101 |
| -}); |
102 |
| - |
103 |
| -// Set up timers |
104 |
| -const defineLazyTimer = name => { |
105 |
| - polyfillGlobal(name, () => require('JSTimers')[name]); |
106 |
| -}; |
107 |
| -defineLazyTimer('setTimeout'); |
108 |
| -defineLazyTimer('setInterval'); |
109 |
| -defineLazyTimer('setImmediate'); |
110 |
| -defineLazyTimer('clearTimeout'); |
111 |
| -defineLazyTimer('clearInterval'); |
112 |
| -defineLazyTimer('clearImmediate'); |
113 |
| -defineLazyTimer('requestAnimationFrame'); |
114 |
| -defineLazyTimer('cancelAnimationFrame'); |
115 |
| -defineLazyTimer('requestIdleCallback'); |
116 |
| -defineLazyTimer('cancelIdleCallback'); |
117 |
| - |
118 |
| -// Set up XHR |
119 |
| -// The native XMLHttpRequest in Chrome dev tools is CORS aware and won't |
120 |
| -// let you fetch anything from the internet |
121 |
| -polyfillGlobal('XMLHttpRequest', () => require('XMLHttpRequest')); |
122 |
| -polyfillGlobal('FormData', () => require('FormData')); |
123 |
| - |
124 |
| -polyfillGlobal('fetch', () => require('fetch').fetch); |
125 |
| -polyfillGlobal('Headers', () => require('fetch').Headers); |
126 |
| -polyfillGlobal('Request', () => require('fetch').Request); |
127 |
| -polyfillGlobal('Response', () => require('fetch').Response); |
128 |
| -polyfillGlobal('WebSocket', () => require('WebSocket')); |
129 |
| -polyfillGlobal('Blob', () => require('Blob')); |
130 |
| -polyfillGlobal('File', () => require('File')); |
131 |
| -polyfillGlobal('FileReader', () => require('FileReader')); |
132 |
| -polyfillGlobal('URL', () => require('URL')); |
133 |
| - |
134 |
| -// Set up alert |
135 |
| -if (!global.alert) { |
136 |
| - global.alert = function(text) { |
137 |
| - // Require Alert on demand. Requiring it too early can lead to issues |
138 |
| - // with things like Platform not being fully initialized. |
139 |
| - require('Alert').alert('Alert', '' + text); |
140 |
| - }; |
141 |
| -} |
142 |
| - |
143 |
| -// Set up Geolocation |
144 |
| -let navigator = global.navigator; |
145 |
| -if (navigator === undefined) { |
146 |
| - global.navigator = navigator = {}; |
147 |
| -} |
148 |
| - |
149 |
| -// see https://github.com/facebook/react-native/issues/10881 |
150 |
| -polyfillObjectProperty(navigator, 'product', () => 'ReactNative'); |
151 |
| -polyfillObjectProperty(navigator, 'geolocation', () => require('Geolocation')); |
152 |
| - |
153 |
| -// Just to make sure the JS gets packaged up. Wait until the JS environment has |
154 |
| -// been initialized before requiring them. |
155 |
| -const BatchedBridge = require('BatchedBridge'); |
156 |
| -BatchedBridge.registerLazyCallableModule('Systrace', () => require('Systrace')); |
157 |
| -BatchedBridge.registerLazyCallableModule('JSTimers', () => require('JSTimers')); |
158 |
| -BatchedBridge.registerLazyCallableModule('HeapCapture', () => |
159 |
| - require('HeapCapture'), |
160 |
| -); |
161 |
| -BatchedBridge.registerLazyCallableModule('SamplingProfiler', () => |
162 |
| - require('SamplingProfiler'), |
163 |
| -); |
164 |
| -BatchedBridge.registerLazyCallableModule('RCTLog', () => require('RCTLog')); |
165 |
| -BatchedBridge.registerLazyCallableModule('RCTDeviceEventEmitter', () => |
166 |
| - require('RCTDeviceEventEmitter'), |
167 |
| -); |
168 |
| -BatchedBridge.registerLazyCallableModule('RCTNativeAppEventEmitter', () => |
169 |
| - require('RCTNativeAppEventEmitter'), |
170 |
| -); |
171 |
| -BatchedBridge.registerLazyCallableModule('PerformanceLogger', () => |
172 |
| - require('PerformanceLogger'), |
173 |
| -); |
174 |
| -BatchedBridge.registerLazyCallableModule('JSDevSupportModule', () => |
175 |
| - require('JSDevSupportModule'), |
176 |
| -); |
177 |
| - |
178 |
| -global.__fetchSegment = function( |
179 |
| - segmentId: number, |
180 |
| - options: {|+otaBuildNumber: ?string|}, |
181 |
| - callback: (?Error) => void, |
182 |
| -) { |
183 |
| - const {SegmentFetcher} = require('NativeModules'); |
184 |
| - if (!SegmentFetcher) { |
185 |
| - throw new Error( |
186 |
| - 'SegmentFetcher is missing. Please ensure that it is ' + |
187 |
| - 'included as a NativeModule.', |
188 |
| - ); |
189 |
| - } |
190 |
| - |
191 |
| - SegmentFetcher.fetchSegment( |
192 |
| - segmentId, |
193 |
| - options, |
194 |
| - (errorObject: ?{message: string, code: string}) => { |
195 |
| - if (errorObject) { |
196 |
| - const error = new Error(errorObject.message); |
197 |
| - (error: any).code = errorObject.code; |
198 |
| - callback(error); |
199 |
| - } |
200 |
| - |
201 |
| - callback(null); |
202 |
| - }, |
203 |
| - ); |
204 |
| -}; |
205 |
| - |
206 |
| -// Set up devtools |
| 31 | +require('setUpGlobals'); |
| 32 | +require('polyfillES6Collections'); |
| 33 | +require('setUpSystrace'); |
| 34 | +require('setUpErrorHandling'); |
| 35 | +require('checkNativeVersion'); |
| 36 | +require('polyfillPromise'); |
| 37 | +require('setUpRegeneratorRuntime'); |
| 38 | +require('setUpTimers'); |
| 39 | +require('setUpXHR'); |
| 40 | +require('setUpAlert'); |
| 41 | +require('setUpGeolocation'); |
| 42 | +require('setUpBatchedBridge'); |
| 43 | +require('setUpSegmentFetcher'); |
207 | 44 | if (__DEV__) {
|
208 |
| - if (!global.__RCTProfileIsProfiling) { |
209 |
| - BatchedBridge.registerCallableModule('HMRClient', require('HMRClient')); |
210 |
| - |
211 |
| - // not when debugging in chrome |
212 |
| - // TODO(t12832058) This check is broken |
213 |
| - if (!window.document) { |
214 |
| - require('setupDevtools'); |
215 |
| - } |
216 |
| - |
217 |
| - // Set up inspector |
218 |
| - const JSInspector = require('JSInspector'); |
219 |
| - JSInspector.registerAgent(require('NetworkAgent')); |
220 |
| - } |
| 45 | + require('setUpDeveloperTools'); |
221 | 46 | }
|
222 | 47 |
|
223 | 48 | if (startTime != null) {
|
|
0 commit comments