Description[async-functions] support await expressions in finally statements
Changes:
- Async functions no longer desugar return statements in Parser::RewriteReturn. Instead, return desugaring happens in BytecodeGenerator::BuildReturn(). This enables evaluation of ResolvePromise() to wait until all finally blocks are evaluated
- Parameter initialization block (created in Parser::BuildParameterInitializationBlock()) is now stored as a separate member of FunctionLiteral, rather than part of the function body.
- The `Scope::function_var_` assignment (in named function expressions) happens in BytecodeGenerator rather than as part of the function body. This variable is created at the end of ParseFunctionBody in parser-base.h, and is guaranteed to be allocated if there are any inner lazily parsed function scopes which may capture the variable, or any eval calls which may capture the variable.
- The above 2 changes allow for generators and async functions to be desugared in BytecodeGenerator, rather than in the Parser, allowing them to evaluate parameter initialization as part of a try-block, with a catch handler (in the case of async functions) and a finally block which closes the generator.
- BytecodeGenerator::VisitTryCatchStatement and VisitTryFinallyStatement defer to BuildTryCatch and BuildTryFinally, to allow this code to be reused by the async function/generator desugarings in BytecodeGenerator::GenerateBytecodeBody()
- BytecodeGenerator::VisitYield() now defers to BytecodeGenerator::BuildYield() and BytecodeGenerator::BuildAwait(), depending on what type of yield it is, which in turn perform different operations to suspend the generator. BuildYield() is also used to desugar the initial yield in generators and modules. Because of this, ast-numbering.cc ensures that modules and generator have at least one yield point, and syntactic yields begin at yield_id=1 rather than 0.
Because await desugaring happens in BytecodeGenerator rather than in Parser::RewriteAwaitExpression(), BytecodeGenerator tracks the current catch_prediction via member catch_prediction_, in the same way that ast-numbering.cc does this. For each catch block generated (via BuildTryCatch), if the catch prediction bit is not HandlerTable::UNCAUGHT, BytecodeGenerator::catch_prediction_ is updated for the course of the catch block, and restored to its previous value afterwards. This results in BytecodeGenerator selecting the correct Await builtin, depending on whether it occurs at the top-level of an async function, or within a syntactic catch try scope.
BUG=v8:5896
R=gsathya@chromium.org, rmcilroy@chromium.org, neis@chromium.org
Patch Set 1 #Patch Set 2 : Get everything working (except possibly inspector tests) #
Total comments: 2
Patch Set 3 : make -Wunused-variable bots happy maybe #
Total comments: 4
Patch Set 4 : and again #Patch Set 5 : make await desugaring behave like it used to in debugger #Patch Set 6 : fix bytecode for await #Patch Set 7 : clean merge #Patch Set 8 : fix the test262 problems sort of #Patch Set 9 : I'd like to build with -Wunused-variables locally, but how!? #
Messages
Total messages: 47 (39 generated)
|