Reputation: 55779
The part of the specification for script evaluation is here.
Is it correct to say that the lexing and parsing of the contents of a function is performed on step 10
? If not when is the lexing and parsing performed?
- Let result be
GlobalDeclarationInstantiation(ScriptBody, globalEnv)
.
Is it at this point (step 10
) that the [[Scope]]
on the LexicalEnvironment
gets populated with declared functions and variables?
Is step 11
the step at which the code in the function is actually "executed"?
- If
result.[[type]]
is normal, then Let result be the result of evaluatingScriptBody
.
Upvotes: 1
Views: 69
Reputation: 665554
No, ScriptBody
is an already parsed abstract sytax tree. The parsing does happen before the evaluation, in the ScriptEvaluationJob (sourceText)
:
- Parse
sourceText
usingScript
as the goal symbol and analyze the parse result for any Early Error conditions. If the parse was successful and no early errors were found, letcode
be the resulting parse tree. Otherwise, letcode
be an indication of one or more parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation dependent manner. If more than one parse or early error is present, the number and ordering of reported errors is implementation dependent but at least one error must be reported.
As you can see from the hightlighted sentence, ES does not really distinguish between parsing and lexing.
And of course, there is the following note that allows premature optimisation speculative parsing or using cached compilation results:
An implementation may parse a
sourceText
as aScript
and analyze it for Early Error conditions prior to the execution of theScriptEvaluationJob
for thatsourceText
.
Parsing source code also happens in step 3 of PerformEval
, inside Function
and GeneratorFunction
constructors and somewhen for modules.
Upvotes: 2