mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-26 07:42:07 +00:00 
			
		
		
		
	 a92dc4e30d
			
		
	
	
		a92dc4e30d
		
	
	
	
	
		
			
			When using VM::set_variable() to put the created ScriptFunction onto a ScopeObject, we would previously unexpectedly reach the global object as set_variable() checks each traversed scope for an existing Variable with the given name - which would cause a leak of the inner function past the outer function (we even had a test expecting that behaviour!). Now we first declare functions (as DeclarationKind::Var) before setting them. This will need some more work to make hoisting across non-lexical scopes work, but it fixes this specific issue for now. Fixes #6766.
		
			
				
	
	
		
			15 lines
		
	
	
	
		
			423 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			15 lines
		
	
	
	
		
			423 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| test("issue #6766, nested functions should not leak to global object", () => {
 | |
|     function foo() {
 | |
|         function bar() {
 | |
|             function baz() {
 | |
|                 return 42;
 | |
|             }
 | |
|             return baz();
 | |
|         }
 | |
|         return bar();
 | |
|     }
 | |
|     expect(foo()).toBe(42);
 | |
|     expect(globalThis.foo).toBeUndefined();
 | |
|     expect(globalThis.bar).toBeUndefined();
 | |
|     expect(globalThis.baz).toBeUndefined();
 | |
| });
 |