Chromium Code Reviews

Unified Diff: src/parsing/parser-base.h

Issue 1895603002: [esnext] prototype runtime implementation for async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@AsyncFunction
Patch Set: properly rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 5ea3e43d91eaab6cbd35a08da5a246374cf44557..c6dc1378f485a69c13c0833a837c53f03bf08a3a 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -36,6 +36,12 @@ enum class ParseFunctionFlags {
kIsDefault = 4
};
+enum class FunctionBody {
+ Normal,
+ ArrowBlock = Normal,
+ ArrowConcise,
+};
+
static inline ParseFunctionFlags operator|(ParseFunctionFlags lhs,
ParseFunctionFlags rhs) {
typedef unsigned char T;
@@ -308,7 +314,7 @@ class ParserBase : public Traits {
void set_generator_object_variable(
typename Traits::Type::GeneratorVariable* variable) {
DCHECK(variable != NULL);
- DCHECK(is_generator());
+ DCHECK(is_generator() || is_async_function());
generator_object_variable_ = variable;
}
typename Traits::Type::GeneratorVariable* generator_object_variable()
@@ -2149,8 +2155,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
ValidateFormalParameterInitializer(&arrow_formals_classifier, ok);
Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
- Scope* scope =
- this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction);
+ Scope* scope = this->NewScope(scope_, FUNCTION_SCOPE,
+ is_async ? FunctionKind::kAsyncArrowFunction
+ : FunctionKind::kArrowFunction);
// Because the arrow's parameters were parsed in the outer scope, any
// usage flags that might have been triggered there need to be copied
// to the arrow scope.
@@ -3148,11 +3155,12 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
int expected_property_count = -1;
Scanner::Location super_loc;
+ FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
{
typename Traits::Type::Factory function_factory(ast_value_factory());
- FunctionState function_state(
- &function_state_, &scope_, formal_parameters.scope,
- is_async ? kAsyncArrowFunction : kArrowFunction, &function_factory);
+ FunctionState function_state(&function_state_, &scope_,
+ formal_parameters.scope, arrow_kind,
+ &function_factory);
function_state.SkipMaterializedLiterals(
formal_parameters.materialized_literals_count);
@@ -3177,7 +3185,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
} else {
body = this->ParseEagerFunctionBody(
this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters,
- kArrowFunction, FunctionLiteral::kAnonymousExpression, CHECK_OK);
+ arrow_kind, FunctionLiteral::kAnonymousExpression, CHECK_OK);
materialized_literal_count =
function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count();
@@ -3194,8 +3202,17 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
Traits::RewriteNonPattern(&classifier, CHECK_OK);
body = this->NewStatementList(1, zone());
- this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK);
- body->Add(factory()->NewReturnStatement(expression, pos), zone());
+ this->AddParameterInitializationBlock(formal_parameters, body, is_async,
+ CHECK_OK);
+ if (is_async) {
+ this->ParseAsyncArrowSingleExpressionBody(body, accept_IN, &classifier,
+ pos, CHECK_OK);
+ } else {
+ ExpressionT expression =
+ ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
+ Traits::RewriteNonPattern(&classifier, CHECK_OK);
+ body->Add(factory()->NewReturnStatement(expression, pos), zone());
+ }
materialized_literal_count = function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count();
if (allow_tailcalls() && !is_sloppy(language_mode())) {
@@ -3231,7 +3248,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
materialized_literal_count, expected_property_count, num_parameters,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression,
- FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction,
+ FunctionLiteral::kShouldLazyCompile, arrow_kind,
formal_parameters.scope->start_position());
function_literal->set_function_token_position(

Powered by Google App Engine