@@ -13,26 +13,27 @@ function runTests() {
1313 window . document . body . removeChild ( iframe ) ;
1414 }
1515 iframe = null ;
16- delete window [ callbackFnName ] ;
16+ if ( callbackFnName in window ) {
17+ delete window [ callbackFnName ] ;
18+ }
1719 } ) ;
18-
19- it ( '#8581 Should not raise error' , async function ( ) {
20+ this . beforeEach ( ( ) => {
2021 callbackFnName = "callback" + Date . now ( ) ;
21- const okPromise = new Promise ( ( res ) => {
22- window [ callbackFnName ] = ( ) => {
23- delete window [ callbackFnName ] ;
24- res ( ) ;
25- } ;
26- } ) ;
27- iframe = window . document . createElement ( "iframe" ) ;
28- iframe . src = "about:blank" ;
22+ iframe = window . document . createElement ( "iframe" , { src : "about:blank" } ) ;
2923 window . document . body . appendChild ( iframe ) ;
24+ } )
25+
26+ it ( '#8581 Should not raise error' , function ( done ) {
27+ window [ callbackFnName ] = ( err ) => {
28+ if ( timeout ) timeout = clearTimeout ( timeout ) ;
29+ done ( err ) ;
30+ window [ callbackFnName ] = ( ) => { } ;
31+ } ;
32+ let timeout = setTimeout ( ( ) => callbackFnName in window && window [ callbackFnName ] ( new Error ( `Timed out` ) ) , 500 ) ;
3033 const target = iframe . contentDocument ;
3134 const scriptElement = target . createElement ( "script" ) ;
32- scriptElement . innerHTML = `localStorage.setItem("Hello",new Date());
33- requestIdleCallback(()=>window.parent.${ callbackFnName } (),{timeout:100});` ;
35+ scriptElement . innerHTML = `localStorage.setItem("Hello",new Date());setTimeout(window.parent.${ callbackFnName } ,100);` ;
3436 target . body . appendChild ( scriptElement ) ;
35- await Promise . race ( [ okPromise , new Promise ( res => setTimeout ( res , 250 ) ) ] ) ;
3637 } ) ;
3738 } ) ;
3839}
0 commit comments