mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:02:44 +00:00 
			
		
		
		
	 7b1ba4bd5c
			
		
	
	
		7b1ba4bd5c
		
	
	
	
	
		
			
			For something like eval(""), the VM's 'last value' is an empty value,
which we must not leak.
Fixes #6643.
		
	
			
		
			
				
	
	
		
			32 lines
		
	
	
	
		
			860 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
	
		
			860 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 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);
 | |
| });
 | |
| 
 | |
| test("returns value of last value-producing statement", () => {
 | |
|     // See https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluation
 | |
|     expect(eval("")).toBeUndefined();
 | |
|     expect(eval("1;;;;;")).toBe(1);
 | |
|     expect(eval("1;{}")).toBe(1);
 | |
|     expect(eval("1;var a;")).toBe(1);
 | |
| });
 | |
| 
 | |
| test("syntax error", () => {
 | |
|     expect(() => {
 | |
|         eval("{");
 | |
|     }).toThrowWithMessage(
 | |
|         SyntaxError,
 | |
|         "Unexpected token Eof. Expected CurlyClose (line: 1, column: 2)"
 | |
|     );
 | |
| });
 | |
| 
 | |
| test("returns 1st argument unless 1st argument is a string", () => {
 | |
|     var stringObject = new String("1 + 2");
 | |
|     expect(eval(stringObject)).toBe(stringObject);
 | |
| });
 |