| 
									
										
										
										
											2020-04-21 19:21:26 +01:00
										 |  |  | load("test-common.js"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | try { | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertThrowsError( | 
					
						
							|  |  |  |     () => { | 
					
						
							|  |  |  |       for (const _ of 123) { | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       error: TypeError, | 
					
						
							|  |  |  |       message: "for..of right-hand side must be iterable", | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2020-04-21 19:21:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertThrowsError( | 
					
						
							|  |  |  |     () => { | 
					
						
							|  |  |  |       for (const _ of { foo: 1, bar: 2 }) { | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       error: TypeError, | 
					
						
							|  |  |  |       message: "for..of right-hand side must be iterable", | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2020-04-21 19:21:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertVisitsAll( | 
					
						
							|  |  |  |     visit => { | 
					
						
							|  |  |  |       for (const num of [1, 2, 3]) { | 
					
						
							|  |  |  |         visit(num); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     [1, 2, 3] | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2020-04-21 19:21:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertVisitsAll( | 
					
						
							|  |  |  |     visit => { | 
					
						
							|  |  |  |       for (const char of "hello") { | 
					
						
							|  |  |  |         visit(char); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     ["h", "e", "l", "l", "o"] | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2020-04-21 19:21:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertVisitsAll( | 
					
						
							|  |  |  |     visit => { | 
					
						
							|  |  |  |       for (const char of new String("hello")) { | 
					
						
							|  |  |  |         visit(char); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     ["h", "e", "l", "l", "o"] | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2020-04-21 19:21:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   var char; | 
					
						
							|  |  |  |   for (char of "abc"); | 
					
						
							|  |  |  |   assert(char === "c"); | 
					
						
							| 
									
										
										
										
											2020-04-21 19:21:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   console.log("PASS"); | 
					
						
							| 
									
										
										
										
											2020-04-21 19:21:26 +01:00
										 |  |  | } catch (e) { | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   console.log("FAIL: " + e); | 
					
						
							| 
									
										
										
										
											2020-04-21 19:21:26 +01:00
										 |  |  | } |