OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 | 1606 |
1607 // temp === undefined | 1607 // temp === undefined |
1608 Expression* is_undefined = factory()->NewCompareOperation( | 1608 Expression* is_undefined = factory()->NewCompareOperation( |
1609 Token::EQ_STRICT, assign, | 1609 Token::EQ_STRICT, assign, |
1610 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); | 1610 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); |
1611 | 1611 |
1612 // is_undefined ? this : is_object_conditional | 1612 // is_undefined ? this : is_object_conditional |
1613 return_value = factory()->NewConditional(is_undefined, ThisExpression(pos), | 1613 return_value = factory()->NewConditional(is_undefined, ThisExpression(pos), |
1614 is_object_conditional, pos); | 1614 is_object_conditional, pos); |
1615 } | 1615 } |
| 1616 |
1616 if (is_generator()) { | 1617 if (is_generator()) { |
1617 return_value = BuildIteratorResult(return_value, true); | 1618 return_value = BuildIteratorResult(return_value, true); |
1618 } else if (is_async_function()) { | 1619 } else if (is_async_function()) { |
1619 return_value = BuildResolvePromise(return_value, return_value->position()); | 1620 // In an async function, |
| 1621 // return expr; |
| 1622 // is rewritten as |
| 1623 // return .async_return_value = expr; |
| 1624 return_value = factory()->NewAssignment( |
| 1625 Token::ASSIGN, factory()->NewVariableProxy(AsyncReturnVariable()), |
| 1626 return_value, kNoSourcePosition); |
1620 } | 1627 } |
1621 return return_value; | 1628 return return_value; |
1622 } | 1629 } |
1623 | 1630 |
1624 Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) { | 1631 Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) { |
1625 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); | 1632 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); |
1626 DoExpression* expr = factory()->NewDoExpression(body, result, pos); | 1633 DoExpression* expr = factory()->NewDoExpression(body, result, pos); |
1627 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { | 1634 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { |
1628 *ok = false; | 1635 *ok = false; |
1629 return nullptr; | 1636 return nullptr; |
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2970 if (param_scope != nullptr) { | 2977 if (param_scope != nullptr) { |
2971 CheckConflictingVarDeclarations(param_scope, CHECK_OK); | 2978 CheckConflictingVarDeclarations(param_scope, CHECK_OK); |
2972 } | 2979 } |
2973 init_block->statements()->Add(param_block, zone()); | 2980 init_block->statements()->Add(param_block, zone()); |
2974 } | 2981 } |
2975 ++index; | 2982 ++index; |
2976 } | 2983 } |
2977 return init_block; | 2984 return init_block; |
2978 } | 2985 } |
2979 | 2986 |
2980 Block* Parser::BuildRejectPromiseOnException(Block* inner_block) { | 2987 Block* Parser::BuildRejectPromiseOnExceptionForParameters(Block* inner_block) { |
2981 // .promise = %AsyncFunctionPromiseCreate(); | 2988 // .promise = %AsyncFunctionPromiseCreate(); |
2982 // try { | 2989 // try { |
2983 // <inner_block> | 2990 // <inner_block> |
2984 // } catch (.catch) { | 2991 // } catch (.catch) { |
2985 // %RejectPromise(.promise, .catch); | 2992 // return %RejectPromise(.promise, .catch), .promise; |
2986 // return .promise; | |
2987 // } finally { | |
2988 // %AsyncFunctionPromiseRelease(.promise); | |
2989 // } | 2993 // } |
2990 Block* result = factory()->NewBlock(nullptr, 2, true, kNoSourcePosition); | 2994 Block* result = factory()->NewBlock(nullptr, 2, true, kNoSourcePosition); |
2991 | 2995 |
2992 // .promise = %AsyncFunctionPromiseCreate(); | |
2993 Statement* set_promise; | |
2994 { | 2996 { |
| 2997 // .promise = %AsyncFunctionPromiseCreate(); |
2995 Expression* create_promise = factory()->NewCallRuntime( | 2998 Expression* create_promise = factory()->NewCallRuntime( |
2996 Context::ASYNC_FUNCTION_PROMISE_CREATE_INDEX, | 2999 Context::ASYNC_FUNCTION_PROMISE_CREATE_INDEX, |
2997 new (zone()) ZoneList<Expression*>(0, zone()), kNoSourcePosition); | 3000 new (zone()) ZoneList<Expression*>(0, zone()), kNoSourcePosition); |
2998 Assignment* assign_promise = factory()->NewAssignment( | 3001 Assignment* assign_promise = factory()->NewAssignment( |
2999 Token::INIT, factory()->NewVariableProxy(PromiseVariable()), | 3002 Token::INIT, factory()->NewVariableProxy(PromiseVariable()), |
3000 create_promise, kNoSourcePosition); | 3003 create_promise, kNoSourcePosition); |
3001 set_promise = | 3004 Statement* set_promise = |
3002 factory()->NewExpressionStatement(assign_promise, kNoSourcePosition); | 3005 factory()->NewExpressionStatement(assign_promise, kNoSourcePosition); |
| 3006 result->statements()->Add(set_promise, zone()); |
3003 } | 3007 } |
3004 result->statements()->Add(set_promise, zone()); | |
3005 | 3008 |
3006 // catch (.catch) { return %RejectPromise(.promise, .catch), .promise } | 3009 // catch (.catch) { |
| 3010 // return %RejectPromise(.promise, .catch), .promise; |
| 3011 // } |
3007 Scope* catch_scope = NewScope(CATCH_SCOPE); | 3012 Scope* catch_scope = NewScope(CATCH_SCOPE); |
3008 catch_scope->set_is_hidden(); | 3013 catch_scope->set_is_hidden(); |
3009 Variable* catch_variable = | 3014 Variable* catch_variable = |
3010 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); | 3015 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); |
3011 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3016 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
| 3017 { |
| 3018 // return %RejectPromise(.promise, .catch), .promise; |
| 3019 Expression* reject_return_promise = factory()->NewBinaryOperation( |
| 3020 Token::COMMA, BuildRejectPromise(catch_variable), |
| 3021 factory()->NewVariableProxy(PromiseVariable(), kNoSourcePosition), |
| 3022 kNoSourcePosition); |
3012 | 3023 |
3013 Expression* promise_reject = BuildRejectPromise( | 3024 catch_block->statements()->Add( |
3014 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); | 3025 factory()->NewReturnStatement(reject_return_promise, kNoSourcePosition), |
3015 ReturnStatement* return_promise_reject = | 3026 zone()); |
3016 factory()->NewReturnStatement(promise_reject, kNoSourcePosition); | 3027 } |
3017 catch_block->statements()->Add(return_promise_reject, zone()); | |
3018 | 3028 |
3019 TryStatement* try_catch_statement = | 3029 TryStatement* try_catch_statement = |
3020 factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, | 3030 factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, |
3021 catch_variable, catch_block, | 3031 catch_variable, catch_block, |
3022 kNoSourcePosition); | 3032 kNoSourcePosition); |
| 3033 result->statements()->Add(try_catch_statement, zone()); |
| 3034 return result; |
| 3035 } |
3023 | 3036 |
3024 // There is no TryCatchFinally node, so wrap it in an outer try/finally | 3037 Block* Parser::BuildRejectPromiseOnException(Block* inner_block) { |
| 3038 // .is_rejection = false; |
| 3039 // .promise = %AsyncFunctionPromiseCreate(); |
| 3040 // try { |
| 3041 // <inner_block> |
| 3042 // } catch (.catch) { |
| 3043 // .is_rejection = true; |
| 3044 // .async_return_value = .catch; |
| 3045 // } finally { |
| 3046 // .is_rejection |
| 3047 // ? %RejectPromise(.promise, .async_return_value) |
| 3048 // : %ResolvePromise(.promise, .async_return_value); |
| 3049 // %AsyncFunctionPromiseRelease(.promise); |
| 3050 // return .promise; |
| 3051 // } |
| 3052 Block* result = factory()->NewBlock(nullptr, 3, true, kNoSourcePosition); |
| 3053 |
| 3054 Variable* is_rejection_var = |
| 3055 scope()->NewTemporary(ast_value_factory()->empty_string()); |
| 3056 { |
| 3057 // .is_rejection = false; |
| 3058 Assignment* set_is_rejection = factory()->NewAssignment( |
| 3059 Token::INIT, factory()->NewVariableProxy(is_rejection_var), |
| 3060 factory()->NewBooleanLiteral(false, kNoSourcePosition), |
| 3061 kNoSourcePosition); |
| 3062 result->statements()->Add( |
| 3063 factory()->NewExpressionStatement(set_is_rejection, kNoSourcePosition), |
| 3064 zone()); |
| 3065 |
| 3066 // .promise = %AsyncFunctionPromiseCreate(); |
| 3067 Expression* create_promise = factory()->NewCallRuntime( |
| 3068 Context::ASYNC_FUNCTION_PROMISE_CREATE_INDEX, |
| 3069 new (zone()) ZoneList<Expression*>(0, zone()), kNoSourcePosition); |
| 3070 Assignment* assign_promise = factory()->NewAssignment( |
| 3071 Token::INIT, factory()->NewVariableProxy(PromiseVariable()), |
| 3072 create_promise, kNoSourcePosition); |
| 3073 Statement* set_promise = |
| 3074 factory()->NewExpressionStatement(assign_promise, kNoSourcePosition); |
| 3075 result->statements()->Add(set_promise, zone()); |
| 3076 } |
| 3077 |
| 3078 // catch (.catch) { |
| 3079 // .is_rejection = true; |
| 3080 // .async_return_value = .catch; |
| 3081 // } |
| 3082 Scope* catch_scope = NewScope(CATCH_SCOPE); |
| 3083 catch_scope->set_is_hidden(); |
| 3084 Variable* catch_variable = |
| 3085 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); |
| 3086 Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
| 3087 { |
| 3088 // .is_rejection = true; |
| 3089 DCHECK_NOT_NULL(is_rejection_var); |
| 3090 Assignment* set_is_rejection = factory()->NewAssignment( |
| 3091 Token::ASSIGN, factory()->NewVariableProxy(is_rejection_var), |
| 3092 factory()->NewBooleanLiteral(true, kNoSourcePosition), |
| 3093 kNoSourcePosition); |
| 3094 catch_block->statements()->Add( |
| 3095 factory()->NewExpressionStatement(set_is_rejection, kNoSourcePosition), |
| 3096 zone()); |
| 3097 // .async_return_value = .catch; |
| 3098 Assignment* set_async_return_var = factory()->NewAssignment( |
| 3099 Token::ASSIGN, factory()->NewVariableProxy(AsyncReturnVariable()), |
| 3100 factory()->NewVariableProxy(catch_variable), kNoSourcePosition); |
| 3101 |
| 3102 catch_block->statements()->Add(factory()->NewExpressionStatement( |
| 3103 set_async_return_var, kNoSourcePosition), |
| 3104 zone()); |
| 3105 } |
| 3106 |
| 3107 TryStatement* try_catch_statement = |
| 3108 factory()->NewTryCatchStatementForAsyncAwait(inner_block, catch_scope, |
| 3109 catch_variable, catch_block, |
| 3110 kNoSourcePosition); |
3025 Block* outer_try_block = | 3111 Block* outer_try_block = |
3026 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3112 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
3027 outer_try_block->statements()->Add(try_catch_statement, zone()); | 3113 outer_try_block->statements()->Add(try_catch_statement, zone()); |
3028 | 3114 |
3029 // finally { %AsyncFunctionPromiseRelease(.promise) } | 3115 // finally { |
| 3116 // .is_rejection |
| 3117 // ? %RejectPromise(.promise, .async_return_value) |
| 3118 // : %ResolvePromise(.promise, .async_return_value); |
| 3119 // %AsyncFunctionPromiseRelease(.promise); |
| 3120 // return .promise; |
| 3121 // } |
3030 Block* finally_block = | 3122 Block* finally_block = |
3031 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 3123 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
3032 { | 3124 { |
| 3125 // .is_rejection |
| 3126 // ? %RejectPromise(.promise, .async_return_value) |
| 3127 // : %ResolvePromise(.promise, .async_return_value); |
| 3128 Expression* resolve_or_reject_promise = |
| 3129 factory()->NewConditional(factory()->NewVariableProxy(is_rejection_var), |
| 3130 BuildRejectPromise(AsyncReturnVariable()), |
| 3131 BuildResolvePromise(), kNoSourcePosition); |
| 3132 finally_block->statements()->Add( |
| 3133 factory()->NewExpressionStatement(resolve_or_reject_promise, |
| 3134 kNoSourcePosition), |
| 3135 zone()); |
| 3136 |
| 3137 // %AsyncFunctionPromiseRelease(.promise); |
3033 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); | 3138 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); |
3034 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); | 3139 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); |
3035 Expression* call_promise_release = factory()->NewCallRuntime( | 3140 Expression* call_promise_release = factory()->NewCallRuntime( |
3036 Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX, args, kNoSourcePosition); | 3141 Context::ASYNC_FUNCTION_PROMISE_RELEASE_INDEX, args, kNoSourcePosition); |
3037 Statement* promise_release = factory()->NewExpressionStatement( | 3142 Statement* promise_release = factory()->NewExpressionStatement( |
3038 call_promise_release, kNoSourcePosition); | 3143 call_promise_release, kNoSourcePosition); |
3039 finally_block->statements()->Add(promise_release, zone()); | 3144 finally_block->statements()->Add(promise_release, zone()); |
| 3145 |
| 3146 // return .promise; |
| 3147 Statement* return_promise = factory()->NewReturnStatement( |
| 3148 factory()->NewVariableProxy(PromiseVariable()), kNoSourcePosition); |
| 3149 finally_block->statements()->Add(return_promise, zone()); |
3040 } | 3150 } |
3041 | 3151 |
3042 Statement* try_finally_statement = factory()->NewTryFinallyStatement( | 3152 Statement* try_finally_statement = factory()->NewTryFinallyStatement( |
3043 outer_try_block, finally_block, kNoSourcePosition); | 3153 outer_try_block, finally_block, kNoSourcePosition); |
3044 | |
3045 result->statements()->Add(try_finally_statement, zone()); | 3154 result->statements()->Add(try_finally_statement, zone()); |
3046 return result; | 3155 return result; |
3047 } | 3156 } |
3048 | 3157 |
3049 Assignment* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { | 3158 Assignment* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { |
3050 // .generator = %CreateJSGeneratorObject(...); | 3159 // .generator = %CreateJSGeneratorObject(...); |
3051 DCHECK_NOT_NULL(function_state_->generator_object_variable()); | 3160 DCHECK_NOT_NULL(function_state_->generator_object_variable()); |
3052 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 3161 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
3053 args->Add(factory()->NewThisFunction(pos), zone()); | 3162 args->Add(factory()->NewThisFunction(pos), zone()); |
3054 args->Add(IsArrowFunction(kind) ? GetLiteralUndefined(pos) | 3163 args->Add(IsArrowFunction(kind) ? GetLiteralUndefined(pos) |
3055 : ThisExpression(kNoSourcePosition), | 3164 : ThisExpression(kNoSourcePosition), |
3056 zone()); | 3165 zone()); |
3057 Expression* allocation = | 3166 Expression* allocation = |
3058 factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, pos); | 3167 factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, pos); |
3059 VariableProxy* proxy = | 3168 VariableProxy* proxy = |
3060 factory()->NewVariableProxy(function_state_->generator_object_variable()); | 3169 factory()->NewVariableProxy(function_state_->generator_object_variable()); |
3061 return factory()->NewAssignment(Token::INIT, proxy, allocation, | 3170 return factory()->NewAssignment(Token::INIT, proxy, allocation, |
3062 kNoSourcePosition); | 3171 kNoSourcePosition); |
3063 } | 3172 } |
3064 | 3173 |
3065 Expression* Parser::BuildResolvePromise(Expression* value, int pos) { | 3174 Expression* Parser::BuildResolvePromise() { |
3066 // %ResolvePromise(.promise, value), .promise | 3175 // %ResolvePromise(.promise, .async_return_variable), .promise |
3067 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 3176 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
3068 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); | 3177 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); |
3069 args->Add(value, zone()); | 3178 args->Add(factory()->NewVariableProxy(AsyncReturnVariable()), zone()); |
3070 Expression* call_runtime = | 3179 return factory()->NewCallRuntime(Context::PROMISE_RESOLVE_INDEX, args, |
3071 factory()->NewCallRuntime(Context::PROMISE_RESOLVE_INDEX, args, pos); | 3180 kNoSourcePosition); |
3072 return factory()->NewBinaryOperation( | |
3073 Token::COMMA, call_runtime, | |
3074 factory()->NewVariableProxy(PromiseVariable()), pos); | |
3075 } | 3181 } |
3076 | 3182 |
3077 Expression* Parser::BuildRejectPromise(Expression* value, int pos) { | 3183 Expression* Parser::BuildRejectPromise(Variable* value) { |
3078 // %promise_internal_reject(.promise, value, false), .promise | 3184 // %promise_internal_reject(.promise, .value, false) |
3079 // Disables the additional debug event for the rejection since a debug event | 3185 // Disables the additional debug event for the rejection since a debug event |
3080 // already happened for the exception that got us here. | 3186 // already happened for the exception that got us here. |
3081 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(3, zone()); | 3187 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(3, zone()); |
3082 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); | 3188 args->Add(factory()->NewVariableProxy(PromiseVariable()), zone()); |
3083 args->Add(value, zone()); | 3189 args->Add(factory()->NewVariableProxy(value), zone()); |
3084 args->Add(factory()->NewBooleanLiteral(false, pos), zone()); | 3190 args->Add(factory()->NewBooleanLiteral(false, kNoSourcePosition), zone()); |
3085 Expression* call_runtime = factory()->NewCallRuntime( | 3191 return factory()->NewCallRuntime(Context::PROMISE_INTERNAL_REJECT_INDEX, args, |
3086 Context::PROMISE_INTERNAL_REJECT_INDEX, args, pos); | 3192 kNoSourcePosition); |
3087 return factory()->NewBinaryOperation( | |
3088 Token::COMMA, call_runtime, | |
3089 factory()->NewVariableProxy(PromiseVariable()), pos); | |
3090 } | 3193 } |
3091 | 3194 |
3092 Variable* Parser::PromiseVariable() { | 3195 Variable* Parser::PromiseVariable() { |
3093 // Based on the various compilation paths, there are many different code | 3196 // Based on the various compilation paths, there are many different code |
3094 // paths which may be the first to access the Promise temporary. Whichever | 3197 // paths which may be the first to access the Promise temporary. Whichever |
3095 // comes first should create it and stash it in the FunctionState. | 3198 // comes first should create it and stash it in the FunctionState. |
3096 Variable* promise = function_state_->promise_variable(); | 3199 Variable* promise = function_state_->promise_variable(); |
3097 if (function_state_->promise_variable() == nullptr) { | 3200 if (function_state_->promise_variable() == nullptr) { |
3098 promise = scope()->NewTemporary(ast_value_factory()->empty_string()); | 3201 promise = scope()->NewTemporary(ast_value_factory()->empty_string()); |
3099 function_state_->set_promise_variable(promise); | 3202 function_state_->set_promise_variable(promise); |
3100 } | 3203 } |
3101 return promise; | 3204 return promise; |
3102 } | 3205 } |
3103 | 3206 |
| 3207 Variable* Parser::AsyncReturnVariable() { |
| 3208 // Based on the various compilation paths, there are many different |
| 3209 // code paths which may be the first to access the return value |
| 3210 // temporary. Whichever comes first should create it and stash it in |
| 3211 // the FunctionState. |
| 3212 Variable* async_return = function_state_->async_return_variable(); |
| 3213 if (async_return == nullptr) { |
| 3214 async_return = scope()->NewTemporary(ast_value_factory()->empty_string()); |
| 3215 function_state_->set_async_return_variable(async_return); |
| 3216 } |
| 3217 return async_return; |
| 3218 } |
| 3219 |
3104 Expression* Parser::BuildInitialYield(int pos, FunctionKind kind) { | 3220 Expression* Parser::BuildInitialYield(int pos, FunctionKind kind) { |
3105 Assignment* assignment = BuildCreateJSGeneratorObject(pos, kind); | 3221 Assignment* assignment = BuildCreateJSGeneratorObject(pos, kind); |
3106 VariableProxy* generator = | 3222 VariableProxy* generator = |
3107 factory()->NewVariableProxy(function_state_->generator_object_variable()); | 3223 factory()->NewVariableProxy(function_state_->generator_object_variable()); |
3108 // The position of the yield is important for reporting the exception | 3224 // The position of the yield is important for reporting the exception |
3109 // caused by calling the .throw method on a generator suspended at the | 3225 // caused by calling the .throw method on a generator suspended at the |
3110 // initial yield (i.e. right after generator instantiation). | 3226 // initial yield (i.e. right after generator instantiation). |
3111 return factory()->NewYield(generator, assignment, scope()->start_position(), | 3227 return factory()->NewYield(generator, assignment, scope()->start_position(), |
3112 Yield::kOnExceptionThrow); | 3228 Yield::kOnExceptionThrow); |
3113 } | 3229 } |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3775 zone()); | 3891 zone()); |
3776 } | 3892 } |
3777 | 3893 |
3778 // This method completes the desugaring of the body of async_function. | 3894 // This method completes the desugaring of the body of async_function. |
3779 void Parser::RewriteAsyncFunctionBody(ZoneList<Statement*>* body, Block* block, | 3895 void Parser::RewriteAsyncFunctionBody(ZoneList<Statement*>* body, Block* block, |
3780 Expression* return_value, bool* ok) { | 3896 Expression* return_value, bool* ok) { |
3781 // function async_function() { | 3897 // function async_function() { |
3782 // .generator_object = %CreateJSGeneratorObject(); | 3898 // .generator_object = %CreateJSGeneratorObject(); |
3783 // BuildRejectPromiseOnException({ | 3899 // BuildRejectPromiseOnException({ |
3784 // ... block ... | 3900 // ... block ... |
3785 // return %ResolvePromise(.promise, expr), .promise; | 3901 // .async_return_var = expr; |
3786 // }) | 3902 // }) |
3787 // } | 3903 // } |
3788 | 3904 |
3789 return_value = BuildResolvePromise(return_value, return_value->position()); | 3905 Assignment* set_async_return_var = factory()->NewAssignment( |
3790 block->statements()->Add( | 3906 Token::ASSIGN, factory()->NewVariableProxy(AsyncReturnVariable()), |
3791 factory()->NewReturnStatement(return_value, return_value->position()), | 3907 return_value, kNoSourcePosition); |
3792 zone()); | 3908 block->statements()->Add(factory()->NewExpressionStatement( |
| 3909 set_async_return_var, kNoSourcePosition), |
| 3910 zone()); |
3793 block = BuildRejectPromiseOnException(block); | 3911 block = BuildRejectPromiseOnException(block); |
3794 body->Add(block, zone()); | 3912 body->Add(block, zone()); |
3795 } | 3913 } |
3796 | 3914 |
3797 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { | 3915 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { |
3798 // yield do { | 3916 // yield do { |
3799 // tmp = <operand>; | 3917 // tmp = <operand>; |
3800 // %AsyncFunctionAwait(.generator_object, tmp, .promise); | 3918 // %AsyncFunctionAwait(.generator_object, tmp, .promise); |
3801 // .promise | 3919 // .promise |
3802 // } | 3920 // } |
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5026 | 5144 |
5027 return final_loop; | 5145 return final_loop; |
5028 } | 5146 } |
5029 | 5147 |
5030 #undef CHECK_OK | 5148 #undef CHECK_OK |
5031 #undef CHECK_OK_VOID | 5149 #undef CHECK_OK_VOID |
5032 #undef CHECK_FAILED | 5150 #undef CHECK_FAILED |
5033 | 5151 |
5034 } // namespace internal | 5152 } // namespace internal |
5035 } // namespace v8 | 5153 } // namespace v8 |
OLD | NEW |