| 
									
										
										
										
											2020-11-28 16:19:28 +01:00
										 |  |  | test("basic with statement functionality", () => { | 
					
						
							| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  |     var object = { foo: 5, bar: 6, baz: 7 }; | 
					
						
							| 
									
										
										
										
											2020-11-28 16:19:28 +01:00
										 |  |  |     var qux = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var bar = 99; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with (object) { | 
					
						
							|  |  |  |         expect(foo).toBe(5); | 
					
						
							|  |  |  |         expect(bar).toBe(6); | 
					
						
							|  |  |  |         expect(baz).toBe(7); | 
					
						
							|  |  |  |         expect(qux).toBe(1); | 
					
						
							|  |  |  |         expect(typeof quz).toBe("undefined"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bar = 2; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(object.bar).toBe(2); | 
					
						
							| 
									
										
										
										
											2021-09-08 20:46:11 +02:00
										 |  |  |     expect(() => foo).toThrowWithMessage(ReferenceError, "'foo' is not defined"); | 
					
						
							| 
									
										
										
										
											2020-11-28 16:19:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(bar).toBe(99); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:17:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | test("syntax error in strict mode", () => { | 
					
						
							|  |  |  |     expect("'use strict'; with (foo) {}").not.toEval(); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-09-08 20:46:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | test("restores lexical environment even when exception is thrown", () => { | 
					
						
							|  |  |  |     var object = { | 
					
						
							|  |  |  |         foo: 1, | 
					
						
							|  |  |  |         get bar() { | 
					
						
							|  |  |  |             throw Error(); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |         with (object) { | 
					
						
							|  |  |  |             expect(foo).toBe(1); | 
					
						
							|  |  |  |             bar; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         expect().fail(); | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |         expect(() => foo).toThrowWithMessage(ReferenceError, "'foo' is not defined"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     expect(() => foo).toThrowWithMessage(ReferenceError, "'foo' is not defined"); | 
					
						
							|  |  |  | }); |