@@ -22,14 +22,10 @@ else {
2222async function ready ( ) {
2323 var runAutomatedTestsBtn = document . getElementById ( "run-automated-tests-btn" ) ;
2424 var runWeakTestsPart1Btn = document . getElementById ( "run-weak-tests-part-1-btn" ) ;
25- var runWeakTestsPart2Btn = document . getElementById ( "run-weak-tests-part-2-btn" ) ;
26- var runWeakTestsPart3Btn = document . getElementById ( "run-weak-tests-part-3-btn" ) ;
2725 testResultsEl = document . getElementById ( "test-results" ) ;
2826
2927 runAutomatedTestsBtn . addEventListener ( "click" , runAutomatedTests ) ;
3028 runWeakTestsPart1Btn . addEventListener ( "click" , runWeakTestsPart1 ) ;
31- runWeakTestsPart2Btn . addEventListener ( "click" , runWeakTestsPart2 ) ;
32- runWeakTestsPart3Btn . addEventListener ( "click" , runWeakTestsPart3 ) ;
3329
3430 try {
3531 await runAutomatedTests ( ) ;
@@ -43,6 +39,8 @@ async function ready() {
4339}
4440
4541async function runAutomatedTests ( ) {
42+ cleanupWeakTestsButtons ( ) ;
43+
4644 testResultsEl . innerHTML = "Running automated tests...<br>" ;
4745
4846 for ( let testFn of [ runSyncTests , runAsyncTests , ] ) {
@@ -119,7 +117,24 @@ async function runSyncTests() {
119117 false ,
120118 true ,
121119 false ,
122- false
120+ false ,
121+ true ,
122+ true ,
123+ true ,
124+ "A: 23 (true)" ,
125+ true ,
126+ "A: 24 (true)" ,
127+ true ,
128+ "A: 25 (true)" ,
129+ true ,
130+ false ,
131+ false ,
132+ "A: 28 (true)" ,
133+ true ,
134+ false ,
135+ false ,
136+ false ,
137+ false ,
123138 ] ;
124139
125140 class MyEventer extends Eventer {
@@ -145,8 +160,12 @@ async function runSyncTests() {
145160 var onFnBound = events . on . bind ( events ) ;
146161 var AC1 = new AbortController ( ) ;
147162 var AC2 = new AbortController ( ) ;
163+ var AC3 = new AbortController ( ) ;
164+ var AC4 = new AbortController ( ) ;
148165 var AS1 = AC1 . signal ;
149166 var AS2 = AC2 . signal ;
167+ var AS3 = AC3 . signal ;
168+ var AS4 = AC4 . signal ;
150169
151170 results . push ( onFnBound ( "test" , A ) ) ;
152171 results . push ( onFnBound ( "test" , A ) ) ;
@@ -196,6 +215,7 @@ async function runSyncTests() {
196215 results . push ( events3 . once ( "test" , A3 ) ) ;
197216 results . push ( events3 . customEmit ( "test" , counter ++ ) ) ;
198217 results . push ( events3 . off ( "test" , A3 ) ) ;
218+
199219 results . push ( events . on ( "test" , A , { signal : AS1 , } ) ) ;
200220 results . push ( events . emit ( "test" , counter ++ ) ) ;
201221 AC1 . abort ( "unsubscribe-1" ) ;
@@ -207,6 +227,22 @@ async function runSyncTests() {
207227 results . push ( events . emit ( "test" , counter ++ ) ) ;
208228 results . push ( events . off ( "test" , A ) ) ;
209229
230+ results . push ( events . on ( "test-2" , A , { signal : AS3 , } ) ) ;
231+ results . push ( events . on ( "test-3" , A , { signal : AS3 , } ) ) ;
232+ results . push ( events . on ( "test-4" , A , { signal : AS4 , } ) ) ;
233+ results . push ( events . emit ( "test-2" , counter ++ ) ) ;
234+ results . push ( events . emit ( "test-3" , counter ++ ) ) ;
235+ results . push ( events . emit ( "test-4" , counter ++ ) ) ;
236+ AC3 . abort ( "unsubscribe-3" ) ;
237+ results . push ( events . emit ( "test-2" , counter ++ ) ) ;
238+ results . push ( events . emit ( "test-3" , counter ++ ) ) ;
239+ results . push ( events . emit ( "test-4" , counter ++ ) ) ;
240+ results . push ( events . off ( "test-2" , A ) ) ;
241+ results . push ( events . off ( "test-3" , A ) ) ;
242+ AC4 . abort ( "unsubscribe-4" ) ;
243+ results . push ( events . emit ( "test-4" , counter ++ ) ) ;
244+ results . push ( events . off ( "test-4" , A ) ) ;
245+
210246 if ( JSON . stringify ( results ) == JSON . stringify ( expected ) ) {
211247 testResultsEl . innerHTML += "(Sync Tests) PASSED." ;
212248 return true ;
@@ -380,6 +416,8 @@ async function runAsyncTests() {
380416}
381417
382418async function runWeakTestsPart1 ( ) {
419+ cleanupWeakTestsButtons ( ) ;
420+
383421 testResultsEl . innerHTML = "Running weak tests (part 1)...<br>" ;
384422 var expected = [
385423 "A: 0" ,
@@ -417,8 +455,10 @@ async function runWeakTestsPart1() {
417455 weakTests . results . push ( `E: ${ msg } ` ) ;
418456 } ,
419457 } ;
420- var EController = new AbortController ( ) ;
421- var ESignal = EController . signal ;
458+ var EController1 = new AbortController ( ) ;
459+ var ESignal1 = EController1 . signal ;
460+ var EController2 = new AbortController ( ) ;
461+ var ESignal2 = EController2 . signal ;
422462 weakTests . events1 = new Eventer ( { asyncEmit : false , weakListeners : true , } ) ;
423463 weakTests . events2 = new Eventer ( { asyncEmit : false , weakListeners : false , } ) ;
424464 weakTests . events3 = new Eventer ( { asyncEmit : false , weakListeners : false , } ) ;
@@ -430,7 +470,8 @@ async function runWeakTestsPart1() {
430470 weakTests . finalization . register ( weakTests . listeners . C , "C" ) ;
431471 weakTests . finalization . register ( weakTests . listeners . D , "D" ) ;
432472 weakTests . finalization . register ( weakTests . events3 , "events3" ) ;
433- weakTests . finalization . register ( ESignal , "E.signal" ) ;
473+ weakTests . finalization . register ( ESignal1 , "E.signal.1" ) ;
474+ weakTests . finalization . register ( ESignal2 , "E.signal.2" ) ;
434475
435476 try {
436477 var counter = 0 ;
@@ -450,7 +491,9 @@ async function runWeakTestsPart1() {
450491 weakTests . events2 . once ( "test-3" , weakTests . listeners . B ) ;
451492 weakTests . events3 . on ( "test" , weakTests . listeners . D ) ;
452493
453- weakTests . events1 . on ( "test-4" , weakTests . listeners . E , { signal : ESignal , } ) ;
494+ weakTests . events1 . on ( "test-4" , weakTests . listeners . E , { signal : ESignal1 , } ) ;
495+ weakTests . events1 . on ( "test-5" , weakTests . listeners . E , { signal : ESignal1 , } ) ;
496+ weakTests . events1 . on ( "test-6" , weakTests . listeners . E , { signal : ESignal2 , } ) ;
454497
455498 weakTests . results . push ( weakTests . events1 . emit ( "test" , counter ++ ) ) ;
456499 weakTests . results . push ( weakTests . events2 . emit ( "test" , counter ++ ) ) ;
@@ -466,12 +509,21 @@ async function runWeakTestsPart1() {
466509 weakTests . events2 . releaseListeners ( ) ;
467510 weakTests . events3 = null ;
468511 weakTests . listeners = null ;
469- weakTests . EController = EController ;
470- weakTests . ESignal = ESignal ;
471-
472- testResultsEl . innerHTML += "<br><strong>NEXT: Please trigger a GC event in the browser</strong> before running the <em>part 2</em> tests.<br><small>(see instructions above for Chrome or Firefox browsers)<br><br>" ;
473-
474- document . getElementById ( "run-weak-tests-part-2-btn" ) . disabled = false ;
512+ weakTests . EController1 = EController1 ;
513+ weakTests . EController2 = EController2 ;
514+ weakTests . ESignal1 = ESignal1 ;
515+ weakTests . ESignal2 = ESignal2 ;
516+
517+ testResultsEl . innerHTML += `
518+ <br><strong>NEXT: Please trigger a GC event in the browser</strong> before running the <em>part 2</em> tests.
519+ <br>
520+ <small>(see instructions above for Chrome or Firefox browsers)</small>
521+ <br>
522+ <button type="button" id="run-weak-tests-part-2-btn">next (part 2) -></button>
523+ <br><br>
524+ ` ;
525+
526+ document . getElementById ( "run-weak-tests-part-2-btn" ) . addEventListener ( "click" , runWeakTestsPart2 ) ;
475527 return true ;
476528 }
477529 else {
@@ -521,12 +573,21 @@ async function runWeakTestsPart2() {
521573 testResultsEl . innerHTML += "(Weak Tests Part 2) PASSED.<br>" ;
522574
523575 weakTests . results . length = 0 ;
524- // allow GC of abort-controller/signal (for part 3)
525- weakTests . EController = weakTests . ESignal = null ;
576+ // allow GC of abort-controllers/signals (for part 3)
577+ weakTests . EController1 = weakTests . ESignal1 =
578+ weakTests . EController2 = weakTests . ESignal2 = null ;
526579
527- testResultsEl . innerHTML += "<br><strong>LASTLY: Please trigger *ONE MORE* GC event in the browser</strong> before running the <em>part 3</em> tests.<br><small>(see instructions above for Chrome or Firefox browsers)<br><br>" ;
528580
529- document . getElementById ( "run-weak-tests-part-3-btn" ) . disabled = false ;
581+ testResultsEl . innerHTML += `
582+ <br><strong>LASTLY: Please trigger *ONE MORE* GC event in the browser</strong> before running the <em>part 3</em> tests.
583+ <br>
584+ <small>(see instructions above for Chrome or Firefox browsers)</small>
585+ <br>
586+ <button type="button" id="run-weak-tests-part-3-btn">next (part 3) -></button>
587+ <br><br>
588+ ` ;
589+
590+ document . getElementById ( "run-weak-tests-part-3-btn" ) . addEventListener ( "click" , runWeakTestsPart3 ) ;
530591 return true ;
531592 }
532593 else {
@@ -539,15 +600,16 @@ async function runWeakTestsPart2() {
539600 testResultsEl . innerHTML = "(Weak Tests Part 2) FAILED -- see console." ;
540601 }
541602 finally {
542- document . getElementById ( "run-weak-tests-part-2-btn" ) . disabled = true ;
603+ cleanupWeakTestsButtons ( true , false ) ;
543604 }
544605 return false ;
545606}
546607
547608async function runWeakTestsPart3 ( ) {
548609 testResultsEl . innerHTML += "Running weak tests (part 3)...<br>" ;
549610 var expected = [
550- "removed: E.signal" ,
611+ "removed: E.signal.1" ,
612+ "removed: E.signal.2" ,
551613 ] ;
552614 weakTests . finalization = null ;
553615
@@ -573,13 +635,29 @@ async function runWeakTestsPart3() {
573635 testResultsEl . innerHTML = "(Weak Tests Part 3) FAILED -- see console." ;
574636 }
575637 finally {
576- document . getElementById ( "run-weak-tests-part-2-btn" ) . disabled = true ;
577- document . getElementById ( "run-weak-tests-part-3-btn" ) . disabled = true ;
638+ cleanupWeakTestsButtons ( ) ;
578639 weakTests = { } ;
579640 }
580641 return false ;
581642}
582643
644+ function cleanupWeakTestsButtons ( part2 = true , part3 = true ) {
645+ if ( part2 ) {
646+ let btn1 = document . getElementById ( "run-weak-tests-part-2-btn" ) ;
647+ if ( btn1 != null ) {
648+ btn1 . disabled = true ;
649+ btn1 . removeEventListener ( "click" , runWeakTestsPart2 ) ;
650+ }
651+ }
652+ if ( part3 ) {
653+ let btn2 = document . getElementById ( "run-weak-tests-part-3-btn" ) ;
654+ if ( btn2 != null ) {
655+ btn2 . disabled = true ;
656+ btn2 . removeEventListener ( "click" , runWeakTestsPart3 ) ;
657+ }
658+ }
659+ }
660+
583661function timeout ( ms ) {
584662 return new Promise ( res => setTimeout ( res , ms ) ) ;
585663}
0 commit comments