1111 * @format
1212 */
1313
14- /*eslint no-bitwise: 0*/
15-
1614'use strict' ;
1715
1816const ErrorUtils = require ( 'ErrorUtils' ) ;
@@ -26,7 +24,7 @@ export type SpyData = {
2624 type : number ,
2725 module : ?string ,
2826 method : string | number ,
29- args : any ,
27+ args : any [ ] ,
3028} ;
3129
3230const TO_JS = 0 ;
@@ -37,6 +35,7 @@ const METHOD_IDS = 1;
3735const PARAMS = 2 ;
3836const MIN_TIME_BETWEEN_FLUSHES_MS = 5 ;
3937
38+ // eslint-disable-next-line no-bitwise
4039const TRACE_TAG_REACT_APPS = 1 << 17 ;
4140
4241const DEBUG_INFO_LIMIT = 32 ;
@@ -46,17 +45,17 @@ let JSTimers = null;
4645
4746class MessageQueue {
4847 _lazyCallableModules : { [ key : string ] : ( void ) => Object } ;
49- _queue: [ Array < number > , Array < number > , Array < any > , number ] ;
50- _successCallbacks: Array < ?Function > ;
51- _failureCallbacks: Array < ?Function > ;
48+ _queue: [ number [ ] , number [ ] , any [ ] , number ] ;
49+ _successCallbacks: ( ?Function ) [ ] ;
50+ _failureCallbacks: ( ?Function ) [ ] ;
5251 _callID: number ;
5352 _inCall: number ;
5453 _lastFlush: number ;
5554 _eventLoopStartTime: number ;
5655
57- _debugInfo: Object ;
58- _remoteModuleTable: Object ;
59- _remoteMethodTable: Object ;
56+ _debugInfo: { [ number ] : [ number , number ] } ;
57+ _remoteModuleTable: { [ number ] : string } ;
58+ _remoteMethodTable: { [ number ] : string [ ] } ;
6059
6160 __spy: ?( data : SpyData ) => void ;
6261
@@ -107,11 +106,7 @@ class MessageQueue {
107106 }
108107 }
109108
110- callFunctionReturnFlushedQueue (
111- module : string ,
112- method : string ,
113- args : Array < any > ,
114- ) {
109+ callFunctionReturnFlushedQueue ( module : string , method : string , args : any [ ] ) {
115110 this . __guard ( ( ) => {
116111 this . __callFunction ( module , method , args ) ;
117112 } ) ;
@@ -122,7 +117,7 @@ class MessageQueue {
122117 callFunctionReturnResultAndFlushedQueue (
123118 module : string ,
124119 method : string ,
125- args : Array < any > ,
120+ args : any [ ] ,
126121 ) {
127122 let result ;
128123 this . __guard ( ( ) => {
@@ -132,7 +127,7 @@ class MessageQueue {
132127 return [ result , this . flushedQueue ( ) ] ;
133128 }
134129
135- invokeCallbackAndReturnFlushedQueue ( cbID : number , args : Array < any > ) {
130+ invokeCallbackAndReturnFlushedQueue ( cbID : number , args : any [ ] ) {
136131 this . __guard ( ( ) => {
137132 this . __invokeCallback ( cbID , args ) ;
138133 } ) ;
@@ -178,7 +173,7 @@ class MessageQueue {
178173 enqueueNativeCall (
179174 moduleID : number ,
180175 methodID : number ,
181- params : Array < any > ,
176+ params : any [ ] ,
182177 onFail : ?Function ,
183178 onSucc : ?Function ,
184179 ) {
@@ -191,7 +186,9 @@ class MessageQueue {
191186 }
192187 // Encode callIDs into pairs of callback identifiers by shifting left and using the rightmost bit
193188 // to indicate fail (0) or success (1)
189+ // eslint-disable-next-line no-bitwise
194190 onFail && params . push ( this . _callID << 1 ) ;
191+ // eslint-disable-next-line no-bitwise
195192 onSucc && params . push ( ( this . _callID << 1 ) | 1 ) ;
196193 this . _successCallbacks [ this . _callID ] = onSucc ;
197194 this . _failureCallbacks [ this . _callID ] = onFail ;
@@ -248,7 +245,7 @@ class MessageQueue {
248245 }
249246 }
250247
251- createDebugLookup ( moduleID : number , name : string , methods : Array < string > ) {
248+ createDebugLookup ( moduleID : number , name : string , methods : string [ ] ) {
252249 if ( __DEV__ ) {
253250 this . _remoteModuleTable [ moduleID ] = name ;
254251 this . _remoteMethodTable [ moduleID ] = methods ;
@@ -279,7 +276,7 @@ class MessageQueue {
279276 Systrace . endEvent ( ) ;
280277 }
281278
282- __callFunction ( module : string , method : string , args : Array < any > ) {
279+ __callFunction ( module : string , method : string , args : any [ ] ) : any {
283280 this . _lastFlush = new Date ( ) . getTime ( ) ;
284281 this . _eventLoopStartTime = this . _lastFlush ;
285282 Systrace . beginEvent ( `${ module } .${ method } ()` ) ;
@@ -304,16 +301,18 @@ class MessageQueue {
304301 return result ;
305302 }
306303
307- __invokeCallback ( cbID : number , args : Array < any > ) {
304+ __invokeCallback ( cbID : number , args : any [ ] ) {
308305 this . _lastFlush = new Date ( ) . getTime ( ) ;
309306 this . _eventLoopStartTime = this . _lastFlush ;
310307
311308 // The rightmost bit of cbID indicates fail (0) or success (1), the other bits are the callID shifted left.
309+ // eslint-disable-next-line no-bitwise
312310 const callID = cbID >>> 1 ;
313- const callback =
314- cbID & 1
315- ? this . _successCallbacks [ callID ]
316- : this . _failureCallbacks [ callID ] ;
311+ // eslint-disable-next-line no-bitwise
312+ const isSuccess = cbID & 1 ;
313+ const callback = isSuccess
314+ ? this . _successCallbacks [ callID ]
315+ : this . _failureCallbacks [ callID ] ;
317316
318317 if ( __DEV__ ) {
319318 const debug = this . _debugInfo [ callID ] ;
@@ -344,7 +343,7 @@ class MessageQueue {
344343 }
345344
346345 this . _successCallbacks [ callID ] = this . _failureCallbacks [ callID ] = null ;
347- callback . apply ( null , args ) ;
346+ callback ( ... args ) ;
348347
349348 if ( __DEV__ ) {
350349 Systrace . endEvent ( ) ;
0 commit comments