@@ -3,12 +3,12 @@ import global from '../core/global';
33/**
44 * @hidden
55 */
6- let bfsSetImmediate : ( cb : Function ) => any ;
6+ let bfsSetImmediate : ( cb : Function , ... args : any [ ] ) => any ;
77if ( typeof ( setImmediate ) !== "undefined" ) {
88 bfsSetImmediate = setImmediate ;
99} else {
1010 const gScope = global ;
11- const timeouts : ( ( ) => void ) [ ] = [ ] ;
11+ const timeouts : ( { fn : ( ... args : any [ ] ) => void , args : any [ ] } ) [ ] = [ ] ;
1212 const messageName = "zero-timeout-message" ;
1313 const canUsePostMessage = function ( ) {
1414 if ( typeof gScope . importScripts !== 'undefined' || ! gScope . postMessage ) {
@@ -24,8 +24,8 @@ if (typeof(setImmediate) !== "undefined") {
2424 return postMessageIsAsync ;
2525 } ;
2626 if ( canUsePostMessage ( ) ) {
27- bfsSetImmediate = function ( fn : ( ) => void ) {
28- timeouts . push ( fn ) ;
27+ bfsSetImmediate = function ( fn : ( ) => void , ... args : any [ ] ) {
28+ timeouts . push ( { fn , args } ) ;
2929 gScope . postMessage ( messageName , "*" ) ;
3030 } ;
3131 const handleMessage = function ( event : MessageEvent ) {
@@ -36,8 +36,8 @@ if (typeof(setImmediate) !== "undefined") {
3636 event . cancelBubble = true ;
3737 }
3838 if ( timeouts . length > 0 ) {
39- const fn = timeouts . shift ( ) ! ;
40- return fn ( ) ;
39+ const { fn , args } = timeouts . shift ( ) ! ;
40+ return fn ( ... args ) ;
4141 }
4242 }
4343 } ;
@@ -51,16 +51,17 @@ if (typeof(setImmediate) !== "undefined") {
5151 const channel = new gScope . MessageChannel ( ) ;
5252 channel . port1 . onmessage = ( event : any ) => {
5353 if ( timeouts . length > 0 ) {
54- return timeouts . shift ( ) ! ( ) ;
54+ const { fn, args } = timeouts . shift ( ) ! ;
55+ return fn ( ...args ) ;
5556 }
5657 } ;
57- bfsSetImmediate = ( fn : ( ) => void ) => {
58- timeouts . push ( fn ) ;
58+ bfsSetImmediate = ( fn : ( ) => void , ... args : any [ ] ) => {
59+ timeouts . push ( { fn , args } ) ;
5960 channel . port2 . postMessage ( '' ) ;
6061 } ;
6162 } else {
62- bfsSetImmediate = function ( fn : ( ) => void ) {
63- return setTimeout ( fn , 0 ) ;
63+ bfsSetImmediate = function ( fn : ( ) => void , ... args : any [ ] ) {
64+ return setTimeout ( fn , 0 , ... args ) ;
6465 } ;
6566 }
6667}
0 commit comments