4
4
* This source code is licensed under the MIT license found in the
5
5
* LICENSE file in the root directory of this source tree.
6
6
*
7
- * @flow
7
+ * @flow strict
8
8
* @format
9
9
*/
10
10
@@ -22,7 +22,7 @@ export type SpyData = {
22
22
type : number ,
23
23
module : ?string ,
24
24
method : string | number ,
25
- args : any [ ] ,
25
+ args : mixed [ ] ,
26
26
...
27
27
} ;
28
28
@@ -40,10 +40,10 @@ const TRACE_TAG_REACT_APPS = 1 << 17;
40
40
const DEBUG_INFO_LIMIT = 32 ;
41
41
42
42
class MessageQueue {
43
- _lazyCallableModules : { [ key : string ] : ( void ) => Object , ...} ;
44
- _queue : [ number [ ] , number [ ] , any [ ] , number ] ;
45
- _successCallbacks : Map < number , ?Function > ;
46
- _failureCallbacks : Map < number , ?Function > ;
43
+ _lazyCallableModules : { [ key : string ] : ( void ) => { ... } , ...} ;
44
+ _queue : [ number [ ] , number [ ] , mixed [ ] , number ] ;
45
+ _successCallbacks : Map < number , ?( ... mixed [ ] ) => void > ;
46
+ _failureCallbacks : Map < number , ?( ... mixed [ ] ) => void > ;
47
47
_callID : number ;
48
48
_lastFlush : number ;
49
49
_eventLoopStartTime : number ;
@@ -71,11 +71,15 @@ class MessageQueue {
71
71
this . _remoteMethodTable = { } ;
72
72
}
73
73
74
- ( this : any ) . callFunctionReturnFlushedQueue = this . callFunctionReturnFlushedQueue . bind (
74
+ // $FlowFixMe[cannot-write]
75
+ this . callFunctionReturnFlushedQueue = this . callFunctionReturnFlushedQueue . bind (
75
76
this ,
76
77
) ;
77
- ( this : any ) . flushedQueue = this . flushedQueue . bind ( this ) ;
78
- ( this : any ) . invokeCallbackAndReturnFlushedQueue = this . invokeCallbackAndReturnFlushedQueue . bind (
78
+ // $FlowFixMe[cannot-write]
79
+ this . flushedQueue = this . flushedQueue . bind ( this ) ;
80
+
81
+ // $FlowFixMe[cannot-write]
82
+ this . invokeCallbackAndReturnFlushedQueue = this . invokeCallbackAndReturnFlushedQueue . bind (
79
83
this ,
80
84
) ;
81
85
}
@@ -89,7 +93,7 @@ class MessageQueue {
89
93
MessageQueue . prototype . __spy = info => {
90
94
console . log (
91
95
`${ info . type === TO_JS ? 'N->JS' : 'JS->N' } : ` +
92
- `${ info . module ? info . module + '.' : '' } ${ info . method } ` +
96
+ `${ info . module != null ? info . module + '.' : '' } ${ info . method } ` +
93
97
`(${ JSON . stringify ( info . args ) } )` ,
94
98
) ;
95
99
} ;
@@ -103,8 +107,8 @@ class MessageQueue {
103
107
callFunctionReturnFlushedQueue (
104
108
module : string ,
105
109
method : string ,
106
- args : any [ ] ,
107
- ) : null | [ Array < number > , Array < number > , Array < any > , number ] {
110
+ args : mixed [ ] ,
111
+ ) : null | [ Array < number > , Array < number > , Array < mixed > , number ] {
108
112
this . __guard ( ( ) => {
109
113
this . __callFunction ( module , method , args ) ;
110
114
} ) ;
@@ -114,16 +118,16 @@ class MessageQueue {
114
118
115
119
invokeCallbackAndReturnFlushedQueue (
116
120
cbID : number ,
117
- args : any [ ] ,
118
- ) : null | [ Array < number > , Array < number > , Array < any > , number ] {
121
+ args : mixed [ ] ,
122
+ ) : null | [ Array < number > , Array < number > , Array < mixed > , number ] {
119
123
this . __guard ( ( ) => {
120
124
this . __invokeCallback ( cbID , args ) ;
121
125
} ) ;
122
126
123
127
return this . flushedQueue ( ) ;
124
128
}
125
129
126
- flushedQueue ( ) : null | [ Array < number > , Array < number > , Array < any > , number ] {
130
+ flushedQueue ( ) : null | [ Array < number > , Array < number > , Array < mixed > , number ] {
127
131
this . __guard ( ( ) => {
128
132
this . __callImmediates ( ) ;
129
133
} ) ;
@@ -137,13 +141,13 @@ class MessageQueue {
137
141
return Date . now ( ) - this . _eventLoopStartTime ;
138
142
}
139
143
140
- registerCallableModule ( name : string , module : Object ) {
144
+ registerCallableModule ( name : string , module : { ... } ) {
141
145
this . _lazyCallableModules [ name ] = ( ) => module ;
142
146
}
143
147
144
- registerLazyCallableModule ( name : string , factory : void => Object ) {
145
- let module : Object ;
146
- let getValue : ?( void ) => Object = factory ;
148
+ registerLazyCallableModule ( name : string , factory : void => { ... } ) {
149
+ let module : { ... } ;
150
+ let getValue : ?( void ) => { ... } = factory ;
147
151
this . _lazyCallableModules [ name ] = ( ) => {
148
152
if ( getValue ) {
149
153
module = getValue ( ) ;
@@ -153,18 +157,18 @@ class MessageQueue {
153
157
} ;
154
158
}
155
159
156
- getCallableModule ( name : string ) : any | null {
160
+ getCallableModule ( name : string ) : { ... } | null {
157
161
const getValue = this . _lazyCallableModules [ name ] ;
158
162
return getValue ? getValue ( ) : null ;
159
163
}
160
164
161
165
callNativeSyncHook (
162
166
moduleID : number ,
163
167
methodID : number ,
164
- params : any [ ] ,
165
- onFail : ?Function ,
166
- onSucc : ?Function ,
167
- ) : any {
168
+ params : mixed [ ] ,
169
+ onFail : ?( ... mixed [ ] ) = > void ,
170
+ onSucc : ?( ... mixed [ ] ) = > void ,
171
+ ) : mixed {
168
172
if ( __DEV__ ) {
169
173
invariant (
170
174
global . nativeCallSyncHook ,
@@ -181,10 +185,10 @@ class MessageQueue {
181
185
processCallbacks (
182
186
moduleID : number ,
183
187
methodID : number ,
184
- params : any [ ] ,
185
- onFail : ?Function ,
186
- onSucc : ?Function ,
187
- ) {
188
+ params : mixed [ ] ,
189
+ onFail : ?( ... mixed [ ] ) = > void ,
190
+ onSucc : ?( ... mixed [ ] ) = > void ,
191
+ ) : void {
188
192
if ( onFail || onSucc ) {
189
193
if ( __DEV__ ) {
190
194
this . _debugInfo [ this . _callID ] = [ moduleID , methodID ] ;
@@ -232,9 +236,9 @@ class MessageQueue {
232
236
enqueueNativeCall (
233
237
moduleID : number ,
234
238
methodID : number ,
235
- params : any [ ] ,
236
- onFail : ?Function ,
237
- onSucc : ?Function ,
239
+ params : mixed [ ] ,
240
+ onFail : ?( ... mixed [ ] ) = > void ,
241
+ onSucc : ?( ... mixed [ ] ) = > void ,
238
242
) {
239
243
this . processCallbacks ( moduleID , methodID , params , onFail , onSucc ) ;
240
244
@@ -247,30 +251,34 @@ class MessageQueue {
247
251
// function it is permitted here, and special-cased in the
248
252
// conversion.
249
253
const isValidArgument = val => {
250
- const t = typeof val ;
251
- if (
252
- t === 'undefined' ||
253
- t === 'null' ||
254
- t === 'boolean' ||
255
- t === 'string'
256
- ) {
257
- return true ;
258
- }
259
- if ( t === 'number' ) {
260
- return isFinite ( val ) ;
261
- }
262
- if ( t === 'function' || t !== 'object' ) {
263
- return false ;
264
- }
265
- if ( Array . isArray ( val ) ) {
266
- return val . every ( isValidArgument ) ;
267
- }
268
- for ( const k in val ) {
269
- if ( typeof val [ k ] !== 'function' && ! isValidArgument ( val [ k ] ) ) {
254
+ switch ( typeof val ) {
255
+ case 'undefined' :
256
+ case 'boolean' :
257
+ case 'string' :
258
+ return true ;
259
+ case 'number' :
260
+ return isFinite ( val ) ;
261
+ case 'object' :
262
+ if ( val == null ) {
263
+ return true ;
264
+ }
265
+
266
+ if ( Array . isArray ( val ) ) {
267
+ return val . every ( isValidArgument ) ;
268
+ }
269
+
270
+ for ( const k in val ) {
271
+ if ( typeof val [ k ] !== 'function' && ! isValidArgument ( val [ k ] ) ) {
272
+ return false ;
273
+ }
274
+ }
275
+
276
+ return true ;
277
+ case 'function' :
278
+ return false ;
279
+ default :
270
280
return false ;
271
- }
272
281
}
273
- return true ;
274
282
} ;
275
283
276
284
// Replacement allows normally non-JSON-convertible values to be
@@ -295,7 +303,7 @@ class MessageQueue {
295
303
) ;
296
304
297
305
// The params object should not be mutated after being queued
298
- deepFreezeAndThrowOnMutationInDev ( ( params : any ) ) ;
306
+ deepFreezeAndThrowOnMutationInDev ( params ) ;
299
307
}
300
308
this . _queue [ PARAMS ] . push ( params ) ;
301
309
@@ -382,7 +390,7 @@ class MessageQueue {
382
390
Systrace . endEvent ( ) ;
383
391
}
384
392
385
- __callFunction ( module : string , method : string , args : any [ ] ) : void {
393
+ __callFunction ( module : string , method : string , args : mixed [ ] ) : void {
386
394
this . _lastFlush = Date . now ( ) ;
387
395
this . _eventLoopStartTime = this . _lastFlush ;
388
396
if ( __DEV__ || this . __spy ) {
@@ -410,7 +418,7 @@ class MessageQueue {
410
418
Systrace . endEvent ( ) ;
411
419
}
412
420
413
- __invokeCallback ( cbID : number , args : any [ ] ) {
421
+ __invokeCallback ( cbID : number , args : mixed [ ] ) {
414
422
this . _lastFlush = Date . now ( ) ;
415
423
this . _eventLoopStartTime = this . _lastFlush ;
416
424
0 commit comments