| 
									
										
										
										
											2021-03-15 21:42:44 +01:00
										 |  |  | test("basic eval() functionality", () => { | 
					
						
							|  |  |  |     expect(eval("1 + 2")).toBe(3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function foo(a) { | 
					
						
							|  |  |  |         var x = 5; | 
					
						
							|  |  |  |         eval("x += a"); | 
					
						
							|  |  |  |         return x; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     expect(foo(7)).toBe(12); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-03-15 22:08:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 09:12:34 +01:00
										 |  |  | test("returns value of last value-producing statement", () => { | 
					
						
							|  |  |  |     // See https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluation
 | 
					
						
							|  |  |  |     expect(eval("1;;;;;")).toBe(1); | 
					
						
							|  |  |  |     expect(eval("1;{}")).toBe(1); | 
					
						
							|  |  |  |     expect(eval("1;var a;")).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-15 22:08:28 +01:00
										 |  |  | test("syntax error", () => { | 
					
						
							|  |  |  |     expect(() => { | 
					
						
							|  |  |  |         eval("{"); | 
					
						
							|  |  |  |     }).toThrowWithMessage( | 
					
						
							|  |  |  |         SyntaxError, | 
					
						
							|  |  |  |         "Unexpected token Eof. Expected CurlyClose (line: 1, column: 2)" | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | }); |