@@ -43,6 +43,23 @@ private FunctionDefinitionExpression(ScriptLoadingContext lcontext, bool pushSel
43
43
if ( m_UsesGlobalEnv = usesGlobalEnv )
44
44
CheckTokenType ( lcontext , TokenType . Function ) ;
45
45
46
+
47
+ // create scope
48
+ // This needs to be up here to allow for arguments to correctly close over ENV
49
+ // Arguments, however, must come before any other local definitions to avoid closing
50
+ // over uninitialised variables. (Note for hoisting).
51
+ lcontext . Scope . PushFunction ( this ) ;
52
+
53
+ if ( m_UsesGlobalEnv )
54
+ {
55
+ m_Env = lcontext . Scope . DefineLocal ( WellKnownSymbols . ENV ) ;
56
+ }
57
+ else
58
+ {
59
+ lcontext . Scope . ForceEnvUpValue ( ) ;
60
+ }
61
+
62
+ // Parse arguments
46
63
// here lexer should be at the '(' or at the '|'
47
64
//Token openRound = CheckTokenType(lcontext, isLambda ? TokenType.Lambda : TokenType.Brk_Open_Round);
48
65
@@ -78,19 +95,10 @@ private FunctionDefinitionExpression(ScriptLoadingContext lcontext, bool pushSel
78
95
79
96
m_Begin = openRound . GetSourceRefUpTo ( lcontext . Lexer . Current ) ;
80
97
81
- // create scope
82
- lcontext . Scope . PushFunction ( this , m_HasVarArgs ) ;
83
-
84
- if ( m_UsesGlobalEnv )
85
- {
86
- m_Env = lcontext . Scope . DefineLocal ( WellKnownSymbols . ENV ) ;
87
- }
88
- else
89
- {
90
- lcontext . Scope . ForceEnvUpValue ( ) ;
91
- }
92
98
93
99
m_ParamNames = DefineArguments ( paramnames , lcontext ) ;
100
+
101
+ if ( m_HasVarArgs ) lcontext . Scope . SetHasVarArgs ( ) ; //Moved here
94
102
95
103
if ( isLambda )
96
104
m_Statement = CreateLambdaBody ( lcontext , arrowFunc ) ;
0 commit comments