mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-11-04 07:10:57 +00:00 
			
		
		
		
	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.
		
			
				
	
	
		
			41 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
describe("function declarations in if statement clauses", () => {
 | 
						|
    test("if clause", () => {
 | 
						|
        if (true) function foo() {}
 | 
						|
        if (false) function bar() {}
 | 
						|
        expect(typeof foo).toBe("function");
 | 
						|
        expect(typeof bar).toBe("undefined");
 | 
						|
    });
 | 
						|
 | 
						|
    test("else clause", () => {
 | 
						|
        if (false);
 | 
						|
        else function foo() {}
 | 
						|
        if (true);
 | 
						|
        else function bar() {}
 | 
						|
        expect(typeof foo).toBe("function");
 | 
						|
        expect(typeof bar).toBe("undefined");
 | 
						|
    });
 | 
						|
 | 
						|
    test("if and else clause", () => {
 | 
						|
        if (true) function foo() {}
 | 
						|
        else function bar() {}
 | 
						|
        expect(typeof foo).toBe("function");
 | 
						|
        expect(typeof bar).toBe("undefined");
 | 
						|
    });
 | 
						|
 | 
						|
    test("syntax error in strict mode", () => {
 | 
						|
        expect(`
 | 
						|
            "use strict";
 | 
						|
            if (true) function foo() {}
 | 
						|
        `).not.toEval();
 | 
						|
        expect(`
 | 
						|
            "use strict";
 | 
						|
            if (false);
 | 
						|
            else function foo() {}
 | 
						|
        `).not.toEval();
 | 
						|
        expect(`
 | 
						|
            "use strict";
 | 
						|
            if (false) function foo() {}
 | 
						|
            else function bar() {}
 | 
						|
        `).not.toEval();
 | 
						|
    });
 | 
						|
});
 |