How Does GlobalDeclarationInstantiation Initialize Functions?

In the GlobalDeclarationInstantiation abstract operation:

  • VarDeclarations is set to the result of varScopedDeclarations from the script.

  • Only the 8th step populates the functionsToInitialize and declaredFunctionNames lists, and that happens if an element of VarDeclarations is a declaration.

    i also don't understand why it says insert d as the first element instead of append d to functionsToInitialize

  • However, I believe that VarDeclarations cannot contain declarations, as the varScopedDeclarations operation seems to return an empty list for declarations.

If my understanding is correct, how then are functions initialized by the GlobalDeclarationInstantiation operation or any other instantiation operation?

Could you also confirm if my understanding of VarScopedDeclarations is accurate?

varDeclarations comes from VarScopedDeclarations of script, where script is a |Script| parse node. VarScopedDeclarations on a |Script| ends up being

ScriptBody : StatementList

  1. Return the TopLevelVarScopedDeclarations of StatementList.

And TopLevelVarScopedDeclarations has special handling for function declarations. So varDeclarations does in fact end up containing function declarations.

oh yah, I was fixated on declaration's production and missed this.
thanks for answering.